Specifications
Boot Sequence for HAL-Based Programs
System Initialization Code Boot Sequence
The HAL provides system initialization code in the C runtime library (crt0.S). This code performs the
following boot sequence:
• Flushes the instruction and data cache.
• Configures the stack pointer.
• Configures the global pointer register.
• Initializes the block started by symbol (BSS) region to zeroes using the linker-supplied symbols
__bss_start and __bss_end. These are pointers to the beginning and the end of the BSS region.
• If there is no boot loader present in the system, copies to RAM any linker section whose run address is
in RAM, such as .rwdata, .rodata, and .exceptions.
For more information, refer to Global Pointer Register.
• Calls alt_main().
Related Information
Global Pointer Register on page 6-39
Default Implementation Steps
The HAL provides a default implementation of the alt_main() function, which performs the following
steps:
• Calls the alt_irq_init() function, located in alt_sys_init.c. alt_irq_init() initializes the
hardware interrupt controller. The Nios II development flow creates the file alt_sys_init.c for each HAL
BSP.
• Calls ALT_OS_INIT() to perform any necessary operating system specific initialization. For a system
that does not include an operating system (OS) scheduler, this macro has no effect.
• If you are using the HAL with an operating system, initializes the alt_fd_list_lock semaphore,
which controls access to the HAL file systems.
• Enables interrupts.
• Calls the alt_sys_init() function, also located in alt_sys_init.c. alt_sys_init() initializes all
device drivers and software packages in the system.
• Redirects the C standard I/O channels (stdin, stdout, and stderr) to use the appropriate devices.
• Calls the C++ constructors, using the _do_ctors() function.
• Registers the C++ destructors to be called at system shutdown.
• Calls main().
• Calls exit(), passing the return code of main() as the input argument for exit().
alt_main.c, installed with the Nios II EDS, provides this default implementation. The SBT copies alt_main.c
to your BSP directory.
Customizing the Boot Sequence
You can provide your own implementation of the start-up sequence by simply defining alt_main() in
your Nios II project. This gives you complete control of the boot sequence, and allows you to selectively
enable HAL services. If your application requires an alt_main() entry point, you can copy the default
implementation as a starting point and customize it to your needs.
NII5V2
2015.05.14
Boot Sequence for HAL-Based Programs
6-35
Developing Programs Using the Hardware Abstraction Layer
Altera Corporation
Send Feedback