diff options
author | phk <phk@FreeBSD.org> | 1995-12-14 08:21:33 +0000 |
---|---|---|
committer | phk <phk@FreeBSD.org> | 1995-12-14 08:21:33 +0000 |
commit | f39b6a05acd582271603783421cd37553f43150d (patch) | |
tree | 21b884168d85c11441ad2fad31edd222766c450e | |
parent | 4c65cdeaf90bb3e5dc095270b746b620a7336594 (diff) | |
download | FreeBSD-src-f39b6a05acd582271603783421cd37553f43150d.zip FreeBSD-src-f39b6a05acd582271603783421cd37553f43150d.tar.gz |
Make math_emulators LKMable.
-rw-r--r-- | sys/amd64/amd64/trap.c | 16 | ||||
-rw-r--r-- | sys/amd64/include/frame.h | 4 | ||||
-rw-r--r-- | sys/gnu/i386/fpemul/fpu_entry.c | 64 | ||||
-rw-r--r-- | sys/i386/i386/math_emulate.c | 54 | ||||
-rw-r--r-- | sys/i386/i386/trap.c | 16 | ||||
-rw-r--r-- | sys/i386/include/frame.h | 4 | ||||
-rw-r--r-- | sys/kern/subr_trap.c | 16 |
7 files changed, 140 insertions, 34 deletions
diff --git a/sys/amd64/amd64/trap.c b/sys/amd64/amd64/trap.c index 28c78d2..29de5a6 100644 --- a/sys/amd64/amd64/trap.c +++ b/sys/amd64/amd64/trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.63 1995/12/07 12:45:39 davidg Exp $ + * $Id: trap.c,v 1.64 1995/12/09 20:40:43 phk Exp $ */ /* @@ -82,6 +82,8 @@ #include "isa.h" #include "npx.h" +int (*pmath_emulate) __P((struct trapframe *)); + extern void trap __P((struct trapframe frame)); extern int trapwrite __P((unsigned addr)); extern void syscall __P((struct trapframe frame)); @@ -286,8 +288,12 @@ trap(frame) return; #endif /* NNPX > 0 */ -#if defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE) - i = math_emulate(&frame); + if (!pmath_emulate) { + i = SIGFPE; + ucode = FPE_FPU_NP_TRAP; + break; + } + i = (*pmath_emulate)(&frame); if (i == 0) { if (!(frame.tf_eflags & PSL_T)) return; @@ -295,10 +301,6 @@ trap(frame) i = SIGTRAP; } /* else ucode = emulator_only_knows() XXX */ -#else /* MATH_EMULATE || GPL_MATH_EMULATE */ - i = SIGFPE; - ucode = FPE_FPU_NP_TRAP; -#endif /* MATH_EMULATE || GPL_MATH_EMULATE */ break; case T_FPOPFLT: /* FPU operand fetch fault */ diff --git a/sys/amd64/include/frame.h b/sys/amd64/include/frame.h index 9bee6ed..291a0a1d 100644 --- a/sys/amd64/include/frame.h +++ b/sys/amd64/include/frame.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 - * $Id: frame.h,v 1.9 1994/05/25 08:56:02 rgrimes Exp $ + * $Id: frame.h,v 1.10 1995/03/16 18:11:42 bde Exp $ */ #ifndef _MACHINE_FRAME_H_ @@ -137,6 +137,6 @@ struct sigframe { }; int kdb_trap __P((int, int, struct trapframe *)); -int math_emulate __P((struct trapframe * info)); +extern int (*pmath_emulate) __P((struct trapframe *)); #endif /* _MACHINE_FRAME_H_ */ diff --git a/sys/gnu/i386/fpemul/fpu_entry.c b/sys/gnu/i386/fpemul/fpu_entry.c index edbe94d..d00a6de 100644 --- a/sys/gnu/i386/fpemul/fpu_entry.c +++ b/sys/gnu/i386/fpemul/fpu_entry.c @@ -55,7 +55,7 @@ * * W. Metzenthen June 1994. * - * $Id: fpu_entry.c,v 1.5 1994/08/30 20:18:52 davidg Exp $ + * $Id: fpu_entry.c,v 1.6 1995/05/30 07:57:45 rgrimes Exp $ * */ @@ -71,11 +71,17 @@ +---------------------------------------------------------------------------*/ -#include "param.h" -#include "systm.h" -#include "proc.h" -#include "machine/cpu.h" -#include "machine/pcb.h" +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/kernel.h> + +#ifdef LKM +#include <sys/lkm.h> +#endif + +#include <machine/cpu.h> +#include <machine/pcb.h> #include "fpu_emu.h" #include "fpu_system.h" @@ -192,7 +198,7 @@ char emulating = 0; #define math_abort(signo) \ FPU_EIP = FPU_ORIG_EIP;REENTRANT_CHECK(OFF);return(signo); -int +static int math_emulate(struct trapframe * tframe) { @@ -481,3 +487,47 @@ if (--lookahead_limit) REENTRANT_CHECK(OFF); return (0); /* --pink-- */ } + +#ifdef LKM +MOD_MISC(gnufpu); +static int +gnufpu_load(struct lkm_table *lkmtp, int cmd) +{ + if (pmath_emulate) { + printf("Math emulator already present\n"); + return EBUSY; + } + pmath_emulate = math_emulate; + return 0; +} + +static int +gnufpu_unload(struct lkm_table *lkmtp, int cmd) +{ + if (pmath_emulate != math_emulate) { + printf("Cannot unload another math emulator\n"); + return EACCES; + } + pmath_emulate = 0; + return 0; +} + +int +gnufpu(struct lkm_table *lkmtp, int cmd, int ver) +{ + DISPATCH(lkmtp, cmd, ver, gnufpu_load, gnufpu_unload, lkm_nullcmd); +} +#else /* !LKM */ + +static void +gnufpu_init(void) +{ + if (pmath_emulate) + printf("Another Math emulator already present\n"); + else + pmath_emulate = math_emulate; +} + +SYSINIT(gnufpu, SI_SUB_CPU, SI_ORDER_ANY, gnufpu_init, NULL); + +#endif /* LKM */ diff --git a/sys/i386/i386/math_emulate.c b/sys/i386/i386/math_emulate.c index 8051bb8..b182aaf 100644 --- a/sys/i386/i386/math_emulate.c +++ b/sys/i386/i386/math_emulate.c @@ -6,7 +6,7 @@ * [expediant "port" of linux 8087 emulator to 386BSD, with apologies -wfj] * * from: 386BSD 0.1 - * $Id: math_emulate.c,v 1.14 1995/10/29 15:29:56 phk Exp $ + * $Id: math_emulate.c,v 1.15 1995/12/07 12:45:33 davidg Exp $ */ /* @@ -38,6 +38,12 @@ #include <sys/param.h> #include <sys/systm.h> +#ifdef LKM +#include <sys/types.h> +#include <sys/kernel.h> +#include <sys/lkm.h> +#endif + #include <machine/cpu.h> #include <machine/psl.h> #include <machine/reg.h> @@ -95,7 +101,7 @@ static void put_fs_long(u_long val, unsigned long *adr) { (void)suword(adr,val); } -int +static int math_emulate(struct trapframe * info) { unsigned short code; @@ -1543,3 +1549,47 @@ int_to_real(const temp_int * a, temp_real * b) :"0" (b->a),"1" (b->b)); } } + +#ifdef LKM +MOD_MISC(fpu); +static int +fpu_load(struct lkm_table *lkmtp, int cmd) +{ + if (pmath_emulate) { + printf("Math emulator already present\n"); + return EBUSY; + } + pmath_emulate = math_emulate; + return 0; +} + +static int +fpu_unload(struct lkm_table *lkmtp, int cmd) +{ + if (pmath_emulate != math_emulate) { + printf("Cannot unload another math emulator\n"); + return EACCES; + } + pmath_emulate = 0; + return 0; +} + +int +fpu(struct lkm_table *lkmtp, int cmd, int ver) +{ + DISPATCH(lkmtp, cmd, ver, fpu_load, fpu_unload, lkm_nullcmd); +} +#else /* !LKM */ + +static void +fpu_init(void) +{ + if (pmath_emulate) + printf("Another Math emulator already present\n"); + else + pmath_emulate = math_emulate; +} + +SYSINIT(fpu, SI_SUB_CPU, SI_ORDER_ANY, fpu_init, NULL); + +#endif /* LKM */ diff --git a/sys/i386/i386/trap.c b/sys/i386/i386/trap.c index 28c78d2..29de5a6 100644 --- a/sys/i386/i386/trap.c +++ b/sys/i386/i386/trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.63 1995/12/07 12:45:39 davidg Exp $ + * $Id: trap.c,v 1.64 1995/12/09 20:40:43 phk Exp $ */ /* @@ -82,6 +82,8 @@ #include "isa.h" #include "npx.h" +int (*pmath_emulate) __P((struct trapframe *)); + extern void trap __P((struct trapframe frame)); extern int trapwrite __P((unsigned addr)); extern void syscall __P((struct trapframe frame)); @@ -286,8 +288,12 @@ trap(frame) return; #endif /* NNPX > 0 */ -#if defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE) - i = math_emulate(&frame); + if (!pmath_emulate) { + i = SIGFPE; + ucode = FPE_FPU_NP_TRAP; + break; + } + i = (*pmath_emulate)(&frame); if (i == 0) { if (!(frame.tf_eflags & PSL_T)) return; @@ -295,10 +301,6 @@ trap(frame) i = SIGTRAP; } /* else ucode = emulator_only_knows() XXX */ -#else /* MATH_EMULATE || GPL_MATH_EMULATE */ - i = SIGFPE; - ucode = FPE_FPU_NP_TRAP; -#endif /* MATH_EMULATE || GPL_MATH_EMULATE */ break; case T_FPOPFLT: /* FPU operand fetch fault */ diff --git a/sys/i386/include/frame.h b/sys/i386/include/frame.h index 9bee6ed..291a0a1d 100644 --- a/sys/i386/include/frame.h +++ b/sys/i386/include/frame.h @@ -34,7 +34,7 @@ * SUCH DAMAGE. * * from: @(#)frame.h 5.2 (Berkeley) 1/18/91 - * $Id: frame.h,v 1.9 1994/05/25 08:56:02 rgrimes Exp $ + * $Id: frame.h,v 1.10 1995/03/16 18:11:42 bde Exp $ */ #ifndef _MACHINE_FRAME_H_ @@ -137,6 +137,6 @@ struct sigframe { }; int kdb_trap __P((int, int, struct trapframe *)); -int math_emulate __P((struct trapframe * info)); +extern int (*pmath_emulate) __P((struct trapframe *)); #endif /* _MACHINE_FRAME_H_ */ diff --git a/sys/kern/subr_trap.c b/sys/kern/subr_trap.c index 28c78d2..29de5a6 100644 --- a/sys/kern/subr_trap.c +++ b/sys/kern/subr_trap.c @@ -35,7 +35,7 @@ * SUCH DAMAGE. * * from: @(#)trap.c 7.4 (Berkeley) 5/13/91 - * $Id: trap.c,v 1.63 1995/12/07 12:45:39 davidg Exp $ + * $Id: trap.c,v 1.64 1995/12/09 20:40:43 phk Exp $ */ /* @@ -82,6 +82,8 @@ #include "isa.h" #include "npx.h" +int (*pmath_emulate) __P((struct trapframe *)); + extern void trap __P((struct trapframe frame)); extern int trapwrite __P((unsigned addr)); extern void syscall __P((struct trapframe frame)); @@ -286,8 +288,12 @@ trap(frame) return; #endif /* NNPX > 0 */ -#if defined(MATH_EMULATE) || defined(GPL_MATH_EMULATE) - i = math_emulate(&frame); + if (!pmath_emulate) { + i = SIGFPE; + ucode = FPE_FPU_NP_TRAP; + break; + } + i = (*pmath_emulate)(&frame); if (i == 0) { if (!(frame.tf_eflags & PSL_T)) return; @@ -295,10 +301,6 @@ trap(frame) i = SIGTRAP; } /* else ucode = emulator_only_knows() XXX */ -#else /* MATH_EMULATE || GPL_MATH_EMULATE */ - i = SIGFPE; - ucode = FPE_FPU_NP_TRAP; -#endif /* MATH_EMULATE || GPL_MATH_EMULATE */ break; case T_FPOPFLT: /* FPU operand fetch fault */ |