CS318 Project #2 Bootup Mechanism.

Slides:



Advertisements
Similar presentations
Project 5: Virtual Memory
Advertisements

PC bootup Presented by: Rahul Garg (2003CS10183) Rajat Sahni (2003CS10184) Varun Gulshan(2003CS10191)
The Operating System. What is an Operating System? The program that is loaded first and manages the hardware resources like main memory, backing storage.
Crafting a ‘boot time’ program How we can utilize some standard ‘real-mode’ routines that reside in the PC’s ROM-BIOS firmware.
Genesis: from raw hardware to processes System booting sequence: how does a machine come into life.
Computer System Overview
Introduction to Embedded Systems ARM Monitor, Program Loading and Initialization Lecture #5.
计算机系 信息处理实验室 Lecture 5 Startup and Shutdown
09/30/04 Assignment 2 Non-preemptive scheduling COS Operating System Fall 2004.
Outline  Examine some of the H/W supplied with a typical PC and consider the software required to control it.  Introduce Commkit, a software tool that.
11/13/01CS-550 Presentation - Overview of Microsoft disk operating system. 1 An Overview of Microsoft Disk Operating System.
1 Hardware and Software Architecture Chapter 2 n The Intel Processor Architecture n History of PC Memory Usage (Real Mode)
PC hardware and x86 3/3/08 Frans Kaashoek MIT
CS 300 – Lecture 22 Intro to Computer Architecture / Assembly Language Virtual Memory.
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
40 Advanced Operating Systems Implementing System Calls.
CS2422 Assembly Language & System Programming September 22, 2005.
Introduction to Interrupts
8051 ASSEMBLY LANGUAGE PROGRAMMING
Protected Mode. Protected Mode (1 of 2) 4 GB addressable RAM –( to FFFFFFFFh) Each program assigned a memory partition which is protected from.
Build an Operating System
Administrative Overview 6 Projects Design Review: Monday before 6:30pm Lab Friend Center 010 (“Fishbowl”)
Files & Partitions BACS 371 Computer Forensics. Data Hierarchy Computer Hard Disk Drive Partition File Physical File Logical File Cluster Sector Word.
Host and Application Security Lesson 4: The Win32 Boot Process.
6.828: PC hardware and x86 Frans Kaashoek
DOS  In the 1980s or early 1990s, the operating system that shipped with most PCs was a version of the Disk Operating System (DOS) created by Microsoft:
1 Fundamental of Computer Suthida Chaichomchuen : SCC
Laface Operating System Design Booting a PC to run a kernel from Low memory VGA display.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
1. Stage-1 Bootloader ENGI 3655 Lab Sessions Richard Khoury.
Virtual Memory Review Goal: give illusion of a large memory Allow many processes to share single memory Strategy Break physical memory up into blocks (pages)
Topic 2d High-Level languages and Systems Software
2003 Dominic Swayne1 Microsoft Disk Operating System and PC DOS CS-550-1: Operating Systems Fall 2003 Dominic Swayne.
April 23, 2001Systems Architecture I1 Systems Architecture I (CS ) Lecture 9: Assemblers, Linkers, and Loaders * Jeremy R. Johnson Mon. April 23,
SAPC Hardware Pentium CPU (or 486) 4M usable memory no hard disk; boot from floppy no keyboard or monitor or mouse COM2 serial port: used for console i/o.
CSNB374: Microprocessor Systems Chapter 5: Procedures and Interrupts.
UHD:CS2401: A. Berrached1 The Intel x86 Hardware Organization.
Bootstrapping Steve Muckle Dave Eckhardt. Carnegie Mellon University1 Synchronization Project 3 checkpoint 1 Bboard post, web page Paging, COW optional.
CSE 351 Final Exam Review 1. The final exam will be comprehensive, but more heavily weighted towards material after the midterm We will do a few problems.
Memory Management: Overlays and Virtual Memory. Agenda Overview of Virtual Memory –Review material based on Computer Architecture and OS concepts Credits.
4. Kernel and VGA ENGI 3655 Lab Sessions. Richard Khoury2 Textbook Readings  None.
EEL 3801 Part IV The Assembler. OFFSET Operator Returns address of variable used as operand. Actually, it represents the offset from the beginning of.
Microprocessors used in Personal Computers. The Memory Map of a Personal Computers Transient Program Area (TPA): Holds the operating system (interrupt.
Lecture 5 Rootkits Hoglund/Butler (Chapters 1-3).
Microprocessor Fundamentals Week 2 Mount Druitt College of TAFE Dept. Electrical Engineering 2008.
Microprocessor and Assembly Language Addressing Models
Memory Management. 2 How to create a process? On Unix systems, executable read by loader Compiler: generates one object file per source file Linker: combines.
7-Nov Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Oct lecture23-24-hll-interrupts 1 High Level Language vs. Assembly.
Chapter 2 Instruction Addressing and Execution. Lesson plan Review some concepts in the first week First assembly program with EMU8086 Related concepts.
Assembly language programming
Bare metal OS project CSSE 332 Operating Systems
Introduction to Operating Systems
Chapter Objectives In this chapter, you will learn:
Format of Assembly language
143A: Principles of Operating Systems Lecture 7: System boot
Computer Organization & Assembly Language Chapter 3
143A: Principles of Operating Systems Lecture 5: Address translation
Software Development with uMPS
Instructors: Haryadi Gunawi
CS 301 Fall 2001 – Chapter 3 Slides by Prof. Hartman, following “IBM PC Assembly Language Programming” by Peter Abel 9/17/2018.
Topic 2e High-Level languages and Systems Software
Introduction to Operating Systems
CS-401 Computer Architecture & Assembly Language Programming
SAPC Hardware Pentium CPU (or 486) 4M usable memory
CS-401 Computer Architecture & Assembly Language Programming
TRAP Routines Subroutines Privileged Instructions
8051 ASSEMBLY LANGUAGE PROGRAMMING
Program Assembly.
Computer Architecture and System Programming Laboratory
CS444/544 Operating Systems II Virtual Memory
Presentation transcript:

CS318 Project #2 Bootup Mechanism

Reboot

OS Bootup Process When a PC is booted: Startup code in ROM (BIOS*) loads bootsector (head:0, track:0, sector:1), and jumps to it Bootblock code loads OS kernel (start at sector:2) and jumps to it BIOS supplies minimal but sufficient hardware support (screen, disk, keyboard etc.)

Memory (segment:offset) Bootstrapping Layout Disk Memory (segment:offset) 1 BIOS data Video RAM BIOS 0x00000 0x01000 0xb8000 0xfffff 0x07c00 0x9fffe 0x90000 (0x0000:0x1000) (0x7c0:0x0000) (0x9000:0xfffe) Bootblock Kernel BIOS Kernel 2 Bootblock Stack 1: done by BIOS code 2: done by bootblock code

What You Must Do bootblock.s createimage.c Load the kernel Setup stack, data segments Tranfer control to kernel createimage.c Extract code and data from executables Assemble into boot disk (bootblock image + kernel image)

Too Hard? Too easy? bootblock.s createimage.c Little debugging ability About 75 lines of assembly createimage.c About 200 lines of C Little debugging ability Try to print (int $0x10), Not even print! Start Early…

x86 Structures Real Mode Protect Mode Memory limited to 1Mbyte (220 bytes) Originally 16-bit registers Segment : offset Segment << 4 + offset Protect Mode Still segment : offset Virtual address instead of physical address

x86 structures – Register Set

GNU Assembly (AT&T Syntax) Data representations Registers: %eax,%ax,%ah,%al Definitions (.equ): BOOT_SEGMENT, 0x07c0 Constants: $0x0100, $1000 Memory contents: (0x40), %es:(0x40), (label) Labels Terminated by colon Represent instruction pointer location Comments /* enclosed like this */ # or to the end of a line

GNU Assembly (AT&T Syntax) Data operations mov{b,w,l}, lods{b,w,l}, … Logic and arithmetic cmp{b,w,l}, xor{b,w,l}, … Process control jmp, ljmp, call, ret, int, jne, … Directives .equ, .byte, .word, .ascii, .asciz

A Bit on Memory Access segment:[base+index*scale+disp] segment:disp(base, index, scale) (segment)Default: Override: movw $0xb800,%bx movw $0xb800,%bx movw %bx,%ds movw %bx,%es movw $0x074b,(0x40) movw $0x074b,%es:(0x40) Result = (0xb800<<4) + 0x40 = 0xb8040 Bootblock loaded at 0x07c0:0x0000 Kernel loaded at 0x0000:0x1000

Memory (segment:offset) Bootstrapping Layout Disk Memory (segment:offset) BIOS data 0x00000 0x01000 0xb8000 0xfffff 0x07c00 0x9fffe 0x90000 (0x0000:0x1000) (0x7c0:0x0000) (0x9000:0xfffe) Bootblock Kernel BIOS Kernel Bootblock Stack

Layout (to scale) Low High TPA: transient program area (640K) 0x00000 0x00000 Interrupt vectors/BIOS comm. area Low 0x10000 0x01000 Kernel 0x20000 0x02000 0x30000 0x03000 0x40000 0x04000 TPA: transient program area (640K) 0x50000 0x05000 0x60000 0x06000 0x70000 0x07000 bootblock 0x80000 0x08000 0x90000 Stack 0x09000 0xa0000 Video RAM (graphics area) 0x0a000 0xb0000 Video RAM (text area) 0x0b000 0xc0000 Video BIOS ROM Hard disk and LAN controllers ROM 0x0c000 System area (384K) 0xd0000 0x0d000 0xe0000 BASIC language ROM (early PCs) 0x0e000 High 0xf0000 BIOS system ROM 0x0f000

bootblock.s Setup stack and segment registers bootblock and kernel use same stack Set up (ss:sp) Stack pointer at the bottom Set bootblock data segment (ds=0x7c0) (bootblock code segment (cs=0x7c0) set by BIOS) Read the kernel into memory Starting at 0x0:0x1000 Use hardcoded kernel size (os_size: number of sectors)

bootblock.s (cont’d) Set the kernel data segment Set data segment (ds) to 0x0 Long jump to kernel ljmp 0x0,0x1000 This automatically sets code segment (cs) to 0x0

ELF What’s ELF? a.out vs. ELF Executable & Linkable Format a.out vs. ELF ELF header, Program header table & segments

createimage.c Read a list of executable files (ELF) Write segments (real code) into bootblock + kernel image file Note: Segments expand when loaded into memory (pad) Executable Program Header Table (Elf32_Phdr list) ELF Header (Elf32_Ehdr) Segment 1 Segment 2 …

createimage.c (cont’d) Read ELF header to find offset of program header table Read program header to find start address, size and location of segment Pad and copy segment into image file Write kernel size to hardcoded location in image file (in bootblock and be used when loading kernel) Loop

ELF to Image Example (4096) Bootblock ELF … Bootdisk Image Kernel ELF *In decimal for clarity … Bootdisk Image Kernel ELF Bootblock Segment 0 Loaded by BIOS 0x7c00:0x0 Program Header 0 (Elf32_Phdr) p_offset p_vaddr=4096* p_filesz=200 p_memsz=250 ELF Header (Elf32_Ehdr) e_phoff e_phnum=2 Program Header 1 (Elf32_Phdr) p_offset p_vaddr=4896* p_filesz=300 p_memsz=300 Segment 0 Segment 1 Padding (sector boundary) 512 Kernel Segment 0 712 Padding (memsz>filesz) 762 Padding (sector boundary) Loaded by bootblock 0x0:0x1000 1024 Padding (start address) 1312 Kernel Segment 1 1612 Padding (sector boundary) 2048 … Other ELFs Segment File Location = vaddr-0x1000+512 … (4096)

elf.h (usr/include/elf.h) Utilize the Elf32_Ehdr and Elf32_Phdr structures Use fseek() and fread() to get them Example: /* … */ Elf32_Ehdr elfHdr; /* … */ ret=fread(&elfHdr,1,sizeof(elfHdr),fd);

FAQ Sectors, Heads, Tracks? Use 32bit registers in real mode? 80 tracks:2 heads:18 sectors:512 bytes = 1.44Mb Use 32bit registers in real mode? You can, but it’s not necessary. Won’t a big kernel overwrite the bootblock? Yes. For extra credit, you can move the bootblock elsewhere first. Int13 can only load 36 sectors at once. For large kernels, you might load one sector at a time… How many files should createimage handle? As many as are in the command line (bootblock, kernel, and any number of others)