Page 1 of 1

Privileged intruction in user mode leads to triple fault.

Posted: Fri Jul 09, 2021 10:43 am
by antoni
I have successfully implemented scheduler in my OS. Now I'm able to run programs in ring 3. However, executing any privileged instruction in user mode leads to triple fault.

I don't know why. I have handlers for all exceptions and they work in kernel mode.

I thought that maybe it's the problem with my TSS. I set it as follows:

Code: Select all

memset(&tss_entry, 0, sizeof(tss_entry));
tss_entry.rsp0 = (uint64_t) &kernel_stack + 0x4000;
	
GDT.tss.limit_low = limit & 0xFFFF;
GDT.tss.base_low = base & 0xFFFF;
GDT.tss.base_middle = (base >> 16) & 0xFF;
GDT.tss.access = 0xE9;
GDT.tss.granularity = (limit >> 16) & 0xF;
GDT.tss.base_high = (base >> 24) & 0xFF;
*((uint64_t*) &GDT.tssu) = (base >> 32);

flush_tss();
I have no other idea what might be causing this error.

Re: Privileged intruction in user mode leads to triple fault

Posted: Fri Jul 09, 2021 10:53 am
by Gigasoft
(Edit: never mind, I don't know)

Re: Privileged intruction in user mode leads to triple fault

Posted: Fri Jul 09, 2021 11:07 am
by nexos
Did you set SS in TSS?

Re: Privileged intruction in user mode leads to triple fault

Posted: Fri Jul 09, 2021 11:28 am
by Octocontrabass
Have you tried running it in a VM that can log exceptions (such as QEMU with "-d int") to see exactly which exceptions are causing the triple fault?

(There's no SS in a 64-bit TSS.)

Re: Privileged intruction in user mode leads to triple fault

Posted: Fri Jul 09, 2021 11:49 am
by nexos
Octocontrabass wrote:(There's no SS in a 64-bit TSS.)
Oops, I forgot that. Its been a while since I worked in Long Mode.

Re: Privileged intruction in user mode leads to triple fault

Posted: Fri Jul 09, 2021 3:08 pm
by antoni
Have you tried running it in a VM that can log exceptions (such as QEMU with "-d int") to see exactly which exceptions are causing the triple fault?
1. General Protection Fault (as expected)
2. Page Fault
3. Double Fault

Thank you. I did not know about this flag. i tried multiply debugging opitons but haven't been able to check this. Now, with this information, it'll be much easier for me to track down this bug.