This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

the relationship between startup_ARMCM3.s and gcc_arm.ld from Cortex-M3 of MDK5.

Dear All,
Currently now I'm trying to undersatnd the relationship between startup_ARMCM3.s and gcc_arm.ld from Cortex-M3 of MDK5.
the following codes are refered from Cortex-M3 of MDK5 example code.


1 //---startup_ARMCM3.s----------//
2
3 __HeapLimit:
4 .size __HeapLimit, . - __HeapLimit
5
6 .section .vectors
7 .align 2
8 .globl __Vectors
9 __Vectors:
10 .long __StackTop /* Top of Stack */
11 .long Reset_Handler /* Reset Handler */
12 .long NMI_Handler /* NMI Handler */
13 .long HardFault_Handler /* Hard Fault Handler */
14
15 .size __Vectors, . - __Vectors
16
17 .text
18 .thumb
19 .thumb_func
20 .align 2
21 .globl Reset_Handler
22 .type Reset_Handler, %function
23 Reset_Handler:
24
25
26 //---gcc_arm.ld----------//
27 ENTRY(Reset_Handler)
28
29 SECTIONS
30 {
31 .text :
32 {
33 KEEP(*(.vectors))
34 __Vectors_End = .;
35 __Vectors_Size = __Vectors_End - __Vectors;
36 __end__ = .;
37
38 *(.text*)

I want to know how to interpret the both code.
Especially,
1. at the line 33 of gcc_arm.ld, what exactly .vectors indicate the range on the startup_ARMCM3.s ?
2. at the line 38 of gcc_arm.ld, what exactly .text indicate the range n the startup_ARMCM3.s ?
3. what is the relationship between gcc_arm.ld (line 27) of ENTRY(Reset_Handler) and startup_ARMCM3.s (line 23) of Reset_Handler: ?

  • Hi ele,

    I'm not sure what you mean by "what exactly X indicate the range of Y", hopefully my explanation below will answer your question.

    Line 6 to 15 define an array of pointers (__StackTop, Reset_Handler, NMI_Handler, HardFault_Handler) which is put into the .vectors section of your executable. In gcc_arm.ld, .vectors (line 33) is the first input sections listed for the .text output section (line 31) so the .vectors will be at the beginning of the .text output section. Since no address or region is given for the .text output section, it will start at address 0x0 [1] and hence the array of pointers will be your interrupt table and execution will start in Reset_Handler thanks to line 27.

    [1] https://sourceware.org/binutils/docs/ld/Output-Section-Address.html#Output-Section-Address

    Then after the .vectors input sections come all the .text input sections. So in your final executable you will have:

    0x0 start of .text (output section)
    .vectors (from first object file)
    .vectors (from second object file)
    etc…
    .text (from first object file)
    .text (from second object file)
    etc…

    Best regards,

    Thomas