[FrontPage] [TitleIndex] [WordIndex

Note: You are looking at a static copy of the former PineWiki site, used for class notes by James Aspnes from 2003 to 2012. Many mathematical formulas are broken, and there are likely to be other bugs as well. These will most likely not be fixed. You may be able to find more up-to-date versions of some of these notes at http://www.cs.yale.edu/homes/aspnes/#classes.

Description of how a typical OS is organized, with emphasis on x86.

1. Hardware

2. CPU operation

Normal operation
  • Fetch next instruction based on IP register
  • Do what it says
  • Device signals some event
  • Interrupt controller kicks CPU
  • CPU calls interrupt handler
    • Disables further interrupts
    • Pushes current state onto the stack
    • (In protected mode) switches to ring 0
    • Jumps to interrupt handler at standard location (new CS:IP stored at physical address 0x04*(interrupt number) for x86 real mode)

    • Interrupt handler does its thing
    • Returns (using iret on x86)

      • Pops state and re-enables interrupts
  • Like interrupts, except something bad happened (division by 0, overflow, segmentation faults, etc.)
  • Mechanism is exactly the same on x86 except for interrupt number
System calls
  • Simulate interrupt using int instruction (old x86 method) or sysenter (newer x86's).

  • Typically just one trap number is used for all system calls (0x2e in Windows, 0x80 in Linux).
    • Further dispatch in the kernel through handler table indexed by syscall number (typically passed in AX register).
  • Details of system call are stored in registers.
  • Return value(s) come back in registers.
  • Note that system calls are expected to change register state, unlike interrupts and traps which are expected to be invisible to the running program.
BIOS calls
  • Like system calls, only jumping into ROM supplied with your motherboard.
    • Standard locations and interface dating back to 1981 IBM PC.
    • See BIOS_Interrupt_Calls for a sketchy list.

    • INT 13 for disk access (int $13 in AT&T syntax)

  • Mostly used in real mode by DOS.
  • Modern OSs bypass BIOS for most operations.
    • Except power management and other whizzy system control features that are closely tied to the motherboard hardware.

3. I/O


Stands for Basic Input/Output System. It's what comes built-in to your motherboard and what is called first at boot time. See BootProcess. It may also provide a primitive core OS that manages simple devices (although most modern OSs bypass this interface).

5. Memory

OS memory layout is pretty much the same as in a process. We have executable code (the text segment), preinitialized data (the data segment), dynamically-allocated data (the heap), and a stack.

In x86 real mode these segments are typically pointed to by segment registers, e.g. CS for the code segment, DS for the data segment, SS for the stack segment. See IntelAssemblyProgramming.

Certain physical addresses are reserved in IBM PC architecture. This puts constraints on where the OS can operate in real mode.

A typical setup is:




Buffers and system stuff


Kernel memory


Kernel stack


System ROM


Video RAM


BIOS entry point

Important point: Physical addresses above FFFFF are inaccessible in real mode. Physical addresses above A0000 (640K) are here-there-be-monsters territory, not usable by the OS.


2014-06-17 11:58