#include <stdio.h>
#include <stdlib.h>
#include <sys/io.h>

main(int argc, char **argv)
{
	int port, length, fir;
	int val;
	unsigned char bank;

	if (argc < 3)
		exit(-1);

	port = strtoul(argv[1], NULL, 0);
	length = strtoul(argv[2], NULL, 0);

	if (iopl(3) < 0) {
		perror("iopl");
		exit(-1);
	}

	if (argc > 3) {
		fir = strtoul(argv[3], NULL, 0);
		printf("selecting bank 3 (fir at 0x%x)\n", fir);
		bank = inb(fir + 7);
		bank &= 0xf0;
		bank |= 3;
		outb(bank, fir + 7);
	}

	while (length--) {
		val = inb(port);
		if ((port & 0x7) == 0)
			printf("0x%04x:", port);
		printf(" 0x%02x", val & 0xff);
		if ((port & 0x7) == 0x7)
			printf("\n");
		port++;
	}

	exit(0);
}
