Friday, November 7, 2008

Function of C Start-up routine

C start-up routine

A C program start with a main() function . A function can only be called from another function. The main() is called by the start-up routines in the operating system. After that the program start executing from the main() and value will returned to the caller depending upon the implementation.

Functions of C start-up routine:

The given below are the series of functions done by the start-up routine while calling the main ().

Disable all the interrupts.

Copy any initialized data from ROM to RAM.

Fill the un-initialized area with zeroes.

Allocates the space for stack and initializes the stack.

Initializes the processor stack pointer.

Creates and initializes heap.

Execute the constructor and initializes all global variables.

Enabling the interrupts.

Call the main().

Some more instructions.- This will be executed only in the event that the high level programs exits. Depending upon the nature of the embedded system, the instruction my halt processor, or reset the entire system or transfer the control to a debugging tool.


Hardware and Software initialization process:

Reset Code

H/W

Initialization

Start-up Code

Main()

Reset Code:

It consist of two or three instructions that the processor executes immediately after POR(Power On Reset). The aim is to transfer control to the hardware initialization routine. The first instruction of the reset code must be places at a specific location in memory called Reset Address.

Hardware Initialization:

This is to inform the processor about the runtime environment. This is a good place to initialize interrupt controller and other critical peripherals.

No comments: