This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: What to do with hardware exception (unaligned access) ? ARM920T processor


2008/10/1 Vladimir Sterjantov <vfs@tersy.ru>:
> Hi!
>
> Processor ARM920T, chip Atmel at91rm9200.
>
> Simple C code:
>
> char c[30];
> unsigned short *pN = &c[1];
>
> *pN = 0x1234;
>
> causes hardware exeption - memory aborts (used to implement memory
> protection or virtual memory).
>
> We have a lot of source code, with pieces of code like this, which must be
> ported from x86 to ARM9.
>
> Are there any compiler options to handle this exception?
>
Not to this day. Code like this is generally not portable.

You can have a header with something like:

typedef struct __attribute__((packed)) { unsigned short val } un16_t;

and then replace the unsigned short *pN by un16_t *pN, like this:
un16_t *pN = (un16_t *)&c[1];
pN.val = 0x1234;

... but IMHO this is as much work as replacing that by portable code.
See: http://c-faq.com/strangeprob/ptralign.html for furter directions.

Good luck!


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]