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