Home | History | Annotate | Download | only in fpe
History log of /src/sys/arch/m68k/fpe/fpu_emulate.c
RevisionDateAuthorComments
 1.49  06-Jan-2025  isaki m68k/fpe: Avoid an illegal mod/reg before decoding it.
This also works for machines with FPU.
If the kernel defines FPU_EMULATE, even illegal FPU instructions in the real
6888x machines, the FPE will be executed by F line exception. So the FPE
must raise SIGILL appropriately for these.
 1.48  28-Dec-2024  isaki m68k/fpe: Remove duplicated assignments.
These are already stored before. No functional changes intended.
 1.47  28-Dec-2024  isaki m68k/fpe: Fix FTRAPcc emulation raise the correct trap.
Currently fpu_emul_type1() returns SIGFPE only if FTRAPcc's condition is met,
so this works. But I wish there was a better way..
fputest.x(0.24.10.08) about ftrapcc passed 100%.
 1.46  28-Dec-2024  isaki m68k/fpe: Reimplement and simplify test_cc().
This logic was analized by Y.Sugahara (in 2016).
Finally fputest.x(0.24.10.08) about fbcc fdbcc fscc (40960 tests) passed 100%!
 1.45  28-Dec-2024  isaki m68k/fpe: Two bugfixes in test_cc().
- Don't clear the exception byte in FPSR.
According to the manual, all bits except BSUN are "not affected".
- Accumulate AIOP bit always.
XXX Need to look this again later. brcc() looks to have similar one.
 1.44  28-Dec-2024  isaki m68k/fpe: Several bugfixes in FDBcc and FTRAPcc emulation.
In fpu_emul_type1(),
- If test_cc() returns >0, it's an error, that is an illegal instruction in
this case. So it should just return without doing anything.
By this fix, FTRAPcc with illegal cc now causes SIGILL correctly.
- In result, branch can only be 0 or -1 after that. It makes code simple.
By this cleanup, FDBcc with illegal cc now causes SIGILL correctly.
- FTRAPcc must advance PC regardless of whether the condition is met.
(although FTRAPcc does not work at this point by anothor problem)
 1.43  28-Dec-2024  isaki m68k/fpe: Fix several FMOVEM FPctl emulation.
- Fix the write order of FMOVEM FPctl,-(An).
For example, "FMOVEM FPCR/FPSR,-(An)" instruction first decrements An by
the total size (4*2 bytes), then writes FPCR and FPSR in this order.
Therefore, it's differs from "FMOVEM FPCR,-(An); FMOVEM FPSR,-(An)" sequence.
- Support multiple immediate case like "FMOVEM #imm/#imm,FPCR/FPIAR".
- Mask writes to FPSR and FPCR registers correctly.
- Support reglist=0 case too. It's not common case but makes code easier.
 1.42  28-Dec-2024  isaki m68k/fpe: FMOVEM (both FPn and FPctl) must not update accrued byte in FPSR.
 1.41  17-Sep-2023  andvar branches: 1.41.6;
word was changed to sval at rev 1.39, but DPRINTF values were not updated.

Fixes DEBUG_FPE enabled build for 68k FPE code.
 1.40  27-Dec-2019  msaitoh s/opration/operation/
 1.39  06-Apr-2019  thorpej Overhaul the API used to fetch and store individual memory cells in
userspace. The old fetch(9) and store(9) APIs (fubyte(), fuword(),
subyte(), suword(), etc.) are retired and replaced with new ufetch(9)
and ustore(9) APIs that can return proper error codes, etc. and are
implemented consistently across all platforms. The interrupt-safe
variants are no longer supported (and several of the existing attempts
at fuswintr(), etc. were buggy and not actually interrupt-safe).

Also augmement the ucas(9) API, making it consistently available on
all plaforms, supporting uniprocessor and multiprocessor systems, even
those that do not have CAS or LL/SC primitives.

Welcome to NetBSD 8.99.37.
 1.38  25-Oct-2013  martin branches: 1.38.30;
Comment unused stuff (for documentation purposes)
 1.37  26-Mar-2013  isaki branches: 1.37.4;
