Source code structure

QNX SDP8.0Building Embedded SystemsConfigurationDeveloper

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:
  • disables interrupts, because the startup module can't handle interrupts
  • sets the location of the C stack
  • turns off the cache, if required
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:
  • sets up startup command-line options, so they can be passed into the main() function’s argument vector (argv[])
  • sets up what will happen when the main() function returns (e.g., jump into procnto)
  • calls main()
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.
Page updated: