Then I tried to labeling the tables and it instant reboot the OS.
Original code:
Code: Select all
mov edi, 0x1000 ; Set the destination index to 0x1000.
mov cr3, edi ; Set control register 3 to the destination index.
xor eax, eax ; Nullify the A-register.
mov ecx, 4096 ; Set the C-register to 4096.
rep stosd ; Clear the memory.
mov edi, cr3 ; Set the destination index to control register 3.
mov DWORD [edi], 0x2003 ; Set the uint32_t at the destination index to 0x2003.
add edi, 0x1000 ; Add 0x1000 to the destination index.
mov DWORD [edi], 0x3003 ; Set the uint32_t at the destination index to 0x3003.
add edi, 0x1000 ; Add 0x1000 to the destination index.
mov DWORD [edi], 0x4003 ; Set the uint32_t at the destination index to 0x4003.
add edi, 0x1000 ; Add 0x1000 to the destination index.
mov ebx, 0x00000003 ; Set the B-register to 0x00000003.
mov ecx, 512 ; Set the C-register to 512.
.SetEntry:
mov DWORD [edi], ebx ; Set the uint32_t at the destination index to the B-register.
add ebx, 0x1000 ; Add 0x1000 to the B-register.
add edi, 8 ; Add eight to the destination index.
loop .SetEntry ; Set the next entry.
Code: Select all
; Setup page table
;{
%define PG_PRESENT (1 << 0)
%define PG_WRITE (1 << 1)
%define PG_READABLE (1 << 2)
mov DWORD [p4_table], p3_table + (PG_PRESENT + PG_WRITE + PG_READABLE)
mov DWORD [p3_table], p2_table + (PG_PRESENT + PG_WRITE + PG_READABLE)
mov DWORD [p2_table], p1_table + (PG_PRESENT + PG_WRITE + PG_READABLE)
mov ebx, PG_PRESENT + PG_WRITE + PG_READABLE ; Set the B-register to 0x00000003.
mov ecx, 512 ; Set the C-register to 512.
mov edi, p1_table
.SetEntry:
;{
mov [edi], ebx ; Set the uint32_t at the destination index to the B-register.
add ebx, 0x1000 ; Add 0x1000 to the B-register.
add edi, 8 ; Add eight to the destination index.
loop .SetEntry ; Set the next entry.
;}
;}
p5_table: times 0x1000 db 0 ; Page Map Level 5
p4_table: times 0x1000 db 0 ; Page Map Level 4
p3_table: times 0x1000 db 0 ; Page Directory Pointer Table
p2_table: times 0x1000 db 0 ; Page Directory
p1_table: times 0x1000 db 0 ; Page Table