Red Hat axp-list: Linux on Alpha (1995-2022)
 help / color / mirror / Atom feed
From: Jim Paradis <jrp@jrp.tiac.net>
Subject: SIGFPE -- the answer
Date: Wed, 16 Apr 1997 23:05:56 -0400	[thread overview]
Message-ID: <b17acb01e28cf9a4a648e186bd3c7baa.axp-list@archive.invalid> (raw)

[ cc'ed to axp-list for everyone's edification ]
Randy,

I can be soooo dense sometimes.  Remember the divide-by-zero
exception handling problem you were having?  I figured out what
was *really* going on.

Seeing as I wrote the floating-point emulation code for Linux/Alpha
(or, more accurately, I wrote the code for another project which I
then gave to David M-T to hammer into the Linux sources), I shoulda
known this.

Anyhow: there is a way to turn off those nasty SIGFPE's and get the
results you want.  It's a "secret" system call (osf_setsysinfo) 
which can be used to set the floating-point exception enable bits 
in the process struct.

Here's da goods:  To read and write the floating-point exception 
enable bits, you can use the following routines:

	#include <asm/fpu.h>

	#define __NR_getsysinfo 256
	#define __NR_setsysinfo 257

	unsigned long read_fpe_bits()
	{
	    unsigned long fpcw;
	    syscall(__NR_getsysinfo, 45, &fpcw, sizeof(fpcw), 0, 0);
	    return(fpcw & IEEE_TRAP_ENABLE_MASK);
	}

	void write_fpe_bits(unsigned long fpcw)
	{
	    syscall(__NR_setsysinfo, 14, &fpcw, sizeof(fpcw), 0, 0);
	}

The bits themselves are defined in /usr/include/asm/fpu.h.
Look for "IEEE_TRAP_ENABLE_xxx".  Apparently INV (invalid operand),
DZE (divide-by-zero) and OVF (overflow) are turned ON by default
for all processes, and you have to turn them off manually.

Hope this helps!

-- 
Jim Paradis   jrp@jrp.tiac.net  
http://www.tiac.net/users/jrp/index.html
"It's not procrastination, it's my new Just-In-Time Workload Management
System!"

--
To unsubscribe: send e-mail to axp-list-request@redhat.com with
'unsubscribe' as the subject.  Do not send it to axp-list@redhat.com

             reply	other threads:[~1997-04-17  3:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-04-17  3:05 Jim Paradis [this message]
  -- strict thread matches above, loose matches on Subject: below --
1997-04-17 10:45 SIGFPE -- the answer Uncle George
     [not found] <33559394.1AD81EDB@jrp.tiac.net>
1997-04-17 19:51 ` Richard Henderson
1997-04-18  2:02 Jim Paradis
1997-04-18  4:39 Randy Chapman
     [not found] <3356D61F.78ED3FC1@jrp.tiac.net>
1997-04-21 18:32 ` Richard Henderson
1997-04-22  0:51 David Mosberger-Tang
1997-04-22 14:49 Randy Chapman
read-only archive

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox