input and output how things get into and out of the cpu
DESCRIPTION
Input and Output How things get into and out of the CPU. Computer System. I/O Devices. Keyboard User presses ‘A’ key - > ‘a’ ASCII code is 0x61 Keyboard sends this on wires 1 for start, 8-bits of data, 0 for stop ‘a’ is: 1011000010 Buffer at computer catches these bits. I/O Devices. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/1.jpg)
Input and Output
How things get into and out of the CPU
![Page 2: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/2.jpg)
2CMPE12c Gabriel Hugh Elkaim
Computer System
![Page 3: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/3.jpg)
3CMPE12c Gabriel Hugh Elkaim
I/O Devices
Keyboard
• User presses ‘A’ key -> ‘a’• ASCII code is 0x61• Keyboard sends this on wires• 1 for start, 8-bits of data, 0 for stop• ‘a’ is: 1011000010• Buffer at computer catches these bits
![Page 4: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/4.jpg)
4CMPE12c Gabriel Hugh Elkaim
Displays
• Character display works with the reverse process (sort of)
• Most displays are “bit mapped”
I/O Devices
Printers
• Just like a display but now being “printed” to paper, not a screen.
• Again, most printers are now “bit mapped” verses character.
![Page 5: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/5.jpg)
5CMPE12c Gabriel Hugh Elkaim
I/O Devices
Hard Disk
•A spinning disk (4600, 5200, 7200, 10000+ RPM)•2 – 240 GB and growing FAST•Magnetic and read/write (like tape)•Both sides •Usually a stack of platters•Disk access
•Electronic speeds are in the nanoseconds (10-9 sec)•Disk speeds are in the milliseconds (10-3 sec)•Why use a disk?
Queuing Seek Rotation Transfer
Depends
10ms 10ms 1ms
![Page 6: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/6.jpg)
6CMPE12c Gabriel Hugh Elkaim
I/O Devices
Questions
• How does CPU ask for a char to be printed?• Which printer?• Which display? Who’s?• When is printer ready for the next char?• When does keyboard have the next char?• What about the million times slower?
![Page 7: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/7.jpg)
7CMPE12c Gabriel Hugh Elkaim
MAL I/O
putc $s0 is
# address of char is in $s0lb $4, ($s0) # $4 char to be printedaddi $2, $0, 11 # this syscall is like:syscall # jal operating_system_function
getc $s0 is
addi $2, $0, 12 # this syscall is like:syscall # jal operating_system_function
# returns with char read in $2
![Page 8: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/8.jpg)
8CMPE12c Gabriel Hugh Elkaim
MAL I/O
•Don’t use “jal” because•OS doesn’t trust user to provide the correct address•Want to switch into OS mode, where more thingsare allowed
•Allowed by what?•OS catches “syscall” and uses value in $2 to determine what to do•OS will not allow (or should not)
•Users to read each other’s keyboards•Users to send infinite jobs to printers (well, actually…)
![Page 9: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/9.jpg)
9CMPE12c Gabriel Hugh Elkaim
MAL I/O
How does the OS do I/O?
What instructions cause an I/O?•Could have special instructions•Hard to anticipate all possibilities
Solutions•overload load and store•Memory-mapped I/O
![Page 10: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/10.jpg)
10CMPE12c Gabriel Hugh Elkaim
Memory Mapped IO
• Idea is to place devices other than RAM chips at physical address locations.
• This way to access IO devices you use the same load and store instructions.
![Page 11: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/11.jpg)
11CMPE12c Gabriel Hugh Elkaim
Memory Mapped I/O
Design hardware and software to recognize certain addresses
Real Memory - RAM
0x00000000
0xFFFF0000
0xFFFF0008
0xFFFF0010
From keyboard
To display
Set some labels and use those to access devices
keyboardData equ 0xFFFF0008displayData equ 0xFFFF0010
![Page 12: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/12.jpg)
12CMPE12c Gabriel Hugh Elkaim
Memory Mapped I/O
CPU MEM
Keyboard Buffer0xFFFF0008
Display Buffer0xFFFF0010
•Devices on bus watch for their address•getc
operating_system_function_12: # getc char and put it in $2lw $2, KeyboardData“return from syscall”
•putcoperating_system_function_11: # putc char, where char is in $4
sw $2, DisplayData“return from syscall”
•But is there a new char to read?•But is the display done with the last char?
System bus
![Page 13: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/13.jpg)
13CMPE12c Gabriel Hugh Elkaim
Device Status
Need I/O device status to coordinate
Set up some more labelsKeyboardStatusequ 0xFFFF000cDisplayStatus equ 0xFFFF0014
Assume Status is word where MSB==1 means ready.
0x00000000
0xFFFF0000
0xFFFF00080xFFFF000c
DATA from keyboardSTATUS from keyboard
0xFFFF00100xFFFF0014
DATA to Display
STATUS from Display
Real Memory - RAM
![Page 14: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/14.jpg)
14CMPE12c Gabriel Hugh Elkaim
Device Status
GETC
Operating_system_function_12: # getc char and put it in $2WaitLoop12:
lw $14, KeybaordStatusbgez $14, WaitLoop12 # keep waiting if $14 non-negativelw $2, KeyboardData # same as before“return from syscall”
PUTCOperating_system_function_11: # putc char, where char is in $4WaitLoop12:
lw $14, DisplayStatusbgez $14, WaitLoop11 # keep waiting if $14 non-negativesw $4, DisplayData # same as before“return from syscall”
MAL OS calls
![Page 15: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/15.jpg)
15CMPE12c Gabriel Hugh Elkaim
Device Status
Polling (non-interrupt) I/O
GETCHARGETCHAR:
LDAA SCSR ; status registerANDA #$20 ; rdrf bit maskBEQ GETCHAR ; loop if rdrf = 0LDAA SCDR ; read dataRTS
OUTCHAROUTCHAR:
LDAB SCSR ; load sci status registerBITB #$80 ; tdre bitBEQ OUTCHAR ; loop intil tdre = 0STAA SCDR ; write character to portRTS
HC11
![Page 16: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/16.jpg)
16CMPE12c Gabriel Hugh Elkaim
Device Status
•How much time is spent spinning?•A putc or getc is less than 10 instructions, or 10ns on a modern processor
•Mechanical devices take milliseconds•Almost all time is spent spinning
•Must do useful work while waiting•Periodically poll devices and send
characters when ready
![Page 17: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/17.jpg)
17CMPE12c Gabriel Hugh Elkaim
Polling I/O
•The OS must check regularly (poll) for ready devices•Perhaps once a millisecond
•If ready, then OS services device•Keyboard: transfer character and put on queue
•Display: transmit character to the graphics HW
•Problems:•How often to poll?•How does the OS code get run?•What happens to the user program?•Is there a better solution?
![Page 18: Input and Output How things get into and out of the CPU](https://reader035.vdocuments.us/reader035/viewer/2022070409/5681449a550346895db14523/html5/thumbnails/18.jpg)
18CMPE12c Gabriel Hugh Elkaim
Questions?