Lecture 0: Booting
Preparation
Don’t be dismayed by unfamiliar technical jargon;
you’ll get a better idea once you start the labs.
Class structure
- Goals
- understand OS concepts and apply to labs
- learn to work with systems software: reading code/manuals, debugging, etc.
- Lectures: concepts, reading OS code, recent topics, lab review
- Sections: help you with labs
- Labs: JOS, an exokernel-style OS on x86
- Final exam: open book, open notes, open laptop; no Internet or other communication
- Overload form
See the 451 class website
for details.
Overview
- What’s an OS?
- a library
- a set of programming abstractions
- a mediator between applications, and between applications and hardware
- The PC hardware
- example: IBM T42
- abstract model:
CPU, Memory, and I/O
- CPU interprets instructions: IP (Instruction Pointer) to memory
- memory stores instructions and data
- I/O to external world: memory-mapped I/O & port I/O
- for labs, we use QEMU to emulate the PC
- concepts apply to non-x86 architectures as well: JOS/arm demo (Raspberry Pi)
The booting process
- What happens after power on?
- high-level: firmware → bootloader → OS kernel
- JOS: BIOS →
boot/*
→ kern/*
- why three steps
- what’re the “handover protocols”
- BIOS: a program stored in non-volatile memory
- real mode: 16-bit registers, 20-bit (1 MB) addresses
- detect & initialize hardware
- Lab 1: E820 memory map
- later: ACPI tables for multiprocessor, etc.
- load the master boot record (the first sector, 512 bytes) to 0x7c00
- BIOS-bootloader handover: jump to that address
- Bootloader: why do we need it?
- hard to fit the entire OS in 512 bytes
- more options for users: boot from cdrom, network, usb, etc.
- can have multiple stages
- Example: JOS bootloader
boot/boot.s
and boot/main.c
- basic setup
- get the E820 memory map
- switch to protected mode: 32-bit registers/addresses
- load the kernel (in ELF) from hard drive
- prepare machine state & handover: jump to the entry point
- the JOS bootloader-kernel handover protocol is called Multiboot
eax
: magic number 0x1BADB002
ebx
: set to a struct multiboot_info
(for the E820 map)
- BIOS-booting pros & cons
- simple but restrictive
- arch-specific: x86 real to protected (to long) mode
- drivers?
- Unified Extensible Firmware Interface (UEFI)
- More examples
- Summary
- handover protocols: firmware-bootloader & bootloader-kernel
- understand the machine state after each handover
The JOS kernel
- Lab 1:
kern/entry.S
and kern/init.c
- set up paging & jump to C function
i386_init()
- set up console: we can finally print out something!
- print CPU and memory information
- drop into the kernel monitor, for now
- How does JOS print to screen?
- read/write memory:
crt_buf
at KERNBASE + 0xB8000
- one byte for character, one byte for attribute
- memory-mapped I/O
- talk to devices through memory address space
- will see more examples in later labs
- alternative: port I/O (not our focus)
- through special instructions
in
and out
- I/O address space is separate from memory address space
- Lab 1
- start now!
- tomorrow’s sections
- review x86 calling convention from CSE 351