xref: /titanic_50/usr/src/common/smbios/mktables.sh (revision 84ab085a13f931bc78e7415e7ce921dbaa14fcb3)
1*84ab085aSmws#!/bin/sh
2*84ab085aSmws#
3*84ab085aSmws# CDDL HEADER START
4*84ab085aSmws#
5*84ab085aSmws# The contents of this file are subject to the terms of the
6*84ab085aSmws# Common Development and Distribution License, Version 1.0 only
7*84ab085aSmws# (the "License").  You may not use this file except in compliance
8*84ab085aSmws# with the License.
9*84ab085aSmws#
10*84ab085aSmws# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
11*84ab085aSmws# or http://www.opensolaris.org/os/licensing.
12*84ab085aSmws# See the License for the specific language governing permissions
13*84ab085aSmws# and limitations under the License.
14*84ab085aSmws#
15*84ab085aSmws# When distributing Covered Code, include this CDDL HEADER in each
16*84ab085aSmws# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17*84ab085aSmws# If applicable, add the following below this CDDL HEADER, with the
18*84ab085aSmws# fields enclosed by brackets "[]" replaced with your own identifying
19*84ab085aSmws# information: Portions Copyright [yyyy] [name of copyright owner]
20*84ab085aSmws#
21*84ab085aSmws# CDDL HEADER END
22*84ab085aSmws#
23*84ab085aSmws#
24*84ab085aSmws# Copyright 2005 Sun Microsystems, Inc.  All rights reserved.
25*84ab085aSmws# Use is subject to license terms.
26*84ab085aSmws#
27*84ab085aSmws#ident	"%Z%%M%	%I%	%E% SMI"
28*84ab085aSmws
29*84ab085aSmws#
30*84ab085aSmws# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to-
31*84ab085aSmws# string conversion routines for the various constants defined in the SMBIOS
32*84ab085aSmws# spec.  These functions are used by smbios(1M) and prtdiag(1M) and can be
33*84ab085aSmws# leveraged by other clients as well.  To simplify maintenance of the source
34*84ab085aSmws# base, this shell script automatically generates the source code for all of
35*84ab085aSmws# these functions from the <sys/smbios.h> header file and its comments.  Each
36*84ab085aSmws# set of constants should be given a unique #define prefix, listed in the
37*84ab085aSmws# tables below.  The smbios_*_name() functions return the identifier of the
38*84ab085aSmws# cpp define, and the smbios_*_desc() functions return the text of the comment.
39*84ab085aSmws#
40*84ab085aSmws
41*84ab085aSmwsname_funcs='
42*84ab085aSmwsSMB_BBFL_	smbios_bboard_flag_name		uint_t
43*84ab085aSmwsSMB_BIOSFL_	smbios_bios_flag_name		uint64_t
44*84ab085aSmwsSMB_BIOSXB1_	smbios_bios_xb1_name		uint_t
45*84ab085aSmwsSMB_BIOSXB2_	smbios_bios_xb2_name		uint_t
46*84ab085aSmwsSMB_CAT_	smbios_cache_ctype_name		uint_t
47*84ab085aSmwsSMB_CAF_	smbios_cache_flag_name		uint_t
48*84ab085aSmwsSMB_EVFL_	smbios_evlog_flag_name		uint_t
49*84ab085aSmwsSMB_IPMI_F_	smbios_ipmi_flag_name		uint_t
50*84ab085aSmwsSMB_MDF_	smbios_memdevice_flag_name	uint_t
51*84ab085aSmwsSMB_TYPE_ 	smbios_type_name		uint_t
52*84ab085aSmwsSMB_SLCH1_	smbios_slot_ch1_name		uint_t
53*84ab085aSmwsSMB_SLCH2_	smbios_slot_ch2_name		uint_t
54*84ab085aSmws'
55*84ab085aSmws
56*84ab085aSmwsdesc_funcs='
57*84ab085aSmwsSMB_BBFL_	smbios_bboard_flag_desc		uint_t
58*84ab085aSmwsSMB_BBT_	smbios_bboard_type_desc		uint_t
59*84ab085aSmwsSMB_BIOSFL_	smbios_bios_flag_desc		uint64_t
60*84ab085aSmwsSMB_BIOSXB1_	smbios_bios_xb1_desc		uint_t
61*84ab085aSmwsSMB_BIOSXB2_	smbios_bios_xb2_desc		uint_t
62*84ab085aSmwsSMB_BOOT_	smbios_boot_desc		uint_t
63*84ab085aSmwsSMB_CAA_	smbios_cache_assoc_desc		uint_t
64*84ab085aSmwsSMB_CAT_	smbios_cache_ctype_desc		uint_t
65*84ab085aSmwsSMB_CAE_	smbios_cache_ecc_desc		uint_t
66*84ab085aSmwsSMB_CAF_	smbios_cache_flag_desc		uint_t
67*84ab085aSmwsSMB_CAL_	smbios_cache_loc_desc		uint_t
68*84ab085aSmwsSMB_CAG_	smbios_cache_logical_desc	uint_t
69*84ab085aSmwsSMB_CAM_	smbios_cache_mode_desc		uint_t
70*84ab085aSmwsSMB_CHST_	smbios_chassis_state_desc	uint_t
71*84ab085aSmwsSMB_CHT_	smbios_chassis_type_desc	uint_t
72*84ab085aSmwsSMB_EVFL_	smbios_evlog_flag_desc		uint_t
73*84ab085aSmwsSMB_EVHF_	smbios_evlog_format_desc	uint_t
74*84ab085aSmwsSMB_EVM_	smbios_evlog_method_desc	uint_t
75*84ab085aSmwsSMB_HWSEC_PS_	smbios_hwsec_desc		uint_t
76*84ab085aSmwsSMB_IPMI_F_	smbios_ipmi_flag_desc		uint_t
77*84ab085aSmwsSMB_IPMI_T_	smbios_ipmi_type_desc		uint_t
78*84ab085aSmwsSMB_MAL_	smbios_memarray_loc_desc	uint_t
79*84ab085aSmwsSMB_MAU_	smbios_memarray_use_desc	uint_t
80*84ab085aSmwsSMB_MAE_	smbios_memarray_ecc_desc	uint_t
81*84ab085aSmwsSMB_MDF_	smbios_memdevice_flag_desc	uint_t
82*84ab085aSmwsSMB_MDFF_	smbios_memdevice_form_desc	uint_t
83*84ab085aSmwsSMB_MDT_	smbios_memdevice_type_desc	uint_t
84*84ab085aSmwsSMB_POC_	smbios_port_conn_desc		uint_t
85*84ab085aSmwsSMB_POT_	smbios_port_type_desc		uint_t
86*84ab085aSmwsSMB_PRF_	smbios_processor_family_desc	uint_t
87*84ab085aSmwsSMB_PRS_	smbios_processor_status_desc	uint_t
88*84ab085aSmwsSMB_PRT_	smbios_processor_type_desc	uint_t
89*84ab085aSmwsSMB_PRU_	smbios_processor_upgrade_desc	uint_t
90*84ab085aSmwsSMB_SLCH1_	smbios_slot_ch1_desc		uint_t
91*84ab085aSmwsSMB_SLCH2_	smbios_slot_ch2_desc		uint_t
92*84ab085aSmwsSMB_SLL_	smbios_slot_length_desc		uint_t
93*84ab085aSmwsSMB_SLT_	smbios_slot_type_desc		uint_t
94*84ab085aSmwsSMB_SLU_	smbios_slot_usage_desc		uint_t
95*84ab085aSmwsSMB_SLW_	smbios_slot_width_desc		uint_t
96*84ab085aSmwsSMB_TYPE_ 	smbios_type_desc		uint_t
97*84ab085aSmwsSMB_WAKEUP_	smbios_system_wakeup_desc	uint_t
98*84ab085aSmws'
99*84ab085aSmws
100*84ab085aSmwsif [ $# -ne 1 ]; then
101*84ab085aSmws	echo "Usage: $0 file.h > file.c" >&2
102*84ab085aSmws	exit 2
103*84ab085aSmwsfi
104*84ab085aSmws
105*84ab085aSmwsecho "\
106*84ab085aSmws/*\n\
107*84ab085aSmws * Copyright 2005 Sun Microsystems, Inc.  All rights reserved.\n\
108*84ab085aSmws * Use is subject to license terms.\n\
109*84ab085aSmws */\n\
110*84ab085aSmws\n\
111*84ab085aSmws#pragma ident\t\"%Z%%M%\t%I%\t%E% SMI\"\n\
112*84ab085aSmws\n\
113*84ab085aSmws#include <smbios.h>"
114*84ab085aSmws
115*84ab085aSmwsecho "$name_funcs" | while read p name type; do
116*84ab085aSmws	[ -z "$p" ] && continue
117*84ab085aSmws	pattern="^#define[	 ]\($p[A-Za-z0-9_]*\)[	 ]*[A-Z0-9]*.*$"
118*84ab085aSmws	replace='	case \1: return ("\1");'
119*84ab085aSmws
120*84ab085aSmws	echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
121*84ab085aSmws	sed -n "s@$pattern@$replace@p" < $1 || exit 1
122*84ab085aSmws	echo "\t}\n\treturn (NULL);\n}"
123*84ab085aSmwsdone
124*84ab085aSmws
125*84ab085aSmws#
126*84ab085aSmws# Generate the description functions based on the comment next to a #define.
127*84ab085aSmws# The transformations for descriptive comments are slightly more complicated
128*84ab085aSmws# than those used for the identifier->name functions above:
129*84ab085aSmws#
130*84ab085aSmws# (1) strip any [RO] suffix from the comment (a header file convention)
131*84ab085aSmws# (2) replace any " with \" so it is escaped for the final output string
132*84ab085aSmws# (3) replace return (...); with return ("..."); to finish the code
133*84ab085aSmws#
134*84ab085aSmwsecho "$desc_funcs" | while read p name type; do
135*84ab085aSmws	[ -z "$p" ] && continue
136*84ab085aSmws	pattern="^#define[	 ]\($p[A-Za-z0-9_]*\)[	 ]*.*/\\* \(.*\) \\*/$"
137*84ab085aSmws	replace='	case \1: return (\2);'
138*84ab085aSmws
139*84ab085aSmws	echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
140*84ab085aSmws	sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \
141*84ab085aSmws	    sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1
142*84ab085aSmws	echo "\t}\n\treturn (NULL);\n}"
143*84ab085aSmwsdone
144*84ab085aSmws
145*84ab085aSmwsexit 0
146