PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun...

30
PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Transcript of PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun...

Page 1: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

PC bootup

Presented by:Rahul Garg (2003CS10183)Rajat Sahni (2003CS10184)Varun Gulshan(2003CS10191)

Page 2: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

From power on to Kernel load

PC firmware or BIOS.

bootSect.S / Bootloader.

Boot loader to kernel.

Page 3: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Memory Map at Power up

MAPPED TO ROM

FREE SPACE

FREE SPACE

0xA0000

0x100000

Page 4: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

ROM 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.

Page 5: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Start up Sequence

CS:IP = 0xf000:fff0. Starts in real mode.

16 bit mode. IP = 16 bit offset CS = Segment offset in 16 byte units. i.e PC = 16*CS+IP Max: 1MB of address space. A20 pain from the past.

Page 6: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Start 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.

Page 7: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

BIOS contd…

Looks for bootable media. Loads Boot sector(512 bytes) of the

media at 0x7c00 . Jumps to CS:IP = 0000:7c00 with

DL=drive id of bootable drive.

BIOS data area from 0x0000 to 0x7c00. (Contains IDT,ISR’s and data).

Page 8: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

BIOS 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.

Page 9: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Memory Map at this stage

BIOS DATA

BOOT SECTOR

BIOS ROMVGA

0x0000

0x00100000 (1MB)

0xA0000 (640KB)

0x7C00

FREE SPACE

Page 10: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Structure 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

Page 11: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Flow Diagram

BIOS

Bootsect.S

Stage 1

Stage 2

Setup.S

Head.S

Jumps to init

Booting with bootloader

Part of Kernelimage

Page 12: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Role 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

Page 13: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

How ‘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)

Page 14: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

How head.S calls init?

Gunzips kernel image Enables paging, check CPU type. Get kernel params from memory Start_kernel() finally which calls init !

Page 15: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Memory Map during booting procedure

Bios Data

Bootsect.S0x7c00

Bootsect.S0x90000

setup.S

1 MB

Compressed kernel image

Head.S

UncompressedKernel image

Page 16: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Booting 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)

Page 17: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Biblical 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…..

Page 18: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

GRUB

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.

Page 19: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

GRUB 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.

Page 20: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Multiboot

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

Page 21: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

OS 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

Page 22: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Machine 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

Page 23: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Boot 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!)

Page 24: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Booting: 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

Page 25: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

EFI : Concept

EFI Abstracts out hardware for OS loaders

Page 26: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

EFI : Overview

EFI specification defines a set of API’s and data structures EFI device drivers EFI diagnostics and system utilities EFI shell OS loaders OS

Page 27: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Booting 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.

Page 28: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

Loading Linux Kernel using ELILO

EFI initializes system directly in protected mode

Kernel loaded using EFI calls

ExitBootServices() to transfer control to kernel

EFI

EFI Boot Mgr

ELILO Load Kernel

Collect BootParams

Start_kernelJump to kernel

init

Page 29: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)

References

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

Page 30: PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)