Subject: Re: RFC: Change SWI number base?
To: David Laight <David.Laight@btinternet.com>
From: Richard Earnshaw <rearnsha@arm.com>
List: port-arm
Date: 01/09/2002 12:20:42
> The following has a 50% chance of success (on some cpus):
> 
>     .code16
>     ...
> go_32:
>     bx pc
>     nop
>     .code32
>     .balign 4
> code_32:
>     ldr r0,=0x12345    /* [pc,#nn] */
> 
> if go_32 is at address 4n+2, code_32 will be 4n+8, the 'pc' when the
> 'bx pc' is execute will be '.+4' or 4n+6. In 32 bit mode bits 0 and 1
> of the pc are ignored when fetching instructions, so the first fetch
> is the the thumb 'nop' and the pad! - hopefully a nop.  But the pc used
> in the pc-relative load will have bit 1 set.....

But you've removed the ".align 0" which forced the correct (4-byte) 
alignment of the go_32 label.  Once you put that back the code will always 
work (and there is no need for the .balign 4).

This is *the* standard code sequence for switching from thumb code to arm 
code; for it not to work would represent a non-functional device.

R.