]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/thread_act.h
20f8b7ed942166165ef5790dc434f78bf5989cea
[apple/xnu.git] / osfmk / i386 / thread_act.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 #ifndef _I386_THREAD_ACT_H_
30 #define _I386_THREAD_ACT_H_
31
32 #include <mach/boolean.h>
33 #include <mach/i386/vm_types.h>
34 #include <mach/i386/fp_reg.h>
35 #include <mach/thread_status.h>
36
37 #include <kern/lock.h>
38
39 #include <i386/iopb.h>
40 #include <i386/tss.h>
41 #include <i386/eflags.h>
42
43 /*
44 * i386_saved_state:
45 *
46 * Has been exported to servers. See: mach/i386/thread_status.h
47 *
48 * This structure corresponds to the state of user registers
49 * as saved upon kernel entry. It lives in the pcb.
50 * It is also pushed onto the stack for exceptions in the kernel.
51 * For performance, it is also used directly in syscall exceptions
52 * if the server has requested i386_THREAD_STATE flavor for the exception
53 * port.
54 *
55 * We define the following as an alias for the "esp" field of the
56 * structure, because we actually save cr2 here, not the kernel esp.
57 */
58 #define cr2 esp
59
60 /*
61 * Save area for user floating-point state.
62 * Allocated only when necessary.
63 */
64
65 struct i386_fpsave_state {
66 boolean_t fp_valid;
67 struct i386_fp_save fp_save_state;
68 struct i386_fp_regs fp_regs;
69 };
70
71 /*
72 * v86_assist_state:
73 *
74 * This structure provides data to simulate 8086 mode
75 * interrupts. It lives in the pcb.
76 */
77
78 struct v86_assist_state {
79 vm_offset_t int_table;
80 unsigned short int_count;
81 unsigned short flags; /* 8086 flag bits */
82 };
83 #define V86_IF_PENDING 0x8000 /* unused bit */
84
85 /*
86 * i386_interrupt_state:
87 *
88 * This structure describes the set of registers that must
89 * be pushed on the current ring-0 stack by an interrupt before
90 * we can switch to the interrupt stack.
91 */
92
93 struct i386_interrupt_state {
94 int es;
95 int ds;
96 int edx;
97 int ecx;
98 int eax;
99 int eip;
100 int cs;
101 int efl;
102 };
103
104 /*
105 * i386_kernel_state:
106 *
107 * This structure corresponds to the state of kernel registers
108 * as saved in a context-switch. It lives at the base of the stack.
109 */
110
111 struct i386_kernel_state {
112 int k_ebx; /* kernel context */
113 int k_esp;
114 int k_ebp;
115 int k_edi;
116 int k_esi;
117 int k_eip;
118 };
119
120 /*
121 * i386_machine_state:
122 *
123 * This structure corresponds to special machine state.
124 * It lives in the pcb. It is not saved by default.
125 */
126
127 struct i386_machine_state {
128 iopb_tss_t io_tss;
129 struct user_ldt * ldt;
130 struct i386_fpsave_state *ifps;
131 struct v86_assist_state v86s;
132 };
133
134 typedef struct pcb {
135 struct i386_interrupt_state iis[2]; /* interrupt and NMI */
136 struct i386_saved_state iss;
137 struct i386_machine_state ims;
138 #ifdef MACH_BSD
139 unsigned long cthread_self; /* for use of cthread package */
140 #endif
141 decl_simple_lock_data(,lock)
142 } *pcb_t;
143
144 /*
145 * Maps state flavor to number of words in the state:
146 */
147 extern unsigned int state_count[];
148
149
150 #define USER_REGS(ThrAct) (&(ThrAct)->mact.pcb->iss)
151
152 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
153
154
155 #define is_user_thread(ThrAct) \
156 ((USER_REGS(ThrAct)->efl & EFL_VM) \
157 || ((USER_REGS(ThrAct)->cs & 0x03) != 0))
158
159 #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip)
160 #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp)
161
162 #define syscall_emulation_sync(task) /* do nothing */
163
164 typedef struct MachineThrAct {
165 /*
166 * pointer to process control block
167 * (actual storage may as well be here, too)
168 */
169 struct pcb xxx_pcb;
170 pcb_t pcb;
171
172 } MachineThrAct, *MachineThrAct_t;
173
174 extern void *act_thread_csave(void);
175 extern void act_thread_catt(void *ctx);
176 extern void act_thread_cfree(void *ctx);
177
178 #define current_act_fast() (current_thread()->top_act)
179 #define current_act_slow() ((current_thread()) ? \
180 current_act_fast() : \
181 THR_ACT_NULL)
182
183 #define current_act() current_act_slow() /* JMM - til we find the culprit */
184
185 #endif /* _I386_THREAD_ACT_H_ */