Merge copy-and-pasted fpu_probe() function (to share it among more m68k ports).

Tested on TT030, Sun3/80, and X68030.
This commit is contained in:
tsutsui 2011-11-15 12:23:21 +00:00
parent e179a96fd3
commit 556c80110c
11 changed files with 56 additions and 238 deletions

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.15 2009/03/18 10:22:24 cegger Exp $ */
/* $NetBSD: fpu_machdep.c,v 1.1 2011/11/15 12:23:21 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -30,12 +30,11 @@
*/
/*
* Floating Point Unit (MC68881/882/040)
* Probe for the FPU at autoconfig time.
* Floating Point Unit (MC68881/882/040) initialization.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.15 2009/03/18 10:22:24 cegger Exp $");
__KERNEL_RCSID(0, "$NetBSD: fpu_machdep.c,v 1.1 2011/11/15 12:23:21 tsutsui Exp $");
#include "opt_fpu_emulate.h"
@ -54,14 +53,16 @@ extern int *nofault;
static const char *fpu_descr[] = {
#ifdef FPU_EMULATE
" emulated ", /* 0 */
[FPU_NONE] = " emulated ",
#else
" no ", /* 0 */
[FPU_NONE] = " no ",
#endif
" mc68881 ", /* 1 */
" mc68882 ", /* 2 */
"/", /* 3 68040 internal */
"??? " };
[FPU_68881] = " mc68881 ",
[FPU_68882] = " mc68882 ",
[FPU_68040] = "/",
[FPU_68060] = "/",
[FPU_UNKNOWN] = "??? "
};
const char *
fpu_describe(int type)
@ -70,69 +71,5 @@ fpu_describe(int type)
if ((type < 0) || (type > maxtype))
type = 0;
return(fpu_descr[type]);
}
int
fpu_probe(void)
{
/*
* A 68881 idle frame is 28 bytes and a 68882's is 60 bytes.
* We, of course, need to have enough room for either.
*/
struct fpframe fpframe;
label_t faultbuf;
u_char b;
nofault = (int *) &faultbuf;
if (setjmp((label_t *)nofault)) {
nofault = (int *) 0;
return(0);
}
/*
* Synchronize FPU or cause a fault.
* This should leave the 881/882 in the IDLE state,
* state, so we can determine which we have by
* examining the size of the FP state frame
*/
__asm("fnop");
nofault = (int *) 0;
/*
* Presumably, if we're an 040 and did not take exception
* above, we have an FPU. Don't bother probing.
*/
if (mmutype == MMU_68040) {
return 3;
}
/*
* 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("movl %0, %%a0; fsave %%a0@" : : "a" (&fpframe) : "a0" );
b = fpframe.fpf_fsize;
/*
* Now, restore a NULL state to reset the FPU.
*/
fpframe.fpf_null = 0;
fpframe.fpf_idle.fpf_ccr = 0; /* XXX: really needed? */
m68881_restore(&fpframe);
/*
* The size of a 68881 IDLE frame is 0x18
* and a 68882 frame is 0x38
*/
if (b == 0x18) return 1;
if (b == 0x38) return 2;
/*
* If it's not one of the above, we have no clue what it is.
*/
return 4;
return fpu_descr[type];
}

View File

@ -1,5 +1,5 @@
#
# $NetBSD: files.atari,v 1.119 2011/06/12 03:35:39 rmind Exp $
# $NetBSD: files.atari,v 1.120 2011/11/15 12:23:21 tsutsui Exp $
maxpartitions 16
@ -212,11 +212,12 @@ file arch/atari/atari/mainbus.c
file arch/atari/atari/pmap_bootstrap.c
file arch/atari/atari/trap.c
file arch/atari/atari/stalloc.c
file arch/atari/atari/fpu.c
file arch/atari/atari/fpu_machdep.c
file arch/atari/dev/ym2149.c _atarihw_
file arch/atari/atari/intr.c
file arch/m68k/m68k/cacheops.c
file arch/m68k/m68k/db_memrw.c ddb
file arch/m68k/m68k/fpu.c
file arch/m68k/m68k/pmap_motorola.c
file arch/m68k/m68k/procfs_machdep.c procfs
file arch/m68k/m68k/sys_machdep.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.67 2011/05/16 13:22:52 tsutsui Exp $ */
/* $NetBSD: cpu.h,v 1.68 2011/11/15 12:23:22 tsutsui Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -160,7 +160,6 @@ void config_console(void);
* Prototypes from fpu.c
*/
const char *fpu_describe(int);
int fpu_probe(void);
/*
* Prototypes from locore.s

View File

@ -1,4 +1,4 @@
/* $NetBSD: m68k.h,v 1.19 2011/05/16 13:22:53 tsutsui Exp $ */
/* $NetBSD: m68k.h,v 1.20 2011/11/15 12:23:22 tsutsui Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -118,6 +118,9 @@ void setfunc_trampoline(void);
void w16zero(void *, u_int);
void w16copy(const void *, void *, u_int);
/* fpu.c */
int fpu_probe(void);
#ifdef MAPPEDCOPY
/* mappedcopy.c */
int mappedcopyin(void *fromp, void *top, size_t count);

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.14 2008/04/28 20:23:40 martin Exp $ */
/* $NetBSD: fpu.c,v 1.1 2011/11/15 12:23:22 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -31,11 +31,11 @@
/*
* Floating Point Unit (MC68881/882/040/060)
* Probe for the FPU at autoconfig time.
* Probe for the FPU at early bootstrap.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.14 2008/04/28 20:23:40 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.1 2011/11/15 12:23:22 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@ -57,12 +57,12 @@ fpu_probe(void)
* We, of course, need to have enough room for either.
*/
struct fpframe fpframe;
label_t faultbuf;
u_char b;
label_t faultbuf;
uint8_t b;
nofault = (int *) &faultbuf;
nofault = (int *)&faultbuf;
if (setjmp(&faultbuf)) {
nofault = (int *) 0;
nofault = (int *)0;
return FPU_NONE;
}
@ -80,11 +80,10 @@ fpu_probe(void)
* Presumably, if we're an 040/060 and did not take exception
* above, we have an FPU. Don't bother probing.
*/
if (cputype == CPU_68060) {
if (cputype == CPU_68060)
return FPU_68060;
} else if (cputype == CPU_68040) {
if (cputype == CPU_68040)
return FPU_68040;
}
/*
* Presumably, this will not cause a fault--the fnop should
@ -106,8 +105,10 @@ fpu_probe(void)
* The size of a 68881 IDLE frame is 0x18
* and a 68882 frame is 0x38
*/
if (b == 0x18) return FPU_68881;
if (b == 0x38) return FPU_68882;
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.

View File

