Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/arch/sun3/sun3 Bring FPU probe code from atari/fpu.c and...
details: https://anonhg.NetBSD.org/src/rev/3942b7a7f97e
branches: trunk
changeset: 503238:3942b7a7f97e
user: tsutsui <tsutsui%NetBSD.org@localhost>
date: Sat Feb 03 14:30:42 2001 +0000
description:
Bring FPU probe code from atari/fpu.c and remove unneeded includes.
diffstat:
sys/arch/sun3/sun3/fpu.c | 78 ++++++++++++++++++++++++++++++++----------------
1 files changed, 52 insertions(+), 26 deletions(-)
diffs (128 lines):
diff -r bb56f3567ead -r 3942b7a7f97e sys/arch/sun3/sun3/fpu.c
--- a/sys/arch/sun3/sun3/fpu.c Sat Feb 03 13:25:00 2001 +0000
+++ b/sys/arch/sun3/sun3/fpu.c Sat Feb 03 14:30:42 2001 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: fpu.c,v 1.15 1998/02/05 04:57:34 gwr Exp $ */
+/* $NetBSD: fpu.c,v 1.16 2001/02/03 14:30:42 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@@ -43,16 +43,10 @@
#include <sys/param.h>
#include <sys/systm.h>
-#include <sys/time.h>
-#include <sys/kernel.h>
-#include <sys/device.h>
-#include <machine/psl.h>
#include <machine/cpu.h>
#include <machine/frame.h>
-#include <machine/mon.h>
-#include <sun3/sun3/interreg.h>
#include <sun3/sun3/machdep.h>
static int fpu_probe __P((void));
@@ -63,27 +57,30 @@
#else
"no math support", /* 0 */
#endif
- "mc68881", /* 1 */
- "mc68882", /* 2 */
- "?" };
+ "mc68881", /* 1 */
+ "mc68882", /* 2 */
+ "mc68040 internal", /* 3 */
+ "mc68060 internal", /* 4 */
+ "unknown type" }; /* 5 */
void
initfpu()
{
char *descr;
+ int maxtype = sizeof(fpu_descr) / sizeof(fpu_descr[0]) - 1;
/* Set the FPU bit in the "system enable register" */
enable_fpu(1);
fputype = fpu_probe();
- if ((0 <= fputype) && (fputype <= 2))
- descr = fpu_descr[fputype];
- else
- descr = "unknown type";
+ if (fputype < 0 || fputype > maxtype)
+ fputype = FPU_UNKNOWN;
+
+ descr = fpu_descr[fputype];
printf("fpu: %s\n", descr);
- if (fputype == 0) {
+ if (fputype == FPU_NONE) {
/* Might as well turn the enable bit back off. */
enable_fpu(0);
}
@@ -93,22 +90,51 @@
fpu_probe()
{
label_t faultbuf;
- struct fpframe null_fpf;
+ struct fpframe fpframe;
+ u_char b;
nofault = &faultbuf;
if (setjmp(&faultbuf)) {
nofault = NULL;
- return(0);
+ return FPU_NONE;
}
- bzero(&null_fpf, sizeof(null_fpf));
- /* This will trap if there is no FPU present. */
- m68881_restore(&null_fpf);
+
+ /*
+ * Synchronize FPU or cause a fault.
+ * This should leave the 881/882 in the IDLE state,
+ * so we can determine which we have by
+ * examining the size of the FP state frame.
+ */
+ asm("fnop");
+
nofault = NULL;
- /* XXX - See atari version. */
-#ifdef _SUN3X_
- return(2);
-#else
- return(1);
-#endif
+ /* Presumably, this will not cause a fault--the fnop should
+ * have if this will. We save the state in order to get the
+ * size of the frame.
+ */
+ asm("fsave %0@" : : "a" (&fpframe) : "memory");
+
+ b = fpframe.fpf_fsize;
+
+ /*
+ * Now, restore a NULL state to reset the FPU.
+ */
+ fpframe.fpf_null = 0;
+ fpframe.fpf_idle.fpf_ccr = 0;
+ m68881_restore(&fpframe);
+
+ /*
+ * The size of a 68881 IDLE frame is 0x18
+ * and 68882 frame is 0x38
+ */
+ if (b == 0x18)
+ return FPU_68881;
+ if (b == 0x38)
+ return FPU_68882;
+
+ /*
+ * If it's not one of the above, we have no clue what it is.
+ */
+ return FPU_UNKNOWN;
}
Home |
Main Index |
Thread Index |
Old Index