OSDev.org
https://forum.osdev.org/

[solved]How transfer from ring 0 to ring 3?
https://forum.osdev.org/viewtopic.php?f=1&t=23043
Page 1 of 1

Author:  zhongyijun [ Tue Jan 25, 2011 7:56 pm ]
Post subject:  [solved]How transfer from ring 0 to ring 3?

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]

Author:  gravaera [ Tue Jan 25, 2011 8:03 pm ]
Post subject:  Re: How transfer from ring 0 to ring 3?

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.

Author:  zhongyijun [ Tue Jan 25, 2011 9:00 pm ]
Post subject:  Re: How transfer from ring 0 to ring 3?

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?

Author:  pcmattman [ Tue Jan 25, 2011 9:24 pm ]
Post subject:  Re: How transfer from ring 0 to ring 3?

Quote:
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.

Quote:
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 :).

Author:  zhongyijun [ Tue Jan 25, 2011 9:36 pm ]
Post subject:  Re: How transfer from ring 0 to ring 3?

pcmattman wrote:
Quote:
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.

Quote:
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

Page 1 of 1 All times are UTC - 6 hours
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/