u_int -> uint32_t
 1.36  15-Oct-2011  tsutsui branches: 1.36.2; 1.36.12;
Add hyperboric and trigonometric functions to m68k FPE, written by isaki@.
With these emulations (~4KB text) xeyes on XM6i works better.
Discussed with isaki@ at OSC 2011 Hiroshima.
 1.35  18-Jul-2011  isaki fix indent again.
- "Second level indents are four spaces." pointed out by tsutsui@
- fold long line.
 1.34  18-Jul-2011  isaki fix indent. no functional changes.
 1.33  23-May-2011  tsutsui - use DPRINTF() style debug printfs
- use __func__ to print function names
- consistently use #ifdef DEBUG_FPE
- add some missing debug messages including \n in error paths
 1.32  23-May-2011  tsutsui KNF, mostly indent. No binary change.
 1.31  14-May-2011  tsutsui Fix botch in rev 1.28 that causes wrong results of fcmp and ftst in FPE.
fpu_upd_fpsr() should be called even in discard_result case if an emulated
instruction gets proper result without signal.

Fixes weird behavior of awk(1) seen on /etc/rc.d/postfix on XM6i and
TME emulating sun3 without 68881.

Should be pulled up to all netbsd-4 and netbsd-5 branches.
 1.30  14-Mar-2009  dsl branches: 1.30.4; 1.30.6;
Change about 4500 of the K&R function definitions to ANSI ones.
There are still about 1600 left, but they have ',' or /* ... */
in the actual variable definitions - which my awk script doesn't handle.
There are also many that need () -> (void).
(The script does handle misordered arguments.)
 1.29  14-Mar-2009  dsl Remove all the __P() from sys (excluding sys/dist)
Diff checked with grep and MK1 eyeball.
i386 and amd64 GENERIC and sys still build.
 1.28  20-Jan-2009  tsutsui branches: 1.28.2;
In fpu_emul_arith(), check lower 7 bits in word1 rather than only 6 bits
to check 040/060 FP instructions, and don't call fpu_implode() and
fpu_upd_fpsr() if no vaild emulated result is set otherwise these
functions cause NULL pointer dereference.

Fixes panics triggered by 040/060's FDADD instruction
(which has the same lower 6 bits with fscale instruction)
on 020/030 machines (even with 68881/68882) running kernels
with options FPU_EMULATE.
Problem reported by John Carr on port-sun3.

Should be pulled up to netbsd-4-0, netbsd-4 and netbsd-5.

XXX: m68k 4.0 packages binaries on ftp have this FDADD instruction.
 1.27  09-Mar-2007  tsutsui branches: 1.27.44; 1.27.52; 1.27.54;
Make these compile with options DEBUG_FPE.
 1.26  11-Dec-2005  christos branches: 1.26.24; 1.26.26;
merge ktrace-lwp.
 1.25  22-Sep-2003  cl branches: 1.25.14; 1.25.16;
SA_SIGINFO support for m68k
 1.24  15-Jul-2003  lukem __KERNEL_RCSID()
 1.23  05-Feb-2001  chs branches: 1.23.24;
conditionalize the ddb hook on DDB && DEBUG_FPE rather than DDB && DEBUG,
since that's the condition under which we include the header file that
allows it to compile.
 1.22  05-Jan-2001  is Make this actually sort-of-work for 68060 w. disabled FPU (tested), 68LC060,
and I suspect, 68LC040 and 68040V machines. Method used:

1. do NOT use the frames effective address at all
2. do NOT use the frames next instruction address, but
3. restore the "this instruction" pc into the pc field of the frame at the
beginning of the emulation, if we got a frame format 4.

TODO:
A. find the bug in the usage of the frame EA, and revert to using it.
B. find the bug in the usage of the frames next instruction address, and
consider whether it's worthwhile to use it.
C. make the emulation complete.... FEXP FETOM1, and the trigonometric functions
are missing.
 1.21  30-May-1999  briggs branches: 1.21.2;
