This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Integer division by zero



Hello,

In register "c1, System Control Register" bit 19

[19] DZ Divide by zero:

0 = do not generate an Undefined instruction exception
1 = generate an Undefined instruction exception.
The reset value of this bit is 0.

I would like to change this value to 1, so an undefined instruction exception is generated. The question is:

How can I know if the reason of the undefined instruction exception is a division by zero or any other cause?

In the "ARM Architecture Reference Manual" I can read

"The only mechanism to determine the cause of an Undefined Instruction exception is analysis of the instruction indicated by the return link in the LR on exception entry. Therefore it is important that a coprocessor only reports exceptional conditions by generating Undefined Instruction exceptions on its own coprocessor instructions."

So, I guess that the only way of knowing if the undefined instruction exception was caused by a division by zero is to check if LR points to a either UDIV or SDIV instructions and divisor is 0.

Is there an easier way to know if the undefined instruction exception was caused by a division by zero?

Thanks for helping.

Francis.

  • Hello Francis,

    Do not have an answer ready on this, I need to check and get back to you on this to see if there is a better way out.
  • Hi Francis,

    The following is copied from the ARMv7-R Architecture Manual:

    Note
    The only mechanism to determine the cause of an Undefined Instruction exception is analysis of the instruction indicated by the return link in the LR on exception entry.

    Best Regards,
    Christian
  • Hello Christian,

    Yes, I saw this comment. As this can be quite complicated I was just asking if by any change there is any other  way, I will assume no.

    Thanks for helping.

    Francis.

  • Hi Francis,

    Sorry, I missed that you copied exactly the same from ARM.

    Please keep in mind, that an Undefined Instruction Exception is usually indicating a very severe issue.
    What I want to say with this is, what's the value of knowing the instruction which caused the Exception, except for debugging purpose?

    If you like to do so you should take a look into:

    The Example (47) code to determine the address of the instruction caused the SVC should be similar to the one needed for UNDEF as:

    Best Regards,
    Christian

  • Hello Christian,

    "What's the value of knowing the instruction which caused the Exception, except for debugging purpose?"

    We want to enable in register "c1, System Control Register" bit [19] DZ Divide by zero:
    0 = do not generate an Undefined instruction exception
    1 = generate an Undefined instruction exception.
    The reset value of this bit is 0.

    So, when I set this bit to 1, a division by zero (I mean integer division, float division are handled by the FPU and we already have that covered), so division by zero will generate an undefined exception. We would like to signal that to the user but without stopping the execution. As you pointed an undefined exception is very serious and at the moment we go to safe state.

    So, by enabling this, we would like to inform the user that something is wrong in his/her code but continue with the execution.

    Regards,
    Francis.