Operating System Programming

Getting Started

I started out trying to do this all in Windows and Mac OS X. However most tutorials and the required software is all written for linux. (Note while OS X has much similarities with linux the default ld command doesn’t work as in any of the tutorials.) I don’t have the spare hardware around to set up a linux box so I downloaded a VM to install Ubuntu server. For Windows I used microsoft Virutal PC and Mac I used Virtual Box. The VM choice and linux OS is up to you.

I downloaded and installed the following:

  1. Bochs IA-32 Emulator - The docs are here

<ARCHIVED>

This is a page for notes I need on programming an Operating System on the Intel x86. 32bits not 64
RTFM!!!! -> Intel Manuals

I have used grub as a boot loader installed on a usb stick.
Tutorials and useful information can be found at:
OSDev
OSDever
JamesMolly (JM from now)
OSRC

Bran’s Kernel Development Tutorial is also good (JamesMolly is based on it). Its on the OSDever site.

First I want to set up the GDT.

GDT is the global descriptor table used to set up segments in memory. There is a load and store instruction (lgdt, sgdt). The GDT register (GDTR) is 48 bits as seen in 2.4.1 chapter 3A Intel Manual.
Bits 0-15: The table limit
Bits 16-47: The linear base address (This should be aligned on an eight byte boundary).

The base address is the linear address to the first byte of the GDT. The limit is the number of bytes in the GDT. Each entry in the GDT is 8 bytes. The GDT has to have at least one entry, or two if the null entry doesn’t count :P.

So we need to set up a GDT and then load the start and size of the GDT into the GDTR using the lgdt command. Easy-ish (it only took me days/weeks to understand this).

To set up a GDT we need to create segment descriptors (3.4.5 in chapter 3A Intel Manual).

  • Segment Limit: I think this is just the end byte of the segment in linear address. It looks like JM+Bran just used 0xFFFFFFFF for all of them.
  • Base address: I guess the start byte, JM+Bran used 0.
  • Pge 97 get back to