interrupts and exceptions today s lecture
play

Interrupts and Exceptions Todays lecture Use addressing to get - PowerPoint PPT Presentation

Interrupts and Exceptions Todays lecture Use addressing to get data from the outside world Data is moved from peripherals to memory Addressing schemes


  1. Interrupts and Exceptions

  2. Today’s lecture � Use ¡addressing ¡to ¡get ¡data ¡from ¡the ¡outside ¡world ¡ � Data ¡is ¡moved ¡from ¡peripherals ¡to ¡memory ¡ � Addressing ¡schemes ¡ � Memory-­‑mapped ¡vs. ¡isolated ¡I/O ¡ � Data ¡movement ¡schemes ¡ � Programmed ¡I/O ¡vs. ¡Interrupt-­‑driven ¡I/O ¡vs. ¡Direct ¡memory ¡access ¡

  3. Most modern operating systems pre-emptively schedule programs Memory ¡ Program ¡ � If ¡a ¡computer ¡is ¡running ¡two ¡programs ¡ Counter ¡ A ¡and ¡B, ¡the ¡O/S ¡will ¡periodically ¡ switch ¡between ¡them ¡ 1. Stop ¡A ¡from ¡running ¡ Register ¡ 2. Copy ¡A ’ s ¡register ¡values ¡to ¡memory ¡ File ¡ 3. Copy ¡B ’ s ¡register ¡values ¡from ¡memory ¡ 4. Start ¡B ¡running ¡ How ¡does ¡the ¡O/S ¡stop ¡ program ¡A? ¡

  4. We can treat most devices “as if” they were memory with an “address” for reading/writing � Many ¡ISAs ¡oMen ¡make ¡this ¡analogy ¡ explicit ¡ ⎯ ¡to ¡transfer ¡data ¡to/from ¡a ¡ parPcular ¡device, ¡the ¡CPU ¡ ¡can ¡access ¡special ¡addresses ¡ � Example : ¡Video ¡card ¡can ¡be ¡accessed ¡via ¡ addresses ¡3B0-­‑3BB, ¡3C0-­‑3DF ¡and ¡A0000-­‑ BFFFF ¡

  5. Most ISAs one of two protocols for addressing devices: memory-mapped I/O or isolated I/O FFFFFFFF Isolated ¡I/O ¡creates ¡a ¡ Memory-­‑mapped ¡I/O ¡ FFFF Memory separate ¡memory ¡ reserves ¡a ¡porPon ¡of ¡ address ¡space ¡for ¡ D000 main ¡memory ¡ I/O C000 devices ¡ addresses ¡for ¡I/O ¡ Main memory Memory 00000000 0000FFFF I/O devices 0000 00000000

  6. Memory-mapped I/O divides main memory addresses into actual memory and devices FFFF � Apple ¡IIe ¡(right) ¡had ¡a ¡16-­‑bit ¡address ¡bus ¡ Memory � Addresses ¡C000-­‑CFFF ¡accessed ¡I/O ¡devices. ¡ D000 I/O C000 � No ¡actual ¡main ¡memory ¡at ¡C000-­‑CFFF ¡ � All ¡other ¡addresses ¡reference ¡main ¡memory. ¡ � I/O ¡addresses ¡are ¡shared ¡by ¡many ¡peripherals. ¡ � C010 ¡→ ¡keyboard ¡ ¡ � C030 ¡→ ¡speaker ¡ Memory � Some ¡devices ¡may ¡need ¡several ¡I/O ¡addresses. ¡ 0000

  7. We use control and addressing to determine when data goes to memory or devices Control Address Data Memory Hard disks CD-ROM Network Display CPU � Each ¡device ¡has ¡to ¡monitor ¡the ¡address ¡bus ¡to ¡see ¡if ¡it ¡is ¡the ¡target. ¡ (Apple ¡IIe ¡example) ¡ � Main ¡memory ¡ignores ¡any ¡transacPons ¡with ¡addresses ¡C000-­‑CFFF. ¡ ¡ � The ¡speaker ¡only ¡responds ¡when ¡C030 ¡appears ¡on ¡the ¡address ¡bus. ¡

  8. Isolated I/O creates two separate address spaces and needs two sets of instructions FFFFFFFF � Example ¡(x86): ¡ � regular ¡instrucPons ¡like ¡MOV ¡reference ¡RAM ¡ � special ¡instrucPons ¡IN ¡and ¡OUT ¡access ¡a ¡ Main separate ¡I/O ¡address ¡space ¡ memory � An ¡address ¡could ¡refer ¡to ¡ either ¡main ¡memory ¡ or ¡ an ¡I/O ¡device, ¡depending ¡on ¡the ¡instrucPon ¡used ¡ 00000000 0000FFFF I/O devices 00000000

  9. iclicker MIPS ¡provides ¡the ¡following ¡instrucPons ¡ ¡for ¡managing ¡memory: ¡ load word, load halfword, load byte, store word, store halfword and ¡ store byte . ¡ ¡ ¡ Which ¡I/O ¡addressing ¡method ¡does ¡MIPS ¡use? ¡ a) Memory-­‑mapped ¡I/O ¡ b) Isolated ¡I/O ¡

  10. MIPS/SPIMbot uses memory-mapped I/O � Examples ¡ lw $reg, 0xffff0020($0) # gets SPIMbot x-coord sw $reg, 0xffff0010($0) # sets bot speed = $reg ¡ � Some ¡control ¡commands ¡require ¡a ¡sequence ¡of ¡instrucPons ¡ sw $reg, 0xffff0014($0) li $t0, 1 $t0, 0xffff0018 # sets bot angle = $reg ¡ sw ¡

  11. Example SPIMbot commands What ¡ How ¡ get ¡SPIMbot’s ¡current ¡x/y-­‑ lw ¡from ¡ 0xffff0020 (x) ¡ ¡ coordinate ¡ lw ¡from ¡ 0xffff0024 (y) set ¡SPIMbot’s ¡angle ¡ sw the ¡angle ¡to ¡ 0xffff0014 (absolute) ¡ sw 1 to ¡ 0xffff0018 set ¡SPIMbot’s ¡angle ¡ sw ¡the ¡angle ¡to ¡ 0xffff0014 (relaPve) ¡ sw 0 to ¡ 0xffff0018 set ¡SPIMbot’s ¡velocity ¡ sw ¡a ¡number ¡between ¡ -10 and ¡ 10 ¡to ¡ 0xffff0010 read ¡the ¡current ¡Pme ¡ lw from ¡ 0xffff001c request ¡a ¡Pmer ¡interrupt ¡ sw ¡the ¡desired ¡(future) ¡Pme ¡to ¡ 0xffff001c acknowledge ¡a ¡bonk ¡ sw any ¡value ¡to ¡ 0xffff0060 interrupt ¡ acknowledge ¡a ¡Pmer ¡ sw any ¡value ¡to ¡ 0xffff006c interrupt ¡

  12. SPIMbot coordinate system X=0 ¡ X=300 ¡ Y=0 ¡ 270 ◦ ¡ 180 ◦ ¡ 0 ◦ ¡ 90 ◦ ¡ Y=300 ¡

  13. What will SPIMbot do? Suppose ¡we ¡want ¡SPIMbot ¡to ¡travel ¡north. ¡Which ¡of ¡the ¡following ¡ sequences ¡of ¡instrucPons ¡will ¡always ¡cause ¡SPIMbot ¡to ¡travel ¡north? ¡ ¡ a) ¡ b) ¡ li $a0, 270 li $a0, 270 sw $a0, 0xffff0014 ($zero) sw $a0, 0xffff0014 ($zero) sw $zero, 0xffff0018 ($zero) li $t0, 1 sw $t0, 0xffff0018 ($zero) c) ¡ d) ¡ li $a0, 270 li $a0, 270 sw $a0, 0xffff0018 ($zero) sw $a0, 0xffff0018 ($zero) sw $zero, 0xffff0014 ($zero) li $t0, 1 sw $t0, 0xffff0014 ($zero)

  14. In programmed I/O, the program or OS is responsible for transmitting data CPU sends read � CPU ¡makes ¡a ¡request ¡and ¡then ¡waits ¡ request to device (loops) ¡unPl ¡device ¡is ¡ready ¡(loop ¡1) ¡ Not ready � Buses ¡are ¡typically ¡32-­‑64 ¡bits ¡wide, ¡so ¡loop ¡ CPU waits for device 2 ¡is ¡repeated ¡for ¡large ¡transfers ¡ Ready CPU reads word � Also ¡called ¡polling ¡ from device CPU writes word to main memory No Done? Yes

  15. Programmed I/O is generally bad � A ¡lot ¡of ¡CPU ¡Pme ¡is ¡needed ¡for ¡this! ¡ � most ¡devices ¡ are ¡slow ¡compared ¡to ¡CPUs ¡ � CPU ¡also ¡ “ wastes ¡Pme ” ¡doing ¡actual ¡data ¡transfer ¡ � CPU ¡must ¡ask ¡repeatedly ¡ � CPU ¡must ¡ask ¡oMen ¡enough ¡to ¡ensure ¡that ¡it ¡doesn ’ t ¡miss ¡anything, ¡ which ¡means ¡it ¡can ’ t ¡do ¡much ¡else ¡while ¡waiPng ¡

  16. Interrupt-driven I/O transfers data when devices interrupt the processor CPU sends read request to device Interrupt-­‑driven ¡I/O ¡solves ¡the ¡inefficiencies ¡of ¡ Programmed ¡I/O ¡ CPU does other stuff . . . � Instead ¡of ¡waiPng, ¡the ¡CPU ¡conPnues ¡with ¡other ¡ CPU receives interrupt calculaPons ¡ � The ¡device ¡interrupts ¡the ¡processor ¡when ¡the ¡data ¡is ¡ ready ¡ CPU reads word from device � CPU ¡sPll ¡does ¡the ¡data ¡transfer ¡ CPU writes word to main memory No Done? Yes

  17. Direct memory access (DMA) parallelizes data transfer with a separate controller � The ¡DMA ¡controller ¡is ¡a ¡simple ¡processor ¡which ¡ CPU sends read manages ¡I/O ¡and ¡memory ¡data ¡transfers ¡ ¡ request to DMA unit � The ¡CPU ¡asks ¡the ¡DMA ¡controller ¡to ¡transfer ¡data ¡between ¡ a ¡device ¡and ¡main ¡memory. ¡AMer ¡that, ¡the ¡CPU ¡can ¡ conPnue ¡with ¡other ¡tasks ¡ CPU does other stuff . . . � The ¡DMA ¡controller ¡issues ¡requests ¡to ¡the ¡right ¡I/O ¡device, ¡ CPU receives DMA waits, ¡and ¡manages ¡the ¡transfers ¡between ¡the ¡device ¡and ¡ interrupt main ¡memory ¡ � Once ¡finished, ¡the ¡DMA ¡controller ¡interrupts ¡the ¡CPU ¡

  18. Example of data transfer using DMA System bus CPU Memory DMA unit Hard disks CD-ROM Network Since ¡both ¡the ¡processor ¡and ¡the ¡DMA ¡controller ¡may ¡need ¡to ¡access ¡ main ¡memory, ¡some ¡form ¡of ¡arbitraPon ¡is ¡required ¡

  19. Side Note: MIPS ¡uses ¡a ¡co-­‑processor ¡(a ¡separate ¡datapath ¡with ¡a ¡ separate ¡set ¡of ¡registers) ¡to ¡help ¡handle ¡interrupts ¡

  20. More details on interrupts � Examples : ¡I/O ¡device ¡needs ¡ahenPon, ¡Pmer ¡interrupts ¡to ¡mark ¡cycle ¡ � All ¡interrupts ¡are ¡recoverable: ¡interrupted ¡program ¡should ¡resume ¡ aMer ¡the ¡interrupt ¡is ¡handled ¡ � OS ¡responsible ¡to ¡do ¡the ¡right ¡thing, ¡such ¡as: ¡ � Save ¡the ¡current ¡state ¡and ¡shut ¡down ¡the ¡hardware ¡devices ¡ � Find ¡and ¡load ¡the ¡correct ¡data ¡from ¡the ¡hard ¡disk ¡ � Transfer ¡data ¡to/from ¡the ¡I/O ¡device, ¡or ¡install ¡drivers ¡

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend