]> git.saurik.com Git - apple/xnu.git/blob - osfmk/arm/thread.h
46a603dcce9d51837aea671f5b368f95a3369544
[apple/xnu.git] / osfmk / arm / thread.h
1 /*
2 * Copyright (c) 2007 Apple Inc. All rights reserved.
3 *
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
5 *
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.
14 *
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
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
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.
25 *
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
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 #ifndef _ARM_THREAD_H_
60 #define _ARM_THREAD_H_
61
62 #include <mach/mach_types.h>
63 #include <mach/boolean.h>
64 #include <mach/arm/vm_types.h>
65 #include <mach/thread_status.h>
66
67 #ifdef MACH_KERNEL_PRIVATE
68 #include <arm/cpu_data.h>
69 #include <arm/proc_reg.h>
70 #endif
71
72 #if __ARM_VFP__
73
74 #define VFPSAVE_ALIGN 16
75 #define VFPSAVE_ATTRIB __attribute__ ((aligned (VFPSAVE_ALIGN)))
76 #define THREAD_ALIGN VFPSAVE_ALIGN
77
78 /*
79 * vector floating point saved state
80 */
81 struct arm_vfpsaved_state {
82 uint32_t r[64];
83 uint32_t fpscr;
84 uint32_t fpexc;
85 };
86 #endif
87
88 struct perfcontrol_state {
89 uint64_t opaque[8] __attribute__((aligned(8)));
90 };
91
92 /*
93 * Maps state flavor to number of words in the state:
94 */
95 extern unsigned int _MachineStateCount[];
96
97 #ifdef MACH_KERNEL_PRIVATE
98 #if __arm64__
99 typedef arm_context_t machine_thread_kernel_state;
100 #else
101 typedef struct arm_saved_state machine_thread_kernel_state;
102 #endif
103 #include <kern/thread_kernel_state.h>
104
105 struct machine_thread {
106 #if __arm64__
107 arm_context_t *contextData; /* allocated user context */
108 arm_saved_state_t *upcb; /* pointer to user GPR state */
109 arm_neon_saved_state_t *uNeon; /* pointer to user VFP state */
110 #elif __arm__
111 struct arm_saved_state PcbData;
112 #if __ARM_VFP__
113 struct arm_vfpsaved_state uVFPdata VFPSAVE_ATTRIB;
114 struct arm_vfpsaved_state kVFPdata VFPSAVE_ATTRIB;
115 #endif /* __ARM_VFP__ */
116
117 #else
118 #error Unknown arch
119 #endif
120 #if __ARM_USER_PROTECT__
121 unsigned int uptw_ttc;
122 unsigned int uptw_ttb;
123 unsigned int kptw_ttb;
124 unsigned int asid;
125 #endif
126
127 vm_offset_t kstackptr; /* top of kernel stack */
128 struct cpu_data *CpuDatap; /* current per cpu data */
129 unsigned int preemption_count; /* preemption count */
130
131 #if __ARM_SMP__
132 #define MACHINE_THREAD_FLAGS_ON_CPU (0x1)
133
134 uint8_t machine_thread_flags;
135 #endif /* __ARM_SMP__ */
136
137 arm_debug_state_t *DebugData;
138 mach_vm_address_t cthread_self; /* for use of cthread package */
139 mach_vm_address_t cthread_data; /* for use of cthread package */
140
141 struct perfcontrol_state perfctrl_state;
142 #if __arm64__
143 uint64_t energy_estimate_nj;
144 #endif
145
146 #if INTERRUPT_MASKED_DEBUG
147 uint64_t intmask_timestamp; /* timestamp of when interrupts were masked */
148 #endif
149 };
150 #endif
151
152 extern struct arm_saved_state *get_user_regs(thread_t);
153 extern struct arm_saved_state *find_user_regs(thread_t);
154 extern struct arm_saved_state *find_kern_regs(thread_t);
155 extern struct arm_vfpsaved_state *find_user_vfp(thread_t);
156 #if defined(__arm__)
157 extern arm_debug_state_t *find_debug_state(thread_t);
158 #elif defined(__arm64__)
159 extern arm_debug_state32_t *find_debug_state32(thread_t);
160 extern arm_debug_state64_t *find_debug_state64(thread_t);
161 extern arm_neon_saved_state_t *get_user_neon_regs(thread_t);
162 #else
163 #error unknown arch
164 #endif
165
166 #define FIND_PERFCONTROL_STATE(th) (&th->machine.perfctrl_state)
167
168 #ifdef MACH_KERNEL_PRIVATE
169 #if __ARM_VFP__
170 extern void vfp_state_initialize(struct arm_vfpsaved_state *vfp_state);
171 extern void vfp_save(struct arm_vfpsaved_state *vfp_ss);
172 extern void vfp_load(struct arm_vfpsaved_state *vfp_ss);
173 extern void toss_live_vfp(void *vfp_fc);
174 #endif /* __ARM_VFP__ */
175 extern void arm_debug_set(arm_debug_state_t *debug_state);
176 #if defined(__arm64__)
177 extern void arm_debug_set32(arm_debug_state_t *debug_state);
178 extern void arm_debug_set64(arm_debug_state_t *debug_state);
179
180 kern_return_t handle_get_arm_thread_state(
181 thread_state_t tstate,
182 mach_msg_type_number_t * count,
183 const arm_saved_state_t *saved_state);
184 kern_return_t handle_get_arm32_thread_state(
185 thread_state_t tstate,
186 mach_msg_type_number_t * count,
187 const arm_saved_state_t *saved_state);
188 kern_return_t handle_get_arm64_thread_state(
189 thread_state_t tstate,
190 mach_msg_type_number_t * count,
191 const arm_saved_state_t *saved_state);
192
193 kern_return_t handle_set_arm_thread_state(
194 const thread_state_t tstate,
195 mach_msg_type_number_t count,
196 arm_saved_state_t *saved_state);
197 kern_return_t handle_set_arm32_thread_state(
198 const thread_state_t tstate,
199 mach_msg_type_number_t count,
200 arm_saved_state_t *saved_state);
201 kern_return_t handle_set_arm64_thread_state(
202 const thread_state_t tstate,
203 mach_msg_type_number_t count,
204 arm_saved_state_t *saved_state);
205 #endif
206 #endif /* MACH_KERNEL_PRIVATE */
207
208 extern void *act_thread_csave(void);
209 extern void act_thread_catt(void *ctx);
210 extern void act_thread_cfree(void *ctx);
211
212 /*
213 * Return address of the function that called current function, given
214 * address of the first parameter of current function.
215 */
216 #define GET_RETURN_PC(addr) (((vm_offset_t *)0))
217
218 /*
219 * Defining this indicates that MD code will supply an exception()
220 * routine, conformant with kern/exception.c (dependency alert!)
221 * but which does wonderfully fast, machine-dependent magic.
222 */
223 #define MACHINE_FAST_EXCEPTION 1
224
225 #endif /* _ARM_THREAD_H_ */