1999-01-01 00:41:46 +00:00
|
|
|
/*
|
2001-10-13 16:37:16 +00:00
|
|
|
isadump.c - isadump, a user-space program to dump ISA registers
|
2004-04-19 18:02:10 +00:00
|
|
|
Copyright (C) 2000 Frodo Looijaard <frodol@dds.nl>, and
|
2000-05-06 17:49:53 +00:00
|
|
|
Mark D. Studebaker <mdsxyz123@yahoo.com>
|
2004-04-19 18:02:10 +00:00
|
|
|
Copyright (C) 2004 The lm_sensors group
|
1999-01-01 00:41:46 +00:00
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program; if not, write to the Free Software
|
|
|
|
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
2001-10-13 16:37:16 +00:00
|
|
|
/*
|
|
|
|
Typical usage:
|
|
|
|
isadump 0x295 0x296 Basic winbond dump using address/data registers
|
|
|
|
isadump 0x295 0x296 2 Winbond dump, bank 2
|
2004-04-19 18:02:10 +00:00
|
|
|
isadump 0x2e 0x2f 0x09 0x07 Super-I/O, logical device 9
|
2001-10-13 16:37:16 +00:00
|
|
|
isadump -f 0x5000 Flat address space dump like for Via 686a
|
|
|
|
*/
|
|
|
|
|
1999-01-01 00:41:46 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
2003-06-16 17:22:22 +00:00
|
|
|
#include <string.h>
|
1999-01-01 00:41:46 +00:00
|
|
|
|
1999-04-28 18:18:12 +00:00
|
|
|
|
1999-01-14 00:41:44 +00:00
|
|
|
/* To keep glibc2 happy */
|
1999-07-21 22:04:34 +00:00
|
|
|
#if defined(__GLIBC__) && __GLIBC__ == 2 && __GLIBC_MINOR__ >= 0
|
2001-06-02 03:31:58 +00:00
|
|
|
#include <sys/io.h>
|
|
|
|
#else
|
|
|
|
#include <asm/io.h>
|
1999-01-14 00:41:44 +00:00
|
|
|
#endif
|
|
|
|
|
1999-04-28 18:18:12 +00:00
|
|
|
#ifdef __powerpc__
|
|
|
|
unsigned long isa_io_base = 0; /* XXX for now */
|
|
|
|
#endif /* __powerpc__ */
|
|
|
|
|
1999-01-01 00:41:46 +00:00
|
|
|
char hexchar(int i)
|
|
|
|
{
|
|
|
|
if ((i >= 0) && (i <= 9))
|
|
|
|
return '0' + i;
|
|
|
|
else if (i <= 15)
|
|
|
|
return 'a' - 10 + i;
|
|
|
|
else
|
|
|
|
return 'X';
|
|
|
|
}
|
|
|
|
|
|
|
|
void help(void)
|
|
|
|
{
|
2000-05-06 17:49:53 +00:00
|
|
|
fprintf(stderr,"Syntax: isadump ADDRREG DATAREG [BANK [BANKREG]]\n");
|
2001-10-13 16:37:16 +00:00
|
|
|
fprintf(stderr," isadump -f ADDRESS (for flat address space)\n");
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2004-04-19 18:02:10 +00:00
|
|
|
int addrreg, datareg = 0, bank = -1, bankreg = 0x4E;
|
|
|
|
int oldbank = 0;
|
1999-01-01 00:41:46 +00:00
|
|
|
int i,j,res;
|
2001-10-13 16:37:16 +00:00
|
|
|
int flat = 0;
|
|
|
|
char *end;
|
1999-01-01 00:41:46 +00:00
|
|
|
|
2001-10-13 16:37:16 +00:00
|
|
|
if (argc < 3) {
|
1999-01-01 00:41:46 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2001-10-13 16:37:16 +00:00
|
|
|
if(strcmp(argv[1], "-f")) {
|
|
|
|
addrreg = strtol(argv[1],&end,0);
|
|
|
|
} else {
|
|
|
|
if(argc != 3) {
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flat = 1;
|
|
|
|
addrreg = strtol(argv[2],&end,0) & 0xff00;
|
|
|
|
}
|
1999-01-01 00:41:46 +00:00
|
|
|
if (*end) {
|
2001-10-13 16:37:16 +00:00
|
|
|
fprintf(stderr,"Error: Invalid address!\n");
|
1999-01-01 00:41:46 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-10-13 16:37:16 +00:00
|
|
|
if ((addrreg < 0) || (addrreg > 0xffff)) {
|
|
|
|
fprintf(stderr,"Error: Address out of range!\n");
|
1999-01-01 00:41:46 +00:00
|
|
|
help();
|
2000-05-06 17:49:53 +00:00
|
|
|
exit(1);
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|
|
|
|
|
2001-10-13 16:37:16 +00:00
|
|
|
if(flat)
|
|
|
|
goto START;
|
2000-05-06 17:49:53 +00:00
|
|
|
|
1999-01-01 00:41:46 +00:00
|
|
|
datareg = strtol(argv[2],&end,0);
|
|
|
|
if (*end) {
|
2001-10-13 16:37:16 +00:00
|
|
|
fprintf(stderr,"Error: Invalid data register!\n");
|
1999-01-01 00:41:46 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
2001-10-13 16:37:16 +00:00
|
|
|
if ((datareg < 0) || (datareg > 0xffff)) {
|
1999-01-01 00:41:46 +00:00
|
|
|
fprintf(stderr,"Error: Data register out of range!\n");
|
|
|
|
help();
|
2000-05-06 17:49:53 +00:00
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc > 3) {
|
|
|
|
bank = strtol(argv[3],&end,0);
|
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr,"Error: Invalid bank number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((bank < 0) || (bank > 15)) {
|
|
|
|
fprintf(stderr,"Error: bank out of range (0-15)!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if(argc > 4) {
|
|
|
|
bankreg = strtol(argv[4],&end,0);
|
|
|
|
if (*end) {
|
2001-10-13 16:37:16 +00:00
|
|
|
fprintf(stderr,"Error: Invalid bank register!\n");
|
2000-05-06 17:49:53 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if ((bankreg < 0) || (bankreg > 0xff)) {
|
|
|
|
fprintf(stderr,"Error: bank out of range (0-0xff)!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|
|
|
|
|
2001-10-13 16:37:16 +00:00
|
|
|
START:
|
|
|
|
|
1999-01-01 00:41:46 +00:00
|
|
|
if (getuid()) {
|
|
|
|
fprintf(stderr,"Error: Can only be run as root (or make it suid root)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
fprintf(stderr," WARNING! Running this program can cause system crashes, "
|
|
|
|
"data loss and worse!\n");
|
2001-10-13 16:37:16 +00:00
|
|
|
if(flat)
|
|
|
|
fprintf(stderr," I will probe address range 0x%04x to "
|
|
|
|
"0x%04x.\n",addrreg, addrreg + 0xff);
|
|
|
|
else
|
|
|
|
fprintf(stderr," I will probe address register 0x%04x and "
|
1999-01-01 00:41:46 +00:00
|
|
|
"data register 0x%04x.\n",addrreg,datareg);
|
2004-04-19 18:02:10 +00:00
|
|
|
if(bank>=0)
|
2000-05-06 17:49:53 +00:00
|
|
|
fprintf(stderr," Probing bank %d using bank register 0x%02x.\n",
|
|
|
|
bank, bankreg);
|
1999-01-01 00:41:46 +00:00
|
|
|
fprintf(stderr," You have five seconds to reconsider and press CTRL-C!\n\n");
|
|
|
|
sleep(5);
|
|
|
|
|
1999-04-28 18:18:12 +00:00
|
|
|
#ifndef __powerpc__
|
2001-10-13 16:37:16 +00:00
|
|
|
if ((datareg < 0x400) && (addrreg < 0x400) && !flat) {
|
1999-01-01 00:41:46 +00:00
|
|
|
if(ioperm(datareg,1,1)) {
|
|
|
|
fprintf(stderr,"Error: Could not ioperm() data register!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if(ioperm(addrreg,1,1)) {
|
|
|
|
fprintf(stderr,"Error: Could not ioperm() address register!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if(iopl(3)) {
|
|
|
|
fprintf(stderr,"Error: Could not do iopl(3)!\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
1999-04-28 18:18:12 +00:00
|
|
|
#endif
|
1999-01-01 00:41:46 +00:00
|
|
|
|
2004-04-19 18:02:10 +00:00
|
|
|
if(bank>=0) {
|
2000-05-06 17:49:53 +00:00
|
|
|
outb(bankreg,addrreg);
|
2004-04-19 18:02:10 +00:00
|
|
|
oldbank=inb(datareg);
|
|
|
|
outb(bank,datareg);
|
2000-05-06 17:49:53 +00:00
|
|
|
}
|
|
|
|
|
1999-01-01 00:41:46 +00:00
|
|
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
|
|
|
|
for (i = 0; i < 256; i+=16) {
|
|
|
|
printf("%c0: ",hexchar(i/16));
|
|
|
|
for(j = 0; j < 16; j++) {
|
2001-10-13 16:37:16 +00:00
|
|
|
if(flat) {
|
|
|
|
res = inb(addrreg + i + j);
|
|
|
|
} else {
|
|
|
|
outb(i+j,addrreg);
|
|
|
|
res = inb(datareg);
|
|
|
|
}
|
|
|
|
printf("%c%c ",hexchar(res/16),hexchar(res%16));
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
|
|
|
}
|
2004-04-19 18:02:10 +00:00
|
|
|
if(bank>=0) {
|
2000-05-06 17:49:53 +00:00
|
|
|
outb(bankreg,addrreg);
|
2004-04-19 18:02:10 +00:00
|
|
|
outb(oldbank,datareg); /* restore original value */
|
2000-05-06 17:49:53 +00:00
|
|
|
}
|
1999-01-01 00:41:46 +00:00
|
|
|
exit(0);
|
|
|
|
}
|