STM32/GCC: Problems calling assembly from C.

Hi!

I have a small C program from which I attempt to call a function implemented in a separate assembly file:

	.thumb
	@ Code to .text segment:
	.text

	@ r0 = pointer to PCB to start with.
	.global CM3_start
CM3_start:
	add	r1, r0, #4 	@ r1 = &thread_stack_top
	ldr	r1, [r1]	@ Set r1 = thread_stack_top.
	sub	r1, r1, #32	@ 8 regs will be popped during 'bx lr'.
	msr	PSP, r1		@ Initialize process stack pointer.
	ldr	r1, =0xfffffffd
	mov	lr, r1		@ Use process stack when returning.
	bx	lr		@ Return, starting the process.

The assembly is assembled using:

arm-elf-as -mfpu=softfpa -mcpu=cortex-m3 -mthumb -o os_s.o os_s.s

The C file is compiled using the following flags:

-c -g -O0 -fno-common -mcpu=cortex-m3 -mthumb 

And the link:

arm-elf-ld -T link.cmd -o os os.o os_s.o 

I keep getting linker warnings such as:

arm-elf-ld: os_s.o(CM3_start): warning: interworking not enabled.
  first occurrence: os.o: Thumb call to ARM

In spite of the warnings, a proper executable seems to be created. Using objdump I can show that there is really just thumb2 code in all object files. Gcc version is 4.3.2. Does anyone have a clue?

Hello,

I think you need “.thumb_func” too before the function label.

Giovanni

Thanks a lot! Or grazie mille, maybe :slight_smile:

You’re absolutely right, works fine now! And right now, I’m reading http://stuff.mit.edu/afs/sipb/project/e … terworking to find out why!