Page 2 of 2

Re: GDT problems while switching to user-mode

Posted: Wed Mar 23, 2016 11:12 am
by MDenham
TheRussianFail wrote:
iansjack wrote:When you call the function it accesses the stack to save the return address.
I'm not calling any functions, I'm iret'ing to the function. The return address of the thread is already stored in the stack.

But what I think is the most strange is that the #PF handler isn't called during the page fault, although the kernel is still mapped. Instead it just triple-faults.
That's because the page fault is happening when the processor is trying to invoke the #DF handler.

Also, your TSS is... abnormally large. (The limit should not be base + sizeof(), just sizeof().) I don't know if this is part of what's causing the problem or not, though.

Re: GDT problems while switching to user-mode

Posted: Wed Mar 23, 2016 11:17 am
by heat
MDenham wrote:
TheRussianFail wrote:
iansjack wrote:When you call the function it accesses the stack to save the return address.
I'm not calling any functions, I'm iret'ing to the function. The return address of the thread is already stored in the stack.

But what I think is the most strange is that the #PF handler isn't called during the page fault, although the kernel is still mapped. Instead it just triple-faults.
That's because the page fault is happening when the processor is trying to invoke the #DF handler.

Also, your TSS is... abnormally large. (The limit should not be base + sizeof(), just sizeof().) I don't know if this is part of what's causing the problem or not, though.
Fixed it.Still the same problem though. GDT is now like this:

Code: Select all

<bochs:3> info gdt
Global Descriptor Table (base=0x00000000c0111aa0, limit=47):
GDT[0x00]=??? descriptor hi=0x00000000, lo=0x00000000
GDT[0x01]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Conforming, Accessed, 32-bit
GDT[0x02]=Data segment, base=0x00000000, limit=0xffffffff, Read/Write, Accessed
GDT[0x03]=Code segment, base=0x00000000, limit=0xffffffff, Execute/Read, Conforming, Accessed, 32-bit
GDT[0x04]=Data segment, base=0x00000000, limit=0xffffffff, Read/Write, Accessed
GDT[0x05]=32-Bit TSS (Busy) at 0xc0111a20, length 0x00068
You can list individual entries with 'info gdt [NUM]' or groups with 'info gdt [NUM] [NUM]'
<bochs:4>