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