PR 7220 from Ken Nakata:
I've fixed most (not all) m68k FPE bugs that give bogus
calculation results, esp. fsqrt instruction. Also, the internal FP
representation has been reduced from 115-bit mantissa to 67-bit
mantissa which reduced the required mantissa operation roughly by one
fourth. I've done an extensive (though not exhaustive - it's
impossible!) test on the internal routines by feeding them randomly
generated FP numbers, and found that the new code is more precise than
MC68040 FPU (it seems to have a rounding bug).

[ Only change was to keep fpu_calcea.c's name instead of renaming to
fpu_ea.c in Ken's patch. --akb ]
 1.20  04-Jul-1998  jonathan branches: 1.20.8; 1.20.10; 1.20.12;
defopt DDB.
 1.19  03-Nov-1997  is Back out last change, which was a thinko.
 1.18  02-Nov-1997  is Add ftwotox emulation, by using the fscale emulation routine (preload
destination register bit pattern with 1.0), which automatically provides
corner case handling.
Missing ftwotox emulation originally reported by Norman Mackenzie in PR 4237,
but he proposed a different implementation.
 1.17  20-Jul-1997  is Make us pass the full ieeefp except regression test.
XXX This is probably a horrible hack, and wrong. FPU signal handling needs
to be further evaluated.
 1.16  19-Jul-1997  is Fix my own PR port-m68k/3871, nee port-amiga/3871:
- don't erase FPSR exception bits _after_ doing most of the operations in
fpu_implode(), erase them before doing arith and store operations. This fixes
losing the DZ bit.
- create FPSR_OVFL and FPSR_UNFL bits in fpu_implode(). This showed up when
the first error was fixed.
XXX some more work needs to be done. E.g., creating OPERR together with
OVFL looks bogus, but I'm too tired know to re-check docs; and at least we
pass our own regression tests know.
 1.15  17-Jul-1997  veego include <m68k/db_machdep.h> to get the prototype for kdb_trap if DDB and
DEBUG are defined and add a cast for the second argument to the
kdb_trap call.
 1.14  18-Dec-1996  scottr Work around another uninitialized variable warning
 1.13  17-Dec-1996  gwr Fix warnings.
 1.12  30-Oct-1996  is Bug fix for FSINCOS: wouldn't handle FPc == FP1 earlier.
 1.11  16-Oct-1996  scottr Eliminate fusword() prototype, as it's now in <sys/systm.h>
 1.10  13-Oct-1996  christos backout previous kprintf change
 1.9  11-Oct-1996  christos printf -> kprintf, sprintf -> ksprintf
 1.8  07-Oct-1996  scottr The 68LC040 generates a format 4 stack frame for floating point
exceptions, which puts the address of the instruction we faulted
on in a different location. Copy it and handle as we normally would,
restoring the saved PC before returning.

The FPE should probably be reworked to take advantage of the 68LC040's
precalculated effective address, at some point.
 1.7  04-Oct-1996  scottr Fix FMOVEM emulation; postincrement modes use different ordering than
predecrement modes, per 68K Programmer's Manual p. 5-88. Pointed out
by Takeshi Nakayama <takeshi@sakabe.nuie.nagoya-u.ac.jp>, verified by me.
 1.6  15-May-1996  leo branches: 1.6.4;
Fix "might be used uninitialized" warnings.
 1.5  30-Apr-1996  briggs Update for -Wall -Wstrict-prototypes -Wmissing-prototypes -Wno-uninitialized.
 1.4  05-Nov-1995  briggs Fixes from Ken Nakata. Mainly renaming debug_level to fpu_debug_level.
 1.3  03-Nov-1995  briggs Still incomplete, but much more complete FPE from Ken Nakata
<kenn@remus.rutgers.edu>. This emulator does not yet emulate
the following functions:
FSINH, FETOXM1, FTANH, FATAN, FASIN, FATANH, FSIN, FTAN,
FETOX, FTWOTOX, FTENTOX, FCOSH, FACOS, FCOS, FSINCOS
It is sufficient, however, to allow programs like df, w, and newfs,
to run to completion with correct results.
Portions of this code were based on the sparc fpe and on initial
work by gwr.
 1.2  10-Mar-1995  gwr Add missing break in switch (not that it mattered 8^)
 1.1  01-Mar-1995  gwr branches: 1.1.1;
Initial revision
 1.1.1.1  01-Mar-1995  gwr First cut at an mc68881 emulator. Works only for fmovem right now.
 1.6.4.1  05-Dec-1996  rat Pullup request 1.11 to 1.12 from Ignatios Souvatzis <ignatios@cs.uni-bonn.de>

>This fixes an oversight/editing error, which would prevent us from emulating
>the FSINCOS opcode, where FPcos == FP1.
 1.20.12.1  30-Nov-1999  itojun bring in latest KAME (as of 19991130, KAME/NetBSD141) into kame branch
just for reference purposes.
This commit includes 1.4 -> 1.4.1 sync for kame branch.

The branch does not compile at all (due to the lack of ALTQ and some other
source code). Please do not try to modify the branch, this is just for
referenre purposes.

synchronization to latest KAME will take place on HEAD branch soon.
 1.20.10.1  21-Jun-1999  thorpej Sync w/ -current.
 1.20.8.2  06-Feb-2000  he Apply patch (requested by is):
Revert floating point emulation software to the version released
as NetBSD 1.4. The upgrade done in 1.4.1 had problems.
 1.20.8.1  21-Jun-1999  perry pullup 1.20->1.21 (briggs): fix FPE
 1.21.2.2  11-Feb-2001  bouyer Sync with HEAD.
 1.21.2.1  18-Jan-2001  bouyer Sync with head (for UBC+NFS fixes, mostly).
 1.23.24.3  21-Sep-2004  skrll Fix the sync with head I botched.
 1.23.24.2  18-Sep-2004  skrll Sync with HEAD.
 1.23.24.1  03-Aug-2004  skrll Sync with HEAD
 1.25.16.1  03-Sep-2007  yamt sync with head.
 1.25.14.1  31-Mar-2007  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1703):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.27
