cos318 lec 21 operating system structures vivek pai princeton university
Post on 19-Dec-2015
214 views
TRANSCRIPT
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( );}
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?
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?
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
COS318 Lec 2 6
A Typical Computer from a Hardware Point of View
CPU
ChipsetMemory
I/O bus
CPU. . .
Network
COS318 Lec 2 7
A Typical Computer System
Operating System Software
Programs and data
MemoryCPU
CPU
...
OSApps
Data
Network
COS318 Lec 2 8
Typical Unix OS Structure
Application
Portable OS Layer
Libraries
Machine-dependent layer
User space/level
Kernel space/level
COS318 Lec 2 9
Typical Unix OS Structure
Application
Portable OS Layer
Libraries
Machine-dependent layer
Written by programmerCompiled by programmerUses function calls
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
COS318 Lec 2 11
Typical Unix OS Structure
Application
Portable OS Layer
Libraries
Machine-dependent layer
“Guts” of system callsAll “high-level” code
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
COS318 Lec 2 13
Another Look: Unix “Onion”
Applications
OS Service
Device
Driver
Hardware
User and Kernelboundary
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?
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
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
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
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
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
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
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
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. . .
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
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
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
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
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?