makesyscalls.sh revision 1.119.2.3 1 # $NetBSD: makesyscalls.sh,v 1.119.2.3 2013/01/23 00:06:21 yamt 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 "#ifdef RUMP_CLIENT\n" > rumpcalls
223 printf "#include \"rumpuser_port.h\"\n" > rumpcalls
224 printf "#endif /* RUMP_CLIENT */\n\n" > rumpcalls
225 printf "#include <sys/param.h>\n\n" > rumpcalls
226 printf "#ifdef __NetBSD__\n" > rumpcalls
227 printf "#include <sys/cdefs.h>\n__KERNEL_RCSID(0, \"%s\");\n\n", tag > rumpcalls
228
229 printf "#include <sys/fstypes.h>\n" > rumpcalls
230 printf "#include <sys/proc.h>\n" > rumpcalls
231 printf "#endif /* __NetBSD__ */\n\n" > rumpcalls
232 printf "#ifdef RUMP_CLIENT\n" > rumpcalls
233 printf "#include <errno.h>\n" > rumpcalls
234 printf "#include <stdint.h>\n" > rumpcalls
235 printf "#include <stdlib.h>\n\n" > rumpcalls
236 printf "#include <srcsys/syscall.h>\n" > rumpcalls
237 printf "#include <srcsys/syscallargs.h>\n\n" > rumpcalls
238 printf "#include <rump/rumpclient.h>\n\n" > rumpcalls
239 printf "#define rsys_syscall(num, data, dlen, retval)\t\\\n" > rumpcalls
240 printf " rumpclient_syscall(num, data, dlen, retval)\n" > rumpcalls
241 printf "#define rsys_seterrno(error) errno = error\n" > rumpcalls
242 printf "#define rsys_alias(a,b)\n#else\n" > rumpcalls
243 printf "#include <sys/syscall.h>\n" > rumpcalls
244 printf "#include <sys/syscallargs.h>\n\n" > rumpcalls
245 printf "#include <sys/syscallvar.h>\n\n" > rumpcalls
246 printf "#include <rump/rumpuser.h>\n" > rumpcalls
247 printf "#include \"rump_private.h\"\n\n" > rumpcalls
248 printf "static int\nrsys_syscall" > rumpcalls
249 printf "(int num, void *data, size_t dlen, register_t *retval)" > rumpcalls
250 printf "\n{\n\tstruct sysent *callp = rump_sysent + num;\n" > rumpcalls
251 printf "\tint rv;\n" > rumpcalls
252 printf "\n\tKASSERT(num > 0 && num < SYS_NSYSENT);\n\n" > rumpcalls
253 printf "\trump_schedule();\n" > rumpcalls
254 printf "\trv = sy_call(callp, curlwp, data, retval);\n" > rumpcalls
255 printf "\trump_unschedule();\n\n\treturn rv;\n}\n\n" > rumpcalls
256 printf "#define rsys_seterrno(error) rumpuser_seterrno(error)\n" > rumpcalls
257 printf "#define rsys_alias(a,b) __weak_alias(a,b);\n#endif\n\n" > rumpcalls
258
259 printf "#if\tBYTE_ORDER == BIG_ENDIAN\n" > rumpcalls
260 printf "#define SPARG(p,k)\t((p)->k.be.datum)\n" > rumpcalls
261 printf "#else /* LITTLE_ENDIAN, I hope dearly */\n" > rumpcalls
262 printf "#define SPARG(p,k)\t((p)->k.le.datum)\n" > rumpcalls
263 printf "#endif\n\n" > rumpcalls
264 printf "#ifndef RUMP_CLIENT\n" > rumpcalls
265 printf "int rump_enosys(void);\n" > rumpcalls
266 printf "int\nrump_enosys()\n{\n\n\treturn ENOSYS;\n}\n" > rumpcalls
267 printf "#endif\n" > rumpcalls
268
269 printf "\n#ifndef RUMP_CLIENT\n" > rumpsysent
270 printf "#define\ts(type)\tsizeof(type)\n" > rumpsysent
271 printf "#define\tn(type)\t(sizeof(type)/sizeof (%s))\n", registertype > rumpsysent
272 printf "#define\tns(type)\tn(type), s(type)\n\n", registertype > rumpsysent
273 printf "struct sysent rump_sysent[] = {\n" > rumpsysent
274
275 # System call names are included by userland (kdump(1)), so
276 # hide the include files from it.
277 printf "#if defined(_KERNEL_OPT)\n" > sysnames
278
279 printf "#endif /* _KERNEL_OPT */\n\n" > sysnamesbottom
280 printf "const char *const %s[] = {\n",namesname > sysnamesbottom
281
282 printf " * created from%s\n */\n\n", $0 > sysnumhdr
283 printf "#ifndef _" constprefix "SYSCALL_H_\n" > sysnumhdr
284 printf "#define _" constprefix "SYSCALL_H_\n\n" > sysnumhdr
285
286 printf " * created from%s\n */\n\n", $0 > sysarghdr
287 printf "#ifndef _" constprefix "SYSCALLARGS_H_\n" > sysarghdr
288 printf "#define _" constprefix "SYSCALLARGS_H_\n\n" > sysarghdr
289
290 printf " * created from%s\n */\n\n", $0 > rumpcallshdr
291 printf "#ifndef _RUMP_RUMP_SYSCALLS_H_\n" > rumpcallshdr
292 printf "#define _RUMP_RUMP_SYSCALLS_H_\n\n" > rumpcallshdr
293 printf "#ifdef _KERNEL\n" > rumpcallshdr
294 printf "#error Interface not supported inside kernel\n" > rumpcallshdr
295 printf "#endif /* _KERNEL */\n\n" > rumpcallshdr
296 printf "#include <sys/types.h> /* typedefs */\n" > rumpcallshdr
297 printf "#include <sys/select.h> /* typedefs */\n" > rumpcallshdr
298 printf "#include <sys/socket.h> /* typedefs */\n\n" > rumpcallshdr
299 printf "#include <signal.h> /* typedefs */\n\n" > rumpcallshdr
300 printf "#include <rump/rump_syscalls_compat.h>\n\n" > rumpcallshdr
301
302 printf "%s", sysarghdrextra > sysarghdr
303 # Write max number of system call arguments to both headers
304 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
305 > sysnumhdr
306 printf("#define\t%sMAXSYSARGS\t%d\n\n", constprefix, maxsysargs) \
307 > sysarghdr
308 printf "#undef\tsyscallarg\n" > sysarghdr
309 printf "#define\tsyscallarg(x)\t\t\t\t\t\t\t\\\n" > sysarghdr
310 printf "\tunion {\t\t\t\t\t\t\t\t\\\n" > sysarghdr
311 printf "\t\t%s pad;\t\t\t\t\t\t\\\n", registertype > sysarghdr
312 printf "\t\tstruct { x datum; } le;\t\t\t\t\t\\\n" > sysarghdr
313 printf "\t\tstruct { /* LINTED zero array dimension */\t\t\\\n" \
314 > sysarghdr
315 printf "\t\t\tint8_t pad[ /* CONSTCOND */\t\t\t\\\n" > sysarghdr
316 printf "\t\t\t\t(sizeof (%s) < sizeof (x))\t\\\n", \
317 registertype > sysarghdr
318 printf "\t\t\t\t? 0\t\t\t\t\t\\\n" > sysarghdr
319 printf "\t\t\t\t: sizeof (%s) - sizeof (x)];\t\\\n", \
320 registertype > sysarghdr
321 printf "\t\t\tx datum;\t\t\t\t\t\\\n" > sysarghdr
322 printf "\t\t} be;\t\t\t\t\t\t\t\\\n" > sysarghdr
323 printf "\t}\n" > sysarghdr
324 printf("\n#undef check_syscall_args\n") >sysarghdr
325 printf("#define check_syscall_args(call) /*LINTED*/ \\\n" \
326 "\ttypedef char call##_check_args" \
327 "[sizeof (struct call##_args) \\\n" \
328 "\t\t<= %sMAXSYSARGS * sizeof (%s) ? 1 : -1];\n", \
329 constprefix, registertype) >sysarghdr
330
331 # compat types from syscalls.master. this is slightly ugly,
332 # but given that we have so few compats from over 17 years,
333 # a more complicated solution is not currently warranted.
334 uncompattypes["struct timeval50"] = "struct timeval";
335 uncompattypes["struct timespec50"] = "struct timespec";
336 uncompattypes["struct stat30"] = "struct stat";
337
338 next
339 }
340 NF == 0 || $1 ~ /^;/ {
341 next
342 }
343 $0 ~ /^%%$/ {
344 intable = 1
345 next
346 }
347 $1 ~ /^#[ ]*include/ {
348 print > sysdcl
349 print > sysnames
350 next
351 }
352 $1 ~ /^#/ && !intable {
353 print > sysdcl
354 print > sysnames
355 next
356 }
357 $1 ~ /^#/ && intable {
358 if ($1 ~ /^#[ ]*if/) {
359 savedepth++
360 savesyscall[savedepth] = syscall
361 }
362 if ($1 ~ /^#[ ]*else/) {
363 if (savedepth <= 0) {
364 printf("%s: line %d: unbalanced #else\n", \
365 infile, NR)
366 exit 1
367 }
368 syscall = savesyscall[savedepth]
369 }
370 if ($1 ~ /^#[ ]*endif/) {
371 if (savedepth <= 0) {
372 printf("%s: line %d: unbalanced #endif\n", \
373 infile, NR)
374 exit 1
375 }
376 savedepth--
377 }
378 print > sysent
379 print > sysarghdr
380 print > sysnumhdr
381 print > sysprotos
382 print > sysnamesbottom
383
384 # XXX: technically we do not want to have conditionals in rump,
385 # but it is easier to just let the cpp handle them than try to
386 # figure out what we want here in this script
387 print > rumpsysent
388 next
389 }
390 syscall != $1 {
391 printf "%s: line %d: syscall number out of sync at %d\n", \
392 infile, NR, syscall
393 printf "line is:\n"
394 print
395 exit 1
396 }
397 function parserr(was, wanted) {
398 printf "%s: line %d: unexpected %s (expected <%s>)\n", \
399 infile, NR, was, wanted
400 printf "line is:\n"
401 print
402 exit 1
403 }
404 function parseline() {
405 f=3 # toss number and type
406 if ($2 == "INDIR")
407 sycall_flags="SYCALL_INDIRECT"
408 else
409 sycall_flags="0"
410 if ($NF != "}") {
411 funcalias=$NF
412 end=NF-1
413 } else {
414 funcalias=""
415 end=NF
416 }
417 if ($f == "INDIR") { # allow for "NOARG INDIR"
418 sycall_flags = "SYCALL_INDIRECT | " sycall_flags
419 f++
420 }
421 if ($f == "MODULAR") { # registered at runtime
422 modular = 1
423 f++
424 } else {
425 modular = 0;
426 }
427 if ($f == "RUMP") {
428 rumpable = 1
429 f++
430 } else {
431 rumpable = 0
432 }
433 if ($f ~ /^[a-z0-9_]*$/) { # allow syscall alias
434 funcalias=$f
435 f++
436 }
437 if ($f != "{")
438 parserr($f, "{")
439 f++
440 if ($end != "}")
441 parserr($end, "}")
442 end--
443 if ($end != ";")
444 parserr($end, ";")
445 end--
446 if ($end != ")")
447 parserr($end, ")")
448 end--
449
450 returntype = oldf = "";
451 do {
452 if (returntype != "" && oldf != "*")
453 returntype = returntype" ";
454 returntype = returntype$f;
455 oldf = $f;
456 f++
457 } while ($f != "|" && f < (end-1))
458 if (f == (end - 1)) {
459 parserr($f, "function argument definition (maybe \"|\"?)");
460 }
461 f++
462
463 fprefix=$f
464 f++
465 if ($f != "|") {
466 parserr($f, "function compat delimiter (maybe \"|\"?)");
467 }
468 f++
469
470 fcompat=""
471 if ($f != "|") {
472 fcompat=$f
473 f++
474 }
475
476 if ($f != "|") {
477 parserr($f, "function name delimiter (maybe \"|\"?)");
478 }
479 f++
480 fbase=$f
481
482 # pipe is special in how to returns its values.
483 # So just generate it manually if present.
484 if (rumpable == 1 && fbase == "pipe") {
485 rumpable = 0;
486 rumphaspipe = 1;
487 }
488
489 if (fcompat != "") {
490 funcname=fprefix "___" fbase "" fcompat
491 } else {
492 funcname=fprefix "_" fbase
493 }
494 if (returntype == "quad_t" || returntype == "off_t") {
495 if (sycall_flags == "0")
496 sycall_flags = "SYCALL_RET_64";
497 else
498 sycall_flags = "SYCALL_RET_64 | " sycall_flags;
499 }
500
501 if (funcalias == "") {
502 funcalias=funcname
503 sub(/^([^_]+_)*sys_/, "", funcalias)
504 realname=fbase
505 } else {
506 realname=funcalias
507 }
508 rumpfname=realname "" fcompat
509 f++
510
511 if ($f != "(")
512 parserr($f, "(")
513 f++
514
515 argc=0;
516 argalign=0;
517 if (f == end) {
518 if ($f != "void")
519 parserr($f, "argument definition")
520 isvarargs = 0;
521 varargc = 0;
522 argtype[0]="void";
523 return
524 }
525
526 # some system calls (open() and fcntl()) can accept a variable
527 # number of arguments. If syscalls accept a variable number of
528 # arguments, they must still have arguments specified for
529 # the remaining argument "positions," because of the way the
530 # kernel system call argument handling works.
531 #
532 # Indirect system calls, e.g. syscall(), are exceptions to this
533 # rule, since they are handled entirely by machine-dependent code
534 # and do not need argument structures built.
535
536 isvarargs = 0;
537 args64 = 0;
538 ptr = 0;
539 while (f <= end) {
540 if ($f == "...") {
541 f++;
542 isvarargs = 1;
543 varargc = argc;
544 continue;
545 }
546 argc++
547 argtype[argc]=""
548 oldf=""
549 while (f < end && $(f+1) != ",") {
550 if (argtype[argc] != "" && oldf != "*")
551 argtype[argc] = argtype[argc]" ";
552 argtype[argc] = argtype[argc]$f;
553 oldf = $f;
554 f++
555 }
556 if (argtype[argc] == "")
557 parserr($f, "argument definition")
558 if (argtype[argc] == "off_t" \
559 || argtype[argc] == "dev_t" \
560 || argtype[argc] == "time_t") {
561 if ((argalign % 2) != 0 && sysalign &&
562 funcname != "sys_posix_fadvise") # XXX for now
563 parserr($f, "a padding argument")
564 } else {
565 argalign++;
566 }
567 if (argtype[argc] == "quad_t" || argtype[argc] == "off_t" \
568 || argtype[argc] == "dev_t" || argtype[argc] == "time_t") {
569 if (sycall_flags == "0")
570 sycall_flags = "SYCALL_ARG"argc-1"_64";
571 else
572 sycall_flags = "SYCALL_ARG"argc-1"_64 | " sycall_flags;
573 args64++;
574 }
575 if (index(argtype[argc], "*") != 0 && ptr == 0) {
576 if (sycall_flags == "0")
577 sycall_flags = "SYCALL_ARG_PTR";
578 else
579 sycall_flags = "SYCALL_ARG_PTR | " sycall_flags;
580 ptr = 1;
581 }
582 argname[argc]=$f;
583 f += 2; # skip name, and any comma
584 }
585 if (args64 > 0)
586 sycall_flags = "SYCALL_NARGS64_VAL("args64") | " sycall_flags;
587 # must see another argument after varargs notice.
588 if (isvarargs) {
589 if (argc == varargc)
590 parserr($f, "argument definition")
591 } else
592 varargc = argc;
593 }
594
595 function printproto(wrap) {
596 printf("/* syscall: \"%s%s\" ret: \"%s\" args:", wrap, funcalias,
597 returntype) > sysnumhdr
598 for (i = 1; i <= varargc; i++)
599 printf(" \"%s\"", argtype[i]) > sysnumhdr
600 if (isvarargs)
601 printf(" \"...\"") > sysnumhdr
602 printf(" */\n") > sysnumhdr
603 printf("#define\t%s%s%s\t%d\n\n", constprefix, wrap, funcalias,
604 syscall) > sysnumhdr
605
606 # rumpalooza
607 if (!rumpable)
608 return
609
610 # accumulate fbases we have seen. we want the last
611 # occurence for the default __RENAME()
612 seen = funcseen[fbase]
613 funcseen[fbase] = rumpfname
614 if (seen)
615 return
616
617 printf("%s rump_sys_%s(", returntype, realname) > rumpprotos
618
619 for (i = 1; i < varargc; i++)
620 if (argname[i] != "PAD")
621 printf("%s, ", uncompattype(argtype[i])) > rumpprotos
622
623 if (isvarargs)
624 printf("%s, ...)", uncompattype(argtype[varargc]))>rumpprotos
625 else
626 printf("%s)", uncompattype(argtype[argc])) > rumpprotos
627
628 printf(" __RENAME(RUMP_SYS_RENAME_%s)", toupper(fbase))> rumpprotos
629 printf(";\n") > rumpprotos
630
631 # generate forward-declares for types, apart from the
632 # braindead typedef jungle we cannot easily handle here
633 for (i = 1; i <= varargc; i++) {
634 type=uncompattype(argtype[i])
635 sub("const ", "", type)
636 if (!typeseen[type] && \
637 match(type, "struct") && match(type, "\\*")) {
638 typeseen[type] = 1
639 sub(" *\\*", "", type);
640 printf("%s;\n", type) > rumptypes
641 }
642 }
643 }
644
645 function printrumpsysent(insysent, compatwrap) {
646 if (!insysent) {
647 eno[0] = "rump_enosys"
648 eno[1] = "sys_nomodule"
649 flags[0] = "SYCALL_NOSYS"
650 flags[1] = "0"
651 printf("\t{ 0, 0, %s,\n\t (sy_call_t *)%s }, \t" \
652 "/* %d = %s */\n", \
653 flags[modular], eno[modular], syscall, funcalias) \
654 > rumpsysent
655 return
656 }
657
658 printf("\t{ ") > rumpsysent
659 if (argc == 0) {
660 printf("0, 0, ") > rumpsysent
661 } else {
662 printf("ns(struct %ssys_%s_args), ", compatwrap_, funcalias) > rumpsysent
663 }
664
665 if (compatwrap == "") {
666 if (modular)
667 rfn = "(sy_call_t *)sys_nomodule"
668 else
669 rfn = "(sy_call_t *)" funcname
670 } else {
671 rfn = "(sy_call_t *)" compatwrap "_" funcname
672 }
673
674 printf("0,\n\t %s },", rfn) > rumpsysent
675 for (i = 0; i < (33 - length(rfn)) / 8; i++)
676 printf("\t") > rumpsysent
677 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > rumpsysent
678 }
679
680 function iscompattype(type) {
681 for (var in uncompattypes) {
682 if (match(type, var)) {
683 return 1
684 }
685 }
686
687 return 0
688 }
689
690 function uncompattype(type) {
691 for (var in uncompattypes) {
692 if (match(type, var)) {
693 sub(var, uncompattypes[var], type)
694 return type
695 }
696 }
697
698 return type
699 }
700
701 function putent(type, compatwrap) {
702 # output syscall declaration for switch table.
703 if (compatwrap == "")
704 compatwrap_ = ""
705 else
706 compatwrap_ = compatwrap "_"
707 if (argc == 0)
708 arg_type = "void";
709 else {
710 arg_type = "struct " compatwrap_ funcname "_args";
711 }
712 proto = "int\t" compatwrap_ funcname "(struct lwp *, const " \
713 arg_type " *, register_t *);\n"
714 if (sysmap[proto] != 1) {
715 sysmap[proto] = 1;
716 print proto > sysprotos;
717 }
718
719 # output syscall switch entry
720 printf("\t{ ") > sysent
721 if (argc == 0) {
722 printf("0, 0, ") > sysent
723 } else {
724 printf("ns(struct %s%s_args), ", compatwrap_, funcname) > sysent
725 }
726 if (modular)
727 wfn = "(sy_call_t *)sys_nomodule";
728 else if (compatwrap == "")
729 wfn = "(sy_call_t *)" funcname;
730 else
731 wfn = "(sy_call_t *)" compatwrap "(" funcname ")";
732 printf("%s,\n\t %s },", sycall_flags, wfn) > sysent
733 for (i = 0; i < (33 - length(wfn)) / 8; i++)
734 printf("\t") > sysent
735 printf("/* %d = %s%s */\n", syscall, compatwrap_, funcalias) > sysent
736
737 # output syscall name for names table
738 printf("\t/* %3d */\t\"%s%s\",\n", syscall, compatwrap_, funcalias) \
739 > sysnamesbottom
740
741 # output syscall number of header, if appropriate
742 if (type == "STD" || type == "NOARGS" || type == "INDIR" || \
743 type == "NOERR") {
744 # output a prototype, to be used to generate lint stubs in
745 # libc.
746 printproto("")
747 } else if (type == "COMPAT" || type == "EXTERN") {
748 # Just define the syscall number with a comment. These
749 # may be used by compatibility stubs in libc.
750 printproto(compatwrap_)
751 }
752
753 # output syscall argument structure, if it has arguments
754 if (argc != 0) {
755 printf("\n") > sysarghdr
756 if (haverumpcalls && !rumpable)
757 printf("#ifndef RUMP_CLIENT\n") > sysarghdr
758 printf("struct %s%s_args", compatwrap_, funcname) > sysarghdr
759 if (type != "NOARGS") {
760 print " {" >sysarghdr;
761 for (i = 1; i <= argc; i++)
762 printf("\tsyscallarg(%s) %s;\n", argtype[i],
763 argname[i]) > sysarghdr
764 printf "}" >sysarghdr;
765 }
766 printf(";\n") > sysarghdr
767 if (type != "NOARGS" && type != "INDIR") {
768 printf("check_syscall_args(%s%s)\n", compatwrap_,
769 funcname) >sysarghdr
770 }
771 if (haverumpcalls && !rumpable)
772 printf("#endif /* !RUMP_CLIENT */\n") > sysarghdr
773 }
774
775 if (!rumpable) {
776 if (funcname == "sys_pipe" && rumphaspipe == 1)
777 insysent = 1
778 else
779 insysent = 0
780 } else {
781 insysent = 1
782 }
783 printrumpsysent(insysent, compatwrap)
784
785 # output rump marshalling code if necessary
786 if (!rumpable) {
787 return
788 }
789
790 # need a local prototype, we export the re-re-named one in .h
791 printf("\n%s rump___sysimpl_%s(", returntype, rumpfname) \
792 > rumpcalls
793 for (i = 1; i < argc; i++) {
794 if (argname[i] != "PAD")
795 printf("%s, ", uncompattype(argtype[i])) > rumpcalls
796 }
797 printf("%s);", uncompattype(argtype[argc])) > rumpcalls
798
799 printf("\n%s\nrump___sysimpl_%s(", returntype, rumpfname) > rumpcalls
800 for (i = 1; i < argc; i++) {
801 if (argname[i] != "PAD")
802 printf("%s %s, ", uncompattype(argtype[i]), \
803 argname[i]) > rumpcalls
804 }
805 printf("%s %s)\n", uncompattype(argtype[argc]), argname[argc]) \
806 > rumpcalls
807 printf("{\n\tregister_t retval[2] = {0, 0};\n") > rumpcalls
808 if (returntype != "void") {
809 if (type != "NOERR") {
810 printf("\tint error = 0;\n") > rumpcalls
811 }
812 # assume rumpcalls return only integral types
813 printf("\t%s rv = -1;\n", returntype) > rumpcalls
814 }
815
816 argarg = "NULL"
817 argsize = 0;
818 if (argc) {
819 argarg = "&callarg"
820 argsize = "sizeof(callarg)"
821 printf("\tstruct %s%s_args callarg;\n\n",compatwrap_,funcname) \
822 > rumpcalls
823 for (i = 1; i <= argc; i++) {
824 if (argname[i] == "PAD") {
825 printf("\tSPARG(&callarg, %s) = 0;\n", \
826 argname[i]) > rumpcalls
827 } else {
828 if (iscompattype(argtype[i])) {
829 printf("\tSPARG(&callarg, %s) = " \
830 "(%s)%s;\n", argname[i], argtype[i], \
831 argname[i]) > rumpcalls
832 } else {
833 printf("\tSPARG(&callarg, %s) = %s;\n",\
834 argname[i], argname[i]) > rumpcalls
835 }
836 }
837 }
838 printf("\n") > rumpcalls
839 } else {
840 printf("\n") > rumpcalls
841 }
842 printf("\t") > rumpcalls
843 if (returntype != "void" && type != "NOERR")
844 printf("error = ") > rumpcalls
845 printf("rsys_syscall(%s%s%s, " \
846 "%s, %s, retval);\n", constprefix, compatwrap_, funcalias, \
847 argarg, argsize) > rumpcalls
848 if (type != "NOERR") {
849 printf("\trsys_seterrno(error);\n") > rumpcalls
850 printf("\tif (error == 0) {\n") > rumpcalls
851 indent="\t\t"
852 ending="\t}\n"
853 } else {
854 indent="\t"
855 ending=""
856 }
857 if (returntype != "void") {
858 printf("%sif (sizeof(%s) > sizeof(register_t))\n", \
859 indent, returntype) > rumpcalls
860 printf("%s\trv = *(%s *)retval;\n", \
861 indent, returntype) > rumpcalls
862 printf("%selse\n", indent, indent) > rumpcalls
863 printf("%s\trv = *retval;\n", indent, returntype) > rumpcalls
864 printf("%s", ending) > rumpcalls
865 printf("\treturn rv;\n") > rumpcalls
866 }
867 printf("}\n") > rumpcalls
868 printf("rsys_alias(%s%s,rump_enosys)\n", \
869 compatwrap_, funcname) > rumpcalls
870
871 }
872 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "INDIR" \
873 || $2 == "NOERR" {
874 parseline()
875 putent($2, "")
876 syscall++
877 next
878 }
879 $2 == "OBSOL" || $2 == "UNIMPL" || $2 == "EXCL" || $2 == "IGNORED" {
880 if ($2 == "OBSOL")
881 comment="obsolete"
882 else if ($2 == "EXCL")
883 comment="excluded"
884 else if ($2 == "IGNORED")
885 comment="ignored"
886 else
887 comment="unimplemented"
888 for (i = 3; i <= NF; i++)
889 comment=comment " " $i
890
891 if ($2 == "IGNORED")
892 sys_stub = "(sy_call_t *)nullop";
893 else
894 sys_stub = sys_nosys;
895
896 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = %s */\n", \
897 sys_stub, syscall, comment) > sysent
898 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = %s */\n", \
899 "(sy_call_t *)rump_enosys", syscall, comment) > rumpsysent
900 printf("\t/* %3d */\t\"#%d (%s)\",\n", syscall, syscall, comment) \
901 > sysnamesbottom
902 if ($2 != "UNIMPL")
903 printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
904 syscall++
905 next
906 }
907 $2 == "EXTERN" {
908 parseline()
909 putent("EXTERN", "")
910 syscall++
911 next
912 }
913 {
914 for (i = 1; i <= ncompat; i++) {
915 if ($2 == compat_upper[i]) {
916 parseline();
917 putent("COMPAT", compat[i])
918 syscall++
919 next
920 }
921 }
922 printf("%s: line %d: unrecognized keyword %s\n", infile, NR, $2)
923 exit 1
924 }
925 END {
926 # output pipe() syscall with its special retval[2] handling
927 if (rumphaspipe) {
928 printf("int rump_sys_pipe(int *);\n") > rumpprotos
929 printf("\nint rump_sys_pipe(int *);\n") > rumpcalls
930 printf("int\nrump_sys_pipe(int *fd)\n{\n") > rumpcalls
931 printf("\tregister_t retval[2] = {0, 0};\n") > rumpcalls
932 printf("\tint error = 0;\n") > rumpcalls
933 printf("\n\terror = rsys_syscall(SYS_pipe, ") > rumpcalls
934 printf("NULL, 0, retval);\n") > rumpcalls
935 printf("\tif (error) {\n") > rumpcalls
936 printf("\t\trsys_seterrno(error);\n") > rumpcalls
937 printf("\t} else {\n\t\tfd[0] = retval[0];\n") > rumpcalls
938 printf("\t\tfd[1] = retval[1];\n\t}\n") > rumpcalls
939 printf("\treturn error ? -1 : 0;\n}\n") > rumpcalls
940 }
941
942 # print default rump syscall interfaces
943 for (var in funcseen) {
944 printf("#ifndef RUMP_SYS_RENAME_%s\n", \
945 toupper(var)) > rumpcallshdr
946 printf("#define RUMP_SYS_RENAME_%s rump___sysimpl_%s\n", \
947 toupper(var), funcseen[var]) > rumpcallshdr
948 printf("#endif\n\n") > rumpcallshdr
949 }
950
951 maxsyscall = syscall
952 if (nsysent) {
953 if (syscall > nsysent) {
954 printf("%s: line %d: too many syscalls [%d > %d]\n", infile, NR, syscall, nsysent)
955 exit 1
956 }
957 while (syscall < nsysent) {
958 printf("\t{ 0, 0, 0,\n\t %s },\t\t\t/* %d = filler */\n", \
959 sys_nosys, syscall) > sysent
960 printf("\t{ 0, 0, SYCALL_NOSYS,\n\t %s },\t\t/* %d = filler */\n", \
961 "(sy_call_t *)rump_enosys", syscall) > rumpsysent
962 printf("\t/* %3d */\t\"# filler\",\n", syscall) \
963 > sysnamesbottom
964 syscall++
965 }
966 }
967 printf("};\n") > sysent
968 printf("};\n") > rumpsysent
969 printf("CTASSERT(__arraycount(rump_sysent) == SYS_NSYSENT);\n") > rumpsysent
970 printf("__strong_alias(sysent,rump_sysent);\n") > rumpsysent
971 printf("#endif /* RUMP_CLIENT */\n") > rumpsysent
972 if (haverumpcalls)
973 printf("#endif /* !RUMP_CLIENT */\n") > sysprotos
974 printf("};\n") > sysnamesbottom
975 printf("#define\t%sMAXSYSCALL\t%d\n", constprefix, maxsyscall) > sysnumhdr
976 if (nsysent)
977 printf("#define\t%sNSYSENT\t%d\n", constprefix, nsysent) > sysnumhdr
978 } '
979
980 cat $sysprotos >> $sysarghdr
981 echo "#endif /* _${constprefix}SYSCALL_H_ */" >> $sysnumhdr
982 echo "#endif /* _${constprefix}SYSCALLARGS_H_ */" >> $sysarghdr
983 printf "\n#endif /* _RUMP_RUMP_SYSCALLS_H_ */\n" >> $rumpprotos
984 cat $sysdcl $sysent > $syssw
985 cat $sysnamesbottom >> $sysnames
986 cat $rumpsysent >> $rumpcalls
987
988 touch $rumptypes
989 cat $rumptypes >> $rumpcallshdr
990 echo >> $rumpcallshdr
991 cat $rumpprotos >> $rumpcallshdr
992
993 #chmod 444 $sysnames $sysnumhdr $syssw
994