Marked all dubious parts with ATS :-) for better searching. First round
of better documentation of the math emulator and of bugfixing it.
* [expediant "port" of linux 8087 emulator to 386BSD, with apologies -wfj]
*
* from: 386BSD 0.1
* [expediant "port" of linux 8087 emulator to 386BSD, with apologies -wfj]
*
* from: 386BSD 0.1
- * $Id: math_emulate.c,v 1.6 1993/12/19 00:50:05 wollman Exp $
+ * $Id: math_emulate.c,v 1.7 1994/01/29 22:07:16 nate Exp $
case 0x1d1: case 0x1d2: case 0x1d3:
case 0x1d4: case 0x1d5: case 0x1d6: case 0x1d7:
math_abort(info,SIGILL);
case 0x1d1: case 0x1d2: case 0x1d3:
case 0x1d4: case 0x1d5: case 0x1d6: case 0x1d7:
math_abort(info,SIGILL);
ST(0).exponent ^= 0x8000;
return(0);
ST(0).exponent ^= 0x8000;
return(0);
ST(0).exponent &= 0x7fff;
return(0);
case 0x1e2: case 0x1e3:
math_abort(info,SIGILL);
ST(0).exponent &= 0x7fff;
return(0);
case 0x1e2: case 0x1e3:
math_abort(info,SIGILL);
- case 0x1e4:
- ftst(PST(0));
+ case 0x1e4: /* fxtract */
+ ftst(PST(0)); /* ?????? */
printf("fxam not implemented\n\r");
math_abort(info,SIGILL);
case 0x1e6: case 0x1e7:
math_abort(info,SIGILL);
printf("fxam not implemented\n\r");
math_abort(info,SIGILL);
case 0x1e6: case 0x1e7:
math_abort(info,SIGILL);
fpush();
ST(0) = CONST1;
return(0);
fpush();
ST(0) = CONST1;
return(0);
+ case 0x1e9: /* fld2t */
fpush();
ST(0) = CONSTL2T;
return(0);
fpush();
ST(0) = CONSTL2T;
return(0);
+ case 0x1ea: /* fld2e */
fpush();
ST(0) = CONSTL2E;
return(0);
fpush();
ST(0) = CONSTL2E;
return(0);
+ case 0x1eb: /* fldpi */
fpush();
ST(0) = CONSTPI;
return(0);
fpush();
ST(0) = CONSTPI;
return(0);
+ case 0x1ec: /* fldlg2 */
fpush();
ST(0) = CONSTLG2;
return(0);
fpush();
ST(0) = CONSTLG2;
return(0);
+ case 0x1ed: /* fldln2 */
fpush();
ST(0) = CONSTLN2;
return(0);
fpush();
ST(0) = CONSTLN2;
return(0);
fpush();
ST(0) = CONSTZ;
return(0);
fpush();
ST(0) = CONSTZ;
return(0);
"math_emulate: instruction %04x not implemented\n",
code + 0xd800);
math_abort(info,SIGILL);
"math_emulate: instruction %04x not implemented\n",
code + 0xd800);
math_abort(info,SIGILL);
+ case 0x1fc: /* frndint */
+ frndint(PST(0),&tmp);
+ real_to_real(&tmp,&ST(0));
+ return(0);
+ case 0x1fd: /* fscale */
/* incomplete and totally inadequate -wfj */
Fscale(PST(0), PST(1), &tmp);
real_to_real(&tmp,&ST(0));
return(0); /* 19 Sep 92*/
/* incomplete and totally inadequate -wfj */
Fscale(PST(0), PST(1), &tmp);
real_to_real(&tmp,&ST(0));
return(0); /* 19 Sep 92*/
- case 0x1fc:
- frndint(PST(0),&tmp);
- real_to_real(&tmp,&ST(0));
- return(0);
- case 0x2e9:
+ case 0x2e9: /* ????? */
+/* if this should be a fucomp ST(0),ST(1) , it must be a 0x3e9 ATS */
fucom(PST(1),PST(0));
fpop(); fpop();
return(0);
fucom(PST(1),PST(0));
fpop(); fpop();
return(0);
- case 0x3d0: case 0x3d1:
+ case 0x3d0: case 0x3d1: /* fist ?? */
+ case 0x3e2: /* fclex */
I387.swd &= 0x7f00;
return(0);
I387.swd &= 0x7f00;
return(0);
+ case 0x3e3: /* fninit */
I387.cwd = 0x037f;
I387.swd = 0x0000;
I387.twd = 0x0000;
return(0);
case 0x3e4:
return(0);
I387.cwd = 0x037f;
I387.swd = 0x0000;
I387.twd = 0x0000;
return(0);
case 0x3e4:
return(0);
+ case 0x6d9: /* fcompp */
fcom(PST(1),PST(0));
fpop(); fpop();
return(0);
fcom(PST(1),PST(0));
fpop(); fpop();
return(0);
+ case 0x7e0: /* fstsw ax */
*(short *) &info->tf_eax = I387.swd;
return(0);
}
switch (code >> 3) {
*(short *) &info->tf_eax = I387.swd;
return(0);
}
switch (code >> 3) {
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fmul(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fmul(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fcom(PST(code & 7),PST(0));
return(0);
fcom(PST(code & 7),PST(0));
return(0);
fcom(PST(code & 7),PST(0));
fpop();
return(0);
fcom(PST(code & 7),PST(0));
fpop();
return(0);
real_to_real(&ST(code & 7),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(0),&tmp,&tmp);
real_to_real(&tmp,&ST(0));
return(0);
real_to_real(&ST(code & 7),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(0),&tmp,&tmp);
real_to_real(&tmp,&ST(0));
return(0);
ST(0).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
ST(0).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(0));
return(0);
- ST(0) = ST((code & 7)+1);
+ ST(0) = ST((code & 7)+1); /* why plus 1 ????? ATS */
fxchg(&ST(0),&ST(code & 7));
return(0);
fxchg(&ST(0),&ST(code & 7));
return(0);
+ case 0x3b: /* ??? ??? wrong ???? ATS */
ST(code & 7) = ST(0);
fpop();
return(0);
ST(code & 7) = ST(0);
fpop();
return(0);
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fmul(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fmul(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
+ case 0x9a: /* ???? , my manual don't list a direction bit
+for fcom , ??? ATS */
fcom(PST(code & 7),PST(0));
return(0);
fcom(PST(code & 7),PST(0));
return(0);
+ case 0x9b: /* same as above , ATS */
fcom(PST(code & 7),PST(0));
fpop();
return(0);
fcom(PST(code & 7),PST(0));
fpop();
return(0);
ST(code & 7).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
ST(code & 7).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
real_to_real(&ST(0),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(code & 7),&tmp,&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
real_to_real(&ST(0),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(code & 7),&tmp,&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
return(0);
printf("ffree not implemented\n\r");
math_abort(info,SIGILL);
printf("ffree not implemented\n\r");
math_abort(info,SIGILL);
+ case 0xb9: /* fstp ???? where is the pop ? ATS */
fxchg(&ST(0),&ST(code & 7));
return(0);
fxchg(&ST(0),&ST(code & 7));
return(0);
ST(code & 7) = ST(0);
return(0);
ST(code & 7) = ST(0);
return(0);
+ case 0xbb: /* ????? encoding of fstp to mem ? ATS */
ST(code & 7) = ST(0);
fpop();
return(0);
ST(code & 7) = ST(0);
fpop();
return(0);
fucom(PST(code & 7),PST(0));
return(0);
fucom(PST(code & 7),PST(0));
return(0);
+ case 0xbd: /* fucomp */
fucom(PST(code & 7),PST(0));
fpop();
return(0);
fucom(PST(code & 7),PST(0));
fpop();
return(0);
fadd(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fadd(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fmul(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fmul(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
+ case 0xda: /* ??? encoding of ficom with 16 bit mem ? ATS */
fcom(PST(code & 7),PST(0));
fpop();
return(0);
fcom(PST(code & 7),PST(0));
fpop();
return(0);
+ case 0xdc: /* fsubrp */
ST(code & 7).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
ST(code & 7).exponent ^= 0x8000;
fadd(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
real_to_real(&ST(0),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(code & 7),&tmp,&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
real_to_real(&ST(0),&tmp);
tmp.exponent ^= 0x8000;
fadd(PST(code & 7),&tmp,&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
+ case 0xde: /* fdivrp */
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fdiv(PST(0),PST(code & 7),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
fdiv(PST(code & 7),PST(0),&tmp);
real_to_real(&tmp,&ST(code & 7));
fpop();
return(0);
+ case 0xf8: /* fild 16-bit mem ???? ATS */
printf("ffree not implemented\n\r");
math_abort(info,SIGILL);
fpop();
return(0);
printf("ffree not implemented\n\r");
math_abort(info,SIGILL);
fpop();
return(0);
+ case 0xf9: /* ????? ATS */
fxchg(&ST(0),&ST(code & 7));
return(0);
fxchg(&ST(0),&ST(code & 7));
return(0);
- case 0xfa:
- case 0xfb:
+ case 0xfa: /* fist 16-bit mem ? ATS */
+ case 0xfb: /* fistp 16-bit mem ? ATS */
ST(code & 7) = ST(0);
fpop();
return(0);
ST(code & 7) = ST(0);
fpop();
return(0);