i386 Input/Output Address Space


Input/Output

The i386 has a seperate I/O address space in addition to main physical memory. Instead of using instructions that access memory, however, the I/O address space requires that you use the IN and OUT instructions to read and write it.

Using these instructions in assembly is simply a matter of knowing the syntax and register usage. However, communicating these to gcc is definitely not a trivial task. Linux has a pretty decent set of macros for inputting a byte from a port (a port is an I/O address) and outputting a byte to a port. gcc doesn't do type-checking on macros, but their definitions would look like this:

void outb_p(unsigned char val, unsigned int port);  /* pausing version */
void outb(unsigned char val, unsigned int port);
unsigned char inb_p(unsigned int port);             /* pausing version */
unsigned char inb(unsigned int port);
There are two versions of each routine, one that runs at full speed, and one that pauses slightly after each access. Normally, you don't need to use the pausing versions, but there are certain chips and devices that require it (like the PIC). I'll point these out as they come up.

Remember that the header file that defines these macros is Linus Torvald's work, and should be recognized as such.