I/O and Operating Systems Flashcards
I/O controller
Acts as a translator between digital (CPU) and analog (device); consists of three basic parts:
○ electronics (convert device’s inputs into digital data the CPU can understand)
○ status register
○ data register(s)
Status register
hardware register containing information about the state of the I/O device
Data register
stores the data being transferred to and from the I/O device
Isolation
In terms of the OS and I/O discussion, the OS isolates user programs from one another. A given user program should “feel” it owns the hardware but the OS actually owns it. All programs “believe” they own hardware but they are really using it in a time-sharing mode controlled by the OS.
○ Makes programs much easier to write.
○ Makes the whole system more stable and secure.
■ A can’t mess with B if it doesn’t even know B exists!
Polling
one of two techniques for working with I/O devices. Polling refers to requesting status from the I/O devices until there is status to be given. Sort of like a “Mom/Dad, are we there yet? How about now? How about now?” model.
Interrupts
second technique for working with I/O devices. The I/O device sends a signal to the OS (called an “interrupt request”) to give its status. When the OS is ready, it deals with the interrupt (usually by invoking something like a trap).
○ Think of how you set up email on your smartphone: you can have the server send it to you (like the interrupt model) or you can constantly check it for new emails (poll the server)!
Video display
○ Entire display is memory-mapped.
○ One memory location per pixel
○ Memory region xC000-xFDFF
■ xC000-xC07F is first row, xC080-xC0FF is second row, etc.
○ To set pixel color, write to memory location.
Adressing a pixel
○ Pixel at vmem[2][5] stored at ■ xC000 + (2 * 128) + 5 ○ In general vmem[y][x] stored at ■ xC000 + (y * 128) + x ○ Note indexing from upper-left corner of the display
TRAP
○ The TRAP instruction is very similar to a JSR but it also elevates the privilege level of the CPU from 0 to 1.
○ The purpose of the TRAP instruction is to allow a program to run in USER program memory.
○ Because of TRAPs limitation, the user can only jump into the first 256 rows of the OS. We shouldn’t install our “TRAPS” starting at x8000.
RTI
○ The RTI instruction is very similar to a RET:
■ It restores the PC back to the value saved in R7 (just like RET).
■ But it also lowers the privilege level of the CPU from 1 to 0.
○ The purpose of the RTI instruction:
■ Allow a subroutine running in the OS program memory to return back to a caller in the USER program memory.
ASCI HEX for A and a
A = 0x41 a = 0x61
First job of OS
Handle I/O
User program ask OS to perform I/O on their behalf
Why I/O only handled by OS
- Standardization: I/O device interface nasty and may of them, programs shouldn’t have to deal with them
- Abstraction: Wrap nasty physical interfaces withnice logical ones. Wrap disk layout in file system interface
- Enforce isolation: Each program thinks it has the hardware to itself. User programs unaware of the other programs. Makes programs much easier to write. Makes system more stable and secure. A can’t mess with B.
2 schemes to interact with I/O devices
- Polling: Check register in a loop. Inefficient
2. Interrupts: Device sends signal to CPU when status changes. CPU can do something different while nothing to do.
Synchronous / Asynchroous
Interrupt driven i/o is asynchronous, takes unbounded time. To us it looks like I/O is synchronous, i.e. happens immediately