Privileged intruction in user mode leads to triple fault.

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
antoni
Member
Member
Posts: 61
Joined: Sun May 24, 2020 9:11 am
Location: /dev/null

Privileged intruction in user mode leads to triple fault.

Post 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.
Gigasoft
Member
Member
Posts: 856
Joined: Sat Nov 21, 2009 5:11 pm

Re: Privileged intruction in user mode leads to triple fault

Post by Gigasoft »

(Edit: never mind, I don't know)
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Privileged intruction in user mode leads to triple fault

Post by nexos »

Did you set SS in TSS?
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
Octocontrabass
Member
Member
Posts: 5568
Joined: Mon Mar 25, 2013 7:01 pm

Re: Privileged intruction in user mode leads to triple fault

Post 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.)
nexos
Member
Member
Posts: 1081
Joined: Tue Feb 18, 2020 3:29 pm
Libera.chat IRC: nexos

Re: Privileged intruction in user mode leads to triple fault

Post 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.
"How did you do this?"
"It's very simple — you read the protocol and write the code." - Bill Joy
Projects: NexNix | libnex | nnpkg
antoni
Member
Member
Posts: 61
Joined: Sun May 24, 2020 9:11 am
Location: /dev/null

Re: Privileged intruction in user mode leads to triple fault

Post 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.
Post Reply