1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
|
/* $XConsortium: mRegs.c /main/2 1996/10/27 11:49:43 kaleb $ */
/* $XFree86: xc/programs/Xserver/hw/xfree86/drivers/chips/util/mRegs.c,v 1.4 2000/04/28 18:19:23 eich Exp $ */
#ifdef __NetBSD__
# include <sys/types.h>
# include <machine/pio.h>
# include <machine/sysarch.h>
#else
# ifdef SVR4
# include <sys/types.h>
# ifdef NCR
/* broken NCR <sys/sysi86.h> */
# define __STDC
# include <sys/sysi86.h>
# undef __STDC
# else
# include <sys/sysi86.h>
# endif
# ifdef SVR4
# if !defined(sun)
# include <sys/seg.h>
# endif
# endif
# include <sys/v86.h>
# if defined(sun)
# include <sys/psw.h>
# endif
# endif
# include "AsmMacros.h"
#endif /* NetBSD */
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef __NetBSD__
# define SET_IOPL() i386_iopl(3)
# define RESET_IOPL() i386_iopl(0)
#else
# ifdef SVR4
# ifndef SI86IOPL
# define SET_IOPL() sysi86(SI86V86,V86SC_IOPL,PS_IOPL)
# define RESET_IOPL() sysi86(SI86V86,V86SC_IOPL,0)
# else
# define SET_IOPL() sysi86(SI86IOPL,3)
# define RESET_IOPL() sysi86(SI86IOPL,0)
# endif
# else
# ifndef Lynx
# define SET_IOPL() iopl(3)
# define RESET_IOPL() iopl(0)
# else
# define SET_IOPL() 0
# define RESET_IOPL() 0
# endif
# endif
#endif
int hex2int(char* str);
int main(int argc, char** argv)
{
int i, value, index;
char c, cport;
char* str;
unsigned int port;
int query = 0;
if(argc < 2) {
printf("usage: %s Cvvxx [Cvvxx]\n",argv[0]);
printf(" where C = A|a write vv to ARxx\n");
printf(" = C|c write vv to CRxx\n");
printf(" = F|f write vv to FRxx (6555x only)\n");
printf(" = G|g write vv to GRxx\n");
printf(" = M|m write vv to MRxx (6555x only)\n");
printf(" = S|s write vv to SRxx\n");
printf(" = X|x write vv to XRxx\n");
printf(" xx is in hexadecimal\n");
printf(" vv is in hexadecimal or '?' for query\n");
}
if(SET_IOPL())
return -1;
for(i = 1; i < argc; i++){
value = 0;
str = argv[i];
c = *str++;
switch (c) {
case 'f':
case 'F':
cport = 'F';
port = 0x3D0;
break;
case 'c':
case 'C':
cport = 'C';
port = 0x3D4;
break;
case 'x':
case 'X':
cport = 'X';
port = 0x3D6;
break;
case 'g':
case 'G':
cport = 'G';
port = 0x3CE;
break;
case 'a':
case 'A':
cport = 'A';
port = 0x3C0;
break;
case 's':
case 'S':
cport = 'S';
port = 0x3C4;
break;
case 'm':
case 'M':
cport = 'M';
port = 0x3D2;
break;
default:
continue;
break;
}
index = inb(port);
while (c = *str++){
if (c == '?') {
query = 1;
}
if(c >= '0' && c <= '9')
value = (value << 4) | (c - '0'); /*ASCII assumed*/
else if(c >= 'A' && c < 'G')
value = (value << 4) | (c - 'A'+10); /*ASCII assumed*/
else if(c >= 'a' && c < 'g')
value = (value << 4) | (c - 'a'+10); /*ASCII assumed*/
}
outb(port,value&0xFF);
if (query) {
printf("%cR%X: 0x%X\n", cport, value & 0xFF,
inb(port+1)&0xFF);
} else {
printf("%cR%X: 0x%X -> 0x%X\n", cport, value & 0xFF,
inb(port+1)&0xFF, (value&0xFF00)>>8);
outw(port, value);
outb(port, index &0xFF);
}
}
RESET_IOPL();
return 0;
}
|