Here is a portion of my asm file:
Code: Select all
;setup the PD and PTs
; as the page tables are allocated in the bss section they default
; to zero, I will change the entries that hold the 1st mb + the kernel
xor bx, bx
mov eax, kernel_end ; eax now holds the size
sub eax, VIRTUAL_OFFSET ; of the kernel + 1st mb in memory
shr eax, 12
inc eax ; eax now holds the number of pages needed to store memory from 0 to the end of the kernel
mov ecx, eax ; ecx now holds the number of pages needed to store memory from 0 to the end of the kernel
mov ebx, _kernel_page_tables - VIRTUAL_OFFSET ; move the address of the start of the page tables to ebx
; eax = page table entry to save at address
; ebx = page tables pointer(incrementing)
; ecx = number of pages(constant)
; edx =
; in each loop 4096 will be added to eax
; initialise eax with pte for to map first address
mov eax, 3 ; read/write and present
; loop through adding 4096 to each succesive page table entry, this
; works because all the page tables have been preallocated
.l1:
mov dword [ebx], eax
add ebx, 4
add eax, 4096
loop .l1
; set the first few pde's to point to the kernel page table 1 and 2
mov dword [_kernel_pd - VIRTUAL_OFFSET], _kernel_page_tables - VIRTUAL_OFFSET
mov dword [_kernel_pd - VIRTUAL_OFFSET + 4], _kernel_page_tables - VIRTUAL_OFFSET + 4096
; enable paging
mov eax, (_kernel_pd - VIRTUAL_OFFSET)
mov cr3, eax
mov ecx, cr0
or ecx, 0x80000000
mov cr0, ecx
;halt for debugging
xchg bx, bx
hlt
section .bss
align 4
stack:
resb STACKSIZE ; reserve 16k stack on a doubleword boundary
align 0x1000
_kernel_pd:
resb 0x1000
_kernel_page_tables: ; I am creating 256 page tables here
resb 0x100000
Here is the complete debugger output for three runs:
Code: Select all
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[98692884] ??? (physical address not available)
(0).[98692884] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[178217280] ??? (physical address not available)
(0).[178217280] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)
(0) Magic breakpoint
(0) Magic breakpoint
(0).[315778885] ??? (physical address not available)
bx_dbg_read_linear: physical memory read error (phy=0x0000000100000000, lin=0x0000000100000000)