IO Ports
On x86_64 since its roots back down to the original 8080 there is a separate address space specific for IO operations to certain peripherals like the PIC, PIT, PS/2, etc. On other architectures and modern x86_64 peripherals everything will be done using MMIO but when making an OS it will be easier to use IO ports and to use legacy hardware as it tends to be simpler to setup
Interacting with port IO space
For the most part these two functions should be all that is needed to send and get data from port IO although there are more ways to do this although there are more ways to do this
void outb(unsigned short port, unsigned char val) {
__asm__ volatile ( "outb %0, %1" : : "a"(val), "Nd"(port) );
}
unsigned char inb(unsigned short port) {
unsigned char ret;
__asm__ volatile ( "inb %1, %0"
: "=a"(ret)
: "Nd"(port) );
return ret;
}
Common Ports
These ports are almost always going to exist for these devices in a standard x86_64 system. Others addresses in port IO space may exist but they would have to be found out in other ways
| Ports | Usage |
|---|---|
0x0020-0x0021 |
Master Programmable Interrupt Controller |
0x00A0-0x00A1 |
Slave Programmable Interrupt Controller |
0x0040-0x0047 |
Programmable Interval Timer |
0x0060-0x0064 |
PS/2 Controller |
0x03F8-0x03FF |
Serial Port 1 |