10 static int iobfd = -1;
11 static int iowfd = -1;
12 static int iolfd = -1;
13 static int biosfd = -1;
14 static int msrfd = -1;
21 static int ctlfd = -1;
22 static char ctlbuf[Nctlchar];
31 devopen(char* device, int mode)
35 if((fd = open(device, mode)) < 0)
36 error("devopen(%s, %d): %r\n", device, mode);
46 iobfd = devopen("#P/iob", ORDWR);
48 if(pread(iobfd, &data, sizeof(data), port) != sizeof(data))
49 error("inportb(0x%4.4lx): %r\n", port);
54 outportb(long port, uchar data)
57 iobfd = devopen("#P/iob", ORDWR);
59 if(pwrite(iobfd, &data, sizeof(data), port) != sizeof(data))
60 error("outportb(0x%4.4lx, 0x%2.2uX): %r\n", port, data);
69 iowfd = devopen("#P/iow", ORDWR);
71 if(pread(iowfd, &data, sizeof(data), port) != sizeof(data))
72 error("inportw(0x%4.4lx): %r\n", port);
77 outportw(long port, ushort data)
80 iowfd = devopen("#P/iow", ORDWR);
82 if(pwrite(iowfd, &data, sizeof(data), port) != sizeof(data))
83 error("outportw(0x%4.4lx, 0x%2.2uX): %r\n", port, data);
92 iolfd = devopen("#P/iol", ORDWR);
94 if(pread(iolfd, &data, sizeof(data), port) != sizeof(data))
95 error("inportl(0x%4.4lx): %r\n", port);
100 outportl(long port, ulong data)
103 iolfd = devopen("#P/iol", ORDWR);
105 if(pwrite(iolfd, &data, sizeof(data), port) != sizeof(data))
106 error("outportl(0x%4.4lx, 0x%2.2luX): %r\n", port, data);
115 msrfd = devopen("#P/msr", ORDWR);
117 if(pread(msrfd, &data, sizeof(data), port) != sizeof(data))
118 error("rdmsr(0x%4.4lx): %r\n", port);
123 wrmsr(long port, uvlong data)
126 msrfd = devopen("#P/msr", ORDWR);
128 if(pwrite(msrfd, &data, sizeof(data), port) != sizeof(data))
129 error("wrmsr(0x%4.4lx, 0x%2.2lluX): %r\n", port, data);
142 ctlfd = devopen("#v/vgactl", ORDWR);
143 memset(attr, 0, sizeof(attr));
147 nattr = read(ctlfd, ctlbuf, Nctlchar-1);
149 error("vgactlr: read: %r\n");
154 for(nl = strchr(ctlbuf, '\n'); nl; nl = strchr(nl, '\n')){
157 if(p = strchr(vp, ' ')){
159 attr[nattr].attr = vp;
161 error("vgactlr: bad format: <%s>\n", vp);
165 error("vgactlr: bad format: <%s>\n", vp);
167 if(++nattr >= Nattr-2)
168 error("vgactlr: too many attributes: %d\n", nattr);
169 attr[nattr].attr = 0;
178 vgactlr(char* a, char* v)
182 trace("vgactlr: look for %s\n", a);
184 for(i = 0; attr[i].attr; i++){
185 if(strcmp(attr[i].attr, a) == 0){
186 strcpy(v, attr[i].val);
187 trace("vgactlr: value %s\n", v);
191 trace("vgactlr: %s not found\n", a);
197 vgactlw(char* attr, char* val)
203 ctlfd = devopen("#v/vgactl", ORDWR);
206 len = sprint(buf, "%s %s", attr, val);
207 trace("+vgactlw %s\n", buf);
208 if(write(ctlfd, buf, len) != len)
209 error("vgactlw: <%s>: %r\n", buf);
210 trace("-vgactlw %s\n", buf);
224 ctlfd = devopen("#v/vgactl", ORDWR);
225 len = snprint(buf, sizeof(buf), "pcidev %lux", (ulong)p->tbdf);
227 /* ignore error for old kernel */
228 write(ctlfd, buf, len);
234 setpalette(int p, int r, int g, int b)
243 doreadbios(char* buf, long len, long offset)
246 biosfd = open("/dev/realmodemem", OREAD);
248 biosfd = open("#P/realmodemem", OREAD);
251 seek(biosfd, offset, 0);
252 return read(biosfd, buf, len);
256 readbios(long len, long offset)
258 static char bios[0x10000];
259 static long biosoffset;
263 if(biosoffset <= offset && offset+len <= biosoffset+bioslen)
264 return bios+(offset - biosoffset);
266 if(len > sizeof(bios))
267 error("enormous bios len %ld at %lux\n", len, offset);
269 n = doreadbios(bios, sizeof(bios), offset);
271 error("short bios read %ld at %lux got %d\n", len,offset, n);
288 if(doreadbios((char*)buf, size, offset) != size)
289 error("short bios read in dumpbios\n");
291 if(buf[0] != 0x55 || buf[1] != 0xAA){
293 if(doreadbios((char*)buf, size, offset) != size)
294 error("short bios read in dumpbios\n");
295 if(buf[0] != 0x55 || buf[1] != 0xAA){
301 for(i = 0; i < size; i += 16){
302 Bprint(&stdout, "0x%luX", offset+i);
303 for(n = 0; n < 16; n++)
304 Bprint(&stdout, " %2.2uX", buf[i+n]);
305 Bprint(&stdout, " ");
306 for(n = 0; n < 16; n++){
308 if(c < 0x20 || c >= 0x7F)
310 Bprint(&stdout, "%c", c);
312 Bprint(&stdout, "\n");
322 if((v = malloc(nbytes)) == 0)
323 error("alloc: %lud bytes - %r\n", nbytes);
325 return memset(v, 0, nbytes);
329 printitem(char* ctlr, char* item)
335 Bprint(&stdout, "\n");
340 n = Bprint(&stdout, "%s ", ctlr);
341 Bprint(&stdout, "%-*s", 20-n, item);
350 if((curprintindex % 16) == 0 && curprintindex){
351 Bprint(&stdout, "\n");
355 if(curprintindex == 8)
356 Bprint(&stdout, " -");
357 Bprint(&stdout, "%*.2luX", width, data);
361 static char *flagname[32] = {
386 printflag(ulong flag)
392 for(i = 31; i >= 0; i--){
393 if((flag & (1<<i)) == 0)
396 Bprint(&stdout, "%c%s", first, flagname[i]);
398 Bprint(&stdout, "%c0x%x", first, 1<<i);