Re: QUERY : ARM mode inline instructions in C Thumb mode file?
- From: "gdisirio" <herpes@xxxxxx>
- Date: Wed, 27 Aug 2008 02:24:58 -0500
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\t"
".arm \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
"pop { r0 }"
);
}
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
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}
81a6: b082 sub sp, #8
81a8: bc80 pop {r7}
81aa: bc01 pop {r0}
81ac: 4700 bx r0
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?
Aaron
Makefile
--------
CC = arm-elf-gcc
TARGET_ARCH = -mlittle-endian -mcpu=arm7tdmi -march=armv4t
TARGET_ARCH += -mthumb -mno-tpcs-frame -mthumb-interwork
all: test
arm-elf-objdump -S -D test > test.lst
clean:
rm -f test test.o function.o
C CODE
------
void function_f( void )
{
asm volatile
(
".align \n\t"
".arm \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
"pop { r0 }"
);
}
int main( void )
{
function_f();
return 0;
}
Try this:
void function_f( void )
{
asm volatile
(
".code 32 \n\t"
"mrs r0, cpsr \n\t"
"msr cpsr_c, r0 \n\t"
".code 16 \n\t"
"pop { r0 }"
);
}
It generates:
function_f:
.code 32
mrs r0, cpsr
msr cpsr_c, r0
.code 16
pop { r0 }
bx lr
You need to return to thumb mode after inserting the arm code or the
assembles will get confused.
BTW, that "pop r0" will crash the program.
regards,
Giovanni Di Sirio
---
ChibiOS/RT http://chibios.sourceforge.net
.
- Follow-Ups:
- Re: QUERY : ARM mode inline instructions in C Thumb mode file?
- From: Wilco Dijkstra
- Re: QUERY : ARM mode inline instructions in C Thumb mode file?
- Prev by Date: Prodrive MCCB-3
- Next by Date: Helpful :)
- Previous by thread: Prodrive MCCB-3
- Next by thread: Re: QUERY : ARM mode inline instructions in C Thumb mode file?
- Index(es):
Relevant Pages
|