Real Mode is the adressing mode in which the CPU behaves like beeing a 8086.
For compatibility reasons, all x86 CPUs start in this mode.
The 8086 has 20 adress lines, which means that it can access a maximum of 2^20 = 1048576 = 1024 K = 1MB bytes of RAM. For adressing it, the 8086 has two kinds of registers, both 16 bit wide: The one are called segment registers. They point to an adress somewhere in the memory which is a multiple of 16. The other registers are called index or offset registers. They point to an adress between 0 and 2^16=65536 RELATIVE to an adress residing in a segment register.
Privilege levels ( PL )(they are often called rings, but I
think this terminology is terribly stupid) have been implemented for
ensuring that user programmes cannot destroy the operating system or crash the
computer. Privilege Level 0 means that the programme can execute all CPU
instructions. The operating system has this PL. Other programmes have higher
PLs, normal user programmes are typically assigned PL3. The lower the PL is, the
more the programme is allowed to do. Programmes running in low PLs are
considered as being secure and safe while programmes with high PLs may be
Programmes are only allowed to call functions which have the same or lower PL, this prevents system programmes from using potentially unsafe code. It is also possible to prohibit port accesses (printer, keyboard, harddisk, soundcard,...) for several privilege levels.
If a programme does something it is not allowed to do, the operating system will be called by the CPU for solving the problem (it has to carry out or deny the port access, kill the programme or present an error message etc.).
In Real Mode, the memory was adressed by a segment register containing a
start adress and an index register which points to the adress relatively to the
adress contained in the segment register.
In Protected Mode index registers are used in the same way, but the role of the segment register has completely changed: It does no longer point to a physical adress. Instead it is used as an index, too - an index into a table which has been created somewhere in the RAM by the OS. This table contains the descriptions of the memory areas being accessed by the programmes running. One of these descriptions - they are called descriptors and the table is therefore called descriptor table- contains of the following elements:
The main difference between 286 and 386 in Protected Mode is that memory blocks can be bigger than on the 286 and that the starting address can be bigger than 16MB. Doing so, using a 386 is quite the same as using a 286.
Even today, more than a decade since the introduction of the 386, computers use only a small percentage of the 4 GB of RAM which can be used together with a 386. Paging on the 286 was easy, every computer had enough RAM to load and store a complete logical memory block into physical RAM. But the 386 allows these blocks to be up to 4GB large - more than most systems have. The problem was solved by including a separate paging unit into the 386.
This new processor extension operates completely separated from the normal
Protected Mode memory addressing unit. The 4GB adress space is divided into
small chunks which can be moved around inside the RAM or they can be removed
from RAM and stored onto the harddisk freeing RAM for other
Because it has nothing to do with the selector-offset addressing even programmes creating or changing their own descriptors will not be able to recognize if paging is active or not. Memory access is now a three-layer thing:
Although Protected Mode is a powerful thing, Real Mode applications were
still famous. Because running Real Mode applications in Protected Mode was very
problematic to realize, the V86 Mode was included into the 386.
This mode allows trapping specific I/O ports for emulating them in software and code running in V86 uses the same addressing method like in Real Mode. This allows a Real Mode emulation within protected mode for one or more programmes running at the same time.
The only difference to pure Real Mode is that these programmes are only allowed to use the instructions available in Privilege Level 3. The simulated Real Mode memory can be mapped everywhere inside the Protected Mode address space, including memory swapping. All accesses to the hardware interfering with other applications have to be handled by the OS.
Multitasking is executing several pieces of code simultaneously. As x86 CPUs
can only execute one programme at a certain time they have to switch between all
programmes running so fast that it looks like they are running
A lot of help by the OS is needed for multitasking, also depending on the kind and complexity of the task switching implemented. There are two different types of multitasking: Cooperative multitasking is realized in the way that a programm is called, it executes its part of code and then it gives the control back to the OS for the next programme. The problem is that this realization can lock up easily even if only one programme is buggy.
The other implementation uses frequently occuring events like the system timer ticks for switching between the programmes. This is much safer than the other version. However, the programmes are interrupted asynchronously. So every switch needs a lot of organization overhead to backup and restore the complete state of the processor.
Many people think multitasking needs a 286 or higher. In fact, it may also be possible to do multitasking on an 8086. This is more theoretical, not only due to CPU speed and memory limits, but mainly because you need the Protected Mode for preventing programmes from disturbing other programmes or the OS. And the 286 and especially the 386 have a lot of goodies making the switches faster and easier.