Readings

Note minor typo on pg. 103
- assembly code, 2nd to last line should read: decr R2

I/O (Device) Management

Software layer:
- application processes: invoke device driver to effect data transfer/control
- device driver: the special piece of code/process responsible for
  coordinating activity between user/system processes and the device
	- provides an abstract API to the user that is similar
	  from one device to another
	- provides device-dependent operations to implement the API

Hardware layer:
- device controller: contains command, status, and data registers
  for interaction with the device
	- command register: load/store
	- status register: busy/idle
	- data registers: hold the actual data being transferred
- device: peripheral to/from which the process wishes to transfer data

How does process synchronize with I/O device?

1. Direct I/O with polling
- process requests device driver to effect the transfer
- CPU is responsible for data transfer
- does a busy-wait for device to complete
- once done, process continues

example: simple 1-byte read from device
	calling process invokes device driver

	Device Driver:
		while (device.CSR == busy) ;
		device.CCR = load;		// starts the device
		while (device.CSR == busy) ;
		data = device.CDR;
		return (data);

2. Interrupt-driven I/O
- process requests device driver to effect the transfer
- when device is done, generates an interrupt
- interrupt handler determines which device and unblocks calling process
- why would we want to do this?

example: the simple 1-byte read made more complicated
	calling process invokes device driver 
	OS blocks caller

	Device Driver: ("top half")
		while (device.CSR == busy) ;
		device.CCR = load;		// starts the device
		save calling process info in device status table
			- device #
			- PID
			- return address
	
	when device is finished operation, it generated an interrupt

	Interrupt Handler:
		device <- device that generated interrupt
		invokes device handler for device

	Device Handler: ("bottom half")
		PID <- process associated with device in device status table
		data = device.CDR;
		copies data into process's address space
		ask process manager to unblock process PID