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 * @OSF_COPYRIGHT@ 30 */ 31/* 32 * Mach Operating System 33 * Copyright (c) 1991,1990 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#include <platforms.h> 58#include <mach_ldebug.h> 59 60/* 61 * Pass field offsets to assembly code. 62 */ 63#include <kern/ast.h> 64#include <kern/thread.h> 65#include <kern/task.h> 66#include <kern/lock.h> 67#include <kern/locks.h> 68#include <kern/host.h> 69#include <kern/misc_protos.h> 70#include <ipc/ipc_space.h> 71#include <ipc/ipc_port.h> 72#include <ipc/ipc_pset.h> 73#include <vm/vm_map.h> 74#include <arm/pmap.h> 75#include <arm/mp.h> 76#include <arm/thread.h> 77#include <arm/cpu_data.h> 78#include <arm/cpu_capabilities.h> 79#include <mach/arm/vm_param.h> 80#include <mach/arm/thread_status.h> 81#include <machine/commpage.h> 82#include <pexpert/arm/boot.h> 83 84#if CONFIG_DTRACE 85#define NEED_DTRACE_DEFS 86#include <../bsd/sys/lockstat.h> 87#endif 88 89/* 90 * genassym.c is used to produce an 91 * assembly file which, intermingled with unuseful assembly code, 92 * has all the necessary definitions emitted. This assembly file is 93 * then postprocessed with sed to extract only these definitions 94 * and thus the final assyms.s is created. 95 * 96 * This convoluted means is necessary since the structure alignment 97 * and packing may be different between the host machine and the 98 * target so we are forced into using the cross compiler to generate 99 * the values, but we cannot run anything on the target machine. 100 */ 101 102#undef offsetof 103#define offsetof(TYPE, MEMBER) ((size_t) &((TYPE)0)->MEMBER) 104 105#if 0 106#define DECLARE(SYM,VAL) \ 107 __asm("#DEFINITION#\t.set\t" SYM ",\t%0" : : "n" ((u_int)(VAL))) 108#else 109#define DECLARE(SYM,VAL) \ 110 __asm("#DEFINITION##define " SYM "\t%0" : : "n" ((u_int)(VAL))) 111#endif 112 113int main( 114 int argc, 115 char ** argv); 116 117int 118main( 119 int argc, 120 char **argv) 121{ 122 123 DECLARE("AST_URGENT", AST_URGENT); 124 DECLARE("AST_BSD", AST_BSD); 125 126 DECLARE("MAX_CPUS", MAX_CPUS); 127 128 /* Mutex structure */ 129 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr)); 130 DECLARE("MUTEX_STATE", offsetof(lck_mtx_t *, lck_mtx_state)); 131 132 DECLARE("MUTEX_IND", LCK_MTX_TAG_INDIRECT); 133 DECLARE("MUTEX_PTR", offsetof(lck_mtx_t *, lck_mtx_ptr)); 134 DECLARE("MUTEX_ASSERT_OWNED", LCK_MTX_ASSERT_OWNED); 135 DECLARE("MUTEX_ASSERT_NOTOWNED",LCK_MTX_ASSERT_NOTOWNED); 136 DECLARE("GRP_MTX_STAT_UTIL", offsetof(lck_grp_t *, lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_util_cnt)); 137 DECLARE("GRP_MTX_STAT_MISS", offsetof(lck_grp_t *, lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_miss_cnt)); 138 DECLARE("GRP_MTX_STAT_WAIT", offsetof(lck_grp_t *, lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_wait_cnt)); 139 140 /* Per-mutex statistic element */ 141 DECLARE("MTX_ACQ_TSC", offsetof(lck_mtx_ext_t *, lck_mtx_stat)); 142 143 /* Mutex group statistics elements */ 144 DECLARE("MUTEX_GRP", offsetof(lck_mtx_ext_t *, lck_mtx_grp)); 145 146 /* Boot-args */ 147 DECLARE("BOOT_ARGS_VIRTBASE", offsetof(boot_args*, virtBase)); 148 DECLARE("BOOT_ARGS_PHYSBASE", offsetof(boot_args*, physBase)); 149 DECLARE("BOOT_ARGS_MEMSIZE", offsetof(boot_args*, memSize)); 150 DECLARE("BOOT_ARGS_TOP_OF_KERNEL", offsetof(boot_args*, topOfKernelData)); 151 DECLARE("BOOT_ARGS_DEVICETREEP", offsetof(boot_args*, deviceTreeP)); 152 153 /* 154 * The use of this field is somewhat at variance with the alias. 155 */ 156 DECLARE("GRP_MTX_STAT_DIRECT_WAIT", offsetof(lck_grp_t *, lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_held_cnt)); 157 158 DECLARE("GRP_MTX_STAT_HELD_MAX", offsetof(lck_grp_t *, lck_grp_stat.lck_grp_mtx_stat.lck_grp_mtx_held_max)); 159 /* Reader writer lock types */ 160 DECLARE("RW_SHARED", LCK_RW_TYPE_SHARED); 161 DECLARE("RW_EXCL", LCK_RW_TYPE_EXCLUSIVE); 162 163 DECLARE("TH_RECOVER", offsetof(thread_t, recover)); 164 DECLARE("TH_CONTINUATION", offsetof(thread_t, continuation)); 165 DECLARE("TH_KERNEL_STACK", offsetof(thread_t, kernel_stack)); 166 DECLARE("TH_MUTEX_COUNT", offsetof(thread_t, mutex_count)); 167 DECLARE("TH_WAS_PROMOTED_ON_WAKEUP", offsetof(thread_t, was_promoted_on_wakeup)); 168 169 DECLARE("TH_SYSCALLS_MACH", offsetof(thread_t, syscalls_mach)); 170 DECLARE("TH_SYSCALLS_UNIX", offsetof(thread_t, syscalls_unix)); 171 172 DECLARE("TASK_VTIMERS", offsetof(struct task *, vtimers)); 173 174 /* These fields are being added on demand */ 175 DECLARE("MACHINE_THREAD", offsetof(thread_t, machine)); 176 DECLARE("MACHINE_THREAD_PREEMPT_COUNT", offsetof(thread_t, machine.preempt_count)); 177 DECLARE("MACHINE_THREAD_CPU_DATA", offsetof(thread_t, machine.cpu_data)); 178 DECLARE("MACHINE_THREAD_CTHREAD_SELF", offsetof(thread_t, machine.cthread_self)); 179 180 DECLARE("CPU_PENDING_AST", offsetof(cpu_data_t*, cpu_pending_ast)); 181 DECLARE("CPU_PREEMPT_COUNT", offsetof(cpu_data_t*, cpu_preemption_level)); 182 183 DECLARE("CPU_PMAP", offsetof(cpu_data_t*, user_pmap)); 184 185 DECLARE("TH_TASK", offsetof(thread_t, task)); 186 DECLARE("TH_AST", offsetof(thread_t, ast)); 187 DECLARE("TH_MAP", offsetof(thread_t, map)); 188 DECLARE("TH_PCB_ISS", offsetof(thread_t, machine.iss)); 189 DECLARE("TH_PCB_USS", offsetof(thread_t, machine.uss)); 190 191 192#if NCOPY_WINDOWS > 0 193 DECLARE("TH_COPYIO_STATE", offsetof(thread_t, machine.copyio_state)); 194 DECLARE("WINDOWS_CLEAN", WINDOWS_CLEAN); 195#endif 196 197 DECLARE("MAP_PMAP", offsetof(vm_map_t, pmap)); 198 199 DECLARE("VM_MIN_ADDRESS", VM_MIN_ADDRESS); 200 DECLARE("VM_MAX_ADDRESS", VM_MAX_ADDRESS); 201 DECLARE("KERNELBASE", VM_MIN_KERNEL_ADDRESS); 202 DECLARE("LINEAR_KERNELBASE", LINEAR_KERNEL_ADDRESS); 203 DECLARE("KERNEL_STACK_SIZE", KERNEL_STACK_SIZE); 204 205 DECLARE("ASM_COMM_PAGE32_BASE_ADDRESS", _COMM_PAGE32_BASE_ADDRESS); 206 DECLARE("ASM_COMM_PAGE32_START_ADDRESS", _COMM_PAGE32_START_ADDRESS); 207 208 DECLARE("CPU_THIS", 209 offsetof(cpu_data_t *, cpu_this)); 210 DECLARE("CPU_ACTIVE_THREAD", 211 offsetof(cpu_data_t *, cpu_active_thread)); 212 DECLARE("CPU_ACTIVE_STACK", 213 offsetof(cpu_data_t *, cpu_active_stack)); 214 DECLARE("CPU_KERNEL_STACK", 215 offsetof(cpu_data_t *, cpu_kernel_stack)); 216 DECLARE("CPU_INT_STACK_TOP", 217 offsetof(cpu_data_t *, cpu_int_stack_top)); 218 219#if MACH_RT 220 DECLARE("CPU_PREEMPTION_LEVEL", 221 offsetof(cpu_data_t *, cpu_preemption_level)); 222#endif /* MACH_RT */ 223 DECLARE("CPU_PROCESSOR", 224 offsetof(cpu_data_t *,cpu_processor)); 225 DECLARE("CPU_ONFAULT", 226 offsetof(cpu_data_t *,cpu_onfault)); 227 228 /* 229 * usimple_lock fields 230 */ 231 DECLARE("INTSTACK_SIZE", INTSTACK_SIZE); 232 233 /* values from kern/timer.h */ 234 DECLARE("TIMER_TSTAMP", 235 offsetof(struct timer *, tstamp)); 236 237 238#if CONFIG_DTRACE 239 DECLARE("LS_LCK_MTX_LOCK_ACQUIRE", LS_LCK_MTX_LOCK_ACQUIRE); 240 DECLARE("LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE", LS_LCK_MTX_TRY_SPIN_LOCK_ACQUIRE); 241 DECLARE("LS_LCK_MTX_UNLOCK_RELEASE", LS_LCK_MTX_UNLOCK_RELEASE); 242 DECLARE("LS_LCK_MTX_TRY_LOCK_ACQUIRE", LS_LCK_MTX_TRY_LOCK_ACQUIRE); 243 DECLARE("LS_LCK_RW_LOCK_SHARED_ACQUIRE", LS_LCK_RW_LOCK_SHARED_ACQUIRE); 244 DECLARE("LS_LCK_RW_DONE_RELEASE", LS_LCK_RW_DONE_RELEASE); 245 DECLARE("LS_LCK_MTX_EXT_LOCK_ACQUIRE", LS_LCK_MTX_EXT_LOCK_ACQUIRE); 246 DECLARE("LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE", LS_LCK_MTX_TRY_EXT_LOCK_ACQUIRE); 247 DECLARE("LS_LCK_MTX_EXT_UNLOCK_RELEASE", LS_LCK_MTX_EXT_UNLOCK_RELEASE); 248 DECLARE("LS_LCK_RW_LOCK_EXCL_ACQUIRE", LS_LCK_RW_LOCK_EXCL_ACQUIRE); 249 DECLARE("LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE", LS_LCK_RW_LOCK_SHARED_TO_EXCL_UPGRADE); 250 DECLARE("LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE", LS_LCK_RW_TRY_LOCK_EXCL_ACQUIRE); 251 DECLARE("LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE", LS_LCK_RW_TRY_LOCK_SHARED_ACQUIRE); 252 DECLARE("LS_LCK_MTX_LOCK_SPIN_ACQUIRE", LS_LCK_MTX_LOCK_SPIN_ACQUIRE); 253#endif 254 255 return (0); 256} 257