errors.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739
  1. /*---------------------------------------------------------------------------+
  2. | errors.c |
  3. | |
  4. | The error handling functions for wm-FPU-emu |
  5. | |
  6. | Copyright (C) 1992,1993,1994,1996 |
  7. | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
  8. | E-mail billm@jacobi.maths.monash.edu.au |
  9. | |
  10. | |
  11. +---------------------------------------------------------------------------*/
  12. /*---------------------------------------------------------------------------+
  13. | Note: |
  14. | The file contains code which accesses user memory. |
  15. | Emulator static data may change when user memory is accessed, due to |
  16. | other processes using the emulator while swapping is in progress. |
  17. +---------------------------------------------------------------------------*/
  18. #include <linux/signal.h>
  19. #include <asm/uaccess.h>
  20. #include "fpu_emu.h"
  21. #include "fpu_system.h"
  22. #include "exception.h"
  23. #include "status_w.h"
  24. #include "control_w.h"
  25. #include "reg_constant.h"
  26. #include "version.h"
  27. /* */
  28. #undef PRINT_MESSAGES
  29. /* */
  30. #if 0
  31. void Un_impl(void)
  32. {
  33. u_char byte1, FPU_modrm;
  34. unsigned long address = FPU_ORIG_EIP;
  35. RE_ENTRANT_CHECK_OFF;
  36. /* No need to check access_ok(), we have previously fetched these bytes. */
  37. printk("Unimplemented FPU Opcode at eip=%p : ", (void __user *) address);
  38. if ( FPU_CS == __USER_CS )
  39. {
  40. while ( 1 )
  41. {
  42. FPU_get_user(byte1, (u_char __user *) address);
  43. if ( (byte1 & 0xf8) == 0xd8 ) break;
  44. printk("[%02x]", byte1);
  45. address++;
  46. }
  47. printk("%02x ", byte1);
  48. FPU_get_user(FPU_modrm, 1 + (u_char __user *) address);
  49. if (FPU_modrm >= 0300)
  50. printk("%02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
  51. else
  52. printk("/%d\n", (FPU_modrm >> 3) & 7);
  53. }
  54. else
  55. {
  56. printk("cs selector = %04x\n", FPU_CS);
  57. }
  58. RE_ENTRANT_CHECK_ON;
  59. EXCEPTION(EX_Invalid);
  60. }
  61. #endif /* 0 */
  62. /*
  63. Called for opcodes which are illegal and which are known to result in a
  64. SIGILL with a real 80486.
  65. */
  66. void FPU_illegal(void)
  67. {
  68. math_abort(FPU_info,SIGILL);
  69. }
  70. void FPU_printall(void)
  71. {
  72. int i;
  73. static const char *tag_desc[] = { "Valid", "Zero", "ERROR", "Empty",
  74. "DeNorm", "Inf", "NaN" };
  75. u_char byte1, FPU_modrm;
  76. unsigned long address = FPU_ORIG_EIP;
  77. RE_ENTRANT_CHECK_OFF;
  78. /* No need to check access_ok(), we have previously fetched these bytes. */
  79. printk("At %p:", (void *) address);
  80. if ( FPU_CS == __USER_CS )
  81. {
  82. #define MAX_PRINTED_BYTES 20
  83. for ( i = 0; i < MAX_PRINTED_BYTES; i++ )
  84. {
  85. FPU_get_user(byte1, (u_char __user *) address);
  86. if ( (byte1 & 0xf8) == 0xd8 )
  87. {
  88. printk(" %02x", byte1);
  89. break;
  90. }
  91. printk(" [%02x]", byte1);
  92. address++;
  93. }
  94. if ( i == MAX_PRINTED_BYTES )
  95. printk(" [more..]\n");
  96. else
  97. {
  98. FPU_get_user(FPU_modrm, 1 + (u_char __user *) address);
  99. if (FPU_modrm >= 0300)
  100. printk(" %02x (%02x+%d)\n", FPU_modrm, FPU_modrm & 0xf8, FPU_modrm & 7);
  101. else
  102. printk(" /%d, mod=%d rm=%d\n",
  103. (FPU_modrm >> 3) & 7, (FPU_modrm >> 6) & 3, FPU_modrm & 7);
  104. }
  105. }
  106. else
  107. {
  108. printk("%04x\n", FPU_CS);
  109. }
  110. partial_status = status_word();
  111. #ifdef DEBUGGING
  112. if ( partial_status & SW_Backward ) printk("SW: backward compatibility\n");
  113. if ( partial_status & SW_C3 ) printk("SW: condition bit 3\n");
  114. if ( partial_status & SW_C2 ) printk("SW: condition bit 2\n");
  115. if ( partial_status & SW_C1 ) printk("SW: condition bit 1\n");
  116. if ( partial_status & SW_C0 ) printk("SW: condition bit 0\n");
  117. if ( partial_status & SW_Summary ) printk("SW: exception summary\n");
  118. if ( partial_status & SW_Stack_Fault ) printk("SW: stack fault\n");
  119. if ( partial_status & SW_Precision ) printk("SW: loss of precision\n");
  120. if ( partial_status & SW_Underflow ) printk("SW: underflow\n");
  121. if ( partial_status & SW_Overflow ) printk("SW: overflow\n");
  122. if ( partial_status & SW_Zero_Div ) printk("SW: divide by zero\n");
  123. if ( partial_status & SW_Denorm_Op ) printk("SW: denormalized operand\n");
  124. if ( partial_status & SW_Invalid ) printk("SW: invalid operation\n");
  125. #endif /* DEBUGGING */
  126. printk(" SW: b=%d st=%ld es=%d sf=%d cc=%d%d%d%d ef=%d%d%d%d%d%d\n",
  127. partial_status & 0x8000 ? 1 : 0, /* busy */
  128. (partial_status & 0x3800) >> 11, /* stack top pointer */
  129. partial_status & 0x80 ? 1 : 0, /* Error summary status */
  130. partial_status & 0x40 ? 1 : 0, /* Stack flag */
  131. partial_status & SW_C3?1:0, partial_status & SW_C2?1:0, /* cc */
  132. partial_status & SW_C1?1:0, partial_status & SW_C0?1:0, /* cc */
  133. partial_status & SW_Precision?1:0, partial_status & SW_Underflow?1:0,
  134. partial_status & SW_Overflow?1:0, partial_status & SW_Zero_Div?1:0,
  135. partial_status & SW_Denorm_Op?1:0, partial_status & SW_Invalid?1:0);
  136. printk(" CW: ic=%d rc=%ld%ld pc=%ld%ld iem=%d ef=%d%d%d%d%d%d\n",
  137. control_word & 0x1000 ? 1 : 0,
  138. (control_word & 0x800) >> 11, (control_word & 0x400) >> 10,
  139. (control_word & 0x200) >> 9, (control_word & 0x100) >> 8,
  140. control_word & 0x80 ? 1 : 0,
  141. control_word & SW_Precision?1:0, control_word & SW_Underflow?1:0,
  142. control_word & SW_Overflow?1:0, control_word & SW_Zero_Div?1:0,
  143. control_word & SW_Denorm_Op?1:0, control_word & SW_Invalid?1:0);
  144. for ( i = 0; i < 8; i++ )
  145. {
  146. FPU_REG *r = &st(i);
  147. u_char tagi = FPU_gettagi(i);
  148. switch (tagi)
  149. {
  150. case TAG_Empty:
  151. continue;
  152. break;
  153. case TAG_Zero:
  154. case TAG_Special:
  155. tagi = FPU_Special(r);
  156. case TAG_Valid:
  157. printk("st(%d) %c .%04lx %04lx %04lx %04lx e%+-6d ", i,
  158. getsign(r) ? '-' : '+',
  159. (long)(r->sigh >> 16),
  160. (long)(r->sigh & 0xFFFF),
  161. (long)(r->sigl >> 16),
  162. (long)(r->sigl & 0xFFFF),
  163. exponent(r) - EXP_BIAS + 1);
  164. break;
  165. default:
  166. printk("Whoops! Error in errors.c: tag%d is %d ", i, tagi);
  167. continue;
  168. break;
  169. }
  170. printk("%s\n", tag_desc[(int) (unsigned) tagi]);
  171. }
  172. RE_ENTRANT_CHECK_ON;
  173. }
  174. static struct {
  175. int type;
  176. const char *name;
  177. } exception_names[] = {
  178. { EX_StackOver, "stack overflow" },
  179. { EX_StackUnder, "stack underflow" },
  180. { EX_Precision, "loss of precision" },
  181. { EX_Underflow, "underflow" },
  182. { EX_Overflow, "overflow" },
  183. { EX_ZeroDiv, "divide by zero" },
  184. { EX_Denormal, "denormalized operand" },
  185. { EX_Invalid, "invalid operation" },
  186. { EX_INTERNAL, "INTERNAL BUG in "FPU_VERSION },
  187. { 0, NULL }
  188. };
  189. /*
  190. EX_INTERNAL is always given with a code which indicates where the
  191. error was detected.
  192. Internal error types:
  193. 0x14 in fpu_etc.c
  194. 0x1nn in a *.c file:
  195. 0x101 in reg_add_sub.c
  196. 0x102 in reg_mul.c
  197. 0x104 in poly_atan.c
  198. 0x105 in reg_mul.c
  199. 0x107 in fpu_trig.c
  200. 0x108 in reg_compare.c
  201. 0x109 in reg_compare.c
  202. 0x110 in reg_add_sub.c
  203. 0x111 in fpe_entry.c
  204. 0x112 in fpu_trig.c
  205. 0x113 in errors.c
  206. 0x115 in fpu_trig.c
  207. 0x116 in fpu_trig.c
  208. 0x117 in fpu_trig.c
  209. 0x118 in fpu_trig.c
  210. 0x119 in fpu_trig.c
  211. 0x120 in poly_atan.c
  212. 0x121 in reg_compare.c
  213. 0x122 in reg_compare.c
  214. 0x123 in reg_compare.c
  215. 0x125 in fpu_trig.c
  216. 0x126 in fpu_entry.c
  217. 0x127 in poly_2xm1.c
  218. 0x128 in fpu_entry.c
  219. 0x129 in fpu_entry.c
  220. 0x130 in get_address.c
  221. 0x131 in get_address.c
  222. 0x132 in get_address.c
  223. 0x133 in get_address.c
  224. 0x140 in load_store.c
  225. 0x141 in load_store.c
  226. 0x150 in poly_sin.c
  227. 0x151 in poly_sin.c
  228. 0x160 in reg_ld_str.c
  229. 0x161 in reg_ld_str.c
  230. 0x162 in reg_ld_str.c
  231. 0x163 in reg_ld_str.c
  232. 0x164 in reg_ld_str.c
  233. 0x170 in fpu_tags.c
  234. 0x171 in fpu_tags.c
  235. 0x172 in fpu_tags.c
  236. 0x180 in reg_convert.c
  237. 0x2nn in an *.S file:
  238. 0x201 in reg_u_add.S
  239. 0x202 in reg_u_div.S
  240. 0x203 in reg_u_div.S
  241. 0x204 in reg_u_div.S
  242. 0x205 in reg_u_mul.S
  243. 0x206 in reg_u_sub.S
  244. 0x207 in wm_sqrt.S
  245. 0x208 in reg_div.S
  246. 0x209 in reg_u_sub.S
  247. 0x210 in reg_u_sub.S
  248. 0x211 in reg_u_sub.S
  249. 0x212 in reg_u_sub.S
  250. 0x213 in wm_sqrt.S
  251. 0x214 in wm_sqrt.S
  252. 0x215 in wm_sqrt.S
  253. 0x220 in reg_norm.S
  254. 0x221 in reg_norm.S
  255. 0x230 in reg_round.S
  256. 0x231 in reg_round.S
  257. 0x232 in reg_round.S
  258. 0x233 in reg_round.S
  259. 0x234 in reg_round.S
  260. 0x235 in reg_round.S
  261. 0x236 in reg_round.S
  262. 0x240 in div_Xsig.S
  263. 0x241 in div_Xsig.S
  264. 0x242 in div_Xsig.S
  265. */
  266. asmlinkage void FPU_exception(int n)
  267. {
  268. int i, int_type;
  269. int_type = 0; /* Needed only to stop compiler warnings */
  270. if ( n & EX_INTERNAL )
  271. {
  272. int_type = n - EX_INTERNAL;
  273. n = EX_INTERNAL;
  274. /* Set lots of exception bits! */
  275. partial_status |= (SW_Exc_Mask | SW_Summary | SW_Backward);
  276. }
  277. else
  278. {
  279. /* Extract only the bits which we use to set the status word */
  280. n &= (SW_Exc_Mask);
  281. /* Set the corresponding exception bit */
  282. partial_status |= n;
  283. /* Set summary bits iff exception isn't masked */
  284. if ( partial_status & ~control_word & CW_Exceptions )
  285. partial_status |= (SW_Summary | SW_Backward);
  286. if ( n & (SW_Stack_Fault | EX_Precision) )
  287. {
  288. if ( !(n & SW_C1) )
  289. /* This bit distinguishes over- from underflow for a stack fault,
  290. and roundup from round-down for precision loss. */
  291. partial_status &= ~SW_C1;
  292. }
  293. }
  294. RE_ENTRANT_CHECK_OFF;
  295. if ( (~control_word & n & CW_Exceptions) || (n == EX_INTERNAL) )
  296. {
  297. #ifdef PRINT_MESSAGES
  298. /* My message from the sponsor */
  299. printk(FPU_VERSION" "__DATE__" (C) W. Metzenthen.\n");
  300. #endif /* PRINT_MESSAGES */
  301. /* Get a name string for error reporting */
  302. for (i=0; exception_names[i].type; i++)
  303. if ( (exception_names[i].type & n) == exception_names[i].type )
  304. break;
  305. if (exception_names[i].type)
  306. {
  307. #ifdef PRINT_MESSAGES
  308. printk("FP Exception: %s!\n", exception_names[i].name);
  309. #endif /* PRINT_MESSAGES */
  310. }
  311. else
  312. printk("FPU emulator: Unknown Exception: 0x%04x!\n", n);
  313. if ( n == EX_INTERNAL )
  314. {
  315. printk("FPU emulator: Internal error type 0x%04x\n", int_type);
  316. FPU_printall();
  317. }
  318. #ifdef PRINT_MESSAGES
  319. else
  320. FPU_printall();
  321. #endif /* PRINT_MESSAGES */
  322. /*
  323. * The 80486 generates an interrupt on the next non-control FPU
  324. * instruction. So we need some means of flagging it.
  325. * We use the ES (Error Summary) bit for this.
  326. */
  327. }
  328. RE_ENTRANT_CHECK_ON;
  329. #ifdef __DEBUG__
  330. math_abort(FPU_info,SIGFPE);
  331. #endif /* __DEBUG__ */
  332. }
  333. /* Real operation attempted on a NaN. */
  334. /* Returns < 0 if the exception is unmasked */
  335. int real_1op_NaN(FPU_REG *a)
  336. {
  337. int signalling, isNaN;
  338. isNaN = (exponent(a) == EXP_OVER) && (a->sigh & 0x80000000);
  339. /* The default result for the case of two "equal" NaNs (signs may
  340. differ) is chosen to reproduce 80486 behaviour */
  341. signalling = isNaN && !(a->sigh & 0x40000000);
  342. if ( !signalling )
  343. {
  344. if ( !isNaN ) /* pseudo-NaN, or other unsupported? */
  345. {
  346. if ( control_word & CW_Invalid )
  347. {
  348. /* Masked response */
  349. reg_copy(&CONST_QNaN, a);
  350. }
  351. EXCEPTION(EX_Invalid);
  352. return (!(control_word & CW_Invalid) ? FPU_Exception : 0) | TAG_Special;
  353. }
  354. return TAG_Special;
  355. }
  356. if ( control_word & CW_Invalid )
  357. {
  358. /* The masked response */
  359. if ( !(a->sigh & 0x80000000) ) /* pseudo-NaN ? */
  360. {
  361. reg_copy(&CONST_QNaN, a);
  362. }
  363. /* ensure a Quiet NaN */
  364. a->sigh |= 0x40000000;
  365. }
  366. EXCEPTION(EX_Invalid);
  367. return (!(control_word & CW_Invalid) ? FPU_Exception : 0) | TAG_Special;
  368. }
  369. /* Real operation attempted on two operands, one a NaN. */
  370. /* Returns < 0 if the exception is unmasked */
  371. int real_2op_NaN(FPU_REG const *b, u_char tagb,
  372. int deststnr,
  373. FPU_REG const *defaultNaN)
  374. {
  375. FPU_REG *dest = &st(deststnr);
  376. FPU_REG const *a = dest;
  377. u_char taga = FPU_gettagi(deststnr);
  378. FPU_REG const *x;
  379. int signalling, unsupported;
  380. if ( taga == TAG_Special )
  381. taga = FPU_Special(a);
  382. if ( tagb == TAG_Special )
  383. tagb = FPU_Special(b);
  384. /* TW_NaN is also used for unsupported data types. */
  385. unsupported = ((taga == TW_NaN)
  386. && !((exponent(a) == EXP_OVER) && (a->sigh & 0x80000000)))
  387. || ((tagb == TW_NaN)
  388. && !((exponent(b) == EXP_OVER) && (b->sigh & 0x80000000)));
  389. if ( unsupported )
  390. {
  391. if ( control_word & CW_Invalid )
  392. {
  393. /* Masked response */
  394. FPU_copy_to_regi(&CONST_QNaN, TAG_Special, deststnr);
  395. }
  396. EXCEPTION(EX_Invalid);
  397. return (!(control_word & CW_Invalid) ? FPU_Exception : 0) | TAG_Special;
  398. }
  399. if (taga == TW_NaN)
  400. {
  401. x = a;
  402. if (tagb == TW_NaN)
  403. {
  404. signalling = !(a->sigh & b->sigh & 0x40000000);
  405. if ( significand(b) > significand(a) )
  406. x = b;
  407. else if ( significand(b) == significand(a) )
  408. {
  409. /* The default result for the case of two "equal" NaNs (signs may
  410. differ) is chosen to reproduce 80486 behaviour */
  411. x = defaultNaN;
  412. }
  413. }
  414. else
  415. {
  416. /* return the quiet version of the NaN in a */
  417. signalling = !(a->sigh & 0x40000000);
  418. }
  419. }
  420. else
  421. #ifdef PARANOID
  422. if (tagb == TW_NaN)
  423. #endif /* PARANOID */
  424. {
  425. signalling = !(b->sigh & 0x40000000);
  426. x = b;
  427. }
  428. #ifdef PARANOID
  429. else
  430. {
  431. signalling = 0;
  432. EXCEPTION(EX_INTERNAL|0x113);
  433. x = &CONST_QNaN;
  434. }
  435. #endif /* PARANOID */
  436. if ( (!signalling) || (control_word & CW_Invalid) )
  437. {
  438. if ( ! x )
  439. x = b;
  440. if ( !(x->sigh & 0x80000000) ) /* pseudo-NaN ? */
  441. x = &CONST_QNaN;
  442. FPU_copy_to_regi(x, TAG_Special, deststnr);
  443. if ( !signalling )
  444. return TAG_Special;
  445. /* ensure a Quiet NaN */
  446. dest->sigh |= 0x40000000;
  447. }
  448. EXCEPTION(EX_Invalid);
  449. return (!(control_word & CW_Invalid) ? FPU_Exception : 0) | TAG_Special;
  450. }
  451. /* Invalid arith operation on Valid registers */
  452. /* Returns < 0 if the exception is unmasked */
  453. asmlinkage int arith_invalid(int deststnr)
  454. {
  455. EXCEPTION(EX_Invalid);
  456. if ( control_word & CW_Invalid )
  457. {
  458. /* The masked response */
  459. FPU_copy_to_regi(&CONST_QNaN, TAG_Special, deststnr);
  460. }
  461. return (!(control_word & CW_Invalid) ? FPU_Exception : 0) | TAG_Valid;
  462. }
  463. /* Divide a finite number by zero */
  464. asmlinkage int FPU_divide_by_zero(int deststnr, u_char sign)
  465. {
  466. FPU_REG *dest = &st(deststnr);
  467. int tag = TAG_Valid;
  468. if ( control_word & CW_ZeroDiv )
  469. {
  470. /* The masked response */
  471. FPU_copy_to_regi(&CONST_INF, TAG_Special, deststnr);
  472. setsign(dest, sign);
  473. tag = TAG_Special;
  474. }
  475. EXCEPTION(EX_ZeroDiv);
  476. return (!(control_word & CW_ZeroDiv) ? FPU_Exception : 0) | tag;
  477. }
  478. /* This may be called often, so keep it lean */
  479. int set_precision_flag(int flags)
  480. {
  481. if ( control_word & CW_Precision )
  482. {
  483. partial_status &= ~(SW_C1 & flags);
  484. partial_status |= flags; /* The masked response */
  485. return 0;
  486. }
  487. else
  488. {
  489. EXCEPTION(flags);
  490. return 1;
  491. }
  492. }
  493. /* This may be called often, so keep it lean */
  494. asmlinkage void set_precision_flag_up(void)
  495. {
  496. if ( control_word & CW_Precision )
  497. partial_status |= (SW_Precision | SW_C1); /* The masked response */
  498. else
  499. EXCEPTION(EX_Precision | SW_C1);
  500. }
  501. /* This may be called often, so keep it lean */
  502. asmlinkage void set_precision_flag_down(void)
  503. {
  504. if ( control_word & CW_Precision )
  505. { /* The masked response */
  506. partial_status &= ~SW_C1;
  507. partial_status |= SW_Precision;
  508. }
  509. else
  510. EXCEPTION(EX_Precision);
  511. }
  512. asmlinkage int denormal_operand(void)
  513. {
  514. if ( control_word & CW_Denormal )
  515. { /* The masked response */
  516. partial_status |= SW_Denorm_Op;
  517. return TAG_Special;
  518. }
  519. else
  520. {
  521. EXCEPTION(EX_Denormal);
  522. return TAG_Special | FPU_Exception;
  523. }
  524. }
  525. asmlinkage int arith_overflow(FPU_REG *dest)
  526. {
  527. int tag = TAG_Valid;
  528. if ( control_word & CW_Overflow )
  529. {
  530. /* The masked response */
  531. /* ###### The response here depends upon the rounding mode */
  532. reg_copy(&CONST_INF, dest);
  533. tag = TAG_Special;
  534. }
  535. else
  536. {
  537. /* Subtract the magic number from the exponent */
  538. addexponent(dest, (-3 * (1 << 13)));
  539. }
  540. EXCEPTION(EX_Overflow);
  541. if ( control_word & CW_Overflow )
  542. {
  543. /* The overflow exception is masked. */
  544. /* By definition, precision is lost.
  545. The roundup bit (C1) is also set because we have
  546. "rounded" upwards to Infinity. */
  547. EXCEPTION(EX_Precision | SW_C1);
  548. return tag;
  549. }
  550. return tag;
  551. }
  552. asmlinkage int arith_underflow(FPU_REG *dest)
  553. {
  554. int tag = TAG_Valid;
  555. if ( control_word & CW_Underflow )
  556. {
  557. /* The masked response */
  558. if ( exponent16(dest) <= EXP_UNDER - 63 )
  559. {
  560. reg_copy(&CONST_Z, dest);
  561. partial_status &= ~SW_C1; /* Round down. */
  562. tag = TAG_Zero;
  563. }
  564. else
  565. {
  566. stdexp(dest);
  567. }
  568. }
  569. else
  570. {
  571. /* Add the magic number to the exponent. */
  572. addexponent(dest, (3 * (1 << 13)) + EXTENDED_Ebias);
  573. }
  574. EXCEPTION(EX_Underflow);
  575. if ( control_word & CW_Underflow )
  576. {
  577. /* The underflow exception is masked. */
  578. EXCEPTION(EX_Precision);
  579. return tag;
  580. }
  581. return tag;
  582. }
  583. void FPU_stack_overflow(void)
  584. {
  585. if ( control_word & CW_Invalid )
  586. {
  587. /* The masked response */
  588. top--;
  589. FPU_copy_to_reg0(&CONST_QNaN, TAG_Special);
  590. }
  591. EXCEPTION(EX_StackOver);
  592. return;
  593. }
  594. void FPU_stack_underflow(void)
  595. {
  596. if ( control_word & CW_Invalid )
  597. {
  598. /* The masked response */
  599. FPU_copy_to_reg0(&CONST_QNaN, TAG_Special);
  600. }
  601. EXCEPTION(EX_StackUnder);
  602. return;
  603. }
  604. void FPU_stack_underflow_i(int i)
  605. {
  606. if ( control_word & CW_Invalid )
  607. {
  608. /* The masked response */
  609. FPU_copy_to_regi(&CONST_QNaN, TAG_Special, i);
  610. }
  611. EXCEPTION(EX_StackUnder);
  612. return;
  613. }
  614. void FPU_stack_underflow_pop(int i)
  615. {
  616. if ( control_word & CW_Invalid )
  617. {
  618. /* The masked response */
  619. FPU_copy_to_regi(&CONST_QNaN, TAG_Special, i);
  620. FPU_pop();
  621. }
  622. EXCEPTION(EX_StackUnder);
  623. return;
  624. }