CS 410/510. Mark P Jones Portland State University

Similar documents
The Early System Start-Up Process. Group Presentation by: Tianyuan Liu, Caiwei He, Krishna Parasuram Srinivasan, Wenbin Xu

Bootstrapping. Steve Muckle Dave Eckhardt

PL-I Assignment Broup B-Ass 5 BIOS & UEFI

CS3210: Booting and x86

CS3210: Booting and x86. Taesoo Kim

Faculty of Computer Science Institute for System Architecture, Operating Systems Group. MKC Exercise 2. Nils Asmussen

IA32 OS START-UP UEFI FIRMWARE. CS124 Operating Systems Fall , Lecture 6

Boot. How OS boots

Initial Bootloader. On power-up, when a computer is turned on, the following operations are performed:

Assembly Language. Lecture 2 x86 Processor Architecture

Segmentation with Paging. Review. Segmentation with Page (MULTICS) Segmentation with Page (MULTICS) Segmentation with Page (MULTICS)

Assembly Language. Lecture 2 - x86 Processor Architecture. Ahmed Sallam

These boots are made for walking. Johan Montelius HT2018

FreeBSD and the IBM PC BIOS

Boot Process in details for (X86) Computers

BOOTSTRAP, PC BIOS, AND IA32 MEMORY MODES. CS124 Operating Systems Winter , Lecture 5

SPPEXA TEACHLET: GETTING STARTED WITH L4RE CARSTEN WEINHOLD

Typical File Extensions File Structure

User. Applications. Operating System. Hardware

Installing Linux (Chapter 8) Note packet # 4. CSN 115 Operating Systems Ken Mead Genesee Community College. Objectives

Preview. COSC350 System Software, Fall

Operating Systems. Objective

Lab1 tutorial CS

The FAT File System. 1. FAT Overview. 2. Boot Sector, FAT, Root Directory, and Files The FAT F 䤀耄 le System

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

CS 261 Fall Mike Lam, Professor. Virtual Memory

We can study computer architectures by starting with the basic building blocks. Adders, decoders, multiplexors, flip-flops, registers,...

Speeding up the Booting Time of a Toro Appliance

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

ECE 498 Linux Assembly Language Lecture 1

File System. Preview. File Name. File Structure. File Types. File Structure. Three essential requirements for long term information storage

AMSC/CMSC 662 Computer Organization and Programming for Scientific Computing Fall 2011 Operating Systems Dianne P. O Leary c 2011

COS 318: Operating Systems. Overview. Andy Bavier Computer Science Department Princeton University

OPERATING SYSTEMS CS136

COS 318: Operating Systems

16-Bit Intel Processor Architecture

Computer Systems II. Memory Management" Subdividing memory to accommodate many processes. A program is loaded in main memory to be executed

Xosdev Chapter 1 [The Bootloader] by mr. xsism

Advanced Operating Systems

COS 318: Operating Systems. Overview. Prof. Margaret Martonosi Computer Science Department Princeton University

Operating Systems CS3502 Spring 2018

THOMAS RUSSELL, Information Technology Teacher

Representation of Information

Four Components of a Computer System

HPS SoC Boot Guide - Cyclone V SoC Development Kit

Linux+ Guide to Linux Certification, Third Edition. Chapter 2 Linux Installation and Usage

Linux Boot Process. Nassim Eddequiouaq LSE Summer Week 2015

1.Explain with the diagram IVT of 80X86. Ans-

File Directories Associated with any file management system and collection of files is a file directories The directory contains information about

Modesto Junior College Course Outline of Record CMPSC 241

Computer Organization (II) IA-32 Processor Architecture. Pu-Jen Cheng

Chapter 2: Operating-System Structures

Project 1: Bootloader. COS 318 Fall 2015

File Systems. File system interface (logical view) File system implementation (physical view)

The Extended MBR (version 1.05) (dated: 01 Nov 2018) by Benjamin David Lunt Copyright (c) Forever Young Software

TMS470 ARM ABI Migration

Macs don t have BIOS and some lower-end PCs use either emulated BIOS or the UEFI method. This project assumes an honest-to-goodness PC.

Hardware and Software Architecture. Chapter 2

Advanced Operating Systems (CS 202) Virtualization

Introduction. What is an Operating System? A Modern Computer System. Computer System Components. What is an Operating System?

CS4500/5500 Operating Systems File Systems and Implementations

3. Process Management in xv6

Long-term Information Storage Must store large amounts of data Information stored must survive the termination of the process using it Multiple proces

