VOGONS


Switching DOS into REAL mode

Topic actions

First post, by Gahhhrrrlic

User metadata
Rank Member
Rank
Member

I tried to run memtest just recently and it complained about being in protected mode. Now the easy way to fix this is simply to run the bootable floppy but it got me thinking... what if I want to switch into real mode without rebooting? I did some reading and with a 386, it seems more than possible to do so but I was unable to find an executable for download that would do the switch. Does any such program exist that can put me into real mode on command?

https://hubpages.com/technology/How-to-Maximi … -Retro-Computer

Reply 1 of 21, by Falcosoft

User metadata
Rank Oldbie
Rank
Oldbie

It's the other way around. You have to prevent your EMM386.EXE (or similar) memory manager to switch your CPU into protected mode. The default is real mode. There must be a line in your config.sys that starts it at boot time. Put a REM before it. E.g:
REM DEVICE=C:\DOS\EMM386.EXE RAM I=B000-B7FF
Or even better you should do a a boot menu for multiple configurations. E.g in config.sys:

[MENU]
menuitem=EMS
menuitem=NOEMS

[COMMON]
FILES=40
...

[EMS]
DEVICE=C:\DOS\EMM386.EXE RAM I=B000-B7FF
...

[NOEMS]
...

After you have loaded EMM386 you cannot unload it.

Website, Facebook, Youtube
Falcosoft Soundfont Midi Player + Munt VSTi + BassMidi VSTi
VST Midi Driver Midi Mapper

Reply 2 of 21, by derSammler

User metadata
Rank l33t
Rank
l33t

You can only switch from real mode to protected mode, but not vice-versa. To get back to real mode, you must reset the CPU (note: the CPU, not the system, which can be done in software with tricks).

But as Falcosoft already said, just don't load EMM386. You can also press F5 when DOS starts (up to 6.22), or F8 (7.x) to boot without startup files, which will leave the CPU in real mode as well.

Reply 5 of 21, by Azarien

User metadata
Rank Oldbie
Rank
Oldbie
derSammler wrote:

You can only switch from real mode to protected mode, but not vice-versa. To get back to real mode, you must reset the CPU (note: the CPU, not the system, which can be done in software with tricks).

It's only the 286 that needed to be reset. 386+ are perfectly capable of exiting protected mode. But I'm not sure if EMM386 will let you do that.

Reply 6 of 21, by dr_st

User metadata
Rank l33t
Rank
l33t
derSammler wrote:

F5 on Win9x will boot Windows in safe mode. You need to use F8 if you want to boot into command line.

Ah, OK. But if BootGUI=0, it probably won't boot Windows either way.

https://cloakedthargoid.wordpress.com/ - Random content on hardware, software, games and toys

Reply 7 of 21, by tpowell.ca

User metadata
Rank Member
Rank
Member
Azarien wrote:
derSammler wrote:

You can only switch from real mode to protected mode, but not vice-versa. To get back to real mode, you must reset the CPU (note: the CPU, not the system, which can be done in software with tricks).

It's only the 286 that needed to be reset. 386+ are perfectly capable of exiting protected mode. But I'm not sure if EMM386 will let you do that.

My understanding is that 286+ CPUs go into protected mode as soon as an EMS memory manager is loaded. Himem is safe.
Since you can't unload EMM386, you're stuck.

Not sure about QEMM and others though.

  • Merlin: MS-4144, AMD5x86-160 32MB, 16GB CF, ZIP100, Orpheus, GUS, S3 VirgeGX 2MB
    Tesla: GA-6BXC, VIA C3 Ezra-T, 256MB, 120GB SATA, YMF744, GUSpnp, Quadro2
    Newton: K6XV3+/66, AMD K6-III+500, 256MB, 32GB SSD, AWE32, Voodoo3

Reply 8 of 21, by Jo22

User metadata
Rank l33t++
Rank
l33t++

Hi, by nature Expanded-Memory works in any mode. It uses bank-switching and was originally made for real-mode and the IBM PC 5150/5160.
It depends on the EMS manager to provide that memory. Originally, EMS memory was installed on a dedicated ISA card.
EMM386/QEMM usually switch to protected mode in order to access memory from above 1MiB, which in turn they use to emulate EMS.
Some 286 chipsets emulated EMS and didn't require protected-mode.

That memory beyond 1MIB is often called Extended-Memory. But becareful, XMS does not quite equal "Extended-Memory".
XMS stands for EXtended Memory Specification and is an API for programs.
Just like with EMS, it is up to the XMS manager (Himem.sys) to provide that memory somehow.
There is also a BIOS service, int 15h, which allows to access little pieces of Extended Memory (in real-mode).

In the past/the 80s, Himem.sys switched back-and-forth between real-/protected-mode.
On a 286 system. it caused a CPU reset to get back to real-mode

This changed in the late 80s/early 90s, when Himem.sys from IBM/Microsoft got different code paths.
Himem.sys since 2.06 uses the LOADALL instruction on a 286 to "go back" to real-mode (in reality, it never had to leave it).
On a 386, it uses the official method to go back to real-mode.

Himem.sys from MS-DOS 5 and 6.x do not reset the 286.

Edit: Fixes. Line of text added.
Edit: Removed writing about EMM286 (since it relies on Himem.sys)

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//

Reply 9 of 21, by Gahhhrrrlic

User metadata
Rank Member
Rank
Member

So how does that all add up to commanding a 386 running dos 6.22 to go back into real mode once it's booted with a memory manager that put it in protected mode?