sys/arch/m68k/fpe/fpu_calcea.c: revision 1.18
sys/arch/m68k/fpe/fpu_fstore.c: revision 1.10
Make these compile with options DEBUG_FPE.
Don't disable EA_DIRECT in fpu_load_ea(), which seems disabled
accidentally in rev 1.11 about six years ago, otherwise
fmovel %dN,%fpN instructions cause unexpected memory access.
 1.26.26.1  12-Mar-2007  rmind Sync with HEAD.
 1.26.24.2  31-Jan-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1268):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.28
In fpu_emul_arith(), check lower 7 bits in word1 rather than only 6 bits
to check 040/060 FP instructions, and don't call fpu_implode() and
fpu_upd_fpsr() if no vaild emulated result is set otherwise these
functions cause NULL pointer dereference.
Fixes panics triggered by 040/060's FDADD instruction
(which has the same lower 6 bits with fscale instruction)
on 020/030 machines (even with 68881/68882) running kernels
with options FPU_EMULATE.
Problem reported by John Carr on port-sun3.
Should be pulled up to netbsd-4-0, netbsd-4 and netbsd-5.
XXX: m68k 4.0 packages binaries on ftp have this FDADD instruction.
 1.26.24.1  31-Mar-2007  bouyer branches: 1.26.24.1.6;
Pull up following revision(s) (requested by tsutsui in ticket #526):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.27
sys/arch/m68k/fpe/fpu_calcea.c: revision 1.18
sys/arch/m68k/fpe/fpu_fstore.c: revision 1.10
Make these compile with options DEBUG_FPE.
Don't disable EA_DIRECT in fpu_load_ea(), which seems disabled
accidentally in rev 1.11 about six years ago, otherwise
fmovel %dN,%fpN instructions cause unexpected memory access.
 1.26.24.1.6.1  31-Jan-2009  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1268):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.28
