diff options
Diffstat (limited to '')
-rw-r--r-- | kernel/src/arch/i686/paging.asm | 43 |
1 files changed, 31 insertions, 12 deletions
diff --git a/kernel/src/arch/i686/paging.asm b/kernel/src/arch/i686/paging.asm index f74cc55..0e0a87f 100644 --- a/kernel/src/arch/i686/paging.asm +++ b/kernel/src/arch/i686/paging.asm @@ -1,17 +1,20 @@ global page_directory +global page_tables global paging_init global paging_finish global KERNEL_MAPPING -KERNEL_MAPPING equ 0xC0000000 -VGABUF equ 0x000B8000 +KERNEL_MAPPING equ 0xC0000000 +VGABUF equ 0x000B8000 + +%define mapped(addr) addr - KERNEL_MAPPING section .bss align 4096 page_directory: -resb 4096 -page_table1: -resb 4096 +resb 1024 * 4 +page_tables: +resb 1024 * 1024 * 4 section .bootstrap.text align 8 @@ -20,14 +23,14 @@ paging_init: extern kernel_end paging_load: - mov edi, page_table1 - KERNEL_MAPPING + mov edi, mapped(page_tables) mov esi, 0 mov ecx, 1023 paging_cmp: cmp esi, kernel_start jl paging_add - cmp esi, kernel_end - KERNEL_MAPPING + cmp esi, mapped(kernel_end) jge paging_map mov edx, esi @@ -40,13 +43,27 @@ paging_add: loop paging_cmp paging_map: - mov dword [page_table1 - KERNEL_MAPPING + 1023 * 4], VGABUF | 0x003 - mov dword [page_directory - KERNEL_MAPPING + 0], page_table1 - KERNEL_MAPPING + 0x003 - mov dword [page_directory - KERNEL_MAPPING + 768 * 4], page_table1 - KERNEL_MAPPING + 0x003 - mov ecx, page_directory - KERNEL_MAPPING + lea eax, mapped(page_directory) + push eax + extern setup_pgdir + call mapped(setup_pgdir) + add esp, 0x04 + + ; map VGA buffer + mov dword [mapped(page_tables) + 1023 * 4], VGABUF + 0x003 + + ; map 8MB for the kernel + mov dword [mapped(page_directory) + 0 * 4], mapped(page_tables) + 0x003 + mov dword [mapped(page_directory) + 1 * 4], mapped(page_tables) + 0x400000000 + 0x003 + mov dword [mapped(page_directory) + 768 * 4], mapped(page_tables) + 0x003 + mov dword [mapped(page_directory) + 769 * 4], mapped(page_tables) + 0x400000000 + 0x003 + + ; tell the MMU where the page dir is + mov ecx, mapped(page_directory) mov cr3, ecx + ; finally init paging mov ecx, cr0 or ecx, 0x80010000 mov cr0, ecx @@ -56,7 +73,9 @@ paging_map: section .text align 8 paging_finish: - mov dword [page_directory], 0 + ; remove the 8MB ident mapping + mov dword [page_directory + 0 * 4], 0 + mov dword [page_directory + 1 * 4], 0 mov ecx, cr3 mov cr3, ecx ret |