//------------------------------------------------------------------- // openuhci.cpp // // This program will demonstrate the 'side-effect' that opening // our '/dev/uhci' device-file has upon a process's IOPL value. // // to compile: $ g++ openuhci.cpp -o openuhci // to execute: $ ./openuhci // // NOTES: Prior installation of a companion module is required. // Conditional compilation accommodates both x86 architectures. // // programmer: ALLAN CRUSE // written on: 19 MAR 2010 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() char devname[] = "/dev/uhci"; // name of the device-file unsigned long flags_reg; // declare global variable int main( int argc, char **argv ) { // transfer flags-register's value to memory-variable #ifdef __i386__ asm(" pushfl \n popl flags_reg "); #else asm(" pushfq \n popq flags_reg "); #endif // show the initial value of this task's IOPL printf( "\nBefore device-file \'%s\' has been opened: \n", devname ); printf( "\n FLAGS=%08lX ", flags_reg ); printf( " IOPL=%lu \n\n", (flags_reg >> 12)&3 ); // invoke a system-call to open the device-file int fd = open( devname, O_RDWR ); if ( fd < 0 ) { perror( devname ); exit(1); } // transfer flags-register's value to memory-variable #ifdef __i386__ asm(" pushfl \n popl flags_reg "); #else asm(" pushfq \n popq flags_reg "); #endif // show the resulting effect on this task's IOPL printf( "\nAfter device-file \'%s\' has been opened: \n", devname ); printf( "\n FLAGS=%08lX ", flags_reg ); printf( " IOPL=%lu \n\n", (flags_reg >> 12)&3 ); }