global page_directory global paging_init global paging_finish global KERNEL_MAPPING KERNEL_MAPPING equ 0xC0000000 VGABUF equ 0x000B8000 section .bss align 4096 page_directory: resb 4096 page_table1: resb 4096 section .bootstrap.text align 8 paging_init: extern kernel_start extern kernel_end paging_load: mov edi, page_table1 - KERNEL_MAPPING mov esi, 0 mov ecx, 1023 paging_cmp: cmp esi, kernel_start jl paging_add cmp esi, kernel_end - KERNEL_MAPPING jge paging_map mov edx, esi or edx, 0x003 mov [edi], edx paging_add: add esi, 4096 add edi, 4 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 mov cr3, ecx mov ecx, cr0 or ecx, 0x80010000 mov cr0, ecx ret section .text align 8 paging_finish: mov dword [page_directory], 0 mov ecx, cr3 mov cr3, ecx ret