reg_ld_str.c 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375
  1. /*---------------------------------------------------------------------------+
  2. | reg_ld_str.c |
  3. | |
  4. | All of the functions which transfer data between user memory and FPU_REGs.|
  5. | |
  6. | Copyright (C) 1992,1993,1994,1996,1997 |
  7. | W. Metzenthen, 22 Parker St, Ormond, Vic 3163, Australia |
  8. | E-mail billm@suburbia.net |
  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 "fpu_emu.h"
  19. #include <asm/uaccess.h>
  20. #include "fpu_system.h"
  21. #include "exception.h"
  22. #include "reg_constant.h"
  23. #include "control_w.h"
  24. #include "status_w.h"
  25. #define DOUBLE_Emax 1023 /* largest valid exponent */
  26. #define DOUBLE_Ebias 1023
  27. #define DOUBLE_Emin (-1022) /* smallest valid exponent */
  28. #define SINGLE_Emax 127 /* largest valid exponent */
  29. #define SINGLE_Ebias 127
  30. #define SINGLE_Emin (-126) /* smallest valid exponent */
  31. static u_char normalize_no_excep(FPU_REG *r, int exp, int sign)
  32. {
  33. u_char tag;
  34. setexponent16(r, exp);
  35. tag = FPU_normalize_nuo(r);
  36. stdexp(r);
  37. if ( sign )
  38. setnegative(r);
  39. return tag;
  40. }
  41. int FPU_tagof(FPU_REG *ptr)
  42. {
  43. int exp;
  44. exp = exponent16(ptr) & 0x7fff;
  45. if ( exp == 0 )
  46. {
  47. if ( !(ptr->sigh | ptr->sigl) )
  48. {
  49. return TAG_Zero;
  50. }
  51. /* The number is a de-normal or pseudodenormal. */
  52. return TAG_Special;
  53. }
  54. if ( exp == 0x7fff )
  55. {
  56. /* Is an Infinity, a NaN, or an unsupported data type. */
  57. return TAG_Special;
  58. }
  59. if ( !(ptr->sigh & 0x80000000) )
  60. {
  61. /* Unsupported data type. */
  62. /* Valid numbers have the ms bit set to 1. */
  63. /* Unnormal. */
  64. return TAG_Special;
  65. }
  66. return TAG_Valid;
  67. }
  68. /* Get a long double from user memory */
  69. int FPU_load_extended(long double __user *s, int stnr)
  70. {
  71. FPU_REG *sti_ptr = &st(stnr);
  72. RE_ENTRANT_CHECK_OFF;
  73. FPU_access_ok(VERIFY_READ, s, 10);
  74. __copy_from_user(sti_ptr, s, 10);
  75. RE_ENTRANT_CHECK_ON;
  76. return FPU_tagof(sti_ptr);
  77. }
  78. /* Get a double from user memory */
  79. int FPU_load_double(double __user *dfloat, FPU_REG *loaded_data)
  80. {
  81. int exp, tag, negative;
  82. unsigned m64, l64;
  83. RE_ENTRANT_CHECK_OFF;
  84. FPU_access_ok(VERIFY_READ, dfloat, 8);
  85. FPU_get_user(m64, 1 + (unsigned long __user *) dfloat);
  86. FPU_get_user(l64, (unsigned long __user *) dfloat);
  87. RE_ENTRANT_CHECK_ON;
  88. negative = (m64 & 0x80000000) ? SIGN_Negative : SIGN_Positive;
  89. exp = ((m64 & 0x7ff00000) >> 20) - DOUBLE_Ebias + EXTENDED_Ebias;
  90. m64 &= 0xfffff;
  91. if ( exp > DOUBLE_Emax + EXTENDED_Ebias )
  92. {
  93. /* Infinity or NaN */
  94. if ((m64 == 0) && (l64 == 0))
  95. {
  96. /* +- infinity */
  97. loaded_data->sigh = 0x80000000;
  98. loaded_data->sigl = 0x00000000;
  99. exp = EXP_Infinity + EXTENDED_Ebias;
  100. tag = TAG_Special;
  101. }
  102. else
  103. {
  104. /* Must be a signaling or quiet NaN */
  105. exp = EXP_NaN + EXTENDED_Ebias;
  106. loaded_data->sigh = (m64 << 11) | 0x80000000;
  107. loaded_data->sigh |= l64 >> 21;
  108. loaded_data->sigl = l64 << 11;
  109. tag = TAG_Special; /* The calling function must look for NaNs */
  110. }
  111. }
  112. else if ( exp < DOUBLE_Emin + EXTENDED_Ebias )
  113. {
  114. /* Zero or de-normal */
  115. if ((m64 == 0) && (l64 == 0))
  116. {
  117. /* Zero */
  118. reg_copy(&CONST_Z, loaded_data);
  119. exp = 0;
  120. tag = TAG_Zero;
  121. }
  122. else
  123. {
  124. /* De-normal */
  125. loaded_data->sigh = m64 << 11;
  126. loaded_data->sigh |= l64 >> 21;
  127. loaded_data->sigl = l64 << 11;
  128. return normalize_no_excep(loaded_data, DOUBLE_Emin, negative)
  129. | (denormal_operand() < 0 ? FPU_Exception : 0);
  130. }
  131. }
  132. else
  133. {
  134. loaded_data->sigh = (m64 << 11) | 0x80000000;
  135. loaded_data->sigh |= l64 >> 21;
  136. loaded_data->sigl = l64 << 11;
  137. tag = TAG_Valid;
  138. }
  139. setexponent16(loaded_data, exp | negative);
  140. return tag;
  141. }
  142. /* Get a float from user memory */
  143. int FPU_load_single(float __user *single, FPU_REG *loaded_data)
  144. {
  145. unsigned m32;
  146. int exp, tag, negative;
  147. RE_ENTRANT_CHECK_OFF;
  148. FPU_access_ok(VERIFY_READ, single, 4);
  149. FPU_get_user(m32, (unsigned long __user *) single);
  150. RE_ENTRANT_CHECK_ON;
  151. negative = (m32 & 0x80000000) ? SIGN_Negative : SIGN_Positive;
  152. if (!(m32 & 0x7fffffff))
  153. {
  154. /* Zero */
  155. reg_copy(&CONST_Z, loaded_data);
  156. addexponent(loaded_data, negative);
  157. return TAG_Zero;
  158. }
  159. exp = ((m32 & 0x7f800000) >> 23) - SINGLE_Ebias + EXTENDED_Ebias;
  160. m32 = (m32 & 0x7fffff) << 8;
  161. if ( exp < SINGLE_Emin + EXTENDED_Ebias )
  162. {
  163. /* De-normals */
  164. loaded_data->sigh = m32;
  165. loaded_data->sigl = 0;
  166. return normalize_no_excep(loaded_data, SINGLE_Emin, negative)
  167. | (denormal_operand() < 0 ? FPU_Exception : 0);
  168. }
  169. else if ( exp > SINGLE_Emax + EXTENDED_Ebias )
  170. {
  171. /* Infinity or NaN */
  172. if ( m32 == 0 )
  173. {
  174. /* +- infinity */
  175. loaded_data->sigh = 0x80000000;
  176. loaded_data->sigl = 0x00000000;
  177. exp = EXP_Infinity + EXTENDED_Ebias;
  178. tag = TAG_Special;
  179. }
  180. else
  181. {
  182. /* Must be a signaling or quiet NaN */
  183. exp = EXP_NaN + EXTENDED_Ebias;
  184. loaded_data->sigh = m32 | 0x80000000;
  185. loaded_data->sigl = 0;
  186. tag = TAG_Special; /* The calling function must look for NaNs */
  187. }
  188. }
  189. else
  190. {
  191. loaded_data->sigh = m32 | 0x80000000;
  192. loaded_data->sigl = 0;
  193. tag = TAG_Valid;
  194. }
  195. setexponent16(loaded_data, exp | negative); /* Set the sign. */
  196. return tag;
  197. }
  198. /* Get a long long from user memory */
  199. int FPU_load_int64(long long __user *_s)
  200. {
  201. long long s;
  202. int sign;
  203. FPU_REG *st0_ptr = &st(0);
  204. RE_ENTRANT_CHECK_OFF;
  205. FPU_access_ok(VERIFY_READ, _s, 8);
  206. if (copy_from_user(&s,_s,8))
  207. FPU_abort;
  208. RE_ENTRANT_CHECK_ON;
  209. if (s == 0)
  210. {
  211. reg_copy(&CONST_Z, st0_ptr);
  212. return TAG_Zero;
  213. }
  214. if (s > 0)
  215. sign = SIGN_Positive;
  216. else
  217. {
  218. s = -s;
  219. sign = SIGN_Negative;
  220. }
  221. significand(st0_ptr) = s;
  222. return normalize_no_excep(st0_ptr, 63, sign);
  223. }
  224. /* Get a long from user memory */
  225. int FPU_load_int32(long __user *_s, FPU_REG *loaded_data)
  226. {
  227. long s;
  228. int negative;
  229. RE_ENTRANT_CHECK_OFF;
  230. FPU_access_ok(VERIFY_READ, _s, 4);
  231. FPU_get_user(s, _s);
  232. RE_ENTRANT_CHECK_ON;
  233. if (s == 0)
  234. { reg_copy(&CONST_Z, loaded_data); return TAG_Zero; }
  235. if (s > 0)
  236. negative = SIGN_Positive;
  237. else
  238. {
  239. s = -s;
  240. negative = SIGN_Negative;
  241. }
  242. loaded_data->sigh = s;
  243. loaded_data->sigl = 0;
  244. return normalize_no_excep(loaded_data, 31, negative);
  245. }
  246. /* Get a short from user memory */
  247. int FPU_load_int16(short __user *_s, FPU_REG *loaded_data)
  248. {
  249. int s, negative;
  250. RE_ENTRANT_CHECK_OFF;
  251. FPU_access_ok(VERIFY_READ, _s, 2);
  252. /* Cast as short to get the sign extended. */
  253. FPU_get_user(s, _s);
  254. RE_ENTRANT_CHECK_ON;
  255. if (s == 0)
  256. { reg_copy(&CONST_Z, loaded_data); return TAG_Zero; }
  257. if (s > 0)
  258. negative = SIGN_Positive;
  259. else
  260. {
  261. s = -s;
  262. negative = SIGN_Negative;
  263. }
  264. loaded_data->sigh = s << 16;
  265. loaded_data->sigl = 0;
  266. return normalize_no_excep(loaded_data, 15, negative);
  267. }
  268. /* Get a packed bcd array from user memory */
  269. int FPU_load_bcd(u_char __user *s)
  270. {
  271. FPU_REG *st0_ptr = &st(0);
  272. int pos;
  273. u_char bcd;
  274. long long l=0;
  275. int sign;
  276. RE_ENTRANT_CHECK_OFF;
  277. FPU_access_ok(VERIFY_READ, s, 10);
  278. RE_ENTRANT_CHECK_ON;
  279. for ( pos = 8; pos >= 0; pos--)
  280. {
  281. l *= 10;
  282. RE_ENTRANT_CHECK_OFF;
  283. FPU_get_user(bcd, s+pos);
  284. RE_ENTRANT_CHECK_ON;
  285. l += bcd >> 4;
  286. l *= 10;
  287. l += bcd & 0x0f;
  288. }
  289. RE_ENTRANT_CHECK_OFF;
  290. FPU_get_user(sign, s+9);
  291. sign = sign & 0x80 ? SIGN_Negative : SIGN_Positive;
  292. RE_ENTRANT_CHECK_ON;
  293. if ( l == 0 )
  294. {
  295. reg_copy(&CONST_Z, st0_ptr);
  296. addexponent(st0_ptr, sign); /* Set the sign. */
  297. return TAG_Zero;
  298. }
  299. else
  300. {
  301. significand(st0_ptr) = l;
  302. return normalize_no_excep(st0_ptr, 63, sign);
  303. }
  304. }
  305. /*===========================================================================*/
  306. /* Put a long double into user memory */
  307. int FPU_store_extended(FPU_REG *st0_ptr, u_char st0_tag, long double __user *d)
  308. {
  309. /*
  310. The only exception raised by an attempt to store to an
  311. extended format is the Invalid Stack exception, i.e.
  312. attempting to store from an empty register.
  313. */
  314. if ( st0_tag != TAG_Empty )
  315. {
  316. RE_ENTRANT_CHECK_OFF;
  317. FPU_access_ok(VERIFY_WRITE, d, 10);
  318. FPU_put_user(st0_ptr->sigl, (unsigned long __user *) d);
  319. FPU_put_user(st0_ptr->sigh, (unsigned long __user *) ((u_char __user *)d + 4));
  320. FPU_put_user(exponent16(st0_ptr), (unsigned short __user *) ((u_char __user *)d + 8));
  321. RE_ENTRANT_CHECK_ON;
  322. return 1;
  323. }
  324. /* Empty register (stack underflow) */
  325. EXCEPTION(EX_StackUnder);
  326. if ( control_word & CW_Invalid )
  327. {
  328. /* The masked response */
  329. /* Put out the QNaN indefinite */
  330. RE_ENTRANT_CHECK_OFF;
  331. FPU_access_ok(VERIFY_WRITE,d,10);
  332. FPU_put_user(0, (unsigned long __user *) d);
  333. FPU_put_user(0xc0000000, 1 + (unsigned long __user *) d);
  334. FPU_put_user(0xffff, 4 + (short __user *) d);
  335. RE_ENTRANT_CHECK_ON;
  336. return 1;
  337. }
  338. else
  339. return 0;
  340. }
  341. /* Put a double into user memory */
  342. int FPU_store_double(FPU_REG *st0_ptr, u_char st0_tag, double __user *dfloat)
  343. {
  344. unsigned long l[2];
  345. unsigned long increment = 0; /* avoid gcc warnings */
  346. int precision_loss;
  347. int exp;
  348. FPU_REG tmp;
  349. if ( st0_tag == TAG_Valid )
  350. {
  351. reg_copy(st0_ptr, &tmp);
  352. exp = exponent(&tmp);
  353. if ( exp < DOUBLE_Emin ) /* It may be a denormal */
  354. {
  355. addexponent(&tmp, -DOUBLE_Emin + 52); /* largest exp to be 51 */
  356. denormal_arg:
  357. if ( (precision_loss = FPU_round_to_int(&tmp, st0_tag)) )
  358. {
  359. #ifdef PECULIAR_486
  360. /* Did it round to a non-denormal ? */
  361. /* This behaviour might be regarded as peculiar, it appears
  362. that the 80486 rounds to the dest precision, then
  363. converts to decide underflow. */
  364. if ( !((tmp.sigh == 0x00100000) && (tmp.sigl == 0) &&
  365. (st0_ptr->sigl & 0x000007ff)) )
  366. #endif /* PECULIAR_486 */
  367. {
  368. EXCEPTION(EX_Underflow);
  369. /* This is a special case: see sec 16.2.5.1 of
  370. the 80486 book */
  371. if ( !(control_word & CW_Underflow) )
  372. return 0;
  373. }
  374. EXCEPTION(precision_loss);
  375. if ( !(control_word & CW_Precision) )
  376. return 0;
  377. }
  378. l[0] = tmp.sigl;
  379. l[1] = tmp.sigh;
  380. }
  381. else
  382. {
  383. if ( tmp.sigl & 0x000007ff )
  384. {
  385. precision_loss = 1;
  386. switch (control_word & CW_RC)
  387. {
  388. case RC_RND:
  389. /* Rounding can get a little messy.. */
  390. increment = ((tmp.sigl & 0x7ff) > 0x400) | /* nearest */
  391. ((tmp.sigl & 0xc00) == 0xc00); /* odd -> even */
  392. break;
  393. case RC_DOWN: /* towards -infinity */
  394. increment = signpositive(&tmp) ? 0 : tmp.sigl & 0x7ff;
  395. break;
  396. case RC_UP: /* towards +infinity */
  397. increment = signpositive(&tmp) ? tmp.sigl & 0x7ff : 0;
  398. break;
  399. case RC_CHOP:
  400. increment = 0;
  401. break;
  402. }
  403. /* Truncate the mantissa */
  404. tmp.sigl &= 0xfffff800;
  405. if ( increment )
  406. {
  407. if ( tmp.sigl >= 0xfffff800 )
  408. {
  409. /* the sigl part overflows */
  410. if ( tmp.sigh == 0xffffffff )
  411. {
  412. /* The sigh part overflows */
  413. tmp.sigh = 0x80000000;
  414. exp++;
  415. if (exp >= EXP_OVER)
  416. goto overflow;
  417. }
  418. else
  419. {
  420. tmp.sigh ++;
  421. }
  422. tmp.sigl = 0x00000000;
  423. }
  424. else
  425. {
  426. /* We only need to increment sigl */
  427. tmp.sigl += 0x00000800;
  428. }
  429. }
  430. }
  431. else
  432. precision_loss = 0;
  433. l[0] = (tmp.sigl >> 11) | (tmp.sigh << 21);
  434. l[1] = ((tmp.sigh >> 11) & 0xfffff);
  435. if ( exp > DOUBLE_Emax )
  436. {
  437. overflow:
  438. EXCEPTION(EX_Overflow);
  439. if ( !(control_word & CW_Overflow) )
  440. return 0;
  441. set_precision_flag_up();
  442. if ( !(control_word & CW_Precision) )
  443. return 0;
  444. /* This is a special case: see sec 16.2.5.1 of the 80486 book */
  445. /* Overflow to infinity */
  446. l[0] = 0x00000000; /* Set to */
  447. l[1] = 0x7ff00000; /* + INF */
  448. }
  449. else
  450. {
  451. if ( precision_loss )
  452. {
  453. if ( increment )
  454. set_precision_flag_up();
  455. else
  456. set_precision_flag_down();
  457. }
  458. /* Add the exponent */
  459. l[1] |= (((exp+DOUBLE_Ebias) & 0x7ff) << 20);
  460. }
  461. }
  462. }
  463. else if (st0_tag == TAG_Zero)
  464. {
  465. /* Number is zero */
  466. l[0] = 0;
  467. l[1] = 0;
  468. }
  469. else if ( st0_tag == TAG_Special )
  470. {
  471. st0_tag = FPU_Special(st0_ptr);
  472. if ( st0_tag == TW_Denormal )
  473. {
  474. /* A denormal will always underflow. */
  475. #ifndef PECULIAR_486
  476. /* An 80486 is supposed to be able to generate
  477. a denormal exception here, but... */
  478. /* Underflow has priority. */
  479. if ( control_word & CW_Underflow )
  480. denormal_operand();
  481. #endif /* PECULIAR_486 */
  482. reg_copy(st0_ptr, &tmp);
  483. goto denormal_arg;
  484. }
  485. else if (st0_tag == TW_Infinity)
  486. {
  487. l[0] = 0;
  488. l[1] = 0x7ff00000;
  489. }
  490. else if (st0_tag == TW_NaN)
  491. {
  492. /* Is it really a NaN ? */
  493. if ( (exponent(st0_ptr) == EXP_OVER)
  494. && (st0_ptr->sigh & 0x80000000) )
  495. {
  496. /* See if we can get a valid NaN from the FPU_REG */
  497. l[0] = (st0_ptr->sigl >> 11) | (st0_ptr->sigh << 21);
  498. l[1] = ((st0_ptr->sigh >> 11) & 0xfffff);
  499. if ( !(st0_ptr->sigh & 0x40000000) )
  500. {
  501. /* It is a signalling NaN */
  502. EXCEPTION(EX_Invalid);
  503. if ( !(control_word & CW_Invalid) )
  504. return 0;
  505. l[1] |= (0x40000000 >> 11);
  506. }
  507. l[1] |= 0x7ff00000;
  508. }
  509. else
  510. {
  511. /* It is an unsupported data type */
  512. EXCEPTION(EX_Invalid);
  513. if ( !(control_word & CW_Invalid) )
  514. return 0;
  515. l[0] = 0;
  516. l[1] = 0xfff80000;
  517. }
  518. }
  519. }
  520. else if ( st0_tag == TAG_Empty )
  521. {
  522. /* Empty register (stack underflow) */
  523. EXCEPTION(EX_StackUnder);
  524. if ( control_word & CW_Invalid )
  525. {
  526. /* The masked response */
  527. /* Put out the QNaN indefinite */
  528. RE_ENTRANT_CHECK_OFF;
  529. FPU_access_ok(VERIFY_WRITE,dfloat,8);
  530. FPU_put_user(0, (unsigned long __user *) dfloat);
  531. FPU_put_user(0xfff80000, 1 + (unsigned long __user *) dfloat);
  532. RE_ENTRANT_CHECK_ON;
  533. return 1;
  534. }
  535. else
  536. return 0;
  537. }
  538. if ( getsign(st0_ptr) )
  539. l[1] |= 0x80000000;
  540. RE_ENTRANT_CHECK_OFF;
  541. FPU_access_ok(VERIFY_WRITE,dfloat,8);
  542. FPU_put_user(l[0], (unsigned long __user *)dfloat);
  543. FPU_put_user(l[1], 1 + (unsigned long __user *)dfloat);
  544. RE_ENTRANT_CHECK_ON;
  545. return 1;
  546. }
  547. /* Put a float into user memory */
  548. int FPU_store_single(FPU_REG *st0_ptr, u_char st0_tag, float __user *single)
  549. {
  550. long templ = 0;
  551. unsigned long increment = 0; /* avoid gcc warnings */
  552. int precision_loss;
  553. int exp;
  554. FPU_REG tmp;
  555. if ( st0_tag == TAG_Valid )
  556. {
  557. reg_copy(st0_ptr, &tmp);
  558. exp = exponent(&tmp);
  559. if ( exp < SINGLE_Emin )
  560. {
  561. addexponent(&tmp, -SINGLE_Emin + 23); /* largest exp to be 22 */
  562. denormal_arg:
  563. if ( (precision_loss = FPU_round_to_int(&tmp, st0_tag)) )
  564. {
  565. #ifdef PECULIAR_486
  566. /* Did it round to a non-denormal ? */
  567. /* This behaviour might be regarded as peculiar, it appears
  568. that the 80486 rounds to the dest precision, then
  569. converts to decide underflow. */
  570. if ( !((tmp.sigl == 0x00800000) &&
  571. ((st0_ptr->sigh & 0x000000ff) || st0_ptr->sigl)) )
  572. #endif /* PECULIAR_486 */
  573. {
  574. EXCEPTION(EX_Underflow);
  575. /* This is a special case: see sec 16.2.5.1 of
  576. the 80486 book */
  577. if ( !(control_word & CW_Underflow) )
  578. return 0;
  579. }
  580. EXCEPTION(precision_loss);
  581. if ( !(control_word & CW_Precision) )
  582. return 0;
  583. }
  584. templ = tmp.sigl;
  585. }
  586. else
  587. {
  588. if ( tmp.sigl | (tmp.sigh & 0x000000ff) )
  589. {
  590. unsigned long sigh = tmp.sigh;
  591. unsigned long sigl = tmp.sigl;
  592. precision_loss = 1;
  593. switch (control_word & CW_RC)
  594. {
  595. case RC_RND:
  596. increment = ((sigh & 0xff) > 0x80) /* more than half */
  597. || (((sigh & 0xff) == 0x80) && sigl) /* more than half */
  598. || ((sigh & 0x180) == 0x180); /* round to even */
  599. break;
  600. case RC_DOWN: /* towards -infinity */
  601. increment = signpositive(&tmp)
  602. ? 0 : (sigl | (sigh & 0xff));
  603. break;
  604. case RC_UP: /* towards +infinity */
  605. increment = signpositive(&tmp)
  606. ? (sigl | (sigh & 0xff)) : 0;
  607. break;
  608. case RC_CHOP:
  609. increment = 0;
  610. break;
  611. }
  612. /* Truncate part of the mantissa */
  613. tmp.sigl = 0;
  614. if (increment)
  615. {
  616. if ( sigh >= 0xffffff00 )
  617. {
  618. /* The sigh part overflows */
  619. tmp.sigh = 0x80000000;
  620. exp++;
  621. if ( exp >= EXP_OVER )
  622. goto overflow;
  623. }
  624. else
  625. {
  626. tmp.sigh &= 0xffffff00;
  627. tmp.sigh += 0x100;
  628. }
  629. }
  630. else
  631. {
  632. tmp.sigh &= 0xffffff00; /* Finish the truncation */
  633. }
  634. }
  635. else
  636. precision_loss = 0;
  637. templ = (tmp.sigh >> 8) & 0x007fffff;
  638. if ( exp > SINGLE_Emax )
  639. {
  640. overflow:
  641. EXCEPTION(EX_Overflow);
  642. if ( !(control_word & CW_Overflow) )
  643. return 0;
  644. set_precision_flag_up();
  645. if ( !(control_word & CW_Precision) )
  646. return 0;
  647. /* This is a special case: see sec 16.2.5.1 of the 80486 book. */
  648. /* Masked response is overflow to infinity. */
  649. templ = 0x7f800000;
  650. }
  651. else
  652. {
  653. if ( precision_loss )
  654. {
  655. if ( increment )
  656. set_precision_flag_up();
  657. else
  658. set_precision_flag_down();
  659. }
  660. /* Add the exponent */
  661. templ |= ((exp+SINGLE_Ebias) & 0xff) << 23;
  662. }
  663. }
  664. }
  665. else if (st0_tag == TAG_Zero)
  666. {
  667. templ = 0;
  668. }
  669. else if ( st0_tag == TAG_Special )
  670. {
  671. st0_tag = FPU_Special(st0_ptr);
  672. if (st0_tag == TW_Denormal)
  673. {
  674. reg_copy(st0_ptr, &tmp);
  675. /* A denormal will always underflow. */
  676. #ifndef PECULIAR_486
  677. /* An 80486 is supposed to be able to generate
  678. a denormal exception here, but... */
  679. /* Underflow has priority. */
  680. if ( control_word & CW_Underflow )
  681. denormal_operand();
  682. #endif /* PECULIAR_486 */
  683. goto denormal_arg;
  684. }
  685. else if (st0_tag == TW_Infinity)
  686. {
  687. templ = 0x7f800000;
  688. }
  689. else if (st0_tag == TW_NaN)
  690. {
  691. /* Is it really a NaN ? */
  692. if ( (exponent(st0_ptr) == EXP_OVER) && (st0_ptr->sigh & 0x80000000) )
  693. {
  694. /* See if we can get a valid NaN from the FPU_REG */
  695. templ = st0_ptr->sigh >> 8;
  696. if ( !(st0_ptr->sigh & 0x40000000) )
  697. {
  698. /* It is a signalling NaN */
  699. EXCEPTION(EX_Invalid);
  700. if ( !(control_word & CW_Invalid) )
  701. return 0;
  702. templ |= (0x40000000 >> 8);
  703. }
  704. templ |= 0x7f800000;
  705. }
  706. else
  707. {
  708. /* It is an unsupported data type */
  709. EXCEPTION(EX_Invalid);
  710. if ( !(control_word & CW_Invalid) )
  711. return 0;
  712. templ = 0xffc00000;
  713. }
  714. }
  715. #ifdef PARANOID
  716. else
  717. {
  718. EXCEPTION(EX_INTERNAL|0x164);
  719. return 0;
  720. }
  721. #endif
  722. }
  723. else if ( st0_tag == TAG_Empty )
  724. {
  725. /* Empty register (stack underflow) */
  726. EXCEPTION(EX_StackUnder);
  727. if ( control_word & EX_Invalid )
  728. {
  729. /* The masked response */
  730. /* Put out the QNaN indefinite */
  731. RE_ENTRANT_CHECK_OFF;
  732. FPU_access_ok(VERIFY_WRITE,single,4);
  733. FPU_put_user(0xffc00000, (unsigned long __user *) single);
  734. RE_ENTRANT_CHECK_ON;
  735. return 1;
  736. }
  737. else
  738. return 0;
  739. }
  740. #ifdef PARANOID
  741. else
  742. {
  743. EXCEPTION(EX_INTERNAL|0x163);
  744. return 0;
  745. }
  746. #endif
  747. if ( getsign(st0_ptr) )
  748. templ |= 0x80000000;
  749. RE_ENTRANT_CHECK_OFF;
  750. FPU_access_ok(VERIFY_WRITE,single,4);
  751. FPU_put_user(templ,(unsigned long __user *) single);
  752. RE_ENTRANT_CHECK_ON;
  753. return 1;
  754. }
  755. /* Put a long long into user memory */
  756. int FPU_store_int64(FPU_REG *st0_ptr, u_char st0_tag, long long __user *d)
  757. {
  758. FPU_REG t;
  759. long long tll;
  760. int precision_loss;
  761. if ( st0_tag == TAG_Empty )
  762. {
  763. /* Empty register (stack underflow) */
  764. EXCEPTION(EX_StackUnder);
  765. goto invalid_operand;
  766. }
  767. else if ( st0_tag == TAG_Special )
  768. {
  769. st0_tag = FPU_Special(st0_ptr);
  770. if ( (st0_tag == TW_Infinity) ||
  771. (st0_tag == TW_NaN) )
  772. {
  773. EXCEPTION(EX_Invalid);
  774. goto invalid_operand;
  775. }
  776. }
  777. reg_copy(st0_ptr, &t);
  778. precision_loss = FPU_round_to_int(&t, st0_tag);
  779. ((long *)&tll)[0] = t.sigl;
  780. ((long *)&tll)[1] = t.sigh;
  781. if ( (precision_loss == 1) ||
  782. ((t.sigh & 0x80000000) &&
  783. !((t.sigh == 0x80000000) && (t.sigl == 0) &&
  784. signnegative(&t))) )
  785. {
  786. EXCEPTION(EX_Invalid);
  787. /* This is a special case: see sec 16.2.5.1 of the 80486 book */
  788. invalid_operand:
  789. if ( control_word & EX_Invalid )
  790. {
  791. /* Produce something like QNaN "indefinite" */
  792. tll = 0x8000000000000000LL;
  793. }
  794. else
  795. return 0;
  796. }
  797. else
  798. {
  799. if ( precision_loss )
  800. set_precision_flag(precision_loss);
  801. if ( signnegative(&t) )
  802. tll = - tll;
  803. }
  804. RE_ENTRANT_CHECK_OFF;
  805. FPU_access_ok(VERIFY_WRITE,d,8);
  806. if (copy_to_user(d, &tll, 8))
  807. FPU_abort;
  808. RE_ENTRANT_CHECK_ON;
  809. return 1;
  810. }
  811. /* Put a long into user memory */
  812. int FPU_store_int32(FPU_REG *st0_ptr, u_char st0_tag, long __user *d)
  813. {
  814. FPU_REG t;
  815. int precision_loss;
  816. if ( st0_tag == TAG_Empty )
  817. {
  818. /* Empty register (stack underflow) */
  819. EXCEPTION(EX_StackUnder);
  820. goto invalid_operand;
  821. }
  822. else if ( st0_tag == TAG_Special )
  823. {
  824. st0_tag = FPU_Special(st0_ptr);
  825. if ( (st0_tag == TW_Infinity) ||
  826. (st0_tag == TW_NaN) )
  827. {
  828. EXCEPTION(EX_Invalid);
  829. goto invalid_operand;
  830. }
  831. }
  832. reg_copy(st0_ptr, &t);
  833. precision_loss = FPU_round_to_int(&t, st0_tag);
  834. if (t.sigh ||
  835. ((t.sigl & 0x80000000) &&
  836. !((t.sigl == 0x80000000) && signnegative(&t))) )
  837. {
  838. EXCEPTION(EX_Invalid);
  839. /* This is a special case: see sec 16.2.5.1 of the 80486 book */
  840. invalid_operand:
  841. if ( control_word & EX_Invalid )
  842. {
  843. /* Produce something like QNaN "indefinite" */
  844. t.sigl = 0x80000000;
  845. }
  846. else
  847. return 0;
  848. }
  849. else
  850. {
  851. if ( precision_loss )
  852. set_precision_flag(precision_loss);
  853. if ( signnegative(&t) )
  854. t.sigl = -(long)t.sigl;
  855. }
  856. RE_ENTRANT_CHECK_OFF;
  857. FPU_access_ok(VERIFY_WRITE,d,4);
  858. FPU_put_user(t.sigl, (unsigned long __user *) d);
  859. RE_ENTRANT_CHECK_ON;
  860. return 1;
  861. }
  862. /* Put a short into user memory */
  863. int FPU_store_int16(FPU_REG *st0_ptr, u_char st0_tag, short __user *d)
  864. {
  865. FPU_REG t;
  866. int precision_loss;
  867. if ( st0_tag == TAG_Empty )
  868. {
  869. /* Empty register (stack underflow) */
  870. EXCEPTION(EX_StackUnder);
  871. goto invalid_operand;
  872. }
  873. else if ( st0_tag == TAG_Special )
  874. {
  875. st0_tag = FPU_Special(st0_ptr);
  876. if ( (st0_tag == TW_Infinity) ||
  877. (st0_tag == TW_NaN) )
  878. {
  879. EXCEPTION(EX_Invalid);
  880. goto invalid_operand;
  881. }
  882. }
  883. reg_copy(st0_ptr, &t);
  884. precision_loss = FPU_round_to_int(&t, st0_tag);
  885. if (t.sigh ||
  886. ((t.sigl & 0xffff8000) &&
  887. !((t.sigl == 0x8000) && signnegative(&t))) )
  888. {
  889. EXCEPTION(EX_Invalid);
  890. /* This is a special case: see sec 16.2.5.1 of the 80486 book */
  891. invalid_operand:
  892. if ( control_word & EX_Invalid )
  893. {
  894. /* Produce something like QNaN "indefinite" */
  895. t.sigl = 0x8000;
  896. }
  897. else
  898. return 0;
  899. }
  900. else
  901. {
  902. if ( precision_loss )
  903. set_precision_flag(precision_loss);
  904. if ( signnegative(&t) )
  905. t.sigl = -t.sigl;
  906. }
  907. RE_ENTRANT_CHECK_OFF;
  908. FPU_access_ok(VERIFY_WRITE,d,2);
  909. FPU_put_user((short)t.sigl, d);
  910. RE_ENTRANT_CHECK_ON;
  911. return 1;
  912. }
  913. /* Put a packed bcd array into user memory */
  914. int FPU_store_bcd(FPU_REG *st0_ptr, u_char st0_tag, u_char __user *d)
  915. {
  916. FPU_REG t;
  917. unsigned long long ll;
  918. u_char b;
  919. int i, precision_loss;
  920. u_char sign = (getsign(st0_ptr) == SIGN_NEG) ? 0x80 : 0;
  921. if ( st0_tag == TAG_Empty )
  922. {
  923. /* Empty register (stack underflow) */
  924. EXCEPTION(EX_StackUnder);
  925. goto invalid_operand;
  926. }
  927. else if ( st0_tag == TAG_Special )
  928. {
  929. st0_tag = FPU_Special(st0_ptr);
  930. if ( (st0_tag == TW_Infinity) ||
  931. (st0_tag == TW_NaN) )
  932. {
  933. EXCEPTION(EX_Invalid);
  934. goto invalid_operand;
  935. }
  936. }
  937. reg_copy(st0_ptr, &t);
  938. precision_loss = FPU_round_to_int(&t, st0_tag);
  939. ll = significand(&t);
  940. /* Check for overflow, by comparing with 999999999999999999 decimal. */
  941. if ( (t.sigh > 0x0de0b6b3) ||
  942. ((t.sigh == 0x0de0b6b3) && (t.sigl > 0xa763ffff)) )
  943. {
  944. EXCEPTION(EX_Invalid);
  945. /* This is a special case: see sec 16.2.5.1 of the 80486 book */
  946. invalid_operand:
  947. if ( control_word & CW_Invalid )
  948. {
  949. /* Produce the QNaN "indefinite" */
  950. RE_ENTRANT_CHECK_OFF;
  951. FPU_access_ok(VERIFY_WRITE,d,10);
  952. for ( i = 0; i < 7; i++)
  953. FPU_put_user(0, d+i); /* These bytes "undefined" */
  954. FPU_put_user(0xc0, d+7); /* This byte "undefined" */
  955. FPU_put_user(0xff, d+8);
  956. FPU_put_user(0xff, d+9);
  957. RE_ENTRANT_CHECK_ON;
  958. return 1;
  959. }
  960. else
  961. return 0;
  962. }
  963. else if ( precision_loss )
  964. {
  965. /* Precision loss doesn't stop the data transfer */
  966. set_precision_flag(precision_loss);
  967. }
  968. RE_ENTRANT_CHECK_OFF;
  969. FPU_access_ok(VERIFY_WRITE,d,10);
  970. RE_ENTRANT_CHECK_ON;
  971. for ( i = 0; i < 9; i++)
  972. {
  973. b = FPU_div_small(&ll, 10);
  974. b |= (FPU_div_small(&ll, 10)) << 4;
  975. RE_ENTRANT_CHECK_OFF;
  976. FPU_put_user(b, d+i);
  977. RE_ENTRANT_CHECK_ON;
  978. }
  979. RE_ENTRANT_CHECK_OFF;
  980. FPU_put_user(sign, d+9);
  981. RE_ENTRANT_CHECK_ON;
  982. return 1;
  983. }
  984. /*===========================================================================*/
  985. /* r gets mangled such that sig is int, sign:
  986. it is NOT normalized */
  987. /* The return value (in eax) is zero if the result is exact,
  988. if bits are changed due to rounding, truncation, etc, then
  989. a non-zero value is returned */
  990. /* Overflow is signalled by a non-zero return value (in eax).
  991. In the case of overflow, the returned significand always has the
  992. largest possible value */
  993. int FPU_round_to_int(FPU_REG *r, u_char tag)
  994. {
  995. u_char very_big;
  996. unsigned eax;
  997. if (tag == TAG_Zero)
  998. {
  999. /* Make sure that zero is returned */
  1000. significand(r) = 0;
  1001. return 0; /* o.k. */
  1002. }
  1003. if (exponent(r) > 63)
  1004. {
  1005. r->sigl = r->sigh = ~0; /* The largest representable number */
  1006. return 1; /* overflow */
  1007. }
  1008. eax = FPU_shrxs(&r->sigl, 63 - exponent(r));
  1009. very_big = !(~(r->sigh) | ~(r->sigl)); /* test for 0xfff...fff */
  1010. #define half_or_more (eax & 0x80000000)
  1011. #define frac_part (eax)
  1012. #define more_than_half ((eax & 0x80000001) == 0x80000001)
  1013. switch (control_word & CW_RC)
  1014. {
  1015. case RC_RND:
  1016. if ( more_than_half /* nearest */
  1017. || (half_or_more && (r->sigl & 1)) ) /* odd -> even */
  1018. {
  1019. if ( very_big ) return 1; /* overflow */
  1020. significand(r) ++;
  1021. return PRECISION_LOST_UP;
  1022. }
  1023. break;
  1024. case RC_DOWN:
  1025. if (frac_part && getsign(r))
  1026. {
  1027. if ( very_big ) return 1; /* overflow */
  1028. significand(r) ++;
  1029. return PRECISION_LOST_UP;
  1030. }
  1031. break;
  1032. case RC_UP:
  1033. if (frac_part && !getsign(r))
  1034. {
  1035. if ( very_big ) return 1; /* overflow */
  1036. significand(r) ++;
  1037. return PRECISION_LOST_UP;
  1038. }
  1039. break;
  1040. case RC_CHOP:
  1041. break;
  1042. }
  1043. return eax ? PRECISION_LOST_DOWN : 0;
  1044. }
  1045. /*===========================================================================*/
  1046. u_char __user *fldenv(fpu_addr_modes addr_modes, u_char __user *s)
  1047. {
  1048. unsigned short tag_word = 0;
  1049. u_char tag;
  1050. int i;
  1051. if ( (addr_modes.default_mode == VM86) ||
  1052. ((addr_modes.default_mode == PM16)
  1053. ^ (addr_modes.override.operand_size == OP_SIZE_PREFIX)) )
  1054. {
  1055. RE_ENTRANT_CHECK_OFF;
  1056. FPU_access_ok(VERIFY_READ, s, 0x0e);
  1057. FPU_get_user(control_word, (unsigned short __user *) s);
  1058. FPU_get_user(partial_status, (unsigned short __user *) (s+2));
  1059. FPU_get_user(tag_word, (unsigned short __user *) (s+4));
  1060. FPU_get_user(instruction_address.offset, (unsigned short __user *) (s+6));
  1061. FPU_get_user(instruction_address.selector, (unsigned short __user *) (s+8));
  1062. FPU_get_user(operand_address.offset, (unsigned short __user *) (s+0x0a));
  1063. FPU_get_user(operand_address.selector, (unsigned short __user *) (s+0x0c));
  1064. RE_ENTRANT_CHECK_ON;
  1065. s += 0x0e;
  1066. if ( addr_modes.default_mode == VM86 )
  1067. {
  1068. instruction_address.offset
  1069. += (instruction_address.selector & 0xf000) << 4;
  1070. operand_address.offset += (operand_address.selector & 0xf000) << 4;
  1071. }
  1072. }
  1073. else
  1074. {
  1075. RE_ENTRANT_CHECK_OFF;
  1076. FPU_access_ok(VERIFY_READ, s, 0x1c);
  1077. FPU_get_user(control_word, (unsigned short __user *) s);
  1078. FPU_get_user(partial_status, (unsigned short __user *) (s+4));
  1079. FPU_get_user(tag_word, (unsigned short __user *) (s+8));
  1080. FPU_get_user(instruction_address.offset, (unsigned long __user *) (s+0x0c));
  1081. FPU_get_user(instruction_address.selector, (unsigned short __user *) (s+0x10));
  1082. FPU_get_user(instruction_address.opcode, (unsigned short __user *) (s+0x12));
  1083. FPU_get_user(operand_address.offset, (unsigned long __user *) (s+0x14));
  1084. FPU_get_user(operand_address.selector, (unsigned long __user *) (s+0x18));
  1085. RE_ENTRANT_CHECK_ON;
  1086. s += 0x1c;
  1087. }
  1088. #ifdef PECULIAR_486
  1089. control_word &= ~0xe080;
  1090. #endif /* PECULIAR_486 */
  1091. top = (partial_status >> SW_Top_Shift) & 7;
  1092. if ( partial_status & ~control_word & CW_Exceptions )
  1093. partial_status |= (SW_Summary | SW_Backward);
  1094. else
  1095. partial_status &= ~(SW_Summary | SW_Backward);
  1096. for ( i = 0; i < 8; i++ )
  1097. {
  1098. tag = tag_word & 3;
  1099. tag_word >>= 2;
  1100. if ( tag == TAG_Empty )
  1101. /* New tag is empty. Accept it */
  1102. FPU_settag(i, TAG_Empty);
  1103. else if ( FPU_gettag(i) == TAG_Empty )
  1104. {
  1105. /* Old tag is empty and new tag is not empty. New tag is determined
  1106. by old reg contents */
  1107. if ( exponent(&fpu_register(i)) == - EXTENDED_Ebias )
  1108. {
  1109. if ( !(fpu_register(i).sigl | fpu_register(i).sigh) )
  1110. FPU_settag(i, TAG_Zero);
  1111. else
  1112. FPU_settag(i, TAG_Special);
  1113. }
  1114. else if ( exponent(&fpu_register(i)) == 0x7fff - EXTENDED_Ebias )
  1115. {
  1116. FPU_settag(i, TAG_Special);
  1117. }
  1118. else if ( fpu_register(i).sigh & 0x80000000 )
  1119. FPU_settag(i, TAG_Valid);
  1120. else
  1121. FPU_settag(i, TAG_Special); /* An Un-normal */
  1122. }
  1123. /* Else old tag is not empty and new tag is not empty. Old tag
  1124. remains correct */
  1125. }
  1126. return s;
  1127. }
  1128. void frstor(fpu_addr_modes addr_modes, u_char __user *data_address)
  1129. {
  1130. int i, regnr;
  1131. u_char __user *s = fldenv(addr_modes, data_address);
  1132. int offset = (top & 7) * 10, other = 80 - offset;
  1133. /* Copy all registers in stack order. */
  1134. RE_ENTRANT_CHECK_OFF;
  1135. FPU_access_ok(VERIFY_READ,s,80);
  1136. __copy_from_user(register_base+offset, s, other);
  1137. if ( offset )
  1138. __copy_from_user(register_base, s+other, offset);
  1139. RE_ENTRANT_CHECK_ON;
  1140. for ( i = 0; i < 8; i++ )
  1141. {
  1142. regnr = (i+top) & 7;
  1143. if ( FPU_gettag(regnr) != TAG_Empty )
  1144. /* The loaded data over-rides all other cases. */
  1145. FPU_settag(regnr, FPU_tagof(&st(i)));
  1146. }
  1147. }
  1148. u_char __user *fstenv(fpu_addr_modes addr_modes, u_char __user *d)
  1149. {
  1150. if ( (addr_modes.default_mode == VM86) ||
  1151. ((addr_modes.default_mode == PM16)
  1152. ^ (addr_modes.override.operand_size == OP_SIZE_PREFIX)) )
  1153. {
  1154. RE_ENTRANT_CHECK_OFF;
  1155. FPU_access_ok(VERIFY_WRITE,d,14);
  1156. #ifdef PECULIAR_486
  1157. FPU_put_user(control_word & ~0xe080, (unsigned long __user *) d);
  1158. #else
  1159. FPU_put_user(control_word, (unsigned short __user *) d);
  1160. #endif /* PECULIAR_486 */
  1161. FPU_put_user(status_word(), (unsigned short __user *) (d+2));
  1162. FPU_put_user(fpu_tag_word, (unsigned short __user *) (d+4));
  1163. FPU_put_user(instruction_address.offset, (unsigned short __user *) (d+6));
  1164. FPU_put_user(operand_address.offset, (unsigned short __user *) (d+0x0a));
  1165. if ( addr_modes.default_mode == VM86 )
  1166. {
  1167. FPU_put_user((instruction_address.offset & 0xf0000) >> 4,
  1168. (unsigned short __user *) (d+8));
  1169. FPU_put_user((operand_address.offset & 0xf0000) >> 4,
  1170. (unsigned short __user *) (d+0x0c));
  1171. }
  1172. else
  1173. {
  1174. FPU_put_user(instruction_address.selector, (unsigned short __user *) (d+8));
  1175. FPU_put_user(operand_address.selector, (unsigned short __user *) (d+0x0c));
  1176. }
  1177. RE_ENTRANT_CHECK_ON;
  1178. d += 0x0e;
  1179. }
  1180. else
  1181. {
  1182. RE_ENTRANT_CHECK_OFF;
  1183. FPU_access_ok(VERIFY_WRITE, d, 7*4);
  1184. #ifdef PECULIAR_486
  1185. control_word &= ~0xe080;
  1186. /* An 80486 sets nearly all of the reserved bits to 1. */
  1187. control_word |= 0xffff0040;
  1188. partial_status = status_word() | 0xffff0000;
  1189. fpu_tag_word |= 0xffff0000;
  1190. I387.soft.fcs &= ~0xf8000000;
  1191. I387.soft.fos |= 0xffff0000;
  1192. #endif /* PECULIAR_486 */
  1193. if (__copy_to_user(d, &control_word, 7*4))
  1194. FPU_abort;
  1195. RE_ENTRANT_CHECK_ON;
  1196. d += 0x1c;
  1197. }
  1198. control_word |= CW_Exceptions;
  1199. partial_status &= ~(SW_Summary | SW_Backward);
  1200. return d;
  1201. }
  1202. void fsave(fpu_addr_modes addr_modes, u_char __user *data_address)
  1203. {
  1204. u_char __user *d;
  1205. int offset = (top & 7) * 10, other = 80 - offset;
  1206. d = fstenv(addr_modes, data_address);
  1207. RE_ENTRANT_CHECK_OFF;
  1208. FPU_access_ok(VERIFY_WRITE,d,80);
  1209. /* Copy all registers in stack order. */
  1210. if (__copy_to_user(d, register_base+offset, other))
  1211. FPU_abort;
  1212. if ( offset )
  1213. if (__copy_to_user(d+other, register_base, offset))
  1214. FPU_abort;
  1215. RE_ENTRANT_CHECK_ON;
  1216. finit();
  1217. }
  1218. /*===========================================================================*/