1/* 2 * Copyright (c) 2000-2010 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/* 30 * @OSF_COPYRIGHT@ 31 */ 32 33/* 34 * Mach Operating System 35 * Copyright (c) 1991,1990 Carnegie Mellon University 36 * All Rights Reserved. 37 * 38 * Permission to use, copy, modify and distribute this software and its 39 * documentation is hereby granted, provided that both the copyright 40 * notice and this permission notice appear in all copies of the 41 * software, derivative works or modified versions, and any portions 42 * thereof, and that both notices appear in supporting documentation. 43 * 44 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS" 45 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR 46 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. 47 * 48 * Carnegie Mellon requests users of this software to return to 49 * 50 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU 51 * School of Computer Science 52 * Carnegie Mellon University 53 * Pittsburgh PA 15213-3890 54 * 55 * any improvements or extensions that they make and grant Carnegie Mellon 56 * the rights to redistribute these changes. 57 */ 58 59#include <platforms.h> 60#include <mach_ldebug.h> 61 62/* 63 * Pass field offsets to assembly code. 64 */ 65#include <kern/ast.h> 66#include <kern/thread.h> 67#include <kern/task.h> 68#include <kern/lock.h> 69#include <kern/locks.h> 70#include <kern/host.h> 71#include <kern/misc_protos.h> 72#include <ipc/ipc_space.h> 73#include <ipc/ipc_port.h> 74#include <ipc/ipc_pset.h> 75#include <vm/vm_map.h> 76#include <arm/pmap.h> 77#include <arm/mp.h> 78#include <arm/thread.h> 79#include <arm/cpu_data.h> 80#include <arm/cpu_capabilities.h> 81#include <mach/arm/vm_param.h> 82#include <mach/arm/thread_status.h> 83#include <machine/commpage.h> 84#include <pexpert/arm/boot.h> 85 86#if CONFIG_DTRACE 87#define NEED_DTRACE_DEFS 88#include <../bsd/sys/lockstat.h> 89#endif 90 91/* 92 * genassym.c is used to produce an 93 * assembly file which, intermingled with unuseful assembly code, 94 * has all the necessary definitions emitted. This assembly file is 95 * then postprocessed with sed to extract only these definitions 96 * and thus the final assyms.s is created. 97 * 98 * This convoluted means is necessary since the structure alignment 99 * and packing may be different between the host machine and the 100 * target so we are forced into using the cross compiler to generate 101 * the values, but we cannot run anything on the target machine. 102 */ 103 104#undef offsetof 105#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER) 106 107#if 0 108#define DECLARE(SYM,VAL) \ 109 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL))) 110#else 111#define DECLARE(SYM,VAL) \ 112 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL))) 113#endif 114 115int main(int argc, char **argv); 116 117int main(int argc, char **argv) 118{ 119 120 DECLARE("AST_URGENT", AST_URGENT); 121 DECLARE("AST_BSD", AST_BSD); 122 123 DECLARE("MAX_CPUS", MAX_CPUS); 124 125 /* 126 * Mutex structure 127 */ 128 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr)); 129 DECLARE("MUTEX_STATE", offsetof(lck_mtx_t *, lck_mtx_state)); 130 131 DECLARE("MUTEX_IND", LCK_MTX_TAG_INDIRECT); 132 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr)); 133 DECLARE("MUTEX_ASSERT_OWNED", LCK_MTX_ASSERT_OWNED); 134 DECLARE("MUTEX_ASSERT_NOTOWNED", LCK_MTX_ASSERT_NOTOWNED); 135 DECLARE("GRP_MTX_STAT_UTIL", 136 offsetof(lck_grp_t *, 137 lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt)); 138 DECLARE("GRP_MTX_STAT_MISS", 139 offsetof(lck_grp_t *, 140 lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt)); 141 DECLARE("GRP_MTX_STAT_WAIT", 142 offsetof(lck_grp_t *, 143 lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt)); 144 145 /* 146 * Per-mutex statistic element 147 */ 148 DECLARE("MTX_ACQ_TSC", offsetof(lck_mtx_ext_t *, lck_mtx_stat)); 149 150 /* 151 * Mutex group statistics elements 152 */ 153 DECLARE("MUTEX_GRP", offsetof(lck_mtx_ext_t *, lck_mtx_grp)); 154 155 /* 156 * Boot-args 157 */ 158 DECLARE("BOOT_ARGS_VERSION", offsetof(boot_args *, Version)); 159 DECLARE("BOOT_ARGS_VIRTBASE", offsetof(boot_args *, virtBase)); 160 DECLARE("BOOT_ARGS_PHYSBASE", offsetof(boot_args *, physBase)); 161 DECLARE("BOOT_ARGS_MEMSIZE", offsetof(boot_args *, memSize)); 162 DECLARE("BOOT_ARGS_TOP_OF_KERNEL", offsetof(boot_args *, topOfKernelData)); 163 DECLARE("BOOT_ARGS_DEVICETREEP", offsetof(boot_args *, deviceTreeP)); 164 165 /* 166 * The use of this field is somewhat at variance with the alias. 167 */ 168 DECLARE("GRP_MTX_STAT_DIRECT_WAIT", 169 offsetof(lck_grp_t *, 170 lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_held_cnt)); 171 172 DECLARE("GRP_MTX_STAT_HELD_MAX", 173 offsetof(lck_grp_t *, 174 lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_held_max)); 175 /* 176 * Reader writer lock types 177 */ 178 DECLARE("RW_SHARED", LCK_RW_TYPE_SHARED); 179 DECLARE("RW_EXCL", LCK_RW_TYPE_EXCLUSIVE); 180 181 DECLARE("TH_RECOVER", offsetof(thread_t, recover)); 182 DECLARE("TH_CONTINUATION", offsetof(thread_t, continuation)); 183 DECLARE("TH_KERNEL_STACK", offsetof(thread_t, kernel_stack)); 184 DECLARE("TH_MUTEX_COUNT", offsetof(thread_t, mutex_count)); 185 DECLARE("TH_WAS_PROMOTED_ON_WAKEUP", 186 offsetof(thread_t, was_promoted_on_wakeup)); 187 188 DECLARE("TH_SYSCALLS_MACH", offsetof(thread_t, syscalls_mach)); 189 DECLARE("TH_SYSCALLS_UNIX", offsetof(thread_t, syscalls_unix)); 190 191 DECLARE("TASK_VTIMERS", offsetof(struct task *, vtimers)); 192 193 /* 194 * These fields are being added on demand 195 */ 196 DECLARE("MACHINE_THREAD", offsetof(thread_t, machine)); 197 DECLARE("MACHINE_THREAD_PREEMPT_COUNT", 198 offsetof(thread_t, machine.preempt_count)); 199 DECLARE("MACHINE_THREAD_CPU_DATA", offsetof(thread_t, machine.cpu_data)); 200 DECLARE("MACHINE_THREAD_CTHREAD_SELF", 201 offsetof(thread_t, machine.cthread_self)); 202 203 DECLARE("CPU_PENDING_AST", offsetof(cpu_data_t *, cpu_pending_ast)); 204 DECLARE("CPU_PREEMPT_COUNT", offsetof(cpu_data_t *, cpu_preemption_level)); 205 206 DECLARE("CPU_FLEH_RESET", offsetof(cpu_data_t *, fleh_reset)); 207 DECLARE("CPU_FLEH_UNDEF", offsetof(cpu_data_t *, fleh_undef)); 208 DECLARE("CPU_FLEH_SWI", offsetof(cpu_data_t *, fleh_swi)); 209 DECLARE("CPU_FLEH_PREFETCH", offsetof(cpu_data_t *, fleh_prefabt)); 210 DECLARE("CPU_FLEH_DATAABORT", offsetof(cpu_data_t *, fleh_dataabt)); 211 DECLARE("CPU_FLEH_DATAEXC", offsetof(cpu_data_t *, fleh_prefabt)); 212 DECLARE("CPU_FLEH_IRQ", offsetof(cpu_data_t *, fleh_irq)); 213 214 DECLARE("CPU_PMAP", offsetof(cpu_data_t *, user_pmap)); 215 216 DECLARE("TH_TASK", offsetof(thread_t, task)); 217 DECLARE("TH_AST", offsetof(thread_t, ast)); 218 DECLARE("TH_MAP", offsetof(thread_t, map)); 219 DECLARE("TH_PCB_ISS", offsetof(thread_t, machine.iss)); 220 DECLARE("TH_PCB_USS", offsetof(thread_t, machine.uss)); 221 222#if NCOPY_WINDOWS > 0 223 DECLARE("TH_COPYIO_STATE", offsetof(thread_t, machine.copyio_state)); 224 DECLARE("WINDOWS_CLEAN", WINDOWS_CLEAN); 225#endif 226 227 DECLARE("MAP_PMAP", offsetof(vm_map_t, pmap)); 228 229 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS); 230 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS); 231 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS); 232 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS); 233 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE); 234 235 DECLARE("ASM_COMM_PAGE32_BASE_ADDRESS", _COMM_PAGE32_BASE_ADDRESS); 236 DECLARE("ASM_COMM_PAGE32_START_ADDRESS", _COMM_PAGE32_START_ADDRESS); 237 238 DECLARE("CPU_THIS", offsetof(cpu_data_t *, cpu_this)); 239 DECLARE("CPU_ACTIVE_THREAD", offsetof(cpu_data_t *, cpu_active_thread)); 240 DECLARE("CPU_ACTIVE_STACK", offsetof(cpu_data_t *, cpu_active_stack)); 241 DECLARE("CPU_KERNEL_STACK", offsetof(cpu_data_t *, cpu_kernel_stack)); 242 DECLARE("CPU_INT_STACK_TOP", offsetof(cpu_data_t *, cpu_int_stack_top)); 243 244#if MACH_RT 245 DECLARE("CPU_PREEMPTION_LEVEL", 246 offsetof(cpu_data_t *, cpu_preemption_level)); 247#endif /* MACH_RT */ 248 DECLARE("CPU_PROCESSOR", offsetof(cpu_data_t *, cpu_processor)); 249 DECLARE("CPU_ONFAULT", offsetof(cpu_data_t *, cpu_onfault)); 250 251 DECLARE("CPU_INTERRUPT_LEVEL", 252 offsetof(cpu_data_t *, cpu_interrupt_level)); 253 254 /* 255 * usimple_lock fields 256 */ 257 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE); 258 259 /* 260 * values from kern/timer.h 261 */ 262 DECLARE("TIMER_TSTAMP", offsetof(struct timer *, tstamp)); 263 264#if CONFIG_DTRACE 265 DECLARE("LS_LCK_MTX_LOCK_ACQUIRE", LS_LCK_MTX_LOCK_ACQUIRE); 266 DECLARE("LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE", 267 LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE); 268 DECLARE("LS_LCK_MTX_UNLOCK_RELEASE", LS_LCK_MTX_UNLOCK_RELEASE); 269 DECLARE("LS_LCK_MTX_TRY_LOCK_ACQUIRE", LS_LCK_MTX_TRY_LOCK_ACQUIRE); 270 DECLARE("LS_LCK_RW_LOCK_SHARED_ACQUIRE", LS_LCK_RW_LOCK_SHARED_ACQUIRE); 271 DECLARE("LS_LCK_RW_DONE_RELEASE", LS_LCK_RW_DONE_RELEASE); 272 DECLARE("LS_LCK_MTX_EXT_LOCK_ACQUIRE", LS_LCK_MTX_EXT_LOCK_ACQUIRE); 273 DECLARE("LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE", LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE); 274 DECLARE("LS_LCK_MTX_EXT_UNLOCK_RELEASE", LS_LCK_MTX_EXT_UNLOCK_RELEASE); 275 DECLARE("LS_LCK_RW_LOCK_EXCL_ACQUIRE", LS_LCK_RW_LOCK_EXCL_ACQUIRE); 276 DECLARE("LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE", 277 LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE); 278 DECLARE("LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE", LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE); 279 DECLARE("LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE", 280 LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE); 281 DECLARE("LS_LCK_MTX_LOCK_SPIN_ACQUIRE", LS_LCK_MTX_LOCK_SPIN_ACQUIRE); 282#endif 283 284 return (0); 285} 286