Smart Port Card (SPC) William Eatherton Toshiya Aramaki Edward Spitznagel Guru Parulkar Applied Research Lab Washington University in St.

Chapter 3 Memory Management: Virtual Memory

What You Need to Know for Project Three. Dave Eckhardt Steve Muckle

File Systems. CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

RAID Option ROM. Product Implementation Guide. Version 1.8 Date: 08/19/2009. Copyright 2009, Promise Technology, Inc. All Rights Reserved

CG2007 Microprocessor systems.

ECE 471 Embedded Systems Lecture 16

ECE 471 Embedded Systems Lecture 16

ECE 598 Advanced Operating Systems Lecture 2

EE2007 Microprocessor systems.

CS399 New Beginnings. Jonathan Walpole

Chapter 1: Introduction. Operating System Concepts 9 th Edit9on

IA32 Intel 32-bit Architecture

PROCESS VIRTUAL MEMORY. CS124 Operating Systems Winter , Lecture 18

Overview of System Virtualization: The most powerful platform for program analysis and system security. Zhiqiang Lin

Introduction. Yolanda Becerra Fontal Juan José Costa Prats

CHAPTER 11: IMPLEMENTING FILE SYSTEMS (COMPACT) By I-Chen Lin Textbook: Operating System Concepts 9th Ed.

CS333 Intro to Operating Systems. Jonathan Walpole

ECE 471 Embedded Systems Lecture 12

File System Case Studies. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

UEFI Support for Memtest86+ Patricio Chilano Mateo

CS 390 Chapter 8 Homework Solutions

Microsoft File Allocation Table

Microprocessor Architecture. mywbut.com 1

What Operating Systems Do An operating system is a program hardware that manages the computer provides a basis for application programs acts as an int

Xbox Security. Daniel Butnaru. 28 th June 2006

Using grub to Boot various Operating Systems

ECE 471 Embedded Systems Lecture 5

Chapter 2. Operating-System Structures

Operating Systems CMPSCI 377 Spring Mark Corner University of Massachusetts Amherst

Operating Systems Design Fall 2010 Exam 1 Review. Paul Krzyzanowski

Advanced Computer Architecture

x86 architecture et similia

,879 B FAT #1 FAT #2 root directory data. Figure 1: Disk layout for a 1.44 Mb DOS diskette. B is the boot sector.

Memory management. Last modified: Adaptation of Silberschatz, Galvin, Gagne slides for the textbook Applied Operating Systems Concepts

Hardware OS & OS- Application interface

Transcription:

CS 41/51 Languages & Low-Level Programming Mark P Jones Portland State University Fall 21 Week 2: Bare Metal and the Boot Process 1 Copyright Notice These slides are distributed under the Creative Commons Attribution 3. License You are free: to share to copy, distribute and transmit the work to remix to adapt the work under the following conditions: Attribution: You must attribute the work (but not in any way that suggests that the author endorses you or your use of the work) as follows: Courtesy of Mark P. Jones, Portland State University The complete license text can be found at http://creativecommons.org/licenses/by/3./legalcode 2

Bare Metal Programming 3 A conventional computing environment The standard applications that we run on our computers do so with the support of an underlying operating system: Browser Compiler Operating System Hardware Editor These applications benefit enormously from the functionality that the operating system provides: Memory management I/O File systems Networking etc 4

A bare metal environment What if we ran applications directly on the hardware, without an underlying operating system? Browser Compiler Hardware Editor Applications like this are said to be running on bare metal Direct access to and manipulation of hardware Potential to reduce complexity and cost Less suited to general purpose computing Although conventional operating systems are bare metal systems that a general purpose environment. 5 The boot process When your computer is running, it looks something like this: CPU OS Data OS App App App Memory Disk Network Graphics Devices Data The CPU is initialized The memory contains the apps and data that we need The devices are initialized and operational How did that happen? 6

Initializing the CPU The CPU will typically initialize itself when power is first applied or when the system is reset: Basic self-test Initialize registers to known states including the instruction pointer/program counter On IA32, for example, execution starts at xfffffff So the computer can begin executing programs And those programs can initialize the devices But only if those programs are in memory! where does this information come from? 7 Building a Simple Computer System

Building a basic computer system Let s review some basic techniques that are used to construct a typical computer For the purposes of this exercise, we ll assume a 16 bit processor but the same ideas apply to other architectures Key goal: understand how physical memory might be organized and addressed 9 data/ /16 / 64KB ROM Read Only Memory Memory Map KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

