Protected Mode
Protected mode is the mode in which most modern operating systems run their code. When the computer boots, it first enters real mode; the operating system is responsible for switching into protected mode.
The 80286 processor did have a 16-bit protected mode. It is of historic interest only. We will concentrate on the 32-bit protected mode, found on the 80386 processors and all its successors.
There are new registers in protected mode:
All the general application registers (AX, BX, CX, DX, SI, DI, SP and BP) are extended to a total of 32 bits. To denote that you intend the 32-bit register instead of the low 16-bit part, add an E before the name of the register..
EAX, EBX, ECX, EDX, ESI, EDI, ESP and EBP
The segment registers remain 16 bits wide and do not change names.
CS, DS, ES, FS, GS and SS
The segment registers do not work like they did in real mode. Instead, they are used to point out an selector in a table pointed to by the GDTR- or LDTR-register.
The FLAGS- and IP-registers are also extended to 32 bits.
EIP, EFLAGS
There are also new registers. They are useful only to system programmers.
CR0, CR2, CR3, CR4, GDTR, LDTR, IDTR, TR..
They are used by the operating system and cannot be accessed by ordinary user programs.
There are also some other registers, like the test registers, debug registers, MMX, MSR, XMM and others.
How to switch to protected mode:
* load GDTR with the pointer to the GDT-table.
* load IDTR with the pointer to the IDT OR dissable interrupts.
* set the PE-bit in the CR0-register.
* make a far jump to the 32-bit code.
* initialize TR with the selector of a valid TSS.
* optional: load LDTR with the pointer to the LDT-table.
SNAFU (System Normal, All F*cked Up) is an operating system written in x86-assembly. It quite clearly shows how an operating system works at a very basic level. SNAFU is published as Public Domain. http://home.swipnet.se/smaffy/snafu/
Menuet is also an operating system written in pure x86-assembly. It is larger than SNAFU and has almost left the development phase. Menuet OS is distributed under the GNU Public License. http://www.menuetos.org