xref: /titanic_50/usr/src/uts/common/tnf/mkprobehdr.sh (revision 554ff184129088135ad2643c1c9832174a17be88)
1#!/usr/bin/sh
2#
3# CDDL HEADER START
4#
5# The contents of this file are subject to the terms of the
6# Common Development and Distribution License, Version 1.0 only
7# (the "License").  You may not use this file except in compliance
8# with the License.
9#
10# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11# or http://www.opensolaris.org/os/licensing.
12# See the License for the specific language governing permissions
13# and limitations under the License.
14#
15# When distributing Covered Code, include this CDDL HEADER in each
16# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17# If applicable, add the following below this CDDL HEADER, with the
18# fields enclosed by brackets "[]" replaced with your own identifying
19# information: Portions Copyright [yyyy] [name of copyright owner]
20#
21# CDDL HEADER END
22#
23#
24# Copyright (c) 1994-2000 by Sun Microsystems, Inc.
25# All rights reserved.
26#
27#ident	"%Z%%M%	%I%	%E% SMI"
28
29cat <<ENDSTR
30/*
31 *	Copyright (c) 1994, by Sun Microsytems, Inc.
32 */
33
34#ifndef _SYS_TNF_PROBE_H
35#define	_SYS_TNF_PROBE_H
36
37#pragma ident	"%Z%tnf_probe.h	%I%	%E% SMI"
38
39#include <sys/tnf_writer.h>
40
41#ifdef __cplusplus
42extern "C" {
43#endif
44
45/*
46 * These macros are used to convert the __LINE__ directive to a
47 * string in the probe macros below.
48 */
49
50#define	TNF_STRINGIFY(x) #x
51#define	TNF_STRINGVALUE(x) TNF_STRINGIFY(x)
52
53/*
54 * Alignment of tnf_ref32_t
55 */
56
57struct _tnf_ref32_align {
58	char		c;
59	tnf_ref32_t	t;
60};
61#define	TNF_REF32_ALIGN		TNF_OFFSETOF(struct _tnf_ref32_align, t)
62
63/*
64 * Probe versioning
65 */
66
67struct tnf_probe_version {
68	size_t	version_size;		/* sizeof(struct tnf_probe_version) */
69	size_t	probe_control_size;	/* sizeof(tnf_probe_control_t) */
70};
71
72extern struct tnf_probe_version __tnf_probe_version_1;
73#pragma weak __tnf_probe_version_1
74
75/*
76 * Typedefs
77 */
78
79typedef struct tnf_probe_control tnf_probe_control_t;
80typedef struct tnf_probe_setup tnf_probe_setup_t;
81
82/* returns pointer to buffer */
83typedef void * (*tnf_probe_test_func_t)(void *,
84					tnf_probe_control_t *,
85					tnf_probe_setup_t *);
86
87/* returns buffer pointer */
88typedef void * (*tnf_probe_alloc_func_t)(tnf_ops_t *,	/* tpd	*/
89					tnf_probe_control_t *,
90					tnf_probe_setup_t *);
91
92typedef void (*tnf_probe_func_t)(tnf_probe_setup_t *);
93
94/*
95 * Probe argument block
96 */
97
98struct tnf_probe_setup {
99	tnf_ops_t		*tpd_p;
100	void			*buffer_p;
101	tnf_probe_control_t	*probe_p;
102};
103
104/*
105 * Probe control block
106 */
107
108struct tnf_probe_control {
109	const struct tnf_probe_version	*version;
110	tnf_probe_control_t	*next;
111	tnf_probe_test_func_t	test_func;
112	tnf_probe_alloc_func_t	alloc_func;
113	tnf_probe_func_t	probe_func;
114	tnf_probe_func_t	commit_func;
115	tnf_uint32_t		index;
116	const char		*attrs;
117	tnf_tag_data_t		***slot_types;
118	unsigned long		tnf_event_size;
119};
120
121#ifdef _KERNEL
122
123#define	TNF_NEXT_INIT	0
124
125#else
126
127#define	TNF_NEXT_INIT	-1
128
129#endif	/* _KERNEL */
130
131/*
132 * TNF Type extension
133 */
134
135#ifdef NPROBE
136
137#define	TNF_DECLARE_RECORD(ctype, record)				\\
138	typedef tnf_reference_t record##_t
139
140#else
141
142#define	TNF_DECLARE_RECORD(ctype, record)				\\
143	typedef tnf_reference_t record##_t;				\\
144	extern tnf_tag_data_t *record##_tag_data;			\\
145	extern record##_t record(tnf_ops_t *, ctype *, tnf_reference_t)
146
147#endif	/* NPROBE */
148
149ENDSTR
150
151#
152# The following code generates the five type extension macros
153#
154for i in 1 2 3 4 5; do
155  echo "#ifdef NPROBE\n"
156  echo "/* CSTYLED */"
157  echo "#define	TNF_DEFINE_RECORD_$i(ctype, ctype_record\c"
158  j=1; while [ $j -le $i ]; do
159    echo ", t$j, n$j\c"
160    j=`expr $j + 1`
161  done
162  echo ")\n"
163  echo "#else\n"
164  echo "/* CSTYLED */"
165  echo "#define	TNF_DEFINE_RECORD_$i(ctype, ctype_record\c"
166  j=1; while [ $j -le $i ]; do
167    echo ", t$j, n$j\c"
168    j=`expr $j + 1`
169  done
170  echo ") \\"
171  echo "typedef struct {						\\"
172  echo "	tnf_tag_t	tag;					\\"
173  j=1; while [ $j -le $i ]; do
174    echo "	t$j##_t		data_$j;				\\"
175    j=`expr $j + 1`
176  done
177  echo "} ctype_record##_prototype_t;					\\"
178  echo "static tnf_tag_data_t **ctype_record##_type_slots[] = {		\\"
179  echo "	&tnf_tag_tag_data,					\\"
180  j=1; while [ $j -le $i ]; do
181    echo "	&t$j##_tag_data,					\\"
182    j=`expr $j + 1`
183  done
184  echo "	0 };							\\";
185  echo "static char *ctype_record##_slot_names[] = {			\\";
186  echo "	\"tnf_tag\",						\\"
187  j=1; while [ $j -le $i ]; do
188    echo "	\"\"#n$j,						\\"
189    j=`expr $j + 1`
190  done
191  echo "	0 };							\\"
192  echo "static tnf_tag_data_t ctype_record##_tag_data_rec = {		\\"
193  echo "	TNF_TAG_VERSION, &tnf_struct_tag_1,			\\"
194  echo "	0, #ctype_record, &tnf_user_struct_properties,		\\"
195  echo "	sizeof (ctype_record##_prototype_t),			\\"
196  echo "	TNF_REF32_ALIGN,					\\"
197  echo "	sizeof (ctype_record##_t), TNF_STRUCT, 0,		\\"
198  echo "	ctype_record##_type_slots, ctype_record##_slot_names	\\"
199  echo "};								\\"
200  echo "tnf_tag_data_t *ctype_record##_tag_data =			\\"
201  echo "			&ctype_record##_tag_data_rec;		\\"
202  echo "ctype_record##_t						\\"
203  echo "ctype_record(tnf_ops_t *ops, ctype * the_ctype,			\\"
204  echo "				tnf_reference_t reference)	\\"
205  echo "{								\\"
206  echo "	tnf_tag_data_t			*metatag_data;		\\"
207  echo "	tnf_record_p			metatag_index;		\\"
208  echo "	ctype_record##_prototype_t	*buffer;		\\"
209  echo "								\\"
210  echo "	if (the_ctype == NULL)					\\"
211  echo "		return (0);					\\"
212  echo "	buffer = (ctype_record##_prototype_t *) tnf_allocate(ops, \\"
213  echo "			sizeof (ctype_record##_prototype_t));	\\"
214  echo "	if (buffer == NULL)					\\"
215  echo "		return (0);					\\"
216  echo "								\\"
217  echo "	metatag_data = ctype_record##_tag_data;			\\"
218  echo "	metatag_index = metatag_data->tag_index ?		\\"
219  echo "		metatag_data->tag_index:			\\"
220  echo "		metatag_data->tag_desc(ops, metatag_data);	\\"
221  echo "	buffer->tag = tnf_tag(ops, metatag_index,		\\"
222  echo "		(tnf_reference_t) &buffer->tag);		\\"
223  j=1; while [ $j -le $i ]; do
224    echo "	buffer->data_$j = t$j(ops, the_ctype->n$j,		\\"
225    echo "			(tnf_reference_t) &(buffer->data_$j));	\\"
226    j=`expr $j + 1`
227  done
228  echo "	return (tnf_ref32(ops, (tnf_record_p) buffer, reference)); \\"
229  echo "}\n"
230  echo "#endif /* NPROBE */"
231  echo ""
232done
233
234echo "/*"
235echo " * Probe Macros"
236echo " */"
237echo ""
238
239#
240# The following code generates the six probe macros ...
241#
242for i in 0 1 2 3 4 5; do
243  echo "#ifdef NPROBE\n"
244  echo "/* CSTYLED */"
245  echo "#define	TNF_PROBE_$i(namearg, keysarg, detail\c"
246  j=1; while [ $j -le $i ]; do
247    echo ", type_$j, namearg_$j, valarg_$j\c"
248    j=`expr $j + 1`
249  done
250  echo ") \\"
251  echo "\t\t((void)0)\n"
252  echo "#else\n"
253  echo "/* CSTYLED */"
254  echo "#define	TNF_PROBE_$i(namearg, keysarg, detail\c"
255  j=1; while [ $j -le $i ]; do
256    echo ", type_$j, namearg_$j, valarg_$j\c";
257    j=`expr $j + 1`
258  done
259  echo ")	\\"
260  echo "{								\\"
261  echo "	struct tnf_v_buf_$i {					\\"
262  echo "		tnf_probe_event_t	probe_event;		\\"
263  echo "		tnf_time_delta_t	time_delta;		\\"
264  j=1; while [ $j -le $i ]; do
265    echo "		type_$j##_t		data_$j;		\\"
266    j=`expr $j + 1`
267  done
268  echo "	};							\\"
269  echo "	static tnf_tag_data_t ** tnf_v_##namearg##_info[] = {		\\"
270  echo "		&tnf_probe_event_tag_data,			\\"
271  echo "		&tnf_time_delta_tag_data,			\\"
272  j=1; while [ $j -le $i ]; do
273    echo "		&type_$j##_tag_data,				\\"
274    j=`expr $j + 1`
275  done
276  echo "		0 };						\\"
277  echo "	static struct tnf_probe_control tnf_v_##namearg##_probe = {	\\"
278  echo "		&__tnf_probe_version_1,				\\"
279  echo "		(tnf_probe_control_t *) TNF_NEXT_INIT,		\\"
280  echo "		(tnf_probe_test_func_t) 0,			\\"
281  echo "		(tnf_probe_alloc_func_t) 0,			\\"
282  echo "		(tnf_probe_func_t) 0,				\\"
283  echo "		(tnf_probe_func_t) 0,				\\"
284  echo "		(tnf_uint32_t) 0,				\\"
285  echo "			/* attribute string */			\\"
286  echo "			\"name \" TNF_STRINGVALUE(namearg) \";\" \\"
287#  echo "			\"slots \"\c"
288#  j=1; while [ $j -le $i ]; do
289#    echo " #namearg_$j \" \"\c"
290#    j=`expr $j + 1`
291  echo "			\"slots \"				\\"
292  j=1; while [ $j -le $i ]; do
293    echo "			\"\"#namearg_$j\" \"			\\"
294    j=`expr $j + 1`
295  done
296  echo "			\";\"					\\"
297  echo "			\"keys \" keysarg \";\"			\\"
298  echo "			\"file \" __FILE__ \";\"		\\"
299  echo "			\"line \" TNF_STRINGVALUE(__LINE__) \";\" \\"
300  echo "			detail,					\\"
301  echo "		tnf_v_##namearg##_info,					\\"
302  echo "		sizeof (struct tnf_v_buf_$i)			\\"
303  echo "	};							\\"
304  echo "	tnf_probe_control_t	*tnf_v_probe_p = &tnf_v_##namearg##_probe; \\"
305  echo "	tnf_probe_test_func_t	tnf_v_probe_test = tnf_v_probe_p->test_func; \\"
306  echo "	tnf_probe_setup_t	tnf_v_set_p;			\\"
307  echo "	struct tnf_v_buf_$i	*tnf_v_probe_buffer;		\\"
308  echo "								\\"
309  echo "	if (tnf_v_probe_test) {					\\"
310  echo "		tnf_v_probe_buffer = (struct tnf_v_buf_$i *)	\\"
311  echo "		    tnf_v_probe_test(0, tnf_v_probe_p, &tnf_v_set_p); \\"
312  echo "		if (tnf_v_probe_buffer) {			\\"
313  j=1; while [ $j -le $i ]; do
314    echo "		    tnf_v_probe_buffer->data_$j = type_$j(	\\"
315    echo "			tnf_v_set_p.tpd_p, valarg_$j,		\\"
316    echo "			(tnf_reference_t) &(tnf_v_probe_buffer->data_$j)); \\"
317    j=`expr $j + 1`
318  done
319  echo "		    (tnf_v_probe_p->probe_func)(&tnf_v_set_p);	\\"
320  echo "		}						\\"
321  echo "	}							\\"
322  echo "}\n"
323  echo "#endif /* NPROBE */"
324  echo ""
325  done
326
327echo "/*"
328echo " * Debug Probe Macros (contain an additional \"debug\" attribute)"
329echo " */"
330echo ""
331
332#
333# The following code generates the six debug probe macros ...
334#
335for i in 0 1 2 3 4 5; do
336  echo "#if defined(TNF_DEBUG)\n"
337  echo "/* CSTYLED */"
338  echo "#define	TNF_PROBE_${i}_DEBUG(namearg, keysarg, detail\c"
339  j=1; while [ $j -le $i ]; do
340    echo ", type_$j, namearg_$j, valarg_$j\c";
341    j=`expr $j + 1`
342  done
343  echo ")\t\c"
344  echo "TNF_PROBE_$i(namearg, keysarg, \"debug;\" detail\c"
345  j=1; while [ $j -le $i ]; do
346    echo ", type_$j, namearg_$j, valarg_$j\c"
347    j=`expr $j + 1`
348  done
349  echo ")\n"
350  echo "#else\n"
351  echo "/* CSTYLED */"
352  echo "#define	TNF_PROBE_${i}_DEBUG(namearg, keysarg, detail\c"
353  j=1; while [ $j -le $i ]; do
354    echo ", type_$j, namearg_$j, valarg_$j\c"
355    j=`expr $j + 1`
356  done
357  echo ") \\"
358  echo "\t\t((void)0)\n"
359  echo "#endif /* defined(TNF_DEBUG) */"
360  echo ""
361  done
362
363  echo "#ifdef __cplusplus"
364  echo "}"
365  echo "#endif"
366  echo ""
367  echo "#endif /* _SYS_TNF_PROBE_H */"
368