This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: What to do with hardware exception (unaligned access) ? ARM920T processor
- From: "Alexandre Pereira Nunes" <alexandre dot nunes at gmail dot com>
- To: "Vladimir Sterjantov" <vfs at tersy dot ru>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 21 Oct 2008 17:19:12 -0200
- Subject: Re: What to do with hardware exception (unaligned access) ? ARM920T processor
- References: <48E32805.3090502@tersy.ru>
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!