Page 1 of 1

Privilege level switching in x86

Posted: Tue Jan 23, 2007 1:03 am
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

Posted: Tue Jan 23, 2007 4:31 am
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)

thx for the info it works fine now :-)

Posted: Mon Jan 29, 2007 5:33 am
by sampath
thx for the info it works fine now :-)

Posted: Mon Jan 29, 2007 5:37 am
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.