Mapping the page directory to 0xFFFFF000 (problem)
Posted: Thu Dec 13, 2007 2:46 pm
With a little help I got basic paging working. I'm now trying to access my page tables/directory from virtual memory by mapping them in in high memory. The problem, is that I don't think it works like it should.
Here's the paging code:
The problem is that the printed numbers aren't the same. I think they should be. The first number is 1204227, the second is 1204259. I think it should be 1204227 both times.
Please help!
Edit: I forgot so say that if I comment out the magic part of the code, then I get a general protection fault as expected.
Here's the paging code:
Code: Select all
paging_init:
; alloc and clear pdir
call new_frame
shl eax, 12
mov [kernel_pd], eax ; move pointer to page directory into kernel_pd
push PAGE_SIZE
push eax
call zeromeml ; clear the page directory so we get error messages by access the wrong memory
; alloc tbl and setup pdir
call new_frame
shl eax, 12
mov [table], eax
or eax, PG_PRESENT or PG_WRITE
mov edx, [kernel_pd]
mov [edx+0*4], eax
; eax is verified to be 1204227 here
; setup ptbl
mov edx, [table]
mov eax, PG_PRESENT or PG_WRITE
mov ecx, 0
.pageloop:
mov [edx+ecx*4], eax
add eax, PAGE_SIZE
add ecx, 1
cmp ecx, 1024
jne .pageloop
; circle map pdir
; here the magic mystic error maybe happens
mov eax, [kernel_pd] ; load pointer to page directory
mov edx, eax
or edx, PG_PRESENT or PG_WRITE
mov [eax+1023*4], edx
; print the first 4 bytes of the page directory by directly accessing the memory
mov eax, [kernel_pd]
push dword [eax]
call screen_puti
; enable paging
mov eax, [kernel_pd]
mov cr3, eax
mov eax, cr0
or eax, PG_ENABLE_PAGING
mov cr0, eax
; print the first 4 bytes of the page directory through virtual memory mapping
mov eax, [0xFFFFF000]
push eax
call screen_puti
ret
Please help!
Edit: I forgot so say that if I comment out the magic part of the code, then I get a general protection fault as expected.