Date: Mon, 31 Aug 1998 12:25:25 +0200 From: Martin Cracauer <cracauer@cons.org> To: Bruce Evans <bde@zeta.org.au>, cracauer@cons.org, current@FreeBSD.ORG Subject: Re: Floating Point Exceptions, signal handlers & subsequent ops Message-ID: <19980831122525.A25527@cons.org> In-Reply-To: <199808310322.NAA24605@godzilla.zeta.org.au>; from Bruce Evans on Mon, Aug 31, 1998 at 01:22:29PM %2B1000 References: <199808310322.NAA24605@godzilla.zeta.org.au>
next in thread | previous in thread | raw e-mail | index | archive | help
In <199808310322.NAA24605@godzilla.zeta.org.au>, Bruce Evans wrote: > >> >If sig == SIGFPE, then expect the trap code to be one of FPE_*_TRAP > >> >values from machine/trap.h, *not* one of the T_* values. > >> > >> Except this is not implemented. > > > >Does the appended diff count as an implementation? Test program > >included. > > Er, no. The exception status word is a bitmap. Code to map it to a > machine_dependent exception code should look something like: ^^ independent? > code = translation_table[ffs(status_word & control_word & 0x3F)]; But the values of the symbols the application tests against ("FP_X_...") are chosen so that no translation is needed. Your translation table would look like this: tab[0x01] = 0x01 tab[0x02] = 0x02 tab[0x04] = 0x04 ... tab[0x20] = 0x20 OK, actually, more like tab[0x01] = FP_X_INV ... which is probably your point, but still the same :-) Is it really canon that we should bloat the kernel with tables like this that are needed only when someone make undesired changes to a machine/ header file? > Perhaps it should do more if the final bitmap doesn't have precisely 1 bit > set in it. It's normal for the status word to have multiple bits set. > Anding with the control word and 0x3F probably reduces the number to > 1 in most cases, but it is possible for applications to create strange > bitmaps using control instructions. It is my intent to delete all bits but the one that caused this particular exception, to tell the application why it entered the exception handler (and nothing else). First, I clear all bits but the 6 exception bit and since bits from masked exceptions can be set besides the one for the unmasked exception that is just processed, I 'and' with the status word. I expect this to leave one bit only. Is it really the case that more than one bit for unmasked exceptions can be set before the FPE is triggered? If the application wants to know about more bits set (from masked exceptions), it has to fetch the status word itself. There is no need for kernel code to support that. > >Index: i386/i386/machdep.c > >=================================================================== > >RCS file: /home/CVS-FreeBSD/src/sys/i386/i386/machdep.c,v > >retrieving revision 1.304 > >diff -c -r1.304 machdep.c > >*** machdep.c 1998/08/18 07:46:58 1.304 > >--- machdep.c 1998/08/30 00:22:59 > >*************** > >*** 136,141 **** > >--- 136,143 ---- > > #include <machine/random.h> > > #include <sys/ptrace.h> > > > >+ #include <machine/floatingpoint.h> > >+ > > This header is application-only. I need it for the __fnstcw macro. What to do instead, insert the asm() directives directly? That would be duplication of code. Move the __fnstcw() macro to a header that is for kernel and applications? > > extern void init386 __P((int first)); > > extern void dblfault_handler __P((void)); > > > >*************** > >*** 502,508 **** > >--- 504,515 ---- > > struct sigframe sf; > > struct sigacts *psp = p->p_sigacts; > > int oonstack; > >+ u_long fpuctrl; > > > >+ if (sig == SIGFPE && code == 0) { > >+ __fnstcw(&fpuctrl); > > The FPU can't be used here if there was a context switch between the > FPU trap and here. So I have to treat it like curpcb->pcb_savefpu.sv_ex_sw, that means I store it into a new field curpcb->pcb_savefpu.sv_ex_cw in npx.c:npxintr() ? > >+ code = 0x3F & ~fpuctrl & curpcb->pcb_savefpu.sv_ex_sw; > >+ } > > This is missing the translation from the machine-dependent bitmap to the > "machine-independent" single-exception code. See above. Martin -- %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536 Paper: (private) Waldstrasse 200, 22846 Norderstedt, Germany To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-current" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19980831122525.A25527>