Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
21 years ago

[Nios II]: questions on "trap" and modelsim

Hi,

I started to use the "Nios II/fast core" and made some timing tests.

but I got some trouble to find out how "trap" work.

in assembly, when user issue a trap:

      ....
      trap
      ....

how is it possible to attach a handler (same as irq?? with alt_irq_register??)

or should I write in a status register a number of irq ??

A question about modelsim: do you know how to see which instruction is executed, and which are in the pipeline at T time??

thanks for your help,

Sylvain

6 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    There is no public API for adding your own trap handler to the HAL. However if you copy the file alt_exceptions.S from the altera_nios2 component into your system library project, you will be able to modify it to include your own trap handler.

    Search for the "trap_handler" symbol in that file, and you will see where to add your own code.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Ok, thanks for the response.

    But, I looked at Exception.S and I dont really see the meaning of this instruction though.

    the main purpose seems to manage software multiplication and division, when the Nios generate itself a trap.

    but, what is the purpose for the user, to issue a trap??

    ( no difference with a system call?!)

    Sylvain
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Sylvian,

    The multiply/divide stuff is executed in our default handler as the result of an "unimplemenrted instruction" exception, something different from a user trap. We do this so that we can maintain binary compatibility between different versions of the Nios II core... so if some code is compiled to call a hardware multiplier that doesn't exist (as one example), the unimplmeneted insrtuction exception gets generated and we handle the multiply in software.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Hi Jesse,

    Yes I saw the part of multiplication/division emulation. But in this case the branch is done automaticaly by the nios (exception interruption not implemented). So in the code, there are nowhere the instruction trap. right?

    If right, I wonder what the point of having a "trap" instruction is. Is is done so that the user can put a "trap" in his own code?. The only meaning I see, is if the user wants to make a function call, that would be executed in supervisor mode (trap changes mode to user mode)??

    Sorry, I got a lot of question, I just started to study the Nios for a few days, but it seems really cool http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif !

    By the Way, I saw you are working at Altera. Is this forum altera-official? anyway, it&#39;s a really good idea:) Thanks you a lot for your responses

    Sylvain,

    ...missing california...
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    <div class='quotetop'>QUOTE </div>

    --- Quote Start ---

    Yes I saw the part of multiplication/division emulation. But in this case the branch is done automaticaly by the nios (exception interruption not implemented). So in the code, there are nowhere the instruction trap. right?[/b]

    --- Quote End ---

    I&#39;m not sure if I follow you; the reason I gave mul as an example is that if your code calls "mul", and the hardware is physically not present, a software exception gets generated and you find you find yourself in the alt_exceptions.S code. The first thing done here is to decode the opcode to determine if its a trap, otherwise its an unimplmented instruction (where you get the mul emulation), or possibly illegal instruction (a feature recently added to aid if the system has corrupt memory and you get a bad opcode).

    About traps: I have a limited understanding of this, but what I do know is that traps do put you into supervisor mode as you mention (this is all covered in the Nios CPU reference manual). This can be useful if you&#39;re running an (RT)OS.

    About this site: This forum is not an Altera support channel nor is it officially run by Altera http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/cool.gif If you need specific help on an Altera product of any sort there are FAEs, distributors, and the Altera mySupport which are designed for this. However, you&#39;ll see that a number of us post replies to various questions here, time permitting... it is encouraging to see a lot of people using the forum because that means people in the community helping answer others&#39; questions.
  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    oky, I think I will follow this principle then, that main purpose of trap, from a user utilisation, is to put processor in supervisor mode.

    I also contacted altera for some documentation I wasn&#39;t able to find, .and they offered me NiosII books, really kind http://forum.niosforum.com/work2/style_emoticons/<#EMO_DIR#>/smile.gif

    Sylvain