Lecture: booting
Preparation
Class structure
- goals
- understand low-level systems
- learn to work with systems software: reading code/manuals, debugging, etc.
- two OSes
- xv6 (exercises): a Unix-style OS on x86
- JOS (labs): an exokernel-style OS on x86
- lectures: basic/more modern concepts
- sections: help you with exercises/labs
- final exam: open book/notes/laptop; no Internet or other communication
Overview
- 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
- in this class we use QEMU to emulate the PC
- concepts apply to non-x86 architectures
- how does printing “hello” work on this PC?
- example: a tiny hello “kernel” (tar and source code)
- run
make qemu
- VGA text buffer at physical memory address
0xb8000
- one byte for character, one byte for attribute
- memory-mapped I/O:
0xb8000
+ (row * 80 + column) * 2;
- talk to devices through memory address space
- will see more examples in later labs
- perhaps the lowest-level “hello world” you have seen so far
- what if we have two applications trying to print?
- what’s an OS / why do we need an OS
- a reusable library
- a set of programming abstractions
- a mediator between applications/hardware
- a brief history
The booting process
- what happens after power on?
- high-level: firmware → bootloader → OS kernel
- what’re the “handover protocols” / machine state after each handover
- example: BIOS-bootloader handover
- BIOS firmware: a program stored in non-volatile memory
- detect & initialize hardware
- start in real mode: 16-bit registers, 20-bit (1 MB) addresses
- load the master boot record (the first sector, 512 bytes) to
0x7c00
& jump there
- example: bootloader-kernel handover via Multiboot
- the xv6 bootloader:
bootasm.S
and bootmain.c
- 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 in
entry.S
- why do we need the bootloader
- hard to fit the entire OS in 512 bytes
- more options for users: boot from cdrom, network, usb, etc.
- can have multiple stages
- BIOS-booting pros & cons
- simple but restrictive
- arch-specific: x86 real to protected (to long) mode
- drivers?
- Unified Extensible Firmware Interface (UEFI)
- the first xv6 exercise & JOS lab 1
- start now!
- tomorrow’s sections
- review x86 calling convention from CSE 351