1 /* Peek and poke using /dev/mem.
3 * Callers now ought to check the return values.
5 * Calling peek() requires read permission on /dev/mem, and consumes
6 * a file descriptor. Calling poke() requires write permission, and
7 * consumes another file descriptor.
10 #include <sys/types.h>
14 _PROTOTYPE( int peek
, (unsigned segment
, unsigned offset
));
15 _PROTOTYPE( int poke
, (unsigned segment
, unsigned offset
, unsigned value
));
19 int peek(segment
, offset
)
23 unsigned char chvalue
;
26 if (infd
< 0) infd
= open("/dev/mem", O_RDONLY
);
28 lseek(infd
, (unsigned long) segment
* SEGSIZE
+ offset
, SEEK_SET
) < 0 ||
29 read(infd
, (char *) &chvalue
, (unsigned) 1) != 1)
34 int poke(segment
, offset
, value
)
39 unsigned char chvalue
;
40 static int outfd
= -1;
43 if (outfd
< 0) outfd
= open("/dev/mem", O_WRONLY
);
45 lseek(outfd
, (unsigned long) segment
* SEGSIZE
+ offset
, SEEK_SET
) < 0 ||
46 write(outfd
, (char *) &chvalue
, (unsigned) 1) != 1)