Re: Problems with Ring3 (Problems with GDT and TSS structure
Posted: Fri Aug 23, 2013 1:38 am
After some twiddling, I realised my error.
The LFB in QEMU is 0xFD000000... the one in Bochs is 0xC0000000.
And *that*, ladies and gentlemen, was the cause of the page-fault.
But there's still a little problem... Returning to ring0.
(For this I've just set up a page-fault to happen on purpose)
The page fault by right should cause me to return to ring0, which it does... sorta.
CS at this point is 0x0B... instead of 0x8.
Highly suspicious.
Next, the TSS doesn't seem to work properly.
This is the TSS code, placing it at 5MB: (don't worry 0-8MB is all identity mapped)
And this are the fields I set:
Supposedly, it will change RSP to 0x00300000 on returning to ring0.
And it should set RSP to 0x00600000 on an exception... configured as such.
The 8-bit field containing the IST, if == 0x01, would be IST1 on AMD's manual (2012) figure 12-8... Right?
Unless it needs to be 0x0... which doesn't make sense since that is the default value and the lack of a TSS would probably kill everything.
Setting it to 1 for selector < 32 (All the CPU exceptions basically) gives a stack fault when I get an exception (when I push the error-code and the exception number).
At this point %rsp is still the user-mode stack at 0x3FFFF0.
If the TSS works, I'd be seeing a value of 0x600000, right?!
So it probably doesn't work.
Any pointers?
The LFB in QEMU is 0xFD000000... the one in Bochs is 0xC0000000.
And *that*, ladies and gentlemen, was the cause of the page-fault.
But there's still a little problem... Returning to ring0.
(For this I've just set up a page-fault to happen on purpose)
The page fault by right should cause me to return to ring0, which it does... sorta.
CS at this point is 0x0B... instead of 0x8.
Highly suspicious.
Next, the TSS doesn't seem to work properly.
This is the TSS code, placing it at 5MB: (don't worry 0-8MB is all identity mapped)
Code: Select all
GDTTSS:
.word 0x0068 // Limit (low)
.word 0x0000 // Base (Addr of TSS)
.byte 0x50 // middle
.byte 0xE9
.byte 0x80
.byte 0x00
.long 0x00
.long 0x00
Code: Select all
Memory::Set32((void*)0x500004, 0x00300000, 1);
Memory::Set32((void*)0x500024, 0x00600000, 1);
asm volatile("mov $0x2B, %ax; ltr %ax");
And it should set RSP to 0x00600000 on an exception... configured as such.
The 8-bit field containing the IST, if == 0x01, would be IST1 on AMD's manual (2012) figure 12-8... Right?
Unless it needs to be 0x0... which doesn't make sense since that is the default value and the lack of a TSS would probably kill everything.
Setting it to 1 for selector < 32 (All the CPU exceptions basically) gives a stack fault when I get an exception (when I push the error-code and the exception number).
At this point %rsp is still the user-mode stack at 0x3FFFF0.
If the TSS works, I'd be seeing a value of 0x600000, right?!
So it probably doesn't work.
Any pointers?