]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/thread_act.h
xnu-517.9.5.tar.gz
[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 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22 /*
23 * @OSF_COPYRIGHT@
24 */
25
26 #ifndef _I386_THREAD_ACT_H_
27 #define _I386_THREAD_ACT_H_
28
29 #include <mach/boolean.h>
30 #include <mach/i386/vm_types.h>
31 #include <mach/i386/fp_reg.h>
32 #include <mach/thread_status.h>
33
34 #include <kern/lock.h>
35
36 #include <i386/iopb.h>
37 #include <i386/tss.h>
38 #include <i386/seg.h>
39 #include <i386/eflags.h>
40
41 /*
42 * i386_saved_state:
43 *
44 * Has been exported to servers. See: mach/i386/thread_status.h
45 *
46 * This structure corresponds to the state of user registers
47 * as saved upon kernel entry. It lives in the pcb.
48 * It is also pushed onto the stack for exceptions in the kernel.
49 * For performance, it is also used directly in syscall exceptions
50 * if the server has requested i386_THREAD_STATE flavor for the exception
51 * port.
52 *
53 * We define the following as an alias for the "esp" field of the
54 * structure, because we actually save cr2 here, not the kernel esp.
55 */
56 #define cr2 esp
57
58 /*
59 * Save area for user floating-point state.
60 * Allocated only when necessary.
61 */
62
63 struct i386_fpsave_state {
64 boolean_t fp_valid;
65 struct i386_fp_save fp_save_state;
66 struct i386_fp_regs fp_regs;
67 struct i386_fx_save fx_save_state __attribute__ ((aligned (16)));
68 int fp_save_flavor;
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 gs;
95 int fs;
96 int es;
97 int ds;
98 int edx;
99 int ecx;
100 int eax;
101 int eip;
102 int cs;
103 int efl;
104 };
105
106 /*
107 * i386_kernel_state:
108 *
109 * This structure corresponds to the state of kernel registers
110 * as saved in a context-switch. It lives at the base of the stack.
111 */
112
113 struct i386_kernel_state {
114 int k_ebx; /* kernel context */
115 int k_esp;
116 int k_ebp;
117 int k_edi;
118 int k_esi;
119 int k_eip;
120 };
121
122 /*
123 * i386_machine_state:
124 *
125 * This structure corresponds to special machine state.
126 * It lives in the pcb. It is not saved by default.
127 */
128
129 struct i386_machine_state {
130 iopb_tss_t io_tss;
131 struct user_ldt * ldt;
132 struct i386_fpsave_state *ifps;
133 struct v86_assist_state v86s;
134 };
135
136 typedef struct pcb {
137 struct i386_interrupt_state iis[2]; /* interrupt and NMI */
138 struct i386_saved_state iss;
139 struct i386_machine_state ims;
140 #ifdef MACH_BSD
141 unsigned long cthread_self; /* for use of cthread package */
142 struct real_descriptor cthread_desc;
143 #endif
144 decl_simple_lock_data(,lock)
145 } *pcb_t;
146
147 /*
148 * Maps state flavor to number of words in the state:
149 */
150 extern unsigned int state_count[];
151
152
153 #define USER_REGS(ThrAct) (&(ThrAct)->mact.pcb->iss)
154
155 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
156
157
158 #define is_user_thread(ThrAct) \
159 ((USER_REGS(ThrAct)->efl & EFL_VM) \
160 || ((USER_REGS(ThrAct)->cs & 0x03) != 0))
161
162 #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip)
163 #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp)
164
165 #define syscall_emulation_sync(task) /* do nothing */
166
167 typedef struct MachineThrAct {
168 /*
169 * pointer to process control block
170 * (actual storage may as well be here, too)
171 */
172 struct pcb xxx_pcb;
173 pcb_t pcb;
174
175 } MachineThrAct, *MachineThrAct_t;
176
177 extern void *act_thread_csave(void);
178 extern void act_thread_catt(void *ctx);
179 extern void act_thread_cfree(void *ctx);
180
181 extern vm_offset_t active_stacks[NCPUS];
182 extern vm_offset_t kernel_stack[NCPUS];
183 extern thread_act_t active_kloaded[NCPUS];
184
185 #endif /* _I386_THREAD_ACT_H_ */