summaryrefslogtreecommitdiff
path: root/util/mRegs.c
blob: 4d8da1177fee4b997071a456ed03093b91c900f3 (plain)
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
/* $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.6 2001/11/16 21:13:34 tsi Exp $ */

#ifdef __NetBSD__
#  include <sys/types.h>
#  include <machine/pio.h>
#  include <machine/sysarch.h>
#else
#  if defined(SVR4) && defined(i386)
#    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
#  if defined(SVR4) && defined(i386)
#    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
#    ifdef linux
#      define SET_IOPL() iopl(3)
#      define RESET_IOPL() iopl(0)
#    else
#      define SET_IOPL() (void)0
#      define RESET_IOPL() (void)0
#    endif
#  endif
#endif

int hex2int(char* str);

int main(int argc, char** argv)
{
    int i, value, index = 0;
    char c, cport;
    char* str;
    unsigned int port, port1 = 0;
    int query = 0;

    if(argc < 2) {
	printf("usage: %s [Cvvxx [Cvvxx]] [Dxx]\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("     where D = Y|y write xx to FCR\n");
        printf("             = Z|z write vv to MSR\n");
        printf("     xx is in hexadecimal\n");
	printf("     vv is in hexadecimal or '?' for query\n");
    }    

    SET_IOPL();

    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;
	  case 'y':
	  case 'Y':
	    cport = 'Y';
	    port = 0x3DA;
            port1 = 0x3CA;
	    break;
	  case 'z':
	  case 'Z':
	    cport = 'Z';
	    port = 0x3C2;
	    port1 = 0x3CC;
	    break;
	  default:
	    continue;
	    break;
	}
	if ((cport != 'Z') && (cport != 'Y')) 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*/
	}		
	if ((cport != 'Z') && (cport != 'Y')) outb(port,value&0xFF);
	if (query) {
	    if ((cport != 'Z') && (cport != 'Y')) 
		printf("%cR%X: 0x%X\n", cport, value & 0xFF, 
		   inb(port+1)&0xFF);
	    else
	        if (cport == 'Z')
		    printf("MSR: 0x%X\n", inb(port1)&0xFF);
		else
		    printf("FCR: 0x%X\n", inb(port1)&0xFF);
	} else {
	    if ((cport != 'Z') && (cport != 'Y')) {
		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);
	    } else {
	        if (cport == 'Z')
		    printf("MSR: 0x%X -> 0x%X\n", inb(port1)&0xFF, value&0xFF);
		else
		    printf("FCR: 0x%X -> 0x%X\n", inb(port1)&0xFF, value&0xFF);
		outb(port, value & 0xFF);
	    }
	}
    }
    RESET_IOPL();
    return 0;
}