Blackbug
August 4th, 2014, 12:30 AM
Hello,
I am new to embedded programming and trying to run the following code, however, it crashes with core dump.
I am trying to assign memory to a specific address 0x400380 and, while I try to modify one of the bitfields, it results in a core dump.
However, when I don't specify any address everything works perfectly.
typedef union siu_pcr_u
{
volatile unsigned short REG;
struct
{
volatile unsigned short :3;
volatile unsigned short PA:3;
volatile unsigned short OBE:1;
volatile unsigned short IBE:1;
volatile unsigned short DSC:2;
volatile unsigned short ODE:1;
volatile unsigned short HYS:1;
volatile unsigned short SRC:2;
volatile unsigned short WPE:1;
volatile unsigned short WPS:1;
} FIELDS;
} SIU_PCR;
int main()
{
volatile SIU_PCR *siu_pcr_ptr;
siu_pcr_ptr = (SIU_PCR*)(0X400380); // Assigned to a specific address
for(int i=122; i<130; i++)
{
siu_pcr_ptr[i].FIELDS.PA = 0; // Crashes here
}
return 0;
}
The gdb gives following info:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000004006f8 in main () at ex04.cpp:211
211 siu_pcr_ptr[i].FIELDS.PA = 0;
(gdb) p siu_pcr_ptr[i]
$1 = {REG = 0, FIELDS = {PA = 0, OBE = 0, IBE = 0, DSC = 0, ODE = 0, HYS = 0, SRC = 0, WPE = 0, WPS = 0}}
(gdb) p siu_pcr_ptr
$2 = (volatile SIU_PCR *) 0x400380
(gdb)
Can anyone point out whats wrong here?
Thanks.
I am new to embedded programming and trying to run the following code, however, it crashes with core dump.
I am trying to assign memory to a specific address 0x400380 and, while I try to modify one of the bitfields, it results in a core dump.
However, when I don't specify any address everything works perfectly.
typedef union siu_pcr_u
{
volatile unsigned short REG;
struct
{
volatile unsigned short :3;
volatile unsigned short PA:3;
volatile unsigned short OBE:1;
volatile unsigned short IBE:1;
volatile unsigned short DSC:2;
volatile unsigned short ODE:1;
volatile unsigned short HYS:1;
volatile unsigned short SRC:2;
volatile unsigned short WPE:1;
volatile unsigned short WPS:1;
} FIELDS;
} SIU_PCR;
int main()
{
volatile SIU_PCR *siu_pcr_ptr;
siu_pcr_ptr = (SIU_PCR*)(0X400380); // Assigned to a specific address
for(int i=122; i<130; i++)
{
siu_pcr_ptr[i].FIELDS.PA = 0; // Crashes here
}
return 0;
}
The gdb gives following info:
Program terminated with signal SIGSEGV, Segmentation fault.
#0 0x00000000004006f8 in main () at ex04.cpp:211
211 siu_pcr_ptr[i].FIELDS.PA = 0;
(gdb) p siu_pcr_ptr[i]
$1 = {REG = 0, FIELDS = {PA = 0, OBE = 0, IBE = 0, DSC = 0, ODE = 0, HYS = 0, SRC = 0, WPE = 0, WPS = 0}}
(gdb) p siu_pcr_ptr
$2 = (volatile SIU_PCR *) 0x400380
(gdb)
Can anyone point out whats wrong here?
Thanks.