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