[Home]  [Edit this page]  [Recent Changes]  [Special Pages]  [Help
x86ASMFAQ_Hardware
What are IO ports?

IO ports are one of the three ways of accessing hardware. When you access memory the data is sent or fetched over the memory bus. When you perform IO data is sent or fetched over the IO bus. An IO port is just an "address" on the IO bus. The IO bus is access through four opcodes: out, in, outs, and ins. outs and ins are rarely used. A port is specified in the dx register (so there are only 65536 ports), and the value is read into or from al, ax, or eax.

|Up|

What are memory mapped IO ports?

The second way to access hardware is through memory-mapped IO. There are only 65536 IO ports, which can be a problem for peripherals that need a lot of IO and a problem of simply running out of IO ports. The archetypical example of memory-mapped IO is the video card. High-resolution modes would require millions of ports. Instead, a chunk of the address space for memory is allocated for the peripheral, so when you write to that address you are actually writing to a port on the peripheral.

|Up|

How do I access the keyboard?

You should (or may have to) go through operating system to do this. However, if you are writing an OS, or keyboard driver then the following information will be useful.

IO port 0x60 is the data port for the keyboard. Reading it will give you the scancode of the last key pressed. The highest bit specifies whether the key is being pressed (MSB==0) or released (MSB==1). The scancode is NOT the ASCII code of the key. It needs to be translated, which can be done with a lookup table and the xlat opcode. Also, despite the fact that 7 bits corresponds to 128 possible values, and most extended keyboards only have 101 or 102 keys, certain extended keys don't generate a unique code, but rather generate two codes at a time. IO port 0x64 is the status port for the keyboard. With it you can check whether a key has been pressed (or released) since last time you checked.

The keyboard also takes IRQ 1 and typically generates an interrupt everytime a key is pressed or released. There is a lot more that you can get from and do to the keyboard, however the IRQ and port 0x60 are about all you ever need to know simply to use the keyboard. If you are interested in the other details, chapter 20 of the DOS Art of Assembly covers it in detail.

|Up|

What is DMA?

DMA stands for Direct Memory Access and it is the third way to access hardware. Harddrives, soundcards, and network cards are some of the peripherals that use DMA. DMA allows those peripherals to access memory without having to go through the CPU, in other words, except for setting it up, the CPU doesn't have to do anything and can be doing other stuff while the DMA transfer occurs.

OSRC Miscellaneous Devices

|Up|

What is the PIC?

PIC stands for Programmable Interrupt Controller. With it you can mask out specific hardware interrupts, change what IRQs correspond to what interrupts, and it's always necessary to reset it when handling IRQs.

OSRC Miscellaneous Devices

|Up|

What is the PIT?

PIT stands for Programmable Interval Timer. This controls the rate of the timer interrupt, the DMA refresh of DRAM, and the internal PC speaker, controlled by channel 0, 1, and 2 respectively. Messing with the DRAM refresh rate is probably a very bad idea unless you know what you are doing. However, reprogramming channel 0 (the timer) can be useful in a variety of situations: it can be used as an event generator, a precise real-time timer (perhaps for sampling device input), and it is almost always necessary to reprogram it for multi-threading/tasking. Finally, channel 2 can be used to play sounds from the PC speaker (*shudder*).

OSRC Miscellaneous Devices

|Up|

Where can I get a list of ports?

Ralph Brown's Interrupt List also contains a list of ports and their common usages.

|Up|

last edited (November 25, 2002) by Darius, Number of views: 5984, Current Rev: 5 (Diff)

[Edit this page]  [Page history]  [What links here]  [Discuss this topic]  [Printer Friendly]  

Members

Username:

Password:


Register
Forgot Password?




Programmers Heaven - for .NET, Java, C/C++ and WEB Developers!
© 1996-2008 Community Networks Ltd. All rights reserved. Reproduction in whole or in part, in any form or medium without express written permission is prohibited. Violators of this policy may be subject to legal action. Please read Terms Of Use and Privacy Statement for more information. Development by Tore Nestenius at .NET Consultant - Synchron Data.