17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * CDDL HEADER START 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * The contents of this file are subject to the terms of the 57c478bd9Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only 67c478bd9Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance 77c478bd9Sstevel@tonic-gate * with the License. 87c478bd9Sstevel@tonic-gate * 97c478bd9Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 107c478bd9Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing. 117c478bd9Sstevel@tonic-gate * See the License for the specific language governing permissions 127c478bd9Sstevel@tonic-gate * and limitations under the License. 137c478bd9Sstevel@tonic-gate * 147c478bd9Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each 157c478bd9Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 167c478bd9Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the 177c478bd9Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying 187c478bd9Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner] 197c478bd9Sstevel@tonic-gate * 207c478bd9Sstevel@tonic-gate * CDDL HEADER END 217c478bd9Sstevel@tonic-gate */ 227c478bd9Sstevel@tonic-gate /* 237c478bd9Sstevel@tonic-gate * Copyright 2005 Sun Microsystems, Inc. All rights reserved. 247c478bd9Sstevel@tonic-gate * Use is subject to license terms. 257c478bd9Sstevel@tonic-gate */ 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate #ifndef _SYS_MODEL_H 287c478bd9Sstevel@tonic-gate #define _SYS_MODEL_H 297c478bd9Sstevel@tonic-gate 307c478bd9Sstevel@tonic-gate #ifdef __cplusplus 317c478bd9Sstevel@tonic-gate extern "C" { 327c478bd9Sstevel@tonic-gate #endif 337c478bd9Sstevel@tonic-gate 347c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM) 357c478bd9Sstevel@tonic-gate #include <sys/debug.h> 367c478bd9Sstevel@tonic-gate #endif /* _KERNEL && !_ASM */ 377c478bd9Sstevel@tonic-gate 387c478bd9Sstevel@tonic-gate #include <sys/isa_defs.h> 397c478bd9Sstevel@tonic-gate 40*8329232eSGordon Ross #if defined(_KERNEL) || defined(_FAKE_KERNEL) || defined(_KMEMUSER) 417c478bd9Sstevel@tonic-gate 427c478bd9Sstevel@tonic-gate /* 437c478bd9Sstevel@tonic-gate * These bits are used in various places to specify the data model 447c478bd9Sstevel@tonic-gate * of the originator (and/or consumer) of data items. See <sys/conf.h> 457c478bd9Sstevel@tonic-gate * <sys/file.h>, <sys/stream.h> and <sys/sunddi.h>. 467c478bd9Sstevel@tonic-gate * 477c478bd9Sstevel@tonic-gate * This state should only be known to the kernel implementation. 487c478bd9Sstevel@tonic-gate */ 497c478bd9Sstevel@tonic-gate #define DATAMODEL_MASK 0x0FF00000 507c478bd9Sstevel@tonic-gate 517c478bd9Sstevel@tonic-gate #define DATAMODEL_ILP32 0x00100000 527c478bd9Sstevel@tonic-gate #define DATAMODEL_LP64 0x00200000 537c478bd9Sstevel@tonic-gate 547c478bd9Sstevel@tonic-gate #define DATAMODEL_NONE 0 557c478bd9Sstevel@tonic-gate 567c478bd9Sstevel@tonic-gate #if defined(_LP64) 577c478bd9Sstevel@tonic-gate #define DATAMODEL_NATIVE DATAMODEL_LP64 587c478bd9Sstevel@tonic-gate #elif defined(_ILP32) 597c478bd9Sstevel@tonic-gate #define DATAMODEL_NATIVE DATAMODEL_ILP32 607c478bd9Sstevel@tonic-gate #else 617c478bd9Sstevel@tonic-gate #error "No DATAMODEL_NATIVE specified" 627c478bd9Sstevel@tonic-gate #endif /* _LP64 || _ILP32 */ 637c478bd9Sstevel@tonic-gate 647c478bd9Sstevel@tonic-gate #endif /* _KERNEL || _KMEMUSER */ 657c478bd9Sstevel@tonic-gate 667c478bd9Sstevel@tonic-gate #ifndef _ASM 677c478bd9Sstevel@tonic-gate /* 687c478bd9Sstevel@tonic-gate * XXX Ick. This type needs to be visible outside the above guard because 697c478bd9Sstevel@tonic-gate * the proc structure is visible outside the _KERNEL | _KMEMUSER guard. 707c478bd9Sstevel@tonic-gate * If we can make proc internals less visible, (which we obviously should) 717c478bd9Sstevel@tonic-gate * then this can be invisible too. 727c478bd9Sstevel@tonic-gate */ 737c478bd9Sstevel@tonic-gate typedef unsigned int model_t; 747c478bd9Sstevel@tonic-gate 757c478bd9Sstevel@tonic-gate #endif /* _ASM */ 767c478bd9Sstevel@tonic-gate 777c478bd9Sstevel@tonic-gate #if defined(_KERNEL) && !defined(_ASM) 787c478bd9Sstevel@tonic-gate /* 797c478bd9Sstevel@tonic-gate * These macros allow two views of the same piece of memory depending 807c478bd9Sstevel@tonic-gate * on the originating user-mode program's data model. See the STRUCT_DECL(9F) 817c478bd9Sstevel@tonic-gate * man page. 827c478bd9Sstevel@tonic-gate */ 837c478bd9Sstevel@tonic-gate #if defined(_LP64) 847c478bd9Sstevel@tonic-gate 857c478bd9Sstevel@tonic-gate #define STRUCT_HANDLE(struct_type, handle) \ 867c478bd9Sstevel@tonic-gate struct { \ 877c478bd9Sstevel@tonic-gate union { \ 887c478bd9Sstevel@tonic-gate struct struct_type##32 *m32; \ 897c478bd9Sstevel@tonic-gate struct struct_type *m64; \ 907c478bd9Sstevel@tonic-gate } ptr; \ 917c478bd9Sstevel@tonic-gate model_t model; \ 927c478bd9Sstevel@tonic-gate } handle = { NULL, DATAMODEL_ILP32 } 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate #define STRUCT_DECL(struct_type, handle) \ 957c478bd9Sstevel@tonic-gate struct struct_type __##handle##_buf; \ 967c478bd9Sstevel@tonic-gate STRUCT_HANDLE(struct_type, handle) 977c478bd9Sstevel@tonic-gate 987c478bd9Sstevel@tonic-gate #define STRUCT_SET_HANDLE(handle, umodel, addr) \ 997c478bd9Sstevel@tonic-gate (handle).model = (model_t)(umodel) & DATAMODEL_MASK; \ 1007c478bd9Sstevel@tonic-gate ASSERT(((umodel) & DATAMODEL_MASK) != DATAMODEL_NONE); \ 1017c478bd9Sstevel@tonic-gate ((handle).ptr.m64) = (addr) 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate #define STRUCT_INIT(handle, umodel) \ 1047c478bd9Sstevel@tonic-gate STRUCT_SET_HANDLE(handle, umodel, &__##handle##_buf) 1057c478bd9Sstevel@tonic-gate 1067c478bd9Sstevel@tonic-gate #define STRUCT_SIZE(handle) \ 1077c478bd9Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 1087c478bd9Sstevel@tonic-gate sizeof (*(handle).ptr.m32) : \ 1097c478bd9Sstevel@tonic-gate sizeof (*(handle).ptr.m64)) 1107c478bd9Sstevel@tonic-gate 1117c478bd9Sstevel@tonic-gate /* 1127c478bd9Sstevel@tonic-gate * In STRUCT_FADDR and STRUCT_FGETP a sleight of hand is employed to make 1137c478bd9Sstevel@tonic-gate * the compiler cope with having two different pointer types within ?:. 1147c478bd9Sstevel@tonic-gate * The (void *) case on the ILP32 case makes it a pointer which can be 1157c478bd9Sstevel@tonic-gate * converted to the pointer on the LP64 case, thus quieting the compiler. 1167c478bd9Sstevel@tonic-gate */ 1177c478bd9Sstevel@tonic-gate #define STRUCT_FADDR(handle, field) \ 1187c478bd9Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 1197c478bd9Sstevel@tonic-gate (void *)&(handle).ptr.m32->field : \ 1207c478bd9Sstevel@tonic-gate &(handle).ptr.m64->field) 1217c478bd9Sstevel@tonic-gate 1227c478bd9Sstevel@tonic-gate #define STRUCT_FGET(handle, field) \ 1237c478bd9Sstevel@tonic-gate (((handle).model == DATAMODEL_ILP32) ? \ 1247c478bd9Sstevel@tonic-gate (handle).ptr.m32->field : \ 1257c478bd9Sstevel@tonic-gate (handle).ptr.m64->field) 1267c478bd9Sstevel@tonic-gate 1277c478bd9Sstevel@tonic-gate #define STRUCT_FGETP(handle, field) \ 1287c478bd9Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 1297c478bd9Sstevel@tonic-gate (void *)(uintptr_t)(handle).ptr.m32->field : \ 1307c478bd9Sstevel@tonic-gate (handle).ptr.m64->field) 1317c478bd9Sstevel@tonic-gate 1327c478bd9Sstevel@tonic-gate #define STRUCT_FSET(handle, field, val) \ 1337c478bd9Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 1347c478bd9Sstevel@tonic-gate ((handle).ptr.m32->field = (val)) : \ 1357c478bd9Sstevel@tonic-gate ((handle).ptr.m64->field = (val))) 1367c478bd9Sstevel@tonic-gate 1377c478bd9Sstevel@tonic-gate #define STRUCT_FSETP(handle, field, val) \ 1387c478bd9Sstevel@tonic-gate ((handle).model == DATAMODEL_ILP32 ? \ 1397c478bd9Sstevel@tonic-gate (void) ((handle).ptr.m32->field = (caddr32_t)(uintptr_t)(val)) : \ 1407c478bd9Sstevel@tonic-gate (void) ((handle).ptr.m64->field = (val))) 1417c478bd9Sstevel@tonic-gate 1427c478bd9Sstevel@tonic-gate #define STRUCT_BUF(handle) ((handle).ptr.m64) 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate #define SIZEOF_PTR(umodel) \ 1457c478bd9Sstevel@tonic-gate (((umodel) & DATAMODEL_MASK) == DATAMODEL_ILP32 ? \ 1467c478bd9Sstevel@tonic-gate sizeof (caddr32_t) : \ 1477c478bd9Sstevel@tonic-gate sizeof (caddr_t)) 1487c478bd9Sstevel@tonic-gate 1497c478bd9Sstevel@tonic-gate #define SIZEOF_STRUCT(struct_type, umodel) \ 1507c478bd9Sstevel@tonic-gate (((umodel) & DATAMODEL_MASK) == DATAMODEL_ILP32 ? \ 1517c478bd9Sstevel@tonic-gate sizeof (struct struct_type##32) : \ 1527c478bd9Sstevel@tonic-gate sizeof (struct struct_type)) 1537c478bd9Sstevel@tonic-gate 1547c478bd9Sstevel@tonic-gate #else /* _LP64 */ 1557c478bd9Sstevel@tonic-gate 1567c478bd9Sstevel@tonic-gate #define STRUCT_HANDLE(struct_type, handle) \ 1577c478bd9Sstevel@tonic-gate struct { \ 1587c478bd9Sstevel@tonic-gate struct struct_type *ptr; \ 159571b0a13SToomas Soome model_t model; \ 160571b0a13SToomas Soome } handle = { NULL, DATAMODEL_ILP32 } 1617c478bd9Sstevel@tonic-gate 1627c478bd9Sstevel@tonic-gate #define STRUCT_DECL(struct_type, handle) \ 1637c478bd9Sstevel@tonic-gate struct struct_type __##handle##_buf; \ 1647c478bd9Sstevel@tonic-gate STRUCT_HANDLE(struct_type, handle) 1657c478bd9Sstevel@tonic-gate 1667c478bd9Sstevel@tonic-gate #define STRUCT_SET_HANDLE(handle, umodel, addr) \ 167571b0a13SToomas Soome (handle).model = (model_t)(umodel) & DATAMODEL_MASK; \ 168571b0a13SToomas Soome ASSERT(((umodel) & DATAMODEL_MASK) == DATAMODEL_ILP32); \ 1697c478bd9Sstevel@tonic-gate (handle).ptr = (addr) 1707c478bd9Sstevel@tonic-gate 1717c478bd9Sstevel@tonic-gate #define STRUCT_INIT(handle, umodel) \ 1727c478bd9Sstevel@tonic-gate STRUCT_SET_HANDLE(handle, umodel, &__##handle##_buf) 1737c478bd9Sstevel@tonic-gate 1747c478bd9Sstevel@tonic-gate #define STRUCT_SIZE(handle) (sizeof (*(handle).ptr)) 1757c478bd9Sstevel@tonic-gate 1767c478bd9Sstevel@tonic-gate #define STRUCT_FADDR(handle, field) (&(handle).ptr->field) 1777c478bd9Sstevel@tonic-gate 1787c478bd9Sstevel@tonic-gate #define STRUCT_FGET(handle, field) ((handle).ptr->field) 1797c478bd9Sstevel@tonic-gate 1807c478bd9Sstevel@tonic-gate #define STRUCT_FGETP STRUCT_FGET 1817c478bd9Sstevel@tonic-gate 1827c478bd9Sstevel@tonic-gate #define STRUCT_FSET(handle, field, val) ((handle).ptr->field = (val)) 1837c478bd9Sstevel@tonic-gate 1847c478bd9Sstevel@tonic-gate #define STRUCT_FSETP STRUCT_FSET 1857c478bd9Sstevel@tonic-gate 1867c478bd9Sstevel@tonic-gate #define STRUCT_BUF(handle) ((handle).ptr) 1877c478bd9Sstevel@tonic-gate 1887c478bd9Sstevel@tonic-gate #define SIZEOF_PTR(umodel) sizeof (caddr_t) 1897c478bd9Sstevel@tonic-gate 1907c478bd9Sstevel@tonic-gate #define SIZEOF_STRUCT(struct_type, umodel) sizeof (struct struct_type) 1917c478bd9Sstevel@tonic-gate 1927c478bd9Sstevel@tonic-gate #endif /* _LP64 */ 1937c478bd9Sstevel@tonic-gate 1947c478bd9Sstevel@tonic-gate #if defined(_LP64) || defined(__lint) 1957c478bd9Sstevel@tonic-gate 1967c478bd9Sstevel@tonic-gate struct _klwp; 1977c478bd9Sstevel@tonic-gate 1987c478bd9Sstevel@tonic-gate extern model_t lwp_getdatamodel(struct _klwp *); 1997c478bd9Sstevel@tonic-gate extern model_t get_udatamodel(void); 2007c478bd9Sstevel@tonic-gate 2017c478bd9Sstevel@tonic-gate #else 2027c478bd9Sstevel@tonic-gate 2037c478bd9Sstevel@tonic-gate /* 2047c478bd9Sstevel@tonic-gate * If we're the 32-bit kernel, the result of these function 2057c478bd9Sstevel@tonic-gate * calls is completely predictable, so let's just cheat. A 2067c478bd9Sstevel@tonic-gate * good compiler should be able to elide all the unreachable code 2077c478bd9Sstevel@tonic-gate * that results. Optimism about optimization reigns supreme ;-) 2087c478bd9Sstevel@tonic-gate */ 2097c478bd9Sstevel@tonic-gate #define lwp_getdatamodel(t) DATAMODEL_ILP32 2107c478bd9Sstevel@tonic-gate #define get_udatamodel() DATAMODEL_ILP32 2117c478bd9Sstevel@tonic-gate 2127c478bd9Sstevel@tonic-gate #endif /* _LP64 || __lint */ 2137c478bd9Sstevel@tonic-gate 2147c478bd9Sstevel@tonic-gate #endif /* _KERNEL && !_ASM */ 2157c478bd9Sstevel@tonic-gate 2167c478bd9Sstevel@tonic-gate #ifdef __cplusplus 2177c478bd9Sstevel@tonic-gate } 2187c478bd9Sstevel@tonic-gate #endif 2197c478bd9Sstevel@tonic-gate 2207c478bd9Sstevel@tonic-gate #endif /* _SYS_MODEL_H */ 221