OSDev.org

The Place to Start for Operating System Developers
It is currently Thu Mar 28, 2024 7:43 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: [solved]How transfer from ring 0 to ring 3?
PostPosted: Tue Jan 25, 2011 7:56 pm 
Offline
User avatar

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

_________________
OS,run!


Last edited by zhongyijun on Thu Jan 27, 2011 3:53 am, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: How transfer from ring 0 to ring 3?
PostPosted: Tue Jan 25, 2011 8:03 pm 
Offline
Member
Member
User avatar

Joined: Tue Jun 02, 2009 4:35 pm
Posts: 737
Location: Supporting the cause: Use \tabs to indent code. NOT \x20 spaces.
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.


Top
 Profile  
 
 Post subject: Re: How transfer from ring 0 to ring 3?
PostPosted: Tue Jan 25, 2011 9:00 pm 
Offline
User avatar

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


Top
 Profile  
 
 Post subject: Re: How transfer from ring 0 to ring 3?
PostPosted: Tue Jan 25, 2011 9:24 pm 
Offline
Member
Member

Joined: Sun Jan 14, 2007 9:15 pm
Posts: 2566
Location: Sydney, Australia (I come from a land down under!)
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 :).

_________________
Pedigree | GitHub | Twitter | LinkedIn


Top
 Profile  
 
 Post subject: Re: How transfer from ring 0 to ring 3?
PostPosted: Tue Jan 25, 2011 9:36 pm 
Offline
User avatar

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

_________________
OS,run!


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC - 6 hours


Who is online

Users browsing this forum: belliash, SemrushBot [Bot] and 63 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group