Leaving Compatability, Entering Long Mode
Posted: Mon Nov 20, 2006 6:53 am
I can't even say how many bugs I found trying just to enter compatability mode. Now I realized I can't even get into true long mode. The faq says to alter some of the stuff in the GDT. Does this mean I should load a new GDT (which I tried, didn't work) or should I just change stuff in the current GDT (which I don't think is possible)? All Bochs ever says is "(instruction unavailable) page not present". Heres my code (everything to enable long mode):
I know my paging code is terrible, I just did that so I could actually see Bochs say that I enabled compatability mode without getting errors.
Code: Select all
MOV EAX, CR4 ; Switch CR4 to EAX
BTS EAX, 5 ; Enable CR4.PAE
MOV CR4, EAX ; Switch Back
MOV EAX, 100000h ; Set CR3 to 100000h
MOV CR3, EAX ; Switch EAX back to CR3
XOR EAX, EAX ; EAX = Addr
XOR EBX, EBX ; EBX = Storage
XOR ECX, ECX ; ECX = Counter
.LoopPD:
MOV EBX, EAX ; Store EAX in EBX
OR EBX, 3 ; Or it by 3 (Kernel Mode)
MOV [101000h+ECX], EBX ; Assignment
ADD ECX, 4 ; Increase the counter by a DD
ADD EAX, 4096 ; Increase Address by 4KB
CMP ECX, 4096 ; Compare to 4KB
JL .LoopPD ; Jump back if less
XOR EAX, [101000h] ; EAX = Addr = [101000h]
XOR EBX, EBX ; EBX = Storage
XOR ECX, ECX ; ECX = Counter
.LoopPT:
MOV EBX, EAX ; Store EAX in EBX
OR EBX, 3 ; Or it by 3
MOV [100000h+ECX], EBX ; Assignment
ADD ECX, 4 ; Increase the counter by a DD
CMP ECX, 4096 ; Compare to 4KB
JL .LoopPT ; Jump back if less
MOV ECX, 0C0000080h ; Load ECX with the MSR
RDMSR ; Must be used with ECX
BTS EAX, 8 ; Set Bit 8 of ECX
WRMSR ; Must be used with ECX
MOV EAX, CR0 ; Switch CR0 to EAX
BTS EAX, 31 ; Set Bit 31 of CR0
MOV CR0, EAX ; Switch CR0 to EAX