1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
|
#!/bin/sh
#
# CDDL HEADER START
#
# The contents of this file are subject to the terms of the
# Common Development and Distribution License, Version 1.0 only
# (the "License"). You may not use this file except in compliance
# with the License.
#
# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
# or http://www.opensolaris.org/os/licensing.
# See the License for the specific language governing permissions
# and limitations under the License.
#
# When distributing Covered Code, include this CDDL HEADER in each
# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
# If applicable, add the following below this CDDL HEADER, with the
# fields enclosed by brackets "[]" replaced with your own identifying
# information: Portions Copyright [yyyy] [name of copyright owner]
#
# CDDL HEADER END
#
#
# Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.
# Copyright (c) 2018, Joyent, Inc.
# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
#
# The SMBIOS interfaces defined in <sys/smbios.h> include a set of integer-to-
# string conversion routines for the various constants defined in the SMBIOS
# spec. These functions are used by smbios(1M) and prtdiag(1M) and can be
# leveraged by other clients as well. To simplify maintenance of the source
# base, this shell script automatically generates the source code for all of
# these functions from the <sys/smbios.h> header file and its comments. Each
# set of constants should be given a unique #define prefix, listed in the
# tables below. The smbios_*_name() functions return the identifier of the
# cpp define, and the smbios_*_desc() functions return the text of the comment.
#
name_funcs='
SMB_BBFL_ smbios_bboard_flag_name uint_t
SMB_BIOSFL_ smbios_bios_flag_name uint64_t
SMB_BIOSXB1_ smbios_bios_xb1_name uint_t
SMB_BIOSXB2_ smbios_bios_xb2_name uint_t
SMB_CAT_ smbios_cache_ctype_name uint_t
SMB_CAF_ smbios_cache_flag_name uint_t
SMB_EVFL_ smbios_evlog_flag_name uint_t
SMB_IPMI_F_ smbios_ipmi_flag_name uint_t
SMB_POWERSUP_F_ smbios_powersup_flag_name uint_t
SMB_MOMC_ smbios_memdevice_op_capab_name uint_t
SMB_MDF_ smbios_memdevice_flag_name uint_t
SMB_PRC_ smbios_processor_core_flag_name uint_t
SMB_RV_ISA_ smbios_riscv_isa_name uint64_t
SMB_RV_PRIV_ smbios_riscv_priv_name uint_t
SMB_TYPE_ smbios_type_name uint_t
SMB_SLCH1_ smbios_slot_ch1_name uint_t
SMB_SLCH2_ smbios_slot_ch2_name uint_t
'
desc_funcs='
SMB_BBFL_ smbios_bboard_flag_desc uint_t
SMB_BBT_ smbios_bboard_type_desc uint_t
SMB_BDC_ smbios_battery_chem_desc uint_t
SMB_BIOSFL_ smbios_bios_flag_desc uint64_t
SMB_BIOSXB1_ smbios_bios_xb1_desc uint_t
SMB_BIOSXB2_ smbios_bios_xb2_desc uint_t
SMB_BOOT_ smbios_boot_desc uint_t
SMB_CAA_ smbios_cache_assoc_desc uint_t
SMB_CAT_ smbios_cache_ctype_desc uint_t
SMB_CAE_ smbios_cache_ecc_desc uint_t
SMB_CAF_ smbios_cache_flag_desc uint_t
SMB_CAL_ smbios_cache_loc_desc uint_t
SMB_CAG_ smbios_cache_logical_desc uint_t
SMB_CAM_ smbios_cache_mode_desc uint_t
SMB_CHST_ smbios_chassis_state_desc uint_t
SMB_CHT_ smbios_chassis_type_desc uint_t
SMB_COOLDEV_S_ smbios_cooldev_status_desc uint_t
SMB_COOLDEV_T_ smbios_cooldev_type_desc uint_t
SMB_EVFL_ smbios_evlog_flag_desc uint_t
SMB_EVHF_ smbios_evlog_format_desc uint_t
SMB_EVM_ smbios_evlog_method_desc uint_t
SMB_HWSEC_PS_ smbios_hwsec_desc uint_t
SMB_IPMI_F_ smbios_ipmi_flag_desc uint_t
SMB_IPMI_T_ smbios_ipmi_type_desc uint_t
SMB_IPROBE_L_ smbios_iprobe_loc_desc uint_t
SMB_IPROBE_S_ smbios_iprobe_status_desc uint_t
SMB_POWERSUP_F_ smbios_powersup_flag_desc uint_t
SMB_POWERSUP_I_ smbios_powersup_input_desc uint_t
SMB_POWERSUP_S_ smbios_powersup_status_desc uint_t
SMB_POWERSUP_T_ smbios_powersup_type_desc uint_t
SMB_MAL_ smbios_memarray_loc_desc uint_t
SMB_MAU_ smbios_memarray_use_desc uint_t
SMB_MAE_ smbios_memarray_ecc_desc uint_t
SMB_MDF_ smbios_memdevice_flag_desc uint_t
SMB_MDFF_ smbios_memdevice_form_desc uint_t
SMB_MDT_ smbios_memdevice_type_desc uint_t
SMB_MDR_ smbios_memdevice_rank_desc uint_t
SMB_MTECH_ smbios_memdevice_memtech_desc uint_t
SMB_MOMC_ smbios_memdevice_op_capab_desc uint_t
SMB_OBT_ smbios_onboard_type_desc uint_t
SMB_PDI_ smbios_pointdev_iface_desc uint_t
SMB_PDT_ smbios_pointdev_type_desc uint_t
SMB_POC_ smbios_port_conn_desc uint_t
SMB_POT_ smbios_port_type_desc uint_t
SMB_PRC_ smbios_processor_core_flag_desc uint_t
SMB_PRF_ smbios_processor_family_desc uint_t
SMB_PROCINFO_T smbios_processor_info_type_desc uint_t
SMB_PRS_ smbios_processor_status_desc uint_t
SMB_PRT_ smbios_processor_type_desc uint_t
SMB_PRU_ smbios_processor_upgrade_desc uint_t
SMB_RV_ISA_ smbios_riscv_isa_desc uint64_t
SMB_RV_PRIV_ smbios_riscv_priv_desc uint_t
SMB_RV_WIDTH_ smbios_riscv_width_desc uint_t
SMB_SLCH1_ smbios_slot_ch1_desc uint_t
SMB_SLCH2_ smbios_slot_ch2_desc uint_t
SMB_SLL_ smbios_slot_length_desc uint_t
SMB_SLT_ smbios_slot_type_desc uint_t
SMB_SLU_ smbios_slot_usage_desc uint_t
SMB_SLW_ smbios_slot_width_desc uint_t
SMB_TPROBE_L_ smbios_tprobe_loc_desc uint_t
SMB_TPROBE_S_ smbios_tprobe_status_desc uint_t
SMB_TYPE_ smbios_type_desc uint_t
SMB_VPROBE_L_ smbios_vprobe_loc_desc uint_t
SMB_VPROBE_S_ smbios_vprobe_status_desc uint_t
SMB_WAKEUP_ smbios_system_wakeup_desc uint_t
'
if [ $# -ne 1 ]; then
echo "Usage: $0 file.h > file.c" >&2
exit 2
fi
echo "\
/*\n\
* Copyright 2015 OmniTI Computer Consulting, Inc. All rights reserved.\n\
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.\n\
* Use is subject to license terms.\n\
*/\n\
\n\
#include <smbios.h>"
echo "$name_funcs" | while read p name type; do
[ -z "$p" ] && continue
pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*[A-Z0-9]*.*$"
replace=' case \1: return ("\1");'
echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
sed -n "s@$pattern@$replace@p" < $1 || exit 1
echo "\t}\n\treturn (NULL);\n}"
done
#
# Generate the description functions based on the comment next to a #define.
# The transformations for descriptive comments are slightly more complicated
# than those used for the identifier->name functions above:
#
# (1) strip any [RO] suffix from the comment (a header file convention)
# (2) replace any " with \" so it is escaped for the final output string
# (3) replace return (...); with return ("..."); to finish the code
#
echo "$desc_funcs" | while read p name type; do
[ -z "$p" ] && continue
pattern="^#define[ ]\($p[A-Za-z0-9_]*\)[ ]*.*/\\* \(.*\) \\*/$"
replace=' case \1: return (\2);'
echo "\nconst char *\n$name($type x)\n{\n\tswitch (x) {"
sed -n "s@$pattern@$replace@p" < $1 | sed 's/ ([RO]))/)/' | \
sed 's/"/\\"/g' | sed 's/(/("/;s/);$/");/' || exit 1
echo "\t}\n\treturn (NULL);\n}"
done
exit 0
|