[英]Compiling assembly code with gcc for STM32
我嘗試為STM32編譯了一個簡單的匯編程序來檢查GCC是否正常工作:
.syntax unified
.cpu cortex-m3
.thumb
.word 0x20000400
.word 0x080000ed
.space 0xe4
nop
arm-none-eabi-gcc -mcpu=cortex-m3 -mthumb main.s
編譯器產生以下消息:
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7-m/nofp/crt0.o: in function `_mainCRTStartup':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7-m/nofp/libgloss/arm/semihv2m/../../../../../../../../libgloss/arm/crt0.S:545: undefined reference to `main'
/usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/bin/ld: /usr/lib/gcc/arm-none-eabi/10.3.1/../../../arm-none-eabi/lib/thumb/v7-m/nofp/libc.a(lib_a-exit.o): in function `exit':
/build/newlib-pB30de/newlib-3.3.0/build/arm-none-eabi/thumb/v7-m/nofp/newlib/libc/stdlib/../../../../../../../../newlib/libc/stdlib/exit.c:64: undefined reference to `_exit'
collect2: error: ld returned 1 exit status
即使在做了一些研究之后,我也無法確定發生的問題。 我了解編譯器的基本原理,但不精通 GCC。
如果您的目標只是驗證您的 gcc 是否正常工作,您可以使用以下命令構建可執行文件 - 您的程序略有修改,以便它有一個入口點 (Reset_Handler),並且.space 0xe4
現在是.space 0xf8
所以該代碼將在 4 字節邊界上對齊。 我決定程序將從0x00080100
開始,但根據目標上中斷向量的數量,這可能是一個不同的值。
.syntax unified
.cpu cortex-m3
.thumb
.word 0x20000400
.word 0x08000100
.space 0xf8
.text
.global ResetHandler
ResetHandler:
nop
.end
編譯/鏈接:
arm-none-eabi-gcc -o main.elf main.s -nostartfiles -nostdlib -e ResetHandler -Wl,-Ttext,0x080000
轉儲內存內容/反匯編:
arm-none-eabi-objdump -D -s -j .text main.elf
main.elf: file format elf32-littlearm
Contents of section .text:
80000 00040020 00010008 00000000 00000000 ... ............
80010 00000000 00000000 00000000 00000000 ................
80020 00000000 00000000 00000000 00000000 ................
80030 00000000 00000000 00000000 00000000 ................
80040 00000000 00000000 00000000 00000000 ................
80050 00000000 00000000 00000000 00000000 ................
80060 00000000 00000000 00000000 00000000 ................
80070 00000000 00000000 00000000 00000000 ................
80080 00000000 00000000 00000000 00000000 ................
80090 00000000 00000000 00000000 00000000 ................
800a0 00000000 00000000 00000000 00000000 ................
800b0 00000000 00000000 00000000 00000000 ................
800c0 00000000 00000000 00000000 00000000 ................
800d0 00000000 00000000 00000000 00000000 ................
800e0 00000000 00000000 00000000 00000000 ................
800f0 00000000 00000000 00000000 00000000 ................
80100 00bf ..
Disassembly of section .text:
00080000 <ResetHandler-0x100>:
80000: 20000400 andcs r0, r0, r0, lsl #8
80004: 08000100 stmdaeq r0, {r8}
...
00080100 <ResetHandler>:
80100: bf00 nop
理想情況下,您現在需要:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.