PC Architecture

If you’re not a Computer Sciences student or alumni, then probably nobody has told you this – PC architecture is all about the CPU and RAM, and CPU knows only a little about it’s surroundings (devices, drives, slots and cards). There I said it – if you go bare metal, you only have access to CPU and it’s abilities to:

  • Do bit-wise operations.
  • Do arithmetic operations.
  • Do memory (i.e. RAM and registers) operations.
  • Do some IO operations via two ways:
    • some memory mapped hardware addresses that you can’t take for granted at first – for some of them you’ll have to scan through RAM, for some there are a defined address specified in specifications;
    • legacy IO instructions – where you still need to know what device connected to which port.
  • Process hardware and software interrupts – again, just an interrupt number and some info in specs about possible values passed on. For hardware interrupts there’s another chip you’ll have to understand – the Programmable Interrupt Controller (or PIC, or APIC for Advanced PIC).

And that’s it. From this point on you’ll need to figure out how to read data from your storage, how to write something on the display and how to read something from your keyboard and mouse. But don’t be worried – I’ll try to guide you through as less painful as possible.

Boot process in a nutshell

As I said in the introductory – we’re going to go the good old BIOS way, as it’s less abstract, yet also less standardized.

  1. When the PC powers up there is this Basic Input Output System that’s loaded from a special flash chip. This BIOS is built with the knowledge of the motherboard configuration by it’s manufacturer. BIOS will detect the amount of RAM, it will detect and initialize other hardware.
  2. When BIOS is done with hardware, it will read the first sector (sector at the address 0 and in size of 512 bytes) from user’s selected boot device to RAM starting at location 0x7C00 and pass it on to CPU. That is called Master Boot Record (MBR). From this point BIOS has done it’s job and control is yours.
  3. This means that these first 512 bytes (actually it’s less – around 440 up to 510 bytes, depending on weather you’ll use partition table) are your starting point. All you can do here is to read more data from the boot device (or other) and pass on to executing it. This process is called bootstrapping.

Some will tell you there’s more to it than that, but that’s actually it – the rest is up to you. Weather you’re going to use standard paradigms, implement standard partition tables, read Volume Boot Records (VBR) or not. You could implement your own storage layout, completely ignoring the standard partition tables (that are only necessary for Linux or Windows systems) or GUID Partition Table layout (used by most of the modern OSes), thus rendering your system incapable of being multi-bootable.

What you could and probably should do is:

  1. While being in Real Mode (this is where BIOS leaves you), using BIOS interrupts (kind of like OS API functions), read your second stage bootloader from the boot partition (from the location of your own choice).
  2. Pass on the execution to the second stage bootloader, where you should prepare the basic execution environment:
    1. enter protected mode
    2. build a page table
    3. enter long mode
    4. prepare interrupt handlers
    5. enable PIC
    6. write a simple ATA driver to continiue reading from the boot disk

Join the Conversation


  1. If, nevertheless, two of the cards acquired precisely the
    same importance, then it’s the following highest card.

Leave a comment

Your email address will not be published.