OK, there was an issue with the flags in the PDPE table being wrong (thanks goodness for the Bochs debugger) but I've now sorted that. Trouble is, it triple faults still after I set paging active (no interrupts set up yet) :-
Code: Select all
Next at t=0
(0) [0x0000fffffff0] f000:fff0 (unk. ctxt): jmpf 0xf000:e05b ; ea5be000f0
<bochs:1> c
(0).[92902891] ??? (physical address not available)
Next at t=92902892
(0).[92902892] ??? (physical address not available)
<bochs:2> r
rax: 00000000_e0000011 rcx: 00000000_c0000080
rdx: 00000000_00000000 rbx: 00000000_0000933d
rsp: 00000000_0009ffff rbp: 00000000_00008000
rsi: 00000000_000e0000 rdi: 00000000_00021020
r8 : 00000000_00000000 r9 : 00000000_00000000
r10: 00000000_00000000 r11: 00000000_00000000
r12: 00000000_00000000 r13: 00000000_00000000
r14: 00000000_00000000 r15: 00000000_00000000
rip: 00000000_00009436
eflags 0x00010012: id vip vif ac vm RF nt IOPL=0 of df if tf sf zf AF pf cf
<bochs:3> page 1
PML4: 0x000000000002100b ps a pcd PWT S W P
PDPE: 0x0000000000000081 PS g pat d a pcd pwt S R P
physical address not available for linear 0x0000000000000000
<bochs:4> quit
(0).[92902892] ??? (physical address not available)
The (messy) code for the tables is :-
Code: Select all
mov ax,ds ;start of 64 bit page translation tables
mov es,ax ;
mov edi,PML4E ;
xor ax,ax ;mov 0 to al for storing in tables
mov ecx,0x2000 ;8k for both tables
rep stosb ;store al 8k times
mov eax,PDPE
add eax,0xb ;flags for the first entry in PM4LE
mov [PML4E],eax ;
mov edi,PDPE ;Next the three entries for the 3 gigs of code and memory
mov eax,0x81 ;Flags 0b00000010000001
mov [edi],eax ;store flags+0 base address
;next part of address will be 0 too
mov [edi+4],dword 0 ;store 0 for the next part of the address + 0 in NX bit
add edi,dword 8 ;Next table
mov eax,dword 0x81 ;
bts eax,30 ;set 2GB start
mov [edi],eax ;
xor eax,eax
bts eax,31 ;set 'no eecute' bit as it's data
mov [edi+4],eax
add edi,dword 8 ;next table
mov eax,dword 0x81 ;
bts eax,31 ;3GB
mov [edi],eax
xor eax,eax
bts eax,31 ;no execute bit set as this is data
mov [edi+4],eax
add edi,dword 8
mov eax,0xc0000000 ;4GB
add eax,dword 0x81 ;
mov [edi],eax
xor eax,eax
bts eax,31 ;no execute bit set as this is data
mov [edi+4],eax
add edi,dword 8
mov eax, PML4E ; Pointer to PML4 table (<4GB).
mov cr3, eax ; Initialize CR3 with PML4 base.
It must be an issue with my paging table, I wanted the first 1GB from 0:0 up to 1GB to be a code page and I've set it R/W for now. Can I not use 0:0 as the first address in the table? I'm basically wanting to set the first 1GB to code and the rest to data as there will only be one process running.
Bipman