errors.c 18 KB

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