HP 3000 Manuals

Handling Arithmetic Traps [ Trap Handling Programmer's Guide ] MPE/iX 5.0 Documentation


Trap Handling Programmer's Guide

Handling Arithmetic Traps 

When you invoke a user-written trap handling procedure, it is passed a
pointer to a record that contains some useful information.  This record
has different fields depending upon the trap condition.  The following
fields are supplied for all trap conditions:

instruction               32-bit integer 

                          The offending instruction.

offset                    32-bit integer 

                          Offset of the offending instruction.

space_id                  32-bit integer 

                          Space ID of the offending instruction.

error_code                32-bit integer 

                          Trap type.  The error-code is formed by setting
                          the bit corresponding to the trap condition in
                          a 32-bit integer.  These bits are described in
                          the discussion of the mask parameter of the
                          XARITRAP intrinsic.


NOTE If two exceptions occur simultaneously, the error-code is the inclusive-OR of the error-code for each exception. The only exceptions that coincide are IEEE inexact with IEEE overflow, and IEEE inexact with IEEE underflow.
The following paragraphs describe the contents of this record structure for the various arithmetic trap conditions. Assertion Trap The record structure for a trap condition resulting from an assertion trap is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. Currently, this trap is used only by COBOL II/XL for on-size error conditions for COBOL exponentiation. 3000 Mode Packed Decimal Error The record structure for the trap condition resulting from a 3000 mode packed decimal error is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | 20 |--------------------------------| | operation | 24 |--------------------------------| | operand1_ptr | 28 |--------------------------------| | operand1_leng | 32 |--------------------------------| | operand2_ptr | 36 |--------------------------------| | operand2_leng | 40 |--------------------------------| | cc_ptr | 44 |--------------------------------| | status_ptr | 48 |--------------------------------| | carry_ptr | 52 |--------------------------------| | sign_control | 56 |--------------------------------| | shift_amount | 60 |--------------------------------| | shift_amt_ptr | |--------------------------------|
NOTE A knowledge of the packed decimal routines is assumed. For more information regarding them, refer to Chapter 4 of Compiler Library/XL Reference Manual (32650-90029).
The following discussion explains the information supplied in the additional record fields associated with the 3000 Mode Packed Decimal Error traps: subcode 32-bit integer Indicates what type of packed decimal error has occurred. A summary of the possible values for this field and their associated types follows: Value Type of Packed Decimal Error --------------------------------------------------------------------------------------- 1 Decimal Overflow 2 Invalid ASCII Digit 3 Invalid Packed Decimal Digit 4 Invalid Source Word Count 5 Invalid Decimal Operand Length 6 Decimal Divide By Zero operation 32-bit integer Indicates what procedure was being executed. A summary of the possible values for this field and their associated procedures follows: Value Procedure --------------------------------------------------------------------------------------- 1 HPPACCVAD 2 HPPACCVDA 3 HPPACCVBD 4 HPPACCVDB 5 HPPACADDD 6 HPPACSUBD 7 HPPACCMPD 8 HPPACSLD 9 HPPACNSLD 10 HPPACSRD 11 HPPACMPYD 12 HPPACLONGDIVD 13 HPPACDIVD operand1_ptr 32-bit address Points to the first digit of OPERAND1 or the source. operand1_leng 32-bit integer Gives the length of OPERAND1; zero if not applicable. operand2_ptr 32-bit address Points to the first digit of OPERAND2 or the target. operand2_leng 32-bit integer Gives the length of OPERAND2; zero if not applicable. cc_ptr 32-bit address Points to a user variable that is to receive the comparison code. status_ptr 32-bit address Points to a user variable that is to receive the status indicator. carry_ptr 32-bit address Points to a user variable that is to receive the carry indicator; NIL if not applicable. sign_control 32-bit integer Gives the value of the parameter specifying the treatment of the signed source fields; zero if not applicable. shift_amount 32-bit integer Gives the value of the parameter specifying the number of digits to be shifted; zero if not applicable. shift_amt_ptr 32-bit address Points to a user variable that contains the number of digits to be shifted; NIL if not applicable. With this information, you can correct invalid digits and/or assign desired values to the result fields and then allow execution to resume. Paragraph Stack Overflow The record structure for a trap condition resulting from a paragraph stack overflow is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. Unimplemented Conditional Trap The record structure for a trap condition resulting from a non-recognized trap is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. Pointer Arithmetic Errors The record structure for a trap condition resulting from a pointer arithmetic error is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. Nil Pointer Reference The record structure for a trap condition resulting from a nil pointer reference is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. Range Errors The record structure for a trap condition resulting from a range error is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | |--------------------------------| Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. IEEE Floating Point Traps The IEEE floating-point traps include the following conditions: * IEEE Floating Point Divide By Zero * IEEE Floating Point, Inexact Result * IEEE Floating Point Underflow * IEEE Floating Point Overflow * IEEE Floating Point, Invalid Operation The record structure for an IEEE floating-point trap condition is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | status | 20 |--------------------------------| | operation | 24 |--------------------------------| | format | 28 |--------------------------------| | src_op1_ptr | 32 |--------------------------------| | src_op2_ptr | 36 |--------------------------------| | result_ptr | |--------------------------------| The following list explains the information supplied in the additional record fields associated with IEEE traps: status 32-bit integer Value of the status register of the IEEE coprocessor. You can assign a new value to this field if you want to change the contents of the status register. The most common use of this field is to change the rounding mode. operation 32-bit integer Indicates which floating-point operation caused the trap. The values of this field are associated with IEEE floating-point operations as follows: Hex Value Operation 18 ADD 19 SUB 1A MPY 1B DIV 1C REM 04 SQRT 03 ABS 05 RND 08 CNVFF 0A CNVFX 09 CNVXF 10 CMP
NOTE The value of the operation record field is formed by extracting the OP and CLASS fields from the instruction that caused the trap. The instruction appears as follows: 0 26 27 28 29 31 |---------------------------|------|------| | all zeros |Class | OP | |---------------------------|------|------|
format 32-bit integer Indicates whether the operation that caused the trap had 32-bit, 64-bit, or 128-bit operands. If the operation is not a CONVERT, then the following are the values of the format field: Value Format 0 32-bit 1 64-bit 3 128-bit If the operation is a CONVERT, then these are the values of the format field: Value Format 1 The source is 64-bit; the result is 32-bit. 3 The source is 128-bit; the result is 32-bit. 4 The source is 32-bit; the result is 64-bit. 7 The source is 128-bit; the result is 64-bit. 12 The source is 32-bit; the result is 128-bit. 13 The source is 64-bit; the result is 128-bit. src_op1_ptr 32-bit address Address of the first operand. This operand can be a 32-bit, 64-bit, or 128-bit floating-point number depending upon the operation and format. The address is properly aligned, with 32-bit items on a word boundary, and 64-bit and larger items on a double-word boundary. src_op2_ptr 32-bit address Address of the second operand. This operand can be a 32-bit, 64-bit, or 128-bit floating-point number depending upon the operation and format. For operations that require only one operand, this field must be ignored. result_ptr 32-bit address Points to the result of the operation that resulted in the exception condition. This address can point to a 32-bit, 64-bit, or 128-bit result depending upon the operation and format. You can examine the result and replace it with the desired value.
NOTE 128-bit floating-point numbers are not yet implemented.
Decimal Divide by Zero The record structure for a trap condition resulting from a decimal divide by zero is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | result_addr | 20 |--------------------------------| | digit_count | |--------------------------------| The following list explains the information supplied in the additional record fields associated with the Decimal Divide by Zero trap: result_addr 32-bit address Address of the result. digit_count 32-bit integer Number of digits in the result. With this information, you can assign the desired value to the result, and allow execution to resume with the operation following the division. Invalid Decimal Digit The record structure for a trap condition resulting from an invalid decimal digit is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | 20 |--------------------------------| | source_addr | 24 |--------------------------------| | digit_count | |--------------------------------| The following list explains the information supplied in the additional record fields associated with the Invalid Decimal Digit trap: subcode 32-bit integer Indicates what type of invalid digit has occurred. The following list summarizes the possible values for this field and their associated meanings: Value Meaning 0 There is an illegal digit and/or sign. 1 The number is not signed. 2 The input number on an unsigned-to-unsigned operation is signed. 3 The input number on an unsigned-to-signed operation is signed. source_addr 32-bit address Address of the first digit. digit-count 32-bit integer Number of decimal digits, including the sign bit. With this information, you can correct the invalid digits, and then allow execution to proceed. Validation of the data occurs before the actual operation begins. This allows you to correct invalid data and continue from the beginning of the actual operation. For complete information on decimal format, refer to Data Types Conversion Programmer's Guide (32650-90015). Invalid ASCII Digit The record structure for a trap condition resulting from an invalid ASCII digit is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | 20 |--------------------------------| | source_addr | 24 |--------------------------------| | digit_count | |--------------------------------| The following list explains the information supplied in the additional record fields associated with the Invalid ASCII Digit trap: subcode 32-bit integer Indicates what type of invalid digit has occurred. The following list summarizes the possible values for this field and their associated meanings: Value Meaning 0 There is an illegal digit and/or sign. 1 The number is not signed. 2 The input number on an unsigned-to-unsigned operation is signed. 3 The input number on an unsigned-to-signed operation is signed. source_addr 32-bit address Address of the first digit. digit_count 32-bit integer Number of bytes. With this information, you can correct the invalid digits, and then allow execution to proceed. Validation of the data occurs before the actual operation begins. This lets you correct invalid data and continue from the beginning of the actual operation. Decimal Overflow The record structure for a trap condition resulting from a decimal overflow is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | |--------------------------------| The following list explains the information supplied in the subcode field: subcode 32-bit integer Indicates what type of decimal overflow has occurred. The following list summarizes the possible values for this field and their associated overflow types: Value Type of Overflow 1 Decimal arithmetic operation resulted in overflow 2 Conversion from integer to ASCII resulted in overflow Corrective action for this trap condition is not supported. You can allow execution to resume, but the result will be unpredictable. 3000 Mode Traps The 3000 Mode traps include the following conditions: * 3000 Mode Double Precision Divide By Zero * 3000 Mode Double Precision Overflow * 3000 Mode Double Precision Underflow * 3000 Mode Floating Point Divide By Zero * 3000 Mode Floating Point Overflow * 3000 Mode Floating Point Underflow The record structure for a 3000 Mode trap condition is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | result_ptr | |--------------------------------| The following explains the information supplied in the result_ptr record field associated with the 3000 Mode trap: result_ptr 32-bit address Points to the result of the floating-point operation. You can examine the result and replace it with the desired value. The address points to a 64-bit value or a 32-bit value depending upon the type of trap (double-precision or floating-point). Integer Overflow The record structure for a trap condition resulting from an integer overflow is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | 20 |--------------------------------| | result_ptr | |--------------------------------| The following list explains the information supplied in the subcode field: subcode 32-bit integer Indicates what type of integer overflow has occurred. The following list summarizes the possible values for this field and their associated overflow types: Value Type of Overflow 1 32-bit overflow 2 16-bit overflow 4 Overflow on conversion from a 3000 mode floating-point number 5 Overflow on conversion from an IEEE floating-point number result_ptr 32-bit address Address of the result. You can modify the result of this overflowing operation to any value you choose. Integer Divide by Zero The record structure for a trap condition resulting from an integer divide by zero is as follows: 0 |--------------------------------| | instruction | 4 |--------------------------------| | offset | 8 |--------------------------------| | space_id | 12 |--------------------------------| | error_code | 16 |--------------------------------| | subcode | 20 |--------------------------------| | result_ptr | |--------------------------------| The following list explains the information supplied in the additional record fields associated with the Integer Divide by Zero trap: subcode 32-bit integer Indicates what type of integer is involved. The following list summarizes the possible values for this field and their associated meanings: Value Meaning 1 32-bit integer 2 16-bit integer result_ptr 32-bit address Address of the result. You can modify the result of the operation to any value you choose.
NOTE If the trap is ignored, or if you continue execution from the trap handler without explicitly modifying the result, then the result of the illegal division is zeroed.

CAUTION A user-defined trap handling procedure cannot perform a goto out of that procedure. The state of the process and the program results are not predictable after a non-local goto. Performing an ESCAPE (HP Pascal/XL) or completing the trap handling procedure are the only valid ways to return.

NOTE An NM arithmetic trap handling routine differs from a CM arithmetic trap handler in its calling sequence [refer to the Introduction to MPE XL for MPE V Programmers (30367-90005)] and the method by which the trap routine obtains error information. However, you need supply only the version for the mode in which you invoke intrinsics. You do not need to modify existing CM applications that use an arithmetic trap handler in order to run them on MPE XL. Likewise, new NM applications need not specify a CM version of their NM trap handling routine. Only those doing mixed-mode programming, who invoke intrinsics in both modes, need to specify and arm trap handling routines in both modes in order to capture all possible arithmetic traps.


MPE/iX 5.0 Documentation