2 * Linux/PA-RISC Project (http://www.parisc-linux.org/)
4 * Floating-point emulation code
5 * Copyright (C) 2001 Hewlett-Packard (Paul Bame) <bame@debian.org>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2, or (at your option)
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
25 * @(#) pa/fp/fpudispatch.c $Revision: 1.1 $
28 * <<please update with a synopsis of the functionality provided by this file>>
30 * External Interfaces:
31 * <<the following list was autogenerated, please review>>
32 * emfpudispatch(ir, dummy1, dummy2, fpregs)
33 * fpudispatch(ir, excp_code, holder, fpregs)
35 * Internal Interfaces:
36 * <<the following list was autogenerated, please review>>
37 * static u_int decode_06(u_int, u_int *)
38 * static u_int decode_0c(u_int, u_int, u_int, u_int *)
39 * static u_int decode_0e(u_int, u_int, u_int, u_int *)
40 * static u_int decode_26(u_int, u_int *)
41 * static u_int decode_2e(u_int, u_int *)
42 * static void update_status_cbit(u_int *, u_int, u_int, u_int)
45 * <<please update with a overview of the operation of this file>>
53 #include <linux/kernel.h>
54 #include <asm/processor.h>
55 /* #include <sys/debug.h> */
56 /* #include <machine/sys/mdep_private.h> */
58 #define COPR_INST 0x30000000
61 * definition of extru macro. If pos and len are constants, the compiler
62 * will generate an extru instruction when optimized
64 #define extru(r,pos,len) (((r) >> (31-(pos))) & (( 1 << (len)) - 1))
65 /* definitions of bit field locations in the instruction */
71 #define fpclass1subpos 16
77 * the following are the extra bits for the 0E major op
85 * the following are for the multi-ops
94 * the following are for the fused FP instructions
104 #define fpfusedsubop 26
108 * offset to constant zero in the FP emulation registers
110 #define fpzeroreg (32*sizeof(double)/sizeof(u_int))
113 * extract the major opcode from the instruction
115 #define get_major(op) extru(op,fpmajorpos,6)
117 * extract the two bit class field from the FP instruction. The class is at bit
120 #define get_class(op) extru(op,fpclasspos,2)
122 * extract the 3 bit subop field. For all but class 1 instructions, it is
123 * located at bit positions 16-18
125 #define get_subop(op) extru(op,fpsubpos,3)
127 * extract the 2 or 3 bit subop field from class 1 instructions. It is located
128 * at bit positions 15-16 (PA1.1) or 14-16 (PA2.0)
130 #define get_subop1_PA1_1(op) extru(op,fpclass1subpos,2) /* PA89 (1.1) fmt */
131 #define get_subop1_PA2_0(op) extru(op,fpclass1subpos,3) /* PA 2.0 fmt */
133 /* definitions of unimplemented exceptions */
134 #define MAJOR_0C_EXCP 0x09
135 #define MAJOR_0E_EXCP 0x0b
136 #define MAJOR_06_EXCP 0x03
137 #define MAJOR_26_EXCP 0x23
138 #define MAJOR_2E_EXCP 0x2b
139 #define PA83_UNIMP_EXCP 0x01
142 * Special Defines for TIMEX specific code
145 #define FPU_TYPE_FLAG_POS (EM_FPU_TYPE_OFFSET>>2)
146 #define TIMEX_ROLEX_FPU_MASK (TIMEX_EXTEN_FLAG|ROLEX_EXTEN_FLAG)
149 * Static function definitions
152 #if defined(_PROTOTYPES) || defined(_lint)
153 static u_int
decode_0c(u_int
, u_int
, u_int
, u_int
*);
154 static u_int
decode_0e(u_int
, u_int
, u_int
, u_int
*);
155 static u_int
decode_06(u_int
, u_int
*);
156 static u_int
decode_26(u_int
, u_int
*);
157 static u_int
decode_2e(u_int
, u_int
*);
158 static void update_status_cbit(u_int
*, u_int
, u_int
, u_int
);
159 #else /* !_PROTOTYPES&&!_lint */
160 static u_int
decode_0c();
161 static u_int
decode_0e();
162 static u_int
decode_06();
163 static u_int
decode_26();
164 static u_int
decode_2e();
165 static void update_status_cbit();
166 #endif /* _PROTOTYPES&&!_lint */
170 static void parisc_linux_get_fpu_type(u_int fpregs
[])
172 /* on pa-linux the fpu type is not filled in by the
173 * caller; it is constructed here
175 if (boot_cpu_data
.cpu_type
== pcxs
)
176 fpregs
[FPU_TYPE_FLAG_POS
] = TIMEX_EXTEN_FLAG
;
177 else if (boot_cpu_data
.cpu_type
== pcxt
||
178 boot_cpu_data
.cpu_type
== pcxt_
)
179 fpregs
[FPU_TYPE_FLAG_POS
] = ROLEX_EXTEN_FLAG
;
180 else if (boot_cpu_data
.cpu_type
>= pcxu
)
181 fpregs
[FPU_TYPE_FLAG_POS
] = PA2_0_FPU_FLAG
;
185 * this routine will decode the excepting floating point instruction and
186 * call the approiate emulation routine.
187 * It is called by decode_fpu with the following parameters:
188 * fpudispatch(current_ir, unimplemented_code, 0, &Fpu_register)
189 * where current_ir is the instruction to be emulated,
190 * unimplemented_code is the exception_code that the hardware generated
191 * and &Fpu_register is the address of emulated FP reg 0.
194 fpudispatch(u_int ir
, u_int excp_code
, u_int holder
, u_int fpregs
[])
197 u_int fpu_type_flags
;
199 /* All FP emulation code assumes that ints are 4-bytes in length */
200 VASSERT(sizeof(int) == 4);
202 parisc_linux_get_fpu_type(fpregs
);
204 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
]; /* get fpu type flags */
206 class = get_class(ir
);
208 if (fpu_type_flags
& PA2_0_FPU_FLAG
)
209 subop
= get_subop1_PA2_0(ir
);
211 subop
= get_subop1_PA1_1(ir
);
214 subop
= get_subop(ir
);
216 if (FPUDEBUG
) printk("class %d subop %d\n", class, subop
);
220 case PA83_UNIMP_EXCP
:
221 return(decode_0c(ir
,class,subop
,fpregs
));
223 return(decode_0e(ir
,class,subop
,fpregs
));
225 return(decode_06(ir
,fpregs
));
227 return(decode_26(ir
,fpregs
));
229 return(decode_2e(ir
,fpregs
));
231 /* "crashme Night Gallery painting nr 2. (asm_crash.s).
232 * This was fixed for multi-user kernels, but
233 * workstation kernels had a panic here. This allowed
234 * any arbitrary user to panic the kernel by executing
235 * setting the FP exception registers to strange values
236 * and generating an emulation trap. The emulation and
237 * exception code must never be able to panic the
240 return(UNIMPLEMENTEDEXCEPTION
);
245 * this routine is called by $emulation_trap to emulate a coprocessor
246 * instruction if one doesn't exist
249 emfpudispatch(u_int ir
, u_int dummy1
, u_int dummy2
, u_int fpregs
[])
251 u_int
class, subop
, major
;
252 u_int fpu_type_flags
;
254 /* All FP emulation code assumes that ints are 4-bytes in length */
255 VASSERT(sizeof(int) == 4);
257 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
]; /* get fpu type flags */
259 major
= get_major(ir
);
260 class = get_class(ir
);
262 if (fpu_type_flags
& PA2_0_FPU_FLAG
)
263 subop
= get_subop1_PA2_0(ir
);
265 subop
= get_subop1_PA1_1(ir
);
268 subop
= get_subop(ir
);
271 return(decode_0c(ir
,class,subop
,fpregs
));
273 return(decode_0e(ir
,class,subop
,fpregs
));
275 return(decode_06(ir
,fpregs
));
277 return(decode_26(ir
,fpregs
));
279 return(decode_2e(ir
,fpregs
));
281 return(PA83_UNIMP_EXCP
);
287 decode_0c(u_int ir
, u_int
class, u_int subop
, u_int fpregs
[])
289 u_int r1
,r2
,t
; /* operand register offsets */
290 u_int fmt
; /* also sf for class 1 conversions */
291 u_int df
; /* for class 1 conversions */
293 u_int retval
, local_status
;
294 u_int fpu_type_flags
;
296 if (ir
== COPR_INST
) {
297 fpregs
[0] = EMULATION_VERSION
<< 11;
300 status
= &fpregs
[0]; /* fp status register */
301 local_status
= fpregs
[0]; /* and local copy */
302 r1
= extru(ir
,fpr1pos
,5) * sizeof(double)/sizeof(u_int
);
303 if (r1
== 0) /* map fr0 source to constant zero */
305 t
= extru(ir
,fptpos
,5) * sizeof(double)/sizeof(u_int
);
306 if (t
== 0 && class != 2) /* don't allow fr0 as a dest */
307 return(MAJOR_0C_EXCP
);
308 fmt
= extru(ir
,fpfmtpos
,2); /* get fmt completer */
313 case 0: /* COPR 0,0 emulated above*/
315 return(MAJOR_0C_EXCP
);
318 case 2: /* illegal */
319 return(MAJOR_0C_EXCP
);
321 t
&= ~3; /* force to even reg #s */
323 fpregs
[t
+3] = fpregs
[r1
+3];
324 fpregs
[t
+2] = fpregs
[r1
+2];
326 fpregs
[t
+1] = fpregs
[r1
+1];
328 fpregs
[t
] = fpregs
[r1
];
333 case 2: /* illegal */
334 return(MAJOR_0C_EXCP
);
336 t
&= ~3; /* force to even reg #s */
338 fpregs
[t
+3] = fpregs
[r1
+3];
339 fpregs
[t
+2] = fpregs
[r1
+2];
341 fpregs
[t
+1] = fpregs
[r1
+1];
343 /* copy and clear sign bit */
344 fpregs
[t
] = fpregs
[r1
] & 0x7fffffff;
349 case 2: /* illegal */
350 return(MAJOR_0C_EXCP
);
352 t
&= ~3; /* force to even reg #s */
354 fpregs
[t
+3] = fpregs
[r1
+3];
355 fpregs
[t
+2] = fpregs
[r1
+2];
357 fpregs
[t
+1] = fpregs
[r1
+1];
359 /* copy and invert sign bit */
360 fpregs
[t
] = fpregs
[r1
] ^ 0x80000000;
363 case 7: /* FNEGABS */
365 case 2: /* illegal */
366 return(MAJOR_0C_EXCP
);
368 t
&= ~3; /* force to even reg #s */
370 fpregs
[t
+3] = fpregs
[r1
+3];
371 fpregs
[t
+2] = fpregs
[r1
+2];
373 fpregs
[t
+1] = fpregs
[r1
+1];
375 /* copy and set sign bit */
376 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
);
394 return(sgl_frnd(&fpregs
[r1
],0,
397 return(dbl_frnd(&fpregs
[r1
],0,
400 case 3: /* quad not implemented */
401 return(MAJOR_0C_EXCP
);
403 } /* end of switch (subop) */
405 case 1: /* class 1 */
406 df
= extru(ir
,fpdfpos
,2); /* get dest format */
407 if ((df
& 2) || (fmt
& 2)) {
409 * fmt's 2 and 3 are illegal of not implemented
412 return(MAJOR_0C_EXCP
);
415 * encode source and dest formats into 2 bits.
416 * high bit is source, low bit is dest.
417 * bit = 1 --> double precision
419 fmt
= (fmt
<< 1) | df
;
423 case 0: /* sgl/sgl */
424 return(MAJOR_0C_EXCP
);
425 case 1: /* sgl/dbl */
426 return(sgl_to_dbl_fcnvff(&fpregs
[r1
],0,
428 case 2: /* dbl/sgl */
429 return(dbl_to_sgl_fcnvff(&fpregs
[r1
],0,
431 case 3: /* dbl/dbl */
432 return(MAJOR_0C_EXCP
);
436 case 0: /* sgl/sgl */
437 return(sgl_to_sgl_fcnvxf(&fpregs
[r1
],0,
439 case 1: /* sgl/dbl */
440 return(sgl_to_dbl_fcnvxf(&fpregs
[r1
],0,
442 case 2: /* dbl/sgl */
443 return(dbl_to_sgl_fcnvxf(&fpregs
[r1
],0,
445 case 3: /* dbl/dbl */
446 return(dbl_to_dbl_fcnvxf(&fpregs
[r1
],0,
451 case 0: /* sgl/sgl */
452 return(sgl_to_sgl_fcnvfx(&fpregs
[r1
],0,
454 case 1: /* sgl/dbl */
455 return(sgl_to_dbl_fcnvfx(&fpregs
[r1
],0,
457 case 2: /* dbl/sgl */
458 return(dbl_to_sgl_fcnvfx(&fpregs
[r1
],0,
460 case 3: /* dbl/dbl */
461 return(dbl_to_dbl_fcnvfx(&fpregs
[r1
],0,
464 case 3: /* FCNVFXT */
466 case 0: /* sgl/sgl */
467 return(sgl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
469 case 1: /* sgl/dbl */
470 return(sgl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
472 case 2: /* dbl/sgl */
473 return(dbl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
475 case 3: /* dbl/dbl */
476 return(dbl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
479 case 5: /* FCNVUF (PA2.0 only) */
481 case 0: /* sgl/sgl */
482 return(sgl_to_sgl_fcnvuf(&fpregs
[r1
],0,
484 case 1: /* sgl/dbl */
485 return(sgl_to_dbl_fcnvuf(&fpregs
[r1
],0,
487 case 2: /* dbl/sgl */
488 return(dbl_to_sgl_fcnvuf(&fpregs
[r1
],0,
490 case 3: /* dbl/dbl */
491 return(dbl_to_dbl_fcnvuf(&fpregs
[r1
],0,
494 case 6: /* FCNVFU (PA2.0 only) */
496 case 0: /* sgl/sgl */
497 return(sgl_to_sgl_fcnvfu(&fpregs
[r1
],0,
499 case 1: /* sgl/dbl */
500 return(sgl_to_dbl_fcnvfu(&fpregs
[r1
],0,
502 case 2: /* dbl/sgl */
503 return(dbl_to_sgl_fcnvfu(&fpregs
[r1
],0,
505 case 3: /* dbl/dbl */
506 return(dbl_to_dbl_fcnvfu(&fpregs
[r1
],0,
509 case 7: /* FCNVFUT (PA2.0 only) */
511 case 0: /* sgl/sgl */
512 return(sgl_to_sgl_fcnvfut(&fpregs
[r1
],0,
514 case 1: /* sgl/dbl */
515 return(sgl_to_dbl_fcnvfut(&fpregs
[r1
],0,
517 case 2: /* dbl/sgl */
518 return(dbl_to_sgl_fcnvfut(&fpregs
[r1
],0,
520 case 3: /* dbl/dbl */
521 return(dbl_to_dbl_fcnvfut(&fpregs
[r1
],0,
524 case 4: /* undefined */
525 return(MAJOR_0C_EXCP
);
526 } /* end of switch subop */
528 case 2: /* class 2 */
529 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
];
530 r2
= extru(ir
, fpr2pos
, 5) * sizeof(double)/sizeof(u_int
);
533 if (fpu_type_flags
& PA2_0_FPU_FLAG
) {
534 /* FTEST if nullify bit set, otherwise FCMP */
535 if (extru(ir
, fpnulpos
, 1)) { /* FTEST */
540 * second param is the t field used for
541 * ftest,acc and ftest,rej
542 * third param is the subop (y-field)
546 * return(ftest(0L,extru(ir,fptpos,5),
547 * &fpregs[0],subop));
552 return(MAJOR_0C_EXCP
);
557 retval
= sgl_fcmp(&fpregs
[r1
],
558 &fpregs
[r2
],extru(ir
,fptpos
,5),
560 update_status_cbit(status
,local_status
,
561 fpu_type_flags
, subop
);
564 retval
= dbl_fcmp(&fpregs
[r1
],
565 &fpregs
[r2
],extru(ir
,fptpos
,5),
567 update_status_cbit(status
,local_status
,
568 fpu_type_flags
, subop
);
570 case 2: /* illegal */
571 case 3: /* quad not implemented */
572 return(MAJOR_0C_EXCP
);
575 } /* end of if for PA2.0 */
576 else { /* PA1.0 & PA1.1 */
584 return(MAJOR_0C_EXCP
);
588 retval
= sgl_fcmp(&fpregs
[r1
],
589 &fpregs
[r2
],extru(ir
,fptpos
,5),
591 update_status_cbit(status
,local_status
,
592 fpu_type_flags
, subop
);
595 retval
= dbl_fcmp(&fpregs
[r1
],
596 &fpregs
[r2
],extru(ir
,fptpos
,5),
598 update_status_cbit(status
,local_status
,
599 fpu_type_flags
, subop
);
601 case 2: /* illegal */
602 case 3: /* quad not implemented */
603 return(MAJOR_0C_EXCP
);
610 * second param is the t field used for
611 * ftest,acc and ftest,rej
612 * third param is the subop (y-field)
616 * return(ftest(0L,extru(ir,fptpos,5),
617 * &fpregs[0],subop));
622 return(MAJOR_0C_EXCP
);
624 } /* end of switch subop */
625 } /* end of else for PA1.0 & PA1.1 */
626 case 3: /* class 3 */
627 r2
= extru(ir
,fpr2pos
,5) * sizeof(double)/sizeof(u_int
);
634 return(MAJOR_0C_EXCP
);
639 return(sgl_fadd(&fpregs
[r1
],&fpregs
[r2
],
642 return(dbl_fadd(&fpregs
[r1
],&fpregs
[r2
],
644 case 2: /* illegal */
645 case 3: /* quad not implemented */
646 return(MAJOR_0C_EXCP
);
651 return(sgl_fsub(&fpregs
[r1
],&fpregs
[r2
],
654 return(dbl_fsub(&fpregs
[r1
],&fpregs
[r2
],
656 case 2: /* illegal */
657 case 3: /* quad not implemented */
658 return(MAJOR_0C_EXCP
);
663 return(sgl_fmpy(&fpregs
[r1
],&fpregs
[r2
],
666 return(dbl_fmpy(&fpregs
[r1
],&fpregs
[r2
],
668 case 2: /* illegal */
669 case 3: /* quad not implemented */
670 return(MAJOR_0C_EXCP
);
675 return(sgl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
678 return(dbl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
680 case 2: /* illegal */
681 case 3: /* quad not implemented */
682 return(MAJOR_0C_EXCP
);
687 return(sgl_frem(&fpregs
[r1
],&fpregs
[r2
],
690 return(dbl_frem(&fpregs
[r1
],&fpregs
[r2
],
692 case 2: /* illegal */
693 case 3: /* quad not implemented */
694 return(MAJOR_0C_EXCP
);
696 } /* end of class 3 switch */
697 } /* end of switch(class) */
699 /* If we get here, something is really wrong! */
700 return(MAJOR_0C_EXCP
);
704 decode_0e(ir
,class,subop
,fpregs
)
705 u_int ir
,class,subop
;
708 u_int r1
,r2
,t
; /* operand register offsets */
709 u_int fmt
; /* also sf for class 1 conversions */
710 u_int df
; /* dest format for class 1 conversions */
712 u_int retval
, local_status
;
713 u_int fpu_type_flags
;
716 local_status
= fpregs
[0];
717 r1
= ((extru(ir
,fpr1pos
,5)<<1)|(extru(ir
,fpxr1pos
,1)));
720 t
= ((extru(ir
,fptpos
,5)<<1)|(extru(ir
,fpxtpos
,1)));
721 if (t
== 0 && class != 2)
722 return(MAJOR_0E_EXCP
);
723 if (class < 2) /* class 0 or 1 has 2 bit fmt */
724 fmt
= extru(ir
,fpfmtpos
,2);
725 else /* class 2 and 3 have 1 bit fmt */
726 fmt
= extru(ir
,fp0efmtpos
,1);
728 * An undefined combination, double precision accessing the
729 * right half of a FPR, can get us into trouble.
730 * Let's just force proper alignment on it.
741 case 0: /* unimplemented */
743 return(MAJOR_0E_EXCP
);
748 return(MAJOR_0E_EXCP
);
750 fpregs
[t
+1] = fpregs
[r1
+1];
752 fpregs
[t
] = fpregs
[r1
];
759 return(MAJOR_0E_EXCP
);
761 fpregs
[t
+1] = fpregs
[r1
+1];
763 fpregs
[t
] = fpregs
[r1
] & 0x7fffffff;
770 return(MAJOR_0E_EXCP
);
772 fpregs
[t
+1] = fpregs
[r1
+1];
774 fpregs
[t
] = fpregs
[r1
] ^ 0x80000000;
777 case 7: /* FNEGABS */
781 return(MAJOR_0E_EXCP
);
783 fpregs
[t
+1] = fpregs
[r1
+1];
785 fpregs
[t
] = fpregs
[r1
] | 0x80000000;
791 return(sgl_fsqrt(&fpregs
[r1
],0,
792 &fpregs
[t
], status
));
794 return(dbl_fsqrt(&fpregs
[r1
],0,
795 &fpregs
[t
], status
));
798 return(MAJOR_0E_EXCP
);
803 return(sgl_frnd(&fpregs
[r1
],0,
804 &fpregs
[t
], status
));
806 return(dbl_frnd(&fpregs
[r1
],0,
807 &fpregs
[t
], status
));
810 return(MAJOR_0E_EXCP
);
812 } /* end of switch (subop */
814 case 1: /* class 1 */
815 df
= extru(ir
,fpdfpos
,2); /* get dest format */
817 * Fix Crashme problem (writing to 31R in double precision)
823 if ((df
& 2) || (fmt
& 2))
824 return(MAJOR_0E_EXCP
);
826 fmt
= (fmt
<< 1) | df
;
830 case 0: /* sgl/sgl */
831 return(MAJOR_0E_EXCP
);
832 case 1: /* sgl/dbl */
833 return(sgl_to_dbl_fcnvff(&fpregs
[r1
],0,
835 case 2: /* dbl/sgl */
836 return(dbl_to_sgl_fcnvff(&fpregs
[r1
],0,
838 case 3: /* dbl/dbl */
839 return(MAJOR_0E_EXCP
);
843 case 0: /* sgl/sgl */
844 return(sgl_to_sgl_fcnvxf(&fpregs
[r1
],0,
846 case 1: /* sgl/dbl */
847 return(sgl_to_dbl_fcnvxf(&fpregs
[r1
],0,
849 case 2: /* dbl/sgl */
850 return(dbl_to_sgl_fcnvxf(&fpregs
[r1
],0,
852 case 3: /* dbl/dbl */
853 return(dbl_to_dbl_fcnvxf(&fpregs
[r1
],0,
858 case 0: /* sgl/sgl */
859 return(sgl_to_sgl_fcnvfx(&fpregs
[r1
],0,
861 case 1: /* sgl/dbl */
862 return(sgl_to_dbl_fcnvfx(&fpregs
[r1
],0,
864 case 2: /* dbl/sgl */
865 return(dbl_to_sgl_fcnvfx(&fpregs
[r1
],0,
867 case 3: /* dbl/dbl */
868 return(dbl_to_dbl_fcnvfx(&fpregs
[r1
],0,
871 case 3: /* FCNVFXT */
873 case 0: /* sgl/sgl */
874 return(sgl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
876 case 1: /* sgl/dbl */
877 return(sgl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
879 case 2: /* dbl/sgl */
880 return(dbl_to_sgl_fcnvfxt(&fpregs
[r1
],0,
882 case 3: /* dbl/dbl */
883 return(dbl_to_dbl_fcnvfxt(&fpregs
[r1
],0,
886 case 5: /* FCNVUF (PA2.0 only) */
888 case 0: /* sgl/sgl */
889 return(sgl_to_sgl_fcnvuf(&fpregs
[r1
],0,
891 case 1: /* sgl/dbl */
892 return(sgl_to_dbl_fcnvuf(&fpregs
[r1
],0,
894 case 2: /* dbl/sgl */
895 return(dbl_to_sgl_fcnvuf(&fpregs
[r1
],0,
897 case 3: /* dbl/dbl */
898 return(dbl_to_dbl_fcnvuf(&fpregs
[r1
],0,
901 case 6: /* FCNVFU (PA2.0 only) */
903 case 0: /* sgl/sgl */
904 return(sgl_to_sgl_fcnvfu(&fpregs
[r1
],0,
906 case 1: /* sgl/dbl */
907 return(sgl_to_dbl_fcnvfu(&fpregs
[r1
],0,
909 case 2: /* dbl/sgl */
910 return(dbl_to_sgl_fcnvfu(&fpregs
[r1
],0,
912 case 3: /* dbl/dbl */
913 return(dbl_to_dbl_fcnvfu(&fpregs
[r1
],0,
916 case 7: /* FCNVFUT (PA2.0 only) */
918 case 0: /* sgl/sgl */
919 return(sgl_to_sgl_fcnvfut(&fpregs
[r1
],0,
921 case 1: /* sgl/dbl */
922 return(sgl_to_dbl_fcnvfut(&fpregs
[r1
],0,
924 case 2: /* dbl/sgl */
925 return(dbl_to_sgl_fcnvfut(&fpregs
[r1
],0,
927 case 3: /* dbl/dbl */
928 return(dbl_to_dbl_fcnvfut(&fpregs
[r1
],0,
931 case 4: /* undefined */
932 return(MAJOR_0C_EXCP
);
933 } /* end of switch subop */
934 case 2: /* class 2 */
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.
944 r2
= (extru(ir
,fpr2pos
,5)<<1);
946 r2
= ((extru(ir
,fpr2pos
,5)<<1)|(extru(ir
,fpxr2pos
,1)));
947 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
];
950 if (fpu_type_flags
& PA2_0_FPU_FLAG
) {
951 /* FTEST if nullify bit set, otherwise FCMP */
952 if (extru(ir
, fpnulpos
, 1)) { /* FTEST */
954 return(MAJOR_0E_EXCP
);
958 * fmt is only 1 bit long
961 retval
= sgl_fcmp(&fpregs
[r1
],
962 &fpregs
[r2
],extru(ir
,fptpos
,5),
964 update_status_cbit(status
,local_status
,
965 fpu_type_flags
, subop
);
968 retval
= dbl_fcmp(&fpregs
[r1
],
969 &fpregs
[r2
],extru(ir
,fptpos
,5),
971 update_status_cbit(status
,local_status
,
972 fpu_type_flags
, subop
);
976 } /* end of if for PA2.0 */
977 else { /* PA1.0 & PA1.1 */
986 return(MAJOR_0E_EXCP
);
990 * fmt is only 1 bit long
993 retval
= sgl_fcmp(&fpregs
[r1
],
994 &fpregs
[r2
],extru(ir
,fptpos
,5),
996 update_status_cbit(status
,local_status
,
997 fpu_type_flags
, subop
);
1000 retval
= dbl_fcmp(&fpregs
[r1
],
1001 &fpregs
[r2
],extru(ir
,fptpos
,5),
1003 update_status_cbit(status
,local_status
,
1004 fpu_type_flags
, subop
);
1007 } /* end of switch subop */
1008 } /* end of else for PA1.0 & PA1.1 */
1009 case 3: /* class 3 */
1011 * Be careful out there.
1012 * Crashme can generate cases where FR31R is specified
1013 * as the source or target of a double precision operation.
1014 * Since we just pass the address of the floating-point
1015 * register to the emulation routines, this can cause
1016 * corruption of fpzeroreg.
1019 r2
= (extru(ir
,fpr2pos
,5)<<1);
1021 r2
= ((extru(ir
,fpr2pos
,5)<<1)|(extru(ir
,fpxr2pos
,1)));
1028 return(MAJOR_0E_EXCP
);
1031 * Note that fmt is only 1 bit for class 3 */
1035 return(sgl_fadd(&fpregs
[r1
],&fpregs
[r2
],
1036 &fpregs
[t
],status
));
1038 return(dbl_fadd(&fpregs
[r1
],&fpregs
[r2
],
1039 &fpregs
[t
],status
));
1044 return(sgl_fsub(&fpregs
[r1
],&fpregs
[r2
],
1045 &fpregs
[t
],status
));
1047 return(dbl_fsub(&fpregs
[r1
],&fpregs
[r2
],
1048 &fpregs
[t
],status
));
1050 case 2: /* FMPY or XMPYU */
1052 * check for integer multiply (x bit set)
1054 if (extru(ir
,fpxpos
,1)) {
1061 * bad instruction if t specifies
1062 * the right half of a register
1065 return(MAJOR_0E_EXCP
);
1068 * impyu(&fpregs[r1],&fpregs[r2],
1071 return(NOEXCEPTION
);
1073 return(MAJOR_0E_EXCP
);
1079 return(sgl_fmpy(&fpregs
[r1
],
1080 &fpregs
[r2
],&fpregs
[t
],status
));
1082 return(dbl_fmpy(&fpregs
[r1
],
1083 &fpregs
[r2
],&fpregs
[t
],status
));
1089 return(sgl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
1090 &fpregs
[t
],status
));
1092 return(dbl_fdiv(&fpregs
[r1
],&fpregs
[r2
],
1093 &fpregs
[t
],status
));
1098 return(sgl_frem(&fpregs
[r1
],&fpregs
[r2
],
1099 &fpregs
[t
],status
));
1101 return(dbl_frem(&fpregs
[r1
],&fpregs
[r2
],
1102 &fpregs
[t
],status
));
1104 } /* end of class 3 switch */
1105 } /* end of switch(class) */
1107 /* If we get here, something is really wrong! */
1108 return(MAJOR_0E_EXCP
);
1113 * routine to decode the 06 (FMPYADD and FMPYCFXT) instruction
1116 decode_06(ir
,fpregs
)
1120 u_int rm1
, rm2
, tm
, ra
, ta
; /* operands */
1124 u_int fpu_type_flags
;
1128 struct { u_int i1
; u_int i2
; } ints
;
1132 status
= fpregs
[0]; /* use a local copy of status reg */
1133 fpu_type_flags
=fpregs
[FPU_TYPE_FLAG_POS
]; /* get fpu type flags */
1134 fmt
= extru(ir
, fpmultifmt
, 1); /* get sgl/dbl flag */
1135 if (fmt
== 0) { /* DBL */
1136 rm1
= extru(ir
, fprm1pos
, 5) * sizeof(double)/sizeof(u_int
);
1139 rm2
= extru(ir
, fprm2pos
, 5) * sizeof(double)/sizeof(u_int
);
1142 tm
= extru(ir
, fptmpos
, 5) * sizeof(double)/sizeof(u_int
);
1144 return(MAJOR_06_EXCP
);
1145 ra
= extru(ir
, fprapos
, 5) * sizeof(double)/sizeof(u_int
);
1146 ta
= extru(ir
, fptapos
, 5) * sizeof(double)/sizeof(u_int
);
1148 return(MAJOR_06_EXCP
);
1150 if (fpu_type_flags
& TIMEX_ROLEX_FPU_MASK
) {
1153 /* special case FMPYCFXT, see sgl case below */
1154 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],
1155 &mtmp
.ints
.i1
,&status
))
1157 if (dbl_to_sgl_fcnvfxt(&fpregs
[ta
],
1158 &atmp
.ints
.i1
,&atmp
.ints
.i1
,&status
))
1163 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1166 if (dbl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1178 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1181 if (dbl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1188 return(MAJOR_06_EXCP
);
1191 fpregs
[tm
] = mtmp
.ints
.i1
;
1192 fpregs
[tm
+1] = mtmp
.ints
.i2
;
1193 fpregs
[ta
] = atmp
.ints
.i1
;
1194 fpregs
[ta
+1] = atmp
.ints
.i2
;
1196 return(NOEXCEPTION
);
1201 * calculate offsets for single precision numbers
1202 * See table 6-14 in PA-89 architecture for mapping
1204 rm1
= (extru(ir
,fprm1pos
,4) | 0x10 ) << 1; /* get offset */
1205 rm1
|= extru(ir
,fprm1pos
-4,1); /* add right word offset */
1207 rm2
= (extru(ir
,fprm2pos
,4) | 0x10 ) << 1; /* get offset */
1208 rm2
|= extru(ir
,fprm2pos
-4,1); /* add right word offset */
1210 tm
= (extru(ir
,fptmpos
,4) | 0x10 ) << 1; /* get offset */
1211 tm
|= extru(ir
,fptmpos
-4,1); /* add right word offset */
1213 ra
= (extru(ir
,fprapos
,4) | 0x10 ) << 1; /* get offset */
1214 ra
|= extru(ir
,fprapos
-4,1); /* add right word offset */
1216 ta
= (extru(ir
,fptapos
,4) | 0x10 ) << 1; /* get offset */
1217 ta
|= extru(ir
,fptapos
-4,1); /* add right word offset */
1219 if (ra
== 0x20 &&(fpu_type_flags
& TIMEX_ROLEX_FPU_MASK
)) {
1220 /* special case FMPYCFXT (really 0)
1221 * This instruction is only present on the Timex and
1222 * Rolex fpu's in so if it is the special case and
1223 * one of these fpu's we run the FMPYCFXT instruction
1225 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1228 if (sgl_to_sgl_fcnvfxt(&fpregs
[ta
],&atmp
.ints
.i1
,
1229 &atmp
.ints
.i1
,&status
))
1233 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,
1236 if (sgl_fadd(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,
1241 return(MAJOR_06_EXCP
);
1244 fpregs
[tm
] = mtmp
.ints
.i1
;
1245 fpregs
[ta
] = atmp
.ints
.i1
;
1247 return(NOEXCEPTION
);
1253 * routine to decode the 26 (FMPYSUB) instruction
1256 decode_26(ir
,fpregs
)
1260 u_int rm1
, rm2
, tm
, ra
, ta
; /* operands */
1267 struct { u_int i1
; u_int i2
; } ints
;
1272 fmt
= extru(ir
, fpmultifmt
, 1); /* get sgl/dbl flag */
1273 if (fmt
== 0) { /* DBL */
1274 rm1
= extru(ir
, fprm1pos
, 5) * sizeof(double)/sizeof(u_int
);
1277 rm2
= extru(ir
, fprm2pos
, 5) * sizeof(double)/sizeof(u_int
);
1280 tm
= extru(ir
, fptmpos
, 5) * sizeof(double)/sizeof(u_int
);
1282 return(MAJOR_26_EXCP
);
1283 ra
= extru(ir
, fprapos
, 5) * sizeof(double)/sizeof(u_int
);
1285 return(MAJOR_26_EXCP
);
1286 ta
= extru(ir
, fptapos
, 5) * sizeof(double)/sizeof(u_int
);
1288 return(MAJOR_26_EXCP
);
1290 if (dbl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,&status
))
1292 if (dbl_fsub(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,&status
))
1295 return(MAJOR_26_EXCP
);
1298 fpregs
[tm
] = mtmp
.ints
.i1
;
1299 fpregs
[tm
+1] = mtmp
.ints
.i2
;
1300 fpregs
[ta
] = atmp
.ints
.i1
;
1301 fpregs
[ta
+1] = atmp
.ints
.i2
;
1303 return(NOEXCEPTION
);
1308 * calculate offsets for single precision numbers
1309 * See table 6-14 in PA-89 architecture for mapping
1311 rm1
= (extru(ir
,fprm1pos
,4) | 0x10 ) << 1; /* get offset */
1312 rm1
|= extru(ir
,fprm1pos
-4,1); /* add right word offset */
1314 rm2
= (extru(ir
,fprm2pos
,4) | 0x10 ) << 1; /* get offset */
1315 rm2
|= extru(ir
,fprm2pos
-4,1); /* add right word offset */
1317 tm
= (extru(ir
,fptmpos
,4) | 0x10 ) << 1; /* get offset */
1318 tm
|= extru(ir
,fptmpos
-4,1); /* add right word offset */
1320 ra
= (extru(ir
,fprapos
,4) | 0x10 ) << 1; /* get offset */
1321 ra
|= extru(ir
,fprapos
-4,1); /* add right word offset */
1323 ta
= (extru(ir
,fptapos
,4) | 0x10 ) << 1; /* get offset */
1324 ta
|= extru(ir
,fptapos
-4,1); /* add right word offset */
1326 if (sgl_fmpy(&fpregs
[rm1
],&fpregs
[rm2
],&mtmp
.ints
.i1
,&status
))
1328 if (sgl_fsub(&fpregs
[ta
], &fpregs
[ra
], &atmp
.ints
.i1
,&status
))
1331 return(MAJOR_26_EXCP
);
1334 fpregs
[tm
] = mtmp
.ints
.i1
;
1335 fpregs
[ta
] = atmp
.ints
.i1
;
1337 return(NOEXCEPTION
);
1344 * routine to decode the 2E (FMPYFADD,FMPYNFADD) instructions
1347 decode_2e(ir
,fpregs
)
1351 u_int rm1
, rm2
, ra
, t
; /* operands */
1354 fmt
= extru(ir
,fpfmtpos
,1); /* get fmt completer */
1355 if (fmt
== DBL
) { /* DBL */
1356 rm1
= extru(ir
,fprm1pos
,5) * sizeof(double)/sizeof(u_int
);
1359 rm2
= extru(ir
,fprm2pos
,5) * sizeof(double)/sizeof(u_int
);
1362 ra
= ((extru(ir
,fpraupos
,3)<<2)|(extru(ir
,fpralpos
,3)>>1)) *
1363 sizeof(double)/sizeof(u_int
);
1366 t
= extru(ir
,fptpos
,5) * sizeof(double)/sizeof(u_int
);
1368 return(MAJOR_2E_EXCP
);
1370 if (extru(ir
,fpfusedsubop
,1)) { /* fmpyfadd or fmpynfadd? */
1371 return(dbl_fmpynfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1372 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1374 return(dbl_fmpyfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1375 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1379 rm1
= (extru(ir
,fprm1pos
,5)<<1)|(extru(ir
,fpxrm1pos
,1));
1382 rm2
= (extru(ir
,fprm2pos
,5)<<1)|(extru(ir
,fpxrm2pos
,1));
1385 ra
= (extru(ir
,fpraupos
,3)<<3)|extru(ir
,fpralpos
,3);
1388 t
= ((extru(ir
,fptpos
,5)<<1)|(extru(ir
,fpxtpos
,1)));
1390 return(MAJOR_2E_EXCP
);
1392 if (extru(ir
,fpfusedsubop
,1)) { /* fmpyfadd or fmpynfadd? */
1393 return(sgl_fmpynfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1394 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1396 return(sgl_fmpyfadd(&fpregs
[rm1
], &fpregs
[rm2
],
1397 &fpregs
[ra
], &fpregs
[0], &fpregs
[t
]));
1403 * update_status_cbit
1405 * This routine returns the correct FP status register value in
1406 * *status, based on the C-bit & V-bit returned by the FCMP
1407 * emulation routine in new_status. The architecture type
1408 * (PA83, PA89 or PA2.0) is available in fpu_type. The y_field
1409 * and the architecture type are used to determine what flavor
1410 * of FCMP is being emulated.
1413 update_status_cbit(status
, new_status
, fpu_type
, y_field
)
1414 u_int
*status
, new_status
;
1419 * For PA89 FPU's which implement the Compare Queue and
1420 * for PA2.0 FPU's, update the Compare Queue if the y-field = 0,
1421 * otherwise update the specified bit in the Compare Array.
1422 * Note that the y-field will always be 0 for non-PA2.0 FPU's.
1424 if ((fpu_type
& TIMEX_EXTEN_FLAG
) ||
1425 (fpu_type
& ROLEX_EXTEN_FLAG
) ||
1426 (fpu_type
& PA2_0_FPU_FLAG
)) {
1428 *status
= ((*status
& 0x04000000) >> 5) | /* old Cbit */
1429 ((*status
& 0x003ff000) >> 1) | /* old CQ */
1430 (new_status
& 0xffc007ff); /* all other bits*/
1432 *status
= (*status
& 0x04000000) | /* old Cbit */
1433 ((new_status
& 0x04000000) >> (y_field
+4)) |
1434 (new_status
& ~0x04000000 & /* other bits */
1435 ~(0x04000000 >> (y_field
+4)));
1438 /* if PA83, just update the C-bit */
1440 *status
= new_status
;