Welcome to ftp.nluug.nl Current directory: /ftp/os/BSD/NetBSD/NetBSD-release-10/src/sys/arch/m68k/fpe/ |
|
Contents of README:* $NetBSD: README,v 1.7 2021/08/21 23:00:31 andvar Exp $ * NetBSD/m68k FPE (floating point emulation) README file * Created Oct/??/95 by kenn@remus.rutgers.edu (Ken Nakata) * Last updated Oct/15/2011 by tsutsui 1. INSTALLATION AND COMPILATION To compile a kernel with FPE built-in, do the following: 1) Add a line "options FPU_EMULATE" to your config file. If you are going to use the resulted kernel on a machine with an FPU for debugging purpose, add "options DEBUG_WITH_FPU" as well. 2) Follow the usual procedure to build a new kernel. NOTE: If you add "options DEBUG_WITH_FPU", FPE will accept cpID=6 as emulated FPU. You will need a modified gas that generates cpID=6 for floating point instructions, instead of normal cpID=1. Mount unionfs or copy the gas source directory and apply the following patch: *** /usr/src/gnu/usr.bin/gas/config/tc-m68k.c Mon Nov 21 16:30:41 1994 --- gas/config/tc-m68k.c Fri Sep 29 07:59:06 1995 *************** *** 1275,1281 **** /* memcpy((char *)(&the_ins.operands[1]), (char *)(&the_ins.operands[0]), opsfound*sizeof(the_ins.operands[0])); */ memset((char *)(&the_ins.operands[0]), '\0', sizeof(the_ins.operands[0])); the_ins.operands[0].mode=MSCR; ! the_ins.operands[0].reg=COPNUM; /* COP #1 */ opsfound++; } --- 1275,1281 ---- /* memcpy((char *)(&the_ins.operands[1]), (char *)(&the_ins.operands[0]), opsfound*sizeof(the_ins.operands[0])); */ memset((char *)(&the_ins.operands[0]), '\0', sizeof(the_ins.operands[0])); the_ins.operands[0].mode=MSCR; ! the_ins.operands[0].reg=COP5; /* COP #6 */ opsfound++; } Also, with the DEBUG_WITH_FPU option, you will be able to run only ONE process that uses FPE at once to get correct results. 2. MISSING PARTS For missing instructions, refer to the Section 3. Other than that, there is one thing that is missing from this version of FPE: packed BCD support. I have no plan to support it since it's rarely used. However, all we need to support it is explosion/implosion functions between the internal FP representation and the m68k PBCD format, so you are more than welcome to write such functions if you wish to. 3. IMPLEMENTED INSTRUCTIONS This is the list of implemented and unimplemented FPU instructions. All 040's directly supported type 0 instructions are already implemented except FSGLDIV and FSGLMUL. Type field = bit 8-6 of opcode word * Implemented Instructions Type=0: FMOVE (mem->FPr), FINT, FINTRZ, FSQRT, FABS, FNEG, FGETEXP, FGETMAN, FDIV, FADD, FMUL, FSGLDIV(*), FSCALE, FSGLMUL(*), FSUB, FCMP, FTST, FMOVE (FPr->mem), FMOVEM (FPr), FMOVEM (FPcr), FMOVECR, FLOGNP1, FLOGN, FLOG10, FLOG2, FMOD, FREM, FCOSH, FSINH, FTANH, FCOS, FSIN, FTAN, FSINCOS, FETOX, FETOXM1, FTENTOX, FTWOTOX, FATANH, FACOS, FASIN, FATAN Type=1: FDBcc, FScc, FTRAPcc, Type=2: FBcc (word, incl. FNOP) Type=3: FBcc (long) Type=4: none Type=5: none *: currently FSGLMUL and FSGLDIV are just aliases of FMUL and FDIV, respectively * Unimplemented Instructions Type=0: none Type=1: none Type=2: none Type=3: none Type=4: FSAVE Type=5: FRESTORE 4. HOW TO ADD A NEW INSTRUCTION SUPPORT Since we need not support FSAVE and FRESTORE operations, all instructions we have to implement are type 0, all of which are arithmetic operations. It is particularly easy to add a new arithmetic instruction to the existing ones (not that it is easy to write a "stable" function to perform floating point operation. That's entirely another matter). In "fpu_emulate.c", there's a function fpu_emul_arith() which calls emulation functions for all arithmetic operations. In it, there's a large switch() { case ... } which dispatches each instruction emulator. An emulation function of any type 0 arithmetic instruction follows this prototype: struct fpn *fpu_op(struct fpemu *fe); Where fe is a pointer to a struct fpemu in which frame, fpframe, and fetched operands are accessible. That's right, you don't have to fetch the operands by yourself in your emulation function. For instance, the parts calling FSQRT, FSUB, FADD and FTST look like: switch(word1 & 0x3F) { [...] case 0x04: /* fsqrt */ res = fpu_sqrt(fe); break; [...] case 0x28: /* fsub */ fe->fe_f2.fp_sign = !fe->fe_f2.fp_sign; /* f2 = -f2 */ case 0x22: /* fadd */ res = fpu_add(fe); break; [...] case 0x3A: /* ftst */ res = &fe->fe_f2; no_store = 1; break; [...] default: sig = SIGILL; } /* switch */ Here, fe->fe_f1 and fe->fe_f2 are fetched operands. You can use fe->fe_f3 for storing the result, or you can return a pointer to either operand if you want to. At any rate, you have to follow the following rules: 1) A dyadic instruction takes two operands fe->fe_f1 and fe->fe_f2. 2) A monadic instruction takes one operands fe->fe_f2 (NOT fe_f1). 3) Must return a pointer to struct fpn where the result is stored, and assign the pointer to the variable "res". 4) If exceptions are detected, set corresponding bits in fe->fe_fpsr. The rest is taken care of in fpu_emul_arith(). 5) Condition code need not be calculated. It's taken care of in fpu_emul_arith(). Actually, after above was written, stubs for the missing functions were added to the source, so you do not have to change fpu_emul_arith() at all. Function names and prototypes are in fpu_arith_proto.h, and all except fpu_sincos() follow the rules above. fpu_sincos() is declared as struct fpn *fpu_sincos(struct fpemu *fe, int cosreg); where cosreg is the FP register number to which cosine of the argument is calculated and assigned. Sine of the argument is stored into the destination register in the same manner as the other arithmetic functions. |
Name Last modified Size
Parent Directory - CVS/ 17-Dec-2022 21:35 - README 22-Aug-2021 01:00 5.7K files.fpe 19-Apr-2013 15:31 1.0K fpu_add.c 26-Mar-2013 12:30 6.8K fpu_arith.h 01-Apr-2013 15:59 6.1K fpu_arith_proto.h 14-Mar-2009 15:46 3.3K fpu_calcea.c 06-Apr-2019 05:06 18K fpu_cordic.c 06-Dec-2016 06:58 10K fpu_div.c 01-Jan-2014 06:23 7.7K fpu_emulate.c 27-Dec-2019 08:41 28K fpu_emulate.h 06-Dec-2016 06:58 10K fpu_exp.c 15-Jan-2017 12:56 5.1K fpu_explode.c 08-Mar-2021 15:37 7.7K fpu_fmovecr.c 26-Mar-2013 12:30 4.3K fpu_fscale.c 26-Mar-2013 12:30 9.2K fpu_fstore.c 26-Mar-2013 12:30 4.0K fpu_getexp.c 18-Jul-2011 09:44 2.7K fpu_hyperb.c 05-Dec-2016 16:31 6.1K fpu_implode.c 26-Mar-2013 12:30 13K fpu_int.c 19-Mar-2013 10:17 2.6K fpu_log.c 04-Jan-2014 14:23 18K fpu_mul.c 06-Dec-2016 07:41 6.8K fpu_rem.c 05-Feb-2015 13:22 5.3K fpu_sqrt.c 24-May-2022 22:00 11K fpu_subr.c 21-Apr-2013 04:50 5.9K fpu_trig.c 16-Jan-2017 13:05 8.8K
NLUUG - Open Systems. Open Standards
Become a member
and get discounts on conferences and more, see the NLUUG website!