@ -1,4 +1,4 @@
# $NetBSD: files.mac68k,v 1.124 2011/06/12 03:35:43 rmind Exp $
# $NetBSD: files.mac68k,v 1.125 2011/11/15 12:23:22 tsutsui Exp $
# mac68k-specific configuration info
@ -158,7 +158,7 @@ file arch/mac68k/mac68k/bus_space.c
file arch/mac68k/mac68k/clock.c
file arch/mac68k/mac68k/conf.c
file arch/mac68k/mac68k/disksubr.c disk
file arch/mac68k/mac68k/fpu.c
file arch/mac68k/mac68k/fpu_machdep.c
file arch/mac68k/mac68k/intr.c
file arch/mac68k/mac68k/iop.c
file arch/mac68k/mac68k/machdep.c
@ -174,6 +174,7 @@ file arch/mac68k/mac68k/via.c
file arch/m68k/m68k/bus_dma.c
file arch/m68k/m68k/cacheops.c
file arch/m68k/m68k/db_memrw.c ddb | kgdb
file arch/m68k/m68k/fpu.c
file arch/m68k/m68k/kgdb_machdep.c kgdb
file arch/m68k/m68k/pmap_motorola.c
file arch/m68k/m68k/procfs_machdep.c procfs

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.38 2008/04/28 20:23:27 martin Exp $ */
/* $NetBSD: fpu_machdep.c,v 1.1 2011/11/15 12:23:22 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -30,13 +30,12 @@
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.38 2008/04/28 20:23:27 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD: fpu_machdep.c,v 1.1 2011/11/15 12:23:22 tsutsui Exp $");
#include "opt_fpu_emulate.h"
/*
* Floating Point Unit (MC68881/882/040)
* Probe for the FPU at autoconfig time.
* Floating Point Unit (MC68881/882/040) initialization.
*/
#include <sys/param.h>
@ -50,19 +49,18 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.38 2008/04/28 20:23:27 martin Exp $");
extern label_t *nofault;
static int fpu_probe(void);
static const char *fpu_descr[] = {
#ifdef FPU_EMULATE
"emulator", /* 0 */
[FPU_NONE] = "emulator",
#else
"no math support", /* 0 */
[FPU_NONE] = "no math support",
#endif
"mc68881", /* 1 */
"mc68882", /* 2 */
"mc68040", /* 3 */
"mc68060", /* 4 */
"unknown" };
[FPU_68881] = "mc68881",
[FPU_68882] = "mc68882",
[FPU_68040] = "mc68040",
[FPU_68060] = "mc68060",
[FPU_UNKNOWN] = "unknown"
};
void
initfpu(void)
@ -82,67 +80,3 @@ initfpu(void)
printf("fpu: %s\n", descr);
}
static int
fpu_probe(void)
{
/*
* A 68881 idle frame is 28 bytes and a 68882's is 60 bytes.
* We, of course, need to have enough room for either.
*/
int fpframe[60 / sizeof(int)];
label_t faultbuf;
u_char b;
nofault = &faultbuf;
if (setjmp(&faultbuf)) {
nofault = (label_t *)0;
return (FPU_NONE);
}
/*
* Synchronize FPU or cause a fault.
* This should leave the 881/882 in the IDLE state,
* state, so we can determine which we have by
* examining the size of the FP state frame
*/
__asm("fnop");
nofault = 0;
/*
* Presumably, if we're an 040 and did not take exception
* above, we have an FPU. Don't bother probing.
*/
if (mmutype == MMU_68040)
return (FPU_68040);
/*
* 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("movl %0,%%a0; fsave %%a0@" : : "a" (fpframe) : "a0");
b = *((u_char *)fpframe + 1);
/*
* Now, restore a NULL state to reset the FPU.
*/
fpframe[0] = fpframe[1] = 0;
m68881_restore((struct fpframe *)fpframe);
/*
* The size of a 68881 IDLE frame is 0x18
* and a 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);
}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.sun3,v 1.79 2011/06/12 03:35:48 rmind Exp $
# $NetBSD: files.sun3,v 1.80 2011/11/15 12:23:22 tsutsui Exp $
#
# sun3-specific configuration info
@ -33,12 +33,13 @@ file arch/sun3/sun3x/pmap.c _sun3x_
file arch/sun3/sun3/autoconf.c
file arch/sun3/sun3/db_machdep.c ddb
file arch/sun3/sun3/db_memrw.c ddb | kgdb
file arch/sun3/sun3/fpu.c
file arch/sun3/sun3/fpu_machdep.c
file arch/sun3/sun3/leds.c
file arch/sun3/sun3/sunmon.c
file arch/sun3/sun3/sys_machdep.c
file arch/sun3/sun3/trap.c
file arch/m68k/m68k/cacheops.c _sun3x_
file arch/m68k/m68k/fpu.c
include "arch/m68k/fpe/files.fpe"

View File

@ -1,4 +1,4 @@
/* $NetBSD: fpu.c,v 1.25 2008/04/28 20:23:38 martin Exp $ */
/* $NetBSD: fpu_machdep.c,v 1.1 2011/11/15 12:23:22 tsutsui Exp $ */
/*-
* Copyright (c) 1996 The NetBSD Foundation, Inc.
@ -30,12 +30,11 @@
*/
/*
* Floating Point Unit (MC68881/882)
* Probe for the FPU at autoconfig time.
* Floating Point Unit (MC68881/882) initialization.
*/
#include <sys/cdefs.h>
__KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.25 2008/04/28 20:23:38 martin Exp $");
__KERNEL_RCSID(0, "$NetBSD");
#include "opt_fpu_emulate.h"
@ -47,8 +46,6 @@ __KERNEL_RCSID(0, "$NetBSD: fpu.c,v 1.25 2008/04/28 20:23:38 martin Exp $");
#include <sun3/sun3/machdep.h>
static int fpu_probe(void);
static const char *fpu_descr[] = {
#ifdef FPU_EMULATE
"emulator", /* 0 */
@ -84,56 +81,3 @@ initfpu(void)
} else
m68k_make_fpu_idle_frame();
}
static int
fpu_probe(void)
{
label_t faultbuf;
struct fpframe fpframe;
u_char b;
nofault = &faultbuf;
if (setjmp(&faultbuf)) {
nofault = NULL;
return FPU_NONE;
}
/*
* 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;
/* 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;
}

View File

@ -1,4 +1,4 @@
# $NetBSD: files.x68k,v 1.74 2011/06/12 03:35:49 rmind Exp $
# $NetBSD: files.x68k,v 1.75 2011/11/15 12:23:22 tsutsui Exp $
#
# new style config file for x68k architecture
#
@ -30,10 +30,10 @@ file arch/x68k/x68k/disksubr.c disk
file arch/x68k/x68k/machdep.c
file arch/x68k/x68k/pmap_bootstrap.c compile-with "${NOPROF_C}"
file arch/x68k/x68k/trap.c
file arch/x68k/x68k/fpu.c
file arch/x68k/x68k/bus.c
file arch/m68k/m68k/cacheops.c
file arch/m68k/m68k/db_memrw.c ddb
file arch/m68k/m68k/fpu.c
file arch/m68k/m68k/pmap_motorola.c
file arch/m68k/m68k/procfs_machdep.c procfs
file arch/m68k/m68k/sys_machdep.c

View File

@ -1,4 +1,4 @@
/* $NetBSD: cpu.h,v 1.54 2011/05/16 13:22:55 tsutsui Exp $ */
/* $NetBSD: cpu.h,v 1.55 2011/11/15 12:23:23 tsutsui Exp $ */
/*
* Copyright (c) 1988 University of Utah.
@ -127,9 +127,6 @@ extern int machineid;
extern uint8_t *intiobase;
extern uint8_t *intiolimit;
/* fpu.c functions */
int fpu_probe(void);
/* machdep.c functions */
void dumpsys(void);