/*==================== basic IO access : port_write_then_read.c =============== PURPOSE - show port write and read. - usage ./port_write_then_read port_num value */ #include #include #include #include #include int main( int argc, char *argv[] ) { if ( argc != 3 ) { cerr << "usage: " << argv[ 0 ] << " port_num write_value\n" << "Both numbers are in hexadecimal\n"; exit( 1 ); } // Output a byte to a port: int port_num = strtol( argv[ 1 ], NULL, 16 ) & 0x3ff; char value = strtol( argv[ 2 ], NULL, 16 ) & 0xff; outb( value, port_num ); // Read the data byte port: cout << showbase << "Wrote " << hex << value << " to port " << port_num << ", read back " << ( unsigned ) inb( port_num ) << endl; exit( 0 ); }