Click to See Complete Forum and Search --> : got segmentation fault


littlebig
05-03-2001, 11:48 PM
the following is the code which received the message:
unsigned long*volatile reg1=(unsigned long*) 0x40800000;

reg1[0x00000c04]=0xe200d9;

anything wrong? :confused:

augur
05-04-2001, 06:54 AM
Greetings,

Originally posted by littlebig:
<STRONG>the following is the code which received the message:
unsigned long*volatile reg1=(unsigned long*) 0x40800000;

reg1[0x00000c04]=0xe200d9;

anything wrong? :confused:</STRONG>

You can't just poke memory around like that.
From the other post I figure that you're trying to write to memory that is not yours, so, you have to either map that memory into your segment, or use "/dev/mem" like a file and just fseek/fread/fwrite into it.

mmap example:


#include &lt;sys/types.h&gt;
#include &lt;sys/stat.h&gt;
#include &lt;sys/mman.h&gt;
#include &lt;fcntl.h&gt;
#include &lt;unistd.h&gt;

int main() {
FILE *f;
long *p;

if ((f=fopen("/dev/mem", "rw"))==NULL)
exit(-1);
p = (long*)mmap(NULL, &lt;length&gt;, PROT_READ | PROT_WRITE, MAP_SHARED, f, &lt;offset&gt; );
close(f);

/* Do the poking and peeking here */
*(p+0xc04) = 0xe200d9;

munmap(p, &lt;length&gt; );
}


I'm not sure this will work, because I'm not at my linux box, but it should be something like that, I hope. :D
Oh, just replace length with whatever suits your needs, and &lt;offset&gt; should be 0x40800000.