Switching from real mode to long mode directly..
Re: Switching from real mode to long mode directly..
I hope mainstream OSes will not adopt this for quite some time more, as Intel & AMD could then start dropping protected mode.
- Love4Boobies
- Member
- Posts: 2111
- Joined: Fri Mar 07, 2008 5:36 pm
- Location: Bucharest, Romania
Re: Switching from real mode to long mode directly..
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 ]
[ Project UDI ]
Re: Switching from real mode to long mode directly..
But when returned in paged protected mode, then it should be possible to disable paging and return to real mode ?No, you can only switch to paged protected mode. However, switching to long mode works from both real mode and non-paged protected mode.
Re: Switching from real mode to long mode directly..
Hi,
The steps would be something like:
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).
Cheers,
Brendan
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.pierrel5 wrote:Is is possible to return to real mode directly from long mode (to call bios in true 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)
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).
No.pierrel5 wrote:Is paging can be disabled in long mode ? (to use one single segment ?)
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.
Re: Switching from real mode to long mode directly..
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
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
Re: Switching from real mode to long mode directly..
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.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.
Re: Switching from real mode to long mode directly..
thank you turdus
Very nice code, exactly what I need
Very nice code, exactly what I need