I/O address space

advertisement
Practical Session No. 12
Input &Output (I/O)
1
I/O Devices
Input/output (I/O) devices provide the
means to interact with the “outside
world”.
 An I/O device can be purely input, purely
output, or both an input and output
device (e.g. mouse, screen, disks).
 Are mostly used to communicate with
the outside world, and to store data.

1.2
Controller

I/O devices are not directly connected to
the system bus. Instead, there is usually an
I/O controller that acts as an interface
between the system and the I/O device.
1.3
Reasons for using an I/O controller

Different devices exhibit different
characteristics. The processor would
spend a lot of time for interaction.
Controller could provide the
necessary low-level commands and
data for proper operation
1.4
Reasons for using an I/O controller

The amount of electrical power used to
send signals on the system bus is very low
Controllers typically contain driver
hardware to send current over long
cables
1.5
I/O Controller

Typically has 3 internal registers:
◦ Data register
◦ Command register
◦ Status register

Processor interacts with an I/O device via
the associated I/O controller
1.6
I/O device interface to the system
1.7
Communication (character output)
Before the processor sends output
character, it has to first check the status
register of the associated controller (e.g.
busy, idle, offline).
 The data register holds the character
(e.g. to be printed).
 The command register determines the
operation requested by the processor
(e.g. send the character in the data
register to the printer).

1.8
Communication (character output)

Sequence of operations:
◦ Wait for the controller to finish the last
command;
◦ Place a character to be printed in the data
register;
◦ Set the command register to initiate the
transfer.
1.9
I/O Ports



An I/O port is the address of a register associated
with an I/O controller.
Two kinds of mapping:
◦ memory-mapped I/O: writing to an I/O port is
similar to writing to a memory address.
◦ I/O address space: separated from the memory
address space.
Special I/O instructions are needed for I/O address
space map. x86 architecture provides two
instructions: in and out, to access I/O ports.
1.10
I/O Ports
x86 provides 64 KB of I/O address space. This
address space can be used for 8-bit,16-bit, and
32-bit-size I/O ports.
 A combination cannot be more than the I/O
address space.
 For example, we can have 64-K 8-bit ports,
32-K 16-bit ports, 16-K 32-bit ports, or
a combination of these that fits the 64-K
address space.

1.11
Register I/O Instructions

The in instruction is used to read data from an
I/O port:
◦ in accumulator, port8 (direct address)
◦ in accumulator, DX
(indirect address)
The out instruction to write data to an I/O port:
◦ out port8, accumulator (direct address)
◦ out DX, accumulator (indirect address)
accumulator must be AL, AX, or EAX.

port8 - access the first 256 ports 00..FF.


1.12
8255 Programmable Peripheral
Interface (PPI) Chip

Provides three 8-bit registers to interface
with I/O devices:
◦
◦
◦
◦
Register
Port address
PA (input port)
PB (output port)
PC (input port)
Command register
60H
61H
62H
63H
1.13
8255 Programmable Peripheral
Interface (PPI) Chip
Keyboard interface is provided by ports
PA and PB7 (MSB bit of PB).
 Keyboard sends an interrupt (to other
interrupt controller) whenever a change
occurs (e.g, key is pressed).
 A scan code of the key whose state has
changed is written in PA.
 Keyboard waits for an acknowledgement
signal from CPU in PB7

1.14
Register Bit Map of 8255

Keyboard scan code if PB7 = 0
◦ PA7 = 0 if a key is depressed
◦ PA7 = 1 if a key is released
◦ PA0–PA6 = key scan code
Configuration switch 1 if PB7 = 1
 PB7 — selects source for PA input

◦ 0— keyboard scan code
◦ 1— configuration switch 1
◦ Also, 1 is used as keyboard acknowledge
1.15
Keyboard Driver
Uses busy wait loop.
 Pressing the esc key terminates the
program.
 Waits for the PA7 bit to go low to
indicate that a key is depressed.
 Scan code is read from PA6 to PA0

1.16
Keyboard Driver
section .data
ESC_KEY EQU 1Bh
KB_DATA EQU 60h
; ASCII code for ESC key
; 8255 port PA
section .text
global _start
_start:
key_up_loop:
;Loops until a key is pressed i.e., until PA7 = 0.
; PA7 = 1 if a key is up.
in AL, KB_DATA ; read keyboard status & scan code
test AL, 80H
; PA7 = 0?
jnz key_up_loop
; if not, loop back
1.17
Keyboard Driver
and AL,7FH
; isolate the scan code
..Translate scan code to ASCII code in AL..
cmp AL,0
je key_down_loop
; ASCII code of 0 => non-interesting key
cmp AL,ESC_KEY
je done
; ESC key---terminate program
display_ch:
; char is now in AL
..Print character AL to screen..
1.18
Keyboard Driver
key_down_loop:
in AL,KB_DATA
test AL, 80H
jz key_down_loop
; PA7 = 1?
; if not, loop back
jmp key_up_loop
done:
..Exit Program..
1.19
Download