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).
pierrel5 wrote:
Is paging can be disabled in long mode ? (to use one single segment ?)
No.
Cheers,
Brendan