feat(kernel): setup recursive page dir

This commit is contained in:
d0p1 🏳️‍⚧️ 2024-12-27 19:24:31 +01:00
parent 1cd839c63a
commit 6510df8068
4 changed files with 46 additions and 8 deletions

View file

@ -237,6 +237,8 @@ common32:
mov edi, KERNEL_BASE mov edi, KERNEL_BASE
rep movsb rep movsb
;; XXX: refactor this code
; identity map first 1MB ; identity map first 1MB
xor esi, esi xor esi, esi
xor ecx, ecx xor ecx, ecx

View file

@ -1,7 +0,0 @@
PE_PRESENT = (1 shl 0)
PE_WRITABLE = (1 shl 1)
PE_USERMODE = (1 shl 2)
PE_ACCESSED = (1 shl 5)
PE_DIRTY = (1 shl 6)

View file

@ -44,6 +44,10 @@ kmain:
mov esi, szMsgBuildDate mov esi, szMsgBuildDate
call klog call klog
call mm_bootstrap
xchg bx, bx
; init pmm (kend, 0x400000) ; init pmm (kend, 0x400000)
mov eax, kend mov eax, kend
mov ebx, 0xC0400000 mov ebx, 0xC0400000
@ -117,6 +121,7 @@ kmain:
include 'klog.inc' include 'klog.inc'
include 'dev/console.inc' include 'dev/console.inc'
include 'dev/dev.inc' include 'dev/dev.inc'
include 'mm/bootstrap.inc'
include 'mm/mm.old.inc' include 'mm/mm.old.inc'
include 'lock.inc' include 'lock.inc'
include 'gdt.inc' include 'gdt.inc'

View file

@ -2,6 +2,44 @@
;; Bootstrap whole PMM and MM ;; Bootstrap whole PMM and MM
;; Function: mm_bootstrap ;; Function: mm_bootstrap
;; Setup recursive page dir at 0xFFFFF000 and temporary identity map first 3GB ;; Setup recursive paging.
;; map page dir at 0xFFFFF000
mm_bootstrap: mm_bootstrap:
mov esi, szMsgMmBootstrap
call klog
; 0x400000
; PDE entry: 0x7ffc00 phys addr 0xC0 and curr virt addr: 0xc07ffc00
; map first 4MB at KERNEL_VIRT_BASE
xor esi, esi
mov edi, KERNEL_VIRT_BASE + 0x400000 + (768 * PAGE_SIZE)
xor ecx, ecx
@@:
mov edx, esi
or edx, (PTE_P or PTE_W)
mov [edi], edx
add edi, 4
add esi, PAGE_SIZE
inc ecx
cmp ecx, 1024
jb @b
; recusive page dir
mov edi, KERNEL_VIRT_BASE + 0x400000 + (1023 * PAGE_SIZE)
xor ecx, ecx
@@:
mov edx, esi
or edx, (PTE_P or PTE_W)
mov [edi], edx
add edi, 4
add esi, PAGE_SIZE
inc ecx
cmp ecx, 1024
jb @b
mov eax, 0x400000 + (1023 * PAGE_SIZE)
mov cr3, eax
ret ret
szMsgMmBootstrap db "MM: boostrap", 0