Nios II Classic Software Developer’s Handbook

ID 683282
Date 5/14/2015
Public
Document Table of Contents

6.14.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 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.