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