Journey To The Protected Land

From OSDev Wiki

Jump to: navigation, search

Contents

Protected....Wha?

Protected mode is essentially a step up from 16-bit, or real, mode. Now, why in the world would you want something more than real mode? Well, the answer is simple and many. I have listed two big ones here. In real mode, you have limited access to any substantial amount of RAM (ie. For all practical purposes.) Moreover, you may not use paging while in real mode which is, as you will find out, a valuable resource. Yet, you are probably wondering: "How exactly, do I get to protected mode?".

The Transformation

The transformation from real mode to protected mode can be as easy or difficult as you choose it to be. Basically, there are really only four things you must do to get into this favored place. They are:

  • Disable Interrupts with CLI.
  • Load a GDT. (Global Descriptor Table)
  • Set the least significant bit of cr0.
  • Jump to your new 32-bit protected mode code.

Now, after doing these four very easy things you are in protected mode. However, there are a few more things you can do once in protected mode. Such as setup your segments and stack, move your kernel to its desired location, or enable paging.

Code!?

You want code don't you? I can sense it. This is some very simple code to get to protected mode.

Disable all irqs before we go to pmode...

cli
lgdt [gdtr]
mov eax, cr0
or eax, 1
mov cr0,eax
jmp 08h:main_32

Happy? I thought so.

The Classics

This is a collection of published articles that are covering OS development. The complete list can be looked up at http://www.dtweed.com/circuitcellar/xnisleye.htm

This page aims to point to those that seems interresting nowadays. If you've read some, you're welcome to post a small resume of what you think about it after the link.

Code samples are given in TASM most of the time you can find them with http://www.circuitcellar.com/pastissues/articles/Nisley/nisley-$(ID).pdf, valids IDs ranging from 48 to 63, afaik ...

Smashing Bugs in Gates tells about dealing with calls & jumps, and how the processor protects about evil code. Also has bits about interrupt table setup.

Booting into Protected Mode details the PC boot process, things like BPB, sector loading, etc.

Entering Virtual-86 Mode

Looking at the Virtual-86 Monitor

it looks like the articles cannot be found online anymore. e-mail to the webmaster is pending ... meanwhile, here's a mirror of a selection of articles i host. just add nisley-$(ID).pdf to get them, e.g. nisley-62.pdf - PypeClicker

Personal tools