makesyscalls.sh revision 1.69.2.3 1 #! /bin/sh -
2 # $NetBSD: makesyscalls.sh,v 1.69.2.3 2010/03/11 15:04:18 yamt 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
77 trap "rm $sysdcl $sysprotos $sysent $sysnamesbottom $rumpsysent" 0
78
79 # Awk program (must support nawk extensions)
80 # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
81 awk=${AWK:-awk}
82
83 # Does this awk have a "toupper" function?
84 have_toupper=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
85
86 # If this awk does not define "toupper" then define our own.
87 if [ "$have_toupper" = TRUE ] ; then
88 # Used awk (GNU awk or nawk) provides it
89 toupper=
90 else
91 # Provide our own toupper()
92 toupper='
93 function toupper(str) {
94 _toupper_cmd = "echo "str" |tr a-z A-Z"
95 _toupper_cmd | getline _toupper_str;
96 close(_toupper_cmd);
97 return _toupper_str;
98 }'
99 fi
100
101 # before handing it off to awk, make a few adjustments:
102 # (1) insert spaces around {, }, (, ), *, and commas.
103 # (2) get rid of any and all dollar signs (so that rcs id use safe)
104 #
105 # The awk script will deal with blank lines and lines that
106 # start with the comment character (';').
107
108 sed -e '
109 s/\$//g
110 :join
111 /\\$/{a\
112
113 N
114 s/\\\n//
115 b join
116 }
117 2,${
118 /^#/!s/\([{}()*,|]\)/ \1 /g
119 }
120 ' < $2 | $awk "
121 $toupper
122 BEGIN {
123 # Create a NetBSD tag that does not get expanded when checking
124 # this script out of CVS. (This part of the awk script is in a
125 # shell double-quoted string, so the backslashes are eaten by
126 # the shell.)
127 tag = \"\$\" \"NetBSD\" \"\$\"
128
129 # to allow nested #if/#else/#endif sets
130 savedepth = 0
131 # to track already processed syscalls
132
133 sysnames = \"$sysnames\"
134 sysprotos = \"$sysprotos\"
135 sysnumhdr = \"$sysnumhdr\"
136 sysarghdr = \"$sysarghdr\"
137 sysarghdrextra = \"$sysarghdrextra\"
138 rumpcalls = \"$rumpcalls\"
139 rumpcallshdr = \"$rumpcallshdr\"
140 rumpsysent = \"$rumpsysent\"
141 switchname = \"$switchname\"
142 namesname = \"$namesname\"
143 constprefix = \"$constprefix\"
144 registertype = \"$registertype\"
145 sysalign=\"$sysalign\"
146 if (!registertype) {
147 registertype = \"register_t\"
148 }
149 nsysent = \"$nsysent\"
150
151 sysdcl = \"$sysdcl\"
152 syscompat_pref = \"$syscompat_pref\"
153 sysent = \"$sysent\"
154 sysnamesbottom = \"$sysnamesbottom\"
155 sys_nosys = \"$sys_nosys\"
156 maxsysargs = \"$maxsysargs\"
157 infile = \"$2\"
158
159 compatopts = \"$compatopts\"
160 "'
161
162 printf "/* %s */\n\n", tag > sysdcl
163 printf "/*\n * System call switch table.\n *\n" > sysdcl
164 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
165
166 ncompat = split(compatopts,compat)
167 for (i = 1; i <= ncompat; i++) {
168 compat_upper[i] = toupper(compat[i])
169
170 printf "\n#ifdef %s\n", compat_upper[i] > sysent
171 printf "#define %s(func) __CONCAT(%s_,func)\n", compat[i], \
172 compat[i] > sysent
173 printf "#else\n" > sysent
174 printf "#define %s(func) %s\n", compat[i], sys_nosys > sysent
175 printf "#endif\n" > sysent
176 }
177
178 printf "\n#define\ts(type)\tsizeof(type)\n" > sysent
179 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > sysent
180 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > sysent
181 printf "struct sysent %s[] = {\n",switchname > sysent
182
183 printf "/* %s */\n\n", tag > sysnames
184 printf "/*\n * System call names.\n *\n" > sysnames
185 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
186
187 printf "\n/*\n * System call prototypes.\n */\n\n" > sysprotos
188
189 printf "/* %s */\n\n", tag > sysnumhdr
190 printf "/*\n * System call numbers.\n *\n" > sysnumhdr
191 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
192
193 printf "/* %s */\n\n", tag > sysarghdr
194 printf "/*\n * System call argument lists.\n *\n" > sysarghdr
195 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
196
197 printf "/* %s */\n\n", tag > rumpcalls
198 printf "/*\n * System call vector and marshalling for rump.\n *\n" > rumpcalls
199 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcalls
200
201 printf "/* %s */\n\n", tag > rumpcallshdr
202 printf "/*\n * System call protos in rump namespace.\n *\n" > rumpcallshdr
203 printf " * DO NOT EDIT-- this file is automatically generated.\n" > rumpcallshdr
204 }
205 NR == 1 {
206 sub(/ $/, "")
207 printf " * created from%s\n */\n\n", $0 > sysdcl
208 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysdcl
209
210 printf " * created from%s\n */\n\n", $0 > sysnames
211 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > sysnames
212
213 printf " * created from%s\n */\n\n", $0 > rumpcalls
214 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
215 printf "#include <sys/types.h>\n" > rumpcalls
216 printf "#include <sys/param.h>\n" > rumpcalls
217 printf "#include <sys/proc.h>\n" > rumpcalls
218 printf "#include <sys/syscall.h>\n" > rumpcalls
219 printf "#include <sys/syscallargs.h>\n" > rumpcalls
220 printf "#include <rump/rumpuser.h>\n" > rumpcalls
221 printf "#include \"rump_private.h\"\n\n" > rumpcalls
222 printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
223 printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
224 printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
225 printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
226 printf "#endif\n\n" > rumpcalls
227 printf "int rump_enosys(void);\n" > rumpcalls
228 printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
229
230 printf "\n#define\ts(type)\tsizeof(type)\n" > rumpsysent
231 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
232 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
233 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
234
235 # System call names are included by userland (kdump(1)), so
236 # hide the include files from it.
237 printf "#if defined(_KERNEL_OPT)\n" > sysnames
238
239 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
240 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
241
242 printf " * created from%s\n */\n\n", $0 > sysnumhdr
243
244 printf " * created from%s\n */\n\n", $0 > sysarghdr
245
246 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
247 printf "#ifdef _RUMPKERNEL\n" > rumpcallshdr
248 printf "#error Interface not supported inside rump kernel\n" > rumpcallshdr
249 printf "#endif /* _RUMPKERNEL */\n\n" > rumpcallshdr
250 printf "#include <sys/types.h>\n" > rumpcallshdr
251 printf "#include <sys/select.h>\n\n" > rumpcallshdr
252 printf "#include <signal.h>\n\n" > rumpcallshdr
253
254 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
255 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
256 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
257 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
258 printf "%s", sysarghdrextra > sysarghdr
259 # Write max number of system call arguments to both headers
260 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
261 > sysnumhdr
262 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
263 > sysarghdr
264 printf "#undef\tsyscallarg\n" > sysarghdr
265 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
266 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
267 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
268 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
269 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
270 > sysarghdr
271 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
272 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
273 registertype > sysarghdr
274 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
275 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
276 registertype > sysarghdr
277 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
278 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
279 printf "\t}\n" > sysarghdr
280 printf("\n#undef check_syscall_args\n") >sysarghdr
281 printf("#define check_syscall_args(call) \\\n" \
282 "\ttypedef char call##_check_args" \
283 "[sizeof (struct call##_args) \\\n" \
284 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
285 constprefix, registertype) >sysarghdr
286 next
287 }
288 NF == 0 || $1 ~ /^;/ {
289 next
290 }
291 $0 ~ /^%%$/ {
292 intable = 1
293 next
294 }
295 $1 ~ /^#[ ]*include/ {
296 print > sysdcl
297 print > sysnames
298 next
299 }
300 $1 ~ /^#/ && !intable {
301 print > sysdcl
302 print > sysnames
303 next
304 }
305 $1 ~ /^#/ && intable {
306 if ($1 ~ /^#[ ]*if/) {
307 savedepth++
308 savesyscall[savedepth] = syscall
309 }
310 if ($1 ~ /^#[ ]*else/) {
311 if (savedepth <= 0) {
312 printf("%s: line %d: unbalanced #else\n", \
313 infile, NR)
314 exit 1
315 }
316 syscall = savesyscall[savedepth]
317 }
318 if ($1 ~ /^#[ ]*endif/) {
319 if (savedepth <= 0) {
320 printf("%s: line %d: unbalanced #endif\n", \
321 infile, NR)
322 exit 1
323 }
324 savedepth--
325 }
326 print > sysent
327 print > sysarghdr
328 print > sysnumhdr
329 print > sysprotos
330 print > sysnamesbottom
331
332 # XXX: technically we do not want to have conditionals in rump,
333 # but it is easier to just let the cpp handle them than try to
334 # figure out what we want here in this script
335 print > rumpsysent
336 next
337 }
338 syscall != $1 {
339 printf "%s: line %d: syscall number out of sync at %d\n", \
340 infile, NR, syscall
341 printf "line is:\n"
342 print
343 exit 1
344 }
345 function parserr(was, wanted) {
346 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
347 infile, NR, was, wanted
348 printf "line is:\n"
349 print
350 exit 1
351 }
352 function parseline() {
353 f=3 # toss number and type
354 if ($2 == "INDIR")
355 sycall_flags="SYCALL_INDIRECT"
356 else
357 sycall_flags="0"
358 if ($NF != "}") {
359 funcalias=$NF
360 end=NF-1
361 } else {
362 funcalias=""
363 end=NF
364 }
365 if ($f == "INDIR") { # allow for "NOARG INDIR"
366 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
367 f++
368 }
369 if ($f == "MODULAR") { # registered at runtime
370 modular = 1
371 f++
372 } else {
373 modular = 0;
374 }
375 if ($f == "RUMP") {
376 rumpable = 1
377 f++
378 } else {
379 rumpable = 0
380 }
381 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
382 funcalias=$f
383 f++
384 }
385 if ($f != "{")
386 parserr($f, "{")
387 f++
388 if ($end != "}")
389 parserr($end, "}")
390 end--
391 if ($end != ";")
392 parserr($end, ";")
393 end--
394 if ($end != ")")
395 parserr($end, ")")
396 end--
397
398 returntype = oldf = "";
399 do {
400 if (returntype != "" && oldf != "*")
401 returntype = returntype" ";
402 returntype = returntype$f;
403 oldf = $f;
404 f++
405 } while ($f != "|" && f < (end-1))
406 if (f == (end - 1)) {
407 parserr($f, "function argument definition (maybe \"|\"?)");
408 }
409 f++
410
411 fprefix=$f
412 f++
413 if ($f != "|") {
414 parserr($f, "function compat delimiter (maybe \"|\"?)");
415 }
416 f++
417
418 fcompat=""
419 if ($f != "|") {
420 fcompat=$f
421 f++
422 }
423
424 if ($f != "|") {
425 parserr($f, "function name delimiter (maybe \"|\"?)");
426 }
427 f++
428 fbase=$f
429
430 # pipe is special in how to returns its values.
431 # So just generate it manually if present.
432 if (rumpable == 1 && fbase == "pipe") {
433 rumpable = 0;
434 rumphaspipe = 1;
435 }
436
437 funcstdname=fprefix "_" fbase
438 if (fcompat != "") {
439 funcname=fprefix "___" fbase "" fcompat
440 wantrename=1
441 } else {
442 funcname=funcstdname
443 wantrename=0
444 }
445 if (returntype == "quad_t" || returntype == "off_t") {
446 if (sycall_flags == "0")
447 sycall_flags = "SYCALL_RET_64";
448 else
449 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
450 }
451
452 if (funcalias == "") {
453 funcalias=funcname
454 sub(/^([^_]+_)*sys_/, "", funcalias)
455 }
456 f++
457
458 if ($f != "(")
459 parserr($f, "(")
460 f++
461
462 argc=0;
463 argalign=0;
464 if (f == end) {
465 if ($f != "void")
466 parserr($f, "argument definition")
467 isvarargs = 0;
468 varargc = 0;
469 argtype[0]="void";
470 return
471 }
472
473 # some system calls (open() and fcntl()) can accept a variable
474 # number of arguments. If syscalls accept a variable number of
475 # arguments, they must still have arguments specified for
476 # the remaining argument "positions," because of the way the
477 # kernel system call argument handling works.
478 #
479 # Indirect system calls, e.g. syscall(), are exceptions to this
480 # rule, since they are handled entirely by machine-dependent code
481 # and do not need argument structures built.
482
483 isvarargs = 0;
484 args64 = 0;
485 while (f <= end) {
486 if ($f == "...") {
487 f++;
488 isvarargs = 1;
489 varargc = argc;
490 continue;
491 }
492 argc++
493 argtype[argc]=""
494 oldf=""
495 while (f < end && $(f+1) != ",") {
496 if (argtype[argc] != "" && oldf != "*")
497 argtype[argc] = argtype[argc]" ";
498 argtype[argc] = argtype[argc]$f;
499 oldf = $f;
500 f++
501 }
502 if (argtype[argc] == "")
503 parserr($f, "argument definition")
504 if (argtype[argc] == "off_t" \
505 || argtype[argc] == "dev_t" \
506 || argtype[argc] == "time_t") {
507 if ((argalign % 2) != 0 && sysalign &&
508 funcname != "sys_posix_fadvise") # XXX for now
509 parserr($f, "a padding argument")
510 } else {
511 argalign++;
512 }
513 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
514 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
515 if (sycall_flags == "0")
516 sycall_flags = "SYCALL_ARG"argc-1"_64";
517 else
518 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
519 args64++;
520 }
521 argname[argc]=$f;
522 f += 2; # skip name, and any comma
523 }
524 if (args64 > 0)
525 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
526 # must see another argument after varargs notice.
527 if (isvarargs) {
528 if (argc == varargc)
529 parserr($f, "argument definition")
530 } else
531 varargc = argc;
532 }
533
534 function printproto(wrap) {
535 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
536 returntype) > sysnumhdr
537 for (i = 1; i <= varargc; i++)
538 printf(" \"%s\"", argtype[i]) > sysnumhdr
539 if (isvarargs)
540 printf(" \"...\"") > sysnumhdr
541 printf(" */\n") > sysnumhdr
542 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
543 syscall) > sysnumhdr
544
545 # rumpalooza
546 if (!rumpable)
547 return
548
549 printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
550 for (i = 1; i < varargc; i++)
551 if (argname[i] != "PAD")
552 printf("%s, ", argtype[i]) > rumpcallshdr
553 if (isvarargs)
554 printf("%s, ...)", argtype[varargc]) > rumpcallshdr
555 else
556 printf("%s)", argtype[argc]) > rumpcallshdr
557 if (wantrename)
558 printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
559 printf(";\n") > rumpcallshdr
560 }
561
562 function printrumpsysent(insysent, compatwrap) {
563 if (!insysent) {
564 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = unrumped */\n", \
565 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
566 return
567 }
568
569 printf("\t{ ") > rumpsysent
570 if (argc == 0) {
571 printf("0, 0, ") > rumpsysent
572 } else {
573 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > rumpsysent
574 }
575 printf("0,\n\t %s },", wfn) > rumpsysent
576 for (i = 0; i < (41 - length(wfn)) / 8; i++)
577 printf("\t") > rumpsysent
578 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
579 }
580
581 function putent(type, compatwrap) {
582 # output syscall declaration for switch table.
583 if (compatwrap == "")
584 compatwrap_ = ""
585 else
586 compatwrap_ = compatwrap "_"
587 if (argc == 0)
588 arg_type = "void";
589 else {
590 arg_type = "struct " compatwrap_ funcname "_args";
591 }
592 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
593 arg_type " *, register_t *);\n"
594 if (sysmap[proto] != 1) {
595 sysmap[proto] = 1;
596 print proto > sysprotos;
597 }
598
599 # output syscall switch entry
600 printf("\t{ ") > sysent
601 if (argc == 0) {
602 printf("0, 0, ") > sysent
603 } else {
604 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
605 }
606 if (modular)
607 wfn = "(sy_call_t *)sys_nomodule";
608 else if (compatwrap == "")
609 wfn = "(sy_call_t *)" funcname;
610 else
611 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
612 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
613 for (i = 0; i < (33 - length(wfn)) / 8; i++)
614 printf("\t") > sysent
615 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
616
617 # output syscall name for names table
618 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
619 > sysnamesbottom
620
621 # output syscall number of header, if appropriate
622 if (type == "STD" || type == "NOARGS" || type == "INDIR") {
623 # output a prototype, to be used to generate lint stubs in
624 # libc.
625 printproto("")
626 } else if (type == "COMPAT") {
627 # Just define the syscall number with a comment. These
628 # may be used by compatibility stubs in libc.
629 printproto(compatwrap_)
630 }
631
632 # output syscall argument structure, if it has arguments
633 if (argc != 0) {
634 printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
635 if (type != "NOARGS") {
636 print " {" >sysarghdr;
637 for (i = 1; i <= argc; i++)
638 printf("\tsyscallarg(%s) %s;\n", argtype[i],
639 argname[i]) > sysarghdr
640 printf "}" >sysarghdr;
641 }
642 printf(";\n") > sysarghdr
643 if (type != "NOARGS" && type != "INDIR") {
644 printf("check_syscall_args(%s%s)\n", compatwrap_,
645 funcname) >sysarghdr
646 }
647 }
648
649 if (!rumpable) {
650 if (funcname == "sys_pipe" && rumphaspipe == 1)
651 insysent = 1
652 else
653 insysent = 0
654 } else {
655 insysent = 1
656 }
657 printrumpsysent(insysent, compatwrap)
658
659 # output rump marshalling code if necessary
660 if (!rumpable) {
661 return
662 }
663
664 # need a local prototype, we export the re-re-named one in .h
665 printf("\n%s rump_%s(", returntype, funcname) > rumpcalls
666 for (i = 1; i < argc; i++) {
667 if (argname[i] != "PAD")
668 printf("%s, ", argtype[i]) > rumpcalls
669 }
670 printf("%s);", argtype[argc]) > rumpcalls
671
672 printf("\n%s\nrump_%s(", returntype, funcname) > rumpcalls
673 for (i = 1; i < argc; i++) {
674 if (argname[i] != "PAD")
675 printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
676 }
677 printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
678 printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
679 > rumpcalls
680
681 argarg = "NULL"
682 argsize = 0;
683 if (argc) {
684 argarg = "&callarg"
685 argsize = "sizeof(callarg)"
686 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
687 > rumpcalls
688 for (i = 1; i <= argc; i++) {
689 if (argname[i] == "PAD") {
690 printf("\tSPARG(&callarg, %s) = 0;\n", \
691 argname[i]) > rumpcalls
692 } else {
693 printf("\tSPARG(&callarg, %s) = %s;\n", \
694 argname[i], argname[i]) > rumpcalls
695 }
696 }
697 printf("\n") > rumpcalls
698 } else {
699 printf("\n") > rumpcalls
700 }
701 printf("\terror = rump_sysproxy(%s%s, rump_sysproxy_arg,\n\t" \
702 " (uint8_t *)%s, %s, rval);\n", constprefix, funcalias, \
703 argarg, argsize) > rumpcalls
704 printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
705 if (returntype != "void") {
706 printf("\t\trumpuser_seterrno(error);\n\t}\n") > rumpcalls
707 printf("\treturn rval[0];\n") > rumpcalls
708 } else {
709 printf("\t}\n") > rumpcalls
710 }
711 printf("}\n") > rumpcalls
712 printf("__weak_alias(%s,rump_enosys);\n", funcname) > rumpcalls
713
714 }
715 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
716 parseline()
717 putent($2, "")
718 syscall++
719 next
720 }
721 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
722 if ($2 == "OBSOL")
723 comment="obsolete"
724 else if ($2 == "EXCL")
725 comment="excluded"
726 else if ($2 == "IGNORED")
727 comment="ignored"
728 else
729 comment="unimplemented"
730 for (i = 3; i <= NF; i++)
731 comment=comment " " $i
732
733 if ($2 == "IGNORED")
734 sys_stub = "(sy_call_t *)nullop";
735 else
736 sys_stub = sys_nosys;
737
738 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
739 sys_stub, syscall, comment) > sysent
740 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
741 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
742 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
743 > sysnamesbottom
744 if ($2 != "UNIMPL")
745 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
746 syscall++
747 next
748 }
749 {
750 for (i = 1; i <= ncompat; i++) {
751 if ($2 == compat_upper[i]) {
752 parseline();
753 putent("COMPAT", compat[i])
754 syscall++
755 next
756 }
757 }
758 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
759 exit 1
760 }
761 END {
762 # output pipe() syscall with its special rval[2] handling
763 if (rumphaspipe) {
764 printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
765 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
766 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
767 printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
768 printf("\tint error = 0;\n") > rumpcalls
769 printf("\n\terror = rump_sysproxy(SYS_pipe, ") > rumpcalls
770 printf("rump_sysproxy_arg, NULL, 0, rval);\n") > rumpcalls
771 printf("\tif (error) {\n") > rumpcalls
772 printf("\t\trumpuser_seterrno(error);\n") > rumpcalls
773 printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
774 printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
775 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
776 }
777
778 maxsyscall = syscall
779 if (nsysent) {
780 if (syscall > nsysent) {
781 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
782 exit 1
783 }
784 while (syscall < nsysent) {
785 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
786 sys_nosys, syscall) > sysent
787 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
788 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
789 syscall++
790 }
791 }
792 printf("};\n") > sysent
793 printf("};\n") > rumpsysent
794 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
795 printf("};\n") > sysnamesbottom
796 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
797 if (nsysent)
798 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
799 } '
800
801 cat $sysprotos >> $sysarghdr
802 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
803 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
804 cat $sysdcl $sysent > $syssw
805 cat $sysnamesbottom >> $sysnames
806 cat $rumpsysent >> $rumpcalls
807
808 #chmod 444 $sysnames $sysnumhdr $syssw
809