[PATCH ARM/THUMB] replace mov with movs in crt0.S

Thomas Klein th.r.klein@web.de
Thu Nov 24 15:25:00 GMT 2011


On 11/23/11 14:22, Richard Earnshaw wrote:
> On 23/11/11 14:12, Thomas Klein wrote:
>> Hi,
>>
>> When using 'unified syntax' a MOV rd, rs with two low registers isn't
>> present for all thumb architectures.
>> The result would be unpredictable when running on v4t or v5t architectures.
>>
>> In case of not using the condition flags a MOVS rd, rs (alias LSLS Rd,
>> Rs, #0)
>> can be used instead.
>>
>> Is this correct, or is there anything wrong with this idea.
>>
> So looking at the entire source for crt0.S, the only use of unified
> syntax is conditional upon __thumb2__ being defined.  If that is defined
> then the 16-bit MOV lo, lo instruction is available.
>
> What options are you using to build newlib that is causing you to see a
> problem here?
>
> R.
At FreeBSD x86 system calling from build directory

../../env/src/configure --prefix=~/local --target=arm-elf-eabi 
--enable-target-optspace --disable-nls --disable-werror --with-newlib 
--without-headers --enable-multilib --enable-gold --enable-ld

I got output directories for arm thumb and thumb2
arm-elf-eabi/newlib
arm-elf-eabi/thumb/newlib
arm-elf-eabi/thumb/thumb2/newlib
arm-elf-eabi/interwork/newlib
arm-elf-eabi/thumb/interwork/newlib
arm-elf-eabi/thumb/thumb2/interwork/newlib

For all of these a crt0.o has been build
..
gmake[9]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/newlib/ 
-isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld  -mthumb 
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../../env/src/newlib/libc/sys/arm -Os 
-DARM_RDI_MONITOR -fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   
-g -Os  -mthumb -c -o crt0.o 
../../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..
gmake[9]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/interwork/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/interwork/newlib/ 
-isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/interwork/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld  -mthumb-interwork 
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../../env/src/newlib/libc/sys/arm -Os 
-DARM_RDI_MONITOR -fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   
-g -Os  -mthumb-interwork -c -o crt0.o 
../../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..
gmake[9]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/newlib/ 
-isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld  -mthumb -march=armv7 
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../../../env/src/newlib/libc/sys/arm -Os 
-DARM_RDI_MONITOR -fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   
-g -Os  -mthumb -march=armv7 -c -o crt0.o 
../../../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..
gmake[9]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/interwork/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/interwork/newlib/ 
-isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/interwork/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld  -mthumb -mthumb-interwork 
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../../../env/src/newlib/libc/sys/arm -Os 
-DARM_RDI_MONITOR -fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   
-g -Os  -mthumb -mthumb-interwork -c -o crt0.o 
../../../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..
gmake[9]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/interwork/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/interwork/newlib/ 
-isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/thumb/thumb2/interwork/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld  -mthumb -march=armv7 
-mthumb-interwork -DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../../../../env/src/newlib/libc/sys/arm -Os 
-DARM_RDI_MONITOR -fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   
-g -Os  -mthumb -march=armv7 -mthumb-interwork -c -o crt0.o 
../../../../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..
gmake[6]: Entering directory 
`/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/newlib/libc/sys/arm'
arm-elf-eabi-gcc 
-B/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/newlib/ -isystem 
/usr/home/thomas/work/build/env_newlib/arm-elf-eabi/newlib/targ-include 
-isystem /usr/home/thomas/work/env/src/newlib/libc/include 
-L/usr/home/thomas/work/build/env_newlib/./ld    
-DPACKAGE_NAME=\"newlib\" -DPACKAGE_TARNAME=\"newlib\" 
-DPACKAGE_VERSION=\"1.19.0\" -DPACKAGE_STRING=\"newlib\ 1.19.0\" 
-DPACKAGE_BUGREPORT=\"\" -DPACKAGE_URL=\"\" -I. 
-I../../../../../../../env/src/newlib/libc/sys/arm -Os -DARM_RDI_MONITOR 
-fno-builtin     -Os -DARM_RDI_MONITOR -fno-builtin   -g -Os -c -o 
crt0.o ../../../../../../../env/src/newlib/libc/sys/arm/crt0.S
..

When building cross gcc I have uncommented in file 
gcc/config/arm/t-arm-elf the lines
#MULTILIB_OPTIONS      += march=armv7
#MULTILIB_DIRNAMES     += thumb2
and its following parts.
I did the same with
# MULTILIB_OPTIONS    += mno-thumb-interwork/mthumb-interwork
# MULTILIB_DIRNAMES   += normal interwork

I've done this to get support for an ARM7TDMI machine toggling between 
thumb and arm mode,
and  a cortex-m3 machine running thumb/thumb2 code only.

The ARM7TDMI machine usually starting with a crt0 in ARM similar the one 
in arm-elf-eabi/newlib.
The Cortex-M3 machine starts with a THUMB2 crt0 similare the one in 
arm-elf-eabi/thumb/thumb2/newlib
When running a test thumb program in arm-sim the crt0 of 
arm-elf-eabi/thumb/newlib is used.
And at least with this I have had the problem.
The simulator did not like the MOV lo, lo.
Using MOVS lo, lo instead helps.

If this problem is been created by myself. Since usually no 
THUMB/Interwork crt0 would be created
and only a ARM or THUMB2 crt0 would exist.
Then I have to say sorry for the trouble I made.

Regards
   Thomas






More information about the Newlib mailing list