[U-Boot-Users] unexpected behaviour !!!

Hi, I have designed my own protocol and am trying to include it in u-boot.
In the Recieve Handler i am trying to dereference the pkt.
struct mypacket { unsigned int seqnum ; char data [24] ; } ;
struct mypacket mypacket ;
void myrecieve_handler (uchar * pkt, unsigned dest, unsigned src, unsigned len) { int seqnum ; uchar * q ;
if (dest != 8888) return ;
printf ("pkt => %u\n", pkt) ; printf ("len => %d\n", len) ;
q = pkt ; for (i = 0 ; i < len ; i++) { printf ("%d:%u=> %c\n", i, q, *q) ; q++ ; }
memcpy (&mypacket, pkt, sizeof (mypacket)) ; printf ("seq:%u\n", mypacket.seq) ; printf ("data:%s\n", mypacket.data) ; printf ("before\n") ; seqnum = * (int *) pkt ; /* <------------------------ Abort - Board Hangs */ printf ("after\n") ;
}
I am able to access the contents of pkt 1) byte by byte 2) memcpy
But, as soon as i try to deference it either by doing 1) * (int *) pkt /***************** board hangs ********/ or 2) mp = (struct mypacket *) pkt printf ("%u\n", mp -> seqnum) ; /************* board Hangs *************/
I get the Error shown below.
As, soon as seqnum = * (int *) pkt - is executed my board prints the message:
Why is that ?.
I dont understand this. i am using an OMAP 5912 OSK BOARD.
Is it not possible to dereference pkt ?.
data abort pc : [<2000d6b0>] lr : [<2000d6a8>] sp : 1ffbfc38 ip : ffffffff fp : 20015fc8 r10: 2001dc24 r9 : 20015fb8 r8 : 1ffbffdc r7 : 2001dc08 r6 : 0000001c r5 : 2001c40a r4 : 000022b8 r3 : 00000020 r2 : 00000001 r1 : 0000000a r0 : 00000000 Flags: nZCv IRQs off FIQs off Mode SVC_32 Resetting CPU ...
Regards, Jo

Maximus wrote: ...
void myrecieve_handler (uchar * pkt, unsigned dest, unsigned src, unsigned len) {
...
As, soon as seqnum = * (int *) pkt - is executed my board prints the message:
One idea without further investigation....
if the pointer pkt is *not* on an 4 byte aligned address, you will get an alignment trap on arm.
Best regards Peter

Hi, Thanks a lot - it took me 2 days to find it out!!!.
The address of a long int, struct should be aligned to address which a multiple of 4.
Regards, Jo
On 1/31/06, Peter Menzebach pm-ub@mw-itcon.de wrote:
Maximus wrote: ...
void myrecieve_handler (uchar * pkt, unsigned dest, unsigned src, unsigned
len)
{
...
As, soon as seqnum = * (int *) pkt - is executed my board prints the
message:
One idea without further investigation....
if the pointer pkt is *not* on an 4 byte aligned address, you will get an alignment trap on arm.
Best regards Peter

Dear Maximus!
Maximus schrieb:
Thanks a lot - it took me 2 days to find it out!!!.
Have you ever read a book or taken a course about ARM architecture? It doesn't seem like this, but it is extremely important to understand the processor architecture when working with it.
With best regards Andreas Schweigstill
participants (3)
-
Andreas Schweigstill
-
Maximus
-
Peter Menzebach