Today Booting Process abstraction Dual mode execution Sept 19, - - PowerPoint PPT Presentation

today
SMART_READER_LITE
LIVE PREVIEW

Today Booting Process abstraction Dual mode execution Sept 19, - - PowerPoint PPT Presentation

Today Booting Process abstraction Dual mode execution Sept 19, 2018 Sprenkle - CSCI330 1 Course Objectives Review Classical OS Emphasis on the why Agile class Synching with the Project


slide-1
SLIDE 1

Today

  • Booting
  • Process abstraction
  • Dual mode execution

Sept 19, 2018 Sprenkle - CSCI330 1

slide-2
SLIDE 2

Course Objectives Review

  • Classical OS

ØEmphasis on the why

  • Agile class
  • Synching with the Project

Sept 19, 2018 Sprenkle - CSCI330 2

https://www.facebook.com/groups/169380229860838/

slide-3
SLIDE 3

Review

  • What do we call the core of the OS?

Sept 19, 2018 Sprenkle - CSCI330 3

slide-4
SLIDE 4

BOOTING

How do we get the OS party started?

Sept 19, 2018 Sprenkle - CSCI330 4

slide-5
SLIDE 5

System Boot

  • Booting: Loading the kernel to render a computer usable
  • When power initialized on system, execution starts at a

fixed memory location

Ø Firmware ROM used to hold initial boot code

  • OS must be available to hardware so hardware can start it

Ø Small piece of code – bootstrap loader—locates the kernel, loads it into memory, and starts it

  • stored in ROM or EEPROM

Ø Sometimes two-step process where boot block at fixed location loaded by ROM code, which loads bootstrap loader from disk

  • Common bootstrap loader, GRUB, allows selection of

kernel from multiple disks, versions, kernel options

  • Kernel loads and system is then running

Sept 19, 2018 Sprenkle - CSCI330 5

slide-6
SLIDE 6

Booting

Sept 19, 2018 Sprenkle - CSCI330 6

Bootloader OS kernel Application

(1) BIOS copies bootloader (2) Bootloader copies OS kernel (3) OS kernel copies application Physical Memory BIOS Bootloader instructions and data OS kernel instructions and data Application instructions and data

slide-7
SLIDE 7

Basic Input/Output System (BIOS)

  • A number of small programs and subroutines:

Ø Power on self test (POST) Ø System configuration utility

  • Settings stored in small amount of battery backed CMOS

memory.

Ø A set of routines for performing basic operations on common input/output devices. Such as…

  • Read/write a specified C:H:S from disk
  • Read character from keyboard
  • Display character on the screen

Ø OS bootstrap program

  • Stored on a Flash ROM that is part of the computer’s

address space.

Sept 19, 2018 Sprenkle - CSCI330 7

slide-8
SLIDE 8

Bootstrap Process

  • Program Counter (PC) is initialized to the address of the POST

program contained in the BIOS

  • The last instruction of the POST jumps to the address of the

bootstrap program, also contained in the BIOS.

  • The bootstrap program uses the BIOS routines to load a

program contained in the Master Boot Record (MBR) of the boot disk into memory at a known address.

Ø MBR = first sector on the disk (512 bytes). Ø Boot disk is identified by data stored in the configuration CMOS.

  • The last instruction in the bootstrap program jumps to the

address at which the MBR program was loaded.

  • The MBR program loads the OS kernel.

Ø Often indirectly by loading another program (a secondary boot loader) that then loads the kernel

Sept 19, 2018 Sprenkle - CSCI330 8

slide-9
SLIDE 9

Booting

Sept 19, 2018 Sprenkle - CSCI330 9

Bootloader OS kernel Application

(1) BIOS copies bootloader (2) Bootloader copies OS kernel (3) OS kernel copies application Physical Memory BIOS Bootloader instructions and data OS kernel instructions and data Application instructions and data

slide-10
SLIDE 10

Design Questions

  • Why don’t we store the whole kernel in ROM?

ØWhy do we need a bootloader?

  • Consider:

ØWhat are the characteristics of ROM? ØWhat are the characteristics of the kernel?

