]>
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 * 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.
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
20 * @APPLE_LICENSE_HEADER_END@
31 #include <mach_assert.h>
35 #include <kern/assert.h>
36 #include <kern/kern_types.h>
37 #include <pexpert/pexpert.h>
41 thread_act_t
*active_thread
;
43 int simple_lock_count
;
45 int cpu_number
; /* Logical CPU number */
46 int cpu_phys_number
; /* Physical CPU Number */
47 cpu_id_t cpu_id
; /* Platform Expert handle */
48 int cpu_status
; /* Boot Status */
49 int cpu_signals
; /* IPI events */
50 int mcount_off
; /* mcount recursion flag */
53 extern cpu_data_t cpu_data
[NCPUS
];
55 /* Macro to generate inline bodies to retrieve per-cpu data fields. */
56 #define offsetof(TYPE,MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
57 #define CPU_DATA_GET(field,type) \
59 __asm__ volatile ("movl %%gs:%P1,%0" \
61 : "i" (offsetof(cpu_data_t,field))); \
65 * Everyone within the osfmk part of the kernel can use the fast
66 * inline versions of these routines. Everyone outside, must call
69 extern thread_act_t __inline__
get_active_thread(void)
71 CPU_DATA_GET(active_thread
,thread_act_t
)
73 #define current_act_fast() get_active_thread()
74 #define current_act() current_act_fast()
75 #define current_thread() current_act_fast()->thread
77 extern int __inline__
get_preemption_level(void)
79 CPU_DATA_GET(preemption_level
,int)
81 extern int __inline__
get_simple_lock_count(void)
83 CPU_DATA_GET(simple_lock_count
,int)
85 extern int __inline__
get_interrupt_level(void)
87 CPU_DATA_GET(interrupt_level
,int)
89 extern int __inline__
get_cpu_number(void)
91 CPU_DATA_GET(cpu_number
,int)
93 extern int __inline__
get_cpu_phys_number(void)
95 CPU_DATA_GET(cpu_phys_number
,int)
98 extern void __inline__
disable_preemption(void)
100 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
102 __asm__
volatile (" incl %%gs:(%0)" : : "r" (idx
));
105 extern void __inline__
enable_preemption(void)
107 extern void kernel_preempt_check (void);
108 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
109 register void (*kpc
)(void)= kernel_preempt_check
;
111 assert(get_preemption_level() > 0);
113 __asm__
volatile ("decl %%gs:(%0); jne 1f; \
116 : "r" (idx
), "r" (kpc
)
117 : "%eax", "%ecx", "%edx", "cc", "memory");
120 extern void __inline__
enable_preemption_no_check(void)
122 register int idx
= (int)&((cpu_data_t
*)0)->preemption_level
;
124 assert(get_preemption_level() > 0);
126 __asm__
volatile ("decl %%gs:(%0)"
132 extern void __inline__
mp_disable_preemption(void)
135 disable_preemption();
136 #endif /* NCPUS > 1 */
139 extern void __inline__
mp_enable_preemption(void)
143 #endif /* NCPUS > 1 */
146 extern void __inline__
mp_enable_preemption_no_check(void)
149 enable_preemption_no_check();
150 #endif /* NCPUS > 1 */
159 #else /* !defined(__GNUC__) */
161 #endif /* defined(__GNUC__) */
163 #endif /* I386_CPU_DATA */