OSDev.org

The Place to Start for Operating System Developers
It is currently Fri Feb 26, 2021 12:56 pm

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: CPU restarts at Ring3 syscalls - for Ring0 works fine
PostPosted: Wed Jan 13, 2021 9:06 am 
Offline
User avatar

Joined: Wed Jan 13, 2021 8:49 am
Posts: 22
Hi!
I'm developing my own OS. Successfully started a task in user mode (CPL 3) but when I called a dummy system call it always restarted the CPU. The facts:

architecture: x86, simple 80386 instruction set I use. Test and debug in qemu.
the problem happens in protected mode, fully set GDT and IDT, no paging. Right before the syscall CPU is in a totally consistent state.
dummy syscall means an interrupt gate with DPL=3, resides in kernel (0x8 CS selector), type=0xee, executes cli hlt. Worked fine if I called it from kernel.
User space code is written in C++,with inline asm. Works fine without syscalls.
Eflags' IF is set.
Stacks are OK (both SS and ESP)
IDT vectors look like this: 0x0008090c 0x0010ee00 (DPL=3, S=0, P=1, type=e, selector=8, offset=0x10090c. All offsets are correct.
The restart happens at the 'int 0x30' instruction.
Do you have any idea, what I've missed?

Thanks in advance,
Robert


Top
 Profile  
 
 Post subject: Re: CPU restarts at Ring3 syscalls - for Ring0 works fine
PostPosted: Wed Jan 13, 2021 5:53 pm 
Offline
Member
Member

Joined: Mon Mar 25, 2013 7:01 pm
Posts: 2796
Robert wrote:
Do you have any idea, what I've missed?

Did you set up exception handlers? They can help you troubleshoot issues like this.

Did you set up a TSS?


Top
 Profile  
 
 Post subject: Re: CPU restarts at Ring3 syscalls - for Ring0 works fine
PostPosted: Wed Jan 13, 2021 8:52 pm 
Offline
Member
Member

Joined: Fri May 11, 2018 6:51 am
Posts: 70
No sure what happened, but CPU restarts in case of a Triple_Fault.
Briefly, it means that a fault occurred while trying to execute an interrupt handler, a software exception triggered by your user code in this case, and that there was no double-fault handler or if a fault occurred while trying to execute the double fault handler itself.

One of the reasons for a fault to occur when the CPU is trying to execute an exception handler is being unable to write to the stack.
That's why Octocontrabass asked if you did setup a TSS. The CPU needs to know which ESP and SS to use in case an
interrupt occurs.

_________________
Tilck, a Tiny Linux-Compatible Kernel: https://github.com/vvaltchev/tilck


Top
 Profile  
 
 Post subject: Re: CPU restarts at Ring3 syscalls - for Ring0 works fine
PostPosted: Thu Jan 14, 2021 8:19 am 
Offline
User avatar

Joined: Wed Jan 13, 2021 8:49 am
Posts: 22
Octocontrabass wrote:
Robert wrote:
Do you have any idea, what I've missed?

Did you set up exception handlers? They can help you troubleshoot issues like this.

Did you set up a TSS?


TSS was the solution. Although I use sw task switching,kernel needed a TSS in GDT. Loaded by
LTR then everything worked fine.
Thanks for the help.

Problem solved, this topic became pointless.
Should I close it somehow?


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: kzinti and 16 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group