data/ /16 / 64KB ROM Read Only Memory KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB data/ /16 / 64KB ROM Read Only Memory ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

/13 KB ROM data/ / ROM ROM ROM ROM ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB /13 KB ROM data/ / ROM ROM ROM ROM ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

/13 KB ROM data/ / ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB data/ /13 /12 KB ROM / / 4KB RAM Random Access Memory ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

data/ /13 /12 KB ROM / / 4KB RAM Random Access Memory ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB data/ /13 /12 KB ROM / / 4KB RAM Random Access Memory ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

data/ /13 /12 KB ROM / / 4KB RAM Random Access Memory RAM RAM RAM RAM RAM RAM RAM RAM ROM ROM ROM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB /13 /12 KB ROM 4KB RAM data/ / / RAM RAM ROM RAM RAM ROM RAM RAM ROM RAM RAM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

/13 /12 KB ROM 4KB RAM data/ / / RAM RAM RAM RAM RAM RAM RAM RAM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB /13 /12 KB ROM 4KB RAM data/ / / RAM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

/13 /12 KB ROM 4KB RAM data/ / / RAM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB /13 /12 /12 KB ROM 4KB RAM I/O / / data/ RAM I/O ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB

/13 /12 /12 busy KB ROM 4KB RAM Video / / data/ RAM VRAM ROM KB 16KB 24KB 32KB 4KB 4KB 56KB 64KB Booting a PC 26

Introducing the BIOS (Basic I/O System) The original IBM PC had a 2 bit address bus, so it could address up to of data: KB The CPU starts executing programs at an address close to the top of the address space so we can install a ROM at that address: KB 64KB ROM The ROM contains the BIOS, or basic I/O system, for the computer 27 continued The rest of the address space can be used for RAM (who would need more than 64KB, eh?): KB RAM 64KB xa Video RAM is also mapped within the region above 64KB (at address xb), so it doesn t interfere with lower memory: KB RAM But the BIOS does need to use some of that memory for its own purposes: Interrupt Vector Table BIOS Data Area 64KB BIOS BIOS, Video RAM, IVT BDA KB 1KB 4ff RAM 64KB BIOS, Video RAM, 2

The master boot record (MBR) We don t want the BIOS to make too many assumptions about the operating system that it is booting Instead, the BIOS searches the available hardware for a bootable disk that contains a 512 byte Master Boot Record or MBR: Master Boot Record (MBR), 1 sector = 512 bytes 55 AA 446 bytes of code partition table (4x16 bytes) identifies as bootable KB IVT BDA 1KB 4ff 7c 32KB RAM 64KB BIOS, Video RAM, 29 booting, continued Now the program from the MBR can continue the process of loading the rest of the operating system taking advantage of BIOS routines but without relying on a BIOS that is hardwired to that particular OS 3

Boot loaders 31 Boot scenarios Custom hardware App Simple, single purpose programmed system, app in ROM CPU App Single purpose programmed system, app on disk or other media CPU BIOS App 32

continued App on disk or media, leveraging an underlying operating system CPU BIOS possibly supporting multiple applications OS App1 App2 App3 33 continued Boot time configuration that is not required once the system is properly initialized Typical uses: initialize and test a device decrypt/decompress a file system free resources (e.g., memory) that are not required once the system is booted CPU BIOS init OS App1 App2 App3 34

continued Potential to boot into one of multiple operating systems, selected at runtime The role of a boot loader is to: prepare the next stage to run (includes selecting between multiple possible next stages ) collect and pass on configuration details CPU BIOS boot loader OS1 init App1 App2 App3 OS2 App 35 Introducing GRUB (The GNU GRand Universal Bootloader) 36

Booting via GRUB After reset, the CPU starts executing code in the BIOS ROM KB RAM BIOS, Video RAM, Upper Memory 64KB 4GB The BIOS loads and transfers control to the MBR code KB IVT BDA 1KB 4ff MBR RAM 7c 32KB (Extended BIOS Data Area) EBDA BIOS, Video RAM, Upper Memory varies 64KB 4GB The MBR code loads GRUB from a known location on the disk (using BIOS routines) KB IVT BDA 1KB 4ff MBR RAM 7c 32KB GRUB EBDA BIOS, Video RAM, Upper Memory varies 64KB 4GB 37 continued KB IVT BDA 1KB 4ff MBR RAM 7c 32KB GRUB EBDA BIOS, Video RAM, Upper Memory varies 64KB 4GB The main GRUB program (interpreting the higher-level file system on the boot disk) searches for a configuration file, reading and acting on its contents Once a boot option has been identified (possibly with user input), GRUB will load an appropriate kernel file, together with a sequence of zero or more modules, in to memory and then transfer control to the kernel KB IVT BDA 1KB 4ff MBR RAM 7c 32KB GRUB EBDA BIOS, Video RAM, Kernel M varies 64KB 4GB The kernel begins the process of initializing the OS/App/ 3

