This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Alignment trap error on DM365

Hi all:
     I had meet an Alignment trap error when run my application on DM365:

            Alignment trap: stream (702) PC=0x000b77e8 Instr=0xe7825003 Address=0x458b2796 FSR 0x801

            Bus error

    This is an general application, here is the code detail for you reference:

             int functionA()

             {

                          ....

                          unsigned char pool[100];

                          ....

                          functionB(pool);

             }

 

             int functionB(char *buf)

             {

                          ....

                          unsigned int *p = (unsigned int *)buf;

                         *p++ = 100;       // The application will crashed here                          ....

             }

 

              Anyone who can help on this?

  • Tracy,

    Alignment trap occurs when the ARM accesses unaligned address. This is a normal phenomenon and you need to debug your code for this, as this is not related to DM36x or any platfprm.

    Please refer to the link below to get some ideas on debugging alignment trap.

    http://www.mail-archive.com/davinci-linux-open-source@linux.davincidsp.com/msg05982.html

     

    Regards,

    Anshuman

  • Your local char array pool[100] gets allocated with no alignment restrictions (since char has no alignment needs on most processors).  That means that the value of 'pool' (same as &pool[0]) can be aligned to any boundary, including 1 or 2.  It appears that in your case it is getting aligned to 2 (offending address ends in 6), and when you assign this value to an int * and dereference this pointer you will get an alignment trap (since int access to memory must be 4-byte aligned).

    You can get your array to be aligned by doing
        int pool[100/4];
    which will give you the same sized array (100 chars) and align it.

    There are other solutions too, but they (and the solution above) may not be appropriate for your needs.

    Regards,

    - Rob

     

  • Hi Anshuman:

                Could we solve this issue by change toolchain prameters or kernel configration?

                I don't meet this issue on other ARM CPU platform.

  • Tracy,

    I think Rob gave a nice description of why the alignment trap can come. Kernel configurations would not help. Ofcourse, you can hide the alignment traps by changing parameters in /proc/cpu/alignment.

    Basically, if alignmnt trap comes, kernel is trying to help you to fix the application code and avoid any misaligned accesses, instead of fixing the problem itself.

     

    So my suggestion would be fix your application code, use gdb to help you nail down the mis-aligned access.

    Regards,

    Anshuman