I am developping a firmware on an ARM CORTEX M3 processor, with IAR IDE (v6.50). I am wondering the usefullness of the label used for the program entry. I explain.
On the ARM platform, when the chip is reset the PC is loaded with one of the entry of the vector table (the second entry in my case). So the program will start from this adress at power time and at every next reset. So the start address depends on what is declared in this entry. But in the IAR options, it is possible to define a label as the program entry. By default, the program entry is __iar_program_start. It is possible to override it.
But if the PC is loaded with the second entry of the vector table on reset, what is the IAR entry point used for?
I am wondering that question because I am trying to integrate the CMSIS layer in my existing firmware, and the entry point is not __iar_program_start anymore, but Reset_Handler. In the IAR option, I first tryed to override the default entry point __iar_program_start by "Reset_Handler" but I had an ielftool error ("ielftool error: The string '__vector_table' was not found in the string table "). The solution is to let the default program entry point in the IAR linker option but I can't understand why it souldn't be the Reset_Handler label.
Here's a part of my startup code for the example (it's running):
MODULE ?cstartup
;; Forward declaration of sections.
SECTION CSTACK:DATA:NOROOT(3)
SECTION PSTACK:DATA:NOROOT(3)
SECTION .intvec:CODE:NOROOT(2)
EXTERN __cmain
EXTERN SystemInit
EXTERN vPortSVCHandler ; SVCall_Handler is renamed here
EXTERN xPortPendSVHandler ; PendsSV_Handler is renamed here
EXTERN xPortSysTickHandler ; SysTick_Handler is renamed here
PUBLIC __vector_table
PUBLIC __vector_table_0x1c
PUBLIC __Vectors
PUBLIC __Vectors_End
PUBLIC __Vectors_Size
DATA
__vector_table:
DCD sfe(CSTACK) ; Top of Stack
DCD Reset_Handler ; Reset Handler
DCD NMI_Handler ; NMI Handler
DCD HardFault_Handler ; Hard Fault Handler
DCD MemManage_Handler ; MPU Fault Handler
DCD BusFault_Handler ; Bus Fault Handler
DCD UsageFault_Handler ; Usage Fault Handler
__vector_table_0x1c:
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD 0 ; Reserved
DCD vPortSVCHandler ; SVCall Handler
DCD DebugMon_Handler ; Debug Monitor Handler
DCD 0 ; Reserved
DCD xPortPendSVHandler ; PendSV Handler
DCD xPortSysTickHandler ; SysTick Handler
; External Interrupts
...
__Vectors_End
__Vectors EQU __vector_table
__Vectors_Size EQU __Vectors_End - __Vectors
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;
;; Default interrupt handlers.
;;
THUMB
PUBWEAK Reset_Handler
SECTION .text:CODE:REORDER(2)
Reset_Handler
LDR R0, =SystemInit
BLX R0
LDR R0, =__iar_program_start
BX R0
... Other handlers....
__iar_program_start:
;Process stack initialization
MRS r0, CONTROL ; Get PSR
ORR r0,r0,#0x00000002 ; Use Process Stack instead of Main Stack
MSR CONTROL, r0 ;
ISB ; flush pipeline
LDR sp, =SFE(PSTACK) ; init Process Stack address
;Get back with Main Stack
MRS r0, CONTROL
AND r0,r0,#0xFFFFFFFD
MSR CONTROL, r0
ISB
BL __cmain
END
This is old but I'll answer it anyways.
If you look at startup_.s you should see something like this
Reset_Handler
CPSID I ; Mask interrupts
LDR R0, =0xE000ED08
LDR R1, =__vector_table
STR R1, [R0]
LDR R2, [R1]
MSR MSP, R2
LDR R0, =SystemInit
BLX R0
CPSIE I ; Unmask interrupts
LDR R0, =__iar_program_start
BX R0
As you can see Reset_Handler branches to __iar_program_start
User contributions licensed under CC BY-SA 3.0