//------------------------------------------------------------------- // showidt.cpp // // This application uses the '/dev/ram' device special file to // read the processor's Interrupt Descriptor Table and display // its entries in hexadecimal format. (The virtual address of // the IDT in kernel space is obtained using an "unprivileged" // 80x86 processor instruction.) // // NOTE: Written and tested using Linux kernel version 2.4.20. // // programmer: ALLAN CRUSE // written on: 16 MAR 2003 //------------------------------------------------------------------- #include // for printf(), perror() #include // for open() #include // for exit() #include // for read(), close() #define N_VECTORS 256 #define TASK_SIZE 0xC0000000 #define virt_to_phys(vaddr) ( vaddr - TASK_SIZE ) char devname[] = "/dev/ram"; unsigned short idtr[3]; unsigned long idtbase, idtsize; unsigned long long idt[ N_VECTORS ]; int main( int argc, char **argv ) { // open device file for reading physical memory int fd = open( devname, O_RDONLY ); if ( fd < 0 ) { perror( "open" ); exit(1);} // get virtual address of the processor's IDT asm(" sidt idtr " ); idtbase = *(unsigned long*)(idtr+1); // read the table of interrupt descriptors lseek( fd, virt_to_phys(idtbase), SEEK_SET ); int nbytes = read( fd, idt, sizeof(idt) ); if ( nbytes < sizeof(idt) ) { perror( "read" ); exit(1); } // display the descriptors in hexadecimal format printf( "\n\nTABLE OF INTERRUPT DESCRIPTORS %20s", " " ); printf( "(IDTR=%04X%04X-%04X)\n", idtr[2], idtr[1], idtr[0] ); for (int i = 0; i < N_VECTORS; i++) { if ( ( i % 4 ) == 0 ) printf( "\n%02X: ", i ); printf( "%016llX ", idt[ i ] ); } printf( "\n\n" ); // close the device file close( fd ); }