fpudispatch.c 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Linux/PA-RISC Project (http://www.parisc-linux.org/)
  4. *
  5. * Floating-point emulation code
  6. * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <[email protected]>
  7. */
  8. /*
  9. * BEGIN_DESC
  10. *
  11. * File:
  12. * @(#) pa/fp/fpudispatch.c $Revision: 1.1 $
  13. *
  14. * Purpose:
  15. * <<please update with a synopsis of the functionality provided by this file>>
  16. *
  17. * External Interfaces:
  18. * <<the following list was autogenerated, please review>>
  19. * emfpudispatch(ir, dummy1, dummy2, fpregs)
  20. * fpudispatch(ir, excp_code, holder, fpregs)
  21. *
  22. * Internal Interfaces:
  23. * <<the following list was autogenerated, please review>>
  24. * static u_int decode_06(u_int, u_int *)
  25. * static u_int decode_0c(u_int, u_int, u_int, u_int *)
  26. * static u_int decode_0e(u_int, u_int, u_int, u_int *)
  27. * static u_int decode_26(u_int, u_int *)
  28. * static u_int decode_2e(u_int, u_int *)
  29. * static void update_status_cbit(u_int *, u_int, u_int, u_int)
  30. *
  31. * Theory:
  32. * <<please update with a overview of the operation of this file>>
  33. *
  34. * END_DESC
  35. */
  36. #define FPUDEBUG 0
  37. #include "float.h"
  38. #include <linux/bug.h>
  39. #include <linux/kernel.h>
  40. #include <asm/processor.h>
  41. /* #include <sys/debug.h> */
  42. /* #include <machine/sys/mdep_private.h> */
  43. #define COPR_INST 0x30000000
  44. /*
  45. * definition of extru macro. If pos and len are constants, the compiler
  46. * will generate an extru instruction when optimized
  47. */
  48. #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
  49. /* definitions of bit field locations in the instruction */
  50. #define fpmajorpos 5
  51. #define fpr1pos 10
  52. #define fpr2pos 15
  53. #define fptpos 31
  54. #define fpsubpos 18
  55. #define fpclass1subpos 16
  56. #define fpclasspos 22
  57. #define fpfmtpos 20
  58. #define fpdfpos 18
  59. #define fpnulpos 26
  60. /*
  61. * the following are the extra bits for the 0E major op
  62. */
  63. #define fpxr1pos 24
  64. #define fpxr2pos 19
  65. #define fpxtpos 25
  66. #define fpxpos 23
  67. #define fp0efmtpos 20
  68. /*
  69. * the following are for the multi-ops
  70. */
  71. #define fprm1pos 10
  72. #define fprm2pos 15
  73. #define fptmpos 31
  74. #define fprapos 25
  75. #define fptapos 20
  76. #define fpmultifmt 26
  77. /*
  78. * the following are for the fused FP instructions
  79. */
  80. /* fprm1pos 10 */
  81. /* fprm2pos 15 */
  82. #define fpraupos 18
  83. #define fpxrm2pos 19
  84. /* fpfmtpos 20 */
  85. #define fpralpos 23
  86. #define fpxrm1pos 24
  87. /* fpxtpos 25 */
  88. #define fpfusedsubop 26
  89. /* fptpos 31 */
  90. /*
  91. * offset to constant zero in the FP emulation registers
  92. */
  93. #define fpzeroreg (32*sizeof(double)/sizeof(u_int))
  94. /*
  95. * extract the major opcode from the instruction
  96. */
  97. #define get_major(op) extru(op,fpmajorpos,6)
  98. /*
  99. * extract the two bit class field from the FP instruction. The class is at bit
  100. * positions 21-22
  101. */
  102. #define get_class(op) extru(op,fpclasspos,2)
  103. /*
  104. * extract the 3 bit subop field. For all but class 1 instructions, it is
  105. * located at bit positions 16-18
  106. */
  107. #define get_subop(op) extru(op,fpsubpos,3)
  108. /*
  109. * extract the 2 or 3 bit subop field from class 1 instructions. It is located
  110. * at bit positions 15-16 (PA1.1) or 14-16 (PA2.0)
  111. */
  112. #define get_subop1_PA1_1(op) extru(op,fpclass1subpos,2) /* PA89 (1.1) fmt */
  113. #define get_subop1_PA2_0(op) extru(op,fpclass1subpos,3) /* PA 2.0 fmt */
  114. /* definitions of unimplemented exceptions */
  115. #define MAJOR_0C_EXCP 0x09
  116. #define MAJOR_0E_EXCP 0x0b
  117. #define MAJOR_06_EXCP 0x03
  118. #define MAJOR_26_EXCP 0x23
  119. #define MAJOR_2E_EXCP 0x2b
  120. #define PA83_UNIMP_EXCP 0x01
  121. /*
  122. * Special Defines for TIMEX specific code
  123. */
  124. #define FPU_TYPE_FLAG_POS (EM_FPU_TYPE_OFFSET>>2)
  125. #define TIMEX_ROLEX_FPU_MASK (TIMEX_EXTEN_FLAG|ROLEX_EXTEN_FLAG)
  126. /*
  127. * Static function definitions
  128. */
  129. #define _PROTOTYPES
  130. #if defined(_PROTOTYPES) || defined(_lint)
  131. static u_int decode_0c(u_int, u_int, u_int, u_int *);
  132. static u_int decode_0e(u_int, u_int, u_int, u_int *);
  133. static u_int decode_06(u_int, u_int *);
  134. static u_int decode_26(u_int, u_int *);
  135. static u_int decode_2e(u_int, u_int *);
  136. static void update_status_cbit(u_int *, u_int, u_int, u_int);
  137. #else /* !_PROTOTYPES&&!_lint */
  138. static u_int decode_0c();
  139. static u_int decode_0e();
  140. static u_int decode_06();
  141. static u_int decode_26();
  142. static u_int decode_2e();
  143. static void update_status_cbit();
  144. #endif /* _PROTOTYPES&&!_lint */
  145. #define VASSERT(x)
  146. static void parisc_linux_get_fpu_type(u_int fpregs[])
  147. {
  148. /* on pa-linux the fpu type is not filled in by the
  149. * caller; it is constructed here
  150. */
  151. if (boot_cpu_data.cpu_type == pcxs)
  152. fpregs[FPU_TYPE_FLAG_POS] = TIMEX_EXTEN_FLAG;
  153. else if (boot_cpu_data.cpu_type == pcxt ||
  154. boot_cpu_data.cpu_type == pcxt_)
  155. fpregs[FPU_TYPE_FLAG_POS] = ROLEX_EXTEN_FLAG;
  156. else if (boot_cpu_data.cpu_type >= pcxu)
  157. fpregs[FPU_TYPE_FLAG_POS] = PA2_0_FPU_FLAG;
  158. }
  159. /*
  160. * this routine will decode the excepting floating point instruction and
  161. * call the appropriate emulation routine.
  162. * It is called by decode_fpu with the following parameters:
  163. * fpudispatch(current_ir, unimplemented_code, 0, &Fpu_register)
  164. * where current_ir is the instruction to be emulated,
  165. * unimplemented_code is the exception_code that the hardware generated
  166. * and &Fpu_register is the address of emulated FP reg 0.
  167. */
  168. u_int
  169. fpudispatch(u_int ir, u_int excp_code, u_int holder, u_int fpregs[])
  170. {
  171. u_int class, subop;
  172. u_int fpu_type_flags;
  173. /* All FP emulation code assumes that ints are 4-bytes in length */
  174. VASSERT(sizeof(int) == 4);
  175. parisc_linux_get_fpu_type(fpregs);
  176. fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
  177. class = get_class(ir);
  178. if (class == 1) {
  179. if (fpu_type_flags & PA2_0_FPU_FLAG)
  180. subop = get_subop1_PA2_0(ir);
  181. else
  182. subop = get_subop1_PA1_1(ir);
  183. }
  184. else
  185. subop = get_subop(ir);
  186. if (FPUDEBUG) printk("class %d subop %d\n", class, subop);
  187. switch (excp_code) {
  188. case MAJOR_0C_EXCP:
  189. case PA83_UNIMP_EXCP:
  190. return(decode_0c(ir,class,subop,fpregs));
  191. case MAJOR_0E_EXCP:
  192. return(decode_0e(ir,class,subop,fpregs));
  193. case MAJOR_06_EXCP:
  194. return(decode_06(ir,fpregs));
  195. case MAJOR_26_EXCP:
  196. return(decode_26(ir,fpregs));
  197. case MAJOR_2E_EXCP:
  198. return(decode_2e(ir,fpregs));
  199. default:
  200. /* "crashme Night Gallery painting nr 2. (asm_crash.s).
  201. * This was fixed for multi-user kernels, but
  202. * workstation kernels had a panic here. This allowed
  203. * any arbitrary user to panic the kernel by executing
  204. * setting the FP exception registers to strange values
  205. * and generating an emulation trap. The emulation and
  206. * exception code must never be able to panic the
  207. * kernel.
  208. */
  209. return(UNIMPLEMENTEDEXCEPTION);
  210. }
  211. }
  212. /*
  213. * this routine is called by $emulation_trap to emulate a coprocessor
  214. * instruction if one doesn't exist
  215. */
  216. u_int
  217. emfpudispatch(u_int ir, u_int dummy1, u_int dummy2, u_int fpregs[])
  218. {
  219. u_int class, subop, major;
  220. u_int fpu_type_flags;
  221. /* All FP emulation code assumes that ints are 4-bytes in length */
  222. VASSERT(sizeof(int) == 4);
  223. fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
  224. major = get_major(ir);
  225. class = get_class(ir);
  226. if (class == 1) {
  227. if (fpu_type_flags & PA2_0_FPU_FLAG)
  228. subop = get_subop1_PA2_0(ir);
  229. else
  230. subop = get_subop1_PA1_1(ir);
  231. }
  232. else
  233. subop = get_subop(ir);
  234. switch (major) {
  235. case 0x0C:
  236. return(decode_0c(ir,class,subop,fpregs));
  237. case 0x0E:
  238. return(decode_0e(ir,class,subop,fpregs));
  239. case 0x06:
  240. return(decode_06(ir,fpregs));
  241. case 0x26:
  242. return(decode_26(ir,fpregs));
  243. case 0x2E:
  244. return(decode_2e(ir,fpregs));
  245. default:
  246. return(PA83_UNIMP_EXCP);
  247. }
  248. }
  249. static u_int
  250. decode_0c(u_int ir, u_int class, u_int subop, u_int fpregs[])
  251. {
  252. u_int r1,r2,t; /* operand register offsets */
  253. u_int fmt; /* also sf for class 1 conversions */
  254. u_int df; /* for class 1 conversions */
  255. u_int *status;
  256. u_int retval, local_status;
  257. u_int fpu_type_flags;
  258. if (ir == COPR_INST) {
  259. fpregs[0] = EMULATION_VERSION << 11;
  260. return(NOEXCEPTION);
  261. }
  262. status = &fpregs[0]; /* fp status register */
  263. local_status = fpregs[0]; /* and local copy */
  264. r1 = extru(ir,fpr1pos,5) * sizeof(double)/sizeof(u_int);
  265. if (r1 == 0) /* map fr0 source to constant zero */
  266. r1 = fpzeroreg;
  267. t = extru(ir,fptpos,5) * sizeof(double)/sizeof(u_int);
  268. if (t == 0 && class != 2) /* don't allow fr0 as a dest */
  269. return(MAJOR_0C_EXCP);
  270. fmt = extru(ir,fpfmtpos,2); /* get fmt completer */
  271. switch (class) {
  272. case 0:
  273. switch (subop) {
  274. case 0: /* COPR 0,0 emulated above*/
  275. case 1:
  276. return(MAJOR_0C_EXCP);
  277. case 2: /* FCPY */
  278. switch (fmt) {
  279. case 2: /* illegal */
  280. return(MAJOR_0C_EXCP);
  281. case 3: /* quad */
  282. t &= ~3; /* force to even reg #s */
  283. r1 &= ~3;
  284. fpregs[t+3] = fpregs[r1+3];
  285. fpregs[t+2] = fpregs[r1+2];
  286. fallthrough;
  287. case 1: /* double */
  288. fpregs[t+1] = fpregs[r1+1];
  289. fallthrough;
  290. case 0: /* single */
  291. fpregs[t] = fpregs[r1];
  292. return(NOEXCEPTION);
  293. }
  294. BUG();
  295. case 3: /* FABS */
  296. switch (fmt) {
  297. case 2: /* illegal */
  298. return(MAJOR_0C_EXCP);
  299. case 3: /* quad */
  300. t &= ~3; /* force to even reg #s */
  301. r1 &= ~3;
  302. fpregs[t+3] = fpregs[r1+3];
  303. fpregs[t+2] = fpregs[r1+2];
  304. fallthrough;
  305. case 1: /* double */
  306. fpregs[t+1] = fpregs[r1+1];
  307. fallthrough;
  308. case 0: /* single */
  309. /* copy and clear sign bit */
  310. fpregs[t] = fpregs[r1] & 0x7fffffff;
  311. return(NOEXCEPTION);
  312. }
  313. BUG();
  314. case 6: /* FNEG */
  315. switch (fmt) {
  316. case 2: /* illegal */
  317. return(MAJOR_0C_EXCP);
  318. case 3: /* quad */
  319. t &= ~3; /* force to even reg #s */
  320. r1 &= ~3;
  321. fpregs[t+3] = fpregs[r1+3];
  322. fpregs[t+2] = fpregs[r1+2];
  323. fallthrough;
  324. case 1: /* double */
  325. fpregs[t+1] = fpregs[r1+1];
  326. fallthrough;
  327. case 0: /* single */
  328. /* copy and invert sign bit */
  329. fpregs[t] = fpregs[r1] ^ 0x80000000;
  330. return(NOEXCEPTION);
  331. }
  332. BUG();
  333. case 7: /* FNEGABS */
  334. switch (fmt) {
  335. case 2: /* illegal */
  336. return(MAJOR_0C_EXCP);
  337. case 3: /* quad */
  338. t &= ~3; /* force to even reg #s */
  339. r1 &= ~3;
  340. fpregs[t+3] = fpregs[r1+3];
  341. fpregs[t+2] = fpregs[r1+2];
  342. fallthrough;
  343. case 1: /* double */
  344. fpregs[t+1] = fpregs[r1+1];
  345. fallthrough;
  346. case 0: /* single */
  347. /* copy and set sign bit */
  348. fpregs[t] = fpregs[r1] | 0x80000000;
  349. return(NOEXCEPTION);
  350. }
  351. BUG();
  352. case 4: /* FSQRT */
  353. switch (fmt) {
  354. case 0:
  355. return(sgl_fsqrt(&fpregs[r1],0,
  356. &fpregs[t],status));
  357. case 1:
  358. return(dbl_fsqrt(&fpregs[r1],0,
  359. &fpregs[t],status));
  360. case 2:
  361. case 3: /* quad not implemented */
  362. return(MAJOR_0C_EXCP);
  363. }
  364. BUG();
  365. case 5: /* FRND */
  366. switch (fmt) {
  367. case 0:
  368. return(sgl_frnd(&fpregs[r1],0,
  369. &fpregs[t],status));
  370. case 1:
  371. return(dbl_frnd(&fpregs[r1],0,
  372. &fpregs[t],status));
  373. case 2:
  374. case 3: /* quad not implemented */
  375. return(MAJOR_0C_EXCP);
  376. }
  377. } /* end of switch (subop) */
  378. BUG();
  379. case 1: /* class 1 */
  380. df = extru(ir,fpdfpos,2); /* get dest format */
  381. if ((df & 2) || (fmt & 2)) {
  382. /*
  383. * fmt's 2 and 3 are illegal of not implemented
  384. * quad conversions
  385. */
  386. return(MAJOR_0C_EXCP);
  387. }
  388. /*
  389. * encode source and dest formats into 2 bits.
  390. * high bit is source, low bit is dest.
  391. * bit = 1 --> double precision
  392. */
  393. fmt = (fmt << 1) | df;
  394. switch (subop) {
  395. case 0: /* FCNVFF */
  396. switch(fmt) {
  397. case 0: /* sgl/sgl */
  398. return(MAJOR_0C_EXCP);
  399. case 1: /* sgl/dbl */
  400. return(sgl_to_dbl_fcnvff(&fpregs[r1],0,
  401. &fpregs[t],status));
  402. case 2: /* dbl/sgl */
  403. return(dbl_to_sgl_fcnvff(&fpregs[r1],0,
  404. &fpregs[t],status));
  405. case 3: /* dbl/dbl */
  406. return(MAJOR_0C_EXCP);
  407. }
  408. BUG();
  409. case 1: /* FCNVXF */
  410. switch(fmt) {
  411. case 0: /* sgl/sgl */
  412. return(sgl_to_sgl_fcnvxf(&fpregs[r1],0,
  413. &fpregs[t],status));
  414. case 1: /* sgl/dbl */
  415. return(sgl_to_dbl_fcnvxf(&fpregs[r1],0,
  416. &fpregs[t],status));
  417. case 2: /* dbl/sgl */
  418. return(dbl_to_sgl_fcnvxf(&fpregs[r1],0,
  419. &fpregs[t],status));
  420. case 3: /* dbl/dbl */
  421. return(dbl_to_dbl_fcnvxf(&fpregs[r1],0,
  422. &fpregs[t],status));
  423. }
  424. BUG();
  425. case 2: /* FCNVFX */
  426. switch(fmt) {
  427. case 0: /* sgl/sgl */
  428. return(sgl_to_sgl_fcnvfx(&fpregs[r1],0,
  429. &fpregs[t],status));
  430. case 1: /* sgl/dbl */
  431. return(sgl_to_dbl_fcnvfx(&fpregs[r1],0,
  432. &fpregs[t],status));
  433. case 2: /* dbl/sgl */
  434. return(dbl_to_sgl_fcnvfx(&fpregs[r1],0,
  435. &fpregs[t],status));
  436. case 3: /* dbl/dbl */
  437. return(dbl_to_dbl_fcnvfx(&fpregs[r1],0,
  438. &fpregs[t],status));
  439. }
  440. BUG();
  441. case 3: /* FCNVFXT */
  442. switch(fmt) {
  443. case 0: /* sgl/sgl */
  444. return(sgl_to_sgl_fcnvfxt(&fpregs[r1],0,
  445. &fpregs[t],status));
  446. case 1: /* sgl/dbl */
  447. return(sgl_to_dbl_fcnvfxt(&fpregs[r1],0,
  448. &fpregs[t],status));
  449. case 2: /* dbl/sgl */
  450. return(dbl_to_sgl_fcnvfxt(&fpregs[r1],0,
  451. &fpregs[t],status));
  452. case 3: /* dbl/dbl */
  453. return(dbl_to_dbl_fcnvfxt(&fpregs[r1],0,
  454. &fpregs[t],status));
  455. }
  456. BUG();
  457. case 5: /* FCNVUF (PA2.0 only) */
  458. switch(fmt) {
  459. case 0: /* sgl/sgl */
  460. return(sgl_to_sgl_fcnvuf(&fpregs[r1],0,
  461. &fpregs[t],status));
  462. case 1: /* sgl/dbl */
  463. return(sgl_to_dbl_fcnvuf(&fpregs[r1],0,
  464. &fpregs[t],status));
  465. case 2: /* dbl/sgl */
  466. return(dbl_to_sgl_fcnvuf(&fpregs[r1],0,
  467. &fpregs[t],status));
  468. case 3: /* dbl/dbl */
  469. return(dbl_to_dbl_fcnvuf(&fpregs[r1],0,
  470. &fpregs[t],status));
  471. }
  472. BUG();
  473. case 6: /* FCNVFU (PA2.0 only) */
  474. switch(fmt) {
  475. case 0: /* sgl/sgl */
  476. return(sgl_to_sgl_fcnvfu(&fpregs[r1],0,
  477. &fpregs[t],status));
  478. case 1: /* sgl/dbl */
  479. return(sgl_to_dbl_fcnvfu(&fpregs[r1],0,
  480. &fpregs[t],status));
  481. case 2: /* dbl/sgl */
  482. return(dbl_to_sgl_fcnvfu(&fpregs[r1],0,
  483. &fpregs[t],status));
  484. case 3: /* dbl/dbl */
  485. return(dbl_to_dbl_fcnvfu(&fpregs[r1],0,
  486. &fpregs[t],status));
  487. }
  488. BUG();
  489. case 7: /* FCNVFUT (PA2.0 only) */
  490. switch(fmt) {
  491. case 0: /* sgl/sgl */
  492. return(sgl_to_sgl_fcnvfut(&fpregs[r1],0,
  493. &fpregs[t],status));
  494. case 1: /* sgl/dbl */
  495. return(sgl_to_dbl_fcnvfut(&fpregs[r1],0,
  496. &fpregs[t],status));
  497. case 2: /* dbl/sgl */
  498. return(dbl_to_sgl_fcnvfut(&fpregs[r1],0,
  499. &fpregs[t],status));
  500. case 3: /* dbl/dbl */
  501. return(dbl_to_dbl_fcnvfut(&fpregs[r1],0,
  502. &fpregs[t],status));
  503. }
  504. BUG();
  505. case 4: /* undefined */
  506. return(MAJOR_0C_EXCP);
  507. } /* end of switch subop */
  508. BUG();
  509. case 2: /* class 2 */
  510. fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS];
  511. r2 = extru(ir, fpr2pos, 5) * sizeof(double)/sizeof(u_int);
  512. if (r2 == 0)
  513. r2 = fpzeroreg;
  514. if (fpu_type_flags & PA2_0_FPU_FLAG) {
  515. /* FTEST if nullify bit set, otherwise FCMP */
  516. if (extru(ir, fpnulpos, 1)) { /* FTEST */
  517. switch (fmt) {
  518. case 0:
  519. /*
  520. * arg0 is not used
  521. * second param is the t field used for
  522. * ftest,acc and ftest,rej
  523. * third param is the subop (y-field)
  524. */
  525. BUG();
  526. /* Unsupported
  527. * return(ftest(0L,extru(ir,fptpos,5),
  528. * &fpregs[0],subop));
  529. */
  530. case 1:
  531. case 2:
  532. case 3:
  533. return(MAJOR_0C_EXCP);
  534. }
  535. } else { /* FCMP */
  536. switch (fmt) {
  537. case 0:
  538. retval = sgl_fcmp(&fpregs[r1],
  539. &fpregs[r2],extru(ir,fptpos,5),
  540. &local_status);
  541. update_status_cbit(status,local_status,
  542. fpu_type_flags, subop);
  543. return(retval);
  544. case 1:
  545. retval = dbl_fcmp(&fpregs[r1],
  546. &fpregs[r2],extru(ir,fptpos,5),
  547. &local_status);
  548. update_status_cbit(status,local_status,
  549. fpu_type_flags, subop);
  550. return(retval);
  551. case 2: /* illegal */
  552. case 3: /* quad not implemented */
  553. return(MAJOR_0C_EXCP);
  554. }
  555. }
  556. } /* end of if for PA2.0 */
  557. else { /* PA1.0 & PA1.1 */
  558. switch (subop) {
  559. case 2:
  560. case 3:
  561. case 4:
  562. case 5:
  563. case 6:
  564. case 7:
  565. return(MAJOR_0C_EXCP);
  566. case 0: /* FCMP */
  567. switch (fmt) {
  568. case 0:
  569. retval = sgl_fcmp(&fpregs[r1],
  570. &fpregs[r2],extru(ir,fptpos,5),
  571. &local_status);
  572. update_status_cbit(status,local_status,
  573. fpu_type_flags, subop);
  574. return(retval);
  575. case 1:
  576. retval = dbl_fcmp(&fpregs[r1],
  577. &fpregs[r2],extru(ir,fptpos,5),
  578. &local_status);
  579. update_status_cbit(status,local_status,
  580. fpu_type_flags, subop);
  581. return(retval);
  582. case 2: /* illegal */
  583. case 3: /* quad not implemented */
  584. return(MAJOR_0C_EXCP);
  585. }
  586. BUG();
  587. case 1: /* FTEST */
  588. switch (fmt) {
  589. case 0:
  590. /*
  591. * arg0 is not used
  592. * second param is the t field used for
  593. * ftest,acc and ftest,rej
  594. * third param is the subop (y-field)
  595. */
  596. BUG();
  597. /* unsupported
  598. * return(ftest(0L,extru(ir,fptpos,5),
  599. * &fpregs[0],subop));
  600. */
  601. case 1:
  602. case 2:
  603. case 3:
  604. return(MAJOR_0C_EXCP);
  605. }
  606. BUG();
  607. } /* end of switch subop */
  608. } /* end of else for PA1.0 & PA1.1 */
  609. BUG();
  610. case 3: /* class 3 */
  611. r2 = extru(ir,fpr2pos,5) * sizeof(double)/sizeof(u_int);
  612. if (r2 == 0)
  613. r2 = fpzeroreg;
  614. switch (subop) {
  615. case 5:
  616. case 6:
  617. case 7:
  618. return(MAJOR_0C_EXCP);
  619. case 0: /* FADD */
  620. switch (fmt) {
  621. case 0:
  622. return(sgl_fadd(&fpregs[r1],&fpregs[r2],
  623. &fpregs[t],status));
  624. case 1:
  625. return(dbl_fadd(&fpregs[r1],&fpregs[r2],
  626. &fpregs[t],status));
  627. case 2: /* illegal */
  628. case 3: /* quad not implemented */
  629. return(MAJOR_0C_EXCP);
  630. }
  631. BUG();
  632. case 1: /* FSUB */
  633. switch (fmt) {
  634. case 0:
  635. return(sgl_fsub(&fpregs[r1],&fpregs[r2],
  636. &fpregs[t],status));
  637. case 1:
  638. return(dbl_fsub(&fpregs[r1],&fpregs[r2],
  639. &fpregs[t],status));
  640. case 2: /* illegal */
  641. case 3: /* quad not implemented */
  642. return(MAJOR_0C_EXCP);
  643. }
  644. BUG();
  645. case 2: /* FMPY */
  646. switch (fmt) {
  647. case 0:
  648. return(sgl_fmpy(&fpregs[r1],&fpregs[r2],
  649. &fpregs[t],status));
  650. case 1:
  651. return(dbl_fmpy(&fpregs[r1],&fpregs[r2],
  652. &fpregs[t],status));
  653. case 2: /* illegal */
  654. case 3: /* quad not implemented */
  655. return(MAJOR_0C_EXCP);
  656. }
  657. BUG();
  658. case 3: /* FDIV */
  659. switch (fmt) {
  660. case 0:
  661. return(sgl_fdiv(&fpregs[r1],&fpregs[r2],
  662. &fpregs[t],status));
  663. case 1:
  664. return(dbl_fdiv(&fpregs[r1],&fpregs[r2],
  665. &fpregs[t],status));
  666. case 2: /* illegal */
  667. case 3: /* quad not implemented */
  668. return(MAJOR_0C_EXCP);
  669. }
  670. BUG();
  671. case 4: /* FREM */
  672. switch (fmt) {
  673. case 0:
  674. return(sgl_frem(&fpregs[r1],&fpregs[r2],
  675. &fpregs[t],status));
  676. case 1:
  677. return(dbl_frem(&fpregs[r1],&fpregs[r2],
  678. &fpregs[t],status));
  679. case 2: /* illegal */
  680. case 3: /* quad not implemented */
  681. return(MAJOR_0C_EXCP);
  682. }
  683. BUG();
  684. } /* end of class 3 switch */
  685. } /* end of switch(class) */
  686. /* If we get here, something is really wrong! */
  687. return(MAJOR_0C_EXCP);
  688. }
  689. static u_int
  690. decode_0e(ir,class,subop,fpregs)
  691. u_int ir,class,subop;
  692. u_int fpregs[];
  693. {
  694. u_int r1,r2,t; /* operand register offsets */
  695. u_int fmt; /* also sf for class 1 conversions */
  696. u_int df; /* dest format for class 1 conversions */
  697. u_int *status;
  698. u_int retval, local_status;
  699. u_int fpu_type_flags;
  700. status = &fpregs[0];
  701. local_status = fpregs[0];
  702. r1 = ((extru(ir,fpr1pos,5)<<1)|(extru(ir,fpxr1pos,1)));
  703. if (r1 == 0)
  704. r1 = fpzeroreg;
  705. t = ((extru(ir,fptpos,5)<<1)|(extru(ir,fpxtpos,1)));
  706. if (t == 0 && class != 2)
  707. return(MAJOR_0E_EXCP);
  708. if (class < 2) /* class 0 or 1 has 2 bit fmt */
  709. fmt = extru(ir,fpfmtpos,2);
  710. else /* class 2 and 3 have 1 bit fmt */
  711. fmt = extru(ir,fp0efmtpos,1);
  712. /*
  713. * An undefined combination, double precision accessing the
  714. * right half of a FPR, can get us into trouble.
  715. * Let's just force proper alignment on it.
  716. */
  717. if (fmt == DBL) {
  718. r1 &= ~1;
  719. if (class != 1)
  720. t &= ~1;
  721. }
  722. switch (class) {
  723. case 0:
  724. switch (subop) {
  725. case 0: /* unimplemented */
  726. case 1:
  727. return(MAJOR_0E_EXCP);
  728. case 2: /* FCPY */
  729. switch (fmt) {
  730. case 2:
  731. case 3:
  732. return(MAJOR_0E_EXCP);
  733. case 1: /* double */
  734. fpregs[t+1] = fpregs[r1+1];
  735. fallthrough;
  736. case 0: /* single */
  737. fpregs[t] = fpregs[r1];
  738. return(NOEXCEPTION);
  739. }
  740. BUG();
  741. case 3: /* FABS */
  742. switch (fmt) {
  743. case 2:
  744. case 3:
  745. return(MAJOR_0E_EXCP);
  746. case 1: /* double */
  747. fpregs[t+1] = fpregs[r1+1];
  748. fallthrough;
  749. case 0: /* single */
  750. fpregs[t] = fpregs[r1] & 0x7fffffff;
  751. return(NOEXCEPTION);
  752. }
  753. BUG();
  754. case 6: /* FNEG */
  755. switch (fmt) {
  756. case 2:
  757. case 3:
  758. return(MAJOR_0E_EXCP);
  759. case 1: /* double */
  760. fpregs[t+1] = fpregs[r1+1];
  761. fallthrough;
  762. case 0: /* single */
  763. fpregs[t] = fpregs[r1] ^ 0x80000000;
  764. return(NOEXCEPTION);
  765. }
  766. BUG();
  767. case 7: /* FNEGABS */
  768. switch (fmt) {
  769. case 2:
  770. case 3:
  771. return(MAJOR_0E_EXCP);
  772. case 1: /* double */
  773. fpregs[t+1] = fpregs[r1+1];
  774. fallthrough;
  775. case 0: /* single */
  776. fpregs[t] = fpregs[r1] | 0x80000000;
  777. return(NOEXCEPTION);
  778. }
  779. BUG();
  780. case 4: /* FSQRT */
  781. switch (fmt) {
  782. case 0:
  783. return(sgl_fsqrt(&fpregs[r1],0,
  784. &fpregs[t], status));
  785. case 1:
  786. return(dbl_fsqrt(&fpregs[r1],0,
  787. &fpregs[t], status));
  788. case 2:
  789. case 3:
  790. return(MAJOR_0E_EXCP);
  791. }
  792. BUG();
  793. case 5: /* FRMD */
  794. switch (fmt) {
  795. case 0:
  796. return(sgl_frnd(&fpregs[r1],0,
  797. &fpregs[t], status));
  798. case 1:
  799. return(dbl_frnd(&fpregs[r1],0,
  800. &fpregs[t], status));
  801. case 2:
  802. case 3:
  803. return(MAJOR_0E_EXCP);
  804. }
  805. } /* end of switch (subop */
  806. BUG();
  807. case 1: /* class 1 */
  808. df = extru(ir,fpdfpos,2); /* get dest format */
  809. /*
  810. * Fix Crashme problem (writing to 31R in double precision)
  811. * here too.
  812. */
  813. if (df == DBL) {
  814. t &= ~1;
  815. }
  816. if ((df & 2) || (fmt & 2))
  817. return(MAJOR_0E_EXCP);
  818. fmt = (fmt << 1) | df;
  819. switch (subop) {
  820. case 0: /* FCNVFF */
  821. switch(fmt) {
  822. case 0: /* sgl/sgl */
  823. return(MAJOR_0E_EXCP);
  824. case 1: /* sgl/dbl */
  825. return(sgl_to_dbl_fcnvff(&fpregs[r1],0,
  826. &fpregs[t],status));
  827. case 2: /* dbl/sgl */
  828. return(dbl_to_sgl_fcnvff(&fpregs[r1],0,
  829. &fpregs[t],status));
  830. case 3: /* dbl/dbl */
  831. return(MAJOR_0E_EXCP);
  832. }
  833. BUG();
  834. case 1: /* FCNVXF */
  835. switch(fmt) {
  836. case 0: /* sgl/sgl */
  837. return(sgl_to_sgl_fcnvxf(&fpregs[r1],0,
  838. &fpregs[t],status));
  839. case 1: /* sgl/dbl */
  840. return(sgl_to_dbl_fcnvxf(&fpregs[r1],0,
  841. &fpregs[t],status));
  842. case 2: /* dbl/sgl */
  843. return(dbl_to_sgl_fcnvxf(&fpregs[r1],0,
  844. &fpregs[t],status));
  845. case 3: /* dbl/dbl */
  846. return(dbl_to_dbl_fcnvxf(&fpregs[r1],0,
  847. &fpregs[t],status));
  848. }
  849. BUG();
  850. case 2: /* FCNVFX */
  851. switch(fmt) {
  852. case 0: /* sgl/sgl */
  853. return(sgl_to_sgl_fcnvfx(&fpregs[r1],0,
  854. &fpregs[t],status));
  855. case 1: /* sgl/dbl */
  856. return(sgl_to_dbl_fcnvfx(&fpregs[r1],0,
  857. &fpregs[t],status));
  858. case 2: /* dbl/sgl */
  859. return(dbl_to_sgl_fcnvfx(&fpregs[r1],0,
  860. &fpregs[t],status));
  861. case 3: /* dbl/dbl */
  862. return(dbl_to_dbl_fcnvfx(&fpregs[r1],0,
  863. &fpregs[t],status));
  864. }
  865. BUG();
  866. case 3: /* FCNVFXT */
  867. switch(fmt) {
  868. case 0: /* sgl/sgl */
  869. return(sgl_to_sgl_fcnvfxt(&fpregs[r1],0,
  870. &fpregs[t],status));
  871. case 1: /* sgl/dbl */
  872. return(sgl_to_dbl_fcnvfxt(&fpregs[r1],0,
  873. &fpregs[t],status));
  874. case 2: /* dbl/sgl */
  875. return(dbl_to_sgl_fcnvfxt(&fpregs[r1],0,
  876. &fpregs[t],status));
  877. case 3: /* dbl/dbl */
  878. return(dbl_to_dbl_fcnvfxt(&fpregs[r1],0,
  879. &fpregs[t],status));
  880. }
  881. BUG();
  882. case 5: /* FCNVUF (PA2.0 only) */
  883. switch(fmt) {
  884. case 0: /* sgl/sgl */
  885. return(sgl_to_sgl_fcnvuf(&fpregs[r1],0,
  886. &fpregs[t],status));
  887. case 1: /* sgl/dbl */
  888. return(sgl_to_dbl_fcnvuf(&fpregs[r1],0,
  889. &fpregs[t],status));
  890. case 2: /* dbl/sgl */
  891. return(dbl_to_sgl_fcnvuf(&fpregs[r1],0,
  892. &fpregs[t],status));
  893. case 3: /* dbl/dbl */
  894. return(dbl_to_dbl_fcnvuf(&fpregs[r1],0,
  895. &fpregs[t],status));
  896. }
  897. BUG();
  898. case 6: /* FCNVFU (PA2.0 only) */
  899. switch(fmt) {
  900. case 0: /* sgl/sgl */
  901. return(sgl_to_sgl_fcnvfu(&fpregs[r1],0,
  902. &fpregs[t],status));
  903. case 1: /* sgl/dbl */
  904. return(sgl_to_dbl_fcnvfu(&fpregs[r1],0,
  905. &fpregs[t],status));
  906. case 2: /* dbl/sgl */
  907. return(dbl_to_sgl_fcnvfu(&fpregs[r1],0,
  908. &fpregs[t],status));
  909. case 3: /* dbl/dbl */
  910. return(dbl_to_dbl_fcnvfu(&fpregs[r1],0,
  911. &fpregs[t],status));
  912. }
  913. BUG();
  914. case 7: /* FCNVFUT (PA2.0 only) */
  915. switch(fmt) {
  916. case 0: /* sgl/sgl */
  917. return(sgl_to_sgl_fcnvfut(&fpregs[r1],0,
  918. &fpregs[t],status));
  919. case 1: /* sgl/dbl */
  920. return(sgl_to_dbl_fcnvfut(&fpregs[r1],0,
  921. &fpregs[t],status));
  922. case 2: /* dbl/sgl */
  923. return(dbl_to_sgl_fcnvfut(&fpregs[r1],0,
  924. &fpregs[t],status));
  925. case 3: /* dbl/dbl */
  926. return(dbl_to_dbl_fcnvfut(&fpregs[r1],0,
  927. &fpregs[t],status));
  928. }
  929. BUG();
  930. case 4: /* undefined */
  931. return(MAJOR_0C_EXCP);
  932. } /* end of switch subop */
  933. BUG();
  934. case 2: /* class 2 */
  935. /*
  936. * Be careful out there.
  937. * Crashme can generate cases where FR31R is specified
  938. * as the source or target of a double precision operation.
  939. * Since we just pass the address of the floating-point
  940. * register to the emulation routines, this can cause
  941. * corruption of fpzeroreg.
  942. */
  943. if (fmt == DBL)
  944. r2 = (extru(ir,fpr2pos,5)<<1);
  945. else
  946. r2 = ((extru(ir,fpr2pos,5)<<1)|(extru(ir,fpxr2pos,1)));
  947. fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS];
  948. if (r2 == 0)
  949. r2 = fpzeroreg;
  950. if (fpu_type_flags & PA2_0_FPU_FLAG) {
  951. /* FTEST if nullify bit set, otherwise FCMP */
  952. if (extru(ir, fpnulpos, 1)) { /* FTEST */
  953. /* not legal */
  954. return(MAJOR_0E_EXCP);
  955. } else { /* FCMP */
  956. switch (fmt) {
  957. /*
  958. * fmt is only 1 bit long
  959. */
  960. case 0:
  961. retval = sgl_fcmp(&fpregs[r1],
  962. &fpregs[r2],extru(ir,fptpos,5),
  963. &local_status);
  964. update_status_cbit(status,local_status,
  965. fpu_type_flags, subop);
  966. return(retval);
  967. case 1:
  968. retval = dbl_fcmp(&fpregs[r1],
  969. &fpregs[r2],extru(ir,fptpos,5),
  970. &local_status);
  971. update_status_cbit(status,local_status,
  972. fpu_type_flags, subop);
  973. return(retval);
  974. }
  975. }
  976. } /* end of if for PA2.0 */
  977. else { /* PA1.0 & PA1.1 */
  978. switch (subop) {
  979. case 1:
  980. case 2:
  981. case 3:
  982. case 4:
  983. case 5:
  984. case 6:
  985. case 7:
  986. return(MAJOR_0E_EXCP);
  987. case 0: /* FCMP */
  988. switch (fmt) {
  989. /*
  990. * fmt is only 1 bit long
  991. */
  992. case 0:
  993. retval = sgl_fcmp(&fpregs[r1],
  994. &fpregs[r2],extru(ir,fptpos,5),
  995. &local_status);
  996. update_status_cbit(status,local_status,
  997. fpu_type_flags, subop);
  998. return(retval);
  999. case 1:
  1000. retval = dbl_fcmp(&fpregs[r1],
  1001. &fpregs[r2],extru(ir,fptpos,5),
  1002. &local_status);
  1003. update_status_cbit(status,local_status,
  1004. fpu_type_flags, subop);
  1005. return(retval);
  1006. }
  1007. } /* end of switch subop */
  1008. } /* end of else for PA1.0 & PA1.1 */
  1009. BUG();
  1010. case 3: /* class 3 */
  1011. /*
  1012. * Be careful out there.
  1013. * Crashme can generate cases where FR31R is specified
  1014. * as the source or target of a double precision operation.
  1015. * Since we just pass the address of the floating-point
  1016. * register to the emulation routines, this can cause
  1017. * corruption of fpzeroreg.
  1018. */
  1019. if (fmt == DBL)
  1020. r2 = (extru(ir,fpr2pos,5)<<1);
  1021. else
  1022. r2 = ((extru(ir,fpr2pos,5)<<1)|(extru(ir,fpxr2pos,1)));
  1023. if (r2 == 0)
  1024. r2 = fpzeroreg;
  1025. switch (subop) {
  1026. case 5:
  1027. case 6:
  1028. case 7:
  1029. return(MAJOR_0E_EXCP);
  1030. /*
  1031. * Note that fmt is only 1 bit for class 3 */
  1032. case 0: /* FADD */
  1033. switch (fmt) {
  1034. case 0:
  1035. return(sgl_fadd(&fpregs[r1],&fpregs[r2],
  1036. &fpregs[t],status));
  1037. case 1:
  1038. return(dbl_fadd(&fpregs[r1],&fpregs[r2],
  1039. &fpregs[t],status));
  1040. }
  1041. BUG();
  1042. case 1: /* FSUB */
  1043. switch (fmt) {
  1044. case 0:
  1045. return(sgl_fsub(&fpregs[r1],&fpregs[r2],
  1046. &fpregs[t],status));
  1047. case 1:
  1048. return(dbl_fsub(&fpregs[r1],&fpregs[r2],
  1049. &fpregs[t],status));
  1050. }
  1051. BUG();
  1052. case 2: /* FMPY or XMPYU */
  1053. /*
  1054. * check for integer multiply (x bit set)
  1055. */
  1056. if (extru(ir,fpxpos,1)) {
  1057. /*
  1058. * emulate XMPYU
  1059. */
  1060. switch (fmt) {
  1061. case 0:
  1062. /*
  1063. * bad instruction if t specifies
  1064. * the right half of a register
  1065. */
  1066. if (t & 1)
  1067. return(MAJOR_0E_EXCP);
  1068. BUG();
  1069. /* unsupported
  1070. * impyu(&fpregs[r1],&fpregs[r2],
  1071. * &fpregs[t]);
  1072. */
  1073. return(NOEXCEPTION);
  1074. case 1:
  1075. return(MAJOR_0E_EXCP);
  1076. }
  1077. }
  1078. else { /* FMPY */
  1079. switch (fmt) {
  1080. case 0:
  1081. return(sgl_fmpy(&fpregs[r1],
  1082. &fpregs[r2],&fpregs[t],status));
  1083. case 1:
  1084. return(dbl_fmpy(&fpregs[r1],
  1085. &fpregs[r2],&fpregs[t],status));
  1086. }
  1087. }
  1088. BUG();
  1089. case 3: /* FDIV */
  1090. switch (fmt) {
  1091. case 0:
  1092. return(sgl_fdiv(&fpregs[r1],&fpregs[r2],
  1093. &fpregs[t],status));
  1094. case 1:
  1095. return(dbl_fdiv(&fpregs[r1],&fpregs[r2],
  1096. &fpregs[t],status));
  1097. }
  1098. BUG();
  1099. case 4: /* FREM */
  1100. switch (fmt) {
  1101. case 0:
  1102. return(sgl_frem(&fpregs[r1],&fpregs[r2],
  1103. &fpregs[t],status));
  1104. case 1:
  1105. return(dbl_frem(&fpregs[r1],&fpregs[r2],
  1106. &fpregs[t],status));
  1107. }
  1108. } /* end of class 3 switch */
  1109. } /* end of switch(class) */
  1110. /* If we get here, something is really wrong! */
  1111. return(MAJOR_0E_EXCP);
  1112. }
  1113. /*
  1114. * routine to decode the 06 (FMPYADD and FMPYCFXT) instruction
  1115. */
  1116. static u_int
  1117. decode_06(ir,fpregs)
  1118. u_int ir;
  1119. u_int fpregs[];
  1120. {
  1121. u_int rm1, rm2, tm, ra, ta; /* operands */
  1122. u_int fmt;
  1123. u_int error = 0;
  1124. u_int status;
  1125. u_int fpu_type_flags;
  1126. union {
  1127. double dbl;
  1128. float flt;
  1129. struct { u_int i1; u_int i2; } ints;
  1130. } mtmp, atmp;
  1131. status = fpregs[0]; /* use a local copy of status reg */
  1132. fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
  1133. fmt = extru(ir, fpmultifmt, 1); /* get sgl/dbl flag */
  1134. if (fmt == 0) { /* DBL */
  1135. rm1 = extru(ir, fprm1pos, 5) * sizeof(double)/sizeof(u_int);
  1136. if (rm1 == 0)
  1137. rm1 = fpzeroreg;
  1138. rm2 = extru(ir, fprm2pos, 5) * sizeof(double)/sizeof(u_int);
  1139. if (rm2 == 0)
  1140. rm2 = fpzeroreg;
  1141. tm = extru(ir, fptmpos, 5) * sizeof(double)/sizeof(u_int);
  1142. if (tm == 0)
  1143. return(MAJOR_06_EXCP);
  1144. ra = extru(ir, fprapos, 5) * sizeof(double)/sizeof(u_int);
  1145. ta = extru(ir, fptapos, 5) * sizeof(double)/sizeof(u_int);
  1146. if (ta == 0)
  1147. return(MAJOR_06_EXCP);
  1148. if (fpu_type_flags & TIMEX_ROLEX_FPU_MASK) {
  1149. if (ra == 0) {
  1150. /* special case FMPYCFXT, see sgl case below */
  1151. if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],
  1152. &mtmp.ints.i1,&status))
  1153. error = 1;
  1154. if (dbl_to_sgl_fcnvfxt(&fpregs[ta],
  1155. &atmp.ints.i1,&atmp.ints.i1,&status))
  1156. error = 1;
  1157. }
  1158. else {
  1159. if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
  1160. &status))
  1161. error = 1;
  1162. if (dbl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
  1163. &status))
  1164. error = 1;
  1165. }
  1166. }
  1167. else
  1168. {
  1169. if (ra == 0)
  1170. ra = fpzeroreg;
  1171. if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
  1172. &status))
  1173. error = 1;
  1174. if (dbl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
  1175. &status))
  1176. error = 1;
  1177. }
  1178. if (error)
  1179. return(MAJOR_06_EXCP);
  1180. else {
  1181. /* copy results */
  1182. fpregs[tm] = mtmp.ints.i1;
  1183. fpregs[tm+1] = mtmp.ints.i2;
  1184. fpregs[ta] = atmp.ints.i1;
  1185. fpregs[ta+1] = atmp.ints.i2;
  1186. fpregs[0] = status;
  1187. return(NOEXCEPTION);
  1188. }
  1189. }
  1190. else { /* SGL */
  1191. /*
  1192. * calculate offsets for single precision numbers
  1193. * See table 6-14 in PA-89 architecture for mapping
  1194. */
  1195. rm1 = (extru(ir,fprm1pos,4) | 0x10 ) << 1; /* get offset */
  1196. rm1 |= extru(ir,fprm1pos-4,1); /* add right word offset */
  1197. rm2 = (extru(ir,fprm2pos,4) | 0x10 ) << 1; /* get offset */
  1198. rm2 |= extru(ir,fprm2pos-4,1); /* add right word offset */
  1199. tm = (extru(ir,fptmpos,4) | 0x10 ) << 1; /* get offset */
  1200. tm |= extru(ir,fptmpos-4,1); /* add right word offset */
  1201. ra = (extru(ir,fprapos,4) | 0x10 ) << 1; /* get offset */
  1202. ra |= extru(ir,fprapos-4,1); /* add right word offset */
  1203. ta = (extru(ir,fptapos,4) | 0x10 ) << 1; /* get offset */
  1204. ta |= extru(ir,fptapos-4,1); /* add right word offset */
  1205. if (ra == 0x20 &&(fpu_type_flags & TIMEX_ROLEX_FPU_MASK)) {
  1206. /* special case FMPYCFXT (really 0)
  1207. * This instruction is only present on the Timex and
  1208. * Rolex fpu's in so if it is the special case and
  1209. * one of these fpu's we run the FMPYCFXT instruction
  1210. */
  1211. if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
  1212. &status))
  1213. error = 1;
  1214. if (sgl_to_sgl_fcnvfxt(&fpregs[ta],&atmp.ints.i1,
  1215. &atmp.ints.i1,&status))
  1216. error = 1;
  1217. }
  1218. else {
  1219. if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
  1220. &status))
  1221. error = 1;
  1222. if (sgl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
  1223. &status))
  1224. error = 1;
  1225. }
  1226. if (error)
  1227. return(MAJOR_06_EXCP);
  1228. else {
  1229. /* copy results */
  1230. fpregs[tm] = mtmp.ints.i1;
  1231. fpregs[ta] = atmp.ints.i1;
  1232. fpregs[0] = status;
  1233. return(NOEXCEPTION);
  1234. }
  1235. }
  1236. }
  1237. /*
  1238. * routine to decode the 26 (FMPYSUB) instruction
  1239. */
  1240. static u_int
  1241. decode_26(ir,fpregs)
  1242. u_int ir;
  1243. u_int fpregs[];
  1244. {
  1245. u_int rm1, rm2, tm, ra, ta; /* operands */
  1246. u_int fmt;
  1247. u_int error = 0;
  1248. u_int status;
  1249. union {
  1250. double dbl;
  1251. float flt;
  1252. struct { u_int i1; u_int i2; } ints;
  1253. } mtmp, atmp;
  1254. status = fpregs[0];
  1255. fmt = extru(ir, fpmultifmt, 1); /* get sgl/dbl flag */
  1256. if (fmt == 0) { /* DBL */
  1257. rm1 = extru(ir, fprm1pos, 5) * sizeof(double)/sizeof(u_int);
  1258. if (rm1 == 0)
  1259. rm1 = fpzeroreg;
  1260. rm2 = extru(ir, fprm2pos, 5) * sizeof(double)/sizeof(u_int);
  1261. if (rm2 == 0)
  1262. rm2 = fpzeroreg;
  1263. tm = extru(ir, fptmpos, 5) * sizeof(double)/sizeof(u_int);
  1264. if (tm == 0)
  1265. return(MAJOR_26_EXCP);
  1266. ra = extru(ir, fprapos, 5) * sizeof(double)/sizeof(u_int);
  1267. if (ra == 0)
  1268. return(MAJOR_26_EXCP);
  1269. ta = extru(ir, fptapos, 5) * sizeof(double)/sizeof(u_int);
  1270. if (ta == 0)
  1271. return(MAJOR_26_EXCP);
  1272. if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,&status))
  1273. error = 1;
  1274. if (dbl_fsub(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,&status))
  1275. error = 1;
  1276. if (error)
  1277. return(MAJOR_26_EXCP);
  1278. else {
  1279. /* copy results */
  1280. fpregs[tm] = mtmp.ints.i1;
  1281. fpregs[tm+1] = mtmp.ints.i2;
  1282. fpregs[ta] = atmp.ints.i1;
  1283. fpregs[ta+1] = atmp.ints.i2;
  1284. fpregs[0] = status;
  1285. return(NOEXCEPTION);
  1286. }
  1287. }
  1288. else { /* SGL */
  1289. /*
  1290. * calculate offsets for single precision numbers
  1291. * See table 6-14 in PA-89 architecture for mapping
  1292. */
  1293. rm1 = (extru(ir,fprm1pos,4) | 0x10 ) << 1; /* get offset */
  1294. rm1 |= extru(ir,fprm1pos-4,1); /* add right word offset */
  1295. rm2 = (extru(ir,fprm2pos,4) | 0x10 ) << 1; /* get offset */
  1296. rm2 |= extru(ir,fprm2pos-4,1); /* add right word offset */
  1297. tm = (extru(ir,fptmpos,4) | 0x10 ) << 1; /* get offset */
  1298. tm |= extru(ir,fptmpos-4,1); /* add right word offset */
  1299. ra = (extru(ir,fprapos,4) | 0x10 ) << 1; /* get offset */
  1300. ra |= extru(ir,fprapos-4,1); /* add right word offset */
  1301. ta = (extru(ir,fptapos,4) | 0x10 ) << 1; /* get offset */
  1302. ta |= extru(ir,fptapos-4,1); /* add right word offset */
  1303. if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,&status))
  1304. error = 1;
  1305. if (sgl_fsub(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,&status))
  1306. error = 1;
  1307. if (error)
  1308. return(MAJOR_26_EXCP);
  1309. else {
  1310. /* copy results */
  1311. fpregs[tm] = mtmp.ints.i1;
  1312. fpregs[ta] = atmp.ints.i1;
  1313. fpregs[0] = status;
  1314. return(NOEXCEPTION);
  1315. }
  1316. }
  1317. }
  1318. /*
  1319. * routine to decode the 2E (FMPYFADD,FMPYNFADD) instructions
  1320. */
  1321. static u_int
  1322. decode_2e(ir,fpregs)
  1323. u_int ir;
  1324. u_int fpregs[];
  1325. {
  1326. u_int rm1, rm2, ra, t; /* operands */
  1327. u_int fmt;
  1328. fmt = extru(ir,fpfmtpos,1); /* get fmt completer */
  1329. if (fmt == DBL) { /* DBL */
  1330. rm1 = extru(ir,fprm1pos,5) * sizeof(double)/sizeof(u_int);
  1331. if (rm1 == 0)
  1332. rm1 = fpzeroreg;
  1333. rm2 = extru(ir,fprm2pos,5) * sizeof(double)/sizeof(u_int);
  1334. if (rm2 == 0)
  1335. rm2 = fpzeroreg;
  1336. ra = ((extru(ir,fpraupos,3)<<2)|(extru(ir,fpralpos,3)>>1)) *
  1337. sizeof(double)/sizeof(u_int);
  1338. if (ra == 0)
  1339. ra = fpzeroreg;
  1340. t = extru(ir,fptpos,5) * sizeof(double)/sizeof(u_int);
  1341. if (t == 0)
  1342. return(MAJOR_2E_EXCP);
  1343. if (extru(ir,fpfusedsubop,1)) { /* fmpyfadd or fmpynfadd? */
  1344. return(dbl_fmpynfadd(&fpregs[rm1], &fpregs[rm2],
  1345. &fpregs[ra], &fpregs[0], &fpregs[t]));
  1346. } else {
  1347. return(dbl_fmpyfadd(&fpregs[rm1], &fpregs[rm2],
  1348. &fpregs[ra], &fpregs[0], &fpregs[t]));
  1349. }
  1350. } /* end DBL */
  1351. else { /* SGL */
  1352. rm1 = (extru(ir,fprm1pos,5)<<1)|(extru(ir,fpxrm1pos,1));
  1353. if (rm1 == 0)
  1354. rm1 = fpzeroreg;
  1355. rm2 = (extru(ir,fprm2pos,5)<<1)|(extru(ir,fpxrm2pos,1));
  1356. if (rm2 == 0)
  1357. rm2 = fpzeroreg;
  1358. ra = (extru(ir,fpraupos,3)<<3)|extru(ir,fpralpos,3);
  1359. if (ra == 0)
  1360. ra = fpzeroreg;
  1361. t = ((extru(ir,fptpos,5)<<1)|(extru(ir,fpxtpos,1)));
  1362. if (t == 0)
  1363. return(MAJOR_2E_EXCP);
  1364. if (extru(ir,fpfusedsubop,1)) { /* fmpyfadd or fmpynfadd? */
  1365. return(sgl_fmpynfadd(&fpregs[rm1], &fpregs[rm2],
  1366. &fpregs[ra], &fpregs[0], &fpregs[t]));
  1367. } else {
  1368. return(sgl_fmpyfadd(&fpregs[rm1], &fpregs[rm2],
  1369. &fpregs[ra], &fpregs[0], &fpregs[t]));
  1370. }
  1371. } /* end SGL */
  1372. }
  1373. /*
  1374. * update_status_cbit
  1375. *
  1376. * This routine returns the correct FP status register value in
  1377. * *status, based on the C-bit & V-bit returned by the FCMP
  1378. * emulation routine in new_status. The architecture type
  1379. * (PA83, PA89 or PA2.0) is available in fpu_type. The y_field
  1380. * and the architecture type are used to determine what flavor
  1381. * of FCMP is being emulated.
  1382. */
  1383. static void
  1384. update_status_cbit(status, new_status, fpu_type, y_field)
  1385. u_int *status, new_status;
  1386. u_int fpu_type;
  1387. u_int y_field;
  1388. {
  1389. /*
  1390. * For PA89 FPU's which implement the Compare Queue and
  1391. * for PA2.0 FPU's, update the Compare Queue if the y-field = 0,
  1392. * otherwise update the specified bit in the Compare Array.
  1393. * Note that the y-field will always be 0 for non-PA2.0 FPU's.
  1394. */
  1395. if ((fpu_type & TIMEX_EXTEN_FLAG) ||
  1396. (fpu_type & ROLEX_EXTEN_FLAG) ||
  1397. (fpu_type & PA2_0_FPU_FLAG)) {
  1398. if (y_field == 0) {
  1399. *status = ((*status & 0x04000000) >> 5) | /* old Cbit */
  1400. ((*status & 0x003ff000) >> 1) | /* old CQ */
  1401. (new_status & 0xffc007ff); /* all other bits*/
  1402. } else {
  1403. *status = (*status & 0x04000000) | /* old Cbit */
  1404. ((new_status & 0x04000000) >> (y_field+4)) |
  1405. (new_status & ~0x04000000 & /* other bits */
  1406. ~(0x04000000 >> (y_field+4)));
  1407. }
  1408. }
  1409. /* if PA83, just update the C-bit */
  1410. else {
  1411. *status = new_status;
  1412. }
  1413. }