COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile,...
Transcript of COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile,...
![Page 1: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/1.jpg)
COS 318: Operating Systems
Overview
Kai Li Computer Science Department Princeton University
(http://www.cs.princeton.edu/courses/cos318/)
![Page 2: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/2.jpg)
2
Important Times
Lectures 9/20 Lecture is here Other lectures in Bowen Hall 222
Precepts: Tue: 7:30-8:20pm, 104 CS building Thu (9/20): 7:30-8:20pm, 104 CS building
• Tutorial of Assembly programming and kernel debugging
Project 1 Design review:
• 9/24: 10:30am – 10:30pm (Signup online), 010 Friends center Project 1 due: 9/30 at 11:59pm
To do: Lab partner? Enrollment?
![Page 3: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/3.jpg)
3
Today
Overview of OS functionalities Overview of OS components
![Page 4: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/4.jpg)
4
User’s View: Create An Executable File
gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly Assembler compiles assembly code into relocatable object file Linker links object files into an executable For more information:
Read man page of a.out, elf, ld, and nm Read the document of ELF
foo.c gcc as foo.s foo.o
ld bar.c gcc as bar.s bar.o
libc.a …
a.out
![Page 5: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/5.jpg)
5
Run An Application
On Unix, “loader” does the job Read an executable file Layout the code, data, heap and stack Dynamically link to shared libraries Prepare for the OS kernel to run the application
a.out loader *.o, *.a ld Application
Shared library
![Page 6: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/6.jpg)
6
What’s An Application?
Four segments Code/Text – instructions Data – initialized global
variables Stack Heap
Why? Separate code and data Stack and heap go
towards each other
Stack
Heap
Initialized data
Code
2n -1
0
![Page 7: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/7.jpg)
In More Detail
7
![Page 8: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/8.jpg)
8
Responsibilities
Stack Layout by compiler Allocate/deallocate by process creation (fork) and termination Names are relative off of stack pointer and entirely local
Heap Linker and loader say the starting address Allocate/deallocate by library calls such as malloc() and free() Application program use the library calls to manage
Global data/code Compiler allocate statically Compiler emit names and symbolic references Linker translate references and relocate addresses Loader finally lay them out in memory
![Page 9: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/9.jpg)
9
Hardware View of A Typical Computer
Processor
DRAM I/O bus
Processor . . .
ROM
Cache
Network
Interrupt
![Page 10: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/10.jpg)
10
Software + Hardware View
Memory Processor
Processor
. . .
OS Apps Data
Application
Operating System
ROM
BIOS
Network
![Page 11: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/11.jpg)
11
Software View of Interrupts
Raised by external events Interrupt handler is in the
kernel Switch to another process Overlap I/O with CPU …
Eventually resume the interrupted process
0: 1: …
i: i+1: …
N:
Interrupt handler
![Page 12: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/12.jpg)
12
Typical Unix OS Structure
Application
Libraries
Machine-dependent layer
User level
Kernel level Portable OS Layer
![Page 13: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/13.jpg)
13
Typical Unix OS Structure
Application
Libraries
Machine-dependent layer
Portable OS Layer
User function calls written by programmers and compiled by programmers.
![Page 14: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/14.jpg)
14
Typical Unix OS Structure
Application
Libraries
Machine-dependent layer
Portable OS Layer
• Written by elves • Objects pre-compiled • Defined in headers • Input to linker • Invoked like functions • May be “resolved” when program is loaded
![Page 15: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/15.jpg)
15
Typical Unix OS Structure
Application
Libraries
Machine-dependent layer
Portable OS Layer “Guts” of system calls
![Page 16: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/16.jpg)
Run Multiple Applications
Use multiple windows Browser, shell, powerpoint, word, …
Use command line to run multiple applications % ls –al | grep ‘^d’ % foo & % bar &
16
![Page 17: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/17.jpg)
17
Support Multiple Processes
Application
Libraries
Machine-dependent layer
Portable OS Layer
Application
Libraries
Application
Libraries …
![Page 18: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/18.jpg)
18
OS Service Examples
Examples System calls: fork, exec, exit, … System calls: file open, close, read and write Control the CPU so that users won’t stuck by running
• while ( 1 ) ;
Protection: • Keep user programs from crashing OS • Keep user programs from crashing each other
System calls are typically traps or exceptions System calls are implemented in the kernel When finishing the service, a system returns to the user code
![Page 19: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/19.jpg)
19
Typical Unix OS Structure
Application
Libraries
Machine-dependent layer
Portable OS Layer
• Bootstrap • System initialization • Interrupt and exception • I/O device driver • Memory management • Mode switching • Processor management
![Page 20: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/20.jpg)
20
Applications
Software “Onion” Layers
Libraries
OS Services Device
Driver
Kernel
User and Kernel boundary
HW
![Page 21: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/21.jpg)
21
Today
Overview of OS functionalities Overview of OS components
![Page 22: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/22.jpg)
22
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
CPU
CPU I/O
CPU
CPU
CPU
I/O
![Page 23: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/23.jpg)
23
Memory Management
Goals Support programs to run Allocation and management Transfers from and to
secondary storage Issues
Efficiency & convenience Fairness Protection
Register: 1x
L1 cache: 2-4x
L2 cache: ~10x
L3 cache: ~50x
DRAM: ~200-500x
Disks: ~30M x
Archive storage: >1000M x
![Page 24: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/24.jpg)
24
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/O device
I/O device . . .
Driver Driver
![Page 25: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/25.jpg)
25
File System Goals:
Manage disk blocks Map between files and disk
blocks A typical file system
Open a file with authentication
Read/write data in files Close a file
Issues Reliability Safety Efficiency Manageability
User 1 User n . . .
File system services
File File . . .
![Page 26: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/26.jpg)
26
Window Systems
Goals Interacting with a user Interfaces to examine and
manage apps and the system Issues
Inputs from keyboard, mouse, touch screen, …
Display output from applications and systems
Labor of division • All in the kernel (Windows) • All at user level • Split between user and kernel (Unix)
![Page 27: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/27.jpg)
27
Bootstrap
Power up a computer Processor reset
Set to known state Jump to ROM code
(BIOS is in ROM) Load in the boot loader from
stable storage Jump to the boot loader Load the rest of the operating
system Initialize and run
Question: Can BIOS be on disk?
Boot loader
OS sector 1
OS sector 2
OS sector n
. . .
Boot loader
![Page 28: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/28.jpg)
28
Develop An Operating System
A hardware simulator A virtual machine A kernel debugger
When OS crashes, always goes to the debugger Debugging over the network
Smart people
1972 1998
![Page 29: COS 318: Operating Systems Overview · 4 User’s View: Create An Executable File gcc can compile, assemble, and link together Compiler (part of gcc) compiles a program into assembly](https://reader034.fdocuments.in/reader034/viewer/2022042318/5f07f5ae7e708231d41f9f46/html5/thumbnails/29.jpg)
29
Summary
Overview of OS functionalities Layers of abstractions Services to applications Manage resources
Overview of OS components Processor management Memory management I/O device management File system Window system …