this saves the last MEG of 32-bit address space to stdout.
#include <stdio.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/mman.h>
main(int argc, char *argv[])
{
int i;
volatile unsigned char *cp;
int fd;
volatile void *v;
off_t nvram = 0xfff00000;
/* avoid linux mmap bug */
size_t length = 0x100000 /*- 0x1000*/;
if (argc > 1)
nvram = (strtol(argv[1], 0, 0)) << 16;
if (argc > 2)
length = (strtol(argv[2], 0, 0)) ;
if((fd = open("/dev/mem",O_RDWR)) != -1)
{
v = mmap(0, length, PROT_READ | PROT_WRITE, MAP_SHARED,fd,nvram);
fprintf(stderr, "mmap returns %p\n", v);
if ( (int)v == -1)
{
perror("mmap");
exit(1);
}
} else {
perror("open /dev/mem");
exit(1);
}
write(1, v, length);
}