diff io/io.c @ 0:c34b37680055 default tip

Inital commit of random SuperIO code.
author Daniel O'Connor <darius@dons.net.au>
date Thu, 20 Oct 2011 16:48:24 +1030
parents
children
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/io/io.c	Thu Oct 20 16:48:24 2011 +1030
@@ -0,0 +1,42 @@
+#include <stdio.h>
+#include <errno.h>
+#include <string.h>
+#include <fcntl.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <machine/cpufunc.h>
+
+void
+usage(char *name) {
+    fprintf(stderr,
+	    "Bad usage\n"
+	    "\t%s adr [data]\n"
+	    "\n"
+	    "Read/write adr with data\n", name);
+    exit(1);
+}
+
+int
+main(int argc, char **argv) {
+    int	fd, adr, data;
+    
+    if (argc != 2 && argc != 3)
+	usage(argv[0]);
+
+    if ((fd = open("/dev/io", O_RDWR)) == -1) {
+	fprintf(stderr, "Can't open /dev/io: %s\n", strerror(errno));
+	exit(1);
+    }
+
+    adr = strtol(argv[1], NULL, 0) & 0xffff;
+
+    if (argc == 3) {
+	data = strtol(argv[2], NULL, 0) & 0xff;
+	printf("0x%02x <- 0x%02x\n", adr, data);
+	outb(adr, data);
+    } else
+	printf("0x%02x -> 0x%02x\n", adr, inb(adr));
+	
+    exit(0);
+}
+