Understanding C runtime environment (ARM) - where to start

前端 未结 5 1887
青春惊慌失措
青春惊慌失措 2021-02-06 01:54

I\'am embedded developer working with ARM Cortex-M devices mainly. Recently I\'ve switched to Linux and decided to learn more about the build/assemble/link process, how to write

5条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 02:07

    The modules you are referring to (ctr0.o, crti.o, _init, __libc_init_array, _exit) are prebuilt libraries/object files/functions by IAR and/or Keil. As you are saying they are needed to get the environment initialized (global variables initialization, interrupt vector table, etc.) before running your main() function.

    At some point in those libraries/object files there will be a function in C or assembly like this:

    void startup(void)
    { 
        ... init code ...
    
        main();
    
        while(1);   // or _exit()
    }
    

    You may look into these examples that build the startup code from scratch:

    http://www.embedded.com/design/mcus-processors-and-socs/4007119/Building-Bare-Metal-ARM-Systems-with-GNU-Part-1--Getting-Started

    https://github.com/payne92/bare-metal-arm

提交回复
热议问题