]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/i386/cpu_data.h
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
34 #include <mach_assert.h>
38 #include <kern/assert.h>
39 #include <kern/kern_types.h>
40 #include <pexpert/pexpert.h>
44 thread_act_t
*active_thread
;
46 int simple_lock_count
;
48 int cpu_number
; /* Logical CPU number */
49 int cpu_phys_number
; /* Physical CPU Number */
50 cpu_id_t cpu_id
; /* Platform Expert handle */
51 int cpu_status
; /* Boot Status */
52 int cpu_signals
; /* IPI events */
53 int mcount_off
; /* mcount recursion flag */
56 extern cpu_data_t cpu_data
[NCPUS
];
58 /* Macro to generate inline bodies to retrieve per-cpu data fields. */
59 #define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
60 #define CPU_DATA_GET(field,type) \
62 __asm__ volatile ("movl %%gs:%P1,%0" \
64 : "i" (offsetof(cpu_data_t,field))); \
68 * Everyone within the osfmk part of the kernel can use the fast
69 * inline versions of these routines. Everyone outside, must call
72 extern thread_act_t __inline__
get_active_thread(void)
74 CPU_DATA_GET(active_thread
,thread_act_t
)
76 #define current_act_fast() get_active_thread()
77 #define current_act() current_act_fast()
78 #define current_thread() current_act_fast()->thread
80 extern int __inline__
get_preemption_level(void)
82 CPU_DATA_GET(preemption_level
,int)
84 extern int __inline__
get_simple_lock_count(void)
86 CPU_DATA_GET(simple_lock_count
,int)
88 extern int __inline__
get_interrupt_level(void)
90 CPU_DATA_GET(interrupt_level
,int)
92 extern int __inline__
get_cpu_number(void)
94 CPU_DATA_GET(cpu_number
,int)
96 extern int __inline__
get_cpu_phys_number(void)
98 CPU_DATA_GET(cpu_phys_number
,int)
101 extern void __inline__
disable_preemption(void)
103 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
105 __asm__
volatile (" incl %%gs:(%0)" : : "r" (idx
));
108 extern void __inline__
enable_preemption(void)
110 extern void kernel_preempt_check (void);
111 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
112 register void (*kpc
)(void)= kernel_preempt_check
;
114 assert(get_preemption_level() > 0);
116 __asm__
volatile ("decl %%gs:(%0); jne 1f; \
119 : "r" (idx
), "r" (kpc
)
120 : "%eax", "%ecx", "%edx", "cc", "memory");
123 extern void __inline__
enable_preemption_no_check(void)
125 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
127 assert(get_preemption_level() > 0);
129 __asm__
volatile ("decl %%gs:(%0)"
135 extern void __inline__
mp_disable_preemption(void)
138 disable_preemption();
139 #endif /* NCPUS > 1 */
142 extern void __inline__
mp_enable_preemption(void)
146 #endif /* NCPUS > 1 */
149 extern void __inline__
mp_enable_preemption_no_check(void)
152 enable_preemption_no_check();
153 #endif /* NCPUS > 1 */
162 #else /* !defined(__GNUC__) */
164 #endif /* defined(__GNUC__) */
166 #endif /* I386_CPU_DATA */