Privilege level switching in x86

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
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

Privilege level switching in x86

Post by sampath »

Hi all,
I am developing a OS with two privilege levels ring0 and ring3.After doing kernel init I am trying to switch to ring 3 code segment.Its giving GP fault for me.

Inside kernel I am doing this:

.............
..........
push USER_SS
push UESP
pushf
push USER_CS
push UEIP
iret

Inside User code I am doing this:

mov ax,USER_DS
mov ds,ax
mov es,ax
mov fs,ax
mov gs,ax
mov ax,USER_SS
mov ss,ax
mov esp,UESP
..............
................



Please correct my mistakes in implementation or understanding.
Thanks in advance....
Sampath S
User avatar
Combuster
Member
Member
Posts: 9301
Joined: Wed Oct 18, 2006 3:45 am
Libera.chat IRC: [com]buster
Location: On the balcony, where I can actually keep 1½m distance
Contact:

Post by Combuster »

For one, have you checked which instruction is causing the GPF? (tried using Bochs' debugger?)

Secondly, you are setting SS while it has already been set to the correct value.

Wild guess: have you set RPL to 3 as well (i.e. using selector + 3 for cs, ss and ds)
"Certainly avoid yourself. He is a newbie and might not realize it. You'll hate his code deeply a few years down the road." - Sortie
[ My OS ] [ VDisk/SFS ]
sampath
Posts: 18
Joined: Wed Dec 20, 2006 4:00 am

thx for the info it works fine now :-)

Post by sampath »

thx for the info it works fine now :-)
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Post by Solar »

It is considered "good style" to give a hint as to what the problem was and how you solved it, so that others that have a problem with "Privilege level switching in x86" will find a solution in this thread, instead of a loose end.
Every good solution is obvious once you've found it.
Post Reply