Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 14 Nov 1999 10:11:45 +0100
From:      Martin Cracauer <cracauer@cons.org>
To:        Marcel Moolenaar <marcel@FreeBSD.ORG>
Cc:        cvs-committers@FreeBSD.ORG, cvs-all@FreeBSD.ORG
Subject:   Re: cvs commit: src/sys/i386/include signal.h
Message-ID:  <19991114101145.A23853@cons.org>
In-Reply-To: <199911121352.FAA19904@freefall.freebsd.org>; from Marcel Moolenaar on Fri, Nov 12, 1999 at 05:52:12AM -0800
References:  <199911121352.FAA19904@freefall.freebsd.org>

next in thread | previous in thread | raw e-mail | index | archive | help

--DocE+STaALJfprDB
Content-Type: text/plain; charset=us-ascii

In <199911121352.FAA19904@freefall.freebsd.org>, Marcel Moolenaar wrote: 
> marcel      1999/11/12 05:52:11 PST
> 
>   Modified files:
>     sys/i386/include     signal.h 
>   Log:
>   Reserve space for FPU state in struct sigcontext. Fix some style bugs
>   and comments while there.

I still don't like this approach of unstructred allocated space, an
array of unnamed bytes.

The following diffs reorganizes include files so that the structures
describing the FPU are visible from signal.h and the space for FPU
state in sigcontext is now a struct with useful named members.

If you do this, you could write a signal handler like this:

static void
handler_siginfo(const int sig, siginfo_t *const si, void *const third)
{
  sw1 = si->si_sc.sc_savefpu.sv_ex_sw & 0x7F;
  sw2 = si->si_sc.sc_savefpu.sv_env.en_sw & 0x7F;
  reason = si->si_code;
  longjmp(jmpbuf, 1);
}

... instead of accessing one or another bytes in a flat space.

The diff is against pre-64-signals FreeBSD.

It had been discussed and I didn't have the time to polish it, but it
seems we have to decide now over the issue so that we don't go through
multiple rounds of struct sigcontext changes.

Martin
-- 
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Martin Cracauer <cracauer@cons.org> http://www.cons.org/cracauer/
  Tel.: (private) +4940 5221829 Fax.: (private) +4940 5228536

--DocE+STaALJfprDB
Content-Type: text/plain; charset=us-ascii
Content-Disposition: attachment; filename="diff.savefpu-3"

? ~?l
? compile/COUNTER
? compile/NEBULA
? compile/CURRY
? compile/GENERIC
? compile/TEST
? compile/LINT
? i386/conf/TEST
Index: i386/i386/machdep.c
===================================================================
RCS file: /home/CVS-FreeBSD/src/sys/i386/i386/machdep.c,v
retrieving revision 1.357
diff -c -r1.357 machdep.c
*** machdep.c	1999/07/29 01:49:18	1.357
--- machdep.c	1999/08/03 12:47:02
***************
*** 564,569 ****
--- 564,572 ----
  	sf.sf_siginfo.si_sc.sc_fs = regs->tf_fs;
  	sf.sf_siginfo.si_sc.sc_isp = regs->tf_isp;
  
+ 	bcopy(&p->p_addr->u_pcb.pcb_savefpu, &sf.sf_siginfo.si_sc.sc_savefpu,
+ 	    sizeof(struct save87));
+ 
  	/*
  	 * Build the signal context to be used by sigreturn.
  	 */
***************
*** 748,753 ****
--- 751,759 ----
  
  	if (useracc((caddr_t)scp, sizeof (*scp), B_WRITE) == 0)
  		return(EINVAL);
+ 
+ 	bcopy(&scp->sc_savefpu, &p->p_addr->u_pcb.pcb_savefpu,
+ 	    sizeof(struct save87));
  
  	if (scp->sc_onstack & 01)
  		p->p_sigacts->ps_sigstk.ss_flags |= SS_ONSTACK;
Index: i386/include/npx.h
===================================================================
RCS file: /home/CVS-FreeBSD/src/sys/i386/include/npx.h,v
retrieving revision 1.15
diff -c -r1.15 npx.h
*** npx.h	1999/04/28 01:04:03	1.15
--- npx.h	1999/08/03 12:47:03
***************
*** 46,91 ****
  #define	_MACHINE_NPX_H_
  
  #include <machine/globals.h>
