2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
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
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.
23 * @APPLE_LICENSE_HEADER_END@
29 #ifndef _I386_THREAD_ACT_H_
30 #define _I386_THREAD_ACT_H_
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>
37 #include <kern/lock.h>
39 #include <i386/iopb.h>
42 #include <i386/eflags.h>
47 * Has been exported to servers. See: mach/i386/thread_status.h
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
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.
62 * Save area for user floating-point state.
63 * Allocated only when necessary.
66 struct i386_fpsave_state
{
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)));
77 * This structure provides data to simulate 8086 mode
78 * interrupts. It lives in the pcb.
81 struct v86_assist_state
{
82 vm_offset_t int_table
;
83 unsigned short int_count
;
84 unsigned short flags
; /* 8086 flag bits */
86 #define V86_IF_PENDING 0x8000 /* unused bit */
89 * i386_interrupt_state:
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.
96 struct i386_interrupt_state
{
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.
116 struct i386_kernel_state
{
117 int k_ebx
; /* kernel context */
126 * i386_machine_state:
128 * This structure corresponds to special machine state.
129 * It lives in the pcb. It is not saved by default.
132 struct i386_machine_state
{
134 struct user_ldt
* ldt
;
135 struct i386_fpsave_state
*ifps
;
136 struct v86_assist_state v86s
;
140 struct i386_interrupt_state iis
[2]; /* interrupt and NMI */
141 struct i386_saved_state iss
;
142 struct i386_machine_state ims
;
144 unsigned long cthread_self
; /* for use of cthread package */
145 struct real_descriptor cthread_desc
;
147 decl_simple_lock_data(,lock
)
151 * Maps state flavor to number of words in the state:
153 extern unsigned int state_count
[];
156 #define USER_REGS(ThrAct) (&(ThrAct)->mact.pcb->iss)
158 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
161 #define is_user_thread(ThrAct) \
162 ((USER_REGS(ThrAct)->efl & EFL_VM) \
163 || ((USER_REGS(ThrAct)->cs & 0x03) != 0))
165 #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip)
166 #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp)
168 #define syscall_emulation_sync(task) /* do nothing */
170 typedef struct MachineThrAct
{
172 * pointer to process control block
173 * (actual storage may as well be here, too)
178 } MachineThrAct
, *MachineThrAct_t
;
180 extern void *act_thread_csave(void);
181 extern void act_thread_catt(void *ctx
);
182 extern void act_thread_cfree(void *ctx
);
184 extern vm_offset_t active_stacks
[NCPUS
];
185 extern vm_offset_t kernel_stack
[NCPUS
];
186 extern thread_act_t active_kloaded
[NCPUS
];
188 #endif /* _I386_THREAD_ACT_H_ */