]> git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/thread.h
xnu-344.2.tar.gz
[apple/xnu.git] / osfmk / i386 / thread.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 * Mach Operating System
27 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
28 * All Rights Reserved.
29 *
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.
35 *
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.
39 *
40 * Carnegie Mellon requests users of this software to return to
41 *
42 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
43 * School of Computer Science
44 * Carnegie Mellon University
45 * Pittsburgh PA 15213-3890
46 *
47 * any improvements or extensions that they make and grant Carnegie Mellon
48 * the rights to redistribute these changes.
49 */
50 /*
51 */
52
53 /*
54 * File: machine/thread.h
55 *
56 * This file contains the structure definitions for the thread
57 * state as applied to I386 processors.
58 */
59
60 #ifndef _I386_THREAD_H_
61 #define _I386_THREAD_H_
62
63 #include <mach/boolean.h>
64 #include <mach/i386/vm_types.h>
65 #include <mach/i386/fp_reg.h>
66
67 #include <kern/lock.h>
68
69 #include <i386/iopb.h>
70 #include <i386/seg.h>
71 #include <i386/tss.h>
72 #include <i386/eflags.h>
73 #include <i386/thread_act.h>
74
75 /*
76 * i386_exception_link:
77 *
78 * This structure lives at the high end of the kernel stack.
79 * It points to the current thread`s user registers.
80 */
81 struct i386_exception_link {
82 struct i386_saved_state *saved_state;
83 };
84
85
86 /*
87 * On the kernel stack is:
88 * stack: ...
89 * struct i386_exception_link
90 * struct i386_kernel_state
91 * stack+KERNEL_STACK_SIZE
92 */
93
94 #define STACK_IKS(stack) \
95 ((struct i386_kernel_state *)((stack) + KERNEL_STACK_SIZE) - 1)
96 #define STACK_IEL(stack) \
97 ((struct i386_exception_link *)STACK_IKS(stack) - 1)
98
99 #if NCPUS > 1
100 #include <i386/mp_desc.h>
101 #endif
102
103 /*
104 * Boot-time data for master (or only) CPU
105 */
106 extern struct fake_descriptor idt[IDTSZ];
107 extern struct fake_descriptor gdt[GDTSZ];
108 extern struct fake_descriptor ldt[LDTSZ];
109 extern struct i386_tss ktss;
110 #if MACH_KDB
111 extern char db_stack_store[];
112 extern char db_task_stack_store[];
113 extern struct i386_tss dbtss;
114 extern void db_task_start(void);
115 #endif /* MACH_KDB */
116 #if NCPUS > 1
117 #define curr_gdt(mycpu) (mp_gdt[mycpu])
118 #define curr_ktss(mycpu) (mp_ktss[mycpu])
119 #else
120 #define curr_gdt(mycpu) (gdt)
121 #define curr_ktss(mycpu) (&ktss)
122 #endif
123
124 #define gdt_desc_p(mycpu,sel) \
125 ((struct real_descriptor *)&curr_gdt(mycpu)[sel_idx(sel)])
126
127 /*
128 * Return address of the function that called current function, given
129 * address of the first parameter of current function.
130 */
131 #define GET_RETURN_PC(addr) (*((vm_offset_t *)addr - 1))
132
133 /*
134 * Defining this indicates that MD code will supply an exception()
135 * routine, conformant with kern/exception.c (dependency alert!)
136 * but which does wonderfully fast, machine-dependent magic.
137 */
138 #define MACHINE_FAST_EXCEPTION 1
139
140 /*
141 * MD Macro to fill up global stack state,
142 * keeping the MD structure sizes + games private
143 */
144 #define MACHINE_STACK_STASH(stack) \
145 MACRO_BEGIN \
146 mp_disable_preemption(); \
147 kernel_stack[cpu_number()] = (stack) + \
148 (KERNEL_STACK_SIZE - sizeof (struct i386_exception_link) \
149 - sizeof (struct i386_kernel_state)), \
150 active_stacks[cpu_number()] = (stack); \
151 mp_enable_preemption(); \
152 MACRO_END
153
154 #endif /* _I386_THREAD_H_ */