In my Rise of the Triad video,
We touched on the fact that the Wolfenstein 3D engine required rewriting to work in DOS protected mode,
rather than real mode. This allows programs to make use of any extended memory the system has
installed, but what is protected mode? Well, that's what we're going to find out in Byte-Size.
Not content with the 8088 and 8086, Intel began in
1978 to develop processor chips with power rivaling that of minicomputers and mainframes.
One thing micros lacks, but more powerful computers had, was larger memory address spaces.
So, from the 80286's introduction in 1981 onward, Intel chips could address megabytes and megabytes.
A 286 can address 16 megabytes of RAM. A 386 or 486 can talk to four gigabytes.
The term for normal RAM above 1 megabyte is extended memory. So why does this memory above
1024 kilobytes get a completely new name?
Largely because the 286 and later chips have split personalities.
They can either address memory beyond 1024k, or run DOS programs. In order to use memory above
1024k, the 286 and later chips must shift to a new processor mode called protected mode.
Protected mode has lots of virtues,
but one big flaw. When a chip is in protected mode it's incompatible with an older 8088 or 8086 chip.
You see, most early CPUs used in microcomputers were more glorified calculators than computers.
The 4004, 8008, 8080, 8086, et cetera. Even the rarer 80186 falls into this category.
Now, Intel intended that the 286 should have more mainframe-like powers, and in particular
should be able to talk some more memory and protect that memory.
Now, nowadays and back then, large mainframe computers could run multiple programs at the same time.
Basically, the memory space of the computer gets parceled out to the applications.
So, your operating system might designate 120k to a database, 105k to a spreadsheet,
and not allow them to have any more. These programs are all expected to stay in their places.
But what about the odd program that accidentally strayes from its area? If a database
stretches a bit and overrides the spreadsheet's area, what do you do?
Or worse yet, suppose your computer was acting on a server or a local area network and one program,
possibly a virus, tries to pick into the memory of the LAN server program itself. ie. Where all the passwords
are stored. So, this is why memory protection is a good idea, and why mainframes and modern operating
systems had memory protection. The mainframe CPU has hardware built into it that keeps track of what
application gets to use what memory. It's as if the CPU can put a force field around each program.
As long as the program stays within its force field, it's okay.
But if it tries to reach out of that area, it is stopped by the force field and the CPU's security system is alerted
that a protection violation was attempted. The operating system can then terminate the application
with extreme prejudice.
This memory protection is essential for any multitasking OS.
But back in 1981, none of the Intel CPUs had this built-in protection.
But the 286 and later chips had the feature. These chips can address memory beyond 1024k,
but only while in protected mode; they must always request memory blocks from the operating system
before doing anything else. Now in DOS, the whole notion of first asking of the operating system for
permission before using memory is totally unknown.
Programs written for DOS pretty much assumed that they're the only program in the system,
so they just take whatever they want without asking for it. So for the 286 to have memory protection,
it would not only have to be a different chip, it would have to be an incompatible chip. Incompatible
with DOS and DOS programs in particular.
Now, designing and releasing a new chip that was totally incompatible with any previous Intel offerings
would have been suicidal. So, Intel gave the 286 and subsequent chips split personalities.
When they boot up, they act just like the 8088 except faster. They can talk to 1024k of memory and no more.
This 8088 emulation mode is called real mode. With a few instructions, it can shift over
to protected mode and talk to lots of memory beyond the 1 megabyte barrier.
But again, once the 286 or later chip is in this mode, it can't run programs designed for real mode DOS programs.
Now to make use of this, DOS programs normally made use of what was called a
DOS extender like DOS4GW, and this allowed them to make use of the extra memory.
Basically a DOS extender is like a tiny operating system that unlocks the door to this memory
and provides the tools that programmers can exploit to use that memory.
Now, back to our Rise of the Triad example. That particular game couldn't run on a 286, it needed a 386.
Software could, of course enforce its own limitations, knowing that a 286 would be unable to run advanced engines.
But the 386 actually incorporated a vastly improved protected mode
including a 32-bit physical and virtual address space, the ability to return to real mode without resetting the
machine, a virtual 8086 mode, and paging, allowing operating systems like Windows to make use of a swap file.
This version of protected mode is by far the most familiar, and it's the version in use with Rise of the Triad.
The 286 protected mode was more of a test run if you like, and not widely used.
By the 386 arrived, programs were advancing at such a rate however, it was pretty much essential.