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