hello:
one small question regarding use of ARM inline assembly code in a
C file that has been compiled for Thumb mode.
is it possible to use ARM assembly code from within a C file that
has been compiled for Thumb and Thumb interworking?
how this is done is described on this page:
http://www.devrs.com/gba/files/asmc.txt
i have a C file that has been compiled for Thumb mode. in it, i am
using ARM inline assembly code. apparently, GCC issues no error
message but forcibly converts the ARM code into Thumb code.
i think that GCC requires an entire file to be in either Thumb mode
or ARM mode, but i am not sure. is that true?
the C code that is compiled into Thumb is:
void function_f( void )
{
asm volatile
(
".align \n"
"__f_into_arm:\n\t"
".arm \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
"pop { r0 } \n"
"__f_from_arm:\n\t"
".thumb"
);
}
the C code is compiled with:
arm-elf-gcc -mlittle-endian -mcpu=arm7tdmi -march=armv4t \
-mthumb-interwork -mthumb -mno-tpcs-frame .....
here is the generated code:
00008194 <function_f>:
8194: b580 push {r7, lr}
8196: af02 add r7, sp, #8
00008198 <__f_into_arm>:
8198: 0000 lsls r0, r0, #0
819a: e10f b.n 83bc <wrap+0x10>
819c: f000 e121 blx 4083e0 <_stack+0x3883e0>
81a0: 0001 lsls r1, r0, #0
81a2: e8bd 46bd ldmia.w sp!, {r0, r2, r3, r4, r5, r7, r9, sl, lr}
000081a4 <__f_from_arm>:
81a4: b08246bd strlth r4, [r2], sp
81a8: bc01bc80 stclt 12, cr11, [r1], {128}
81ac: 00004700 andeq r4, r0, r0, lsl #14
in the inline assembly code, if i do not use ".arm", i get compiler
errors.
is it possible to use ARM assembly code from within a C file that
has been compiled for Thumb and Thumb interworking?
Makefile
--------
CC = arm-elf-gcc
TARGET_ARCH = -mlittle-endian -mcpu=arm7tdmi -march=armv4t
-mthumb-interwork
TARGET_ARCH += -mthumb -mno-tpcs-frame
all: test
arm-elf-objdump -S -D test > test.lst
clean:
rm -f test test.o function.o
test.c
-------
void function_f( void )
{
asm volatile
(
".align \n"
"__f_into_arm:\n\t"
".arm \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
"pop { r0 } \n"
"__f_from_arm:\n\t"
".thumb"
);
}
int main( void )
{
function_f();
return 0;
}
--
{tel: +91-20-6526-7076; cell: +91-9970-591-079; fax: +1-800-450-5419}