Presentation is loading. Please wait.

Presentation is loading. Please wait.

COS318 Lec 21 Operating System Structures Vivek Pai Princeton University.

Similar presentations


Presentation on theme: "COS318 Lec 21 Operating System Structures Vivek Pai Princeton University."— Presentation transcript:

1 COS318 Lec 21 Operating System Structures Vivek Pai Princeton University

2 COS318 Lec 22 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( ); }

3 COS318 Lec 23 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?

4 COS318 Lec 24 Next Reading Assignment Sections 1.6-2.1 inclusive Keep up with what’s on home page I’ll try to remember to remind you Coming up: x86 assembly for Proj 2

5 COS318 Lec 25 About Quiz 0 It didn’t count, so don’t worry “Scores” are 5: 9 people 4: 14 people 3: 14 people 2: 8 people 1: 1 person

6 COS318 Lec 26 Quiz 0 Questions Register – everyone correct? Stack – data structure: last-in, first-out Stack frame – on procedure calls, formal parameters, local variables, return address all get pushed onto stack

7 COS318 Lec 27 Question 4 (22 out of 46) int *p = 0; printf(“val is %d\n”, *p); Type of p is “pointer to integer”. Value of p is zero. Deref of p is getting value at location 0, being read as an integer. Should cause an error on any sane system.

8 COS318 Lec 28 Question 5 (29 out of 46) Func( ) { int *result; CallSomeFunc(result); } Note: value of result can not change What can change is data at location pointed to by result To change value of result, you have to pass address of result Normally, you declare result as a non-pointer, and pass in its address by &result

9 COS318 Lec 29 A Typical Computer from a Hardware Point of View CPU ChipsetMemory I/O bus CPU... Network

10 COS318 Lec 210 A Typical Computer System Operating System Software Programs and data Memory CPU...... OS Apps Data Network

11 COS318 Lec 211 Typical Unix OS Structure Application Portable OS Layer Libraries Machine-dependent layer User space/level Kernel space/level

12 COS318 Lec 212 Typical Unix OS Structure Application Portable OS Layer Libraries Machine-dependent layer Written by programmer Compiled by programmer Uses function calls

13 COS318 Lec 213 Typical Unix OS Structure Application Portable OS Layer Libraries Machine-dependent layer Written by elves Provided pre-compiled Defined in headers Input to linker (compiler) Invoked like functions May be “resolved” when program is loaded

14 COS318 Lec 214 Typical Unix OS Structure Application Portable OS Layer Libraries Machine-dependent layer “Guts” of system calls All “high-level” code

15 COS318 Lec 215 Typical Unix OS Structure Application Portable OS Layer Libraries Machine-dependent layer Bootstrap System initialization Interrupt and exception I/O device driver Memory management Kernel/user mode switching Processor management

16 COS318 Lec 216 Another Look: Unix “Onion” Applications OS Service Device Driver Hardware User and Kernel boundary

17 COS318 Lec 217 What’s An Application? Four parts (“segments”) Code/Text – instructions Data – initialized global variables Stack Heap What’s a stack and heap?

18 COS318 Lec 218 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 running while ( 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

19 COS318 Lec 219 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 CPUI/OCPU I/O CPU I/O CPU

20 COS318 Lec 220 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

21 COS318 Lec 221 x86 Architecture Registers General-purpose registers Segment registers EFLAGS registerEIP (Instruction Pointer register) EAX EBX ECX EDX EBP ESI EDI ESP 31 0 0 15 CS DS SS ES FS GS AX BX CX DX 16-bit 32-bit DI SI BP SP AL AH BL CL DL BH CH DH 8 715

22 COS318 Lec 222 x86 Memory 0 2 32 -1 Byte order is little endian 31 0 8 716 15...... 24 23 Byte 4 Byte 0 Byte 5 Byte 1Byte 2 Byte 6 Byte 3 Byte 7

23 COS318 Lec 223 I/O Device Management Goals –Interactions between devices and applications –Ability to plug in new devices Issues –Efficiency –Fairness –Protection and sharing User 1User n... Library support I/O device I/O device... Driver

24 COS318 Lec 224 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

25 COS318 Lec 225 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 1User n... File system services File...

26 COS318 Lec 226 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 Boot loader OS sector 1 OS sector 2 OS sector n...... Boot loader

27 COS318 Lec 227 System Boot Power on (processor waits until Power Good Signal) Processor jumps on a PC (“Intel Inside”) to address FFFF0h 1M= 1,048,576= 2 20 =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= 2 32 -16

28 COS318 Lec 228 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

29 COS318 Lec 229 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

30 COS318 Lec 230 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?

31 COS318 Lec 231 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


Download ppt "COS318 Lec 21 Operating System Structures Vivek Pai Princeton University."

Similar presentations


Ads by Google