2 * Copyright (c) 2000-2006 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
89 * Save area for user floating-point state.
90 * Allocated only when necessary.
93 struct x86_fpsave_state
{
99 struct x86_fx_save fx_save_state
__attribute__ ((aligned (16)));
104 * x86_kernel_state32:
106 * This structure corresponds to the state of kernel registers
107 * as saved in a context-switch. It lives at the base of the stack.
108 * kernel only runs in 32 bit mode for now
111 struct x86_kernel_state32
{
112 int k_ebx
; /* kernel context */
119 * Kernel stacks are 16-byte aligned with a 4-byte i386_exception_link at
120 * the top, followed by an x86_kernel_state32. After both structs have
121 * been pushed, we want to be 16-byte aligned. A dummy int gets us there.
129 x86_saved_state_t
*iss
;
130 struct x86_fpsave_state
*ifps
;
132 uint64_t cthread_self
; /* for use of cthread package */
133 struct real_descriptor cthread_desc
;
134 unsigned long uldt_selector
; /* user ldt selector to set */
135 struct real_descriptor uldt_desc
; /* the actual user setable ldt data */
137 decl_simple_lock_data(,lock
);
145 * Maps state flavor to number of words in the state:
147 __private_extern__
unsigned int _MachineStateCount
[];
149 #define USER_STATE(ThrAct) ((ThrAct)->machine.pcb->iss)
150 #define USER_REGS32(ThrAct) (saved_state32(USER_STATE(ThrAct)))
151 #define USER_REGS64(ThrAct) (saved_state64(USER_STATE(ThrAct)))
153 #define user_pc(ThrAct) (is_saved_state32(USER_STATE(ThrAct)) ? \
154 USER_REGS32(ThrAct)->eip : \
155 USER_REGS64(ThrAct)->isf.rip )
158 struct machine_thread
{
160 * pointer to process control block
161 * (actual storage may as well be here, too)
170 user_addr_t user_base
;
171 } copy_window
[NCOPY_WINDOWS
];
174 #define WINDOWS_DIRTY 0
175 #define WINDOWS_CLEAN 1
176 #define WINDOWS_CLOSED 2
177 #define WINDOWS_OPENED 3
178 uint64_t physwindow_pte
;
183 extern void *get_user_regs(thread_t
);
185 extern void *act_thread_csave(void);
186 extern void act_thread_catt(void *ctx
);
187 extern void act_thread_cfree(void *ctx
);
190 * i386_exception_link:
192 * This structure lives at the high end of the kernel stack.
193 * It points to the current thread`s user registers.
195 struct i386_exception_link
{
196 x86_saved_state_t
*saved_state
;
201 * On the kernel stack is:
203 * struct i386_exception_link
204 * struct i386_kernel_state
205 * stack+KERNEL_STACK_SIZE
208 #define STACK_IKS(stack) \
209 ((struct x86_kernel_state32 *)((stack) + KERNEL_STACK_SIZE) - 1)
210 #define STACK_IEL(stack) \
211 ((struct i386_exception_link *)STACK_IKS(stack) - 1)
214 * Return address of the function that called current function, given
215 * address of the first parameter of current function.
217 #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1))
220 * Defining this indicates that MD code will supply an exception()
221 * routine, conformant with kern/exception.c (dependency alert!)
222 * but which does wonderfully fast, machine-dependent magic.
224 #define MACHINE_FAST_EXCEPTION 1
226 #endif /* _I386_THREAD_H_ */