.code32 .extern boot_paging_directory .extern boot_primary_table .section .boot.text, "ax", @progbits .global _boot_paging .type _boot_paging, @function _boot_paging: push %ebp mov %esp, %ebp pusha # Physical address of paging table 1 # movl $(boot_primary_table - 0xC0000000), %edi movl $(boot_primary_table - 0xC0000000), %edi movl $0, %esi movl $1024, %ecx cmpl %esi, %ecx _boot_paging_loop: # stop when after kernel's last address # cmpl $(_kernel_end -0xC0000000), %esi cmpl $(_kernel_end), %esi jge _boot_paging_after_kernel # make address present and writable movl %esi, %edx orl $0x003, %edx movl %edx, (%edi) # next address addl $4096, %esi addl $4, %edi loop _boot_paging_loop _boot_paging_after_kernel: # write to directory movl $(boot_primary_table - 0xC0000000 + 0x003), boot_paging_directory - 0xC0000000 + 0 movl $(boot_primary_table - 0xC0000000 + 0x003), boot_paging_directory - 0xC0000000 + 768 * 4 # write paging directory to cr3 movl $(boot_paging_directory - 0xC0000000), %ecx movl %ecx, %cr3 # enable paging and write protect in cr0 movl %cr0, %ecx orl $0x80010000, %ecx movl %ecx, %cr0 _boot_pagin_end: popa pop %ebp ret