OSD Home

- # - Pmode quick start
- # - Virtual 8086 (V86) mode
- # - Code snippets
- # - Links
- REPORT BUGS OR ERRORS IN THIS DOCUMENT

## Pmode quick start

### No other protected mode OS or code can be running

- A Windows 3.x or Windows 9x DOS box won't work.
- A Windows NT, Windows 2000, or Windows XP command prompt won't work. These OSes do not support 'MS-DOS Mode', so your OS or pmode code must use a bootloader.
- Linux won't work. Use a bootloader.
- The Bochs PC simulator will probably work. Code that works on a real system but fails under Bochs (or vice versa) is usually code that makes unwarranted assumptions, e.g. boot value in CS or DS register, stack location, memory size and layout, availability of VESA video functions, initial state of A20 and supported A20 control methods, etc.
- DOS with EMM386 loaded probably won't work.
- Setting up a Windows 9x shortcut or PIF to put the computer into 'MS-DOS Mode' might work. I don't recommend this because it may be necessary to type `EXIT` from the DOS command prompt in order to re-start Windows.
- Clicking on the Win95 'Start' button, then on 'Shut Down...', then choosing 'Restart the computer in MS-DOS mode' may work, but may also have the same problem as the method listed above.
- Chosing 'Safe mode command prompt only' from the Windows 95 boot menu will work. (To get this menu, reboot your computer, then press and hold F8 just before the 'Starting Windows 95...' message appears.)
- The best way to get plain DOS with Windows 9x:

              C:
              CD \
      	ATTRIB -H -R -S MSDOS.SYS
              EDIT MSDOS.SYS
              add/change the BootGUI line in the [Options] section:
                      [Options]
                      BootGUI=0
              save file, close EDIT
              ATTRIB +H +R +S MSDOS.SYS

  The next time you reboot your computer, only DOS 7 will start. To finish loading Windows, you must type WIN. You will return to the DOS prompt after exiting Windows (i.e. Win9x now works like Win 3.1).

### Start small

- Ignore privilege for now. Use ring 0 for all segment descriptors and selectors.
- Don't use LDTs, TSSes, virtual 8086 (V86) mode, or other 'advanced' pmode features until you have mastered the basics.
- Use the Reset button to return to real mode.
- Ignore interrupts/exceptions. Turn off hardware interrupts. If buggy code causes an exception, the computer will either freeze or reset itself (triple fault).
- Set the limit of each segment to its maximum (4 Gig - 1).

### You must understand x86 segmented addressing

Linear address = segment base address + offset
In pmode, however, the segment base address comes from a descriptor, not from the segment register.

Consult one or more of the many pmode tutorials on the Internet.

### Use video memory for debugging

After each crucial step in the process of switching to pmode, poke a character into video memory, so you can see (literally) how far the code gets. This is demonstrated in the quick-start code, below.

## Virtual 8086 (V86) mode

V86 mode is a hybrid of real mode and protected mode. It lets you run real-mode code at ring 3 (user privilege), with paging, and memory and I/O protection as in true protected mode.

A program that manages transitions between V86 mode and protected mode is called a virtual-8086 mode monitor (VMM). The transitions may proceed in both directions:

VMM type | Application | Kernel | Example
--- | --- | --- | ---
DOS extender | 32-bit | 16-bit | Windows 3.x, Windows 9x
Virtual DOS machine (VDM) | 16-bit | 32-bit | DOSEMU (Linux), NTVDM (Windows NT)

## Pmode code snippets

Enable 'unreal' mode. This is identical with real mode, with the exception that 32-bit addresses greater than 0xFFFF are allowed (they don't cause exception 0Dh, as they do in true real mode). Unreal mode is interesting, but not as useful as you might think.

'Quick-start' code. The register and memory usage of this code is shown here. This code now comes with a bootloader, so you can build it under Linux or Windows NT and boot it from a floppy disk.

A virtual-8086 mode monitor.

## Links

- Intel documentation from x86.org: http://www.x86.org/intel.doc/inteldocs.htm
- The many pages of Alexei Frounze: http://alexfru.chat.ru, http://alexfru.narod.ru, http://welcome.to/pmode,
- Pmode-l ('pmode-ell', not 'pmode-one') mailing list: send mail to `pmode-l-request@fys.ruu.nl` with no subject and this body:

      subscribe   pmode-l   your_email_address_here

- Pmode-l FAQ: http://phantom.urbis.net.il/bphantom/pmode-l_FAQ.html
- http://www.nondot.org/sabre/os/articles/ProtectedMode/
- V86 mode monitors from...
  - Alexei Frounze: http://alexfru.chat.ru/epm.html#v86monitor
  - David Lindauer: http://members.tripod.com/~ladsoft/pmode/vm386.zip
  - MOSS DOS extender: http://www.cs.utah.edu/flux/moss/
  - Jim Brooks: http://x86.ddj.com/ftp/dloads/v86mon.zip
  - John Fine: http://my.execpc.com/~geezer/johnfine/v86call3.zip
- Chris Giese's Triple Fault Club; tutorial and demo code: http://my.execpc.com/~geezer/os

## TO DO

## REPORT BUGS OR ERRORS IN THIS DOCUMENT