From sanders@austin.BSDI.COM Thu Feb 10 15:46:46 1994
Received: from austin.BSDI.COM by fido.wps.com (5.67/wps.com-hackery)
	id AA26603; Thu, 10 Feb 94 15:46:41 -0800
Received: from austin.BSDI.COM (sanders@localhost [127.0.0.1]) by austin.BSDI.COM (8.6.5/8.6.5) with ESMTP id RAA05018 for <tomj@wps.com>; Thu, 10 Feb 1994 17:46:38 -0600
Message-Id: <199402102346.RAA05018@austin.BSDI.COM>
To: tomj@wps.com
Subject: checkrom.c
Organization: Berkeley Software Design, Inc.
Date: Thu, 10 Feb 1994 17:46:37 -0600
From: Tony Sanders <sanders@BSDI.COM>
Status: O


/*-
 * Copyright (c) 1992 Berkeley Software Design, Inc. All rights reserved.
 * The Berkeley Software Design Inc. software License Agreement specifies
 * the terms and conditions for redistribution.
 *
 *	BSDI $Id$
 */

#include <stdio.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/file.h>

#define HOLE_BASE 	0xC0000		/* skipping VGA mem */
#define BIOS_BASE 	0xF0000		/* skipping VGA mem */
#define HOLE_LEN	(0x100000 - HOLE_BASE)

#define MSG_SRCH 	256	/* bytes of rom to search for strings */
#define MINSTR 		6	/* min. string length */
u_char buf[HOLE_LEN];

main(ac, av)
	int ac;
	char *av[];
{
	int mem;
	int fd;
	int addr, len;
	u_char *cp, *sp, *first;

	if ((mem = open("/dev/mem", 2)) == -1) {
		fprintf(stderr, "can't open /dev/mem\n");
		exit(1);
	}
	if ((fd = open("holemem", O_WRONLY|O_CREAT|O_TRUNC), 0666) == -1) {
		fprintf(stderr, "can't create vgabios.hw\n");
		exit(1);
	}
	if (lseek(mem, (off_t) HOLE_BASE, 0) != HOLE_BASE ||
	    read(mem, buf, HOLE_LEN) != HOLE_LEN) {
		fprintf(stderr, "can't read memory\n");
		exit(1);
	}
	write(fd, buf, HOLE_LEN);
	close(fd);
	close(mem);

#define CONT(n)	{ cp += (n); addr += (n); continue; }
	for (cp = buf, addr = HOLE_BASE; cp < buf + HOLE_LEN; ) {
		if ((cp[0] != 0x55 || cp[1] != 0xaa) &&
		    (addr < BIOS_BASE || cp[0] != 0xaa || cp[1] != 0x55))
			CONT(2048);
		len = cp[2] * 512;
		printf("\nROM at 0x%x - 0x%x (%dK):\n",
		    addr, addr + len - 1, len / 1024);
		first = NULL;
		for (sp = cp + 4; sp < cp + MSG_SRCH; sp++) {
			if (isascii(*sp) && isprint(*sp)) {
				if (first == NULL)
					first = sp;
				continue;
			} else {
				if (first && sp - first > MINSTR)
					printf("%.*s\n", sp - first, first);
				first = NULL;
			}
		}
		if (first && sp - first > MINSTR)
			printf("%.*s\n", sp - first);
		CONT(len);
	}
	exit(0);
}

