makesyscalls.sh revision 1.94.2.1 1 #! /bin/sh -
2 # $NetBSD: makesyscalls.sh,v 1.94.2.1 2010/05/30 05:17:57 rmind 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 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
244 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
245
246 printf " * created from%s\n */\n\n", $0 > sysarghdr
247 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
248 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
249
250 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
251 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
252 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
253 printf "#ifdef _KERNEL\n" > rumpcallshdr
254 printf "#error Interface not supported inside kernel\n" > rumpcallshdr
255 printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
256 printf "#include <sys/types.h>\n" > rumpcallshdr
257 printf "#include <sys/select.h>\n\n" > rumpcallshdr
258 printf "#include <signal.h>\n\n" > rumpcallshdr
259
260 printf "%s", sysarghdrextra > sysarghdr
261 # Write max number of system call arguments to both headers
262 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
263 > sysnumhdr
264 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
265 > sysarghdr
266 printf "#undef\tsyscallarg\n" > sysarghdr
267 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
268 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
269 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
270 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
271 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
272 > sysarghdr
273 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
274 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
275 registertype > sysarghdr
276 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
277 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
278 registertype > sysarghdr
279 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
280 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
281 printf "\t}\n" > sysarghdr
282 printf("\n#undef check_syscall_args\n") >sysarghdr
283 printf("#define check_syscall_args(call) \\\n" \
284 "\ttypedef char call##_check_args" \
285 "[sizeof (struct call##_args) \\\n" \
286 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
287 constprefix, registertype) >sysarghdr
288 next
289 }
290 NF == 0 || $1 ~ /^;/ {
291 next
292 }
293 $0 ~ /^%%$/ {
294 intable = 1
295 next
296 }
297 $1 ~ /^#[ ]*include/ {
298 print > sysdcl
299 print > sysnames
300 next
301 }
302 $1 ~ /^#/ && !intable {
303 print > sysdcl
304 print > sysnames
305 next
306 }
307 $1 ~ /^#/ && intable {
308 if ($1 ~ /^#[ ]*if/) {
309 savedepth++
310 savesyscall[savedepth] = syscall
311 }
312 if ($1 ~ /^#[ ]*else/) {
313 if (savedepth <= 0) {
314 printf("%s: line %d: unbalanced #else\n", \
315 infile, NR)
316 exit 1
317 }
318 syscall = savesyscall[savedepth]
319 }
320 if ($1 ~ /^#[ ]*endif/) {
321 if (savedepth <= 0) {
322 printf("%s: line %d: unbalanced #endif\n", \
323 infile, NR)
324 exit 1
325 }
326 savedepth--
327 }
328 print > sysent
329 print > sysarghdr
330 print > sysnumhdr
331 print > sysprotos
332 print > sysnamesbottom
333
334 # XXX: technically we do not want to have conditionals in rump,
335 # but it is easier to just let the cpp handle them than try to
336 # figure out what we want here in this script
337 print > rumpsysent
338 next
339 }
340 syscall != $1 {
341 printf "%s: line %d: syscall number out of sync at %d\n", \
342 infile, NR, syscall
343 printf "line is:\n"
344 print
345 exit 1
346 }
347 function parserr(was, wanted) {
348 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
349 infile, NR, was, wanted
350 printf "line is:\n"
351 print
352 exit 1
353 }
354 function parseline() {
355 f=3 # toss number and type
356 if ($2 == "INDIR")
357 sycall_flags="SYCALL_INDIRECT"
358 else
359 sycall_flags="0"
360 if ($NF != "}") {
361 funcalias=$NF
362 end=NF-1
363 } else {
364 funcalias=""
365 end=NF
366 }
367 if ($f == "INDIR") { # allow for "NOARG INDIR"
368 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
369 f++
370 }
371 if ($f == "MODULAR") { # registered at runtime
372 modular = 1
373 f++
374 } else {
375 modular = 0;
376 }
377 if ($f == "RUMP") {
378 rumpable = 1
379 f++
380 } else {
381 rumpable = 0
382 }
383 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
384 funcalias=$f
385 f++
386 }
387 if ($f != "{")
388 parserr($f, "{")
389 f++
390 if ($end != "}")
391 parserr($end, "}")
392 end--
393 if ($end != ";")
394 parserr($end, ";")
395 end--
396 if ($end != ")")
397 parserr($end, ")")
398 end--
399
400 returntype = oldf = "";
401 do {
402 if (returntype != "" && oldf != "*")
403 returntype = returntype" ";
404 returntype = returntype$f;
405 oldf = $f;
406 f++
407 } while ($f != "|" && f < (end-1))
408 if (f == (end - 1)) {
409 parserr($f, "function argument definition (maybe \"|\"?)");
410 }
411 f++
412
413 fprefix=$f
414 f++
415 if ($f != "|") {
416 parserr($f, "function compat delimiter (maybe \"|\"?)");
417 }
418 f++
419
420 fcompat=""
421 if ($f != "|") {
422 fcompat=$f
423 f++
424 }
425
426 if ($f != "|") {
427 parserr($f, "function name delimiter (maybe \"|\"?)");
428 }
429 f++
430 fbase=$f
431
432 # pipe is special in how to returns its values.
433 # So just generate it manually if present.
434 if (rumpable == 1 && fbase == "pipe") {
435 rumpable = 0;
436 rumphaspipe = 1;
437 }
438
439 funcstdname=fprefix "_" fbase
440 if (fcompat != "") {
441 funcname=fprefix "___" fbase "" fcompat
442 wantrename=1
443 } else {
444 funcname=funcstdname
445 wantrename=0
446 }
447 if (returntype == "quad_t" || returntype == "off_t") {
448 if (sycall_flags == "0")
449 sycall_flags = "SYCALL_RET_64";
450 else
451 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
452 }
453
454 if (funcalias == "") {
455 funcalias=funcname
456 sub(/^([^_]+_)*sys_/, "", funcalias)
457 }
458 f++
459
460 if ($f != "(")
461 parserr($f, "(")
462 f++
463
464 argc=0;
465 argalign=0;
466 if (f == end) {
467 if ($f != "void")
468 parserr($f, "argument definition")
469 isvarargs = 0;
470 varargc = 0;
471 argtype[0]="void";
472 return
473 }
474
475 # some system calls (open() and fcntl()) can accept a variable
476 # number of arguments. If syscalls accept a variable number of
477 # arguments, they must still have arguments specified for
478 # the remaining argument "positions," because of the way the
479 # kernel system call argument handling works.
480 #
481 # Indirect system calls, e.g. syscall(), are exceptions to this
482 # rule, since they are handled entirely by machine-dependent code
483 # and do not need argument structures built.
484
485 isvarargs = 0;
486 args64 = 0;
487 while (f <= end) {
488 if ($f == "...") {
489 f++;
490 isvarargs = 1;
491 varargc = argc;
492 continue;
493 }
494 argc++
495 argtype[argc]=""
496 oldf=""
497 while (f < end && $(f+1) != ",") {
498 if (argtype[argc] != "" && oldf != "*")
499 argtype[argc] = argtype[argc]" ";
500 argtype[argc] = argtype[argc]$f;
501 oldf = $f;
502 f++
503 }
504 if (argtype[argc] == "")
505 parserr($f, "argument definition")
506 if (argtype[argc] == "off_t" \
507 || argtype[argc] == "dev_t" \
508 || argtype[argc] == "time_t") {
509 if ((argalign % 2) != 0 && sysalign &&
510 funcname != "sys_posix_fadvise") # XXX for now
511 parserr($f, "a padding argument")
512 } else {
513 argalign++;
514 }
515 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
516 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
517 if (sycall_flags == "0")
518 sycall_flags = "SYCALL_ARG"argc-1"_64";
519 else
520 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
521 args64++;
522 }
523 argname[argc]=$f;
524 f += 2; # skip name, and any comma
525 }
526 if (args64 > 0)
527 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
528 # must see another argument after varargs notice.
529 if (isvarargs) {
530 if (argc == varargc)
531 parserr($f, "argument definition")
532 } else
533 varargc = argc;
534 }
535
536 function printproto(wrap) {
537 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
538 returntype) > sysnumhdr
539 for (i = 1; i <= varargc; i++)
540 printf(" \"%s\"", argtype[i]) > sysnumhdr
541 if (isvarargs)
542 printf(" \"...\"") > sysnumhdr
543 printf(" */\n") > sysnumhdr
544 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
545 syscall) > sysnumhdr
546
547 # rumpalooza
548 if (!rumpable)
549 return
550
551 printf("%s rump_%s(", returntype, funcstdname) > rumpcallshdr
552 for (i = 1; i < varargc; i++)
553 if (argname[i] != "PAD")
554 printf("%s, ", argtype[i]) > rumpcallshdr
555 if (isvarargs)
556 printf("%s, ...)", argtype[varargc]) > rumpcallshdr
557 else
558 printf("%s)", argtype[argc]) > rumpcallshdr
559 if (wantrename)
560 printf(" __RENAME(rump_%s)", funcname) > rumpcallshdr
561 printf(";\n") > rumpcallshdr
562 }
563
564 function printrumpsysent(insysent, compatwrap) {
565 if (!insysent) {
566 eno[0] = "rump_enosys"
567 eno[1] = "sys_nomodule"
568 printf("\t{ 0, 0, 0,\n\t (sy_call_t *)%s },\t\t\t" \
569 "/* %d = unrumped */\n", \
570 eno[modular], syscall) > rumpsysent
571 return
572 }
573
574 printf("\t{ ") > rumpsysent
575 if (argc == 0) {
576 printf("0, 0, ") > rumpsysent
577 } else {
578 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > rumpsysent
579 }
580 printf("0,\n\t %s },", wfn) > rumpsysent
581 for (i = 0; i < (41 - length(wfn)) / 8; i++)
582 printf("\t") > rumpsysent
583 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
584 }
585
586 function putent(type, compatwrap) {
587 # output syscall declaration for switch table.
588 if (compatwrap == "")
589 compatwrap_ = ""
590 else
591 compatwrap_ = compatwrap "_"
592 if (argc == 0)
593 arg_type = "void";
594 else {
595 arg_type = "struct " compatwrap_ funcname "_args";
596 }
597 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
598 arg_type " *, register_t *);\n"
599 if (sysmap[proto] != 1) {
600 sysmap[proto] = 1;
601 print proto > sysprotos;
602 }
603
604 # output syscall switch entry
605 printf("\t{ ") > sysent
606 if (argc == 0) {
607 printf("0, 0, ") > sysent
608 } else {
609 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
610 }
611 if (modular)
612 wfn = "(sy_call_t *)sys_nomodule";
613 else if (compatwrap == "")
614 wfn = "(sy_call_t *)" funcname;
615 else
616 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
617 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
618 for (i = 0; i < (33 - length(wfn)) / 8; i++)
619 printf("\t") > sysent
620 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
621
622 # output syscall name for names table
623 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
624 > sysnamesbottom
625
626 # output syscall number of header, if appropriate
627 if (type == "STD" || type == "NOARGS" || type == "INDIR") {
628 # output a prototype, to be used to generate lint stubs in
629 # libc.
630 printproto("")
631 } else if (type == "COMPAT") {
632 # Just define the syscall number with a comment. These
633 # may be used by compatibility stubs in libc.
634 printproto(compatwrap_)
635 }
636
637 # output syscall argument structure, if it has arguments
638 if (argc != 0) {
639 printf("\nstruct %s%s_args", compatwrap_, funcname) > sysarghdr
640 if (type != "NOARGS") {
641 print " {" >sysarghdr;
642 for (i = 1; i <= argc; i++)
643 printf("\tsyscallarg(%s) %s;\n", argtype[i],
644 argname[i]) > sysarghdr
645 printf "}" >sysarghdr;
646 }
647 printf(";\n") > sysarghdr
648 if (type != "NOARGS" && type != "INDIR") {
649 printf("check_syscall_args(%s%s)\n", compatwrap_,
650 funcname) >sysarghdr
651 }
652 }
653
654 if (!rumpable) {
655 if (funcname == "sys_pipe" && rumphaspipe == 1)
656 insysent = 1
657 else
658 insysent = 0
659 } else {
660 insysent = 1
661 }
662 printrumpsysent(insysent, compatwrap)
663
664 # output rump marshalling code if necessary
665 if (!rumpable) {
666 return
667 }
668
669 # need a local prototype, we export the re-re-named one in .h
670 printf("\n%s rump_%s(", returntype, funcname) > rumpcalls
671 for (i = 1; i < argc; i++) {
672 if (argname[i] != "PAD")
673 printf("%s, ", argtype[i]) > rumpcalls
674 }
675 printf("%s);", argtype[argc]) > rumpcalls
676
677 printf("\n%s\nrump_%s(", returntype, funcname) > rumpcalls
678 for (i = 1; i < argc; i++) {
679 if (argname[i] != "PAD")
680 printf("%s %s, ", argtype[i], argname[i]) > rumpcalls
681 }
682 printf("%s %s)\n", argtype[argc], argname[argc]) > rumpcalls
683 printf("{\n\tregister_t rval[2] = {0, 0};\n\tint error = 0;\n") \
684 > rumpcalls
685
686 argarg = "NULL"
687 argsize = 0;
688 if (argc) {
689 argarg = "&callarg"
690 argsize = "sizeof(callarg)"
691 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
692 > rumpcalls
693 for (i = 1; i <= argc; i++) {
694 if (argname[i] == "PAD") {
695 printf("\tSPARG(&callarg, %s) = 0;\n", \
696 argname[i]) > rumpcalls
697 } else {
698 printf("\tSPARG(&callarg, %s) = %s;\n", \
699 argname[i], argname[i]) > rumpcalls
700 }
701 }
702 printf("\n") > rumpcalls
703 } else {
704 printf("\n") > rumpcalls
705 }
706 printf("\terror = rump_sysproxy(%s%s, rump_sysproxy_arg,\n\t" \
707 " (uint8_t *)%s, %s, rval);\n", constprefix, funcalias, \
708 argarg, argsize) > rumpcalls
709 printf("\tif (error) {\n\t\trval[0] = -1;\n") > rumpcalls
710 if (returntype != "void") {
711 printf("\t\trumpuser_seterrno(error);\n\t}\n") > rumpcalls
712 printf("\treturn rval[0];\n") > rumpcalls
713 } else {
714 printf("\t}\n") > rumpcalls
715 }
716 printf("}\n") > rumpcalls
717 printf("__weak_alias(%s,rump_enosys);\n", funcname) > rumpcalls
718
719 }
720 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" {
721 parseline()
722 putent($2, "")
723 syscall++
724 next
725 }
726 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
727 if ($2 == "OBSOL")
728 comment="obsolete"
729 else if ($2 == "EXCL")
730 comment="excluded"
731 else if ($2 == "IGNORED")
732 comment="ignored"
733 else
734 comment="unimplemented"
735 for (i = 3; i <= NF; i++)
736 comment=comment " " $i
737
738 if ($2 == "IGNORED")
739 sys_stub = "(sy_call_t *)nullop";
740 else
741 sys_stub = sys_nosys;
742
743 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
744 sys_stub, syscall, comment) > sysent
745 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
746 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
747 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
748 > sysnamesbottom
749 if ($2 != "UNIMPL")
750 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
751 syscall++
752 next
753 }
754 {
755 for (i = 1; i <= ncompat; i++) {
756 if ($2 == compat_upper[i]) {
757 parseline();
758 putent("COMPAT", compat[i])
759 syscall++
760 next
761 }
762 }
763 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
764 exit 1
765 }
766 END {
767 # output pipe() syscall with its special rval[2] handling
768 if (rumphaspipe) {
769 printf("int rump_sys_pipe(int *);\n") > rumpcallshdr
770 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
771 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
772 printf("\tregister_t rval[2] = {0, 0};\n") > rumpcalls
773 printf("\tint error = 0;\n") > rumpcalls
774 printf("\n\terror = rump_sysproxy(SYS_pipe, ") > rumpcalls
775 printf("rump_sysproxy_arg, NULL, 0, rval);\n") > rumpcalls
776 printf("\tif (error) {\n") > rumpcalls
777 printf("\t\trumpuser_seterrno(error);\n") > rumpcalls
778 printf("\t} else {\n\t\tfd[0] = rval[0];\n") > rumpcalls
779 printf("\t\tfd[1] = rval[1];\n\t}\n") > rumpcalls
780 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
781 }
782
783 maxsyscall = syscall
784 if (nsysent) {
785 if (syscall > nsysent) {
786 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
787 exit 1
788 }
789 while (syscall < nsysent) {
790 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
791 sys_nosys, syscall) > sysent
792 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
793 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
794 syscall++
795 }
796 }
797 printf("};\n") > sysent
798 printf("};\n") > rumpsysent
799 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
800 printf("};\n") > sysnamesbottom
801 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
802 if (nsysent)
803 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
804 } '
805
806 cat $sysprotos >> $sysarghdr
807 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
808 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
809 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpcallshdr
810 cat $sysdcl $sysent > $syssw
811 cat $sysnamesbottom >> $sysnames
812 cat $rumpsysent >> $rumpcalls
813
814 #chmod 444 $sysnames $sysnumhdr $syssw
815