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>
|
2007-09-29 19:08:30 +00:00
|
|
|
Copyright (C) 2004,2007 Jean Delvare <khali@linux-fr.org>
|
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-25 13:26:45 +00:00
|
|
|
isadump 0x2e 0x2f 0x09 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
|
2004-04-25 13:26:45 +00:00
|
|
|
isadump -f 0xecf0 0x10 1 PC87366, temperature channel 2
|
2001-10-13 16:37:16 +00:00
|
|
|
*/
|
|
|
|
|
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>
|
2006-12-09 19:20:00 +00:00
|
|
|
#include "util.h"
|
2005-02-09 21:08:17 +00:00
|
|
|
#include "superio.h"
|
|
|
|
|
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__ */
|
|
|
|
|
2007-07-03 16:03:22 +00:00
|
|
|
static void help(void)
|
1999-01-01 00:41:46 +00:00
|
|
|
{
|
2004-04-25 13:26:45 +00:00
|
|
|
fprintf(stderr,
|
|
|
|
"Syntax for I2C-like access:\n"
|
2005-02-09 21:08:17 +00:00
|
|
|
" isadump [-y] [-k V1,V2...] ADDRREG DATAREG [BANK [BANKREG]]\n"
|
2004-04-25 13:26:45 +00:00
|
|
|
"Syntax for flat address space:\n"
|
2004-08-16 18:55:39 +00:00
|
|
|
" isadump [-y] -f ADDRESS [RANGE [BANK [BANKREG]]]\n");
|
2004-04-25 13:26:45 +00:00
|
|
|
}
|
|
|
|
|
2007-07-03 16:03:22 +00:00
|
|
|
static int default_bankreg(int flat, int addrreg, int datareg)
|
2004-04-25 13:26:45 +00:00
|
|
|
{
|
|
|
|
if (flat) {
|
|
|
|
return 0x09; /* Works for National Semiconductor
|
|
|
|
Super-IO chips */
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((addrreg == 0x2e && datareg == 0x2f)
|
|
|
|
|| (addrreg == 0x4e && datareg == 0x4f)) {
|
|
|
|
return 0x07; /* Works for all Super-I/O chips */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0x4e; /* Works for Winbond ISA chips, default */
|
|
|
|
}
|
|
|
|
|
2007-07-03 16:03:22 +00:00
|
|
|
static int set_bank(int flat, int addrreg, int datareg, int bank, int bankreg)
|
2004-04-25 13:26:45 +00:00
|
|
|
{
|
|
|
|
int oldbank;
|
|
|
|
|
|
|
|
if (flat) {
|
|
|
|
oldbank = inb(addrreg+bankreg);
|
|
|
|
outb(bank, addrreg+bankreg);
|
|
|
|
} else {
|
|
|
|
outb(bankreg, addrreg);
|
|
|
|
oldbank = inb(datareg);
|
|
|
|
outb(bank, datareg);
|
|
|
|
}
|
|
|
|
|
|
|
|
return oldbank;
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
2004-08-15 12:23:14 +00:00
|
|
|
int addrreg; /* address in flat mode */
|
|
|
|
int datareg = 0; /* unused in flat mode */
|
|
|
|
int range = 256; /* can be changed only in flat mode */
|
|
|
|
int bank = -1; /* -1 means no bank operation */
|
|
|
|
int bankreg;
|
|
|
|
int oldbank = 0;
|
|
|
|
int i, j, res;
|
2004-08-16 18:55:39 +00:00
|
|
|
int flags = 0;
|
|
|
|
int flat = 0, yes = 0;
|
2004-08-15 12:23:14 +00:00
|
|
|
char *end;
|
2005-02-09 21:08:17 +00:00
|
|
|
unsigned char enter_key[SUPERIO_MAX_KEY+1];
|
|
|
|
|
|
|
|
enter_key[0] = 0;
|
2004-08-15 12:23:14 +00:00
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
/* handle (optional) flags first */
|
|
|
|
while (1+flags < argc && argv[1+flags][0] == '-') {
|
|
|
|
switch (argv[1+flags][1]) {
|
|
|
|
case 'f': flat = 1; break;
|
|
|
|
case 'y': yes = 1; break;
|
2005-02-09 21:08:17 +00:00
|
|
|
case 'k':
|
|
|
|
if (2+flags >= argc
|
|
|
|
|| superio_parse_key(enter_key, argv[2+flags]) < 0) {
|
|
|
|
fprintf(stderr, "Invalid or missing key\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flags++;
|
|
|
|
break;
|
2004-08-16 18:55:39 +00:00
|
|
|
default:
|
|
|
|
fprintf(stderr, "Warning: Unsupported flag "
|
|
|
|
"\"-%c\"!\n", argv[1+flags][1]);
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
flags++;
|
2004-08-15 12:23:14 +00:00
|
|
|
}
|
|
|
|
|
2005-02-09 21:08:17 +00:00
|
|
|
/* key is never needed in flat mode */
|
|
|
|
if (flat && enter_key[0]) {
|
|
|
|
fprintf(stderr, "Error: Cannot use key in flat mode\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
/* verify that the argument count is correct */
|
|
|
|
if ((!flat && argc < 1+flags+2)
|
|
|
|
|| (flat && argc < 1+flags+1)) {
|
|
|
|
help();
|
|
|
|
exit(1);
|
2004-08-15 12:23:14 +00:00
|
|
|
}
|
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
addrreg = strtol(argv[1+flags], &end, 0);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr, "Error: Invalid address!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (addrreg < 0 || addrreg > (flat?0xffff:0x3fff)) {
|
|
|
|
fprintf(stderr, "Error: Address out of range "
|
|
|
|
"(0x0000-0x%04x)!\n", flat?0xffff:0x3fff);
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (flat) {
|
2004-08-16 18:55:39 +00:00
|
|
|
if (1+flags+1 < argc) {
|
|
|
|
range = strtol(argv[1+flags+1], &end, 0);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (*end || range <= 0 || range > 0x100
|
|
|
|
|| range & 0xf) {
|
|
|
|
fprintf(stderr, "Error: Invalid range!\n"
|
|
|
|
"Hint: Must be a multiple of 16 no "
|
|
|
|
"greater than 256.\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
addrreg &= 0xff00; /* Force alignment */
|
|
|
|
}
|
|
|
|
} else {
|
2004-08-16 18:55:39 +00:00
|
|
|
datareg = strtol(argv[1+flags+1], &end, 0);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr, "Error: Invalid data register!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (datareg < 0 || datareg > 0x3fff) {
|
|
|
|
fprintf(stderr, "Error: Data register out of range "
|
|
|
|
"(0x0000-0x3fff)!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bankreg = default_bankreg(flat, addrreg, datareg);
|
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
if (1+flags+2 < argc) {
|
|
|
|
bank = strtol(argv[1+flags+2], &end, 0);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr, "Error: Invalid bank number!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
2006-09-06 15:51:26 +00:00
|
|
|
if ((bank < 0) || (bank > 31)) {
|
|
|
|
fprintf(stderr, "Error: bank out of range (0-31)!\n");
|
2004-08-15 12:23:14 +00:00
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
if (1+flags+3 < argc) {
|
|
|
|
bankreg = strtol(argv[1+flags+3], &end, 0);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (*end) {
|
|
|
|
fprintf(stderr, "Error: Invalid bank "
|
|
|
|
"register!\n");
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
if (bankreg < 0 || bankreg >= range) {
|
|
|
|
fprintf(stderr, "Error: bank out of range "
|
|
|
|
"(0x00-0x%02x)!\n", range-1);
|
|
|
|
help();
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (getuid()) {
|
|
|
|
fprintf(stderr, "Error: Can only be run as root (or make it "
|
|
|
|
"suid root)\n");
|
|
|
|
exit(1);
|
|
|
|
}
|
|
|
|
|
2004-08-16 18:55:39 +00:00
|
|
|
if (!yes) {
|
|
|
|
fprintf(stderr, "WARNING! Running this program can cause "
|
|
|
|
"system crashes, data loss and worse!\n");
|
|
|
|
|
|
|
|
if (flat)
|
|
|
|
fprintf(stderr, "I will probe address range 0x%x to "
|
|
|
|
"0x%x.\n", addrreg, addrreg + range - 1);
|
|
|
|
else
|
|
|
|
fprintf(stderr, "I will probe address register 0x%x "
|
|
|
|
"and data register 0x%x.\n", addrreg, datareg);
|
|
|
|
|
|
|
|
if (bank>=0)
|
|
|
|
fprintf(stderr, "Probing bank %d using bank register "
|
|
|
|
"0x%02x.\n", bank, bankreg);
|
|
|
|
|
|
|
|
fprintf(stderr, "Continue? [Y/n] ");
|
|
|
|
fflush(stderr);
|
2006-12-09 19:20:00 +00:00
|
|
|
if (!user_ack(1)) {
|
2004-08-16 18:55:39 +00:00
|
|
|
fprintf(stderr, "Aborting on user request.\n");
|
|
|
|
exit(0);
|
|
|
|
}
|
|
|
|
}
|
1999-01-01 00:41:46 +00:00
|
|
|
|
1999-04-28 18:18:12 +00:00
|
|
|
#ifndef __powerpc__
|
2004-08-15 12:23:14 +00:00
|
|
|
if ((datareg < 0x400) && (addrreg < 0x400) && !flat) {
|
|
|
|
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
|
|
|
|
2005-02-09 21:08:17 +00:00
|
|
|
/* Enter Super-I/O configuration mode */
|
|
|
|
if (enter_key[0])
|
|
|
|
superio_write_key(addrreg, enter_key);
|
|
|
|
|
2004-08-15 12:23:14 +00:00
|
|
|
if (bank >= 0)
|
|
|
|
oldbank = set_bank(flat, addrreg, datareg, bank, bankreg);
|
|
|
|
|
2005-09-30 17:30:55 +00:00
|
|
|
if (flat)
|
|
|
|
printf(" ");
|
2004-08-15 12:23:14 +00:00
|
|
|
printf(" 0 1 2 3 4 5 6 7 8 9 a b c d e f\n");
|
|
|
|
for (i = 0; i < range; i += 16) {
|
2005-09-30 17:30:55 +00:00
|
|
|
if (flat)
|
|
|
|
printf("%04x: ", addrreg + i);
|
|
|
|
else
|
|
|
|
printf("%02x: ", i);
|
2005-02-09 21:08:17 +00:00
|
|
|
|
|
|
|
/* It was noticed that Winbond Super-I/O chips
|
|
|
|
would leave the configuration mode after
|
|
|
|
an arbitrary number of register reads,
|
|
|
|
causing any subsequent read attempt to
|
|
|
|
silently fail. Repeating the key every 16 reads
|
|
|
|
prevents that. */
|
|
|
|
if (enter_key[0])
|
|
|
|
superio_write_key(addrreg, enter_key);
|
|
|
|
|
2004-08-15 12:23:14 +00:00
|
|
|
for (j = 0; j < 16; j++) {
|
2007-04-03 12:55:30 +00:00
|
|
|
fflush(stdout);
|
2004-08-15 12:23:14 +00:00
|
|
|
if (flat) {
|
|
|
|
res = inb(addrreg + i + j);
|
|
|
|
} else {
|
|
|
|
outb(i+j, addrreg);
|
2007-05-16 09:11:37 +00:00
|
|
|
if (i+j == 0 && inb(addrreg) == 0x80) {
|
2007-04-03 12:55:30 +00:00
|
|
|
/* Bit 7 appears to be a busy flag */
|
|
|
|
range = 128;
|
|
|
|
}
|
2004-08-15 12:23:14 +00:00
|
|
|
res = inb(datareg);
|
|
|
|
}
|
2007-04-03 12:55:30 +00:00
|
|
|
printf("%02x ", res);
|
2004-08-15 12:23:14 +00:00
|
|
|
}
|
|
|
|
printf("\n");
|
2001-10-13 16:37:16 +00:00
|
|
|
}
|
2004-04-25 13:26:45 +00:00
|
|
|
|
2004-08-15 12:23:14 +00:00
|
|
|
/* Restore the original bank value */
|
|
|
|
if (bank >= 0)
|
|
|
|
set_bank(flat, addrreg, datareg, oldbank, bankreg);
|
2004-04-25 13:26:45 +00:00
|
|
|
|
2005-02-09 21:08:17 +00:00
|
|
|
/* Exit Super-I/O configuration mode */
|
|
|
|
if (enter_key[0])
|
|
|
|
superio_reset(addrreg, datareg);
|
|
|
|
|
2004-08-15 12:23:14 +00:00
|
|
|
exit(0);
|
1999-01-01 00:41:46 +00:00
|
|
|
}
|