Hello,
I have a code (my little kernel written in 80386 assembly) running in ring 0 and I'd like to transfer the execution to some other code in the less privileged ring (ring 3) to start executing the userspace code.
What is the best way to do it ? Is the using of task switching (using TSS) needed to do this ?
I'd appreciate also a link to a good documentation on this so I can study the theory myself.
Thanks a lot !
online
How to execute the first "userland" code ?
Re: How to execute the first "userland" code ?
The simplest way to get to ring 3 is to use the iret instruction. You set up the stack to how it would look if an interrupt had been triggered from a lower privilege level (see Intel 3A:6.12.1 - Exception and Interrupt Handling) and then issue iret. Prior to this you need to set up user (dpl = 3) code and data segments. A tss is required for interrupt handling in user mode - it is not required to get there in the first place. Essentially you need the ss0 and esp0 entries set so that if an interrupt is triggered where the interrupt code executed in ring 0 then the system has a valid stack to use. See Getting to Ring 3 for more details.
Regards,
John.
Regards,
John.
Re: How to execute the first "userland" code ?
Thanks, that's exactly what I was looking for !
[ MicroBe OS ]