Results 1 to 7 of 7

Thread: Nios II exception handler

  1. #1
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    1

    Default Nios II exception handler

    Hi,
    I'm using Nios II and experiencing some strange behaviors.
    1. Sometimes the system gets stuck.
    2. The system resets.
    3. In debug mode - the software get stuck after going to a trap.

    The Hardware is Altera's Cyclon3 with Quartus 12 SP2.

    In order to better understand the problem I want to try and catch exception with exception handler.

    I'v enabled hal.enable_instruction_related_exceptions_api in bsp editor, implemented and registered the handler.

    The handler does not work the way I expected it. It is not triggered at all.

    How can I test it? Do I need to add something to the hardware as well?

    Thanks

  2. #2
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    1

    Default Re: Nios II exception handler

    I found out that it is needed to build the hardware with the advanced exception options on.
    In the SOPC builder I checked the following in Advanced features:
    Exception Checking:
    1. Illegal instructions
    2. Missaligned memory access.
    3. Extra exception information.

    After building the new hardware, the handler was triggered when trying to write on missaligned address or trying to execute function from address 0x0.
    Now I want to try and test trap handling. How can I trigger a trap instruction to be handled with the handler I implemented?

  3. #3
    Join Date
    Nov 2009
    Location
    uk
    Posts
    1,736
    Rep Power
    1

    Default Re: Nios II exception handler

    int x[2];

    later: *(int)((char *)x + 1) = 1;

  4. #4
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    1

    Default Re: Nios II exception handler

    This code raised only the miss-alignment exception. Not the trap instruction exception.

    How can I cause this exception?

  5. #5
    Join Date
    Nov 2009
    Location
    uk
    Posts
    1,736
    Rep Power
    1

    Default Re: Nios II exception handler

    asm volatile("trap")

  6. #6
    Join Date
    Oct 2012
    Posts
    14
    Rep Power
    1

    Default Re: Nios II exception handler

    Thanks. It worked.
    Do you know of a way to protect from array overflow? Like the following:
    int x[2];
    x[3] = 1; //I want to protect against this kind of instructions.
    I'd like to have an exception generated in this case.

  7. #7
    Join Date
    Nov 2009
    Location
    uk
    Posts
    1,736
    Rep Power
    1

    Default Re: Nios II exception handler

    You won't find an easy solution to that one. Some options:
    1) Add software to verify that x[3] doesn't change.
    2) Use a mmu and make x[2] be the end of a memory page, and make sure the following page is never allocated.
    3) Use on-chip debugger facilities to trap on writes to specific locations (only a few traps will ever be supported, not sure the nios has any).
    4) Use signaltap to detect writes to x[3].
    5) Wrap all the array accesses in functions and verifu=y the index.
    6) Write the code carefully!

Similar Threads

  1. NIOS II - Exception vector
    By sim in forum General Altera Discussion
    Replies: 0
    Last Post: April 2nd, 2012, 09:53 AM
  2. Dual NIOS exception overwrite
    By NateH in forum General Discussion Forum
    Replies: 3
    Last Post: May 28th, 2011, 05:23 PM
  3. Exception Handler for misaligned data memory access
    By AdeColes in forum General Software Forum
    Replies: 5
    Last Post: February 16th, 2011, 07:06 AM
  4. Nios II Exception Vector
    By nicolas in forum Nios Forum
    Replies: 0
    Last Post: January 17th, 2011, 01:15 PM
  5. Nios-II Exception Address
    By smcnutt in forum Linux Forum
    Replies: 2
    Last Post: December 10th, 2004, 06:09 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •