2 * Copyright (c) 2000-2005 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
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.
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
20 * @APPLE_LICENSE_HEADER_END@
26 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
30 * Permission to use, copy, modify and distribute this software and its
31 * documentation is hereby granted, provided that both the copyright
32 * notice and this permission notice appear in all copies of the
33 * software, derivative works or modified versions, and any portions
34 * thereof, and that both notices appear in supporting documentation.
36 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
37 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
38 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
40 * Carnegie Mellon requests users of this software to return to
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
54 * File: machine/thread.h
56 * This file contains the structure definitions for the thread
57 * state as applied to I386 processors.
60 #ifndef _I386_THREAD_H_
61 #define _I386_THREAD_H_
63 #include <mach/boolean.h>
64 #include <mach/i386/vm_types.h>
65 #include <mach/i386/fp_reg.h>
66 #include <mach/thread_status.h>
68 #include <kern/lock.h>
70 #include <i386/iopb.h>
73 #include <i386/eflags.h>
78 * Has been exported to servers. See: mach/i386/thread_status.h
80 * This structure corresponds to the state of user registers
81 * as saved upon kernel entry. It lives in the pcb.
82 * It is also pushed onto the stack for exceptions in the kernel.
83 * For performance, it is also used directly in syscall exceptions
84 * if the server has requested i386_THREAD_STATE flavor for the exception
87 * We define the following as an alias for the "esp" field of the
88 * structure, because we actually save cr2 here, not the kernel esp.
93 * Save area for user floating-point state.
94 * Allocated only when necessary.
97 struct i386_fpsave_state
{
99 struct i386_fp_save fp_save_state
;
100 struct i386_fp_regs fp_regs
;
101 struct i386_fx_save fx_save_state
__attribute__ ((aligned (16)));
108 * This structure provides data to simulate 8086 mode
109 * interrupts. It lives in the pcb.
112 struct v86_assist_state
{
113 vm_offset_t int_table
;
114 unsigned short int_count
;
115 unsigned short flags
; /* 8086 flag bits */
117 #define V86_IF_PENDING 0x8000 /* unused bit */
120 * i386_interrupt_state:
122 * This structure describes the set of registers that must
123 * be pushed on the current ring-0 stack by an interrupt before
124 * we can switch to the interrupt stack.
127 struct i386_interrupt_state
{
143 * This structure corresponds to the state of kernel registers
144 * as saved in a context-switch. It lives at the base of the stack.
147 struct i386_kernel_state
{
148 int k_ebx
; /* kernel context */
157 * i386_machine_state:
159 * This structure corresponds to special machine state.
160 * It lives in the pcb. It is not saved by default.
163 struct i386_machine_state
{
165 struct user_ldt
* ldt
;
166 struct i386_fpsave_state
*ifps
;
167 struct v86_assist_state v86s
;
171 struct i386_interrupt_state iis
[2]; /* interrupt and NMI */
172 struct i386_saved_state iss
;
173 struct i386_machine_state ims
;
175 unsigned long cthread_self
; /* for use of cthread package */
176 struct real_descriptor cthread_desc
;
177 unsigned long uldt_selector
; /* user ldt selector to set */
178 struct real_descriptor uldt_desc
; /* the actual user setable ldt data */
180 decl_simple_lock_data(,lock
)
184 * Maps state flavor to number of words in the state:
186 __private_extern__
unsigned int _MachineStateCount
[];
188 #define USER_REGS(ThrAct) (&(ThrAct)->machine.pcb->iss)
190 #define act_machine_state_ptr(ThrAct) (thread_state_t)USER_REGS(ThrAct)
193 #define is_user_thread(ThrAct) \
194 ((USER_REGS(ThrAct)->efl & EFL_VM) \
195 || ((USER_REGS(ThrAct)->cs & 0x03) != 0))
197 #define user_pc(ThrAct) (USER_REGS(ThrAct)->eip)
198 #define user_sp(ThrAct) (USER_REGS(ThrAct)->uesp)
200 struct machine_thread
{
202 * pointer to process control block
203 * (actual storage may as well be here, too)
210 extern struct i386_saved_state
*get_user_regs(thread_t
);
212 extern void *act_thread_csave(void);
213 extern void act_thread_catt(void *ctx
);
214 extern void act_thread_cfree(void *ctx
);
217 * i386_exception_link:
219 * This structure lives at the high end of the kernel stack.
220 * It points to the current thread`s user registers.
222 struct i386_exception_link
{
223 struct i386_saved_state
*saved_state
;
228 * On the kernel stack is:
230 * struct i386_exception_link
231 * struct i386_kernel_state
232 * stack+KERNEL_STACK_SIZE
235 #define STACK_IKS(stack) \
236 ((struct i386_kernel_state *)((stack) + KERNEL_STACK_SIZE) - 1)
237 #define STACK_IEL(stack) \
238 ((struct i386_exception_link *)STACK_IKS(stack) - 1)
241 * Return address of the function that called current function, given
242 * address of the first parameter of current function.
244 #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1))
247 * Defining this indicates that MD code will supply an exception()
248 * routine, conformant with kern/exception.c (dependency alert!)
249 * but which does wonderfully fast, machine-dependent magic.
251 #define MACHINE_FAST_EXCEPTION 1
253 #endif /* _I386_THREAD_H_ */