Real-Time Systems Development

A program written in C and compiled with gcc will need a startup routine to run first. This preliminary code is called crt0 (C Run-time) and may require some modification according to the target environment that is to be used. Startup code is usually written in assembler, and it has to be linked to run first and thus set up the basic facilities for the rest of the application. A template source file crt0.S is usually provided to assist with the development of bespoke versions for particular target systems. So, returning to the gcc cross-compilation example, the newlib library comes with a whole group of architecture-dependent crt0.S files in the ${PREFIX}/newlib-1.12.0/newlib/libc/sys/directory. Here is one of the few opportunities that a programmer has to indulge in assembler-level coding, albeit only a dozen lines of code! The startup code needs to do the following things:
Initialize anything that still needs to be initialized. This varies from system to system. If the application gets downloaded using a ROM monitor, then there is usually no need for any hardware initialization. The ROM monitor probably handles it for you. If the plan is to burn the code into a ROM, then the crt0 typically has to do all the hardware initialization required to run the application. This can include initializing the stack and heap, as well as serial port hardware and the memory management unit.
The .bss section for uninitialized data can be cleared to zero. In this case, all the pointer...