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