xref: /titanic_51/usr/src/uts/common/sys/tnf_com.h (revision 3c9168fa8e9c30d55b3aa2fde74bd7da46df53f5)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  *	Copyright (c) 1994, by Sun Microsytems, Inc.
24  */
25 
26 #ifndef	_SYS_TNF_COM_H
27 #define	_SYS_TNF_COM_H
28 
29 #pragma ident	"%Z%%M%	%I%	%E% SMI"
30 
31 #include <sys/types.h>
32 
33 #ifdef __cplusplus
34 extern "C" {
35 #endif
36 
37 /*
38  * NOTE: All types are in host (not necessarily file) format.
39  * Readers are responsible for endian or other transformation.
40  */
41 
42 /*
43  * Magic number(s): first word of TNF file.
44  *
45  * A writer stores the native unsigned 32-bit integer TNF_MAGIC.
46  * A same-endian reader will load it as TNF_MAGIC.
47  * A different-endian reader will load it as TNF_MAGIC_1.
48  */
49 
50 #define	TNF_MAGIC		0x544e4600
51 #define	TNF_MAGIC_1		0x00464e54
52 
53 /*
54  * Fundamental types.  Machine dependent.
55  */
56 
57 typedef char			tnf_char_t;
58 typedef signed char		tnf_int8_t;
59 typedef unsigned char		tnf_uint8_t;
60 typedef short			tnf_int16_t;
61 typedef unsigned short		tnf_uint16_t;
62 typedef int			tnf_int32_t;
63 typedef unsigned int		tnf_uint32_t;
64 typedef longlong_t		tnf_int64_t;
65 typedef u_longlong_t		tnf_uint64_t;
66 typedef float			tnf_float32_t;
67 typedef double			tnf_float64_t;
68 
69 /*
70  * TNF references
71  */
72 
73 typedef tnf_int32_t		tnf_ref32_t; /* self-relative, 32 bits */
74 typedef tnf_int16_t		tnf_ref16_t; /* self-relative, 16 bits */
75 typedef tnf_uint16_t		tnf_abs16_t; /* absolute, 16 bits */
76 
77 /* Generation number for tag blocks */
78 #define	TNF_TAG_GENERATION_NUM	0xffffffff
79 
80 /* definition of space values */
81 #define	TNF_SPACE_MASK		0x80000000
82 #define	TNF_SPACE_PERMANENT	0x80000000
83 #define	TNF_SPACE_RECLAIMABLE	0x0
84 #define	TNF_SPACE_SIGN_BIT	0x40000000
85 
86 /* Macros on setting or checking space values */
87 #define	TNF_REF32_MAKE_PERMANENT(x)	((x) | TNF_SPACE_PERMANENT)
88 #define	TNF_REF32_MAKE_RECLAIMABLE(x)	((x) & ~TNF_SPACE_MASK)
89 #define	TNF_REF32_SPACE(x)	\
90 	((tnf_uint32_t)(x) & TNF_SPACE_MASK)
91 #define	TNF_REF32_IS_PERMANENT(x)	\
92 	(TNF_REF32_SPACE(x) == TNF_SPACE_PERMANENT)
93 #define	TNF_REF32_IS_RECLAIMABLE(x)	\
94 	(TNF_REF32_SPACE(x) == TNF_SPACE_RECLAIMABLE)
95 #define	TNF_REF32_SIGN_EXTEND(x)	\
96 	((((tnf_uint32_t)(x) & TNF_SPACE_SIGN_BIT) == TNF_SPACE_SIGN_BIT) ? \
97 		((tnf_ref32_t)((tnf_uint32_t)(x) | TNF_SPACE_MASK)) :   \
98 		(x))
99 
100 /* definition of references */
101 #define	TNF_REF32_TYPE_MASK	0x3
102 #define	TNF_REF32_T_FULL	0x0
103 #define	TNF_REF32_T_FWD		TNF_REF32_T_FULL
104 #define	TNF_REF32_T_PAIR	0x1
105 #define	TNF_REF32_T_TAG		0x2
106 #define	TNF_REF32_T_RSVD	0x3
107 
108 #define	TNF_REF32_REF16_MASK	0xffff
109 
110 #define	TNF_REF32_TAG16_SHIFT	16
111 #define	TNF_REF32_TAG16_MASK	0xffff
112 
113 #define	TNF_REF16_TYPE_MASK	0x3
114 
115 #define	TNF_TAG16_TYPE_MASK	0x3
116 #define	TNF_TAG16_T_ABS		TNF_REF32_T_PAIR
117 #define	TNF_TAG16_T_REL		TNF_REF32_T_FWD
118 
119 #define	TNF_NULL		0
120 
121 /* Macros on tnf_ref32_t values: */
122 
123 #define	TNF_REF32_TYPE(x)	\
124 	((tnf_uint32_t)(x) & TNF_REF32_TYPE_MASK)
125 #define	TNF_REF32_VALUE(x)	\
126 	((tnf_ref32_t)(((tnf_uint32_t)(x) & ~TNF_REF32_TYPE_MASK) & \
127 					~TNF_SPACE_MASK))
128 
129 #define	TNF_REF32_IS_FULL(x)	(TNF_REF32_TYPE(x) == TNF_REF32_T_FULL)
130 #define	TNF_REF32_IS_FWD(x)	(TNF_REF32_TYPE(x) == TNF_REF32_T_FWD)
131 #define	TNF_REF32_IS_PAIR(x)	(TNF_REF32_TYPE(x) == TNF_REF32_T_PAIR)
132 #define	TNF_REF32_IS_TAG(x)	(TNF_REF32_TYPE(x) == TNF_REF32_T_TAG)
133 #define	TNF_REF32_IS_RSVD(x)	(TNF_REF32_TYPE(x) == TNF_REF32_T_RSVD)
134 #define	TNF_REF32_IS_NULL(x)	((x) == TNF_NULL)
135 
136 #define	TNF_REF32_REF16(x)	\
137 	((tnf_ref16_t)((tnf_uint32_t)(x) & TNF_REF32_REF16_MASK))
138 
139 #define	TNF_REF32_TAG16(x)	\
140 	((tnf_ref16_t)(((tnf_uint32_t)(x) >> TNF_REF32_TAG16_SHIFT)	\
141 				& TNF_REF32_TAG16_MASK))
142 
143 /* Macros on tnf_ref16_t values: */
144 
145 #define	TNF_REF16_TYPE(x)	\
146 	((tnf_uint32_t)(x) & TNF_REF16_TYPE_MASK)
147 #define	TNF_REF16_VALUE(x)	\
148 	((tnf_ref16_t)((tnf_uint32_t)(x) & ~TNF_REF16_TYPE_MASK))
149 
150 #define	TNF_TAG16_TYPE(x)	\
151 	((tnf_uint32_t)(x) & TNF_TAG16_TYPE_MASK)
152 
153 #define	TNF_TAG16_IS_REL(x)	(TNF_TAG16_TYPE(x) == TNF_TAG16_T_REL)
154 #define	TNF_TAG16_IS_ABS(x)	(TNF_TAG16_TYPE(x) == TNF_TAG16_T_ABS)
155 
156 /* The two kinds of values a tag16 can have: */
157 
158 #define	TNF_TAG16_REF16(x)	\
159 	((tnf_ref16_t)((tnf_uint32_t)(x) & ~TNF_TAG16_TYPE_MASK))
160 #define	TNF_TAG16_ABS16(x)	\
161 	((tnf_abs16_t)((tnf_uint32_t)(x) & ~TNF_TAG16_TYPE_MASK))
162 
163 /*
164  * TNF binary layouts
165  */
166 
167 struct tnf_tagged_hdr {
168 	tnf_ref32_t	tag;		/* type record */
169 };
170 
171 struct tnf_array_hdr {
172 	tnf_ref32_t	tag;		/* type record */
173 	tnf_uint32_t 	self_size;	/* total size */
174 };
175 
176 struct tnf_type_hdr {
177 	tnf_ref32_t	tag;		/* type record */
178 	tnf_ref32_t	name;		/* string record */
179 	tnf_ref32_t	properties;	/* array of type records */
180 };
181 
182 struct tnf_struct_type_hdr {
183 	tnf_ref32_t	tag;		/* type record */
184 	tnf_ref32_t	name;		/* string record */
185 	tnf_ref32_t	properties;	/* array of type records */
186 	tnf_ref32_t	slot_types;	/* array of type records */
187 	tnf_uint32_t	type_size;	/* size of struct */
188 };
189 
190 struct tnf_array_type_hdr {
191 	tnf_ref32_t	tag;		/* type record */
192 	tnf_ref32_t	name;		/* string record */
193 	tnf_ref32_t	properties;	/* array of type records */
194 	tnf_ref32_t	slot_types;	/* array of type records */
195 	tnf_uint32_t	header_size;	/* size of array header */
196 };
197 
198 struct tnf_derived_type_hdr {
199 	tnf_ref32_t	tag;		/* type record */
200 	tnf_ref32_t	name;		/* string record */
201 	tnf_ref32_t	properties;	/* array of type records */
202 	tnf_ref32_t	derived_base;	/* type record */
203 };
204 
205 /*
206  * File header, after magic #
207  */
208 
209 #define	TNF_FILE_VERSION	1
210 
211 typedef struct tnf_file_header {
212 	tnf_ref32_t	tag;
213 	tnf_uint32_t	file_version;	/* TNF_FILE_VERSION */
214 	tnf_uint32_t	file_header_size;
215 	tnf_uint32_t	file_log_size;
216 	tnf_uint32_t	block_header_size;
217 	tnf_uint32_t	block_size;
218 	tnf_uint32_t	directory_size;
219 	tnf_uint32_t	block_count;
220 	tnf_uint32_t	blocks_valid;
221 	/* writer-specific information after this	*/
222 	/* zero padding to end of block 		*/
223 } tnf_file_header_t;
224 
225 /*
226  * Block header
227  */
228 
229 typedef unsigned char		tnf_byte_lock_t;
230 
231 typedef struct tnf_block_header {
232 	tnf_ref32_t		tag;
233 	tnf_uint32_t		generation; /* (-1) => tag block */
234 	tnf_uint16_t		bytes_valid;
235 	tnf_byte_lock_t		A_lock;
236 	tnf_byte_lock_t		B_lock;
237 	struct tnf_block_header	*next_block; /* release list */
238 } tnf_block_header_t;
239 
240 /*
241  * TNF type names
242  */
243 
244 #define	TNF_N_INLINE		"tnf_inline"
245 #define	TNF_N_TAGGED		"tnf_tagged"
246 
247 #define	TNF_N_SCALAR		"tnf_scalar"
248 #define	TNF_N_CHAR		"tnf_char"
249 #define	TNF_N_INT8 		"tnf_int8"
250 #define	TNF_N_UINT8		"tnf_uint8"
251 #define	TNF_N_INT16		"tnf_int16"
252 #define	TNF_N_UINT16		"tnf_uint16"
253 #define	TNF_N_INT32		"tnf_int32"
254 #define	TNF_N_UINT32		"tnf_uint32"
255 #define	TNF_N_INT64		"tnf_int64"
256 #define	TNF_N_UINT64		"tnf_uint64"
257 #define	TNF_N_FLOAT32		"tnf_float32"
258 #define	TNF_N_FLOAT64		"tnf_float64"
259 
260 #define	TNF_N_ARRAY		"tnf_array"
261 #define	TNF_N_STRING 		"tnf_string"
262 #define	TNF_N_TYPE_ARRAY	"tnf_type_array"
263 #define	TNF_N_NAME_ARRAY	"tnf_name_array"
264 
265 #define	TNF_N_ALIGN		"tnf_align"
266 #define	TNF_N_DERIVED		"tnf_derived"
267 #define	TNF_N_DERIVED_BASE	"tnf_derived_base"
268 #define	TNF_N_ELEMENT_TYPE	"tnf_element_type"
269 #define	TNF_N_HEADER_SIZE	"tnf_header_size"
270 #define	TNF_N_NAME		"tnf_name"
271 #define	TNF_N_OPAQUE		"tnf_opaque"
272 #define	TNF_N_PROPERTIES	"tnf_properties"
273 #define	TNF_N_SELF_SIZE		"tnf_self_size"
274 #define	TNF_N_SIZE		"tnf_size"
275 #define	TNF_N_SLOT_NAMES	"tnf_slot_names"
276 #define	TNF_N_SLOT_TYPES	"tnf_slot_types"
277 #define	TNF_N_TAG		"tnf_tag"
278 #define	TNF_N_TAG_ARG		"tnf_tag_arg"
279 #define	TNF_N_TYPE_SIZE		"tnf_type_size"
280 
281 #define	TNF_N_STRUCT		"tnf_struct"
282 
283 #define	TNF_N_ARRAY_TYPE	"tnf_array_type"
284 #define	TNF_N_DERIVED_TYPE	"tnf_derived_type"
285 #define	TNF_N_SCALAR_TYPE	"tnf_scalar_type"
286 #define	TNF_N_STRUCT_TYPE	"tnf_struct_type"
287 #define	TNF_N_TYPE		"tnf_type"
288 
289 /*
290  * Reserved names for block and file header information
291  */
292 
293 #define	TNF_N_FILE_HEADER	"tnf_file_header"
294 #define	TNF_N_FILE_VERSION	"file_version"
295 #define	TNF_N_FILE_HEADER_SIZE	"file_header_size"
296 #define	TNF_N_FILE_LOGICAL_SIZE	"file_logical_size"
297 #define	TNF_N_BLOCK_HEADER_SIZE	"block_header_size"
298 #define	TNF_N_BLOCK_SIZE	"block_size"
299 #define	TNF_N_DIRECTORY_SIZE	"directory_size"
300 #define	TNF_N_BLOCK_COUNT	"block_count"
301 #define	TNF_N_BLOCKS_VALID	"blocks_valid"
302 
303 #define	TNF_N_BLOCK_HEADER	"tnf_block_header"
304 #define	TNF_N_GENERATION	"generation"
305 #define	TNF_N_BYTES_VALID	"bytes_valid"
306 
307 /*
308  * Reserved names for schedule record information
309  */
310 
311 #define	TNF_N_USER_SCHEDULE	"tnf_user_schedule"
312 #define	TNF_N_KERNEL_SCHEDULE	"tnf_kernel_schedule"
313 
314 #define	TNF_N_PID		"pid"
315 #define	TNF_N_LWPID		"lwpid"
316 #define	TNF_N_TID		"tid"
317 #define	TNF_N_TIME_BASE		"time_base"
318 #define	TNF_N_TIME_DELTA	"time_delta"
319 
320 /* XXX TODO: kernel type names */
321 
322 #ifdef __cplusplus
323 }
324 #endif
325 
326 #endif /* _SYS_TNF_COM_H */
327