1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
12 * @(#) pa/fp/fpudispatch.c $Revision: 1.1 $
15 * <<please update with a synopsis of the functionality provided by this file>>
17 * External Interfaces:
18 * <<the following list was autogenerated, please review>>
19 * emfpudispatch(ir, dummy1, dummy2, fpregs)
20 * fpudispatch(ir, excp_code, holder, fpregs)
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)
32 * <<please update with a overview of the operation of this file>>
40 #include <linux/bug.h>
41 #include <linux/kernel.h>
42 #include <asm/processor.h>
43 /* #include <sys/debug.h> */
44 /* #include <machine/sys/mdep_private.h> */
46 #define COPR_INST 0x30000000
49 * definition of extru macro. If pos and len are constants, the compiler
50 * will generate an extru instruction when optimized
52 #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
53 /* definitions of bit field locations in the instruction */
59 #define fpclass1subpos 16
65 * the following are the extra bits for the 0E major op
73 * the following are for the multi-ops
82 * the following are for the fused FP instructions
92 #define fpfusedsubop 26
96 * offset to constant zero in the FP emulation registers
98 #define fpzeroreg (32*sizeof(double)/sizeof(u_int))
101 * extract the major opcode from the instruction
103 #define get_major(op) extru(op,fpmajorpos,6)
105 * extract the two bit class field from the FP instruction. The class is at bit
108 #define get_class(op) extru(op,fpclasspos,2)
110 * extract the 3 bit subop field. For all but class 1 instructions, it is
111 * located at bit positions 16-18
113 #define get_subop(op) extru(op,fpsubpos,3)
115 * extract the 2 or 3 bit subop field from class 1 instructions. It is located
116 * at bit positions 15-16 (PA1.1) or 14-16 (PA2.0)
118 #define get_subop1_PA1_1(op) extru(op,fpclass1subpos,2) /* PA89 (1.1) fmt */
119 #define get_subop1_PA2_0(op) extru(op,fpclass1subpos,3) /* PA 2.0 fmt */
121 /* definitions of unimplemented exceptions */
122 #define MAJOR_0C_EXCP 0x09
123 #define MAJOR_0E_EXCP 0x0b
124 #define MAJOR_06_EXCP 0x03
125 #define MAJOR_26_EXCP 0x23
126 #define MAJOR_2E_EXCP 0x2b
127 #define PA83_UNIMP_EXCP 0x01
130 * Special Defines for TIMEX specific code
133 #define FPU_TYPE_FLAG_POS (EM_FPU_TYPE_OFFSET>>2)
134 #define TIMEX_ROLEX_FPU_MASK (TIMEX_EXTEN_FLAG|ROLEX_EXTEN_FLAG)
137 * Static function definitions
140 #if defined(_PROTOTYPES) || defined(_lint)
141 static u_int decode_0c(u_int, u_int, u_int, u_int *);
142 static u_int decode_0e(u_int, u_int, u_int, u_int *);
143 static u_int decode_06(u_int, u_int *);
144 static u_int decode_26(u_int, u_int *);
145 static u_int decode_2e(u_int, u_int *);
146 static void update_status_cbit(u_int *, u_int, u_int, u_int);
147 #else /* !_PROTOTYPES&&!_lint */
148 static u_int decode_0c();
149 static u_int decode_0e();
150 static u_int decode_06();
151 static u_int decode_26();
152 static u_int decode_2e();
153 static void update_status_cbit();
154 #endif /* _PROTOTYPES&&!_lint */
158 static void parisc_linux_get_fpu_type(u_int fpregs[])
160 /* on pa-linux the fpu type is not filled in by the
161 * caller; it is constructed here
163 if (boot_cpu_data.cpu_type == pcxs)
164 fpregs[FPU_TYPE_FLAG_POS] = TIMEX_EXTEN_FLAG;
165 else if (boot_cpu_data.cpu_type == pcxt ||
166 boot_cpu_data.cpu_type == pcxt_)
167 fpregs[FPU_TYPE_FLAG_POS] = ROLEX_EXTEN_FLAG;
168 else if (boot_cpu_data.cpu_type >= pcxu)
169 fpregs[FPU_TYPE_FLAG_POS] = PA2_0_FPU_FLAG;
173 * this routine will decode the excepting floating point instruction and
174 * call the appropriate emulation routine.
175 * It is called by decode_fpu with the following parameters:
176 * fpudispatch(current_ir, unimplemented_code, 0, &Fpu_register)
177 * where current_ir is the instruction to be emulated,
178 * unimplemented_code is the exception_code that the hardware generated
179 * and &Fpu_register is the address of emulated FP reg 0.
182 fpudispatch(u_int ir, u_int excp_code, u_int holder, u_int fpregs[])
185 u_int fpu_type_flags;
187 /* All FP emulation code assumes that ints are 4-bytes in length */
188 VASSERT(sizeof(int) == 4);
190 parisc_linux_get_fpu_type(fpregs);
192 fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
194 class = get_class(ir);
196 if (fpu_type_flags & PA2_0_FPU_FLAG)
197 subop = get_subop1_PA2_0(ir);
199 subop = get_subop1_PA1_1(ir);
202 subop = get_subop(ir);
204 if (FPUDEBUG) printk("class %d subop %d\n", class, subop);
208 case PA83_UNIMP_EXCP:
209 return(decode_0c(ir,class,subop,fpregs));
211 return(decode_0e(ir,class,subop,fpregs));
213 return(decode_06(ir,fpregs));
215 return(decode_26(ir,fpregs));
217 return(decode_2e(ir,fpregs));
219 /* "crashme Night Gallery painting nr 2. (asm_crash.s).
220 * This was fixed for multi-user kernels, but
221 * workstation kernels had a panic here. This allowed
222 * any arbitrary user to panic the kernel by executing
223 * setting the FP exception registers to strange values
224 * and generating an emulation trap. The emulation and
225 * exception code must never be able to panic the
228 return(UNIMPLEMENTEDEXCEPTION);
233 * this routine is called by $emulation_trap to emulate a coprocessor
234 * instruction if one doesn't exist
237 emfpudispatch(u_int ir, u_int dummy1, u_int dummy2, u_int fpregs[])
239 u_int class, subop, major;
240 u_int fpu_type_flags;
242 /* All FP emulation code assumes that ints are 4-bytes in length */
243 VASSERT(sizeof(int) == 4);
245 fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
247 major = get_major(ir);
248 class = get_class(ir);
250 if (fpu_type_flags & PA2_0_FPU_FLAG)
251 subop = get_subop1_PA2_0(ir);
253 subop = get_subop1_PA1_1(ir);
256 subop = get_subop(ir);
259 return(decode_0c(ir,class,subop,fpregs));
261 return(decode_0e(ir,class,subop,fpregs));
263 return(decode_06(ir,fpregs));
265 return(decode_26(ir,fpregs));
267 return(decode_2e(ir,fpregs));
269 return(PA83_UNIMP_EXCP);
275 decode_0c(u_int ir, u_int class, u_int subop, u_int fpregs[])
277 u_int r1,r2,t; /* operand register offsets */
278 u_int fmt; /* also sf for class 1 conversions */
279 u_int df; /* for class 1 conversions */
281 u_int retval, local_status;
282 u_int fpu_type_flags;
284 if (ir == COPR_INST) {
285 fpregs[0] = EMULATION_VERSION << 11;
288 status = &fpregs[0]; /* fp status register */
289 local_status = fpregs[0]; /* and local copy */
290 r1 = extru(ir,fpr1pos,5) * sizeof(double)/sizeof(u_int);
291 if (r1 == 0) /* map fr0 source to constant zero */
293 t = extru(ir,fptpos,5) * sizeof(double)/sizeof(u_int);
294 if (t == 0 && class != 2) /* don't allow fr0 as a dest */
295 return(MAJOR_0C_EXCP);
296 fmt = extru(ir,fpfmtpos,2); /* get fmt completer */
301 case 0: /* COPR 0,0 emulated above*/
303 return(MAJOR_0C_EXCP);
306 case 2: /* illegal */
307 return(MAJOR_0C_EXCP);
309 t &= ~3; /* force to even reg #s */
311 fpregs[t+3] = fpregs[r1+3];
312 fpregs[t+2] = fpregs[r1+2];
315 fpregs[t+1] = fpregs[r1+1];
318 fpregs[t] = fpregs[r1];
324 case 2: /* illegal */
325 return(MAJOR_0C_EXCP);
327 t &= ~3; /* force to even reg #s */
329 fpregs[t+3] = fpregs[r1+3];
330 fpregs[t+2] = fpregs[r1+2];
333 fpregs[t+1] = fpregs[r1+1];
336 /* copy and clear sign bit */
337 fpregs[t] = fpregs[r1] & 0x7fffffff;
343 case 2: /* illegal */
344 return(MAJOR_0C_EXCP);
346 t &= ~3; /* force to even reg #s */
348 fpregs[t+3] = fpregs[r1+3];
349 fpregs[t+2] = fpregs[r1+2];
352 fpregs[t+1] = fpregs[r1+1];
355 /* copy and invert sign bit */
356 fpregs[t] = fpregs[r1] ^ 0x80000000;
360 case 7: /* FNEGABS */
362 case 2: /* illegal */
363 return(MAJOR_0C_EXCP);
365 t &= ~3; /* force to even reg #s */
367 fpregs[t+3] = fpregs[r1+3];
368 fpregs[t+2] = fpregs[r1+2];
371 fpregs[t+1] = fpregs[r1+1];
374 /* copy and set sign bit */
375 fpregs[t] = fpregs[r1] | 0x80000000;
382 return(sgl_fsqrt(&fpregs[r1],0,
385 return(dbl_fsqrt(&fpregs[r1],0,
388 case 3: /* quad not implemented */
389 return(MAJOR_0C_EXCP);
395 return(sgl_frnd(&fpregs[r1],0,
398 return(dbl_frnd(&fpregs[r1],0,
401 case 3: /* quad not implemented */
402 return(MAJOR_0C_EXCP);
404 } /* end of switch (subop) */
406 case 1: /* class 1 */
407 df = extru(ir,fpdfpos,2); /* get dest format */
408 if ((df & 2) || (fmt & 2)) {
410 * fmt's 2 and 3 are illegal of not implemented
413 return(MAJOR_0C_EXCP);
416 * encode source and dest formats into 2 bits.
417 * high bit is source, low bit is dest.
418 * bit = 1 --> double precision
420 fmt = (fmt << 1) | df;
424 case 0: /* sgl/sgl */
425 return(MAJOR_0C_EXCP);
426 case 1: /* sgl/dbl */
427 return(sgl_to_dbl_fcnvff(&fpregs[r1],0,
429 case 2: /* dbl/sgl */
430 return(dbl_to_sgl_fcnvff(&fpregs[r1],0,
432 case 3: /* dbl/dbl */
433 return(MAJOR_0C_EXCP);
438 case 0: /* sgl/sgl */
439 return(sgl_to_sgl_fcnvxf(&fpregs[r1],0,
441 case 1: /* sgl/dbl */
442 return(sgl_to_dbl_fcnvxf(&fpregs[r1],0,
444 case 2: /* dbl/sgl */
445 return(dbl_to_sgl_fcnvxf(&fpregs[r1],0,
447 case 3: /* dbl/dbl */
448 return(dbl_to_dbl_fcnvxf(&fpregs[r1],0,
454 case 0: /* sgl/sgl */
455 return(sgl_to_sgl_fcnvfx(&fpregs[r1],0,
457 case 1: /* sgl/dbl */
458 return(sgl_to_dbl_fcnvfx(&fpregs[r1],0,
460 case 2: /* dbl/sgl */
461 return(dbl_to_sgl_fcnvfx(&fpregs[r1],0,
463 case 3: /* dbl/dbl */
464 return(dbl_to_dbl_fcnvfx(&fpregs[r1],0,
468 case 3: /* FCNVFXT */
470 case 0: /* sgl/sgl */
471 return(sgl_to_sgl_fcnvfxt(&fpregs[r1],0,
473 case 1: /* sgl/dbl */
474 return(sgl_to_dbl_fcnvfxt(&fpregs[r1],0,
476 case 2: /* dbl/sgl */
477 return(dbl_to_sgl_fcnvfxt(&fpregs[r1],0,
479 case 3: /* dbl/dbl */
480 return(dbl_to_dbl_fcnvfxt(&fpregs[r1],0,
484 case 5: /* FCNVUF (PA2.0 only) */
486 case 0: /* sgl/sgl */
487 return(sgl_to_sgl_fcnvuf(&fpregs[r1],0,
489 case 1: /* sgl/dbl */
490 return(sgl_to_dbl_fcnvuf(&fpregs[r1],0,
492 case 2: /* dbl/sgl */
493 return(dbl_to_sgl_fcnvuf(&fpregs[r1],0,
495 case 3: /* dbl/dbl */
496 return(dbl_to_dbl_fcnvuf(&fpregs[r1],0,
500 case 6: /* FCNVFU (PA2.0 only) */
502 case 0: /* sgl/sgl */
503 return(sgl_to_sgl_fcnvfu(&fpregs[r1],0,
505 case 1: /* sgl/dbl */
506 return(sgl_to_dbl_fcnvfu(&fpregs[r1],0,
508 case 2: /* dbl/sgl */
509 return(dbl_to_sgl_fcnvfu(&fpregs[r1],0,
511 case 3: /* dbl/dbl */
512 return(dbl_to_dbl_fcnvfu(&fpregs[r1],0,
516 case 7: /* FCNVFUT (PA2.0 only) */
518 case 0: /* sgl/sgl */
519 return(sgl_to_sgl_fcnvfut(&fpregs[r1],0,
521 case 1: /* sgl/dbl */
522 return(sgl_to_dbl_fcnvfut(&fpregs[r1],0,
524 case 2: /* dbl/sgl */
525 return(dbl_to_sgl_fcnvfut(&fpregs[r1],0,
527 case 3: /* dbl/dbl */
528 return(dbl_to_dbl_fcnvfut(&fpregs[r1],0,
532 case 4: /* undefined */
533 return(MAJOR_0C_EXCP);
534 } /* end of switch subop */
536 case 2: /* class 2 */
537 fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS];
538 r2 = extru(ir, fpr2pos, 5) * sizeof(double)/sizeof(u_int);
541 if (fpu_type_flags & PA2_0_FPU_FLAG) {
542 /* FTEST if nullify bit set, otherwise FCMP */
543 if (extru(ir, fpnulpos, 1)) { /* FTEST */
548 * second param is the t field used for
549 * ftest,acc and ftest,rej
550 * third param is the subop (y-field)
554 * return(ftest(0L,extru(ir,fptpos,5),
555 * &fpregs[0],subop));
560 return(MAJOR_0C_EXCP);
565 retval = sgl_fcmp(&fpregs[r1],
566 &fpregs[r2],extru(ir,fptpos,5),
568 update_status_cbit(status,local_status,
569 fpu_type_flags, subop);
572 retval = dbl_fcmp(&fpregs[r1],
573 &fpregs[r2],extru(ir,fptpos,5),
575 update_status_cbit(status,local_status,
576 fpu_type_flags, subop);
578 case 2: /* illegal */
579 case 3: /* quad not implemented */
580 return(MAJOR_0C_EXCP);
583 } /* end of if for PA2.0 */
584 else { /* PA1.0 & PA1.1 */
592 return(MAJOR_0C_EXCP);
596 retval = sgl_fcmp(&fpregs[r1],
597 &fpregs[r2],extru(ir,fptpos,5),
599 update_status_cbit(status,local_status,
600 fpu_type_flags, subop);
603 retval = dbl_fcmp(&fpregs[r1],
604 &fpregs[r2],extru(ir,fptpos,5),
606 update_status_cbit(status,local_status,
607 fpu_type_flags, subop);
609 case 2: /* illegal */
610 case 3: /* quad not implemented */
611 return(MAJOR_0C_EXCP);
619 * second param is the t field used for
620 * ftest,acc and ftest,rej
621 * third param is the subop (y-field)
625 * return(ftest(0L,extru(ir,fptpos,5),
626 * &fpregs[0],subop));
631 return(MAJOR_0C_EXCP);
634 } /* end of switch subop */
635 } /* end of else for PA1.0 & PA1.1 */
637 case 3: /* class 3 */
638 r2 = extru(ir,fpr2pos,5) * sizeof(double)/sizeof(u_int);
645 return(MAJOR_0C_EXCP);
650 return(sgl_fadd(&fpregs[r1],&fpregs[r2],
653 return(dbl_fadd(&fpregs[r1],&fpregs[r2],
655 case 2: /* illegal */
656 case 3: /* quad not implemented */
657 return(MAJOR_0C_EXCP);
663 return(sgl_fsub(&fpregs[r1],&fpregs[r2],
666 return(dbl_fsub(&fpregs[r1],&fpregs[r2],
668 case 2: /* illegal */
669 case 3: /* quad not implemented */
670 return(MAJOR_0C_EXCP);
676 return(sgl_fmpy(&fpregs[r1],&fpregs[r2],
679 return(dbl_fmpy(&fpregs[r1],&fpregs[r2],
681 case 2: /* illegal */
682 case 3: /* quad not implemented */
683 return(MAJOR_0C_EXCP);
689 return(sgl_fdiv(&fpregs[r1],&fpregs[r2],
692 return(dbl_fdiv(&fpregs[r1],&fpregs[r2],
694 case 2: /* illegal */
695 case 3: /* quad not implemented */
696 return(MAJOR_0C_EXCP);
702 return(sgl_frem(&fpregs[r1],&fpregs[r2],
705 return(dbl_frem(&fpregs[r1],&fpregs[r2],
707 case 2: /* illegal */
708 case 3: /* quad not implemented */
709 return(MAJOR_0C_EXCP);
712 } /* end of class 3 switch */
713 } /* end of switch(class) */
715 /* If we get here, something is really wrong! */
716 return(MAJOR_0C_EXCP);
720 decode_0e(ir,class,subop,fpregs)
721 u_int ir,class,subop;
724 u_int r1,r2,t; /* operand register offsets */
725 u_int fmt; /* also sf for class 1 conversions */
726 u_int df; /* dest format for class 1 conversions */
728 u_int retval, local_status;
729 u_int fpu_type_flags;
732 local_status = fpregs[0];
733 r1 = ((extru(ir,fpr1pos,5)<<1)|(extru(ir,fpxr1pos,1)));
736 t = ((extru(ir,fptpos,5)<<1)|(extru(ir,fpxtpos,1)));
737 if (t == 0 && class != 2)
738 return(MAJOR_0E_EXCP);
739 if (class < 2) /* class 0 or 1 has 2 bit fmt */
740 fmt = extru(ir,fpfmtpos,2);
741 else /* class 2 and 3 have 1 bit fmt */
742 fmt = extru(ir,fp0efmtpos,1);
744 * An undefined combination, double precision accessing the
745 * right half of a FPR, can get us into trouble.
746 * Let's just force proper alignment on it.
757 case 0: /* unimplemented */
759 return(MAJOR_0E_EXCP);
764 return(MAJOR_0E_EXCP);
766 fpregs[t+1] = fpregs[r1+1];
769 fpregs[t] = fpregs[r1];
777 return(MAJOR_0E_EXCP);
779 fpregs[t+1] = fpregs[r1+1];
782 fpregs[t] = fpregs[r1] & 0x7fffffff;
790 return(MAJOR_0E_EXCP);
792 fpregs[t+1] = fpregs[r1+1];
795 fpregs[t] = fpregs[r1] ^ 0x80000000;
799 case 7: /* FNEGABS */
803 return(MAJOR_0E_EXCP);
805 fpregs[t+1] = fpregs[r1+1];
808 fpregs[t] = fpregs[r1] | 0x80000000;
815 return(sgl_fsqrt(&fpregs[r1],0,
816 &fpregs[t], status));
818 return(dbl_fsqrt(&fpregs[r1],0,
819 &fpregs[t], status));
822 return(MAJOR_0E_EXCP);
828 return(sgl_frnd(&fpregs[r1],0,
829 &fpregs[t], status));
831 return(dbl_frnd(&fpregs[r1],0,
832 &fpregs[t], status));
835 return(MAJOR_0E_EXCP);
837 } /* end of switch (subop */
839 case 1: /* class 1 */
840 df = extru(ir,fpdfpos,2); /* get dest format */
842 * Fix Crashme problem (writing to 31R in double precision)
848 if ((df & 2) || (fmt & 2))
849 return(MAJOR_0E_EXCP);
851 fmt = (fmt << 1) | df;
855 case 0: /* sgl/sgl */
856 return(MAJOR_0E_EXCP);
857 case 1: /* sgl/dbl */
858 return(sgl_to_dbl_fcnvff(&fpregs[r1],0,
860 case 2: /* dbl/sgl */
861 return(dbl_to_sgl_fcnvff(&fpregs[r1],0,
863 case 3: /* dbl/dbl */
864 return(MAJOR_0E_EXCP);
869 case 0: /* sgl/sgl */
870 return(sgl_to_sgl_fcnvxf(&fpregs[r1],0,
872 case 1: /* sgl/dbl */
873 return(sgl_to_dbl_fcnvxf(&fpregs[r1],0,
875 case 2: /* dbl/sgl */
876 return(dbl_to_sgl_fcnvxf(&fpregs[r1],0,
878 case 3: /* dbl/dbl */
879 return(dbl_to_dbl_fcnvxf(&fpregs[r1],0,
885 case 0: /* sgl/sgl */
886 return(sgl_to_sgl_fcnvfx(&fpregs[r1],0,
888 case 1: /* sgl/dbl */
889 return(sgl_to_dbl_fcnvfx(&fpregs[r1],0,
891 case 2: /* dbl/sgl */
892 return(dbl_to_sgl_fcnvfx(&fpregs[r1],0,
894 case 3: /* dbl/dbl */
895 return(dbl_to_dbl_fcnvfx(&fpregs[r1],0,
899 case 3: /* FCNVFXT */
901 case 0: /* sgl/sgl */
902 return(sgl_to_sgl_fcnvfxt(&fpregs[r1],0,
904 case 1: /* sgl/dbl */
905 return(sgl_to_dbl_fcnvfxt(&fpregs[r1],0,
907 case 2: /* dbl/sgl */
908 return(dbl_to_sgl_fcnvfxt(&fpregs[r1],0,
910 case 3: /* dbl/dbl */
911 return(dbl_to_dbl_fcnvfxt(&fpregs[r1],0,
915 case 5: /* FCNVUF (PA2.0 only) */
917 case 0: /* sgl/sgl */
918 return(sgl_to_sgl_fcnvuf(&fpregs[r1],0,
920 case 1: /* sgl/dbl */
921 return(sgl_to_dbl_fcnvuf(&fpregs[r1],0,
923 case 2: /* dbl/sgl */
924 return(dbl_to_sgl_fcnvuf(&fpregs[r1],0,
926 case 3: /* dbl/dbl */
927 return(dbl_to_dbl_fcnvuf(&fpregs[r1],0,
931 case 6: /* FCNVFU (PA2.0 only) */
933 case 0: /* sgl/sgl */
934 return(sgl_to_sgl_fcnvfu(&fpregs[r1],0,
936 case 1: /* sgl/dbl */
937 return(sgl_to_dbl_fcnvfu(&fpregs[r1],0,
939 case 2: /* dbl/sgl */
940 return(dbl_to_sgl_fcnvfu(&fpregs[r1],0,
942 case 3: /* dbl/dbl */
943 return(dbl_to_dbl_fcnvfu(&fpregs[r1],0,
947 case 7: /* FCNVFUT (PA2.0 only) */
949 case 0: /* sgl/sgl */
950 return(sgl_to_sgl_fcnvfut(&fpregs[r1],0,
952 case 1: /* sgl/dbl */
953 return(sgl_to_dbl_fcnvfut(&fpregs[r1],0,
955 case 2: /* dbl/sgl */
956 return(dbl_to_sgl_fcnvfut(&fpregs[r1],0,
958 case 3: /* dbl/dbl */
959 return(dbl_to_dbl_fcnvfut(&fpregs[r1],0,
963 case 4: /* undefined */
964 return(MAJOR_0C_EXCP);
965 } /* end of switch subop */
967 case 2: /* class 2 */
969 * Be careful out there.
970 * Crashme can generate cases where FR31R is specified
971 * as the source or target of a double precision operation.
972 * Since we just pass the address of the floating-point
973 * register to the emulation routines, this can cause
974 * corruption of fpzeroreg.
977 r2 = (extru(ir,fpr2pos,5)<<1);
979 r2 = ((extru(ir,fpr2pos,5)<<1)|(extru(ir,fpxr2pos,1)));
980 fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS];
983 if (fpu_type_flags & PA2_0_FPU_FLAG) {
984 /* FTEST if nullify bit set, otherwise FCMP */
985 if (extru(ir, fpnulpos, 1)) { /* FTEST */
987 return(MAJOR_0E_EXCP);
991 * fmt is only 1 bit long
994 retval = sgl_fcmp(&fpregs[r1],
995 &fpregs[r2],extru(ir,fptpos,5),
997 update_status_cbit(status,local_status,
998 fpu_type_flags, subop);
1001 retval = dbl_fcmp(&fpregs[r1],
1002 &fpregs[r2],extru(ir,fptpos,5),
1004 update_status_cbit(status,local_status,
1005 fpu_type_flags, subop);
1009 } /* end of if for PA2.0 */
1010 else { /* PA1.0 & PA1.1 */
1019 return(MAJOR_0E_EXCP);
1023 * fmt is only 1 bit long
1026 retval = sgl_fcmp(&fpregs[r1],
1027 &fpregs[r2],extru(ir,fptpos,5),
1029 update_status_cbit(status,local_status,
1030 fpu_type_flags, subop);
1033 retval = dbl_fcmp(&fpregs[r1],
1034 &fpregs[r2],extru(ir,fptpos,5),
1036 update_status_cbit(status,local_status,
1037 fpu_type_flags, subop);
1040 } /* end of switch subop */
1041 } /* end of else for PA1.0 & PA1.1 */
1043 case 3: /* class 3 */
1045 * Be careful out there.
1046 * Crashme can generate cases where FR31R is specified
1047 * as the source or target of a double precision operation.
1048 * Since we just pass the address of the floating-point
1049 * register to the emulation routines, this can cause
1050 * corruption of fpzeroreg.
1053 r2 = (extru(ir,fpr2pos,5)<<1);
1055 r2 = ((extru(ir,fpr2pos,5)<<1)|(extru(ir,fpxr2pos,1)));
1062 return(MAJOR_0E_EXCP);
1065 * Note that fmt is only 1 bit for class 3 */
1069 return(sgl_fadd(&fpregs[r1],&fpregs[r2],
1070 &fpregs[t],status));
1072 return(dbl_fadd(&fpregs[r1],&fpregs[r2],
1073 &fpregs[t],status));
1079 return(sgl_fsub(&fpregs[r1],&fpregs[r2],
1080 &fpregs[t],status));
1082 return(dbl_fsub(&fpregs[r1],&fpregs[r2],
1083 &fpregs[t],status));
1086 case 2: /* FMPY or XMPYU */
1088 * check for integer multiply (x bit set)
1090 if (extru(ir,fpxpos,1)) {
1097 * bad instruction if t specifies
1098 * the right half of a register
1101 return(MAJOR_0E_EXCP);
1104 * impyu(&fpregs[r1],&fpregs[r2],
1107 return(NOEXCEPTION);
1109 return(MAJOR_0E_EXCP);
1115 return(sgl_fmpy(&fpregs[r1],
1116 &fpregs[r2],&fpregs[t],status));
1118 return(dbl_fmpy(&fpregs[r1],
1119 &fpregs[r2],&fpregs[t],status));
1126 return(sgl_fdiv(&fpregs[r1],&fpregs[r2],
1127 &fpregs[t],status));
1129 return(dbl_fdiv(&fpregs[r1],&fpregs[r2],
1130 &fpregs[t],status));
1136 return(sgl_frem(&fpregs[r1],&fpregs[r2],
1137 &fpregs[t],status));
1139 return(dbl_frem(&fpregs[r1],&fpregs[r2],
1140 &fpregs[t],status));
1142 } /* end of class 3 switch */
1143 } /* end of switch(class) */
1145 /* If we get here, something is really wrong! */
1146 return(MAJOR_0E_EXCP);
1151 * routine to decode the 06 (FMPYADD and FMPYCFXT) instruction
1154 decode_06(ir,fpregs)
1158 u_int rm1, rm2, tm, ra, ta; /* operands */
1162 u_int fpu_type_flags;
1166 struct { u_int i1; u_int i2; } ints;
1170 status = fpregs[0]; /* use a local copy of status reg */
1171 fpu_type_flags=fpregs[FPU_TYPE_FLAG_POS]; /* get fpu type flags */
1172 fmt = extru(ir, fpmultifmt, 1); /* get sgl/dbl flag */
1173 if (fmt == 0) { /* DBL */
1174 rm1 = extru(ir, fprm1pos, 5) * sizeof(double)/sizeof(u_int);
1177 rm2 = extru(ir, fprm2pos, 5) * sizeof(double)/sizeof(u_int);
1180 tm = extru(ir, fptmpos, 5) * sizeof(double)/sizeof(u_int);
1182 return(MAJOR_06_EXCP);
1183 ra = extru(ir, fprapos, 5) * sizeof(double)/sizeof(u_int);
1184 ta = extru(ir, fptapos, 5) * sizeof(double)/sizeof(u_int);
1186 return(MAJOR_06_EXCP);
1188 if (fpu_type_flags & TIMEX_ROLEX_FPU_MASK) {
1191 /* special case FMPYCFXT, see sgl case below */
1192 if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],
1193 &mtmp.ints.i1,&status))
1195 if (dbl_to_sgl_fcnvfxt(&fpregs[ta],
1196 &atmp.ints.i1,&atmp.ints.i1,&status))
1201 if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
1204 if (dbl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
1216 if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
1219 if (dbl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
1226 return(MAJOR_06_EXCP);
1229 fpregs[tm] = mtmp.ints.i1;
1230 fpregs[tm+1] = mtmp.ints.i2;
1231 fpregs[ta] = atmp.ints.i1;
1232 fpregs[ta+1] = atmp.ints.i2;
1234 return(NOEXCEPTION);
1239 * calculate offsets for single precision numbers
1240 * See table 6-14 in PA-89 architecture for mapping
1242 rm1 = (extru(ir,fprm1pos,4) | 0x10 ) << 1; /* get offset */
1243 rm1 |= extru(ir,fprm1pos-4,1); /* add right word offset */
1245 rm2 = (extru(ir,fprm2pos,4) | 0x10 ) << 1; /* get offset */
1246 rm2 |= extru(ir,fprm2pos-4,1); /* add right word offset */
1248 tm = (extru(ir,fptmpos,4) | 0x10 ) << 1; /* get offset */
1249 tm |= extru(ir,fptmpos-4,1); /* add right word offset */
1251 ra = (extru(ir,fprapos,4) | 0x10 ) << 1; /* get offset */
1252 ra |= extru(ir,fprapos-4,1); /* add right word offset */
1254 ta = (extru(ir,fptapos,4) | 0x10 ) << 1; /* get offset */
1255 ta |= extru(ir,fptapos-4,1); /* add right word offset */
1257 if (ra == 0x20 &&(fpu_type_flags & TIMEX_ROLEX_FPU_MASK)) {
1258 /* special case FMPYCFXT (really 0)
1259 * This instruction is only present on the Timex and
1260 * Rolex fpu's in so if it is the special case and
1261 * one of these fpu's we run the FMPYCFXT instruction
1263 if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
1266 if (sgl_to_sgl_fcnvfxt(&fpregs[ta],&atmp.ints.i1,
1267 &atmp.ints.i1,&status))
1271 if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,
1274 if (sgl_fadd(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,
1279 return(MAJOR_06_EXCP);
1282 fpregs[tm] = mtmp.ints.i1;
1283 fpregs[ta] = atmp.ints.i1;
1285 return(NOEXCEPTION);
1291 * routine to decode the 26 (FMPYSUB) instruction
1294 decode_26(ir,fpregs)
1298 u_int rm1, rm2, tm, ra, ta; /* operands */
1305 struct { u_int i1; u_int i2; } ints;
1310 fmt = extru(ir, fpmultifmt, 1); /* get sgl/dbl flag */
1311 if (fmt == 0) { /* DBL */
1312 rm1 = extru(ir, fprm1pos, 5) * sizeof(double)/sizeof(u_int);
1315 rm2 = extru(ir, fprm2pos, 5) * sizeof(double)/sizeof(u_int);
1318 tm = extru(ir, fptmpos, 5) * sizeof(double)/sizeof(u_int);
1320 return(MAJOR_26_EXCP);
1321 ra = extru(ir, fprapos, 5) * sizeof(double)/sizeof(u_int);
1323 return(MAJOR_26_EXCP);
1324 ta = extru(ir, fptapos, 5) * sizeof(double)/sizeof(u_int);
1326 return(MAJOR_26_EXCP);
1328 if (dbl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,&status))
1330 if (dbl_fsub(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,&status))
1333 return(MAJOR_26_EXCP);
1336 fpregs[tm] = mtmp.ints.i1;
1337 fpregs[tm+1] = mtmp.ints.i2;
1338 fpregs[ta] = atmp.ints.i1;
1339 fpregs[ta+1] = atmp.ints.i2;
1341 return(NOEXCEPTION);
1346 * calculate offsets for single precision numbers
1347 * See table 6-14 in PA-89 architecture for mapping
1349 rm1 = (extru(ir,fprm1pos,4) | 0x10 ) << 1; /* get offset */
1350 rm1 |= extru(ir,fprm1pos-4,1); /* add right word offset */
1352 rm2 = (extru(ir,fprm2pos,4) | 0x10 ) << 1; /* get offset */
1353 rm2 |= extru(ir,fprm2pos-4,1); /* add right word offset */
1355 tm = (extru(ir,fptmpos,4) | 0x10 ) << 1; /* get offset */
1356 tm |= extru(ir,fptmpos-4,1); /* add right word offset */
1358 ra = (extru(ir,fprapos,4) | 0x10 ) << 1; /* get offset */
1359 ra |= extru(ir,fprapos-4,1); /* add right word offset */
1361 ta = (extru(ir,fptapos,4) | 0x10 ) << 1; /* get offset */
1362 ta |= extru(ir,fptapos-4,1); /* add right word offset */
1364 if (sgl_fmpy(&fpregs[rm1],&fpregs[rm2],&mtmp.ints.i1,&status))
1366 if (sgl_fsub(&fpregs[ta], &fpregs[ra], &atmp.ints.i1,&status))
1369 return(MAJOR_26_EXCP);
1372 fpregs[tm] = mtmp.ints.i1;
1373 fpregs[ta] = atmp.ints.i1;
1375 return(NOEXCEPTION);
1382 * routine to decode the 2E (FMPYFADD,FMPYNFADD) instructions
1385 decode_2e(ir,fpregs)
1389 u_int rm1, rm2, ra, t; /* operands */
1392 fmt = extru(ir,fpfmtpos,1); /* get fmt completer */
1393 if (fmt == DBL) { /* DBL */
1394 rm1 = extru(ir,fprm1pos,5) * sizeof(double)/sizeof(u_int);
1397 rm2 = extru(ir,fprm2pos,5) * sizeof(double)/sizeof(u_int);
1400 ra = ((extru(ir,fpraupos,3)<<2)|(extru(ir,fpralpos,3)>>1)) *
1401 sizeof(double)/sizeof(u_int);
1404 t = extru(ir,fptpos,5) * sizeof(double)/sizeof(u_int);
1406 return(MAJOR_2E_EXCP);
1408 if (extru(ir,fpfusedsubop,1)) { /* fmpyfadd or fmpynfadd? */
1409 return(dbl_fmpynfadd(&fpregs[rm1], &fpregs[rm2],
1410 &fpregs[ra], &fpregs[0], &fpregs[t]));
1412 return(dbl_fmpyfadd(&fpregs[rm1], &fpregs[rm2],
1413 &fpregs[ra], &fpregs[0], &fpregs[t]));
1417 rm1 = (extru(ir,fprm1pos,5)<<1)|(extru(ir,fpxrm1pos,1));
1420 rm2 = (extru(ir,fprm2pos,5)<<1)|(extru(ir,fpxrm2pos,1));
1423 ra = (extru(ir,fpraupos,3)<<3)|extru(ir,fpralpos,3);
1426 t = ((extru(ir,fptpos,5)<<1)|(extru(ir,fpxtpos,1)));
1428 return(MAJOR_2E_EXCP);
1430 if (extru(ir,fpfusedsubop,1)) { /* fmpyfadd or fmpynfadd? */
1431 return(sgl_fmpynfadd(&fpregs[rm1], &fpregs[rm2],
1432 &fpregs[ra], &fpregs[0], &fpregs[t]));
1434 return(sgl_fmpyfadd(&fpregs[rm1], &fpregs[rm2],
1435 &fpregs[ra], &fpregs[0], &fpregs[t]));
1441 * update_status_cbit
1443 * This routine returns the correct FP status register value in
1444 * *status, based on the C-bit & V-bit returned by the FCMP
1445 * emulation routine in new_status. The architecture type
1446 * (PA83, PA89 or PA2.0) is available in fpu_type. The y_field
1447 * and the architecture type are used to determine what flavor
1448 * of FCMP is being emulated.
1451 update_status_cbit(status, new_status, fpu_type, y_field)
1452 u_int *status, new_status;
1457 * For PA89 FPU's which implement the Compare Queue and
1458 * for PA2.0 FPU's, update the Compare Queue if the y-field = 0,
1459 * otherwise update the specified bit in the Compare Array.
1460 * Note that the y-field will always be 0 for non-PA2.0 FPU's.
1462 if ((fpu_type & TIMEX_EXTEN_FLAG) ||
1463 (fpu_type & ROLEX_EXTEN_FLAG) ||
1464 (fpu_type & PA2_0_FPU_FLAG)) {
1466 *status = ((*status & 0x04000000) >> 5) | /* old Cbit */
1467 ((*status & 0x003ff000) >> 1) | /* old CQ */
1468 (new_status & 0xffc007ff); /* all other bits*/
1470 *status = (*status & 0x04000000) | /* old Cbit */
1471 ((new_status & 0x04000000) >> (y_field+4)) |
1472 (new_status & ~0x04000000 & /* other bits */
1473 ~(0x04000000 >> (y_field+4)));
1476 /* if PA83, just update the C-bit */
1478 *status = new_status;