Operating System StructuresGedankenexperimentMechanicsNext Reading AssignmentAbout Quiz 0Quiz 0 QuestionsQuestion 4 (22 out of 46)Question 5 (29 out of 46)A Typical Computer from a Hardware Point of ViewA Typical Computer SystemTypical Unix OS StructureSlide 12Slide 13Slide 14Slide 15Another Look: Unix “Onion”What’s An Application?OS Service ExamplesProcessor ManagementMemory Managementx86 Architecture Registersx86 MemoryI/O Device ManagementWindow SystemsFile SystemBootstrappingSystem BootROM BIOS startup program (1)ROM BIOS startup program (2)ROM BIOS startup program (3)Ways to Develop An Operating SystemCOS318 Lec 2 1Operating System StructuresVivek PaiPrinceton UniversityCOS318 Lec 2 2GedankenexperimentWhat 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 3MechanicsHave 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 4Next Reading AssignmentSections 1.6-2.1 inclusiveKeep up with what’s on home pageI’ll try to remember to remind youComing up: x86 assembly for Proj 2COS318 Lec 2 5About Quiz 0It didn’t count, so don’t worry“Scores” are5: 9 people4: 14 people3: 14 people2: 8 people1: 1 personCOS318 Lec 2 6Quiz 0 QuestionsRegister – everyone correct?Stack – data structure: last-in, first-outStack frame – on procedure calls, formal parameters, local variables, return address all get pushed onto stackCOS318 Lec 2 7Question 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.COS318 Lec 2 8Question 5 (29 out of 46)Func( ) {int *result;CallSomeFunc(result);}Note: value of result can not changeWhat can change is data at location pointed to by resultTo change value of result, you have to pass address of resultNormally, you declare result as a non-pointer, and pass in its address by &resultCOS318 Lec 2 9A Typical Computer from a Hardware Point of ViewCPUChipsetMemoryI/O busCPU. . .NetworkCOS318 Lec 2 10A Typical Computer SystemOperating System SoftwarePrograms and dataMemoryCPUCPU...OSAppsDataNetworkCOS318 Lec 2 11Typical Unix OS StructureApplicationPortable OS LayerLibrariesMachine-dependent layerUser space/levelKernel space/levelCOS318 Lec 2 12Typical Unix OS StructureApplicationPortable OS LayerLibrariesMachine-dependent layerWritten by programmerCompiled by programmerUses function callsCOS318 Lec 2 13Typical Unix OS StructureApplicationPortable OS LayerLibrariesMachine-dependent layerWritten by elvesProvided pre-compiledDefined in headersInput to linker (compiler)Invoked like functionsMay be “resolved” when program is loadedCOS318 Lec 2 14Typical Unix OS StructureApplicationPortable OS LayerLibrariesMachine-dependent layer“Guts” of system callsAll “high-level” codeCOS318 Lec 2 15Typical Unix OS StructureApplicationPortable OS LayerLibrariesMachine-dependent layerBootstrapSystem initializationInterrupt and exception I/O device driverMemory managementKernel/user mode switchingProcessor managementCOS318 Lec 2 16Another Look: Unix “Onion”ApplicationsOS ServiceDeviceDriverHardwareUser and KernelboundaryCOS318 Lec 2 17What’s An Application?Four parts (“segments”)Code/Text – instructionsData – initialized global variablesStackHeapWhat’s a stack and heap?COS318 Lec 2 18OS Service ExamplesExamples 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 otherExamples that can be provided at user level–Read time of the day–Protected user level stuffCOS318 Lec 2 19Processor ManagementGoals–Overlap between I/O and computation–Time sharing–Multiple CPU allocationsIssues–Do not waste CPU resources–Synchronization and mutual exclusion–Fairness and deadlock freeCPU I/O CPUCPUI/OCPUCPUI/OCPUCPUCPUCOS318 Lec 2 20Memory ManagementGoals–Support programs to run–Allocation and management–Transfers from and to secondary storageIssues–Efficiency & convenience–Fairness–ProtectionTape 100MxDisk 10MxMemory 200xL2 10xRegisterCOS318 Lec 2 21x86 Architecture RegistersGeneral-purpose registersSegment registersEFLAGS register EIP (Instruction Pointer register)EAXEBXECXEDXEBPESIEDIESP310015CSDSSSESFSGSAXBXCXDX16-bit 32-bitDISIBPSPALAHBLCLDLBHCHDH8 715COS318 Lec 2 22x86 Memory0232-1Byte order is little endian 3108 716 15...24 23Byte 4Byte 0Byte 5Byte 1Byte 2Byte 6Byte 3Byte 7COS318 Lec 2 23I/O Device ManagementGoals–Interactions between devices and applications–Ability to plug in new devicesIssues–Efficiency–Fairness–Protection and sharingUser 1 User n. . .Library supportI/OdeviceI/Odevice. . .Driver DriverCOS318 Lec 2 24Window SystemsAll in the kernel (Windows)–Pros: efficient?–Cons: difficult to develop new servicesAll at user level–Pros: easy to develop new apps–Cons: protectionSplit between user and kernel (Unix)–Kernel: display driver and mouse driver–User: the restCOS318 Lec 2 25File SystemA typical file system –Open a file with authentication–Read/write data in files–Close a fileCan the services be moved to user level?User 1 User n. . .File system servicesFile File. . .COS318 Lec 2 26BootstrappingPower up a computerProcessor reset–Set to known state–Jump to ROM codeLoad in the boot loader from stable storageJump to the boot loaderLoad the rest of the operating systemInitialize and runBootloaderOSsector 1OSsector 2OSsector n...BootloaderCOS318 Lec 2 27System BootPower 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 programMaps to FFFFFFF0h= 232-16COS318 Lec 2 28ROM BIOS startup program (1)POST (Power-On Self-Test)•If pass then AX:=0; DH:=5 (586: Pentium);•Stop booting if fatal errors, and
View Full Document