4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or http://www.opensolaris.org/os/licensing.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
23 * Use is subject to license terms.
26 #ifndef _SYS_FPU_FPU_SIMULATOR_H
27 #define _SYS_FPU_FPU_SIMULATOR_H
32 * sparc floating-point simulator definitions.
36 #include <sys/types.h>
37 #include <sys/ieeefp.h>
39 #include <sys/kstat.h>
47 * Constants to decode/extract "fitos" instruction fields
49 #define FITOS_INSTR_MASK 0xc1f83fe0
50 #define FITOS_INSTR 0x81a01880
51 #define FITOS_RS2_SHIFT 0
52 #define FITOS_RD_SHIFT 25
53 #define FITOS_REG_MASK 0x1f
58 enum fcc_type
{ /* relationships */
65 enum cc_type
{ /* icc/fcc number */
76 enum ftt_type
{ /* types of traps */
80 ftt_unimplemented
= 3,
82 ftt_alignment
= 5, /* defined by software convention only */
83 ftt_fault
= 6, /* defined by software convention only */
87 typedef struct { /* sparc V9 FSR. */
89 unsigned int fcc3
: 2; /* fp condition code 3 */
90 unsigned int fcc2
: 2; /* fp condition code 2 */
91 unsigned int fcc1
: 2; /* fp condition code 1 */
92 /* enum fp_direction_type */
93 unsigned int rnd
: 2; /* rounding direction */
94 unsigned int rnp
: 2; /* for v7 compatibility only */
95 unsigned int tem
: 5; /* trap enable mask */
96 unsigned int ns
: 1; /* non-standard */
99 unsigned int ftt
: 3; /* FPU trap type */
100 unsigned int qne
: 1; /* FPQ not empty */
101 unsigned int pr
: 1; /* partial result */
103 unsigned int fcc
: 2; /* fp condition code 0 */
104 unsigned int aexc
: 5; /* accumulated exceptions */
105 unsigned int cexc
: 5; /* current exception */
109 * The C compiler and the C spec do not support bitfields in a long long,
110 * as per fsr_types above, so don't hold your breath waiting for this
111 * workaround cruft to disappear.
119 #define fcc3 fsr.fcc3
120 #define fcc2 fsr.fcc2
121 #define fcc1 fsr.fcc1
126 #define aexc fsr.aexc
127 #define cexc fsr.cexc
129 typedef /* FPU register viewed as single components. */
132 uint32_t exponent
: 8;
133 uint32_t significand
: 23;
136 typedef /* FPU register viewed as double components. */
139 uint32_t exponent
: 11;
140 uint32_t significand
: 20;
143 typedef /* FPU register viewed as extended components. */
146 uint32_t exponent
: 15;
147 uint32_t significand
: 16;
150 typedef /* FPU register with multiple data views. */
157 single_type single_reg
;
158 double_type double_reg
;
159 extended_type extended_reg
;
162 enum fp_op_type
{ /* Type specifiers in FPU instructions. */
163 fp_op_int32
= 0, /* Not in hardware, but convenient to define. */
170 enum fp_opcode
{ /* FPU op codes, minus precision and leading 0. */
174 fp_op_3
= 3, fp_op_4
= 4, fp_op_5
= 5, fp_op_6
= 6, fp_op_7
= 7,
178 fp_op_b
= 0xb, fp_op_c
= 0xc, fp_op_d
= 0xd,
179 fp_op_e
= 0xe, fp_op_f
= 0xf,
186 fp_op_16
= 0x16, fp_op_17
= 0x17,
195 fp_op_24
= 0x24, fp_op_25
= 0x25, fp_op_26
= 0x26, fp_op_27
= 0x27,
196 fp_op_28
= 0x28, fp_op_29
= 0x29, fp_op_2a
= 0x2a, fp_op_2b
= 0x2b,
197 fp_op_2c
= 0x2c, fp_op_2d
= 0x2d, fp_op_2e
= 0x2e, fp_op_2f
= 0x2f,
203 fp_op_35
= 0x35, fp_op_36
= 0x36, fp_op_37
= 0x37,
205 fp_op_39
= 0x39, fp_op_3a
= 0x3a, fp_op_3b
= 0x3b,
207 fp_op_3d
= 0x3d, fp_op_3e
= 0x3e, fp_op_3f
= 0x3f
210 typedef /* FPU instruction. */
212 uint32_t hibits
: 2; /* Top two bits. */
213 uint32_t rd
: 5; /* Destination. */
214 uint32_t op3
: 6; /* Main op code. */
215 uint32_t rs1
: 5; /* First operand. */
216 uint32_t ibit
: 1; /* I format bit. */
217 uint32_t /* enum fp_opcode */ opcode
: 6; /* Floating-point op code. */
218 uint32_t /* enum fp_op_type */ prec
: 2; /* Precision. */
219 uint32_t rs2
: 5; /* Second operand. */
222 enum fp_op_fma_var
{ /* IMPDEP2B FMA-fused instr. variations */
229 typedef /* IMPDEP2B FPU FMA-fused instruction. */
231 uint32_t hibits
: 2; /* Top two bits. */
232 uint32_t rd
: 5; /* Destination. */
233 uint32_t op3
: 6; /* Main op code. */
234 uint32_t rs1
: 5; /* First operand. */
235 uint32_t rs3
: 5; /* Third operand */
236 uint32_t /* enum fp_op_fma_var */ var
: 2; /* Instr. variation */
237 uint32_t sz
: 2; /* Size */
238 uint32_t rs2
: 5; /* Second operand. */
241 typedef /* Integer condition code. */
243 uint32_t : 28; /* the unused part */
244 uint32_t n
: 1; /* Negative bit. */
245 uint32_t z
: 1; /* Zero bit. */
246 uint32_t v
: 1; /* Overflow bit. */
247 uint32_t c
: 1; /* Carry bit. */
250 typedef /* FPU data used by simulator. */
253 enum fp_direction_type fp_direction
;
254 enum fp_precision_type fp_precision
;
255 uint_t fp_current_exceptions
;
256 kfpu_t
*fp_current_pfregs
;
257 void (*fp_current_read_freg
) ();
258 void (*fp_current_write_freg
) ();
259 void (*fp_current_read_dreg
) ();
260 void (*fp_current_write_dreg
) ();
261 uint64_t (*fp_current_read_gsr
) (kfpu_t
*);
262 void (*fp_current_write_gsr
) (uint64_t, kfpu_t
*);
265 struct regs
*fp_traprp
;
266 enum seg_rw fp_traprw
;
270 * FPU related kstat structures
272 struct fpustat_kstat
{
273 struct kstat_named fpu_ieee_traps
;
274 struct kstat_named fpu_unfinished_traps
;
275 struct kstat_named fpu_unimplemented_traps
;
278 struct fpuinfo_kstat
{
279 struct kstat_named fpu_sim_fmovs
;
280 struct kstat_named fpu_sim_fmovd
;
281 struct kstat_named fpu_sim_fmovq
;
282 struct kstat_named fpu_sim_fnegs
;
283 struct kstat_named fpu_sim_fnegd
;
284 struct kstat_named fpu_sim_fnegq
;
285 struct kstat_named fpu_sim_fabss
;
286 struct kstat_named fpu_sim_fabsd
;
287 struct kstat_named fpu_sim_fabsq
;
288 struct kstat_named fpu_sim_fsqrts
;
289 struct kstat_named fpu_sim_fsqrtd
;
290 struct kstat_named fpu_sim_fsqrtq
;
291 struct kstat_named fpu_sim_fadds
;
292 struct kstat_named fpu_sim_faddd
;
293 struct kstat_named fpu_sim_faddq
;
294 struct kstat_named fpu_sim_fsubs
;
295 struct kstat_named fpu_sim_fsubd
;
296 struct kstat_named fpu_sim_fsubq
;
297 struct kstat_named fpu_sim_fmuls
;
298 struct kstat_named fpu_sim_fmuld
;
299 struct kstat_named fpu_sim_fmulq
;
300 struct kstat_named fpu_sim_fdivs
;
301 struct kstat_named fpu_sim_fdivd
;
302 struct kstat_named fpu_sim_fdivq
;
303 struct kstat_named fpu_sim_fcmps
;
304 struct kstat_named fpu_sim_fcmpd
;
305 struct kstat_named fpu_sim_fcmpq
;
306 struct kstat_named fpu_sim_fcmpes
;
307 struct kstat_named fpu_sim_fcmped
;
308 struct kstat_named fpu_sim_fcmpeq
;
309 struct kstat_named fpu_sim_fsmuld
;
310 struct kstat_named fpu_sim_fdmulx
;
311 struct kstat_named fpu_sim_fstox
;
312 struct kstat_named fpu_sim_fdtox
;
313 struct kstat_named fpu_sim_fqtox
;
314 struct kstat_named fpu_sim_fxtos
;
315 struct kstat_named fpu_sim_fxtod
;
316 struct kstat_named fpu_sim_fxtoq
;
317 struct kstat_named fpu_sim_fitos
;
318 struct kstat_named fpu_sim_fitod
;
319 struct kstat_named fpu_sim_fitoq
;
320 struct kstat_named fpu_sim_fstoi
;
321 struct kstat_named fpu_sim_fdtoi
;
322 struct kstat_named fpu_sim_fqtoi
;
323 struct kstat_named fpu_sim_fmovcc
;
324 struct kstat_named fpu_sim_fmovr
;
325 struct kstat_named fpu_sim_fmadds
;
326 struct kstat_named fpu_sim_fmaddd
;
327 struct kstat_named fpu_sim_fmsubs
;
328 struct kstat_named fpu_sim_fmsubd
;
329 struct kstat_named fpu_sim_fnmadds
;
330 struct kstat_named fpu_sim_fnmaddd
;
331 struct kstat_named fpu_sim_fnmsubs
;
332 struct kstat_named fpu_sim_fnmsubd
;
333 struct kstat_named fpu_sim_invalid
;
336 struct visinfo_kstat
{
337 struct kstat_named vis_edge8
;
338 struct kstat_named vis_edge8n
;
339 struct kstat_named vis_edge8l
;
340 struct kstat_named vis_edge8ln
;
341 struct kstat_named vis_edge16
;
342 struct kstat_named vis_edge16n
;
343 struct kstat_named vis_edge16l
;
344 struct kstat_named vis_edge16ln
;
345 struct kstat_named vis_edge32
;
346 struct kstat_named vis_edge32n
;
347 struct kstat_named vis_edge32l
;
348 struct kstat_named vis_edge32ln
;
349 struct kstat_named vis_array8
;
350 struct kstat_named vis_array16
;
351 struct kstat_named vis_array32
;
352 struct kstat_named vis_bmask
;
353 struct kstat_named vis_fcmple16
;
354 struct kstat_named vis_fcmpne16
;
355 struct kstat_named vis_fcmpgt16
;
356 struct kstat_named vis_fcmpeq16
;
357 struct kstat_named vis_fcmple32
;
358 struct kstat_named vis_fcmpne32
;
359 struct kstat_named vis_fcmpgt32
;
360 struct kstat_named vis_fcmpeq32
;
361 struct kstat_named vis_fmul8x16
;
362 struct kstat_named vis_fmul8x16au
;
363 struct kstat_named vis_fmul8x16al
;
364 struct kstat_named vis_fmul8sux16
;
365 struct kstat_named vis_fmul8ulx16
;
366 struct kstat_named vis_fmuld8sux16
;
367 struct kstat_named vis_fmuld8ulx16
;
368 struct kstat_named vis_fpack16
;
369 struct kstat_named vis_fpack32
;
370 struct kstat_named vis_fpackfix
;
371 struct kstat_named vis_fexpand
;
372 struct kstat_named vis_fpmerge
;
373 struct kstat_named vis_pdist
;
374 struct kstat_named vis_pdistn
;
375 struct kstat_named vis_bshuffle
;
378 #define VISINFO_KSTAT(opcode) { \
379 extern void __dtrace_probe___visinfo_##opcode(uint64_t *); \
380 uint64_t *stataddr = &visinfo.opcode.value.ui64; \
381 __dtrace_probe___visinfo_##opcode(stataddr); \
382 atomic_inc_64(&visinfo.opcode.value.ui64); \
386 /* PUBLIC FUNCTIONS */
391 * fpu_vis_sim simulates FPU VIS Partial load store instructions; reads and
392 * writes FPU data registers directly or works with the PCB image if fpu_exists
395 extern enum ftt_type
fpu_vis_sim(fp_simd_type
*pfpsd
, fp_inst_type
*pinst
,
396 struct regs
*pregs
, fsr_type
*pfsr
, uint64_t gsr
, uint32_t inst
);
398 * fpu_simulator simulates FPU instructions only; reads and writes FPU data
399 * registers directly.
401 extern enum ftt_type
fpu_simulator(fp_simd_type
*pfpsd
, fp_inst_type
*pinst
,
402 fsr_type
*pfsr
, uint64_t gsr
, uint32_t inst
);
404 * fp_emulator simulates FPU and CPU-FPU instructions; reads and writes FPU
405 * data registers from image in pfpu.
407 extern enum ftt_type
fp_emulator(fp_simd_type
*pfpsd
, fp_inst_type
*pinst
,
408 struct regs
*rp
, void *prw
, kfpu_t
*pfpu
);
410 * fp_traps handles passing exception conditions to the kernel.
411 * It is called after fp_simulator or fp_emulator fail (return a non-zero ftt).
413 extern void fp_traps(fp_simd_type
*pfpsd
, enum ftt_type ftt
, struct regs
*rp
);
416 * fp_kstat_update tracks fpu exception conditions.
417 * It is called after a hardware trap returns a non-zero ftt.
419 extern void fp_kstat_update(enum ftt_type ftt
);
422 * fp_precise handles floating point unimplemented and unfinished traps,
423 * for sparc V9 hardware. These traps are normally passed along to the
424 * fpu_simulator, to see if it can run the unimplemented instruction or
425 * finish the unfinished instruction. Needless to say, this takes time.
427 extern void fp_precise(struct regs
*rp
);
430 * fpu_trap handles V9 floating point ieee and other floating point traps.
431 * It is called after fp_simulator or fp_emulator fail (return a non-zero ftt),
432 * and from the _fp_ieee_exception trap handler.
434 extern void fpu_trap(struct regs
*rp
, caddr_t addr
, uint32_t type
,
437 #else /* ! __STDC__ */
440 * fpu_simulator simulates FPU instructions only; reads and writes FPU data
441 * registers directly.
443 extern enum ftt_type
fpu_simulator(
444 fp_simd_type
*pfpsd
, /* Pointer to FPU simulator data */
445 fp_inst_type
*pinst
, /* Pointer to FPU instruction to simulate. */
446 fsr_type
*pfsr
, /* Pointer to image of FSR to read & write. */
447 int instr
); /* Instruction to emulate. */
450 * fp_emulator simulates FPU and CPU-FPU instructions; reads and writes FPU
451 * data registers from image in pfpu.
453 extern enum ftt_type
fp_emulator(
454 fp_simd_type
*pfpsd
, /* Pointer to FPU simulator data */
455 fp_inst_type
*pinst
, /* Pointer to FPU instruction to simulate. */
456 struct regs
*pregs
, /* Pointer to PCB image of registers. */
457 struct rwindow
*pwindow
, /* Pointer to locals and ins. */
458 struct _fpu
*pfpu
); /* Pointer to FPU register block. */
461 * fp_traps handles passing exception conditions to the kernel.
462 * It is called after fp_simulator or fp_emulator fail (return a non-zero ftt).
464 extern void fp_traps(
465 fp_simd_type
*pfpsd
, /* Pointer to FPU simulator data */
466 enum ftt_type ftt
, /* Type of trap. */
467 struct regs
*rp
); /* Pointer to PCB image of registers. */
470 * fp_kstat_update tracks fpu exception conditions.
471 * It is called after a hardware trap returns a non-zero ftt.
473 extern void fp_kstat_update(enum ftt_type ftt
); /* Type of trap. */
476 * fp_precise handles floating point unimplemented and unfinished traps,
477 * for sparc V9 hardware. These traps are normally passed along to the
478 * fpu_simulator, to see if it can run the unimplemented instruction or
479 * finish the unfinished instruction. Needless to say, this takes time.
481 extern void fp_precise(
482 struct regs
*rp
); /* Pointer to PCB image of registers. */
485 * fpu_trap handles V9 floating point ieee and other floating point traps.
486 * It is called after fp_simulator or fp_emulator fail (return a non-zero ftt),
487 * and from the _fp_ieee_exception trap handler.
489 extern void fpu_trap(
490 struct regs
*rp
, /* Pointer to PCB image of registers. */
491 caddr_t addr
, /* Address of trapping instruction. */
492 uint32_t type
, /* Type of trapping exception. */
493 uint32_t code
); /* Trap code -> si_code. */
495 #endif /* __STDC__ */
502 #endif /* _SYS_FPU_FPU_SIMULATOR_H */