ru

所属分类:android开发
开发工具:Unix_Linux
文件大小:9KB
下载次数:5
上传日期:2015-01-20 15:17:42
上 传 者驴在哪
说明:  x86 android 下读取io memory pci 的工具源码
(read io memory pci source tools under x86 android)

文件列表:
ru (0, 2014-09-18)
ru\Android.mk (158, 2014-03-26)
ru\readacpi.c (7358, 2014-03-26)
ru\readacpi1.c (1103, 2014-03-26)
ru\readcmos.c (1036, 2014-03-26)
ru\readec.c (2887, 2014-03-26)
ru\readioid.c (1044, 2014-07-22)
ru\readiosp.c (821, 2014-03-26)
ru\readpci.c (1190, 2014-03-26)
ru\ru.c (2398, 2014-07-22)
ru\rw.h (760, 2014-03-26)

/* * read memory * mode = r/w * pos = index of memory * value = the value want to change */ #define MY_PAGE_SIZE 4096 #define READ_SIZE 0x100 typedef unsigned long UINT32; void readmem(char* mode, char* pos, char* addr, char* value) { int mem_fd, count; unsigned long i, offset, address; void* pMem; unsigned long start; unsigned int buff; // start = start address start = strtoul (pos, NULL, 16); if( (mem_fd = open("/dev/mem", O_RDWR)) < 0 ) { printf("Can't open /dev/mem.\n"); } offset = start % MY_PAGE_SIZE; // mmap( , , // , , // , ) pMem = mmap(0, READ_SIZE + offset, PROT_READ|PROT_WRITE, MAP_SHARED, mem_fd, start - offset); if( pMem == MAP_FAILED ) { printf("Can't get the address poniter of PUART:%s\n", strerror(errno)); close(mem_fd); } if(DEBUG) printf("mmap OK\n"); // pointer type determined by argument if( strcmp(mode, "rb") == 0 ) { count = 1; for( i = offset ; i < offset + READ_SIZE ; i +=0x1) { printf(" %02x", *((unsigned char *)(pMem + i))); if ( count == 16 && i != offset + READ_SIZE -1 ) { printf("\n"); count = 0; } count++; } } // pointer type determined by argument else if( strcmp(mode, "rw") == 0 ) { count = 1; for( i = offset ; i < offset + READ_SIZE ; i +=0x2) { printf(" %04x", *((unsigned short *)(pMem + i))); if ( count == 8 && i != offset + READ_SIZE -1 ) { printf("\n"); count = 0; } count++; } } // pointer type determined by argument else if( strcmp(mode, "rd") == 0 ) { count = 1; for( i = offset ; i < offset + READ_SIZE ; i +=0x4) { printf(" %08x", *((unsigned int *)(pMem + i))); if ( count == 4 && i != offset + READ_SIZE -1 ) { printf("\n"); count = 0; } count++; } } else if( strcmp(mode, "wb") == 0 ) { address = strtoul (addr, NULL, 16); sscanf(value, "%x", &buff); lseek(mem_fd, offset + address, SEEK_SET); write(mem_fd, &buff, 1); } else if( strcmp(mode, "ww") == 0 ) { address = strtoul (addr, NULL, 16); sscanf(value, "%x", &buff); lseek(mem_fd, offset + address, SEEK_SET); write(mem_fd, &buff, 2); } else if( strcmp(mode, "wd") == 0 ) { address = strtoul (addr, NULL, 16); sscanf(value, "%x", &buff); lseek(mem_fd, offset + address, SEEK_SET); write(mem_fd, &buff, 4); } munmap(pMem, READ_SIZE + offset); close(mem_fd); }

近期下载者

相关文件


收藏者