Subject: Re: Data Abort Exceptions
To: Jay Monkman <jtm@smoothsmoothie.com>
From: Neil Hoggarth <njh@kernighan.demon.co.uk>
List: port-arm
Date: 07/22/2002 20:41:12
On Mon, 22 Jul 2002, Jay Monkman wrote:

> On Mon, Jul 22, 2002 at 05:48:56PM +0100, Richard Earnshaw wrote:
> > Current releases of NetBSD are configured not to abort the above, but to
> > use a load-and-rotate type of operation, so in the above func2 would print
> > the value contained by loading (*p & ~3) rotated by 8 bits.
>
> How do you make the compiler generate code to do that? I've looked
> through GCC's documentation, and haven't found it, nor have I found
> the where it's set up in NetBSD.

The compiler doesn't do it. Bytewise-rotation-on-unaligned-access is a
hardware feature of ARM processors.

Suppose word 0 (address 0x00000000) in memory contains 0x33221100
    and word 1 (address 0x00000004) in memory contains 0x77665544

A 32-bit fetch from address 0x00000000 gives 0x33221100
                        ... 0x00000001 gives 0x00332211
                        ... 0x00000002 gives 0x11003322
                        ... 0x00000003 gives 0x22110033
                        ... 0x00000004 gives 0x77665544
                        ... 0x00000005 gives 0x44776655
                        ... and so on.

This trick is used in order to allow older ARM processors which (only have
32-bit load/store instructions) to simulate byte-addressable memory; if
one wants to fetch an unsigned byte from 0x00000001 one can do a 32-bit
load from that address, then AND the result with 0x000000FF - the
processor hardware has already done the requisite shift for us, as it was
loading the data.

Regards,

Neil.