1/*	$OpenBSD: fpu.h,v 1.9 2011/03/23 16:54:34 pirofti Exp $	*/
2/*	$NetBSD: fpu.h,v 1.1 2003/04/26 18:39:40 fvdl Exp $	*/
3
4#ifndef	_MACHINE_FPU_H_
5#define	_MACHINE_FPU_H_
6
7#include <sys/types.h>
8
9/*
10 * amd64 only uses the extended save/restore format used
11 * by fxsave/fsrestore, to always deal with the SSE registers,
12 * which are part of the ABI to pass floating point values.
13 * Must be stored in memory on a 16-byte boundary.
14 */
15
16struct fxsave64 {
17	u_int16_t  fx_fcw;
18	u_int16_t  fx_fsw;
19	u_int8_t   fx_ftw;
20	u_int8_t   fx_unused1;
21	u_int16_t  fx_fop;
22	u_int64_t  fx_rip;
23	u_int64_t  fx_rdp;
24	u_int32_t  fx_mxcsr;
25	u_int32_t  fx_mxcsr_mask;
26	u_int64_t  fx_st[8][2];   /* 8 normal FP regs */
27	u_int64_t  fx_xmm[16][2]; /* 16 SSE2 registers */
28	u_int8_t   fx_unused3[96];
29} __packed;
30
31struct savefpu {
32	struct fxsave64 fp_fxsave;	/* see above */
33	u_int16_t fp_ex_sw;		/* saved status from last exception */
34	u_int16_t fp_ex_tw;		/* saved tag from last exception */
35};
36
37/*
38 * The i387 defaults to Intel extended precision mode and round to nearest,
39 * with all exceptions masked.
40 */
41#define	__INITIAL_NPXCW__	0x037f
42#define __INITIAL_MXCSR__ 	0x1f80
43#define __INITIAL_MXCSR_MASK__	0xffbf
44
45#ifdef _KERNEL
46/*
47 * XXX
48 */
49struct trapframe;
50struct cpu_info;
51
52extern uint32_t	fpu_mxcsr_mask;
53
54void fpuinit(struct cpu_info *);
55void fpudrop(void);
56void fpudiscard(struct proc *);
57void fputrap(struct trapframe *);
58void fpusave_proc(struct proc *, int);
59void fpusave_cpu(struct cpu_info *, int);
60void fpu_kernel_enter(void);
61void fpu_kernel_exit(void);
62
63#endif
64
65#endif /* _MACHINE_FPU_H_ */
66