https://hubpages.com/technology/How-to-Maximi … -Retro-Computer

Reply 10 of 21, by Falcosoft

User metadata
Rank Oldbie
Rank
Oldbie

Once you load EMM386.EXE you are in protected/V86 mode. There's no way to undo it in the same session. You cannot unload EMM386 and since EMM386 even prohibits programs to execute privileged instructions no program can switch the CPU back to real mode. So your only option is not to load your memory manager.

For more modern architectures UMBPCI is a good alternative. UMBPCI provides UMB's without switching CPU to protected/V86 mode.

Website, Facebook, Youtube
Falcosoft Soundfont Midi Player + Munt VSTi + BassMidi VSTi
VST Midi Driver Midi Mapper

Reply 11 of 21, by Jo22

User metadata
Rank l33t++
Rank
l33t++
Gahhhrrrlic wrote:

So how does that all add up to commanding a 386 running dos 6.22 to go back into real mode once it's booted with a memory manager that put it in protected mode?

That all adds up to why switching to PM is/was usually a necessarity.

As Falcosoft and the others already told, there's no way EMM386 does allow the CPU to go back to real-mode.
And even if it did, it would cause nothing but trouble. Just imagine what would happen to DOS drivers that were loaded "high" into UMBs.

EMM386 is like a little OS on its own (akin to Win98. whose heart is the V86 virtual machine manager).
It turns on V86 mode (a sub mode of protected-mode) and provides a V86 virtual machine for DOS and DOS programs.

This way, it can intercept any hardware requests. The 386 Memory Managment Unit (MMU), which is enabled in protected-mode,
is then used to provide free UMBS and to simulate the features of an EMS memory board by remapping XMS memory into the EMS page frame.

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//

Reply 13 of 21, by Gahhhrrrlic

User metadata
Rank Member
Rank
Member

Oh ok I get it. So in real mode, memory is just treated as 1 contiguous piece of space but the mem manager is only able to allocate it into specialized blocks because of protected mode and what it can do so once you break it up like that you can't go into real mode or it'd break everything right? I guess it should theoretically still be possible. I did read that 386s could do it and there was some assembly code showing how to force it but maybe the point is that it would have undesirable effects.

So EMM (and its equivalents) is the key here? Just don't load it and you remain in real mode until you do? Should be easy enough.

https://hubpages.com/technology/How-to-Maximi … -Retro-Computer

Reply 14 of 21, by Falcosoft

User metadata
Rank Oldbie
Rank
Oldbie

Oh ok I get it. So in real mode, memory is just treated as 1 contiguous piece of space

No... It's just the opposite 😀
In real mode you can only access memory in 64KB segments (remember real mode is the native mode of the original 8086 that is a 16 bit CPU). You can use a segment + offset scheme to address at most 1MB memory (640KB in practice). Contrary in 32 bit protected mode you can use a 32 bit linear address space to reach at most 4GB of memory.

I guess it should theoretically still be possible.

It's not only theoretically possible. In real mode there is no protection, the user program is king. It can read/write ports, modify specific registers, execute any privileged instructions as it wishes. So a program started in real mode can also switch into protected mode, execute its protected mode payload and switch back to real mode if it wants.

So EMM (and its equivalents) is the key here? Just don't load it and you remain in real mode until you do? Should be easy enough.

Yes. As Jo22 has written above consider EMM386 as a mini operating system. When it is loaded it activates protected/V86 mode and from here user programs run in a V86 'sandbox'. So the big freedom of real mode for user programs is over.

Website, Facebook, Youtube
Falcosoft Soundfont Midi Player + Munt VSTi + BassMidi VSTi
VST Midi Driver Midi Mapper

Reply 15 of 21, by Gahhhrrrlic

User metadata
Rank Member
Rank
Member

Considering the low-level power of real mode, you'd think there'd be some clever provision nowadays to use it more readily. I'm suddenly having thoughts of Arduinos 🤣

https://hubpages.com/technology/How-to-Maximi … -Retro-Computer

Reply 16 of 21, by dr_st

User metadata
Rank l33t
Rank
l33t

Real-mode power such as being limited by a 1MB of addressable RAM and zero protection against crashing the system with random instructions? 😁

https://cloakedthargoid.wordpress.com/ - Random content on hardware, software, games and toys

Reply 17 of 21, by Gahhhrrrlic

User metadata
Rank Member
Rank
Member
dr_st wrote:

Real-mode power such as being limited by a 1MB of addressable RAM and zero protection against crashing the system with random instructions? 😁

Exactly. REAL men live one keystroke at a time!

https://hubpages.com/technology/How-to-Maximi … -Retro-Computer

Reply 18 of 21, by gdjacobs

User metadata
Rank l33t++
Rank
l33t++

Keystroke? Real men toggle everything in on the front panel, one memory word at a time. Keyboards are only useful as an entropy source to feed into TECO when you're bored.

All hail the Great Capacitor Brand Finder

Reply 19 of 21, by Jo22

User metadata
Rank l33t++
Rank
l33t++
gdjacobs wrote:

Keystroke? Real men toggle everything in on the front panel, one memory word at a time.
Keyboards are only useful as an entropy source to feed into TECO when you're bored.

Like so ? https://youtu.be/ObIYVurCfv4

"Time, it seems, doesn't flow. For some it's fast, for some it's slow.
In what to one race is no time at all, another race can rise and fall..." - The Minstrel

//My video channel//