]> Joshua Wise's Git repositories - netwatch.git/blame - tools/port.c
More ICH2-specific code diked out.
[netwatch.git] / tools / port.c
CommitLineData
98e930a2
JP
1/* port.c
2 * General port I/O utility
3 * NetWatch system management mode administration console
4 *
5 * Copyright (c) 2008 Jacob Potter and Joshua Wise. All rights reserved.
6 * This program is free software; you can redistribute and/or modify it under
7 * the terms found in the file LICENSE in the root of this source tree.
8 *
9 */
10
f603a589
JW
11#include <sys/io.h>
12#include <string.h>
13
14int main(int argc, char **argv)
15{
16 unsigned int port;
17 unsigned char type = 'b';
18 unsigned int datum;
19
20 if (iopl(3) < 0)
21 {
22 perror("iopl");
23 return 1;
24 }
25
26 if ((argc < 2) || (argc > 4))
27 {
28 usage:
29 printf("usage: %s port [b|w|l [datum]]\n", argv[0]);
30 return 2;
31 }
32
33 port = strtoul(argv[1], NULL, 0);
34
35 if (argc > 2)
36 type = *argv[2];
37
38 if (argc > 3)
39 {
40 datum = strtoul(argv[3], NULL, 0);
41 switch (type)
42 {
43 case 'b':
44 datum &= 0xFF;
45 outb(datum, port);
46 printf("Wrote byte 0x%02x to port 0x%04x\n", datum, port);
47 break;
48 case 'w':
49 datum &= 0xFFFF;
50 outw(datum, port);
51 printf("Wrote word 0x%04x to port 0x%04x\n", datum, port);
52 break;
53 case 'l':
54 outb(datum, port);
55 printf("Wrote long 0x%08x to port 0x%04x\n", datum, port);
56 break;
57 default:
58 goto usage;
59 }
60 } else {
61 switch(type)
62 {
63 case 'b':
64 datum = inb(port);
65 printf("Read byte 0x%02x from port 0x%04x\n", datum, port);
66 break;
67 case 'w':
68 datum = inw(port);
69 printf("Read word 0x%04x from port 0x%04x\n", datum, port);
70 break;
71 case 'l':
72 datum = inl(port);
73 printf("Read long 0x%08x from port 0x%04x\n", datum, port);
74 break;
75 default:
76 goto usage;
77 }
78 }
79}
This page took 0.037104 seconds and 5 git commands to generate.