Sept 19, 2018 Sprenkle - CSCI330 10

slide-11
SLIDE 11

Design Questions

  • Why don’t we store the whole kernel in ROM?

ØWhy do we need a bootloader?

  • Issues

ØSize of kernel ØUpdatability of kernel

  • What happens if there is an error in kernel?

ØROM – slow, expensive, small

  • Common solution: Add a level of indirection

Sept 19, 2018 Sprenkle - CSCI330 11

"All problems in computer science can be solved by another level of indirection.” – David Wheeler (except for too many levels of indirection)

slide-12
SLIDE 12

Review

  • What goals do the interfaces of the OS enable?
  • What is the basic unit of execution in an OS?
  • What resources does that unit require?

Sept 19, 2018 Sprenkle - CSCI330 12

slide-13
SLIDE 13

Goals for the Process: Boxes in the Application

  • An abstraction for

protection

Ø Represents an application program executing with restricted rights

  • Restricting rights must

not hinder functionality

Ø Must still allow efficient use of hardware Ø Must still enable safe communication

Sept 19, 2018 Sprenkle - CSCI330 13

slide-14
SLIDE 14
  • CPU: Central Processing

Unit

  • PC points to next

instruction

  • CPU loads instruction,

decodes it, executes it, stores result

  • Process “given” CPU by OS

Ø Mechanism: context switch Ø Policy: CPU scheduling

Data in Data in Data in Data in

Process Resource: CPU Time

32-bit Register #0

WE

32-bit Register #1

WE

32-bit Register #2

WE

32-bit Register #3

WE

MUX MUX

Register File A L U

Program Counter (PC): Memory address of next instr Instruction Register (IR): Instruction contents (bits)

Sept 19, 2018 Sprenkle - CSCI330 14

slide-15
SLIDE 15

Process Resource: CPU Time

  • CPU: Central Processing

Unit

  • PC points to next

instruction

  • CPU loads instruction,

decodes it, executes it, stores result

  • Process “given” CPU by OS

Ø Mechanism: context switch Ø Policy: CPU scheduling

Program Counter (PC): Memory address of next instr Instruction Register (IR): Instruction contents (bits)

Sept 19, 2018 Sprenkle - CSCI330 15

Required for process to execute and make progress!

Data in Data in Data in Data in

32-bit Register #0

WE

32-bit Register #1

WE

32-bit Register #2

WE

32-bit Register #3

WE

MUX MUX

Register File A L U

slide-16
SLIDE 16

Sept 19, 2018 Sprenkle - CSCI330 16

slide-17
SLIDE 17

Process Resource: Main Memory

  • Process must store:

Ø Text: code instructions Ø Data: global and static (known at compile time) variables Ø Heap: dynamically requested memory at runtime (malloc, new, etc.) Ø Stack: store local variables and compiler-generated function call state (e.g., saved registers)

Sept 19, 2018 Sprenkle - CSCI330 17

0x0 0xFFFFFFFF Operating system Stack Text Data Heap

Why do the heap and stack grow towards each other? What would an alternative organization look like?

slide-18
SLIDE 18

Process Resource: Main Memory

  • Process must store:

Ø Text: code instructions Ø Data: global and static (known at compile time) variables Ø Heap: dynamically requested memory at runtime (malloc, new, etc.) Ø Stack: store local variables and compiler-generated function call state (e.g., saved registers)

Sept 19, 2018 Sprenkle - CSCI330 18

0x0 0xFFFFFFFF Operating system Stack Text Data Heap

Required for process to store instructions (+data)!

Represents 32 bits à 232 locations

slide-19
SLIDE 19

Process Resource: I/O

  • Allows processes to interact with a

variety of devices (i.e., everything that isn’t a CPU or main memory).

  • Enables files, communication,

human interaction, etc.

  • Learn about or change the state of

the outside world.

Sept 19, 2018 Sprenkle - CSCI330 19

Disk Wireless Network Keyboard / Mouse

Does a process require I/O?

slide-20
SLIDE 20

HOW CAN THE OS ENFORCE RESTRICTED RIGHTS?

