Nios® V Processor Software Developer Handbook

ID 743810
Date 7/20/2023
Public

A newer version of this document is available. Customers should click here to go to the newest version.

Document Table of Contents

6.12.1. 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® V 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® V 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® V 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.