Specifications
1. Enable the Run Time Stack Checking in the BSP project from NIOS II SBT for Eclipce Nios II BSP
Editor. From the BSP project, right-click and navigate to Nios II > BSP editor Settings > Advanced >
hal > enable_run_time_stack_checking.
2. Rebuild BSP and software.
3. Ensure that the FPGA is configured.
4. Start the Debug Session by navigating to Debug As > Nios II Hardware.
5. Run the Software.
Nios II Exception Debugging
To allow easier debugging of Nios II exceptions, first enable the extra exception information in the Nios
II.
Note:
This is already enabled if you have an MMU.
Also you can navigate to Nios II MegaWizard > Advanced Features Exception Checking > Extra
Information Register.
Note:
There are other options you can choose, like unimplemented instructions.
When an exception is hit, the cause value in the Nios II Exception Register can be decoded using the
Nios II Exceptions (In Decreasing Priority Order) table from the Nios II Classic Processor Reference
Handbook.
Note:
This table only provides the general cause.
Related Information
• Nios II Classic Processor Reference Handbook
For more information about the Exception Register Decode Table, refer to the "Exception Overview"
chapter in the "Programming Model" section.
• Nios II Classic Processor Reference Handbook
For more information about the Exception Register Description, refer to the "The exception Register"
chapter in the "Programming Model" section.
Stack Overflow
To enable Stack Checking, go to the BSP Editor and click on the Settings tab, click on Advanced, hal,
and then click enable_runtime_stack_checking. When the Stack Checking is enabled, extra code is
added at the start of each function call to:
• Check the current value of the stack pointer
• Compare this to the max stack size, which is stored in the Exception Temp (ET) Register
If the stack pointed to is outside of the valid range, the software branches and calls a “break 3” instruc‐
tion. This is seen by the Debug Control module.
Note:
With stack checking on, malloc() and new() can detect heap exhaustion, as well.
Example 2-1: Example of function with stack checking code
___vfprintf_internal_r:
000002ec: addi sp,sp,-1308
000002f0: bgeu sp,et,0x2f8 <___vfprintf_internal_r+12>
000002f4: break 3
2-8
Nios II Exception Debugging
NII5V2
2015.05.14
Altera Corporation
Getting Started with the Graphical User Interface
Send Feedback