Slide 1Slide 2Slide 3Slide 4Slide 5Slide 6Slide 7Slide 8Slide 9Slide 10Slide 11Slide 12Slide 13Slide 14Slide 15Slide 16Slide 17Slide 18Slide 19Slide 20Slide 21Slide 22Slide 23Slide 24Slide 25Slide 26Slide 27Slide 28Slide 29Slide 30Slide 31Slide 32Slide 33Slide 34Slide 35Slide 3615-410, S’04- 1 -Hardware OverviewJan. 19, 2004Dave EckhardtDave EckhardtBruce MaggsBruce MaggsL04_Hardware15-410“Computers make very fast, very accurate mistakes.”--Brandon Long15-410, S’04- 1 -SynchronizationToday's classToday's classNot exactly Chapter 2 or 13Project 0Project 0Due tonight at midnightConsider not using a late dayCould be a valuable commodity laterRemember, this is a warm-upReliance on these skills will increase rapidlyUpcomingUpcomingProject 1Lecture on “The Process”15-410, S’04- 1 -SynchronizationPersonal Simics licensesPersonal Simics licensesSimics machine-simulator software is licensedWe have enough “seats” for the classShould work on most CMU-network machinesWill not work on most non-CMU-network machinesOptionsCMU “Address extension” service (non-encrypted VPN)“Personal academic license” for a personal Linux box»locked to your personal machine (MAC address)»apply at www.simics.net (top right of page)15-410, S’04- 1 -SynchronizationSimics on Windows?Simics on Windows?Simics simulator itself is available for Windows15-410 build/debug infrastructure is notOptionsOptionsDual-boot, VMwareUsability via X depends on network latencyPort to cygwin (may be non-trivial)There are those Andrew cluster machines...15-410, S’04- 1 -OutlineComputer hardwareComputer hardwareCPU StateCPU StateFairy tales about system callsFairy tales about system callsCPU context switch (intro)CPU context switch (intro)Interrupt handlersInterrupt handlersInterrupt maskingInterrupt maskingSample hardware device – countdown timerSample hardware device – countdown timer15-410, S’04- 1 -Inside The Box - Historical/LogicalCPUMemoryGraphicsEthernetIDEFloppyUSB15-410, S’04- 1 -Inside The Box - ReallyCPUMemoryAGP GraphicsIDEFloppyUSBNorth BridgeSouth BridgePCIEthernetSCSI15-410, S’04- 1 -CPU StateUser registers (on Planet Intel)User registers (on Planet Intel)General purpose - %eax, %ebx, %ecx, %edxStack Pointer - %espFrame Pointer - %ebpMysterious String Registers - %esi, %edi15-410, S’04- 1 -CPU StateNon-userNon-user registers, a.k.a.... registers, a.k.a....Processor status register(s)Processor status register(s)Currently running: user code / kernel code?Interrupts on / ofVirtual memory on / ofMemory modelsmall, medium, large, purple, dinosaur15-410, S’04- 1 -CPU StateFloating Point Number registersFloating Point Number registersLogically part of “User registers”Sometimes another “special” set of registersSome machines don't have floating pointSome processes don't use floating point15-410, S’04- 1 -Story time!Time for some fairy talesTime for some fairy talesThe getpid() story (shortest legal fairy tale)The read() story (toddler version)The read() story (grade-school version)15-410, S’04- 1 -The Story of getpid()User process is computingUser process is computingUser process calls getpid() library routineLibrary routine executes TRAP(314159)The world changesThe world changesSome registers dumped into memory somewhereSome registers loaded from memory somewhereThe processor has The processor has entered kernel modeentered kernel mode15-410, S’04- 1 -User ModeOperatingSystemProcess 1Process 2CPU15-410, S’04- 1 -Entering Kernel ModeOperatingSystemProcess 1Process 2CPUsave15-410, S’04- 1 -Entering Kernel ModeOperatingSystemProcess 1Process 2CPUEthernetIDEFloppyUSB15-410, S’04- 1 -The Kernel Runtime EnvironmentLanguage runtimes diferLanguage runtimes diferML: no stack, “nothing but heap”C: stack-basedProcessor is more-or-less agnosticProcessor is more-or-less agnosticSome assume/mandate a stackTrap handler builds kernel runtime environmentTrap handler builds kernel runtime environmentDepending on processorDepending on processorSwitches to correct stackSaves registersTurns on virtual memoryFlushes caches15-410, S’04- 1 -The Story of getpid()Process in kernel modeProcess in kernel moderunning->u_reg[R_EAX] = running->u_pid;Return from interruptReturn from interruptProcessor state restored to user mode(modulo %eax)User process returns to computingUser process returns to computingLibrary routine returns %eax as value of getpid()15-410, S’04- 1 -Returning to User ModeOperatingSystemProcess 1Process 2CPUrestore15-410, S’04- 1 -The Story of getpid()What's the getpid() system call?What's the getpid() system call?C function you call to get your process ID“Single instruction” which modifies %eaxPrivileged code which can access OS internal state15-410, S’04- 1 -A Story About read()User process is computingUser process is computingcount = read(7, buf, sizeof (buf));User process “goes to sleep”User process “goes to sleep”Operating system issues disk readOperating system issues disk readTime passesTime passesOperating system copies dataOperating system copies dataUser process “wakes up”User process “wakes up”15-410, S’04- 1 -Another Story About read()P1: read()P1: read()Trap to kernel modeKernel: tell disk: “read sector 2781828”Kernel: tell disk: “read sector 2781828”Kernel: switch to running P2Kernel: switch to running P2Return to user mode - but to P2, not P1!P1 is “blocked in system call”Part-way through driver codeMarked “unable to execute more instructions”P2: compute 1/3 of Mandelbrot setP2: compute 1/3 of Mandelbrot set15-410, S’04- 1 -Another Story About read()Disk: done!Disk: done!Asserts “interrupt request” signalInterrupt to kernel modeRun “disk interrupt handler” codeKernel: switch to P1Kernel: switch to P1Return from interrupt - but to P1, not P2!15-410, S’04- 1 -Interrupt Vector TableHow should CPU handle How should CPU handle this particularthis particular interrupt? interrupt?Disk interrupt invoke disk driverMouse interrupt invoke mouse driverNeed to knowNeed to knowWhere to dump registersoften: property of current process, not of interruptNew register values to load into CPUkey: new program counter, new status register»These define the new execution environment15-410, S’04- 1
View Full Document