annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
1 #include <stdio.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
2 #include <errno.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
3 #include <string.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
4 #include <fcntl.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
5 #include <stdlib.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
6 #include <sys/types.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
7 #include <machine/cpufunc.h>
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
8
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
9 void
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
10 usage(char *name) {
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
11 fprintf(stderr,
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
12 "Bad usage\n"
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
13 "\t%s adr [data]\n"
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
14 "\n"
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
15 "Read/write adr with data\n", name);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
16 exit(1);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
17 }
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
18
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
19 int
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
20 main(int argc, char **argv) {
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
21 int fd, adr, data;
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
22
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
23 if (argc != 2 && argc != 3)
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
24 usage(argv[0]);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
25
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
26 if ((fd = open("/dev/io", O_RDWR)) == -1) {
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
27 fprintf(stderr, "Can't open /dev/io: %s\n", strerror(errno));
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
28 exit(1);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
29 }
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
30
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
31 adr = strtol(argv[1], NULL, 0) & 0xffff;
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
32
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
33 if (argc == 3) {
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
34 data = strtol(argv[2], NULL, 0) & 0xff;
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
35 printf("0x%02x <- 0x%02x\n", adr, data);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
36 outb(adr, data);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
37 } else
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
38 printf("0x%02x -> 0x%02x\n", adr, inb(adr));
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
39
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
40 exit(0);
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
41 }
c34b37680055 Inital commit of random SuperIO code.
Daniel O'Connor <darius@dons.net.au>
parents:
diff changeset
42