sasrer@mozart.unx.sas.com (Rodney Radford) (08/18/90)
I need info on writing a user floating point exception handler that is able to do the following: 1) Catch the SIGFPE exception 2) Decode the exception into one of the following types a) Floating point overflow b) Floating point underflow c) Floating point divide by zero d) Floating point to inter conversion overflow e) Operations on reserved operands (NANs, infinity, denormalized) f) Any others... 3) And then, either: a) longjmp() to a previosly setjmp() address b) bring down the application - exit() c) jump to a specific instruction address d) return to the instruction following the faulting instruction Some of the problems I am having are: 1) How do I decode the specific type of SIGFPE exception that occurred? I am currently using the si_fpsr field in the struct siginfo structure. This works, but the MC88100 guide states that this register is set by software from the FPECR. The FPSR seems to show accumulated information, not necessarily what happed on the current exception. 2) How do I reset the bit in the FPCR if I do a longjmp to another address? If I just return, then the siginfo information is copied to the real processor registers (with the sigret), but how is this done otherwise? I've currently written two small assembly routines that allow me to get/set the fpsr - but do not seem to be working. 3) The assembler (as) under DG/UX 4.30 complains with the instruction "fstcr r2,fcr62" giving the error message: "as: "setfpsr.s": line 17: operand 'fcr62' type mismatch for 'fstcr'". What is wrong with this instruction? If I change the 'fcr62' to 'cr62', it assembles OK, but this seems contrary to the assembler documenation in the 88open OCS. 4) When I try to return to a specific instruction address, I currently use the following algorithm: set the SNIP to the address, with bit 1 on (V) and 0 off (E) set the SFIP to SNIP+4 return from user-handler What should I do if the exception occurred in a delay slot, ie: bcnd.n eq0,R2,label fdiv.sss R8,R2,R3 Do I have to look at the instruction last executed (whatever that was - could have gotten here by a branch), and then emulate it to find out where to set the SFIP? Or if I continue to set the SFIP to SNIP+4, will the branch be executed correctly? 5) Do I have to use siglongjmp() to jump out of a handler? If so, do I have to use sigsetjmp() to create the original buffer? In my application, I do not know at setjmp() time whether I will get here from within an exception or not. If anyone has any experience with 88K SIGFPE exceptions, and can offer any advice, please do so. Thank you. PS: Thanks for all the replies about how to catch fixed point multiply overflows. -- Rodney Radford DG/UX AViiON developer SAS Institute, Inc. sasrer@unx.sas.com (919) 677-8000 x7703 Box 8000, Cary, NC 27512