! 
! /* Environment information of floating point unit */
! struct	env87 {
! 	long	en_cw;		/* control word (16bits) */
! 	long	en_sw;		/* status word (16bits) */
! 	long	en_tw;		/* tag word (16bits) */
! 	long	en_fip;		/* floating point instruction pointer */
! 	u_short	en_fcs;		/* floating code segment selector */
! 	u_short	en_opcode;	/* opcode last executed (11 bits ) */
! 	long	en_foo;		/* floating operand offset */
! 	long	en_fos;		/* floating operand segment selector */
! };
! 
! /* Contents of each floating point accumulator */
! struct	fpacc87 {
! #ifdef dontdef /* too unportable */
! 	u_long	fp_mantlo;	/* mantissa low (31:0) */
! 	u_long	fp_manthi;	/* mantissa high (63:32) */
! 	int	fp_exp:15;	/* exponent */
! 	int	fp_sgn:1;	/* mantissa sign */
! #else
! 	u_char	fp_bytes[10];
! #endif
! };
! 
! /* Floating point context */
! struct	save87 {
! 	struct	env87 sv_env;	/* floating point control/status */
! 	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
! 	u_long	sv_ex_sw;	/* status word for last exception */
! 	/*
! 	 * Bogus padding for emulators.  Emulators should use their own
! 	 * struct and arrange to store into this struct (ending here)
! 	 * before it is inspected for ptracing or for core dumps.  Some
! 	 * emulators overwrite the whole struct.  We have no good way of
! 	 * knowing how much padding to leave.  Leave just enough for the
! 	 * GPL emulator's i387_union (176 bytes total).
! 	 */
! 	u_char	sv_pad[64];	/* padding; used by emulators */
! };
  
  /* Intel prefers long real (53 bit) precision */
  #define	__iBCS_NPXCW__		0x262
--- 46,52 ----
  #define	_MACHINE_NPX_H_
  
  #include <machine/globals.h>
! #include <machine/signal.h>	/* struct save87 */
  
  /* Intel prefers long real (53 bit) precision */
  #define	__iBCS_NPXCW__		0x262
Index: i386/include/signal.h
===================================================================
RCS file: /home/CVS-FreeBSD/src/sys/i386/include/signal.h,v
retrieving revision 1.8
diff -c -r1.8 signal.h
*** signal.h	1997/08/09 00:03:20	1.8
--- signal.h	1999/08/03 12:47:03
***************
*** 47,52 ****
--- 47,87 ----
  
  #include <machine/trap.h>	/* codes for SIGILL, SIGFPE */
  
+ #define SA_FPUSTATE 1
+ 
+ /* Environment information of floating point unit */
+ struct	env87 {
+ 	long	en_cw;		/* control word (16bits) */
+ 	long	en_sw;		/* status word (16bits) */
+ 	long	en_tw;		/* tag word (16bits) */
+ 	long	en_fip;		/* floating point instruction pointer */
+ 	unsigned short	en_fcs;		/* floating code segment selector */
+ 	unsigned short	en_opcode;	/* opcode last executed (11 bits ) */
+ 	long	en_foo;		/* floating operand offset */
+ 	long	en_fos;		/* floating operand segment selector */
+ };
+ 
+ /* Contents of each floating point accumulator */
+ struct	fpacc87 {
+ 	unsigned char	fp_bytes[10];
+ };
+ 
+ /* Floating point context */
+ struct	save87 {
+ 	struct	env87	sv_env;		/* floating point control/status */
+ 	struct	fpacc87	sv_ac[8];	/* accumulator contents, 0-7 */
+ 	unsigned long	sv_ex_sw;	/* status word for last exception */
+ 	/*
+ 	 * Bogus padding for emulators.  Emulators should use their own
+ 	 * struct and arrange to store into this struct (ending here)
+ 	 * before it is inspected for ptracing or for core dumps.  Some
+ 	 * emulators overwrite the whole struct.  We have no good way of
+ 	 * knowing how much padding to leave.  Leave just enough for the
+ 	 * GPL emulator's i387_union (176 bytes total).
+ 	 */
+ 	unsigned char	sv_pad[64];	/* padding; used by emulators */
+ };
+ 
  /*
   * Information pushed on stack when a signal is delivered.
   * This is used by the kernel to restore state following
***************
*** 78,86 ****
  #  define sc_fp sc_ebp
  #  define sc_pc sc_eip
  #  define sc_ps sc_efl
! #  define sc_eflags	sc_efl
  	int	sc_trapno;
  	int	sc_err;
  };
  
  #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */
--- 113,122 ----
  #  define sc_fp sc_ebp
  #  define sc_pc sc_eip
  #  define sc_ps sc_efl
! #  define sc_eflags sc_efl
  	int	sc_trapno;
  	int	sc_err;
+ 	struct	save87 sc_savefpu;
  };
  
  #endif /* !_ANSI_SOURCE && !_POSIX_SOURCE */

--DocE+STaALJfprDB--


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe cvs-all" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?19991114101145.A23853>