feat(kernel/mm): unmap first page
This commit is contained in:
parent
52236d2016
commit
6b89f3c48b
|
@ -202,37 +202,7 @@ common32:
|
|||
|
||||
mov dword [boot_page_directory], boot_0_page_table + 0x3 ; preset and writable
|
||||
|
||||
; map kernel at 0xC0000000
|
||||
mov esi, KERNEL_BASE
|
||||
mov edi, boot_768_page_table
|
||||
xor ecx, ecx
|
||||
@@:
|
||||
mov edx, esi
|
||||
or edx, 0x3
|
||||
mov [edi], edx
|
||||
add edi, 4
|
||||
add esi, 4096
|
||||
add ecx, 4096
|
||||
cmp ecx, [uKernelSize]
|
||||
jbe @b
|
||||
|
||||
; map some memory untils 0xC03B0000 for memory allocator
|
||||
@@:
|
||||
mov edx, esi
|
||||
or edx, 0x3
|
||||
mov [edi], edx
|
||||
add edi, 4
|
||||
add ecx, 4096
|
||||
add esi, 4096
|
||||
cmp ecx, 0x3B0000
|
||||
jb @b
|
||||
|
||||
|
||||
; map 0xB8000 (vga) to 0xC03B0000
|
||||
; 0xC03B0000 >> 12 & 0x3FF == 944
|
||||
mov dword [boot_768_page_table + 944 * 4], 0xB8000 + 0x3
|
||||
|
||||
mov dword [boot_page_directory + (768 * 4)], boot_768_page_table + 0x3
|
||||
mov dword [boot_page_directory + (768 * 4)], boot_0_page_table + 0x3
|
||||
|
||||
mov eax, boot_page_directory
|
||||
mov cr3, eax
|
||||
|
@ -244,7 +214,7 @@ common32:
|
|||
mov eax, STPDBOOT_MAGIC
|
||||
mov ebx, boot_structure
|
||||
|
||||
mov ecx, 0xC0000000
|
||||
mov ecx, 0xC0000000 + KERNEL_BASE
|
||||
jmp ecx
|
||||
|
||||
hang:
|
||||
|
@ -259,9 +229,6 @@ boot_structure BootInfo
|
|||
boot_page_directory:
|
||||
rb 4096
|
||||
|
||||
boot_768_page_table:
|
||||
rb 4096
|
||||
|
||||
boot_0_page_table:
|
||||
rb 4096
|
||||
|
||||
|
|
|
@ -1,4 +1,7 @@
|
|||
KBASE = 0xC0000000
|
||||
KERNEL_VIRT_BASE = 0xC0000000
|
||||
KERNEL_OFFSET = 0x100000
|
||||
KBASE = KERNEL_VIRT_BASE + KERNEL_OFFSET
|
||||
|
||||
PSIZE = 0x1000
|
||||
|
||||
STPDBOOT_MAGIC = 0x53545044
|
||||
|
@ -6,45 +9,8 @@ STPDBOOT_MAGIC = 0x53545044
|
|||
; --------- VERSION -------------
|
||||
VERSION_MAJOR = 1
|
||||
VERSION_MINOR = 0
|
||||
VERSION_COMMIT = "@COMMIT@"
|
||||
|
||||
; --------- Registers ------------
|
||||
CR0_PE = 0x00000001
|
||||
CR0_MP = 0x00000002
|
||||
CR0_EM = 0x00000004
|
||||
CR0_TS = 0x00000008
|
||||
CR0_ET = 0x00000010
|
||||
CR0_NE = 0x00000020
|
||||
CR0_WP = 0x00010000
|
||||
CR0_AM = 0x00040000
|
||||
CR0_NW = 0x20000000
|
||||
CR0_CD = 0x40000000
|
||||
CR0_PG = 0x80000000
|
||||
|
||||
CR3_PWT = 0x08
|
||||
CR3_PCD = 0x10
|
||||
|
||||
CR4_VME = 0x0000001
|
||||
CR4_PVI = 0x0000002
|
||||
CR4_TSD = 0x0000004
|
||||
CR4_DE = 0x0000008
|
||||
CR4_PSE = 0x0000010
|
||||
CR4_PAE = 0x0000020
|
||||
CR4_MCE = 0x0000040
|
||||
CR4_PGE = 0x0000080
|
||||
CR4_PCE = 0x0000100
|
||||
CR4_OSDXSR = 0x0000200
|
||||
CR4_OSXMMEXCPT = 0x0000400
|
||||
CR4_UMIP = 0x0000800
|
||||
CR4_VMXE = 0x0002000
|
||||
CR4_SMXE = 0x0004000
|
||||
CR4_FSGSBASE = 0x0010000
|
||||
CR4_PCIDE = 0x0020000
|
||||
CR4_OSXSAVE = 0x0040000
|
||||
CR4_SMEP = 0x0100000
|
||||
CR4_SMAP = 0x0200000
|
||||
CR4_PKE = 0x0400000
|
||||
CR4_CET = 0x0800000
|
||||
CR4_PKS = 0x1000000
|
||||
|
||||
; ------------- OTHER -----------
|
||||
CR = 0x0D
|
||||
LF = 0x0A
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
VGA_COLUMNS = 80
|
||||
VGA_LINES = 25
|
||||
VGA_BASE = 0xC03B0000
|
||||
VGA_BASE = 0xC00B8000
|
||||
|
||||
vga_lineno db 0
|
||||
vga_colno db 0
|
||||
|
|
|
@ -30,17 +30,17 @@ kmain:
|
|||
mov edi, boot_structure
|
||||
|
||||
; print hello world
|
||||
mov [0xC03B0000], dword 0x08740953
|
||||
mov [0xC03B0004], dword 0x05700675
|
||||
mov [0xC03B0008], dword 0x03640469
|
||||
mov [0xC03B000C], dword 0x0153024F
|
||||
mov [0xC00B8000], dword 0x08740953
|
||||
mov [0xC00B8004], dword 0x05700675
|
||||
mov [0xC00B8008], dword 0x03640469
|
||||
mov [0xC00B800C], dword 0x0153024F
|
||||
|
||||
mov esi, szMsgKernelAlive
|
||||
call klog
|
||||
|
||||
; init pmm (kend, 0x3B0000)
|
||||
; init pmm (kend, 0x400000)
|
||||
mov eax, kend
|
||||
mov ebx, 0xC03B0000
|
||||
mov ebx, 0xC0400000
|
||||
call pmm_init
|
||||
|
||||
; init vmm
|
||||
|
|
|
@ -3,6 +3,10 @@
|
|||
|
||||
include "pmm.inc"
|
||||
|
||||
macro KV2P reg {
|
||||
sub reg, KERNEL_VIRT_BASE
|
||||
}
|
||||
|
||||
mm_init:
|
||||
mov esi, szMsgMmInit
|
||||
call klog
|
||||
|
@ -10,10 +14,6 @@ mm_init:
|
|||
call pmm_alloc_page
|
||||
mov [pKernelPgDir], eax
|
||||
|
||||
push eax
|
||||
mov esi, szMsgMmKernelPgDir
|
||||
call klog
|
||||
|
||||
; clear page dir
|
||||
mov ecx, 4096
|
||||
xor al, al
|
||||
|
@ -22,20 +22,34 @@ mm_init:
|
|||
|
||||
;; Map kernel and kmemory
|
||||
call pmm_alloc_page
|
||||
push eax
|
||||
mov ecx, 4096
|
||||
xor esi, esi
|
||||
xor ecx, ecx
|
||||
mov edi, eax
|
||||
xor al, al
|
||||
rep stosb
|
||||
pop eax
|
||||
|
||||
;; Map video
|
||||
@@:
|
||||
mov edx, esi
|
||||
or edx, 0x3
|
||||
mov [edi], edx
|
||||
add edi, 4
|
||||
add esi, 4096
|
||||
inc ecx
|
||||
cmp ecx, 1024
|
||||
jb @b
|
||||
|
||||
or eax, 0x03
|
||||
mov edx, [pKernelPgDir]
|
||||
add edx, (768 * 4)
|
||||
KV2P eax
|
||||
mov [edx], eax
|
||||
|
||||
;; Map free memory
|
||||
|
||||
; mov eax, [pKernelPgDir]
|
||||
; mov cr3, eax
|
||||
mov eax, [pKernelPgDir]
|
||||
KV2P eax
|
||||
mov cr3, eax
|
||||
|
||||
push eax
|
||||
mov esi, szMsgMmKernelPgDir
|
||||
call klog
|
||||
|
||||
ret
|
||||
|
||||
|
@ -43,5 +57,5 @@ mm_wallk_pagedir:
|
|||
ret
|
||||
|
||||
szMsgMmInit db "MM: initialize", 0
|
||||
szMsgMmKernelPgDir db "MM: Kernel page dir at %x", 0
|
||||
pKernelPgDir dd ?
|
||||
szMsgMmKernelPgDir db "MM: Kernel page dir at %x phys", 0
|
||||
pKernelPgDir dd 0
|
||||
|
|
|
@ -63,8 +63,6 @@ pmm_free_range:
|
|||
mov esi, szMsgPmmFreeRange
|
||||
call klog
|
||||
|
||||
xchg bx, bx
|
||||
|
||||
mov esi, [ebp-4]
|
||||
.loop:
|
||||
mov eax, [pFreeList]
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
struc VMStat
|
||||
{
|
||||
total_page dd 0
|
||||
free_pages dd 0
|
||||
used_pages dd 0
|
||||
}
|
||||
|
Loading…
Reference in a new issue