Main Page   Class Hierarchy   Alphabetical List   Data Structures   File List   Data Fields   Globals  

debug.cc

Go to the documentation of this file.
00001 /*
00002    debug.cc
00003 
00004    A pathetic copy of the DOS debug program. OK for testing io ports.
00005    There is probably a better shareware version somewhere.
00006    Always compile with optimization so inb outb work.
00007 
00008    Modification History:
00009 
00010    13-Jan-2000 WPS created.
00011 */
00012 
00013 
00014 #ifndef linux
00015 
00016 #include <stdio.h>
00017 #include <stdlib.h>
00018 
00019 int main()
00020 {
00021   printf("debug doesn't work on this platform.\n");
00022   exit(-1);
00023 }
00024 
00025 #else
00026 
00027 #include <unistd.h>
00028 #include <sys/io.h>             // ioperm(), inb outb, inw outw
00029 #include <sys/types.h>
00030 #include <stdio.h>
00031 #include <string.h>
00032 #include <stdlib.h>
00033 #include <signal.h>
00034 
00035 
00036 int main(int argc, char **argv)
00037 {
00038   if(geteuid() && getuid())
00039     {
00040       printf("Must be root for this program to work.\n");
00041       exit(-1);
00042     }
00043 
00044   if(-1 == iopl(3))
00045     {
00046       printf("Can't set privaledge level.\n");
00047     }
00048   printf("Commands: (Use 0x for Hexidecimal).\n");
00049   printf("\t inb <port>\n");
00050   printf("\t outb <port> <value>\n");
00051   printf("\t inw <port>\n");
00052   printf("\t outw <port> <value>\n");
00053   printf("\t quit\n\n");
00054 
00055     unsigned long port;
00056   char cval;
00057   short sval;
00058   unsigned long uval;
00059 
00060   while(1)
00061     {
00062       printf("\ndebug>");
00063       char buf[200];
00064       fgets(buf,200,stdin);
00065       char *cmd = buf;
00066       while(*cmd == ' ')
00067         {
00068           cmd++;
00069         }
00070       if(*cmd == 0 || *cmd == '\r' || *cmd == '\n')
00071         {
00072           continue;
00073         }
00074       if(!strncmp(cmd,"inb",3))
00075         {
00076           port = strtol(cmd+4,0,0);
00077           ioperm(port,1,1);
00078           cval = inb(port);
00079           ioperm(port,1,0);
00080           uval = ((unsigned long) cval) & 0xFF;
00081           printf("0x%X\n",uval);
00082         }
00083       else if(!strncmp(cmd,"outb",4))
00084         {
00085           char *e1;
00086           port = strtol(cmd+5, &e1,0);
00087           cval = strtol(e1+1,0,0);
00088           uval = ((unsigned long) cval) & 0xFF;
00089           printf("0x%X 0x%X\n",port,uval);
00090           ioperm(port,1,1);
00091           outb(cval,port);
00092           ioperm(port,1,0);
00093         }
00094       else if(!strncmp(cmd,"inw",3))
00095         {
00096           port = strtol(cmd+4,0,0);
00097           ioperm(port,2,1);
00098           sval = inw(port);
00099           ioperm(port,2,0);
00100           uval = ((unsigned long) sval) & 0xFFFF;
00101           printf("0x%X\n",uval);
00102         }
00103       else if(!strncmp(cmd,"outw",4))
00104         {
00105           char *e1;
00106           port = strtol(cmd+5, &e1,0);
00107           sval = strtol(e1+1,0,0);
00108           uval = ((unsigned long) sval) & 0xFFFF;
00109           printf("0x%X 0x%X\n",port,uval);
00110           ioperm(port,2,1);
00111           outw(sval,port);
00112           ioperm(port,2,0);
00113         }
00114       else if(!strncmp(cmd,"quit",4))
00115         {
00116           break;
00117         }
00118     }
00119 }
00120 #endif

Generated on Sun Dec 2 15:27:36 2001 for EMC by doxygen1.2.11.1 written by Dimitri van Heesch, © 1997-2001