1 Bootloading

Week 1: August 29 - Sept 4, 2022

This unit is all about understanding how an OS comes to life. When you turn on your machine, how does the kernel, which resides on some stable storage device (e.g. a disk), is relocated onto main memory and then its execution begins.

But, first we take an aside and try to understand how any program gets loaded from a file on disk onto memory and its execution begins. To do so, we need to understand what does an executable file actually look like and how the kernel loader lays it out onto memory. We take a unix/linux centric perspective and examine the ELF file format. We understand the steps involved in turning some program from its high-level programming language code into a binary executable: compiling, assembling, linking and finally loading. Note that loaders are part of the kernel or OS, while compilers, assemblers and linkers are user-space code that do not run with kernel priveleges. Why?

Now from that aside, we step back and notice that the kernel itself is an executable file that resides on disk. The hardware has non-volatile firmware, BIOS, that locates the boot block on disk. This is a simple bootloader program that fits nicely on one block, which starts an often multi-stage process of locating the kernel, loading it onto memory and starting it. Lab 1 is about writing a simple bootloader!

1.1 A video summary

The Appendix Compilation worksheet will walk you through the steps of the in-class demo.

Learning Objectives

The Compilation Process

  • Describe what the pre-processor, compiler, assembler and linker do?

ELFs

  • What are the typical sections of an ELF program
  • Why does it make sense to divide executables into sections?
  • Can modern hardware architectures provide extra features to the different sections?
  • Why does it make sense to split the data section into an initialized and uninitialized section?
  • What is the purpose of the symbol table
  • What is a relocation?

The Kernel Loader

  • What does the kernel loader do?
  • What is static linking?
  • What is dynamic linking?
  • What are the pros/cons of static/dynamic linking?
  • What does the linker link to during the compilation of an executable that uses a dynamic library? What happens during execution?
  • How can you make a shared /dynamic library?

Boot Loading

  • Why does loading often occur in a multi-stage process?
  • Where does the boot loader reside?
  • Where does the boot strap routine reside? What is the difference between the bootstrap routine and the bootloader?
  • What do we find on the boot block?