Details: Loading the kernel The kernel must contain a multiboot header in the first KB KB kernel Magic Flags Chksm Address Fields Graphics Fields 1BADB2 use address fields video required memory map required load modules on 4KB boundaries 16 2 1 39 Where should the kernel be loaded? GRUB is able to parse kernel files in ELF format, and will load the different sections of the file in to the appropriate addresses 7F E L F Header Section1 Section2 Section3 If the kernel is not in ELF format, then flag bit 16 must be set and the address fields must be used to specify where the kernel will be loaded Either way, GRUB will not allow the kernel to be loaded below (so GRUB is free to use that memory) End result: Lower kernel mod1 mod2 Upper MB 4GB 4

Kernel in control! GRUB s work is done, and it jumps to the specified entry point for the kernel: eax will contain x2badb2 ebx will contain the address of the multiboot information structure MB Lower kernel mod1 mod2 Values in other registers are also set to appropriate constant values, as described by the multiboot specification What will the kernel do next? Upper 4GB 41 Multiboot Information 4 12 16 2 24 2 flags mem_lower mem_upper boot_device cmdline mods_count mods_addr symbols lower memory in KB (if flags[]) upper memory in KB (if flags[]) pointer to command line string (if flags[2]) number of modules (if flags[3]) address of first module descriptor (if flags[3]) 44 4 52 mmap_length mmap_addr length of memory map buffer (if flags[6]) address of first memory map entry (if flags[6]) etc 42

Multiboot Information, continued For each module For each memory map entry: 4 12 mod_start mod_end string reserved -4 4 12 16 2 size base_lo base_hi len_lo len_hi type type = 1 available RAM 43 Let s look at this in practice 44

hello QEMU hello Linux Virtual Box hello Mac OS X Hardware Introducing mimgload and mimgmake 46

GRUB is great It can load a kernel in one of several executable formats, as well as a collection of uninterpreted modules It supports booting from a variety of different media and file systems It supports network booting It can load from compressed kernel/module images It provides a boot-time menu and allows customization It gathers useful data about the machine and makes it available to the kernel Widely used, multiboot standard, open source, 47 But, of course, it has limits too It can only load one executable Possible workarounds include merging multiple ELF files into a single file, or using a kernel that can unpack executables from modules The address at which modules are loaded cannot be controlled or predicted The location of the multiboot information structures is not specified, and is not even guaranteed to be stored in a contiguous block of memory There are limits on where GRUB can load data (e.g., it does not appear to be able to load into lower memory) 4

Memory Images Think about what we want the memory layout to look like immediately after the boot process completes: MB Package up those components in a (compressed) module: image image.gz Boot from GRUB into a small program that can unpack the image, move the pieces to the required locations (including boot data), and transfer control to the main program: 4GB Lower MB mimgload image Upper 4GB 49 mimgmake and mimgload mimgmake builds image files (in a full Linux environment):../mimg/mimgmake image \ noload:../mimg/mimgload \ bootdata:x-x3fff \ $(KERNEL)/pork \ user/sigma/sigma \ user/l4ka-pingpong/pingpong mimgload loads images (on bare metal): menuentry "InsertKernelNameHere" { } multiboot /mimgload module /image.gz No particular claim to originality: this was just a tool that I built as a learning experience/to meet a practical need 5

The mimg file format Memory images are stored as binary files using a simple format that is like a greatly simplified version of ELF: m i m g versn entry magic number header Individual sections: Section1 Section2 Section3 first last type payload if type is DATA (1) or BOOTDATA(2), payload will contain (last-first+1) bytes if type is ZERO (), or RESERVED (3), payload is empty 51 CPU BIOS A quick look at mimg in practice GRUB mimgload kernel App1 App2 App3 52

Exercises Add a function to the code for hello that can be used to output an integer value (hexadecimal notation is probably easiest, and most useful too). Test to make sure it works correctly Integrate your assembly code for cls into hello Adapt the code from hello or bootinfo to print out a summary of the details that GRUB passes on to the kernel via the multiboot information structure. (Start simple, and add more fields as you go.) Experiment with different virtual machine settings to see what impact this has on the information in the multiboot structure. 53