makesyscalls.sh revision 1.93.2.1 1 #! /bin/sh -
2 # $NetBSD: makesyscalls.sh,v 1.93.2.1 2010/04/30 14:44:11 uebayasi 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 eno[0] = "rump_enosys"
565 eno[1] = "sys_nomodule"
566 printf("\t{ 0, 0, 0,\n\t (sy_call_t *)%s },\t\t\t" \
567 "/* %d = unrumped */\n", \
568 eno[modular], syscall) > rumpsysent
569 return
570 }
571
572 printf("\t{ ") > rumpsysent
573 if (argc == 0) {
574 printf("0, 0, ") > rumpsysent
575 } else {
576 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > rumpsysent
577 }
578 printf("0,\n\t %s },", wfn) > rumpsysent
579 for (i = 0; i < (41 - length(wfn)) / 8; i++)
580 printf("\t") > rumpsysent
581 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
582 }
583
584 function putent(type, compatwrap) {
585 # output syscall declaration for switch table.
586 if (compatwrap == "")
587 compatwrap_ = ""
588 else
589 compatwrap_ = compatwrap "_"
590 if (argc == 0)
591 arg_type = "void";
592 else {
593 arg_type = "struct " compatwrap_ funcname "_args";
594 }
595 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
596 arg_type " *, register_t *);\n"
597 if (sysmap[proto] != 1) {
598 sysmap[proto] = 1;
599 print proto > sysprotos;
600 }
601
602 # output syscall switch entry
603 printf("\t{ ") > sysent
604 if (argc == 0) {
605 printf("0, 0, ") > sysent
606 } else {
607 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
608 }
609 if (modular)
610 wfn = "(sy_call_t *)sys_nomodule";
611 else if (compatwrap == "")
612 wfn = "(sy_call_t *)" funcname;
613 else
614 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
615 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
616 for (i = 0; i < (33 - length(wfn)) / 8; i++)
617 printf("\t") > sysent
618 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
619
620 # output syscall name for names table
621 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
622 > sysnamesbottom
623
624 # output syscall number of header, if appropriate
625 if (type == "STD" || type == "NOARGS" || type == "INDIR") {
626 # output a prototype, to be used to generate lint stubs in
627 # libc.
628 printproto("")
629 } else if (type == "COMPAT") {
630 # Just define the syscall number with a comment. These
631 # may be used by compatibility stubs in libc.
632 printproto(compatwrap_)
633 }
634
635 # output syscall argument structure, if it has arguments
636 if (argc != 0) {
637 printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
638 if (type != "NOARGS") {
639 print " {" >sysarghdr;
640 for (i = 1; i <= argc; i++)
641 printf("\tsyscallarg(%s) %s;\n", argtype[i],
642 argname[i]) > sysarghdr
643 printf "}" >sysarghdr;
644 }
645 printf(";\n") > sysarghdr
646 if (type != "NOARGS" && type != "INDIR") {
647 printf("check_syscall_args(%s%s)\n", compatwrap_,
648 funcname) >sysarghdr
649 }
650 }
651
652 if (!rumpable) {
653 if (funcname == "sys_pipe" && rumphaspipe == 1)
654 insysent = 1
655 else
656 insysent = 0
657 } else {
658 insysent = 1
659 }
660 printrumpsysent(insysent, compatwrap)
661
662 # output rump marshalling code if necessary
663 if (!rumpable) {
664 return
665 }
666
667 # need a local prototype, we export the re-re-named one in .h
668 printf("\n%s rump_%s(", returntype, funcname) > rumpcalls
669 for (i = 1; i < argc; i++) {
670 if (argname[i] != "PAD")
671 printf("%s, ", argtype[i]) > rumpcalls
672 }
673 printf("%s);", argtype[argc]) > rumpcalls
674
675 printf("\n%s\nrump_%s(", returntype, funcname) > rumpcalls
676 for (i = 1; i < argc; i++) {
677 if (argname[i] != "PAD")
678 printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
679 }
680 printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
681 printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
682 > rumpcalls
683
684 argarg = "NULL"
685 argsize = 0;
686 if (argc) {
687 argarg = "&callarg"
688 argsize = "sizeof(callarg)"
689 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
690 > rumpcalls
691 for (i = 1; i <= argc; i++) {
692 if (argname[i] == "PAD") {
693 printf("\tSPARG(&callarg, %s) = 0;\n", \
694 argname[i]) > rumpcalls
695 } else {
696 printf("\tSPARG(&callarg, %s) = %s;\n", \
697 argname[i], argname[i]) > rumpcalls
698 }
699 }
700 printf("\n") > rumpcalls
701 } else {
702 printf("\n") > rumpcalls
703 }
704 printf("\terror = rump_sysproxy(%s%s, rump_sysproxy_arg,\n\t" \
705 " (uint8_t *)%s, %s, rval);\n", constprefix, funcalias, \
706 argarg, argsize) > rumpcalls
707 printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
708 if (returntype != "void") {
709 printf("\t\trumpuser_seterrno(error);\n\t}\n") > rumpcalls
710 printf("\treturn rval[0];\n") > rumpcalls
711 } else {
712 printf("\t}\n") > rumpcalls
713 }
714 printf("}\n") > rumpcalls
715 printf("__weak_alias(%s,rump_enosys);\n", funcname) > rumpcalls
716
717 }
718 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
719 parseline()
720 putent($2, "")
721 syscall++
722 next
723 }
724 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
725 if ($2 == "OBSOL")
726 comment="obsolete"
727 else if ($2 == "EXCL")
728 comment="excluded"
729 else if ($2 == "IGNORED")
730 comment="ignored"
731 else
732 comment="unimplemented"
733 for (i = 3; i <= NF; i++)
734 comment=comment " " $i
735
736 if ($2 == "IGNORED")
737 sys_stub = "(sy_call_t *)nullop";
738 else
739 sys_stub = sys_nosys;
740
741 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
742 sys_stub, syscall, comment) > sysent
743 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
744 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
745 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
746 > sysnamesbottom
747 if ($2 != "UNIMPL")
748 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
749 syscall++
750 next
751 }
752 {
753 for (i = 1; i <= ncompat; i++) {
754 if ($2 == compat_upper[i]) {
755 parseline();
756 putent("COMPAT", compat[i])
757 syscall++
758 next
759 }
760 }
761 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
762 exit 1
763 }
764 END {
765 # output pipe() syscall with its special rval[2] handling
766 if (rumphaspipe) {
767 printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
768 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
769 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
770 printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
771 printf("\tint error = 0;\n") > rumpcalls
772 printf("\n\terror = rump_sysproxy(SYS_pipe, ") > rumpcalls
773 printf("rump_sysproxy_arg, NULL, 0, rval);\n") > rumpcalls
774 printf("\tif (error) {\n") > rumpcalls
775 printf("\t\trumpuser_seterrno(error);\n") > rumpcalls
776 printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
777 printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
778 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
779 }
780
781 maxsyscall = syscall
782 if (nsysent) {
783 if (syscall > nsysent) {
784 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
785 exit 1
786 }
787 while (syscall < nsysent) {
788 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
789 sys_nosys, syscall) > sysent
790 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
791 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
792 syscall++
793 }
794 }
795 printf("};\n") > sysent
796 printf("};\n") > rumpsysent
797 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
798 printf("};\n") > sysnamesbottom
799 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
800 if (nsysent)
801 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
802 } '
803
804 cat $sysprotos >> $sysarghdr
805 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
806 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
807 cat $sysdcl $sysent > $syssw
808 cat $sysnamesbottom >> $sysnames
809 cat $rumpsysent >> $rumpcalls
810
811 #chmod 444 $sysnames $sysnumhdr $syssw
812