2 * Copyright (c) 2007 Apple Inc. All rights reserved.
4 * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
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.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
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.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
32 * Mach Operating System
33 * Copyright (c) 1991,1990,1989 Carnegie Mellon University
34 * All Rights Reserved.
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.
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.
46 * Carnegie Mellon requests users of this software to return to
48 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
49 * School of Computer Science
50 * Carnegie Mellon University
51 * Pittsburgh PA 15213-3890
53 * any improvements or extensions that they make and grant Carnegie Mellon
54 * the rights to redistribute these changes.
59 #ifndef _ARM_THREAD_H_
60 #define _ARM_THREAD_H_
62 #include <mach/mach_types.h>
63 #include <mach/boolean.h>
64 #include <mach/arm/vm_types.h>
65 #include <mach/thread_status.h>
67 #ifdef MACH_KERNEL_PRIVATE
68 #include <arm/cpu_data.h>
69 #include <arm/proc_reg.h>
72 struct perfcontrol_state
{
73 uint64_t opaque
[8] __attribute__((aligned(8)));
77 * Maps state flavor to number of words in the state:
79 extern unsigned int _MachineStateCount
[];
81 #ifdef MACH_KERNEL_PRIVATE
83 typedef arm_context_t machine_thread_kernel_state
;
85 typedef struct arm_saved_state machine_thread_kernel_state
;
87 #include <kern/thread_kernel_state.h>
89 struct machine_thread
{
90 #if __ARM_USER_PROTECT__
91 unsigned int uptw_ttc
;
92 unsigned int uptw_ttb
;
93 unsigned int kptw_ttb
;
98 arm_context_t
* contextData
; /* allocated user context */
99 arm_saved_state_t
* upcb
; /* pointer to user GPR state */
100 arm_neon_saved_state_t
* uNeon
; /* pointer to user VFP state */
102 struct arm_saved_state PcbData
;
107 #if defined(__arm__) && defined(__ARM_VFP__)
108 // for packing reasons chtread_self and DebugData
109 // are inside the the PcbData when __ARM_VFP__ is set
110 #define DebugData PcbData.VFPpadding_DebugData
111 #define cthread_self PcbData.VFPpadding_cthread_self
113 arm_debug_state_t
*DebugData
;
114 vm_address_t cthread_self
; /* for use of cthread package */
117 vm_offset_t kstackptr
; /* top of kernel stack */
118 #if defined(HAS_APPLE_PAC)
120 boolean_t disable_user_jop
;
122 struct cpu_data
* CpuDatap
; /* current per cpu data */
123 unsigned int preemption_count
; /* preemption count */
126 #define MACHINE_THREAD_FLAGS_ON_CPU (0x1)
128 uint8_t machine_thread_flags
;
129 #endif /* __ARM_SMP__ */
131 struct perfcontrol_state perfctrl_state
;
133 uint64_t energy_estimate_nj
;
136 #if INTERRUPT_MASKED_DEBUG
137 uint64_t intmask_timestamp
; /* timestamp of when interrupts were masked */
142 extern struct arm_saved_state
* get_user_regs(thread_t
);
143 extern struct arm_saved_state
* find_user_regs(thread_t
);
144 extern struct arm_saved_state
* find_kern_regs(thread_t
);
145 extern struct arm_vfpsaved_state
* find_user_vfp(thread_t
);
147 extern arm_debug_state_t
* find_debug_state(thread_t
);
148 #elif defined(__arm64__)
149 extern arm_debug_state32_t
* find_debug_state32(thread_t
);
150 extern arm_debug_state64_t
* find_debug_state64(thread_t
);
151 extern arm_neon_saved_state_t
* get_user_neon_regs(thread_t
);
156 #define FIND_PERFCONTROL_STATE(th) (&th->machine.perfctrl_state)
158 #ifdef MACH_KERNEL_PRIVATE
160 extern void vfp_state_initialize(struct arm_vfpsaved_state
*vfp_state
);
161 extern void vfp_save(struct arm_vfpsaved_state
*vfp_ss
);
162 extern void vfp_load(struct arm_vfpsaved_state
*vfp_ss
);
163 #endif /* __ARM_VFP__ */
164 extern void arm_debug_set(arm_debug_state_t
*debug_state
);
165 #if defined(__arm64__)
166 extern void arm_debug_set32(arm_debug_state_t
*debug_state
);
167 extern void arm_debug_set64(arm_debug_state_t
*debug_state
);
169 #endif /* MACH_KERNEL_PRIVATE */
171 extern void *act_thread_csave(void);
172 extern void act_thread_catt(void *ctx
);
173 extern void act_thread_cfree(void *ctx
);
177 * Return address of the function that called current function, given
178 * address of the first parameter of current function.
180 #define GET_RETURN_PC(addr) (__builtin_return_address(0))
182 #endif /* _ARM_THREAD_H_ */