我正在尝试从寄存器中读取值,但它返回分段错误错误。但是,如果我分别传递基地址和偏移量,则此代码可以正常工作,但是当我传递组合地址时,它会返回错误。有人可以指导我解决这个问题。提前感谢>
#define REG_READ(addr) (*(volatile unsigned int*)(addr))
unsigned int Read(unsigned int Base_Address)
{ unsigned int Base_Address_R = Base_Address;
//unsigned int offset = os;
printf("Reading Register");
//UINTPTR Base_Address_R = Reg_base_address_R;
int *reg_addr;
int fd;
int value_return;
int map_length = getpagesize();
fd = open("/dev/mem", (O_RDWR | O_SYNC));
reg_addr = mmap(NULL,map_length, PROT_READ|PROT_WRITE, MAP_SHARED,fd,Base_Address_R);
if (reg_addr == MAP_FAILED)
{
printf("mmap failed");
close(fd);
}
//REG_WRITE(reg_addr, offset,value);
REG_READ(reg_addr);
printf("Memory=%d",(*(volatile unsigned int*)(reg_addr)));
value_return = (*(volatile unsigned int*)(reg_addr));
munmap((void *)reg_addr, map_length);
return value_return;
}
int main()
{ printf("Main");
Read(0xFD480000);
}