OSDev.org

The Place to Start for Operating System Developers
It is currently Sat Dec 14, 2019 5:57 am

All times are UTC - 6 hours




Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Mon May 09, 2011 12:56 am 
Offline
Member
Member

Joined: Wed Oct 01, 2008 1:55 pm
Posts: 2215
I hope mainstream OSes will not adopt this for quite some time more, as Intel & AMD could then start dropping protected mode. :twisted:


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Mon May 09, 2011 12:59 am 
Offline
Member
Member
User avatar

Joined: Fri Mar 07, 2008 5:36 pm
Posts: 2097
Location: Bucharest, Romania
You think they've kept real mode along for 33 years, 26 of which because of backwards compatibility, and they're going to drop protected mode just like that?

_________________
"Computers in the future may weigh no more than 1.5 tons.", Popular Mechanics (1949)
[ Project UDI ]


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Mon May 09, 2011 10:01 am 
Offline

Joined: Wed Feb 16, 2011 6:19 pm
Posts: 11
Quote:
No, you can only switch to paged protected mode. However, switching to long mode works from both real mode and non-paged protected mode.


But when returned in paged protected mode, then it should be possible to disable paging and return to real mode ?


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Mon May 09, 2011 10:19 pm 
Offline
Member
Member
User avatar

Joined: Sat Jan 15, 2005 12:00 am
Posts: 8561
Location: At his keyboard!
Hi,

pierrel5 wrote:
Is is possible to return to real mode directly from long mode (to call bios in true real mode ?)


I haven't tried it, and it's been a while since I messed with switching to/from long mode, but as far as I can tell there's no reason why you couldn't switch from long mode directly to real mode.

The steps would be something like:
  • Make sure your code is running in identity mapped pages below 1 MiB
  • Load 16-bit "compatibility mode" segments at CPL=0
  • Disable IRQs and either disable NMI or load an IDT with "limit = zero" (so that NMI causes triple fault)
  • Clear both the PG flag and PE flag in CR0 (to disable protected/long mode and paging at the same time)
  • Reload segment registers with real-mode values
  • Load a real mode IDT (base = 0, limit = 1023)
  • Enable IRQs (and enable NMI if you disabled it)

This should de-activate long mode. There's no need to disable long mode (rather than simply de-activating it), but you could mess with the EFER, clear the PAE flag, etc afterwards if you really do want to disable long mode.

I probably should mention that there's only 3 reasons for any OS to switch back to real mode like this. The first reason is that your OS is badly designed and failed to finish using the BIOS before switching to long mode in the first place (and you should correct your boot code instead). The second reason is that your OS is badly designed and isn't using the hardware like it should (including reconfiguring just everything from legacy hardware like PIC, PIT all the way up to each PCI device; so that everything isn't stuck in some silly time-warp mode from 1978). The third reason is that you think the first 2 reasons don't apply to you because you're writing the OS as a learning experience and you want to learn how to make design failures (in this case learning how to do something wrong is probably worse than not learning how to do something at all). :D

pierrel5 wrote:
Is paging can be disabled in long mode ? (to use one single segment ?)


No.


Cheers,

Brendan

_________________
For all things; perfection is, and will always remain, impossible to achieve in practice. However; by striving for perfection we create things that are as perfect as practically possible. Let the pursuit of perfection be our guide.


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Tue May 10, 2011 2:15 am 
Offline

Joined: Wed Feb 16, 2011 6:19 pm
Posts: 11
Thank you Brendan for you answer.

I know that returning to real mode is ugly, but my OS is light and must work on usb key on every PC.
So if I don't use int13 to access key, I have to program PCI + USB chips drivers + USB stack, .. very complicated to do something reliable on every PC..

Thank you for your help, I'll try your switch method when have time, actually try to program smp :-)

Cheers,
Pierre

ps: I think than doing something wrong is better than doing noting ;-)


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Tue May 10, 2011 12:10 pm 
Offline
Member
Member
User avatar

Joined: Tue Feb 08, 2011 1:58 pm
Posts: 496
pierrel5 wrote:
I know that returning to real mode is ugly, but my OS is light and must work on usb key on every PC.
So if I don't use int13 to access key, I have to program PCI + USB chips drivers + USB stack, .. very complicated to do something reliable on every PC.

It's not so hard, I have already posted an assembly code on this forum (homework: search) that does that: switch to real mode directly from long mode, calls a bios int, and switches back to long mode. No protected mode involved.


Top
 Profile  
 
 Post subject: Re: Switching from real mode to long mode directly..
PostPosted: Tue May 10, 2011 12:37 pm 
Offline

Joined: Wed Feb 16, 2011 6:19 pm
Posts: 11
thank you turdus
Very nice code, exactly what I need :D


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 6 hours


Who is online

Users browsing this forum: Bing [Bot], Google [Bot] and 8 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