In fpu_emul_arith(), check lower 7 bits in word1 rather than only 6 bits
to check 040/060 FP instructions, and don't call fpu_implode() and
fpu_upd_fpsr() if no vaild emulated result is set otherwise these
functions cause NULL pointer dereference.
Fixes panics triggered by 040/060's FDADD instruction
(which has the same lower 6 bits with fscale instruction)
on 020/030 machines (even with 68881/68882) running kernels
with options FPU_EMULATE.
Problem reported by John Carr on port-sun3.
Should be pulled up to netbsd-4-0, netbsd-4 and netbsd-5.
XXX: m68k 4.0 packages binaries on ftp have this FDADD instruction.
 1.27.54.2  18-Jun-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1626):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.31
Fix botch in rev 1.28 that causes wrong results of fcmp and ftst in FPE.
fpu_upd_fpsr() should be called even in discard_result case if an emulated
instruction gets proper result without signal.
Fixes weird behavior of awk(1) seen on /etc/rc.d/postfix on XM6i and
TME emulating sun3 without 68881.
Should be pulled up to all netbsd-4 and netbsd-5 branches.
 1.27.54.1  26-Jan-2009  snj branches: 1.27.54.1.2; 1.27.54.1.6;
Pull up following revision(s) (requested by tsutsui in ticket #308):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.28
In fpu_emul_arith(), check lower 7 bits in word1 rather than only 6 bits
to check 040/060 FP instructions, and don't call fpu_implode() and
fpu_upd_fpsr() if no vaild emulated result is set otherwise these
functions cause NULL pointer dereference.
Fixes panics triggered by 040/060's FDADD instruction
(which has the same lower 6 bits with fscale instruction)
on 020/030 machines (even with 68881/68882) running kernels
with options FPU_EMULATE.
Problem reported by John Carr on port-sun3.
Should be pulled up to netbsd-4-0, netbsd-4 and netbsd-5.
XXX: m68k 4.0 packages binaries on ftp have this FDADD instruction.
 1.27.54.1.6.1  18-Jun-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1626):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.31
Fix botch in rev 1.28 that causes wrong results of fcmp and ftst in FPE.
fpu_upd_fpsr() should be called even in discard_result case if an emulated
instruction gets proper result without signal.
Fixes weird behavior of awk(1) seen on /etc/rc.d/postfix on XM6i and
TME emulating sun3 without 68881.
Should be pulled up to all netbsd-4 and netbsd-5 branches.
 1.27.54.1.2.1  18-Jun-2011  bouyer Pull up following revision(s) (requested by tsutsui in ticket #1626):
sys/arch/m68k/fpe/fpu_emulate.c: revision 1.31
Fix botch in rev 1.28 that causes wrong results of fcmp and ftst in FPE.
fpu_upd_fpsr() should be called even in discard_result case if an emulated
instruction gets proper result without signal.
Fixes weird behavior of awk(1) seen on /etc/rc.d/postfix on XM6i and
TME emulating sun3 without 68881.
Should be pulled up to all netbsd-4 and netbsd-5 branches.
 1.27.52.2  28-Apr-2009  skrll Sync with HEAD.
 1.27.52.1  03-Mar-2009  skrll Sync with HEAD.
 1.27.44.1  04-May-2009  yamt sync with head.
 1.28.2.1  13-May-2009  jym Sync with HEAD.

Commit is split, to avoid a "too many arguments" protocol error.
 1.30.6.1  06-Jun-2011  jruoho Sync with HEAD.
 1.30.4.1  31-May-2011  rmind sync with head
 1.36.12.2  20-Aug-2014  tls Rebase to HEAD as of a few days ago.
 1.36.12.1  23-Jun-2013  tls resync from head
 1.36.2.1  22-May-2014  yamt sync with head.

for a reference, the tree before this commit was tagged
as yamt-pagecache-tag8.

this commit was splitted into small chunks to avoid
a limitation of cvs. ("Protocol error: too many arguments")
 1.37.4.1  18-May-2014  rmind sync with head
 1.38.30.2  08-Apr-2020  martin Merge changes from current as of 20200406
 1.38.30.1  10-Jun-2019  christos Sync with HEAD
 1.41.6.1  02-Aug-2025  perseant Sync with HEAD

RSS XML Feed