1*0Sstevel@tonic-gate /* 2*0Sstevel@tonic-gate * CDDL HEADER START 3*0Sstevel@tonic-gate * 4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the 5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 7*0Sstevel@tonic-gate * with the License. 8*0Sstevel@tonic-gate * 9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 11*0Sstevel@tonic-gate * See the License for the specific language governing permissions 12*0Sstevel@tonic-gate * and limitations under the License. 13*0Sstevel@tonic-gate * 14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 19*0Sstevel@tonic-gate * 20*0Sstevel@tonic-gate * CDDL HEADER END 21*0Sstevel@tonic-gate */ 22*0Sstevel@tonic-gate /* 23*0Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 24*0Sstevel@tonic-gate * Use is subject to license terms. 25*0Sstevel@tonic-gate */ 26*0Sstevel@tonic-gate 27*0Sstevel@tonic-gate #ifndef _SYS_MODEL_H 28*0Sstevel@tonic-gate #define _SYS_MODEL_H 29*0Sstevel@tonic-gate 30*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI" 31*0Sstevel@tonic-gate 32*0Sstevel@tonic-gate #ifdef __cplusplus 33*0Sstevel@tonic-gate extern "C" { 34*0Sstevel@tonic-gate #endif 35*0Sstevel@tonic-gate 36*0Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM) 37*0Sstevel@tonic-gate #include <sys/debug.h> 38*0Sstevel@tonic-gate #endif /* _KERNEL && !_ASM */ 39*0Sstevel@tonic-gate 40*0Sstevel@tonic-gate #include <sys/isa_defs.h> 41*0Sstevel@tonic-gate 42*0Sstevel@tonic-gate #if defined(_KERNEL) || defined(_KMEMUSER) 43*0Sstevel@tonic-gate 44*0Sstevel@tonic-gate /* 45*0Sstevel@tonic-gate * These bits are used in various places to specify the data model 46*0Sstevel@tonic-gate * of the originator (and/or consumer) of data items. See <sys/conf.h> 47*0Sstevel@tonic-gate * <sys/file.h>, <sys/stream.h> and <sys/sunddi.h>. 48*0Sstevel@tonic-gate * 49*0Sstevel@tonic-gate * This state should only be known to the kernel implementation. 50*0Sstevel@tonic-gate */ 51*0Sstevel@tonic-gate #define DATAMODEL_MASK 0x0FF00000 52*0Sstevel@tonic-gate 53*0Sstevel@tonic-gate #define DATAMODEL_ILP32 0x00100000 54*0Sstevel@tonic-gate #define DATAMODEL_LP64 0x00200000 55*0Sstevel@tonic-gate 56*0Sstevel@tonic-gate #define DATAMODEL_NONE 0 57*0Sstevel@tonic-gate 58*0Sstevel@tonic-gate #if defined(_LP64) 59*0Sstevel@tonic-gate #define DATAMODEL_NATIVE DATAMODEL_LP64 60*0Sstevel@tonic-gate #elif defined(_ILP32) 61*0Sstevel@tonic-gate #define DATAMODEL_NATIVE DATAMODEL_ILP32 62*0Sstevel@tonic-gate #else 63*0Sstevel@tonic-gate #error "No DATAMODEL_NATIVE specified" 64*0Sstevel@tonic-gate #endif /* _LP64 || _ILP32 */ 65*0Sstevel@tonic-gate 66*0Sstevel@tonic-gate #endif /* _KERNEL || _KMEMUSER */ 67*0Sstevel@tonic-gate 68*0Sstevel@tonic-gate #ifndef _ASM 69*0Sstevel@tonic-gate /* 70*0Sstevel@tonic-gate * XXX Ick. This type needs to be visible outside the above guard because 71*0Sstevel@tonic-gate * the proc structure is visible outside the _KERNEL | _KMEMUSER guard. 72*0Sstevel@tonic-gate * If we can make proc internals less visible, (which we obviously should) 73*0Sstevel@tonic-gate * then this can be invisible too. 74*0Sstevel@tonic-gate */ 75*0Sstevel@tonic-gate typedef unsigned int model_t; 76*0Sstevel@tonic-gate 77*0Sstevel@tonic-gate #endif /* _ASM */ 78*0Sstevel@tonic-gate 79*0Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM) 80*0Sstevel@tonic-gate /* 81*0Sstevel@tonic-gate * These macros allow two views of the same piece of memory depending 82*0Sstevel@tonic-gate * on the originating user-mode program's data model. See the STRUCT_DECL(9F) 83*0Sstevel@tonic-gate * man page. 84*0Sstevel@tonic-gate */ 85*0Sstevel@tonic-gate #if defined(_LP64) 86*0Sstevel@tonic-gate 87*0Sstevel@tonic-gate #define STRUCT_HANDLE(struct_type, handle) \ 88*0Sstevel@tonic-gate struct { \ 89*0Sstevel@tonic-gate union { \ 90*0Sstevel@tonic-gate struct struct_type##32 *m32; \ 91*0Sstevel@tonic-gate struct struct_type *m64; \ 92*0Sstevel@tonic-gate } ptr; \ 93*0Sstevel@tonic-gate model_t model; \ 94*0Sstevel@tonic-gate } handle = { NULL, DATAMODEL_ILP32 } 95*0Sstevel@tonic-gate 96*0Sstevel@tonic-gate #define STRUCT_DECL(struct_type, handle) \ 97*0Sstevel@tonic-gate struct struct_type __##handle##_buf; \ 98*0Sstevel@tonic-gate STRUCT_HANDLE(struct_type, handle) 99*0Sstevel@tonic-gate 100*0Sstevel@tonic-gate #define STRUCT_SET_HANDLE(handle, umodel, addr) \ 101*0Sstevel@tonic-gate (handle).model = (model_t)(umodel) & DATAMODEL_MASK; \ 102*0Sstevel@tonic-gate ASSERT(((umodel) & DATAMODEL_MASK) != DATAMODEL_NONE); \ 103*0Sstevel@tonic-gate ((handle).ptr.m64) = (addr) 104*0Sstevel@tonic-gate 105*0Sstevel@tonic-gate #define STRUCT_INIT(handle, umodel) \ 106*0Sstevel@tonic-gate STRUCT_SET_HANDLE(handle, umodel, &__##handle##_buf) 107*0Sstevel@tonic-gate 108*0Sstevel@tonic-gate #define STRUCT_SIZE(handle) \ 109*0Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 110*0Sstevel@tonic-gate sizeof (*(handle).ptr.m32) : \ 111*0Sstevel@tonic-gate sizeof (*(handle).ptr.m64)) 112*0Sstevel@tonic-gate 113*0Sstevel@tonic-gate /* 114*0Sstevel@tonic-gate * In STRUCT_FADDR and STRUCT_FGETP a sleight of hand is employed to make 115*0Sstevel@tonic-gate * the compiler cope with having two different pointer types within ?:. 116*0Sstevel@tonic-gate * The (void *) case on the ILP32 case makes it a pointer which can be 117*0Sstevel@tonic-gate * converted to the pointer on the LP64 case, thus quieting the compiler. 118*0Sstevel@tonic-gate */ 119*0Sstevel@tonic-gate #define STRUCT_FADDR(handle, field) \ 120*0Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 121*0Sstevel@tonic-gate (void *)&(handle).ptr.m32->field : \ 122*0Sstevel@tonic-gate &(handle).ptr.m64->field) 123*0Sstevel@tonic-gate 124*0Sstevel@tonic-gate #define STRUCT_FGET(handle, field) \ 125*0Sstevel@tonic-gate (((handle).model == DATAMODEL_ILP32) ? \ 126*0Sstevel@tonic-gate (handle).ptr.m32->field : \ 127*0Sstevel@tonic-gate (handle).ptr.m64->field) 128*0Sstevel@tonic-gate 129*0Sstevel@tonic-gate #define STRUCT_FGETP(handle, field) \ 130*0Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 131*0Sstevel@tonic-gate (void *)(uintptr_t)(handle).ptr.m32->field : \ 132*0Sstevel@tonic-gate (handle).ptr.m64->field) 133*0Sstevel@tonic-gate 134*0Sstevel@tonic-gate #define STRUCT_FSET(handle, field, val) \ 135*0Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 136*0Sstevel@tonic-gate ((handle).ptr.m32->field = (val)) : \ 137*0Sstevel@tonic-gate ((handle).ptr.m64->field = (val))) 138*0Sstevel@tonic-gate 139*0Sstevel@tonic-gate #define STRUCT_FSETP(handle, field, val) \ 140*0Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 141*0Sstevel@tonic-gate (void) ((handle).ptr.m32->field = (caddr32_t)(uintptr_t)(val)) : \ 142*0Sstevel@tonic-gate (void) ((handle).ptr.m64->field = (val))) 143*0Sstevel@tonic-gate 144*0Sstevel@tonic-gate #define STRUCT_BUF(handle) ((handle).ptr.m64) 145*0Sstevel@tonic-gate 146*0Sstevel@tonic-gate #define SIZEOF_PTR(umodel) \ 147*0Sstevel@tonic-gate (((umodel) & DATAMODEL_MASK) == DATAMODEL_ILP32 ? \ 148*0Sstevel@tonic-gate sizeof (caddr32_t) : \ 149*0Sstevel@tonic-gate sizeof (caddr_t)) 150*0Sstevel@tonic-gate 151*0Sstevel@tonic-gate #define SIZEOF_STRUCT(struct_type, umodel) \ 152*0Sstevel@tonic-gate (((umodel) & DATAMODEL_MASK) == DATAMODEL_ILP32 ? \ 153*0Sstevel@tonic-gate sizeof (struct struct_type##32) : \ 154*0Sstevel@tonic-gate sizeof (struct struct_type)) 155*0Sstevel@tonic-gate 156*0Sstevel@tonic-gate #else /* _LP64 */ 157*0Sstevel@tonic-gate 158*0Sstevel@tonic-gate #define STRUCT_HANDLE(struct_type, handle) \ 159*0Sstevel@tonic-gate struct { \ 160*0Sstevel@tonic-gate struct struct_type *ptr; \ 161*0Sstevel@tonic-gate } handle = { NULL } 162*0Sstevel@tonic-gate 163*0Sstevel@tonic-gate #define STRUCT_DECL(struct_type, handle) \ 164*0Sstevel@tonic-gate struct struct_type __##handle##_buf; \ 165*0Sstevel@tonic-gate STRUCT_HANDLE(struct_type, handle) 166*0Sstevel@tonic-gate 167*0Sstevel@tonic-gate #ifdef __lint 168*0Sstevel@tonic-gate #define STRUCT_SET_HANDLE(handle, umodel, addr) \ 169*0Sstevel@tonic-gate (void) (umodel); \ 170*0Sstevel@tonic-gate (handle).ptr = (addr) 171*0Sstevel@tonic-gate #else 172*0Sstevel@tonic-gate #define STRUCT_SET_HANDLE(handle, umodel, addr) \ 173*0Sstevel@tonic-gate (handle).ptr = (addr) 174*0Sstevel@tonic-gate #endif /* __lint */ 175*0Sstevel@tonic-gate 176*0Sstevel@tonic-gate #define STRUCT_INIT(handle, umodel) \ 177*0Sstevel@tonic-gate STRUCT_SET_HANDLE(handle, umodel, &__##handle##_buf) 178*0Sstevel@tonic-gate 179*0Sstevel@tonic-gate #define STRUCT_SIZE(handle) (sizeof (*(handle).ptr)) 180*0Sstevel@tonic-gate 181*0Sstevel@tonic-gate #define STRUCT_FADDR(handle, field) (&(handle).ptr->field) 182*0Sstevel@tonic-gate 183*0Sstevel@tonic-gate #define STRUCT_FGET(handle, field) ((handle).ptr->field) 184*0Sstevel@tonic-gate 185*0Sstevel@tonic-gate #define STRUCT_FGETP STRUCT_FGET 186*0Sstevel@tonic-gate 187*0Sstevel@tonic-gate #define STRUCT_FSET(handle, field, val) ((handle).ptr->field = (val)) 188*0Sstevel@tonic-gate 189*0Sstevel@tonic-gate #define STRUCT_FSETP STRUCT_FSET 190*0Sstevel@tonic-gate 191*0Sstevel@tonic-gate #define STRUCT_BUF(handle) ((handle).ptr) 192*0Sstevel@tonic-gate 193*0Sstevel@tonic-gate #define SIZEOF_PTR(umodel) sizeof (caddr_t) 194*0Sstevel@tonic-gate 195*0Sstevel@tonic-gate #define SIZEOF_STRUCT(struct_type, umodel) sizeof (struct struct_type) 196*0Sstevel@tonic-gate 197*0Sstevel@tonic-gate #endif /* _LP64 */ 198*0Sstevel@tonic-gate 199*0Sstevel@tonic-gate #if defined(_LP64) || defined(__lint) 200*0Sstevel@tonic-gate 201*0Sstevel@tonic-gate struct _klwp; 202*0Sstevel@tonic-gate 203*0Sstevel@tonic-gate extern model_t lwp_getdatamodel(struct _klwp *); 204*0Sstevel@tonic-gate extern model_t get_udatamodel(void); 205*0Sstevel@tonic-gate 206*0Sstevel@tonic-gate #else 207*0Sstevel@tonic-gate 208*0Sstevel@tonic-gate /* 209*0Sstevel@tonic-gate * If we're the 32-bit kernel, the result of these function 210*0Sstevel@tonic-gate * calls is completely predictable, so let's just cheat. A 211*0Sstevel@tonic-gate * good compiler should be able to elide all the unreachable code 212*0Sstevel@tonic-gate * that results. Optimism about optimization reigns supreme ;-) 213*0Sstevel@tonic-gate */ 214*0Sstevel@tonic-gate #define lwp_getdatamodel(t) DATAMODEL_ILP32 215*0Sstevel@tonic-gate #define get_udatamodel() DATAMODEL_ILP32 216*0Sstevel@tonic-gate 217*0Sstevel@tonic-gate #endif /* _LP64 || __lint */ 218*0Sstevel@tonic-gate 219*0Sstevel@tonic-gate #endif /* _KERNEL && !_ASM */ 220*0Sstevel@tonic-gate 221*0Sstevel@tonic-gate #ifdef __cplusplus 222*0Sstevel@tonic-gate } 223*0Sstevel@tonic-gate #endif 224*0Sstevel@tonic-gate 225*0Sstevel@tonic-gate #endif /* _SYS_MODEL_H */ 226