From 88aa4bcb731ece1ea98d6f37379517ae1cc43c3b Mon Sep 17 00:00:00 2001 From: Tatsumi Hosokawa Date: Thu, 26 Feb 1998 14:36:01 +0000 Subject: [PATCH] added "rdattr" (read attribute memory) function. --- usr.sbin/pccard/pccardc/Makefile | 4 +- usr.sbin/pccard/pccardc/pccardc.c | 4 +- usr.sbin/pccard/pccardc/rdattr.c | 95 +++++++++++++++++++++++++++++++ 3 files changed, 100 insertions(+), 3 deletions(-) create mode 100644 usr.sbin/pccard/pccardc/rdattr.c diff --git a/usr.sbin/pccard/pccardc/Makefile b/usr.sbin/pccard/pccardc/Makefile index 28683df42ab8..095b1cf65d9d 100644 --- a/usr.sbin/pccard/pccardc/Makefile +++ b/usr.sbin/pccard/pccardc/Makefile @@ -1,12 +1,12 @@ # # pccardc Makefile # -# $Id$ +# $Id: Makefile,v 1.6 1997/02/22 16:08:35 peter Exp $ # PROG= pccardc NOMAN= noman SRCS= dumpcis.c enabler.c pccardc.c pccardmem.c printcis.c \ - rdmap.c rdreg.c readcis.c wrattr.c wrreg.c + rdattr.c rdmap.c rdreg.c readcis.c wrattr.c wrreg.c CFLAGS+= -I${.CURDIR}/../pccardd diff --git a/usr.sbin/pccard/pccardc/pccardc.c b/usr.sbin/pccard/pccardc/pccardc.c index e18d66c8930e..c925ea4a408a 100644 --- a/usr.sbin/pccard/pccardc/pccardc.c +++ b/usr.sbin/pccard/pccardc/pccardc.c @@ -26,7 +26,7 @@ #ifndef lint static const char rcsid[] = - "$Id$"; + "$Id: pccardc.c,v 1.6 1997/10/06 11:35:54 charnier Exp $"; #endif /* not lint */ #include @@ -40,6 +40,7 @@ DECL(dumpcis_main); DECL(enabler_main); DECL(help_main); DECL(pccardmem_main); +DECL(rdattr_main); DECL(rdmap_main); DECL(rdreg_main); DECL(wrattr_main); @@ -54,6 +55,7 @@ struct { { "enabler", enabler_main, "Device driver enabler" }, { "help", help_main, "Prints command summary" }, { "pccardmem", pccardmem_main, "Allocate memory for pccard driver" }, + { "rdattr", rdattr_main, "Read attribute memory" }, { "rdmap", rdmap_main, "Read pcic mappings" }, { "rdreg", rdreg_main, "Read pcic register" }, { "wrattr", wrattr_main, "Write byte to attribute memory" }, diff --git a/usr.sbin/pccard/pccardc/rdattr.c b/usr.sbin/pccard/pccardc/rdattr.c new file mode 100644 index 000000000000..9347d97dc786 --- /dev/null +++ b/usr.sbin/pccard/pccardc/rdattr.c @@ -0,0 +1,95 @@ +/* + * Copyright (c) 1995 Andrew McRae. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of the author may not be used to endorse or promote products + * derived from this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES + * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. + * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, + * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY + * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + */ + +/* + * Code cleanup, bug-fix and extension + * by Tatsumi Hosokawa + */ + +#include +#include +#include +#include +#include +#include + +#include + +int +rdattr_main(argc, argv) + int argc; + char *argv[]; +{ + int i, reg, length; + char name[64]; + u_char *buf; + int fd; + off_t offs; + + if (argc != 4) { + fprintf(stderr, "usage: %s rdattr slot offs length\n", argv[0]); + exit(1); + } + sprintf(name, CARD_DEVICE, atoi(argv[1])); + fd = open(name, 2); + if (fd < 0) { + perror(name); + exit(1); + } + reg = MDF_ATTR; + if (ioctl(fd, PIOCRWFLAG, ®)) { + perror("ioctl (PIOCRWFLAG)"); + exit(1); + } + if (sscanf(argv[2], "%x", ®) != 1 || + sscanf(argv[3], "%x", &length) != 1) { + fprintf(stderr, "arg error\n"); + exit(1); + } + offs = reg; + if ((buf = malloc(length)) == 0) { + perror(name); + exit(1); + } + lseek(fd, offs, SEEK_SET); + if (read(fd, buf, length) != length) { + perror(name); + exit(1); + } + for (i = 0; i < length; i++) { + if (i % 16 == 0) { + printf("%04x: ", (int) offs + i); + } + printf("%02x ", buf[i]); + if (i % 16 == 15) { + printf("\n"); + } + } + if (i % 16 != 0) { + printf("\n"); + } + return 0; +}