#define _GNU_SOURCE #include #include #include #include #include #include #include #include #define MAP_SIZE 4096UL #define MAP_MASK (MAP_SIZE - 1) #define DEV_MEM "/dev/mem" static unsigned long addr = 0; static unsigned long len = 0x10; int main() { int ii; int fd; unsigned long paddr = 0; unsigned long offset; unsigned long *map_lbase; if(getpagesize() != MAP_SIZE) { fprintf(stderr, "Incorrect page size\n"); exit(1); } if((fd = open(DEV_MEM, O_RDWR | O_SYNC)) == -1) { fprintf(stderr, "cannot open %s - are you root?\n", DEV_MEM); exit(1); } // Calculate the page number, and the offset within the page. paddr = addr & ~MAP_MASK; offset = addr & MAP_MASK; // Map that page. map_lbase = (unsigned long *)mmap(NULL, MAP_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, paddr); if((long)map_lbase == -1) { perror("cannot mmap"); exit(1); } // Get a pointer to the offset within the page. map_lbase += offset / 4; // Dump the requested bytes. for(ii = 0; ii < len; ii++) { if(ii % 4 == 0) { printf("%08lx: ", addr + (ii * sizeof(unsigned long))); } printf("%08lx ", map_lbase[ii]); if(ii % 4 == 3) { printf("\n"); } } if((ii % 4) != 0) { printf("\n"); } exit(0); } /* * Local Variables: * mode: c * tab-width: 8 * c-basic-offset: 4 * indent-tabs-mode: t * End: * * vim:ts=8:sw=4:sts=4 */