FreeRTOS中有少量的内联汇编代码,并不复杂。
准备一些手册,搜索关键字就可以很快的找到有用的信息。
1.准备一些手册
ELF for the Arm Architecture
ARM v7-M Architecture Reference Manual
User Manual The GNU Assembler
GNU ld manual:
http://ftp.gnu.org/old-gnu/Manuals/ld-2.9.1/html_mono/ld.html
https://sourceware.org/binutils/docs/ld/
所有GNU的手册:
2.利用手册去读懂startup.s
startup.s要配合ld script文件一起读,可能还需要先读一下ELF for the Arm Architecture
/*注释的目的是看懂,之后在freertos里也有一些汇编代码*/
.syntax unified
.cpu cortex-m3
.fpu softvfp
.thumb
/*irq vector table and default handler*/
.global g_pfnVectors
.global Default_Handler
/* 指示data bss段的起始位置,赋值在ld script文件中*/
/* start address for the initialization values of the .data section.
defined in linker script */
/*_sidata要结合ld scatter/script文件来确定,实际上存储了data段在flash中的地址*/
.word _sidata
/* start address for the .data section. defined in linker script */
.word _sdata
/* end address for the .data section. defined in linker script */
.word _edata
/* start address for the .bss section. defined in linker script */
.word _sbss
/* end address for the .bss section. defined in linker script */
.word _ebss
/*BootRAM的值是0xF108F85F*/
.equ BootRAM, 0xF108F85F
/**
* @brief This is the code that gets called when the processor first
* starts execution following a reset event. Only the absolutely
* necessary set is performed, after which the application
* supplied main() routine is called.
* @param None
* @retval : None
*/
/*这个text.Reset_Handler很有迷惑性,它就是一个段名,在ld script中有 *(.text*)*/
.section .text.Reset_Handler
/*.weak 如果这个符号名没有被定义,那么就创建它*/
/*在quick referance没有的,要到GNU AS Manual搜索*/
.weak Reset_Handler
/*设置Reset_Handler符号的类型为函数,也就是说Reset_Handler是函数的名字*/
.type Reset_Handler, %function
/*.section定义了Reset_Handler所属的段,.weak和type定义了它的属性*/
Reset_Handler:
/* Copy the data segment initializers from flash to SRAM */
/*汇编指令的语法和功能要参考对应的指令集,简单的就不再注释*/
/*这段代码是未后面的代码完成必要的初始化工作,所以并没有出现压栈和出栈操作*/
movs r1, #0 /*r1=0,r1是传递给LoopCopyDataInit的一个参数,可以查询APCS*/
b LoopCopyDataInit /*b即branch,所以接下来跳转到LoopCopyDataInit标号执行*/
C