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