//------------------------------------------------------------------- // nicregs.cpp // // This program utilizes our 'mmap8139.c' device-driver to map // the RealTek 8139 network interface registers to user-space. // // It is assumed that the System Administrator has created the // required character-mode device-node in the '/dev' directory // before the user attempts to execute this program: // // root# mknod /dev/nic c 98 0 // root# chmod a+rw /dev/nic // // programmer: ALLAN CRUSE // written on: 04 APR 2005 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for mmap(), munmap() char devname[] = "/dev/nic"; int main( int argc, char **argv ) { // open the device-file int fd = open( devname, O_RDONLY ); if ( fd < 0 ) { perror( devname ); exit(1); } // map the device's io-memory to user-space int prot = PROT_READ; int flag = MAP_SHARED; int size = 0x100; int base = 0; void *vm = mmap( NULL, size, prot, flag, fd, 0 ); if ( vm == MAP_FAILED ) { perror( "mmap" ); exit(1); } // display the contents of io-memory in hexadecimal format printf( "\n\nRealTek 8139 Registers mapped at %p \n", vm ); unsigned long *lp = (unsigned long *)vm; for (int i = 0; i < 64; i++) { if ( ( i % 8 ) == 0 ) printf( "\n%02X: ", i*4 ); printf( "%08lX ", lp[ i ] ); } printf( "\n\n\n" ); }