1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
5 * Floating-point emulation code
6 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
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];
314 fpregs
[t
+1] = fpregs
[r1
+1];
316 fpregs
[t
] = fpregs
[r1
];
321 case 2: /* illegal */
322 return(MAJOR_0C_EXCP
);
324 t
&= ~3; /* force to even reg #s */
326 fpregs
[t
+3] = fpregs
[r1
+3];
327 fpregs
[t
+2] = fpregs
[r1
+2];
329 fpregs
[t
+1] = fpregs
[r1
+1];
331 /* copy and clear sign bit */
332 fpregs
[t
] = fpregs
[r1
] & 0x7fffffff;
337 case 2: /* illegal */
338 return(MAJOR_0C_EXCP
);
340 t
&= ~3; /* force to even reg #s */
342 fpregs
[t
+3] = fpregs
[r1
+3];
343 fpregs
[t
+2] = fpregs
[r1
+2];
345 fpregs
[t
+1] = fpregs
[r1
+1];
347 /* copy and invert sign bit */
348 fpregs
[t
] = fpregs
[r1
] ^ 0x80000000;
351 case 7: /* FNEGABS */
353 case 2: /* illegal */
354 return(MAJOR_0C_EXCP
);
356 t
&= ~3; /* force to even reg #s */
358 fpregs
[t
+3] = fpregs
[r1
+3];
359 fpregs
[t
+2] = fpregs
[r1
+2];
361 fpregs
[t
+1] = fpregs
[r1
+1];
363 /* copy and set sign bit */
364 fpregs
[t
] = fpregs
[r1
] | 0x80000000;
370 return(sgl_fsqrt(&fpregs
[r1
],0,
373 return(dbl_fsqrt(&fpregs
[r1
],0,
376 case 3: /* quad not implemented */
377 return(MAJOR_0C_EXCP
);
382 return(sgl_frnd(&fpregs
[r1
],0,
385 return(dbl_frnd(&fpregs
[r1
],0,
388 case 3: /* quad not implemented */
389 return(MAJOR_0C_EXCP
);
391 } /* end of switch (subop) */
393 case 1: /* class 1 */
394 df
= extru(ir
,fpdfpos
,2); /* get dest format */
395 if ((df
& 2) || (fmt
& 2)) {
397 * fmt's 2 and 3 are illegal of not implemented
400 return(MAJOR_0C_EXCP
);
403 * encode source and dest formats into 2 bits.
404 * high bit is source, low bit is dest.
405 * bit = 1 --> double precision
407 fmt
= (fmt
<< 1) | df
;
411 case 0: /* sgl/sgl */
412 return(MAJOR_0C_EXCP
);
413 case 1: /* sgl/dbl */
414 return(sgl_to_dbl_fcnvff(&fpregs
[r1
],0,
416 case 2: /* dbl/sgl */
417 return(dbl_to_sgl_fcnvff(&fpregs
[r1
],0,
419 case 3: /* dbl/dbl */
420 return(MAJOR_0C_EXCP
);
424 case 0: /* sgl/sgl */
425 return(sgl_to_sgl_fcnvxf(&fpregs
[r1
],0,
427 case 1: /* sgl/dbl */
428 return(sgl_to_dbl_fcnvxf(&fpregs
[r1
],0,
430 case 2: /* dbl/sgl */
431 return(dbl_to_sgl_fcnvxf(&fpregs
[r1
],0,
433 case 3: /* dbl/dbl */
434 return(dbl_to_dbl_fcnvxf(&fpregs
[r1
],0,
439 case 0: /* sgl/sgl */
440 return(sgl_to_sgl_fcnvfx(&fpregs
[r1
],0,
442 case 1: /* sgl/dbl */
443 return(sgl_to_dbl_fcnvfx(&fpregs
[r1
],0,
445 case 2: /* dbl/sgl */
446 return(dbl_to_sgl_fcnvfx(&fpregs
[r1
],0,
448 case 3: /* dbl/dbl */
449 return(dbl_to_dbl_fcnvfx(&fpregs
[r1
],0,
452 case 3: /* FCNVFXT */
454 case 0: /* sgl/sgl */
455 return(sgl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
457 case 1: /* sgl/dbl */
458 return(sgl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
460 case 2: /* dbl/sgl */
461 return(dbl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
463 case 3: /* dbl/dbl */
464 return(dbl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
467 case 5: /* FCNVUF (PA2.0 only) */
469 case 0: /* sgl/sgl */
470 return(sgl_to_sgl_fcnvuf(&fpregs
[r1
],0,
472 case 1: /* sgl/dbl */
473 return(sgl_to_dbl_fcnvuf(&fpregs
[r1
],0,
475 case 2: /* dbl/sgl */
476 return(dbl_to_sgl_fcnvuf(&fpregs
[r1
],0,
478 case 3: /* dbl/dbl */
479 return(dbl_to_dbl_fcnvuf(&fpregs
[r1
],0,
482 case 6: /* FCNVFU (PA2.0 only) */
484 case 0: /* sgl/sgl */
485 return(sgl_to_sgl_fcnvfu(&fpregs
[r1
],0,
487 case 1: /* sgl/dbl */
488 return(sgl_to_dbl_fcnvfu(&fpregs
[r1
],0,
490 case 2: /* dbl/sgl */
491 return(dbl_to_sgl_fcnvfu(&fpregs
[r1
],0,
493 case 3: /* dbl/dbl */
494 return(dbl_to_dbl_fcnvfu(&fpregs
[r1
],0,
497 case 7: /* FCNVFUT (PA2.0 only) */
499 case 0: /* sgl/sgl */
500 return(sgl_to_sgl_fcnvfut(&fpregs
[r1
],0,
502 case 1: /* sgl/dbl */
503 return(sgl_to_dbl_fcnvfut(&fpregs
[r1
],0,
505 case 2: /* dbl/sgl */
506 return(dbl_to_sgl_fcnvfut(&fpregs
[r1
],0,
508 case 3: /* dbl/dbl */
509 return(dbl_to_dbl_fcnvfut(&fpregs
[r1
],0,
512 case 4: /* undefined */
513 return(MAJOR_0C_EXCP
);
514 } /* end of switch subop */
516 case 2: /* class 2 */
517 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
];
518 r2
= extru(ir
, fpr2pos
, 5) * sizeof(double)/sizeof(u_int
);
521 if (fpu_type_flags
& PA2_0_FPU_FLAG
) {
522 /* FTEST if nullify bit set, otherwise FCMP */
523 if (extru(ir
, fpnulpos
, 1)) { /* FTEST */
528 * second param is the t field used for
529 * ftest,acc and ftest,rej
530 * third param is the subop (y-field)
534 * return(ftest(0L,extru(ir,fptpos,5),
535 * &fpregs[0],subop));
540 return(MAJOR_0C_EXCP
);
545 retval
= sgl_fcmp(&fpregs
[r1
],
546 &fpregs
[r2
],extru(ir
,fptpos
,5),
548 update_status_cbit(status
,local_status
,
549 fpu_type_flags
, subop
);
552 retval
= dbl_fcmp(&fpregs
[r1
],
553 &fpregs
[r2
],extru(ir
,fptpos
,5),
555 update_status_cbit(status
,local_status
,
556 fpu_type_flags
, subop
);
558 case 2: /* illegal */
559 case 3: /* quad not implemented */
560 return(MAJOR_0C_EXCP
);
563 } /* end of if for PA2.0 */
564 else { /* PA1.0 & PA1.1 */
572 return(MAJOR_0C_EXCP
);
576 retval
= sgl_fcmp(&fpregs
[r1
],
577 &fpregs
[r2
],extru(ir
,fptpos
,5),
579 update_status_cbit(status
,local_status
,
580 fpu_type_flags
, subop
);
583 retval
= dbl_fcmp(&fpregs
[r1
],
584 &fpregs
[r2
],extru(ir
,fptpos
,5),
586 update_status_cbit(status
,local_status
,
587 fpu_type_flags
, subop
);
589 case 2: /* illegal */
590 case 3: /* quad not implemented */
591 return(MAJOR_0C_EXCP
);
598 * second param is the t field used for
599 * ftest,acc and ftest,rej
600 * third param is the subop (y-field)
604 * return(ftest(0L,extru(ir,fptpos,5),
605 * &fpregs[0],subop));
610 return(MAJOR_0C_EXCP
);
612 } /* end of switch subop */
613 } /* end of else for PA1.0 & PA1.1 */
614 case 3: /* class 3 */
615 r2
= extru(ir
,fpr2pos
,5) * sizeof(double)/sizeof(u_int
);
622 return(MAJOR_0C_EXCP
);
627 return(sgl_fadd(&fpregs
[r1
],&fpregs
[r2
],
630 return(dbl_fadd(&fpregs
[r1
],&fpregs
[r2
],
632 case 2: /* illegal */
633 case 3: /* quad not implemented */
634 return(MAJOR_0C_EXCP
);
639 return(sgl_fsub(&fpregs
[r1
],&fpregs
[r2
],
642 return(dbl_fsub(&fpregs
[r1
],&fpregs
[r2
],
644 case 2: /* illegal */
645 case 3: /* quad not implemented */
646 return(MAJOR_0C_EXCP
);
651 return(sgl_fmpy(&fpregs
[r1
],&fpregs
[r2
],
654 return(dbl_fmpy(&fpregs
[r1
],&fpregs
[r2
],
656 case 2: /* illegal */
657 case 3: /* quad not implemented */
658 return(MAJOR_0C_EXCP
);
663 return(sgl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
666 return(dbl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
668 case 2: /* illegal */
669 case 3: /* quad not implemented */
670 return(MAJOR_0C_EXCP
);
675 return(sgl_frem(&fpregs
[r1
],&fpregs
[r2
],
678 return(dbl_frem(&fpregs
[r1
],&fpregs
[r2
],
680 case 2: /* illegal */
681 case 3: /* quad not implemented */
682 return(MAJOR_0C_EXCP
);
684 } /* end of class 3 switch */
685 } /* end of switch(class) */
687 /* If we get here, something is really wrong! */
688 return(MAJOR_0C_EXCP
);
692 decode_0e(ir
,class,subop
,fpregs
)
693 u_int ir
,class,subop
;
696 u_int r1
,r2
,t
; /* operand register offsets */
697 u_int fmt
; /* also sf for class 1 conversions */
698 u_int df
; /* dest format for class 1 conversions */
700 u_int retval
, local_status
;
701 u_int fpu_type_flags
;
704 local_status
= fpregs
[0];
705 r1
= ((extru(ir
,fpr1pos
,5)<<1)|(extru(ir
,fpxr1pos
,1)));
708 t
= ((extru(ir
,fptpos
,5)<<1)|(extru(ir
,fpxtpos
,1)));
709 if (t
== 0 && class != 2)
710 return(MAJOR_0E_EXCP
);
711 if (class < 2) /* class 0 or 1 has 2 bit fmt */
712 fmt
= extru(ir
,fpfmtpos
,2);
713 else /* class 2 and 3 have 1 bit fmt */
714 fmt
= extru(ir
,fp0efmtpos
,1);
716 * An undefined combination, double precision accessing the
717 * right half of a FPR, can get us into trouble.
718 * Let's just force proper alignment on it.
729 case 0: /* unimplemented */
731 return(MAJOR_0E_EXCP
);
736 return(MAJOR_0E_EXCP
);
738 fpregs
[t
+1] = fpregs
[r1
+1];
740 fpregs
[t
] = fpregs
[r1
];
747 return(MAJOR_0E_EXCP
);
749 fpregs
[t
+1] = fpregs
[r1
+1];
751 fpregs
[t
] = fpregs
[r1
] & 0x7fffffff;
758 return(MAJOR_0E_EXCP
);
760 fpregs
[t
+1] = fpregs
[r1
+1];
762 fpregs
[t
] = fpregs
[r1
] ^ 0x80000000;
765 case 7: /* FNEGABS */
769 return(MAJOR_0E_EXCP
);
771 fpregs
[t
+1] = fpregs
[r1
+1];
773 fpregs
[t
] = fpregs
[r1
] | 0x80000000;
779 return(sgl_fsqrt(&fpregs
[r1
],0,
780 &fpregs
[t
], status
));
782 return(dbl_fsqrt(&fpregs
[r1
],0,
783 &fpregs
[t
], status
));
786 return(MAJOR_0E_EXCP
);
791 return(sgl_frnd(&fpregs
[r1
],0,
792 &fpregs
[t
], status
));
794 return(dbl_frnd(&fpregs
[r1
],0,
795 &fpregs
[t
], status
));
798 return(MAJOR_0E_EXCP
);
800 } /* end of switch (subop */
802 case 1: /* class 1 */
803 df
= extru(ir
,fpdfpos
,2); /* get dest format */
805 * Fix Crashme problem (writing to 31R in double precision)
811 if ((df
& 2) || (fmt
& 2))
812 return(MAJOR_0E_EXCP
);
814 fmt
= (fmt
<< 1) | df
;
818 case 0: /* sgl/sgl */
819 return(MAJOR_0E_EXCP
);
820 case 1: /* sgl/dbl */
821 return(sgl_to_dbl_fcnvff(&fpregs
[r1
],0,
823 case 2: /* dbl/sgl */
824 return(dbl_to_sgl_fcnvff(&fpregs
[r1
],0,
826 case 3: /* dbl/dbl */
827 return(MAJOR_0E_EXCP
);
831 case 0: /* sgl/sgl */
832 return(sgl_to_sgl_fcnvxf(&fpregs
[r1
],0,
834 case 1: /* sgl/dbl */
835 return(sgl_to_dbl_fcnvxf(&fpregs
[r1
],0,
837 case 2: /* dbl/sgl */
838 return(dbl_to_sgl_fcnvxf(&fpregs
[r1
],0,
840 case 3: /* dbl/dbl */
841 return(dbl_to_dbl_fcnvxf(&fpregs
[r1
],0,
846 case 0: /* sgl/sgl */
847 return(sgl_to_sgl_fcnvfx(&fpregs
[r1
],0,
849 case 1: /* sgl/dbl */
850 return(sgl_to_dbl_fcnvfx(&fpregs
[r1
],0,
852 case 2: /* dbl/sgl */
853 return(dbl_to_sgl_fcnvfx(&fpregs
[r1
],0,
855 case 3: /* dbl/dbl */
856 return(dbl_to_dbl_fcnvfx(&fpregs
[r1
],0,
859 case 3: /* FCNVFXT */
861 case 0: /* sgl/sgl */
862 return(sgl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
864 case 1: /* sgl/dbl */
865 return(sgl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
867 case 2: /* dbl/sgl */
868 return(dbl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
870 case 3: /* dbl/dbl */
871 return(dbl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
874 case 5: /* FCNVUF (PA2.0 only) */
876 case 0: /* sgl/sgl */
877 return(sgl_to_sgl_fcnvuf(&fpregs
[r1
],0,
879 case 1: /* sgl/dbl */
880 return(sgl_to_dbl_fcnvuf(&fpregs
[r1
],0,
882 case 2: /* dbl/sgl */
883 return(dbl_to_sgl_fcnvuf(&fpregs
[r1
],0,
885 case 3: /* dbl/dbl */
886 return(dbl_to_dbl_fcnvuf(&fpregs
[r1
],0,
889 case 6: /* FCNVFU (PA2.0 only) */
891 case 0: /* sgl/sgl */
892 return(sgl_to_sgl_fcnvfu(&fpregs
[r1
],0,
894 case 1: /* sgl/dbl */
895 return(sgl_to_dbl_fcnvfu(&fpregs
[r1
],0,
897 case 2: /* dbl/sgl */
898 return(dbl_to_sgl_fcnvfu(&fpregs
[r1
],0,
900 case 3: /* dbl/dbl */
901 return(dbl_to_dbl_fcnvfu(&fpregs
[r1
],0,
904 case 7: /* FCNVFUT (PA2.0 only) */
906 case 0: /* sgl/sgl */
907 return(sgl_to_sgl_fcnvfut(&fpregs
[r1
],0,
909 case 1: /* sgl/dbl */
910 return(sgl_to_dbl_fcnvfut(&fpregs
[r1
],0,
912 case 2: /* dbl/sgl */
913 return(dbl_to_sgl_fcnvfut(&fpregs
[r1
],0,
915 case 3: /* dbl/dbl */
916 return(dbl_to_dbl_fcnvfut(&fpregs
[r1
],0,
919 case 4: /* undefined */
920 return(MAJOR_0C_EXCP
);
921 } /* end of switch subop */
922 case 2: /* class 2 */
924 * Be careful out there.
925 * Crashme can generate cases where FR31R is specified
926 * as the source or target of a double precision operation.
927 * Since we just pass the address of the floating-point
928 * register to the emulation routines, this can cause
929 * corruption of fpzeroreg.
932 r2
= (extru(ir
,fpr2pos
,5)<<1);
934 r2
= ((extru(ir
,fpr2pos
,5)<<1)|(extru(ir
,fpxr2pos
,1)));
935 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
];
938 if (fpu_type_flags
& PA2_0_FPU_FLAG
) {
939 /* FTEST if nullify bit set, otherwise FCMP */
940 if (extru(ir
, fpnulpos
, 1)) { /* FTEST */
942 return(MAJOR_0E_EXCP
);
946 * fmt is only 1 bit long
949 retval
= sgl_fcmp(&fpregs
[r1
],
950 &fpregs
[r2
],extru(ir
,fptpos
,5),
952 update_status_cbit(status
,local_status
,
953 fpu_type_flags
, subop
);
956 retval
= dbl_fcmp(&fpregs
[r1
],
957 &fpregs
[r2
],extru(ir
,fptpos
,5),
959 update_status_cbit(status
,local_status
,
960 fpu_type_flags
, subop
);
964 } /* end of if for PA2.0 */
965 else { /* PA1.0 & PA1.1 */
974 return(MAJOR_0E_EXCP
);
978 * fmt is only 1 bit long
981 retval
= sgl_fcmp(&fpregs
[r1
],
982 &fpregs
[r2
],extru(ir
,fptpos
,5),
984 update_status_cbit(status
,local_status
,
985 fpu_type_flags
, subop
);
988 retval
= dbl_fcmp(&fpregs
[r1
],
989 &fpregs
[r2
],extru(ir
,fptpos
,5),
991 update_status_cbit(status
,local_status
,
992 fpu_type_flags
, subop
);
995 } /* end of switch subop */
996 } /* end of else for PA1.0 & PA1.1 */
997 case 3: /* class 3 */
999 * Be careful out there.
1000 * Crashme can generate cases where FR31R is specified
1001 * as the source or target of a double precision operation.
1002 * Since we just pass the address of the floating-point
1003 * register to the emulation routines, this can cause
1004 * corruption of fpzeroreg.
1007 r2
= (extru(ir
,fpr2pos
,5)<<1);
1009 r2
= ((extru(ir
,fpr2pos
,5)<<1)|(extru(ir
,fpxr2pos
,1)));
1016 return(MAJOR_0E_EXCP
);
1019 * Note that fmt is only 1 bit for class 3 */
1023 return(sgl_fadd(&fpregs
[r1
],&fpregs
[r2
],
1024 &fpregs
[t
],status
));
1026 return(dbl_fadd(&fpregs
[r1
],&fpregs
[r2
],
1027 &fpregs
[t
],status
));
1032 return(sgl_fsub(&fpregs
[r1
],&fpregs
[r2
],
1033 &fpregs
[t
],status
));
1035 return(dbl_fsub(&fpregs
[r1
],&fpregs
[r2
],
1036 &fpregs
[t
],status
));
1038 case 2: /* FMPY or XMPYU */
1040 * check for integer multiply (x bit set)
1042 if (extru(ir
,fpxpos
,1)) {
1049 * bad instruction if t specifies
1050 * the right half of a register
1053 return(MAJOR_0E_EXCP
);
1056 * impyu(&fpregs[r1],&fpregs[r2],
1059 return(NOEXCEPTION
);
1061 return(MAJOR_0E_EXCP
);
1067 return(sgl_fmpy(&fpregs
[r1
],
1068 &fpregs
[r2
],&fpregs
[t
],status
));
1070 return(dbl_fmpy(&fpregs
[r1
],
1071 &fpregs
[r2
],&fpregs
[t
],status
));
1077 return(sgl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
1078 &fpregs
[t
],status
));
1080 return(dbl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
1081 &fpregs
[t
],status
));
1086 return(sgl_frem(&fpregs
[r1
],&fpregs
[r2
],
1087 &fpregs
[t
],status
));
1089 return(dbl_frem(&fpregs
[r1
],&fpregs
[r2
],
1090 &fpregs
[t
],status
));
1092 } /* end of class 3 switch */
1093 } /* end of switch(class) */
1095 /* If we get here, something is really wrong! */
1096 return(MAJOR_0E_EXCP
);
1101 * routine to decode the 06 (FMPYADD and FMPYCFXT) instruction
1104 decode_06(ir
,fpregs
)
1108 u_int rm1
, rm2
, tm
, ra
, ta
; /* operands */
1112 u_int fpu_type_flags
;
1116 struct { u_int i1
; u_int i2
; } ints
;
1120 status
= fpregs
[0]; /* use a local copy of status reg */
1121 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
]; /* get fpu type flags */
1122 fmt
= extru(ir
, fpmultifmt
, 1); /* get sgl/dbl flag */
1123 if (fmt
== 0) { /* DBL */
1124 rm1
= extru(ir
, fprm1pos
, 5) * sizeof(double)/sizeof(u_int
);
1127 rm2
= extru(ir
, fprm2pos
, 5) * sizeof(double)/sizeof(u_int
);
1130 tm
= extru(ir
, fptmpos
, 5) * sizeof(double)/sizeof(u_int
);
1132 return(MAJOR_06_EXCP
);
1133 ra
= extru(ir
, fprapos
, 5) * sizeof(double)/sizeof(u_int
);
1134 ta
= extru(ir
, fptapos
, 5) * sizeof(double)/sizeof(u_int
);
1136 return(MAJOR_06_EXCP
);
1138 if (fpu_type_flags
& TIMEX_ROLEX_FPU_MASK
) {
1141 /* special case FMPYCFXT, see sgl case below */
1142 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],
1143 &mtmp
.ints
.i1
,&status
))
1145 if (dbl_to_sgl_fcnvfxt(&fpregs
[ta
],
1146 &atmp
.ints
.i1
,&atmp
.ints
.i1
,&status
))
1151 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1154 if (dbl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1166 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1169 if (dbl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1176 return(MAJOR_06_EXCP
);
1179 fpregs
[tm
] = mtmp
.ints
.i1
;
1180 fpregs
[tm
+1] = mtmp
.ints
.i2
;
1181 fpregs
[ta
] = atmp
.ints
.i1
;
1182 fpregs
[ta
+1] = atmp
.ints
.i2
;
1184 return(NOEXCEPTION
);
1189 * calculate offsets for single precision numbers
1190 * See table 6-14 in PA-89 architecture for mapping
1192 rm1
= (extru(ir
,fprm1pos
,4) | 0x10 ) << 1; /* get offset */
1193 rm1
|= extru(ir
,fprm1pos
-4,1); /* add right word offset */
1195 rm2
= (extru(ir
,fprm2pos
,4) | 0x10 ) << 1; /* get offset */
1196 rm2
|= extru(ir
,fprm2pos
-4,1); /* add right word offset */
1198 tm
= (extru(ir
,fptmpos
,4) | 0x10 ) << 1; /* get offset */
1199 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 */
1204 ta
= (extru(ir
,fptapos
,4) | 0x10 ) << 1; /* get offset */
1205 ta
|= extru(ir
,fptapos
-4,1); /* add right word offset */
1207 if (ra
== 0x20 &&(fpu_type_flags
& TIMEX_ROLEX_FPU_MASK
)) {
1208 /* special case FMPYCFXT (really 0)
1209 * This instruction is only present on the Timex and
1210 * Rolex fpu's in so if it is the special case and
1211 * one of these fpu's we run the FMPYCFXT instruction
1213 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1216 if (sgl_to_sgl_fcnvfxt(&fpregs
[ta
],&atmp
.ints
.i1
,
1217 &atmp
.ints
.i1
,&status
))
1221 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1224 if (sgl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1229 return(MAJOR_06_EXCP
);
1232 fpregs
[tm
] = mtmp
.ints
.i1
;
1233 fpregs
[ta
] = atmp
.ints
.i1
;
1235 return(NOEXCEPTION
);
1241 * routine to decode the 26 (FMPYSUB) instruction
1244 decode_26(ir
,fpregs
)
1248 u_int rm1
, rm2
, tm
, ra
, ta
; /* operands */
1255 struct { u_int i1
; u_int i2
; } ints
;
1260 fmt
= extru(ir
, fpmultifmt
, 1); /* get sgl/dbl flag */
1261 if (fmt
== 0) { /* DBL */
1262 rm1
= extru(ir
, fprm1pos
, 5) * sizeof(double)/sizeof(u_int
);
1265 rm2
= extru(ir
, fprm2pos
, 5) * sizeof(double)/sizeof(u_int
);
1268 tm
= extru(ir
, fptmpos
, 5) * sizeof(double)/sizeof(u_int
);
1270 return(MAJOR_26_EXCP
);
1271 ra
= extru(ir
, fprapos
, 5) * sizeof(double)/sizeof(u_int
);
1273 return(MAJOR_26_EXCP
);
1274 ta
= extru(ir
, fptapos
, 5) * sizeof(double)/sizeof(u_int
);
1276 return(MAJOR_26_EXCP
);
1278 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,&status
))
1280 if (dbl_fsub(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,&status
))
1283 return(MAJOR_26_EXCP
);
1286 fpregs
[tm
] = mtmp
.ints
.i1
;
1287 fpregs
[tm
+1] = mtmp
.ints
.i2
;
1288 fpregs
[ta
] = atmp
.ints
.i1
;
1289 fpregs
[ta
+1] = atmp
.ints
.i2
;
1291 return(NOEXCEPTION
);
1296 * calculate offsets for single precision numbers
1297 * See table 6-14 in PA-89 architecture for mapping
1299 rm1
= (extru(ir
,fprm1pos
,4) | 0x10 ) << 1; /* get offset */
1300 rm1
|= extru(ir
,fprm1pos
-4,1); /* add right word offset */
1302 rm2
= (extru(ir
,fprm2pos
,4) | 0x10 ) << 1; /* get offset */
1303 rm2
|= extru(ir
,fprm2pos
-4,1); /* add right word offset */
1305 tm
= (extru(ir
,fptmpos
,4) | 0x10 ) << 1; /* get offset */
1306 tm
|= extru(ir
,fptmpos
-4,1); /* add right word offset */
1308 ra
= (extru(ir
,fprapos
,4) | 0x10 ) << 1; /* get offset */
1309 ra
|= extru(ir
,fprapos
-4,1); /* add right word offset */
1311 ta
= (extru(ir
,fptapos
,4) | 0x10 ) << 1; /* get offset */
1312 ta
|= extru(ir
,fptapos
-4,1); /* add right word offset */
1314 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,&status
))
1316 if (sgl_fsub(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,&status
))
1319 return(MAJOR_26_EXCP
);
1322 fpregs
[tm
] = mtmp
.ints
.i1
;
1323 fpregs
[ta
] = atmp
.ints
.i1
;
1325 return(NOEXCEPTION
);
1332 * routine to decode the 2E (FMPYFADD,FMPYNFADD) instructions
1335 decode_2e(ir
,fpregs
)
1339 u_int rm1
, rm2
, ra
, t
; /* operands */
1342 fmt
= extru(ir
,fpfmtpos
,1); /* get fmt completer */
1343 if (fmt
== DBL
) { /* DBL */
1344 rm1
= extru(ir
,fprm1pos
,5) * sizeof(double)/sizeof(u_int
);
1347 rm2
= extru(ir
,fprm2pos
,5) * sizeof(double)/sizeof(u_int
);
1350 ra
= ((extru(ir
,fpraupos
,3)<<2)|(extru(ir
,fpralpos
,3)>>1)) *
1351 sizeof(double)/sizeof(u_int
);
1354 t
= extru(ir
,fptpos
,5) * sizeof(double)/sizeof(u_int
);
1356 return(MAJOR_2E_EXCP
);
1358 if (extru(ir
,fpfusedsubop
,1)) { /* fmpyfadd or fmpynfadd? */
1359 return(dbl_fmpynfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1360 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1362 return(dbl_fmpyfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1363 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1367 rm1
= (extru(ir
,fprm1pos
,5)<<1)|(extru(ir
,fpxrm1pos
,1));
1370 rm2
= (extru(ir
,fprm2pos
,5)<<1)|(extru(ir
,fpxrm2pos
,1));
1373 ra
= (extru(ir
,fpraupos
,3)<<3)|extru(ir
,fpralpos
,3);
1376 t
= ((extru(ir
,fptpos
,5)<<1)|(extru(ir
,fpxtpos
,1)));
1378 return(MAJOR_2E_EXCP
);
1380 if (extru(ir
,fpfusedsubop
,1)) { /* fmpyfadd or fmpynfadd? */
1381 return(sgl_fmpynfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1382 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1384 return(sgl_fmpyfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1385 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1391 * update_status_cbit
1393 * This routine returns the correct FP status register value in
1394 * *status, based on the C-bit & V-bit returned by the FCMP
1395 * emulation routine in new_status. The architecture type
1396 * (PA83, PA89 or PA2.0) is available in fpu_type. The y_field
1397 * and the architecture type are used to determine what flavor
1398 * of FCMP is being emulated.
1401 update_status_cbit(status
, new_status
, fpu_type
, y_field
)
1402 u_int
*status
, new_status
;
1407 * For PA89 FPU's which implement the Compare Queue and
1408 * for PA2.0 FPU's, update the Compare Queue if the y-field = 0,
1409 * otherwise update the specified bit in the Compare Array.
1410 * Note that the y-field will always be 0 for non-PA2.0 FPU's.
1412 if ((fpu_type
& TIMEX_EXTEN_FLAG
) ||
1413 (fpu_type
& ROLEX_EXTEN_FLAG
) ||
1414 (fpu_type
& PA2_0_FPU_FLAG
)) {
1416 *status
= ((*status
& 0x04000000) >> 5) | /* old Cbit */
1417 ((*status
& 0x003ff000) >> 1) | /* old CQ */
1418 (new_status
& 0xffc007ff); /* all other bits*/
1420 *status
= (*status
& 0x04000000) | /* old Cbit */
1421 ((new_status
& 0x04000000) >> (y_field
+4)) |
1422 (new_status
& ~0x04000000 & /* other bits */
1423 ~(0x04000000 >> (y_field
+4)));
1426 /* if PA83, just update the C-bit */
1428 *status
= new_status
;