#include #include #include #include #include #include #include #include #include int main(int argc,char **argv) { char buff[1024]; char file[256]; char *mmaped; int fd; unsigned int st,len,poff; int r; char *dev="/dev/mem"; if(argc!=3) { fprintf(stderr,"memtest \n"); return 1; } st=strtoul(argv[1],NULL,16); len=strtoul(argv[2],NULL,16); poff=st%PAGE_SIZE; fd=open(dev,O_RDONLY); if(fd<0) { fprintf(stderr,"cannot open %s\n",dev); return 1; } fprintf(stderr,"mmap: start %08X len:%08X\n",st-poff,len+poff); mmaped=mmap(0,len+poff,PROT_READ,MAP_SHARED,fd,st-poff); if(mmaped==MAP_FAILED) { fprintf(stderr,"cannot mmap\n"); return 1; } fwrite(mmaped+poff,1,len,stdout); munmap(mmaped,len); close(fd); return 0; }