]> Joshua Wise's Git repositories - netwatch.git/blob - tools/port.c
Dont' worry about that error.
[netwatch.git] / tools / port.c
1 #include <sys/io.h>
2 #include <string.h>
3
4 int main(int argc, char **argv)
5 {
6         unsigned int port;
7         unsigned char type = 'b';
8         unsigned int datum;
9         
10         if (iopl(3) < 0)
11         {
12                 perror("iopl");
13                 return 1;
14         }
15         
16         if ((argc < 2) || (argc > 4))
17         {
18         usage:
19                 printf("usage: %s port [b|w|l [datum]]\n", argv[0]);
20                 return 2;
21         }
22         
23         port = strtoul(argv[1], NULL, 0);
24         
25         if (argc > 2)
26                 type = *argv[2];
27         
28         if (argc > 3)
29         {
30                 datum = strtoul(argv[3], NULL, 0);
31                 switch (type)
32                 {
33                 case 'b':
34                         datum &= 0xFF;
35                         outb(datum, port);
36                         printf("Wrote byte 0x%02x to port 0x%04x\n", datum, port);
37                         break;
38                 case 'w':
39                         datum &= 0xFFFF;
40                         outw(datum, port);
41                         printf("Wrote word 0x%04x to port 0x%04x\n", datum, port);
42                         break;
43                 case 'l':
44                         outb(datum, port);
45                         printf("Wrote long 0x%08x to port 0x%04x\n", datum, port);
46                         break;
47                 default:
48                         goto usage;
49                 }
50         } else {
51                 switch(type)
52                 {
53                 case 'b':
54                         datum = inb(port);
55                         printf("Read byte 0x%02x from port 0x%04x\n", datum, port);
56                         break;
57                 case 'w':
58                         datum = inw(port);
59                         printf("Read word 0x%04x from port 0x%04x\n", datum, port);
60                         break;
61                 case 'l':
62                         datum = inl(port);
63                         printf("Read long 0x%08x from port 0x%04x\n", datum, port);
64                         break;
65                 default:
66                         goto usage;
67                 }
68         }
69 }
This page took 0.029031 seconds and 4 git commands to generate.