在main()之前,iar都做了啥(What did IAR do before main ()).doc
文本预览下载声明
在main()之前,iar都做了啥(What did IAR do before main ())
[original] before main (), what did IAR do? Collection
Recently, I wrote a simple operating system on Cortex-M3 and decided to use IAR. In order to write the startup code, I took some time to understand what IAR did before main ().
First, when the system is reset, the Cortex-M3 obtains the stack top address from the code area offset 0to initialize the value of the MSP register.
Next, move the jump address of the first instruction from the code area offset 0 These addresses are where CM3 requires the interrupt vector table to be placed.
Here is the disassembly of a programs boot zone:
__vector_table:
080040002600
0800400220007E1D
080040060800
This program is started by the IAP program. The IAP program gets the MSP value (0 at 0and sets the value to MSP, which is the maximum 00x200025FF of the main stack. Next, the IAP program gets the address of the Reset_Handler at 0(0x08007E1D) and jumps to Reset_Handler () to execute.
IAP here is a complete imitation of the Cortex-M3 reset sequence, that is, in the absence of IAP system, CM3 can only get MSP from 0 from 0access to the address of the first instruction. And IAP exists on the 0address, IAP startup, has consumed the reset sequence, so IAP to start the UserApp program, but also completely imitate the Cortex-M3 reset sequence.
Next, lets look at the first instruction after reset - whats in the Reset_Handler () function?.
If were using the ST standard peripheral library, then theres already a ready Reset_Handler, but hes a weak definition - PUBWEAK, which can be overridden by the same name we rewrite. In general, we are using the ST provided by Reset_Handler, which can be found in startup_stm32f10x_xx.s in the library of the V3.4 version:
PUBWEAK Reset_Handler
SECTION.Text:CODE:REORDER (2)
Reset_Handler
LDR, R0, =SystemInit
BLX R0
LDR, R0, =__iar_program_start
BX R0
It seem
显示全部