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