Top Banner
COS318 Lec 2 1 Operating System Structures Vivek Pai Princeton University
28

COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

Dec 19, 2015

Download

Documents

Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 1

Operating System Structures

Vivek Pai

Princeton University

Page 2: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 2

Gedankenexperiment

What does this program do?static void Loop(void){

static char *startAddr;char local;printf(“diff is %d\n”, startAddr – (&local));startAddr = &local;Loop( );

}int main(int argc, char *argv[ ]){

Loop( );}

Page 3: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 3

Mechanics

Have you: Subscribed to pu.cs.318? Sent me mail with your details?

– Hey, it was an assignment after all… Sent me a picture of yourself?

Page 4: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 4

More Mechanics

Syllabus is now “complete”, along with goals for each lecture

Preparatory readings are listed– External readings are not yet included

Projects are being finalized– Regular lab not yet operational

How do we want to handle quizzes?– Scheduled or random?

Page 5: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 5

Reading Assignment

Sections 1.0-1.3 inclusive Keep up with what’s on home page I’ll try to remember to remind you

Page 6: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 6

A Typical Computer from a Hardware Point of View

CPU

ChipsetMemory

I/O bus

CPU. . .

Network

Page 7: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 7

A Typical Computer System

Operating System Software

Programs and data

MemoryCPU

CPU

...

OSApps

Data

Network

Page 8: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 8

Typical Unix OS Structure

Application

Portable OS Layer

Libraries

Machine-dependent layer

User space/level

Kernel space/level

Page 9: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 9

Typical Unix OS Structure

Application

Portable OS Layer

Libraries

Machine-dependent layer

Written by programmerCompiled by programmerUses function calls

Page 10: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 10

Typical Unix OS Structure

Application

Portable OS Layer

Libraries

Machine-dependent layer

Written by elvesProvided pre-compiledDefined in headersInput to linker (compiler)Invoked like functionsMay be “resolved” when

program is loaded

Page 11: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 11

Typical Unix OS Structure

Application

Portable OS Layer

Libraries

Machine-dependent layer

“Guts” of system callsAll “high-level” code

Page 12: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 12

Typical Unix OS Structure

Application

Portable OS Layer

Libraries

Machine-dependent layer

BootstrapSystem initializationInterrupt and exception I/O device driverMemory managementKernel/user mode

switchingProcessor management

Page 13: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 13

Another Look: Unix “Onion”

Applications

OS Service

Device

Driver

Hardware

User and Kernelboundary

Page 14: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 14

What’s An Application?

Four parts (“segments”) Code/Text – instructions Data – initialized global variables Stack Heap

What’s a stack and heap?

Page 15: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 15

OS Service Examples

Examples that are not provided at user level– System calls: file open, close, read and write– Control the CPU so that users won’t stuck by

runningwhile ( 1 ) ;

– Protection: • Keep user programs from crashing OS• Keep user programs from crashing each other

Examples that can be provided at user level– Read time of the day– Protected user level stuff

Page 16: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 16

Processor Management

Goals– Overlap between I/O and

computation– Time sharing– Multiple CPU allocations

Issues– Do not waste CPU

resources– Synchronization and mutual

exclusion– Fairness and deadlock free

CPU I/O CPU

CPU

I/O

CPU

CPUI/O

CPU

CPU

CPU

Page 17: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 17

Memory Management

Goals– Support programs to run– Allocation and

management– Transfers from and to

secondary storage Issues

– Efficiency & convenience– Fairness– Protection

Tape 100Mx

Disk 10Mx

Memory 200x

L2 10x

Register

Page 18: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 18

x86 Architecture Registers

General-purpose registers

Segment registers

EFLAGS register EIP (Instruction Pointer register)

EAXEBXECXEDXEBPESIEDIESP

31 0 015

CSDSSSESFSGS

AXBXCXDX

16-bit 32-bit

DISIBP

SP

ALAHBLCLDL

BHCHDH

8 715

Page 19: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 19

x86 Memory

0

232-1

Byte order is little endian

31 08 716 15

.

.

.

24 23

Byte 4Byte 0

Byte 5Byte 1Byte 2

Byte 6Byte 3Byte 7

Page 20: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 20

I/O Device Management

Goals– Interactions between

devices and applications– Ability to plug in new

devices

Issues– Efficiency– Fairness– Protection and sharing

User 1 User n. . .

Library support

I/Odevice

I/Odevice. . .

Driver Driver

Page 21: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 21

Window Systems

All in the kernel (Windows)– Pros: efficient?– Cons: difficult to develop new services

All at user level– Pros: easy to develop new apps– Cons: protection

Split between user and kernel (Unix)– Kernel: display driver and mouse driver– User: the rest

Page 22: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 22

File System

A typical file system

– Open a file with authentication

– Read/write data in files

– Close a file

Can the services be moved to user level?

User 1 User n. . .

File system services

File File. . .

Page 23: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 23

Bootstrapping Power up a computer Processor reset

– Set to known state– Jump to ROM code

Load in the boot loader from stable storage

Jump to the boot loader Load the rest of the

operating system Initialize and run

Bootloader

OSsector 1

OSsector 2

OSsector n

.

.

.

Bootloader

Page 24: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 24

System Boot

Power on (processor waits until Power Good Signal)

Processor jumps on a PC (“Intel Inside”) to address FFFF0h

• 1M= 1,048,576= 220 =FFFFFh+1 • FFFFFh=FFFF0h+16 is the end of the (first 1MB of)

system memory• The original PC using Intel 8088 had 20 address lines :-)

(FFFFFFF0h) is a JMP instruction to the ROM BIOS startup program

Maps to FFFFFFF0h= 232-16

Page 25: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 25

ROM BIOS startup program (1) POST (Power-On Self-Test)

• If pass then AX:=0; DH:=5 (586: Pentium);• Stop booting if fatal errors, and report

Look for video card and execute built-in ROM BIOS code (normally at C000h)

Look for other devices ROM BIOS code• IDE/ATA disk ROM BIOS at C8000h (=819,200d)

Display startup screen• BIOS information

Execute more tests• memory• system inventory

SCSI disks: must often provide their own BIOS

Page 26: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 26

ROM BIOS startup program (2)

Look for logical devices– Label them

• Serial ports– COM 1, 2, 3, 4

• Parallel ports– LPT 1, 2, 3

– Assign each an I/O address and IRQ

Detect and configure PnP devices Display configuration information on screen

Page 27: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 27

ROM BIOS startup program (3)

Search for a drive to BOOT from– Floppy or Hard disk

• Boot at cylinder 0, head 0, sector 1

Load code in boot sector Execute boot loader Boot loader loads program to be booted

• If no OS: "Non-system disk or disk error - Replace and press any key when ready"

Transfer control to loaded program Is it okay to boot at first sector on the floppy or

disk?

Page 28: COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

COS318 Lec 2 28

Ways to Develop An Operating System A hardware simulator A virtual machine A good kernel debugger

– When OS crashes, always goes to the debugger

– Debugging over the network