Specifications

Eliminate All Exit Code
Many embedded systems never exit at all. In such cases, exit code is unnecessary. You can eliminate all
exit code through a BSP setting.
Note: If you enable this option, ensure that your main() function (or alt_main() function) does not
return.
Turn off C++ Support
By default, the HAL provides support for C++ programs, including default constructors and destructors.
You can disable C++ support through a BSP setting.
Boot Sequence and Entry Point
Normally, your program’s entry point is the function main(). There is an alternate entry point,
alt_main(), that you can use to gain greater control of the boot sequence. The difference between
entering at main() and entering at alt_main() is the difference between hosted and free-standing
applications.
Hosted Versus Free-Standing Applications
The ANSI C standard defines a hosted application as one that calls main() to begin execution. At the start
of main(), a hosted application presumes the runtime environment and all system services are initialized
and ready to use. This is true in the HAL environment. If you are new to Nios II programming, the HAL’s
hosted environment helps you come up to speed more easily, because you need not consider what devices
exist in the system or how to initialize each one. The HAL initializes the whole system.
The ANSI C standard also provides for an alternate entry point that avoids automatic initialization, and
assumes that the Nios II programmer initializes any needed hardware explicitly. The alt_main() function
provides a free-standing environment, giving you complete control over the initialization of the system.
The free-standing environment places on the programmer the responsibility to initialize any system
features used in the program. For example, calls to printf() do not function correctly in the free-
standing environment, unless alt_main() first instantiates a character-mode device driver, and redirects
stdout to the device.
Note:
Using the free-standing environment increases the complexity of writing Nios II programs,
because you assume responsibility for initializing the system.
For more information about reducing code footprint, refer to and use the suggestions described in the
“Reducing Code Footprint in Embedded Systems” chapter.
Note:
It is easier to reduce the HAL BSP footprint by using BSP settings, than to use the free-standing
mode.
The Nios II EDS provides examples of both free-standing and hosted programs.
Related Information
Reducing Code Footprint in Embedded Systems on page 6-27
6-34
Eliminate All Exit Code
NII5V2
2015.05.14
Altera Corporation
Developing Programs Using the Hardware Abstraction Layer
Send Feedback