[solved]How transfer from ring 0 to ring 3?

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
User avatar
zhongyijun
Posts: 5
Joined: Wed Jan 12, 2011 1:17 am
Contact:

[solved]How transfer from ring 0 to ring 3?

Post by zhongyijun »

I was running code which was running in ring 0,and now I want to transfer to code segment which is ring 3. How to implement it?

[edit: AJ - removed font colouring]
Last edited by zhongyijun on Thu Jan 27, 2011 3:53 am, edited 1 time in total.
OS,run!
User avatar
gravaera
Member
Member
Posts: 737
Joined: Tue Jun 02, 2009 4:35 pm
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.

Re: How transfer from ring 0 to ring 3?

Post by gravaera »

Yo,

There's no need to type in a large, coloured font: I assure you, the majority of the people who can answer your question can also read English :) .

To switch data segments (DS, ES, FS, GS, SS) you need only do a MOV, or a POP into them. However, for CS, you cannot do a "MOVL $SEGNUM, %cs". You must pop the new code segment descriptor into the CS register via a RETF, or an IRET.
17:56 < sortie> Paging is called paging because you need to draw it on pages in your notebook to succeed at it.
User avatar
zhongyijun
Posts: 5
Joined: Wed Jan 12, 2011 1:17 am
Contact:

Re: How transfer from ring 0 to ring 3?

Post by zhongyijun »

gravaera wrote:Yo,

There's no need to type in a large, coloured font: I assure you, the majority of the people who can answer your question can also read English :) .

To switch data segments (DS, ES, FS, GS, SS) you need only do a MOV, or a POP into them. However, for CS, you cannot do a "MOVL $SEGNUM, %cs". You must pop the new code segment descriptor into the CS register via a RETF, or an IRET.
:D Just want readers happy as more larger font.
Another way transfer to ring 3 other than RETF or IRET?
OS,run!
pcmattman
Member
Member
Posts: 2566
Joined: Sun Jan 14, 2007 9:15 pm
Libera.chat IRC: miselin
Location: Sydney, Australia (I come from a land down under!)
Contact:

Re: How transfer from ring 0 to ring 3?

Post by pcmattman »

Just want readers happy as more larger font.
My (and many others) theme is mostly blue, so your choice of font contrasts badly against the rest of the page. Spend more time thinking about asking your question rather than thinking about how it looks ;).

Dropping to ring3 from ring0 is fairly straightforward. One method you can use is to set your segment registers - all except SS and CS. Once this is done, you can push the userspace stack segment, the userspace stack, EFLAGS, userspace CS, your desired EIP, and then simply iret. Note this order is not necessarily correct ;).

Before you can do all that you will need a TSS in order to get back from ring3 to ring0. A potentially useful wiki page already exists, and links to an article which even has some free assembly code for the move to ring3. Note though that you don't want to copy & paste from this article; you need to understand what you are doing.

The best thing you can do right now, before you write any more code, is read the Intel manuals. All information related to ring transitions will be in Volume 3A. The description of the IRET and RETF instructions will be in volumes 2A and 2B.
Another way transfer to ring 3 other than RETF or IRET?
This sounds like a great opportunity for you to do some research in the manuals, and as an added bonus you'll be a bit more familiar with them :).
User avatar
zhongyijun
Posts: 5
Joined: Wed Jan 12, 2011 1:17 am
Contact:

Re: How transfer from ring 0 to ring 3?

Post by zhongyijun »

pcmattman wrote:
Just want readers happy as more larger font.
My (and many others) theme is mostly blue, so your choice of font contrasts badly against the rest of the page. Spend more time thinking about asking your question rather than thinking about how it looks ;).

Dropping to ring3 from ring0 is fairly straightforward. One method you can use is to set your segment registers - all except SS and CS. Once this is done, you can push the userspace stack segment, the userspace stack, EFLAGS, userspace CS, your desired EIP, and then simply iret. Note this order is not necessarily correct ;).

Before you can do all that you will need a TSS in order to get back from ring3 to ring0. A potentially useful wiki page already exists, and links to an article which even has some free assembly code for the move to ring3. Note though that you don't want to copy & paste from this article; you need to understand what you are doing.

The best thing you can do right now, before you write any more code, is read the Intel manuals. All information related to ring transitions will be in Volume 3A. The description of the IRET and RETF instructions will be in volumes 2A and 2B.
Another way transfer to ring 3 other than RETF or IRET?
This sounds like a great opportunity for you to do some research in the manuals, and as an added bonus you'll be a bit more familiar with them :).
thanks,doing research in manuals now
OS,run!
Post Reply