CS 3210 Fall 2006 - PowerPoint PPT Presentation

1 / 15
About This Presentation
Title:

CS 3210 Fall 2006

Description:

Jump to C-code for high-level init (init:start_kernel ... Renaissance. Modern Age. CS 3210 Operating System Design ... Renaissance: startup_32() Two different ... – PowerPoint PPT presentation

Number of Views:40
Avg rating:3.0/5.0
Slides: 16
Provided by: Phillip4
Category:
Tags: fall

less

Transcript and Presenter's Notes

Title: CS 3210 Fall 2006


1
CS 3210Fall 2006
  • Booting
  • and Kernel Initialization

2
Overview
  • Loading and initializing the kernel is a critical
    but poorly understood procedure
  • Tedious and highly architecture dependent
  • Receives little coverage in traditional OS texts
  • Something a little magical about it ?
  • Two logical phases
  • Booting loading and jumping to kernel code
  • Kernel init data structure setup subsystem
    init creation of first (user) process (init)

3
System Lifecycle
  • Power-on, self test (POST)
  • Transfer to firmware (e.g. BIOS, EFI, OF)
  • Firmware starts load of bootloader
  • Transfer to bootloader (e.g. LILO, GRUB)
  • Bootloader loads more of itself (!) then kernel
  • Transfer to kernel (assembly code) for low-level
    init
  • Jump to C-code for high-level init
    (initstart_kernel())
  • Subsystem initialization, thread/process creation
  • Transfer to user-level init process for OS init

4
Terminology
  • Loader program that loads another program and
    then transfers control to that program
  • Treats program as both data (load) and code
    (transfer)
  • Firmware code stored in persistent memory
  • Many technologies PROM, Flash, etc.
  • Examples BIOS (old Intel), EFI (new Intel), OF
    (PowerPC)
  • System automatically transfers to firmware after
    POST
  • Bootloader, bootstrap program that loads the
    first program
  • Image pulling yourself up by your own bootstrap
    (something from nothing)
  • First program might be a more advanced
    bootloader (!)
  • Boot manager sophisticated loader allowing
    configuration, interactive selection of a kernel,
    loading of other bootloaders (chain loaders)
  • Boot block, MBR (master boot record Intel)
  • First sector of disk containing boot code
    loadable by firmware

5
UNIX Loader?
  • Question How are programs (e.g. cat) loaded
    under UNIX?
  • Answer 1 The shell loads them
  • In the old days, there was an actual loader
  • Now, the shell creates a new process by
  • Fork() create a copy of shell process
  • Exec() re-build address space to contain cat
    code/data
  • Answer 2 The exec() system call loads them
  • Actually, nowadays, exec() just defines the
    address space and the code bits are brought into
    memory from the disk, page by page, when they are
    first touched (demand paging) !
  • Answer 3 Demand paging loads them

6
Intel Booting
  • Old (BIOS-based) Intel systems have a somewhat
    archaic way of bootstrapping
  • BIOS can load exactly one sector (512 bytes)
  • MBR contains 4 element partition table code
  • 400 bytes or so isnt enough code to load kernel!
  • MBR contains enough code (stage 1) to load a
    larger piece of code (stage 2)
  • Stage 2 code is usually the real bootloader that
    can then select and load a kernel
  • Its possible for stage 2 code to load another
    bootloader! (e.g. Windows bootloader)

7
Bootloading Complications
  • We need some hardware support to boot
  • Must be able to access disk, console, memory,
    etc. at least in minimal ways
  • Where does the kernel image actually live?
  • Well, its usually a (compressed) file in a
    filesystem on a disk (zImage, vmlinuz, etc.)
  • Uh oh bootloader needs to understand the file
    system

8
Filesystem Support
  • There are two styles of bootloaders
  • Those that understand filesystems (e.g. GRUB)
  • And those that dont (e.g. LILO)
  • Bootloaders like LILO must be given a list of
    disk blocks (block list) that contain the kernel
    to be loaded a new block list must be poked
    into the bootloader every time you re-compile the
    kernel
  • /sbin/lilo is a map installer
  • Bootloaders like GRUB must contain minimal
    implementations of the filesystem containing the
    kernel image
  • GRUB can load filesystem implementations as Stage
    1.5

9
Linux Startup (Intel)
  • See Bovet Cesati Appendix A ?
  • Prehistoric Age
  • Ancient Age
  • Middle Ages
  • Renaissance
  • Modern Age

10
Prehistoric Age BIOS
  • Operates in Real Mode (no virtual memory)
  • Linux uses BIOS for boot but re-implements all
    BIOS functions once the kernel is up
  • POST
  • ACPI (Advanced Configuration and Power Interface)
    allows device-dependent initialization
  • PCI device discovery, initialization
  • Searches for valid boot block from boot device
    sequence specified in BIOS
  • Copies boot block to 0x7c00 and transfers to code
    portion (after partition table)

11
Ancient Age Bootloader
  • Stage 1 code sets up real-mode stack and loads
    stage 2 (multiple blocks) at 0x96c00 and jumps
    there
  • Bootloader provides a command shell to allow user
    to select kernel, specify parameters, etc.
  • Loads first block of kernel at 0x90000 plus code
    for startup() function (assembly) at 0x90200
  • Loads kernel proper (compressed) at 0x1000
  • Jumps to setup()

12
Middle Ages setup()
  • Re-initializes fundamental devices (without BIOS)
    and builds some tables describing memory, disk,
    etc.
  • Keyboard, video, power management
  • Sets up interrupt handling infrastructure
  • Switches from Real Mode to Protected Mode
  • Enables virtual memory, kernel/user mode, etc.
  • Jumps to startup_32()

13
Renaissance startup_32()
  • Two different startup_32() functions (ack!)
  • arch/i386/boot/compressed/head.S
  • arch/i386/kernel/head.S
  • First function
  • Initializes segmentation, zeros data memory
  • Calls decompress_kernel() (first portion of
    kernel that is not compressed its basically a
    self-extracting archive) decompressed kernel is
    stored at 0x100000
  • Jumps to 0x100000
  • Second function
  • Sets up paging, the kernel stack for process 0
  • Identifies processor
  • Jumps to first C code function start_kernel()

14
Modern Age start_kernel()
  • Initializes various kernel subsystems
  • Ordering is very important
  • On an SMP system, one CPU does initialization,
    others wait (corralled)
  • At this point there is a single thread of control
    in the kernel
  • It eventually starts a new kernel thread which
    will become the first process (/sbin/init pid 1)
  • The initial thread of control (pid 0) becomes the
    idle process

15
Highlights from start_kernel()
  • asmlinkage
  • __init
  • lock_kernel()
  • printks
  • Kernel parameters (parse_args())
  • Kernel profiling
  • Initial ramdisk (initrd)
  • calibrate_delay() BogoMIPS!
  • rest_init()
  • kernel_thread(init, NULL, CLONE_FS
    CLONE_SIGHAND)
  • Kernel init() thread vs. /sbin/init
  • cpu_idle()
Write a Comment
User Comments (0)
About PowerShow.com