My call to mmap is causing a Segmentation fault. Is this the right way to do it?
I have some general-purpose I/O on this Embest ARM-based board. According to the manual for the board, the control register and the data register are at absolute physical addresses
0x56000010 and 0x56000014 respectively.So here is how I tried to test my access to these registers:
#include #include #include #include #include
main() { int fm = open("/dev/mem",O_RDWR); printf("handle to /dev/mem = %08x\r\n",fm);
char *mptr = (char*)mmap( (void*)0, 16, //..16 bytes PROT_READ | PROT_WRITE, MAP_SHARED, fm, 0x56000010); //..starting with Port B CON reg
printf("mptr = %08x", mptr);
printf("GPBCON = %08x\r\n", *((int*)(mptr+0))); printf("GPBDAT = %08x\r\n", *((int*)(mptr+4))); }
When I run this program, the open() returns 4, and then the Segmentation Fault occurs during the execution of mmap, because there was no printf telling what mptr is. Here is the output:
handle to /dec/mem = 00000004
: [] lr : [] Tainted: P
sp : bffffdd8 ip : bffff7d8 fp : bffffea4
r10: 40139280 r9 : 000084a0 r8 : 00000001
r7 : 4000ee5c r6 : 0000830c r5 : bffffec4 r4 : 40020c34
r3 : ffffffff r2 : 0000000f r1 : 00008823 r0 : 0000883c
Flags: NzCv IRQs on FIQs on Mode USER_32 Segment user
Control: C000317F Table: 33E90000 DAC: 00000015
Segmentation fault
- - - - - - - - - - - - - - - - - - - - - - - - - - - I am running as root, so I should be able to do this, right?
Robert Scott Ypsilanti, Michigan