]>
Commit | Line | Data |
---|---|---|
1c79356b | 1 | /* |
39236c6e | 2 | * Copyright (c) 2000-2012 Apple Inc. All rights reserved. |
1c79356b | 3 | * |
2d21ac55 | 4 | * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ |
1c79356b | 5 | * |
2d21ac55 A |
6 | * This file contains Original Code and/or Modifications of Original Code |
7 | * as defined in and that are subject to the Apple Public Source License | |
8 | * Version 2.0 (the 'License'). You may not use this file except in | |
9 | * compliance with the License. The rights granted to you under the License | |
10 | * may not be used to create, or enable the creation or redistribution of, | |
11 | * unlawful or unlicensed copies of an Apple operating system, or to | |
12 | * circumvent, violate, or enable the circumvention or violation of, any | |
13 | * terms of an Apple operating system software license agreement. | |
8f6c56a5 | 14 | * |
2d21ac55 A |
15 | * Please obtain a copy of the License at |
16 | * http://www.opensource.apple.com/apsl/ and read it before using this file. | |
17 | * | |
18 | * The Original Code and all software distributed under the License are | |
19 | * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER | |
8f6c56a5 A |
20 | * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, |
21 | * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, | |
2d21ac55 A |
22 | * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. |
23 | * Please see the License for the specific language governing rights and | |
24 | * limitations under the License. | |
8f6c56a5 | 25 | * |
2d21ac55 | 26 | * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ |
1c79356b A |
27 | */ |
28 | /* | |
29 | * @OSF_COPYRIGHT@ | |
30 | */ | |
31 | /* | |
32 | * Mach Operating System | |
33 | * Copyright (c) 1991,1990,1989 Carnegie Mellon University | |
34 | * All Rights Reserved. | |
35 | * | |
36 | * Permission to use, copy, modify and distribute this software and its | |
37 | * documentation is hereby granted, provided that both the copyright | |
38 | * notice and this permission notice appear in all copies of the | |
39 | * software, derivative works or modified versions, and any portions | |
40 | * thereof, and that both notices appear in supporting documentation. | |
41 | * | |
42 | * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" | |
43 | * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR | |
44 | * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. | |
45 | * | |
46 | * Carnegie Mellon requests users of this software to return to | |
47 | * | |
48 | * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU | |
49 | * School of Computer Science | |
50 | * Carnegie Mellon University | |
51 | * Pittsburgh PA 15213-3890 | |
52 | * | |
53 | * any improvements or extensions that they make and grant Carnegie Mellon | |
54 | * the rights to redistribute these changes. | |
55 | */ | |
56 | /* | |
57 | */ | |
58 | ||
59 | /* | |
60 | * File: machine/thread.h | |
61 | * | |
62 | * This file contains the structure definitions for the thread | |
63 | * state as applied to I386 processors. | |
64 | */ | |
65 | ||
66 | #ifndef _I386_THREAD_H_ | |
67 | #define _I386_THREAD_H_ | |
68 | ||
69 | #include <mach/boolean.h> | |
70 | #include <mach/i386/vm_types.h> | |
71 | #include <mach/i386/fp_reg.h> | |
91447636 | 72 | #include <mach/thread_status.h> |
1c79356b | 73 | |
fe8ab488 | 74 | #include <kern/simple_lock.h> |
1c79356b A |
75 | |
76 | #include <i386/iopb.h> | |
77 | #include <i386/seg.h> | |
78 | #include <i386/tss.h> | |
79 | #include <i386/eflags.h> | |
91447636 | 80 | |
b0d623f7 A |
81 | #include <i386/cpu_data.h> |
82 | ||
6d2010ae | 83 | #include <machine/pal_routines.h> |
8f6c56a5 A |
84 | |
85 | /* | |
b0d623f7 | 86 | * x86_kernel_state: |
91447636 A |
87 | * |
88 | * This structure corresponds to the state of kernel registers | |
89 | * as saved in a context-switch. It lives at the base of the stack. | |
90 | */ | |
91 | ||
b0d623f7 | 92 | struct x86_kernel_state { |
6d2010ae A |
93 | uint64_t k_rbx; /* kernel context */ |
94 | uint64_t k_rsp; | |
95 | uint64_t k_rbp; | |
96 | uint64_t k_r12; | |
97 | uint64_t k_r13; | |
98 | uint64_t k_r14; | |
99 | uint64_t k_r15; | |
100 | uint64_t k_rip; | |
b0d623f7 | 101 | }; |
91447636 | 102 | |
91447636 A |
103 | /* |
104 | * Maps state flavor to number of words in the state: | |
105 | */ | |
39236c6e | 106 | extern unsigned int _MachineStateCount[]; |
91447636 | 107 | |
6d2010ae A |
108 | /* |
109 | * The machine-dependent thread state - registers and all platform-dependent | |
110 | * state - is saved in the machine thread structure which is embedded in | |
111 | * the thread data structure. For historical reasons this is also referred to | |
112 | * as the PCB. | |
113 | */ | |
91447636 | 114 | struct machine_thread { |
6d2010ae A |
115 | x86_saved_state_t *iss; |
116 | void *ifps; | |
117 | void *ids; | |
118 | decl_simple_lock_data(,lock); /* protects ifps and ids */ | |
119 | uint64_t iss_pte0; | |
120 | uint64_t iss_pte1; | |
39236c6e | 121 | |
6d2010ae A |
122 | #ifdef MACH_BSD |
123 | uint64_t cthread_self; /* for use of cthread package */ | |
124 | struct real_descriptor cthread_desc; | |
125 | unsigned long uldt_selector; /* user ldt selector to set */ | |
126 | struct real_descriptor uldt_desc; /* actual user setable ldt */ | |
127 | #endif | |
91447636 | 128 | |
6d2010ae | 129 | struct pal_pcb pal_pcb; |
6d2010ae | 130 | uint32_t specFlags; |
b0d623f7 A |
131 | #define OnProc 0x1 |
132 | #define CopyIOActive 0x2 /* Checked to ensure DTrace actions do not re-enter copyio(). */ | |
fe8ab488 | 133 | uint64_t thread_gpu_ns; |
b0d623f7 | 134 | #if NCOPY_WINDOWS > 0 |
0c530ab8 A |
135 | struct { |
136 | user_addr_t user_base; | |
137 | } copy_window[NCOPY_WINDOWS]; | |
6d2010ae A |
138 | int nxt_window; |
139 | int copyio_state; | |
0c530ab8 A |
140 | #define WINDOWS_DIRTY 0 |
141 | #define WINDOWS_CLEAN 1 | |
142 | #define WINDOWS_CLOSED 2 | |
143 | #define WINDOWS_OPENED 3 | |
6d2010ae A |
144 | uint64_t physwindow_pte; |
145 | int physwindow_busy; | |
b0d623f7 | 146 | #endif |
91447636 | 147 | }; |
6d2010ae | 148 | typedef struct machine_thread *pcb_t; |
91447636 | 149 | |
6d2010ae A |
150 | #define THREAD_TO_PCB(Thr) (&(Thr)->machine) |
151 | ||
152 | #define USER_STATE(Thr) ((Thr)->machine.iss) | |
153 | #define USER_REGS32(Thr) (saved_state32(USER_STATE(Thr))) | |
154 | #define USER_REGS64(Thr) (saved_state64(USER_STATE(Thr))) | |
155 | ||
156 | #define user_pc(Thr) (is_saved_state32(USER_STATE(Thr)) ? \ | |
157 | USER_REGS32(Thr)->eip : \ | |
158 | USER_REGS64(Thr)->isf.rip ) | |
0c530ab8 A |
159 | |
160 | extern void *get_user_regs(thread_t); | |
91447636 A |
161 | |
162 | extern void *act_thread_csave(void); | |
163 | extern void act_thread_catt(void *ctx); | |
164 | extern void act_thread_cfree(void *ctx); | |
1c79356b | 165 | |
3e170ce0 | 166 | #define FIND_PERFCONTROL_STATE(th) (PERFCONTROL_STATE_NULL) |
1c79356b A |
167 | |
168 | /* | |
169 | * On the kernel stack is: | |
170 | * stack: ... | |
b0d623f7 A |
171 | * struct x86_kernel_state |
172 | * stack+kernel_stack_size | |
1c79356b A |
173 | */ |
174 | ||
175 | #define STACK_IKS(stack) \ | |
b0d623f7 | 176 | ((struct x86_kernel_state *)((stack) + kernel_stack_size) - 1) |
1c79356b | 177 | |
b0d623f7 | 178 | /* |
6d2010ae | 179 | * Return the current stack depth including x86_kernel_state |
b0d623f7 A |
180 | */ |
181 | static inline vm_offset_t | |
182 | current_stack_depth(void) | |
183 | { | |
184 | vm_offset_t stack_ptr; | |
185 | ||
186 | assert(get_preemption_level() > 0 || !ml_get_interrupts_enabled()); | |
187 | ||
188 | #if defined(__x86_64__) | |
189 | __asm__ volatile("mov %%rsp, %0" : "=m" (stack_ptr)); | |
190 | #else | |
191 | __asm__ volatile("mov %%esp, %0" : "=m" (stack_ptr)); | |
192 | #endif | |
193 | return (current_cpu_datap()->cpu_kernel_stack | |
194 | + sizeof(struct x86_kernel_state) | |
b0d623f7 A |
195 | - stack_ptr); |
196 | } | |
197 | ||
1c79356b A |
198 | /* |
199 | * Return address of the function that called current function, given | |
200 | * address of the first parameter of current function. | |
201 | */ | |
b0d623f7 | 202 | #define GET_RETURN_PC(addr) (__builtin_return_address(0)) |
1c79356b | 203 | |
1c79356b | 204 | #endif /* _I386_THREAD_H_ */ |