]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/fpu.h
xnu-344.21.74.tar.gz
[apple/xnu.git] / osfmk / i386 / fpu.h
1 /*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
7 *
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * file.
14 *
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
22 *
23 * @APPLE_LICENSE_HEADER_END@
24 */
25 /*
26 * @OSF_COPYRIGHT@
27 */
28 /*
29 * Mach Operating System
30 * Copyright (c) 1991 Carnegie Mellon University
31 * All Rights Reserved.
32 *
33 * Permission to use, copy, modify and distribute this software and its
34 * documentation is hereby granted, provided that both the copyright
35 * notice and this permission notice appear in all copies of the
36 * software, derivative works or modified versions, and any portions
37 * thereof, and that both notices appear in supporting documentation.
38 *
39 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
40 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
41 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
42 *
43 * Carnegie Mellon requests users of this software to return to
44 *
45 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
46 * School of Computer Science
47 * Carnegie Mellon University
48 * Pittsburgh PA 15213-3890
49 *
50 * any improvements or extensions that they make and grant Carnegie Mellon
51 * the rights to redistribute these changes.
52 */
53
54 /*
55 */
56
57 #ifndef _I386_FPU_H_
58 #define _I386_FPU_H_
59
60 /*
61 * Macro definitions for routines to manipulate the
62 * floating-point processor.
63 */
64
65 #include <cpus.h>
66 #include <i386/proc_reg.h>
67 #include <i386/thread.h>
68 #include <kern/kern_types.h>
69 #include <mach/i386/kern_return.h>
70 #include <mach/i386/thread_status.h>
71
72 /*
73 * FPU instructions.
74 */
75 #define fninit() \
76 __asm__ volatile("fninit")
77
78 #define fnstcw(control) \
79 __asm__("fnstcw %0" : "=m" (*(unsigned short *)(control)))
80
81 #define fldcw(control) \
82 __asm__ volatile("fldcw %0" : : "m" (*(unsigned short *) &(control)) )
83
84 extern unsigned short fnstsw(void);
85
86 extern __inline__ unsigned short fnstsw(void)
87 {
88 unsigned short status;
89 __asm__ volatile("fnstsw %0" : "=ma" (status));
90 return(status);
91 }
92
93 #define fnclex() \
94 __asm__ volatile("fnclex")
95
96 #define fnsave(state) \
97 __asm__ volatile("fnsave %0" : "=m" (*state))
98
99 #define frstor(state) \
100 __asm__ volatile("frstor %0" : : "m" (state))
101
102 #define fwait() \
103 __asm__("fwait");
104
105
106 #define fpu_load_context(pcb)
107
108 /*
109 * Save thread`s FPU context.
110 * If only one CPU, we just set the task-switched bit,
111 * to keep the new thread from using the coprocessor.
112 * If multiple CPUs, we save the entire state.
113 */
114 #if NCPUS > 1
115 #define fpu_save_context(thread) \
116 { \
117 register struct i386_fpsave_state *ifps; \
118 ifps = (thread)->top_act->mact.pcb->ims.ifps; \
119 if (ifps != 0 && !ifps->fp_valid) { \
120 /* registers are in FPU - save to memory */ \
121 ifps->fp_valid = TRUE; \
122 fnsave(&ifps->fp_save_state); \
123 } \
124 set_ts(); \
125 }
126
127 #else /* NCPUS == 1 */
128 #define fpu_save_context(thread) \
129 { \
130 set_ts(); \
131 }
132
133 #endif /* NCPUS == 1 */
134
135
136 extern int fp_kind;
137
138 extern void init_fpu(void);
139 extern void fpu_module_init(void);
140 extern void fp_free(
141 struct i386_fpsave_state * fps);
142 extern kern_return_t fpu_set_state(
143 thread_act_t thr_act,
144 struct i386_float_state * st);
145 extern kern_return_t fpu_get_state(
146 thread_act_t thr_act,
147 struct i386_float_state * st);
148 extern void fpnoextflt(void);
149 extern void fpextovrflt(void);
150 extern void fpexterrflt(void);
151 extern void fp_state_alloc(void);
152 extern void fpintr(void);
153 extern void fpflush(thread_act_t);
154
155 #endif /* _I386_FPU_H_ */