Hi everyone! I'm new in the forum. I'm here because I'm having big problems with IA-32E paging and there aren't any good brazilian foruns on OS development.
I'm developing a simple OS as a hobby, just to learn how a OS work. Nowadays, it's only a text mode OS that does all the initialization stuff (A20 line, segmentation, paging, PIC...) and shows some messages on the screen.
I understand all the theory of paging and segmentation, but I can't get IA-32E paging working. I'm running my code under Bochs. After I enable paging, Bochs tells that the physical address is not available. I understand the error, but can't fix it. It must be something simple, but I've been trying to fix it for more than two weeks and can't get it working.
I've reduced my code to the simplest possible. It jumps directly from Real Mode to Long Mode, without Protected Mode. It detects hardware (1Gb pages supported, Long Mode supported and so on), activates A20, loads a 64 bit GDT and identity maps 1Gb (using a PDPTE that maps 1Gb). I believe that most of the code is ok, so I'll post the stuff that may be causing the error.
Before paging, I load this GDT:
Code: Select all
GDT:
dq 0 ;null-selector
;code:
dw 1111_1111_1111_1111b;bits 0-15 -> bits 0-15 of the segment limit
dw 0;bits 16-31 -> bits 0-15 of the base address
db 0;bits 32-39 -> bits 16-23 of the base address
db 1001_1111b
db 1010_1111b
db 0
;data (32 bits):
dw 1111_1111_1111_1111b
dw 0
db 0
db 1001_0111b
db 1010_1111b
db 0
.p: ;pointer
dw GDT.p - GDT - 1
dq GDT
Code: Select all
mov dword [0], (1000h << 12) | 111b ; It's present, Read/Write and accessible for users and supervisors. It points the PDPTE at 1000h
mov dword [4], 0
Code: Select all
mov dword [1000h],(1 << 7) | 111b ; Present, Read/Write, User/Supervisor. Maps a 1Gb page at physical address 0.
mov dword [1000h + 4],0
Code: Select all
xor eax,eax
mov cr3,eax ; PCIDE is off
Code: Select all
mov ecx,0xC0000080
rdmsr
or eax,1 << 8;LME
wrmsr
Code: Select all
mov eax,cr4
or eax,1 << 5;PAE
mov cr4,eax
Code: Select all
mov eax,cr0
or eax,1 << 31 | 1 << 0;Paging (PG) and Protected Mode (PE)
mov cr0,eax
Code: Select all
jmp 8:long_mode
[bits 64]
long_mode:
hlt
Thanks in advance for any help.