MDK开发环境STM32启动文件_main函数分析

MDK开发环境 STM32启动文件_main函数分析

一直对STM32启动文件不了解,在此记录以供查阅。  
========================================================================
** Section #1 'ER_IROM1' (SHT_PROGBITS) [SHF_ALLOC + SHF_EXECINSTR]
    Size   : 1008 bytes (alignment 4)
    Address: 0x08000000

    $d.realdata
    RESET
    __Vectors                                                                               ;向量表起始地址
        0x08000000:    20000460    `..     DCD    536872032                                 ;栈顶指针地址0x20000460
        0x08000004:    08000369    i...    DCD    134218601                                 ;Reset_Handler地址
        0x08000008:    08000371    q...    DCD    134218609
        0x0800000c:    08000373    s...    DCD    134218611
        0x08000010:    08000375    u...    DCD    134218613
        0x08000014:    08000377    w...    DCD    134218615
        0x08000018:    08000379    y...    DCD    134218617

        ...

    $t
    .ARM.Collect$$$$00000000
    .ARM.Collect$$$$00000001
    __Vectors_End                                                                           ;向量表结束                       
    __main
    _main_stk
        0x08000130:    f8dfd00c    ....    LDR      sp,__lit__00000000 ; [0x8000140] = 0x20000460
    .ARM.Collect$$$$00000004                                                                ;设置栈顶指针
    _main_scatterload
        0x08000134:    f000f92a    ..*.    BL       __scatterload ; 0x800038c               ;跳转到__scatterload
    .ARM.Collect$$$$00000008
    .ARM.Collect$$$$0000000A
    .ARM.Collect$$$$0000000B
    __main_after_scatterload
    _main_clock
    _main_cpp_init
    _main_init
        0x08000138:    4800        .H      LDR      r0,[pc,#0] ; [0x800013c] = 0x8000145    ;跳转到main函数, 0x0800013c
        0x0800013a:    4700        .G      BX       r0
    $d
        0x0800013c:    08000145    E...    DCD    134218053
    .ARM.Collect$$$$00002712
    __lit__00000000
    .ARM.Collect$$$$0000000D
    .ARM.Collect$$$$0000000F
    __rt_final_cpp
    __rt_final_exit
        0x08000140:    20000460    `..     DCD    536872032
    $t
    .text
    main                                                                                    ;main函数  
        0x08000144:    bf00        ..      NOP      
        0x08000146:    bf00        ..      NOP      
        0x08000148:    2003        .       MOVS     r0,#3
        0x0800014a:    490c        .I      LDR      r1,[pc,#48] ; [0x800017c] = 0x20000000
        ...

    SystemInit                                                                              ;SystemInit函数                                                 
        0x08000266:    b510        ..      PUSH     {r4,lr}                             
        0x08000268:    4836        6H      LDR      r0,[pc,#216] ; 
        ...

    .text
    Reset_Handler
        0x08000368:    4806        .H      LDR      r0,[pc,#24] ; [0x8000384] = 0x8000267   ;加载SystemInit函数地址到R0,0x08000267
        0x0800036a:    4780        .G      BLX      r0                                      ;跳转到SystemInit
        0x0800036c:    4806        .H      LDR      r0,[pc,#24] ; [0x8000388] = 0x8000131   ;加载_main函数地址到R0,0x8000131
        0x0800036e:    4700        .G      BX       r0                                      ;跳转到_main
    ```
    $d
        0x08000384:    08000267    g...    DCD    134218343
        0x08000388:    08000131    1...    DCD    134218033
    $t
    .text
    __scatterload
    __scatterload_rt2                                                                       
                                                                                            ;在RO段最后一部分,0x80003d0 - 0x80003f0存储的是
                                                                                            ;RW和ZI段的加载域、存储域地址、段长度、以及RW段拷贝
                                                                                            ;__scatterload_copy、ZI清零__scatterload_zeroinit
                                                                                            ;函数的地址
        0x0800038c:    4c06        .L      LDR      r4,[pc,#24] ; [0x80003a8] = 0x80003d0   ;R4 = 0x80003d0, Region$$Table的起始地址
        0x0800038e:    4d07        .M      LDR      r5,[pc,#28] ; [0x80003ac] = 0x80003f0	;R5 = 0x80003f0, Region$$Table的结束地址
        0x08000390:    e006        ..      B        0x80003a0 ; __scatterload + 20          
        0x08000392:    68e0        .h      LDR      r0,[r4,#0xc]                            ;加载R4+0xC地址的值到R0,RW段拷贝或ZI清零函数的地址
        0x08000394:    f0400301    @...    ORR      r3,r0,#1                                ;R3 = [R0] | 0x1, R0最低位置1,给R3
        0x08000398:    e8940007    ....    LDM      r4,{r0-r2}                              ;加载RW或ZI段的加载域、运行域地址以及段长度 到R0 R1 R2
        0x0800039c:    4798        .G      BLX      r3                                      ;跳转到RW段拷贝或ZI清零函数
        0x0800039e:    3410        .4      ADDS     r4,r4,#0x10                             ;段拷贝完成后,开始进行ZI清零, R4 + 0x10
        0x080003a0:    42ac        .B      CMP      r4,r5                                   ;比较R4, R5
        0x080003a2:    d3f6        ..      BCC      0x8000392 ; __scatterload + 6           ;R4 R5不相等时,跳转到0x8000392
        0x080003a4:    f7fffec8    ....    BL       __main_after_scatterload ; 0x8000138    ;RW段拷贝和ZI段清零完成后,进入main函数
    $d
        0x080003a8:    080003d0    ....    DCD    134218704
        0x080003ac:    080003f0    ....    DCD    134218736
    $t
    i.__scatterload_copy
    __scatterload_copy
        0x080003b0:    e002        ..      B        0x80003b8 ; __scatterload_copy + 8
        0x080003b2:    c808        ..      LDM      r0!,{r3}                                ;R0为RW段加载域地址, R3 = [R0], R0 = R0 + 4
        0x080003b4:    1f12        ..      SUBS     r2,r2,#4                                ;R2为RW段数据长度, R2减4
        0x080003b6:    c108        ..      STM      r1!,{r3}                                ;R1为RW段运行域地址, R3值写入R1地址
        0x080003b8:    2a00        .*      CMP      r2,#0                                   ;R2为剩余待拷贝RW段长度
        0x080003ba:    d1fa        ..      BNE      0x80003b2 ; __scatterload_copy + 2      ;拷贝未完成,继续拷贝
        0x080003bc:    4770        pG      BX       lr                                      ;返回0x0800039F
    i.__scatterload_null
    __scatterload_null
        0x080003be:    4770        pG      BX       lr
    i.__scatterload_zeroinit
    __scatterload_zeroinit          
        0x080003c0:    2000        .       MOVS     r0,#0
        0x080003c2:    e001        ..      B        0x80003c8 ; __scatterload_zeroinit + 8  
        0x080003c4:    c101        ..      STM      r1!,{r0}                                ;R0的值写入R1地址, R1 + 4
        0x080003c6:    1f12        ..      SUBS     r2,r2,#4                                ;R2为ZI段数据长度, R2减4
        0x080003c8:    2a00        .*      CMP      r2,#0                                   ;R2为剩余待清零的数据长度
        0x080003ca:    d1fb        ..      BNE      0x80003c4 ; __scatterload_zeroinit + 4  ;清零未完成,继续
        0x080003cc:    4770        pG      BX       lr                                      ;返回0x0800039F               
        0x080003ce:    0000        ..      MOVS     r0,r0
    $d.realdata
    Region$$Table$$Base
        0x080003d0:    080003f0    ....    DCD    134218736                                 ;加载域RW段地址
        0x080003d4:    20000000    ...     DCD    536870912                                 ;运行域RW段地址
        0x080003d8:    0000001c    ....    DCD    28                                        ;RW段长度
        0x080003dc:    080003b0    ....    DCD    134218672                                 ;__scatterload_copy函数地址
        0x080003e0:    0800040c    ....    DCD    134218764                                 ;加载域结束地址
        0x080003e4:    2000001c    ...     DCD    536870940                                 ;运行域ZI段地址
        0x080003e8:    00000444    D...    DCD    1092                                      ;ZI段长度
        0x080003ec:    080003c0    ....    DCD    134218688                                 ;__scatterload_zeroinit函数地址
    Region$$Table$$Limit

   Section #2 'RW_IRAM1' (SHT_PROGBITS) [SHF_ALLOC + SHF_WRITE]                             ;RW段地址0x20000000, 长度28 bytes
    Size   : 28 bytes (alignment 4)
    Address: 0x20000000

   Section #3 'RW_IRAM1' (SHT_NOBITS) [SHF_ALLOC + SHF_WRITE]                               ;ZI段地址0x2000001c, 长度1092 bytes
    Size   : 1092 bytes (alignment 8)
    Address: 0x2000001c

你可能感兴趣的:(STM32)