makesyscalls.sh revision 1.13 1 1.1 glass #! /bin/sh -
2 1.9 cgd #
3 1.12 cgd # Copyright (c) 1994 Christopher G. Demetriou
4 1.12 cgd # All rights reserved.
5 1.12 cgd #
6 1.12 cgd # Redistribution and use in source and binary forms, with or without
7 1.12 cgd # modification, are permitted provided that the following conditions
8 1.12 cgd # are met:
9 1.12 cgd # 1. Redistributions of source code must retain the above copyright
10 1.12 cgd # notice, this list of conditions and the following disclaimer.
11 1.12 cgd # 2. Redistributions in binary form must reproduce the above copyright
12 1.12 cgd # notice, this list of conditions and the following disclaimer in the
13 1.12 cgd # documentation and/or other materials provided with the distribution.
14 1.12 cgd # 3. All advertising materials mentioning features or use of this software
15 1.12 cgd # must display the following acknowledgement:
16 1.12 cgd # This product includes software developed for the NetBSD Project
17 1.12 cgd # by Christopher G. Demetriou.
18 1.12 cgd # 4. The name of the author may not be used to endorse or promote products
19 1.12 cgd # derived from this software without specific prior written permission
20 1.12 cgd #
21 1.12 cgd # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
22 1.12 cgd # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
23 1.12 cgd # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
24 1.12 cgd # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
25 1.12 cgd # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
26 1.12 cgd # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27 1.12 cgd # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28 1.12 cgd # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29 1.12 cgd # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30 1.12 cgd # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 1.12 cgd #
32 1.12 cgd # from: @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
33 1.13 mycroft # $NetBSD: makesyscalls.sh,v 1.13 1994/10/20 23:22:38 mycroft Exp $
34 1.12 cgd #
35 1.1 glass
36 1.1 glass set -e
37 1.1 glass
38 1.11 cgd case $# in
39 1.11 cgd 2) ;;
40 1.11 cgd *) echo "Usage: $0 config-file input-file" 1>&2
41 1.11 cgd exit 1
42 1.11 cgd ;;
43 1.11 cgd esac
44 1.11 cgd
45 1.11 cgd # source the config file.
46 1.11 cgd . $1
47 1.11 cgd
48 1.11 cgd # the config file sets the following variables:
49 1.11 cgd # sysnames the syscall names file
50 1.11 cgd # sysnumhdr the syscall numbers file
51 1.11 cgd # syssw the syscall switch file
52 1.11 cgd # sysarghdr the syscall argument struct definitions
53 1.11 cgd # compatopts those syscall types that are for 'compat' syscalls
54 1.11 cgd # switchname the name for the 'struct sysent' we define
55 1.11 cgd # namesname the name for the 'char *[]' we define
56 1.11 cgd # constprefix the prefix for the system call constants
57 1.11 cgd #
58 1.11 cgd # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'LIBCOMPAT'.
59 1.1 glass
60 1.1 glass # tmp files:
61 1.1 glass sysdcl="sysent.dcl"
62 1.11 cgd syscompat_pref="sysent."
63 1.1 glass sysent="sysent.switch"
64 1.1 glass
65 1.11 cgd syscompat_files=""
66 1.11 cgd for file in $compatopts; do
67 1.11 cgd syscompat_files="$syscompat_files $syscompat_pref$file"
68 1.11 cgd done
69 1.11 cgd
70 1.11 cgd trap "rm $sysdcl $syscompat_files $sysent" 0
71 1.11 cgd
72 1.11 cgd # Awk program (must support nawk extensions)
73 1.11 cgd # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
74 1.11 cgd awk=${AWK:-awk}
75 1.11 cgd
76 1.11 cgd # Does this awk have a "toupper" function? (i.e. is it GNU awk)
77 1.11 cgd isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
78 1.11 cgd
79 1.11 cgd # If this awk does not define "toupper" then define our own.
80 1.11 cgd if [ "$isgawk" = TRUE ] ; then
81 1.11 cgd # GNU awk provides it.
82 1.11 cgd toupper=
83 1.11 cgd else
84 1.11 cgd # Provide our own toupper()
85 1.11 cgd toupper='
86 1.11 cgd function toupper(str) {
87 1.11 cgd _toupper_cmd = "echo "str" |tr a-z A-Z"
88 1.11 cgd _toupper_cmd | getline _toupper_str;
89 1.11 cgd close(_toupper_cmd);
90 1.11 cgd return _toupper_str;
91 1.11 cgd }'
92 1.11 cgd fi
93 1.11 cgd
94 1.11 cgd # before handing it off to awk, make a few adjustments:
95 1.11 cgd # (1) insert spaces around {, }, (, ), *, and commas.
96 1.11 cgd # (2) get rid of any and all dollar signs (so that rcs id use safe)
97 1.11 cgd #
98 1.11 cgd # The awk script will deal with blank lines and lines that
99 1.11 cgd # start with the comment character (';').
100 1.1 glass
101 1.11 cgd sed -e '
102 1.11 cgd s/\$//g
103 1.11 cgd :join
104 1.11 cgd /\\$/{a\
105 1.11 cgd
106 1.11 cgd N
107 1.11 cgd s/\\\n//
108 1.11 cgd b join
109 1.11 cgd }
110 1.11 cgd 2,${
111 1.11 cgd /^#/!s/\([{}()*,]\)/ \1 /g
112 1.11 cgd }
113 1.11 cgd ' < $2 | $awk "
114 1.11 cgd $toupper
115 1.11 cgd BEGIN {
116 1.11 cgd sysnames = \"$sysnames\"
117 1.11 cgd sysnumhdr = \"$sysnumhdr\"
118 1.11 cgd sysarghdr = \"$sysarghdr\"
119 1.11 cgd switchname = \"$switchname\"
120 1.11 cgd namesname = \"$namesname\"
121 1.11 cgd constprefix = \"$constprefix\"
122 1.11 cgd
123 1.11 cgd sysdcl = \"$sysdcl\"
124 1.11 cgd syscompat_pref = \"$syscompat_pref\"
125 1.11 cgd sysent = \"$sysent\"
126 1.11 cgd infile = \"$2\"
127 1.11 cgd
128 1.11 cgd compatopts = \"$compatopts\"
129 1.11 cgd "'
130 1.11 cgd
131 1.11 cgd printf "/*\n * System call switch table.\n *\n" > sysdcl
132 1.11 cgd printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
133 1.11 cgd
134 1.11 cgd ncompat = split(compatopts,compat)
135 1.11 cgd for (i = 1; i <= ncompat; i++) {
136 1.11 cgd compat_upper[i] = toupper(compat[i])
137 1.11 cgd compat_file[i] = sprintf("%s%s", syscompat_pref, compat[i])
138 1.11 cgd
139 1.11 cgd printf "\n#ifdef %s\n", compat_upper[i] > compat_file[i]
140 1.11 cgd printf "#define %s(func) __CONCAT(%s_,func)\n\n", \
141 1.11 cgd compat[i], compat[i] > compat_file[i]
142 1.11 cgd }
143 1.11 cgd
144 1.11 cgd printf "/*\n * System call names.\n *\n" > sysnames
145 1.11 cgd printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
146 1.11 cgd
147 1.11 cgd printf "/*\n * System call numbers.\n *\n" > sysnumhdr
148 1.11 cgd printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
149 1.11 cgd
150 1.13 mycroft printf "/*\n * System call argument lists.\n *\n" > sysarghdr
151 1.11 cgd printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
152 1.11 cgd }
153 1.11 cgd NR == 1 {
154 1.11 cgd printf " * created from%s\n */\n\n", $0 > sysdcl
155 1.11 cgd
156 1.11 cgd printf "#define\ts(type)\tsizeof(type)\n\n" > sysent
157 1.11 cgd printf "struct sysent %s[] = {\n",switchname > sysent
158 1.11 cgd
159 1.11 cgd printf " * created from%s\n */\n\n", $0 > sysnames
160 1.11 cgd printf "char *%s[] = {\n",namesname > sysnames
161 1.11 cgd
162 1.11 cgd printf " * created from%s\n */\n\n", $0 > sysnumhdr
163 1.11 cgd
164 1.11 cgd printf " * created from%s\n */\n\n", $0 > sysarghdr
165 1.11 cgd printf "#define\tsyscallarg(x)\tunion { x datum; register_t pad; }\n" \
166 1.11 cgd > sysarghdr
167 1.11 cgd next
168 1.11 cgd }
169 1.11 cgd NF == 0 || $1 ~ /^;/ {
170 1.11 cgd next
171 1.11 cgd }
172 1.11 cgd $1 ~ /^#[ ]*include/ {
173 1.11 cgd print > sysdcl
174 1.11 cgd next
175 1.11 cgd }
176 1.11 cgd $1 ~ /^#[ ]*if/ {
177 1.11 cgd print > sysent
178 1.11 cgd print > sysdcl
179 1.11 cgd for (i = 1; i <= ncompat; i++)
180 1.11 cgd print > compat_file[i]
181 1.11 cgd print > sysnames
182 1.11 cgd savesyscall = syscall
183 1.11 cgd next
184 1.11 cgd }
185 1.11 cgd $1 ~ /^#[ ]*else/ {
186 1.11 cgd print > sysent
187 1.11 cgd print > sysdcl
188 1.11 cgd for (i = 1; i <= ncompat; i++)
189 1.11 cgd print > compat_file[i]
190 1.11 cgd print > sysnames
191 1.11 cgd syscall = savesyscall
192 1.11 cgd next
193 1.11 cgd }
194 1.11 cgd $1 ~ /^#/ {
195 1.11 cgd print > sysent
196 1.11 cgd print > sysdcl
197 1.11 cgd for (i = 1; i <= ncompat; i++)
198 1.11 cgd print > compat_file[i]
199 1.11 cgd print > sysnames
200 1.11 cgd next
201 1.11 cgd }
202 1.11 cgd syscall != $1 {
203 1.11 cgd printf "%s: line %d: syscall number out of sync at %d\n", \
204 1.11 cgd infile, NR, syscall
205 1.11 cgd printf "line is:\n"
206 1.11 cgd print
207 1.11 cgd exit 1
208 1.11 cgd }
209 1.11 cgd function parserr(was, wanted) {
210 1.11 cgd printf "%s: line %d: unexpected %s (expected %s)\n", \
211 1.11 cgd infile, NR, was, wanted
212 1.11 cgd exit 1
213 1.11 cgd }
214 1.11 cgd function parseline() {
215 1.11 cgd f=3 # toss number and type
216 1.11 cgd if ($NF != "}") {
217 1.11 cgd funcalias=$NF
218 1.11 cgd end=NF-1
219 1.11 cgd } else {
220 1.11 cgd funcalias=""
221 1.11 cgd end=NF
222 1.11 cgd }
223 1.11 cgd if ($f != "{")
224 1.11 cgd parserr($f, "{")
225 1.11 cgd f++
226 1.11 cgd if ($end != "}")
227 1.11 cgd parserr($end, "}")
228 1.11 cgd end--
229 1.11 cgd if ($end != ";")
230 1.11 cgd parserr($end, ";")
231 1.11 cgd end--
232 1.11 cgd if ($end != ")")
233 1.11 cgd parserr($end, ")")
234 1.11 cgd end--
235 1.11 cgd
236 1.11 cgd f++ # toss return type
237 1.11 cgd
238 1.11 cgd funcname=$f
239 1.11 cgd if (funcalias == "")
240 1.11 cgd funcalias=funcname
241 1.11 cgd f++
242 1.11 cgd
243 1.11 cgd if ($f != "(")
244 1.11 cgd parserr($f, ")")
245 1.11 cgd f++
246 1.11 cgd
247 1.11 cgd argc= 0;
248 1.11 cgd if (f == end) {
249 1.11 cgd if ($f != "void")
250 1.11 cgd parserr($f, "argument definition")
251 1.11 cgd return
252 1.11 cgd }
253 1.11 cgd
254 1.11 cgd while (f <= end) {
255 1.11 cgd argc++
256 1.11 cgd argtype[argc]=""
257 1.11 cgd while (f < end && $(f+1) != ",") {
258 1.11 cgd if (argtype[argc] != "")
259 1.11 cgd argtype[argc] = argtype[argc]" ";
260 1.11 cgd argtype[argc] = argtype[argc]$f;
261 1.11 cgd f++
262 1.11 cgd }
263 1.11 cgd if (argtype[argc] == "")
264 1.11 cgd parserr($f, "argument definition")
265 1.11 cgd argname[argc]=$f;
266 1.11 cgd f += 2; # skip name, and any comma
267 1.11 cgd }
268 1.11 cgd }
269 1.11 cgd function putent(nodefs, declfile, compatwrap) {
270 1.11 cgd # output syscall declaration for switch table
271 1.11 cgd if (compatwrap == "")
272 1.11 cgd printf("int\t%s();\n", funcname) > declfile
273 1.11 cgd else
274 1.11 cgd printf("int\t%s(%s)();\n", compatwrap, funcname) > declfile
275 1.11 cgd
276 1.11 cgd # output syscall switch entry
277 1.11 cgd # printf("\t{ { %d", argc) > sysent
278 1.11 cgd # for (i = 1; i <= argc; i++) {
279 1.11 cgd # if (i == 5) # wrap the line
280 1.11 cgd # printf(",\n\t ") > sysent
281 1.11 cgd # else
282 1.11 cgd # printf(", ") > sysent
283 1.11 cgd # printf("s(%s)", argtypenospc[i]) > sysent
284 1.11 cgd # }
285 1.11 cgd printf("\t{ %d, ", argc) > sysent
286 1.11 cgd if (argc == 0)
287 1.11 cgd printf("0") > sysent
288 1.11 cgd else if (compatwrap == "")
289 1.11 cgd printf("s(struct %s_args)", funcname) > sysent
290 1.11 cgd else
291 1.11 cgd printf("s(struct %s_%s_args)", compatwrap, funcname) > sysent
292 1.11 cgd if (compatwrap == "")
293 1.11 cgd wfn = sprintf("%s", funcname);
294 1.11 cgd else
295 1.11 cgd wfn = sprintf("%s(%s)", compatwrap, funcname);
296 1.11 cgd printf(",\n\t %s },", wfn) > sysent
297 1.11 cgd for (i = 0; i < (33 - length(wfn)) / 8; i++)
298 1.11 cgd printf("\t") > sysent
299 1.11 cgd if (compatwrap == "")
300 1.11 cgd printf("/* %d = %s */\n", syscall, funcalias) > sysent
301 1.11 cgd else
302 1.11 cgd printf("/* %d = %s %s */\n", syscall, compatwrap,
303 1.11 cgd funcalias) > sysent
304 1.11 cgd
305 1.11 cgd # output syscall name for names table
306 1.11 cgd if (compatwrap == "")
307 1.11 cgd printf("\t\"%s\",\t\t\t/* %d = %s */\n", funcalias, syscall,
308 1.11 cgd funcalias) > sysnames
309 1.11 cgd else
310 1.11 cgd printf("\t\"%s_%s\",\t/* %d = %s %s */\n", compatwrap,
311 1.11 cgd funcalias, syscall, compatwrap, funcalias) > sysnames
312 1.11 cgd
313 1.11 cgd # output syscall number of header, if appropriate
314 1.11 cgd if (nodefs == "" || nodefs == "NOARGS")
315 1.11 cgd printf("#define\t%s%s\t%d\n", constprefix, funcalias,
316 1.11 cgd syscall) > sysnumhdr
317 1.11 cgd else if (nodefs != "NODEF")
318 1.11 cgd printf("\t\t\t\t/* %d is %s %s */\n", syscall,
319 1.11 cgd compatwrap, funcalias) > sysnumhdr
320 1.11 cgd
321 1.11 cgd # output syscall argument structure, if it has arguments
322 1.11 cgd if (argc != 0 && nodefs != "NOARGS") {
323 1.11 cgd if (compatwrap == "")
324 1.11 cgd printf("\nstruct %s_args {\n", funcname) > sysarghdr
325 1.11 cgd else
326 1.11 cgd printf("\nstruct %s_%s_args {\n", compatwrap,
327 1.11 cgd funcname) > sysarghdr
328 1.11 cgd for (i = 1; i <= argc; i++)
329 1.11 cgd printf("\tsyscallarg(%s) %s;\n", argtype[i],
330 1.11 cgd argname[i]) > sysarghdr
331 1.11 cgd printf("};\n") > sysarghdr
332 1.11 cgd }
333 1.11 cgd }
334 1.11 cgd $2 == "STD" {
335 1.11 cgd parseline()
336 1.11 cgd putent("", sysdcl, "")
337 1.11 cgd syscall++
338 1.11 cgd next
339 1.11 cgd }
340 1.11 cgd $2 == "NODEF" || $2 == "NOARGS" {
341 1.11 cgd parseline()
342 1.11 cgd putent($2, sysdcl, "")
343 1.11 cgd syscall++
344 1.11 cgd next
345 1.11 cgd }
346 1.11 cgd $2 == "OBSOL" || $2 == "UNIMPL" {
347 1.11 cgd if ($2 == "OBSOL")
348 1.11 cgd comment="obsolete"
349 1.11 cgd else
350 1.11 cgd comment="unimplemented"
351 1.11 cgd for (i = 3; i <= NF; i++)
352 1.11 cgd comment=comment " " $i
353 1.11 cgd
354 1.11 cgd printf("\t{ 0, 0,\n\t nosys },\t\t\t\t/* %d = %s */\n", \
355 1.11 cgd syscall, comment) > sysent
356 1.11 cgd printf("\t\"#%d (%s)\",\t\t/* %d = %s */\n", \
357 1.11 cgd syscall, comment, syscall, comment) > sysnames
358 1.11 cgd if ($2 != "UNIMPL")
359 1.11 cgd printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
360 1.11 cgd syscall++
361 1.11 cgd next
362 1.11 cgd }
363 1.11 cgd {
364 1.11 cgd for (i = 1; i <= ncompat; i++) {
365 1.11 cgd if ($2 == compat_upper[i]) {
366 1.11 cgd parseline();
367 1.11 cgd putent("COMMENT", compat_file[i], compat[i])
368 1.11 cgd syscall++
369 1.11 cgd next
370 1.11 cgd }
371 1.11 cgd }
372 1.11 cgd printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
373 1.1 glass exit 1
374 1.11 cgd }
375 1.11 cgd END {
376 1.11 cgd printf "\n#undef\tsyscallarg\n" > sysarghdr
377 1.11 cgd
378 1.11 cgd for (i = 1; i <= ncompat; i++) {
379 1.11 cgd printf("\n#else /* %s */\n", compat_upper[i]) > compat_file[i]
380 1.11 cgd printf("#define %s(func) nosys\n", compat[i]) > \
381 1.11 cgd compat_file[i]
382 1.11 cgd printf("#endif /* %s */\n\n", compat_upper[i]) > compat_file[i]
383 1.11 cgd }
384 1.11 cgd
385 1.11 cgd printf("};\n\n") > sysent
386 1.11 cgd printf("int\tn%s= sizeof(%s) / sizeof(%s[0]);\n", switchname,
387 1.11 cgd switchname, switchname) > sysent
388 1.1 glass
389 1.11 cgd printf("};\n") > sysnames
390 1.11 cgd } '
391 1.1 glass
392 1.11 cgd cat $sysdcl $syscompat_files $sysent > $syssw
393 1.1 glass
394 1.3 cgd #chmod 444 $sysnames $syshdr $syssw
395