Sept 19, 2018 Sprenkle - CSCI330 20

slide-21
SLIDE 21

How can the OS enforce restricted rights?

  • Consider: OS interprets each instruction

ØEvery instruction must be validated/executed by the [privileged] OS

  • Good solution?

ØNo! Slow ØMost instructions are safe: can we just run them in hardware?

Sept 19, 2018 Sprenkle - CSCI330 21

slide-22
SLIDE 22

How can the OS enforce restricted rights?

  • Consider: Dual Mode Execution

ØUser mode: access is restricted ØKernel mode: access is unrestricted ØSupported by the hardware

  • Mode is indicated by a bit in the process status

register

Sept 19, 2018 Sprenkle - CSCI330 22

slide-23
SLIDE 23

Process Modes: User and Kernel

OS

User Kernel

Applications Hardware

Compiler, editor, shell, utilities, libraries Process management, device drivers, system calls Interrupts

Sept 19, 2018 Sprenkle - CSCI330 23

slide-24
SLIDE 24

Process Modes: User and Kernel

OS

User Kernel

Applications Hardware

Compiler, editor, shell, utilities, libraries Process management, device drivers, system calls Interrupts

Sept 19, 2018 Sprenkle - CSCI330 24

trusted untrusted

  • core of the OS
  • code and data

structures that are protected, can be accessed only in the kernel mode Mode stored in a register

slide-25
SLIDE 25

Kernel vs. Userspace: Model

Text Data Stack Text Data Stack Text Data Stack

Kernel

System Calls write read fork System Management Scheduling Context Switching

OS OS Heap Heap OS Heap Process 1 Process 2 Process N

Sept 19, 2018 Sprenkle - CSCI330 26

slide-26
SLIDE 26

Kernel vs. User Mode: Privileged Instructions

  • User processes may not:

Øaddress I/O directly Øuse instructions that manipulate the OS’s memory (e.g., page tables) Øset the mode bits that determine user or kernel mode Ødisable and enable interrupts Øhalt the machine

  • But in kernel mode, the OS does all these things.

Sept 19, 2018 Sprenkle - CSCI330 27

slide-27
SLIDE 27

OS: Taking Control of the CPU

The terminology here is, unfortunately, muddy

1.System call/Trap – user requests service from

the OS

2.Exception – user process has done something

that requires help

3.(Hardware) interrupt – a device needs attention

from the OS

System call often implemented as a special case of exception: execute intentional exception-generating instruction.

Sept 19, 2018 Sprenkle - CSCI330 28

slide-28
SLIDE 28

SYSTEM CALLS & LIBRARIES

Sept 19, 2018 Sprenkle - CSCI330 31

slide-29
SLIDE 29

How system calls work

C Runtime Library Operating System Kernel Application Program Device Driver User-space Kernel-space

Sept 19, 2018 Sprenkle - CSCI330 32

Synchronous request

slide-30
SLIDE 30

Common Functionality

  • Some functions useful to many programs

ØI/O device control ØMemory allocation

  • Place these functions in kernel

ØExplicitly called by programs (system calls) ØOr accessed implicitly as needed (exceptions)

  • Design questions:

ØWhat should these functions be? ØHow many programs should benefit? ØMight kernel get too big?

Sept 19, 2018 Sprenkle - CSCI330 33

slide-31
SLIDE 31

How about a function like printf()?

Recall: What does printf() do?

A.printf() is a system call (why?) B.printf() is not a system call (why not, what

is it?)

Sept 19, 2018 Sprenkle - CSCI330 34

slide-32
SLIDE 32

Why make system calls?

A.Reliability: Kernel code always behaves the

same.

B.Security: Programs can’t use kernel code in

unintended ways.

C.Usability: Kernel code is easier / adds value for

programmers to use.

D.More than one of the above. E.Some other reason(s).

Sept 19, 2018 Sprenkle - CSCI330 35

slide-33
SLIDE 33

Looking Ahead

  • Git
  • Project 1 Introduction

Sept 19, 2018 Sprenkle - CSCI330 36