Startup Code
SC100 C Compiler
6-3
6.1.2 C Environment Startup Code
The C environment startup phase is applicable to all programs. The entry point for this phase is
___start
.
This phase includes initialization code used prior to program start, and finalization code used after the
application terminates.
6.1.2.1 C environment initialization code
The following initialization actions are executed before the application starts:
1.
The memory map is set up and initialized. The stack pointer (SP) value is loaded into memory
by the stack start address, located at
StackStart
. This label is defined in the linker
command file and used by the linker at link time. For further information about the memory
map, see
Section 6.2,
“
Memory Models.
”
2.
If the
-mrom
option has been specified in the shell command line, initialized variables are
copied from ROM into RAM. This option is required for applications which do not use a
loader.
3.
The
argv
and
argc
arguments are set up.
4.
Interrupts are enabled
.
Until this point, interrupts have been disabled.
5.
The application main procedure entry point is called using the function
main
.
6.1.2.2 Initialization of variables
If your system uses a loader, this will by default initialize all variables. In systems that do not include a
loader, it is important that you specify the
-mrom
option when you compile the final version of your
application, to ensure that the initialized variables are copied from ROM into RAM at startup.
Note:
Before a C program executes, certain global variables may assume the assignment of an initial value
of zero. The compiler does not preinitialize variables automatically. You must ensure that your code
includes explicit initialization of any variable that must have an initial value of zero.
6.1.2.3 C environment finalization code
The following steps are activated on return from the application main function:
The runtime function
exit
is called. This terminates any I/O services which have not yet terminated,
and stops the processor by issuing the
stop
instruction.
Certain embedded real time applications never terminate. Such termination activities do not usually
pertain to embedded applications, but may be of use during early development and debugging
stages.
Note:
6.1.2.4 Low level I/O services
The C environment startup code includes the input and output of low level, buffered I/O services. The code
uses calls to
__send
and
__receive
in order to interface with debugging tools and/or runtime systems.