Title: PC bootup
1PC bootup
Presented by Rahul Garg (2003CS10183) Rajat
Sahni (2003CS10184) Varun Gulshan(2003CS10191)
2From power on to Kernel load
- PC firmware or BIOS.
- bootSect.S / Bootloader.
- Boot loader to kernel.
3Memory Map at Power up
FREE SPACE
0x100000
MAPPED TO ROM
0xA0000
FREE SPACE
4ROM shadowing
- The address space occupied by BIOS Roms is not
available as useful RAM. - BIOS can make use of this RAM to shadow its ROM.
- Write protects this shadowed RAM, disables ROM.
5Start up Sequence
- CSIP 0xf000fff0.
- Starts in real mode.
- 16 bit mode.
- IP 16 bit offset
- CS Segment offset in 16 byte units.
- i.e PC 16CSIP
- Max 1MB of address space.
- A20 pain from the past.
6Start up Sequence
- POST(Power on self test)
- Looks for video card and executes its BIOS.
- Looks for other option ROMS e.g IDE disk.
- Does more system inventory e.g COM ports, setting
hard disk params. - Plug and play support.
- Sets up IDT and the interrupt service routines.
7BIOS contd
- Looks for bootable media.
- Loads Boot sector(512 bytes) of the media at
0x7c00 . - Jumps to CSIP 00007c00 with DLdrive id of
bootable drive. - BIOS data area from 0x0000 to 0x7c00. (Contains
IDT,ISRs and data).
8BIOS system calls
- BIOS provides low level I/O routines through
interrupts. - Main services are
- INT 15h Get memory map.
- INT 13h Disk I/O interrupts.
- INT 19h Bootstrap loader.
9Memory Map at this stage
0x00100000 (1MB)
BIOS ROM VGA
0xA0000 (640KB)
FREE SPACE
BOOT SECTOR
0x7C00
BIOS DATA
0x0000
10Structure of MBR
- MBR 512 bytes
- 0-62 bytes BIOS Parameter Block (BPB)
- 63-445 bytes Bootsect.S
- 446-510 bytes Partition table
- 511-512 bytes Boot signature 0xaa55
11Flow Diagram
BIOS
Booting with bootloader
Stage 1
Bootsect.S
Stage 2
Setup.S
Part of Kernel image
Head.S
Jumps to init
12Role of Bootsect.S
- Moves itself to 0x90000
- Get disk parameters (passed by BIOS) and sets up
stack - Loads setup.S right after itself (0x90200)
- Loads compressed kernel image at 0x100000 (1 MB)
- Jumps to setup.S
-
13How kernel starts?
- Control starts in setup.S in real mode
- Copies system data (Memory maps, drive
information, hardware support, APM support) into
appropriate memory locations through BIOS calls - Switches to protected mode
- Jumps to head.S at 0x100000 (1 MB)
14How head.S calls init?
- Gunzips kernel image
- Enables paging, check CPU type.
- Get kernel params from memory
- Start_kernel() finally which calls init !
15Memory Map during booting procedure
Uncompressed Kernel image
Compressed kernel image
Head.S
1 MB
setup.S
Bootsect.S
0x90000
Bootsect.S
0x7c00
Bios Data
16Booting linux kernel using bootloader
- Bootloader resides in the MBR instead of
bootsect.s - Arranges memory layout same as bootsect.S (in
case of linux kernel) - Loads kernel from filesystem
- Pass appropiate parameters (e.g. ramdisk_image,
cmd_line_ptr) to the kernel - Jumps to setup.S (with state same as achieved via
bootsect.S)
17Biblical version Grub
- In the beginning, there was GRUB
- And GRUB loaded the kernel
- And kernel begat init
- And init begat rc
- And rc begat network and httpd and getty, And
getty begat login, and login begat shell and then
there was light..
18GRUB
- GRUB multistage bootloader due to large size
- Stage 1 (Loaded from MBR)
- Stage 1.5 (Optional, gets stage 2 from file
system) - Stage 2
- BIOS passes the drive ID to bootloader through DL
register. - Stage 1 loads and jumps to start.S of stage 1.5/2
at address 0x8000.
19GRUB stage 2
- Start.S loads stage2 at address 0x8200
- Start.S then jumps to asm.S
- asm.S jumps to the C file stage2.c and also
provides helper functions to get system
information from bios. - Many switches from real mode to protected mode
and back are required to accomplish all this.
20Multiboot
- GRUB can also boot multiboot conforming kernels
(e.g. GNU Mach, oskit) . - Multiboot Specification Interface between
bootloader and kernel image so that any compliant
loader can load any compliant kernel. - Three main aspects
- OS image format
- Machine state
- Boot Information Format
21OS Image format
- Ordinary 32 bit executable, but may be loaded at
non default load address. - Contains multiboot header
- load address
- Entry point
- Parameters requested
- Preferred graphics mode
22Machine State
- Particular values are required to be loaded into
the registers like - Pointer to boot info structure (EBX)
- Other register values
- EAX contains multiboot Magic Value
- Enable A20 Gate
- Set EFLAGS, segment register
- OS image must define the undefined registers
- ESP, GDTR, IDTR
23Boot Information Structure
- Contains the parameters that kernel requested
through the header. - Available Memory and memory map
- Boot Device
- Cmdline Parameters passed to kernel
- Other important info (apparently not so important
that we list them out!)
24Booting A messy procedure !
- Booting in real mode to maintain backward
compatibility. - Frequent switches between real mode and protected
mode - Bootloader code becomes messy and involves a lot
of hackwork - BIOS 25 yrs old
- Solution Extensible Firmware Interface
25EFI Concept
EFI Abstracts out hardware for OS loaders
26EFI Overview
- EFI specification defines a set of APIs and
data structures - EFI device drivers
- EFI diagnostics and system utilities
- EFI shell
- OS loaders
- OS
27Booting in EFI Environment
OS Loader is a special ELF binary which calls
ExitBootServices() which transfers control to
the OS. Elilo is an example of an EFI Compliant
boot loader which can load linux kernel.
28Loading Linux Kernel using ELILO
EFI
- EFI initializes system directly in protected mode
- Kernel loaded using EFI calls
- ExitBootServices() to transfer control to kernel
EFI Boot Mgr
ELILO
Load Kernel
Collect Boot Params
Jump to kernel
Start_kernel
init
29References
- Linux HOWTOs (www.tldp.org)
- Grub documentation and source code
- www.bioscentral.com
- www.linuxjournal.com
- www.kernelthread.com
- www.intel.com/technology/efi
- EFI Specification
30(No Transcript)