diff --git a/boot/loader/loader.asm b/boot/loader/loader.asm index daeaf7a..3338d0b 100644 --- a/boot/loader/loader.asm +++ b/boot/loader/loader.asm @@ -237,6 +237,8 @@ common32: mov edi, KERNEL_BASE rep movsb + ;; XXX: refactor this code + ; identity map first 1MB xor esi, esi xor ecx, ecx diff --git a/boot/loader/mmu.inc b/boot/loader/mmu.inc deleted file mode 100644 index 0317859..0000000 --- a/boot/loader/mmu.inc +++ /dev/null @@ -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) - - \ No newline at end of file diff --git a/kernel/kernel.asm b/kernel/kernel.asm index 771a54b..f9d4ce4 100644 --- a/kernel/kernel.asm +++ b/kernel/kernel.asm @@ -44,6 +44,10 @@ kmain: mov esi, szMsgBuildDate call klog + call mm_bootstrap + + xchg bx, bx + ; init pmm (kend, 0x400000) mov eax, kend mov ebx, 0xC0400000 @@ -117,6 +121,7 @@ kmain: include 'klog.inc' include 'dev/console.inc' include 'dev/dev.inc' + include 'mm/bootstrap.inc' include 'mm/mm.old.inc' include 'lock.inc' include 'gdt.inc' diff --git a/kernel/mm/bootstrap.inc b/kernel/mm/bootstrap.inc index a581a5f..d942df0 100644 --- a/kernel/mm/bootstrap.inc +++ b/kernel/mm/bootstrap.inc @@ -2,6 +2,44 @@ ;; Bootstrap whole PMM and MM ;; 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: + 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 + +szMsgMmBootstrap db "MM: boostrap", 0