2013-07-06 15 views
0

我正在嘗試使用符號文件來鏈接CortexM3上的程序。 '程序'在RAM中運行並使用ROM中的靜態綁定功能。所以我使用符號文件來標識所有ROM功能的地址。如何使用皮質M3的符號文件?

的問題是,海灣合作委員會似乎認爲,在symbolfile所有功能都ARM32,而不是拇指,所以我結束了一個拇指> ARM32轉換(當然崩潰,因爲M3不支持ARM32說明)

test.c的:

extern void tfunc(); 
int main() 
{ 
    tfunc(); 
    return 0; 
} 

symbolfile:

tfunc = 0x08011029; 

編譯:

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -c test.c 
arm-none-eabi-ld test.o --just-symbols=symbolfile 

像碼結果:

arm-none-eabi-objdump -d a.out 

a.out:  file format elf32-littlearm 


Disassembly of section .text: 

00008000 <main>: 
    8000: b580  push {r7, lr} 
    8002: af00  add r7, sp, #0 
    8004: f000 e804 blx 8010 <__tfunc_from_thumb> 
    8008: 2300  movs r3, #0 
    800a: 4618  mov r0, r3 
    800c: bd80  pop {r7, pc} 
    800e: bf00  nop 

00008010 <__tfunc_from_thumb>: 
    8010: e51ff004 ldr pc, [pc, #-4] ; 8014 <__tfunc_from_thumb+0x4> 
    8014: 08011029 .word 0x08011029 

注意「BLX」呼叫的是偶數地址,而M3規範任務的所有跳躍都爲奇數(拇指)地址

我發現在線使用,而不是一個symbolfile彙編了各種各樣的解決方案: sym.s:

.global tfunc 
    .type tfunc %function 
    .equ tfunc, 0x08011029 

和建築:

arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb -c test.c 
arm-none-eabi-as -o sym.o sym.s 
arm-none-eabi-ld test.o sym.o 

產生一個(相當冗長,butat至少在功能上正確的貼面):

00008000 <main>: 
    8000: b580  push {r7, lr} 
    8002: af00  add r7, sp, #0 
    8004: f000 f804 bl 8010 <__tfunc_veneer> 
    8008: 2300  movs r3, #0 
    800a: 4618  mov r0, r3 
    800c: bd80  pop {r7, pc} 
    800e: bf00  nop 

00008010 <__tfunc_veneer>: 
    8010: b401  push {r0} 
    8012: 4802  ldr r0, [pc, #8] ; (801c <__tfunc_veneer+0xc>) 
    8014: 4684  mov ip, r0 
    8016: bc01  pop {r0} 
    8018: 4760  bx ip 
    801a: bf00  nop 
    801c: 08011029 .word 0x08011029 

我發現我可以通過添加「的#pragma long_calls」到頂部解決此長叫我c代碼。

但是,我的問題不是如何讓我的代碼正確構建,它是如何使用帶有CortexM的符號文件,因爲有些情況下#pragma不起作用,而組裝選項會是可行的,它使構建系統顯著更復雜

回答

0

注意「BLX」調用是一個偶地址

這些功能是由鏈接ld產生。

arm-none-eabi-ld test.o --just-symbols=symbolfile

你必須告訴您要生成Thumb代碼arm-none-eabi-ld。使用arm-none-eabi-gcc作爲前端進行鏈接通常比較簡單。

相關問題