Source code structure

Most of the startup code is stored in the main() function, which follows the _start() and _main() functions in the startup code sequence.

The _start() function is the entry point to the startup program (e.g., hardware/startup/lib/arm/cstart.S). This function sets up an environment for executing C code. Specifically, the _start() function:

When it completes its work, _start() calls _main(), which prepares the environment for the subsequent main() (without the underscore) function. Specifically, the earlier _main() function:

The pseudo-code below shows the structure of the main() function, with links to the entries for each called function in the Startup Library chapter:

Global variables

main()
{
    // Initialize hardware 
    Call add_callout_array()

    // Parse commandline arguments
    Call handle_common_option()

    // Remove ram used by modules in the image
    Call init_raminfo()
    
    // Initialize the MMU
    if (virtual) Call init_mmu()

    Call init_intrinfo()
    Call init_qtime()
    Call init_cacheattr()
    Call init_cpuinfo()

    // Set hardware machine name
    Call init_system_private()

    //  Print debugging output
    Call print_syspage()
}
Note: You should examine the commented source for each function in the startup library to see if you need to replace any library functions with your own functions.