uxmal / reko

Reko is a binary decompiler.
https://uxmal.github.io/reko
GNU General Public License v2.0
2.09k stars 250 forks source link

Add support for MacOS Classic SANE FPU emulation #493

Open uxmal opened 6 years ago

uxmal commented 6 years ago

MacOS supported FPU emulation using a trap called FP68k (or Pack4). After some digging around, I finally found a book which -- although not an official reference -- contains information relevant to an implementation.

On Macintosh Programming Advanced Techniques, p166, has the following table:

Function PACKs 68881 C Pascal
Arithmetic FP68K
Addition $0000 FADD + +
Subtraction $0002 FSUB - -
Multiplication $0004 FMUL * *
Division $0006 FDIV / /
Remainder, IEEE (md to nearest) $000C FREM
Remainder, modulo (md to zero) FMOD fmod
Negation $000D FNEG
Absolute value $000F FABS fabs abs
Copy sign $0011
Square root $0012 FSQRT sqrt sqrt
Nextafter $0013
Integer part, cur. rounding mode $0014 FINT
Integer part, rounded to zero $0016 FINTRZ trunc* trunc
Integer part, rounded to -oo floor
Integer part, rounded to += ceil
Round, ties round away from zero round
Integer & fractional parts modf
Scale x to [.5,1) and a power of 2 frexp
Scale x by 2^i (i: integer) $0018 FSCALE ldexp
Extract exponent (logb) $001A FGETEXP
Extract mantissa FGETMAN
Logarithmic Elems68K
Log base e (In or natural log) $0000 FLOGN log ln
Log base 2 $0002 FLOG2 log2*
Log (I +x), base e $0004 FLOGNPl lnl*
Log (l+x), base 2 $0006
Log base 10 (common log) FLOG10 log10
Exponential Elems68K
e^x (exponential, natural antilog) $0008 FETOX exp exp
2^x $000A FTWOTOX exp2*
e^x -1 $000C FETOXMl expl*
2^x - 1 $000E
10^x (common antilog) FTENTOX exp10*
x^i (i: integer) $8010
x^y $8012 pow
Trigonometric Elems68K
Sine $0018 FSIN sin sin
Cosine $001A FCOS cos cos
Tangent $001C FTAN tan tan
Inverse sine FASIN asin
Inverse cosine FACOS acos
Inverse tangent $001E FATAN atan arctan
Angle of (x,y) in range [-7t,7t] atan2
Hyperbolic sine FSINH sinh
Hyperbolic cosine FCOSH cosh
Hyperbolic tangent FTANH tanh
Hyperbolic inverse sine
Hyperbolic inverse cosine
Hyperbolic inverse tangent FATANH atanh*

Implementing this is a SMOP.

uxmal commented 6 years ago

Another useful informational link: http://toddp.com/classic/Software%20Install/Apple%20Source%20Code/System%207.1%20Source/Interfaces/AIncludes/SANEMacs.a