Code: Select all
enable_paging:
cli ; disable interrupts if they are enable
page_dir equ 0x9C000 ; the page dir address
page_table equ 0x9D000 ; the page table address
xor eax, eax ; eax = 0
xor ebx, ebx ; ebx = 0
mov ecx, 1024 ; ecx = 1024, the counter for the loop
loop1: ; fill the page table
or eax, 3 ; eax = eax | 3
mov [page_table + ebx], eax ; in C : page_table[ebx/32] = eax
or eax, 3 ; eax = eax | 3 so we have the current address
add ebx, 32 ; ebx = ebx + 32 (32 == one item)
add eax, 4096 ; eax = eax + 4096 (4KB)
loop loop1 ; loop
; fill the page dir
mov eax, page_table ; set the first entry
or eax, 3 ; of the page_dir to the
mov[page_dir + 0x00], eax ; address of the page_table and attributes to 011
xor eax, eax ; eax = 0
or eax, 2 ; eax = eax | 2
mov ebx, 32 ; ebx = 32 (second table item)
mov ecx, 1023 ; loop counter = 1023
loop2:
mov [page_dir + ebx], eax ; in c: page_dir[ebx/32] = eax
add ebx, 32 ; ebx = ebx + 32
loop loop2 ; loop
; enable paging
mov eax, page_dir ; eax = address of page the page dir
mov cr3, eax ; cr3 = eax
mov eax, cr0 ; enable the paging
or eax, 0x80000000 ; bit
mov cr0, eax ; !!!!!!!! Triple Fault : Exception 14 !!!!!!!
ret ; and return