makesyscalls.sh revision 1.108.2.1 1 #! /bin/sh -
2 # $NetBSD: makesyscalls.sh,v 1.108.2.1 2011/06/06 09:09:33 jruoho Exp $
3 #
4 # Copyright (c) 1994, 1996, 2000 Christopher G. Demetriou
5 # All rights reserved.
6 #
7 # Redistribution and use in source and binary forms, with or without
8 # modification, are permitted provided that the following conditions
9 # are met:
10 # 1. Redistributions of source code must retain the above copyright
11 # notice, this list of conditions and the following disclaimer.
12 # 2. Redistributions in binary form must reproduce the above copyright
13 # notice, this list of conditions and the following disclaimer in the
14 # documentation and/or other materials provided with the distribution.
15 # 3. All advertising materials mentioning features or use of this software
16 # must display the following acknowledgement:
17 # This product includes software developed for the NetBSD Project
18 # by Christopher G. Demetriou.
19 # 4. The name of the author may not be used to endorse or promote products
20 # derived from this software without specific prior written permission
21 #
22 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
23 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
26 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
27 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
31 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32
33 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
34
35 set -e
36
37 case $# in
38 2) ;;
39 *) echo "Usage: $0 config-file input-file" 1>&2
40 exit 1
41 ;;
42 esac
43
44 # the config file sets the following variables:
45 # sysalign check for alignment of off_t
46 # sysnames the syscall names file
47 # sysnumhdr the syscall numbers file
48 # syssw the syscall switch file
49 # sysarghdr the syscall argument struct definitions
50 # compatopts those syscall types that are for 'compat' syscalls
51 # switchname the name for the 'struct sysent' we define
52 # namesname the name for the 'const char *[]' we define
53 # constprefix the prefix for the system call constants
54 # registertype the type for register_t
55 # nsysent the size of the sysent table
56 # sys_nosys [optional] name of function called for unsupported
57 # syscalls, if not sys_nosys()
58 # maxsysargs [optiona] the maximum number or arguments
59 #
60 # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'SYSLIBCOMPAT'.
61
62 # source the config file.
63 sys_nosys="sys_nosys" # default is sys_nosys(), if not specified otherwise
64 maxsysargs=8 # default limit is 8 (32bit) arguments
65 rumpcalls="/dev/null"
66 rumpcallshdr="/dev/null"
67 rumpsysent="rumpsysent.tmp"
68 . ./$1
69
70 # tmp files:
71 sysdcl="sysent.dcl"
72 sysprotos="sys.protos"
73 syscompat_pref="sysent."
74 sysent="sysent.switch"
75 sysnamesbottom="sysnames.bottom"
76 rumptypes="rumphdr.types"
77 rumpprotos="rumphdr.protos"
78
79 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent $rumptypes $rumpprotos" 0
80
81 # Awk program (must support nawk extensions)
82 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
83 awk=${AWK:-awk}
84
85 # Does this awk have a "toupper" function?
86 have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
87
88 # If this awk does not define "toupper" then define our own.
89 if [ "$have_toupper" = TRUE ] ; then
90 # Used awk (GNU awk or nawk) provides it
91 toupper=
92 else
93 # Provide our own toupper()
94 toupper='
95 function toupper(str) {
96 _toupper_cmd = "echo "str" |tr a-z A-Z"
97 _toupper_cmd | getline _toupper_str;
98 close(_toupper_cmd);
99 return _toupper_str;
100 }'
101 fi
102
103 # before handing it off to awk, make a few adjustments:
104 # (1) insert spaces around {, }, (, ), *, and commas.
105 # (2) get rid of any and all dollar signs (so that rcs id use safe)
106 #
107 # The awk script will deal with blank lines and lines that
108 # start with the comment character (';').
109
110 sed -e '
111 s/\$//g
112 :join
113 /\\$/{a\
114
115 N
116 s/\\\n//
117 b join
118 }
119 2,${
120 /^#/!s/\([{}()*,|]\)/ \1 /g
121 }
122 ' < $2 | $awk "
123 $toupper
124 BEGIN {
125 # Create a NetBSD tag that does not get expanded when checking
126 # this script out of CVS. (This part of the awk script is in a
127 # shell double-quoted string, so the backslashes are eaten by
128 # the shell.)
129 tag = \"\$\" \"NetBSD\" \"\$\"
130
131 # to allow nested #if/#else/#endif sets
132 savedepth = 0
133 # to track already processed syscalls
134
135 sysnames = \"$sysnames\"
136 sysprotos = \"$sysprotos\"
137 sysnumhdr = \"$sysnumhdr\"
138 sysarghdr = \"$sysarghdr\"
139 sysarghdrextra = \"$sysarghdrextra\"
140 rumpcalls = \"$rumpcalls\"
141 rumpcallshdr = \"$rumpcallshdr\"
142 rumpsysent = \"$rumpsysent\"
143 switchname = \"$switchname\"
144 namesname = \"$namesname\"
145 constprefix = \"$constprefix\"
146 registertype = \"$registertype\"
147 sysalign=\"$sysalign\"
148 if (!registertype) {
149 registertype = \"register_t\"
150 }
151 nsysent = \"$nsysent\"
152
153 sysdcl = \"$sysdcl\"
154 syscompat_pref = \"$syscompat_pref\"
155 sysent = \"$sysent\"
156 sysnamesbottom = \"$sysnamesbottom\"
157 rumpprotos = \"$rumpprotos\"
158 rumptypes = \"$rumptypes\"
159 sys_nosys = \"$sys_nosys\"
160 maxsysargs = \"$maxsysargs\"
161 infile = \"$2\"
162
163 compatopts = \"$compatopts\"
164 "'
165
166 printf "/* %s */\n\n", tag > sysdcl
167 printf "/*\n * System call switch table.\n *\n" > sysdcl
168 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
169
170 ncompat = split(compatopts,compat)
171 for (i = 1; i <= ncompat; i++) {
172 compat_upper[i] = toupper(compat[i])
173
174 printf "\n#ifdef %s\n", compat_upper[i] > sysent
175 printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
176 compat[i] > sysent
177 printf "#else\n" > sysent
178 printf "#define %s(func) %s\n", compat[i], sys_nosys > sysent
179 printf "#endif\n" > sysent
180 }
181
182 printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
183 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
184 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
185 printf "struct sysent %s[] = {\n",switchname > sysent
186
187 printf "/* %s */\n\n", tag > sysnames
188 printf "/*\n * System call names.\n *\n" > sysnames
189 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
190
191 printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
192
193 printf "/* %s */\n\n", tag > sysnumhdr
194 printf "/*\n * System call numbers.\n *\n" > sysnumhdr
195 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
196
197 printf "/* %s */\n\n", tag > sysarghdr
198 printf "/*\n * System call argument lists.\n *\n" > sysarghdr
199 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
200
201 printf "/* %s */\n\n", tag > rumpcalls
202 printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
203 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
204
205 printf "/* %s */\n\n", tag > rumpcallshdr
206 printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
207 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
208 }
209 NR == 1 {
210 sub(/ $/, "")
211 printf " * created from%s\n */\n\n", $0 > sysdcl
212 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
213
214 printf " * created from%s\n */\n\n", $0 > sysnames
215 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
216
217 printf " * created from%s\n */\n\n", $0 > rumpcalls
218 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
219
220 printf "#include <sys/param.h>\n" > rumpcalls
221 printf "#include <sys/fstypes.h>\n" > rumpcalls
222 printf "#include <sys/proc.h>\n" > rumpcalls
223 printf "#ifdef RUMP_CLIENT\n" > rumpcalls
224 printf "#include <srcsys/syscall.h>\n" > rumpcalls
225 printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
226 printf "#include <errno.h>\n" > rumpcalls
227 printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
228 printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
229 printf " rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
230 printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
231 printf "#define rsys_alias(a,b)\n#else\n" > rumpcalls
232 printf "#include <sys/syscall.h>\n" > rumpcalls
233 printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
234 printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
235 printf "#include <rump/rumpuser.h>\n" > rumpcalls
236 printf "#include \"rump_private.h\"\n\n" > rumpcalls
237 printf "static int\nrsys_syscall" > rumpcalls
238 printf "(int num, void *data, size_t dlen, register_t *retval)" > rumpcalls
239 printf "\n{\n\tstruct sysent *callp = rump_sysent + num;\n" > rumpcalls
240 printf "\tint rv;\n" > rumpcalls
241 printf "\n\tKASSERT(num > 0 && num < SYS_NSYSENT);\n\n" > rumpcalls
242 printf "\trump_schedule();\n" > rumpcalls
243 printf "\trv = sy_call(callp, curlwp, data, retval);\n" > rumpcalls
244 printf "\trump_unschedule();\n\n\treturn rv;\n}\n\n" > rumpcalls
245 printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" > rumpcalls
246 printf "#define rsys_alias(a,b) __weak_alias(a,b);\n#endif\n\n" > rumpcalls
247
248 printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
249 printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
250 printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
251 printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
252 printf "#endif\n\n" > rumpcalls
253 printf "#ifndef RUMP_CLIENT\n" > rumpcalls
254 printf "int rump_enosys(void);\n" > rumpcalls
255 printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
256 printf "#endif\n" > rumpcalls
257
258 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
259 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
260 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
261 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
262 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
263
264 # System call names are included by userland (kdump(1)), so
265 # hide the include files from it.
266 printf "#if defined(_KERNEL_OPT)\n" > sysnames
267
268 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
269 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
270
271 printf " * created from%s\n */\n\n", $0 > sysnumhdr
272 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
273 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
274
275 printf " * created from%s\n */\n\n", $0 > sysarghdr
276 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
277 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
278
279 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
280 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
281 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
282 printf "#ifdef _KERNEL\n" > rumpcallshdr
283 printf "#error Interface not supported inside kernel\n" > rumpcallshdr
284 printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
285 printf "#include <sys/types.h> /* typedefs */\n" > rumpcallshdr
286 printf "#include <sys/select.h> /* typedefs */\n\n" > rumpcallshdr
287 printf "#include <signal.h> /* typedefs */\n\n" > rumpcallshdr
288 printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
289
290 printf "%s", sysarghdrextra > sysarghdr
291 # Write max number of system call arguments to both headers
292 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
293 > sysnumhdr
294 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
295 > sysarghdr
296 printf "#undef\tsyscallarg\n" > sysarghdr
297 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
298 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
299 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
300 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
301 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
302 > sysarghdr
303 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
304 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
305 registertype > sysarghdr
306 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
307 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
308 registertype > sysarghdr
309 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
310 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
311 printf "\t}\n" > sysarghdr
312 printf("\n#undef check_syscall_args\n") >sysarghdr
313 printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
314 "\ttypedef char call##_check_args" \
315 "[sizeof (struct call##_args) \\\n" \
316 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
317 constprefix, registertype) >sysarghdr
318
319 # compat types from syscalls.master. this is slightly ugly,
320 # but given that we have so few compats from over 17 years,
321 # a more complicated solution is not currently warranted.
322 uncompattypes["struct timeval50"] = "struct timeval";
323 uncompattypes["struct timespec50"] = "struct timespec";
324 uncompattypes["struct stat30"] = "struct stat";
325
326 next
327 }
328 NF == 0 || $1 ~ /^;/ {
329 next
330 }
331 $0 ~ /^%%$/ {
332 intable = 1
333 next
334 }
335 $1 ~ /^#[ ]*include/ {
336 print > sysdcl
337 print > sysnames
338 next
339 }
340 $1 ~ /^#/ && !intable {
341 print > sysdcl
342 print > sysnames
343 next
344 }
345 $1 ~ /^#/ && intable {
346 if ($1 ~ /^#[ ]*if/) {
347 savedepth++
348 savesyscall[savedepth] = syscall
349 }
350 if ($1 ~ /^#[ ]*else/) {
351 if (savedepth <= 0) {
352 printf("%s: line %d: unbalanced #else\n", \
353 infile, NR)
354 exit 1
355 }
356 syscall = savesyscall[savedepth]
357 }
358 if ($1 ~ /^#[ ]*endif/) {
359 if (savedepth <= 0) {
360 printf("%s: line %d: unbalanced #endif\n", \
361 infile, NR)
362 exit 1
363 }
364 savedepth--
365 }
366 print > sysent
367 print > sysarghdr
368 print > sysnumhdr
369 print > sysprotos
370 print > sysnamesbottom
371
372 # XXX: technically we do not want to have conditionals in rump,
373 # but it is easier to just let the cpp handle them than try to
374 # figure out what we want here in this script
375 print > rumpsysent
376 next
377 }
378 syscall != $1 {
379 printf "%s: line %d: syscall number out of sync at %d\n", \
380 infile, NR, syscall
381 printf "line is:\n"
382 print
383 exit 1
384 }
385 function parserr(was, wanted) {
386 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
387 infile, NR, was, wanted
388 printf "line is:\n"
389 print
390 exit 1
391 }
392 function parseline() {
393 f=3 # toss number and type
394 if ($2 == "INDIR")
395 sycall_flags="SYCALL_INDIRECT"
396 else
397 sycall_flags="0"
398 if ($NF != "}") {
399 funcalias=$NF
400 end=NF-1
401 } else {
402 funcalias=""
403 end=NF
404 }
405 if ($f == "INDIR") { # allow for "NOARG INDIR"
406 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
407 f++
408 }
409 if ($f == "MODULAR") { # registered at runtime
410 modular = 1
411 f++
412 } else {
413 modular = 0;
414 }
415 if ($f == "RUMP") {
416 rumpable = 1
417 f++
418 } else {
419 rumpable = 0
420 }
421 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
422 funcalias=$f
423 f++
424 }
425 if ($f != "{")
426 parserr($f, "{")
427 f++
428 if ($end != "}")
429 parserr($end, "}")
430 end--
431 if ($end != ";")
432 parserr($end, ";")
433 end--
434 if ($end != ")")
435 parserr($end, ")")
436 end--
437
438 returntype = oldf = "";
439 do {
440 if (returntype != "" && oldf != "*")
441 returntype = returntype" ";
442 returntype = returntype$f;
443 oldf = $f;
444 f++
445 } while ($f != "|" && f < (end-1))
446 if (f == (end - 1)) {
447 parserr($f, "function argument definition (maybe \"|\"?)");
448 }
449 f++
450
451 fprefix=$f
452 f++
453 if ($f != "|") {
454 parserr($f, "function compat delimiter (maybe \"|\"?)");
455 }
456 f++
457
458 fcompat=""
459 if ($f != "|") {
460 fcompat=$f
461 f++
462 }
463
464 if ($f != "|") {
465 parserr($f, "function name delimiter (maybe \"|\"?)");
466 }
467 f++
468 fbase=$f
469
470 # pipe is special in how to returns its values.
471 # So just generate it manually if present.
472 if (rumpable == 1 && fbase == "pipe") {
473 rumpable = 0;
474 rumphaspipe = 1;
475 }
476
477 if (fcompat != "") {
478 funcname=fprefix "___" fbase "" fcompat
479 } else {
480 funcname=fprefix "_" fbase
481 }
482 if (returntype == "quad_t" || returntype == "off_t") {
483 if (sycall_flags == "0")
484 sycall_flags = "SYCALL_RET_64";
485 else
486 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
487 }
488
489 if (funcalias == "") {
490 funcalias=funcname
491 sub(/^([^_]+_)*sys_/, "", funcalias)
492 realname=fbase
493 } else {
494 realname=funcalias
495 }
496 rumpfname=realname "" fcompat
497 f++
498
499 if ($f != "(")
500 parserr($f, "(")
501 f++
502
503 argc=0;
504 argalign=0;
505 if (f == end) {
506 if ($f != "void")
507 parserr($f, "argument definition")
508 isvarargs = 0;
509 varargc = 0;
510 argtype[0]="void";
511 return
512 }
513
514 # some system calls (open() and fcntl()) can accept a variable
515 # number of arguments. If syscalls accept a variable number of
516 # arguments, they must still have arguments specified for
517 # the remaining argument "positions," because of the way the
518 # kernel system call argument handling works.
519 #
520 # Indirect system calls, e.g. syscall(), are exceptions to this
521 # rule, since they are handled entirely by machine-dependent code
522 # and do not need argument structures built.
523
524 isvarargs = 0;
525 args64 = 0;
526 while (f <= end) {
527 if ($f == "...") {
528 f++;
529 isvarargs = 1;
530 varargc = argc;
531 continue;
532 }
533 argc++
534 argtype[argc]=""
535 oldf=""
536 while (f < end && $(f+1) != ",") {
537 if (argtype[argc] != "" && oldf != "*")
538 argtype[argc] = argtype[argc]" ";
539 argtype[argc] = argtype[argc]$f;
540 oldf = $f;
541 f++
542 }
543 if (argtype[argc] == "")
544 parserr($f, "argument definition")
545 if (argtype[argc] == "off_t" \
546 || argtype[argc] == "dev_t" \
547 || argtype[argc] == "time_t") {
548 if ((argalign % 2) != 0 && sysalign &&
549 funcname != "sys_posix_fadvise") # XXX for now
550 parserr($f, "a padding argument")
551 } else {
552 argalign++;
553 }
554 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
555 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
556 if (sycall_flags == "0")
557 sycall_flags = "SYCALL_ARG"argc-1"_64";
558 else
559 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
560 args64++;
561 }
562 argname[argc]=$f;
563 f += 2; # skip name, and any comma
564 }
565 if (args64 > 0)
566 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
567 # must see another argument after varargs notice.
568 if (isvarargs) {
569 if (argc == varargc)
570 parserr($f, "argument definition")
571 } else
572 varargc = argc;
573 }
574
575 function printproto(wrap) {
576 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
577 returntype) > sysnumhdr
578 for (i = 1; i <= varargc; i++)
579 printf(" \"%s\"", argtype[i]) > sysnumhdr
580 if (isvarargs)
581 printf(" \"...\"") > sysnumhdr
582 printf(" */\n") > sysnumhdr
583 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
584 syscall) > sysnumhdr
585
586 # rumpalooza
587 if (!rumpable)
588 return
589
590 # accumulate fbases we have seen. we want the last
591 # occurence for the default __RENAME()
592 seen = funcseen[fbase]
593 funcseen[fbase] = rumpfname
594 if (seen)
595 return
596
597 printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
598
599 for (i = 1; i < varargc; i++)
600 if (argname[i] != "PAD")
601 printf("%s, ", uncompattype(argtype[i])) > rumpprotos
602
603 if (isvarargs)
604 printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
605 else
606 printf("%s)", uncompattype(argtype[argc])) > rumpprotos
607
608 printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(fbase))> rumpprotos
609 printf(";\n") > rumpprotos
610
611 # generate forward-declares for types, apart from the
612 # braindead typedef jungle we cannot easily handle here
613 for (i = 1; i <= varargc; i++) {
614 type=uncompattype(argtype[i])
615 sub("const ", "", type)
616 if (!typeseen[type] && \
617 match(type, "struct") && match(type, "\\*")) {
618 typeseen[type] = 1
619 sub(" *\\*", "", type);
620 printf("%s;\n", type) > rumptypes
621 }
622 }
623 }
624
625 function printrumpsysent(insysent, compatwrap) {
626 if (!insysent) {
627 eno[0] = "rump_enosys"
628 eno[1] = "sys_nomodule"
629 flags[0] = "SYCALL_NOSYS"
630 flags[1] = "0"
631 printf("\t{ 0, 0, %s,\n\t (sy_call_t *)%s }, \t" \
632 "/* %d = %s */\n", \
633 flags[modular], eno[modular], syscall, funcalias) \
634 > rumpsysent
635 return
636 }
637
638 printf("\t{ ") > rumpsysent
639 if (argc == 0) {
640 printf("0, 0, ") > rumpsysent
641 } else {
642 printf("ns(struct %ssys_%s_args), ", compatwrap_, funcalias) > rumpsysent
643 }
644
645 if (compatwrap == "") {
646 if (modular)
647 rfn = "(sy_call_t *)sys_nomodule"
648 else
649 rfn = "(sy_call_t *)" funcname
650 } else {
651 rfn = "(sy_call_t *)" compatwrap "_" funcname
652 }
653
654 printf("0,\n\t %s },", rfn) > rumpsysent
655 for (i = 0; i < (33 - length(rfn)) / 8; i++)
656 printf("\t") > rumpsysent
657 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
658 }
659
660 function iscompattype(type) {
661 for (var in uncompattypes) {
662 if (match(type, var)) {
663 return 1
664 }
665 }
666
667 return 0
668 }
669
670 function uncompattype(type) {
671 for (var in uncompattypes) {
672 if (match(type, var)) {
673 sub(var, uncompattypes[var], type)
674 return type
675 }
676 }
677
678 return type
679 }
680
681 function putent(type, compatwrap) {
682 # output syscall declaration for switch table.
683 if (compatwrap == "")
684 compatwrap_ = ""
685 else
686 compatwrap_ = compatwrap "_"
687 if (argc == 0)
688 arg_type = "void";
689 else {
690 arg_type = "struct " compatwrap_ funcname "_args";
691 }
692 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
693 arg_type " *, register_t *);\n"
694 if (sysmap[proto] != 1) {
695 sysmap[proto] = 1;
696 print proto > sysprotos;
697 }
698
699 # output syscall switch entry
700 printf("\t{ ") > sysent
701 if (argc == 0) {
702 printf("0, 0, ") > sysent
703 } else {
704 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
705 }
706 if (modular)
707 wfn = "(sy_call_t *)sys_nomodule";
708 else if (compatwrap == "")
709 wfn = "(sy_call_t *)" funcname;
710 else
711 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
712 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
713 for (i = 0; i < (33 - length(wfn)) / 8; i++)
714 printf("\t") > sysent
715 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
716
717 # output syscall name for names table
718 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
719 > sysnamesbottom
720
721 # output syscall number of header, if appropriate
722 if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
723 type == "NOERR") {
724 # output a prototype, to be used to generate lint stubs in
725 # libc.
726 printproto("")
727 } else if (type == "COMPAT") {
728 # Just define the syscall number with a comment. These
729 # may be used by compatibility stubs in libc.
730 printproto(compatwrap_)
731 }
732
733 # output syscall argument structure, if it has arguments
734 if (argc != 0) {
735 printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
736 if (type != "NOARGS") {
737 print " {" >sysarghdr;
738 for (i = 1; i <= argc; i++)
739 printf("\tsyscallarg(%s) %s;\n", argtype[i],
740 argname[i]) > sysarghdr
741 printf "}" >sysarghdr;
742 }
743 printf(";\n") > sysarghdr
744 if (type != "NOARGS" && type != "INDIR") {
745 printf("check_syscall_args(%s%s)\n", compatwrap_,
746 funcname) >sysarghdr
747 }
748 }
749
750 if (!rumpable) {
751 if (funcname == "sys_pipe" && rumphaspipe == 1)
752 insysent = 1
753 else
754 insysent = 0
755 } else {
756 insysent = 1
757 }
758 printrumpsysent(insysent, compatwrap)
759
760 # output rump marshalling code if necessary
761 if (!rumpable) {
762 return
763 }
764
765 # need a local prototype, we export the re-re-named one in .h
766 printf("\n%s rump___sysimpl_%s(", returntype, rumpfname) \
767 > rumpcalls
768 for (i = 1; i < argc; i++) {
769 if (argname[i] != "PAD")
770 printf("%s, ", uncompattype(argtype[i])) > rumpcalls
771 }
772 printf("%s);", uncompattype(argtype[argc])) > rumpcalls
773
774 printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
775 for (i = 1; i < argc; i++) {
776 if (argname[i] != "PAD")
777 printf("%s %s, ", uncompattype(argtype[i]), \
778 argname[i]) > rumpcalls
779 }
780 printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
781 > rumpcalls
782 printf("{\n\tregister_t retval[2] = {0, 0};\n") > rumpcalls
783 if (returntype != "void") {
784 if (type != "NOERR") {
785 printf("\tint error = 0;\n") > rumpcalls
786 }
787 # assume rumpcalls return only integral types
788 printf("\t%s rv = -1;\n", returntype) > rumpcalls
789 }
790
791 argarg = "NULL"
792 argsize = 0;
793 if (argc) {
794 argarg = "&callarg"
795 argsize = "sizeof(callarg)"
796 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
797 > rumpcalls
798 for (i = 1; i <= argc; i++) {
799 if (argname[i] == "PAD") {
800 printf("\tSPARG(&callarg, %s) = 0;\n", \
801 argname[i]) > rumpcalls
802 } else {
803 if (iscompattype(argtype[i])) {
804 printf("\tSPARG(&callarg, %s) = " \
805 "(%s)%s;\n", argname[i], argtype[i], \
806 argname[i]) > rumpcalls
807 } else {
808 printf("\tSPARG(&callarg, %s) = %s;\n",\
809 argname[i], argname[i]) > rumpcalls
810 }
811 }
812 }
813 printf("\n") > rumpcalls
814 } else {
815 printf("\n") > rumpcalls
816 }
817 printf("\t") > rumpcalls
818 if (returntype != "void" && type != "NOERR")
819 printf("error = ") > rumpcalls
820 printf("rsys_syscall(%s%s%s, " \
821 "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
822 argarg, argsize) > rumpcalls
823 if (type != "NOERR") {
824 printf("\trsys_seterrno(error);\n") > rumpcalls
825 printf("\tif (error == 0) {\n") > rumpcalls
826 indent="\t\t"
827 ending="\t}\n"
828 } else {
829 indent="\t"
830 ending=""
831 }
832 if (returntype != "void") {
833 printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
834 indent, returntype) > rumpcalls
835 printf("%s\trv = *(%s *)retval;\n", \
836 indent, returntype) > rumpcalls
837 printf("%selse\n", indent, indent) > rumpcalls
838 printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
839 printf("%s", ending) > rumpcalls
840 printf("\treturn rv;\n") > rumpcalls
841 }
842 printf("}\n") > rumpcalls
843 printf("rsys_alias(%s%s,rump_enosys)\n", \
844 compatwrap_, funcname) > rumpcalls
845
846 }
847 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
848 || $2 == "NOERR" {
849 parseline()
850 putent($2, "")
851 syscall++
852 next
853 }
854 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
855 if ($2 == "OBSOL")
856 comment="obsolete"
857 else if ($2 == "EXCL")
858 comment="excluded"
859 else if ($2 == "IGNORED")
860 comment="ignored"
861 else
862 comment="unimplemented"
863 for (i = 3; i <= NF; i++)
864 comment=comment " " $i
865
866 if ($2 == "IGNORED")
867 sys_stub = "(sy_call_t *)nullop";
868 else
869 sys_stub = sys_nosys;
870
871 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
872 sys_stub, syscall, comment) > sysent
873 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = %s */\n", \
874 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
875 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
876 > sysnamesbottom
877 if ($2 != "UNIMPL")
878 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
879 syscall++
880 next
881 }
882 {
883 for (i = 1; i <= ncompat; i++) {
884 if ($2 == compat_upper[i]) {
885 parseline();
886 putent("COMPAT", compat[i])
887 syscall++
888 next
889 }
890 }
891 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
892 exit 1
893 }
894 END {
895 # output pipe() syscall with its special retval[2] handling
896 if (rumphaspipe) {
897 printf("int rump_sys_pipe(int *);\n") > rumpprotos
898 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
899 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
900 printf("\tregister_t retval[2] = {0, 0};\n") > rumpcalls
901 printf("\tint error = 0;\n") > rumpcalls
902 printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
903 printf("NULL, 0, retval);\n") > rumpcalls
904 printf("\tif (error) {\n") > rumpcalls
905 printf("\t\trsys_seterrno(error);\n") > rumpcalls
906 printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
907 printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
908 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
909 }
910
911 # print default rump syscall interfaces
912 for (var in funcseen) {
913 printf("#ifndef RUMP_SYS_RENAME_%s\n", \
914 toupper(var)) > rumpcallshdr
915 printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
916 toupper(var), funcseen[var]) > rumpcallshdr
917 printf("#endif\n\n") > rumpcallshdr
918 }
919
920 maxsyscall = syscall
921 if (nsysent) {
922 if (syscall > nsysent) {
923 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
924 exit 1
925 }
926 while (syscall < nsysent) {
927 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
928 sys_nosys, syscall) > sysent
929 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = filler */\n", \
930 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
931 printf("\t/* %3d */\t\"# filler\",\n", syscall) \
932 > sysnamesbottom
933 syscall++
934 }
935 }
936 printf("};\n") > sysent
937 printf("};\n") > rumpsysent
938 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
939 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
940 printf("};\n") > sysnamesbottom
941 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
942 if (nsysent)
943 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
944 } '
945
946 cat $sysprotos >> $sysarghdr
947 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
948 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
949 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
950 cat $sysdcl $sysent > $syssw
951 cat $sysnamesbottom >> $sysnames
952 cat $rumpsysent >> $rumpcalls
953
954 touch $rumptypes
955 cat $rumptypes >> $rumpcallshdr
956 echo >> $rumpcallshdr
957 cat $rumpprotos >> $rumpcallshdr
958
959 #chmod 444 $sysnames $sysnumhdr $syssw
960