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