OSDev.org

The Place to Start for Operating System Developers
It is currently Wed Dec 07, 2022 7:49 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Switch to ring 3
PostPosted: Mon Jun 01, 2015 5:12 pm 
Offline

Joined: Sat Feb 28, 2015 7:25 am
Posts: 3
Hello, I've (at last) successfully created basic of os - software interrupts in ring 3. Now I am aiming to crate hardware handling for for ex. PIT interrupt. I get back to user mode switch code and pushed corrected eflags on to stack, so the iret will pop ant set the register. After doing this my code fails.

Code:
.global usermode_switch
.type usermode_switch, @function
usermode_switch:
    #Data segment setup
    mov $0x13, %ax
    mov %ax, %ds
    mov %ax, %gs
    mov %ax, %fs
    mov %ax, %es
    #Stack save
    mov %esp, %eax
    #stack setup for iret and user space return
    pushl $0x13
    pushl %eax
    pushf
    #enable ints after switch to ring 3
    pop %eax
    or $0x200, %eax
    pushl %eax
    #CS selector
    pushl $0x0b
    pushl $end_switch
    iret
.extern upperKernelCode
end_switch:
    call upperKernelCode


bochs log says only :
Code:
interrupt(): gate descriptor is not valid sys seg (vector=0x08)
and the two more faults.
Edit: I should mention that
Code:
call upperKernelCode
generates GPF


Last edited by Reverted on Tue Jun 02, 2015 12:22 am, edited 2 times in total.

Top
 Profile  
 
 Post subject: Re: Switch to ring 3
PostPosted: Mon Jun 01, 2015 7:21 pm 
Offline
Member
Member
User avatar

Joined: Sun Sep 19, 2010 10:05 pm
Posts: 1074
I dont think 13 (or even 0x13, for that matter) are valid segment numbers. They start at 0x08, and go up by 0x08, and you need at least two entries in the GDT.

So, you should probably be using segments 0x08 and 0x10.

_________________
Project: OZone
Source: GitHub
Current Task: LIB/OBJ file support
"The more they overthink the plumbing, the easier it is to stop up the drain." - Montgomery Scott


Top
 Profile  
 
 Post subject: Re: Switch to ring 3
PostPosted: Mon Jun 01, 2015 9:01 pm 
Offline
Member
Member

Joined: Thu Mar 25, 2010 11:26 pm
Posts: 1801
Location: Melbourne, Australia
SpyderTL wrote:
I dont think 13 (or even 0x13, for that matter) are valid segment numbers. They start at 0x08, and go up by 0x08, and you need at least two entries in the GDT.

So, you should probably be using segments 0x08 and 0x10.
The lowest 2 bits are the RPL so 0x13 could be a valid selector.

_________________
If a trainstation is where trains stop, what is a workstation ?


Top
 Profile  
 
 Post subject: Re: Switch to ring 3
PostPosted: Tue Jun 02, 2015 2:20 am 
Offline

Joined: Tue May 26, 2015 11:53 pm
Posts: 5
First things first, have you set up a TSS? You need SS0 and ESP0 at the very least, and I believe there's a few other things.

Another thing is that when transitioning to ring 3, IRET not only pops EIP, CS, and EFLAGS, but it also pops the user-mode ESP that you will be using.

I would highly recommend using a separate stack, even if you need to set one up purely for returning to ring 0.


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: DotBot [Bot] and 4 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