kernel/libc: Remove sigstack() remains.
[dragonfly.git] / sys / kern / makesyscalls.sh
blob04419e52b8cb2cf7994b9c7a9b8cbca2418b997d
1 #! /bin/sh -
2 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3 # $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.39.2.4 2001/10/20 09:01:24 marcel Exp $
5 set -e
7 # output files:
8 sysnames="syscalls.c"
9 sysproto="../sys/sysproto.h"
10 sysunion="../sys/sysunion.h"
11 sysproto_h=_SYS_SYSPROTO_H_
12 syshdr="../sys/syscall.h"
13 sysmk="../sys/syscall.mk"
14 syssw="init_sysent.c"
15 syscallprefix="SYS_"
16 switchname="sysent"
17 namesname="syscallnames"
19 # tmp files:
20 sysdcl="sysent.dcl.$$"
21 syscompat="sysent.compat.$$"
22 syscompatdcl="sysent.compatdcl.$$"
23 sysent="sysent.switch.$$"
24 sysinc="sysinc.switch.$$"
25 sysarg="sysarg.switch.$$"
26 sysun="sysunion.switch.$$"
28 trap "rm $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun" 0
30 touch $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun
32 case $# in
33 0) echo "Usage: $0 input-file <config-file>" 1>&2
34 exit 1
36 esac
38 if [ -n "$2" -a -f "$2" ]; then
39 . $2
42 sed -e '
43 s/\$//g
44 :join
45 /\\$/{a\
48 s/\\\n//
49 b join
51 2,${
52 /^#/!s/\([{}()*,]\)/ \1 /g
54 ' < $1 | awk "
55 BEGIN {
56 sysdcl = \"$sysdcl\"
57 sysproto = \"$sysproto\"
58 sysproto_h = \"$sysproto_h\"
59 syscompat = \"$syscompat\"
60 syscompatdcl = \"$syscompatdcl\"
61 sysent = \"$sysent\"
62 syssw = \"$syssw\"
63 sysinc = \"$sysinc\"
64 sysarg = \"$sysarg\"
65 sysun = \"$sysun\"
66 sysnames = \"$sysnames\"
67 syshdr = \"$syshdr\"
68 sysmk = \"$sysmk\"
69 compat = \"$compat\"
70 syscallprefix = \"$syscallprefix\"
71 switchname = \"$switchname\"
72 namesname = \"$namesname\"
73 infile = \"$1\"
76 printf "/*\n * System call switch table.\n *\n" > syssw
77 printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > syssw
78 printf " * by running make sysent in the same directory.\n" > syssw
79 printf " */\n\n" > syssw
81 printf "/*\n * System call prototypes.\n *\n" > sysarg
82 printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysarg
83 printf " * by running make sysent in the same directory.\n" > sysarg
84 printf " */\n\n" > sysarg
85 printf "#ifndef %s\n", sysproto_h > sysarg
86 printf "#define\t%s\n\n", sysproto_h > sysarg
87 printf "#include <sys/select.h>\n\n" > sysarg
88 printf "#include <sys/signal.h>\n\n" > sysarg
89 printf "#include <sys/acl.h>\n\n" > sysarg
90 printf "#include <sys/msgport.h>\n\n" > sysarg
91 printf "#include <sys/sysmsg.h>\n\n" > sysarg
92 printf "#include <sys/procctl.h>\n\n" > sysarg
93 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
94 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
96 printf "/*\n * System call names.\n *\n" > sysnames
97 printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysnames
98 printf " * by running make sysent in the same directory.\n" > sysnames
99 printf " */\n\n" > sysnames
100 printf "const char *%s[] = {\n", namesname > sysnames
102 printf "/*\n * System call numbers.\n *\n" > syshdr
103 printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > syshdr
104 printf " * by running make sysent in the same directory.\n" > syshdr
105 printf " */\n\n" > syshdr
107 printf "# DragonFly system call names.\n" > sysmk
108 printf "# DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysmk
109 printf "# by running make sysent in the same directory.\n" > sysmk
110 printf "MIASM = " > sysmk
112 printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
113 printf " * DO NOT EDIT-- To regenerate this file, edit syscalls.master followed\n" > sysun
114 printf " * by running make sysent in the same directory.\n" > sysun
115 printf " */\n\n" > sysun
116 printf "union sysunion {\n" > sysun
117 printf "#ifdef _KERNEL /* header only applies in kernel */\n" > sysun
118 #printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
119 printf "\tstruct\tsysmsg sysmsg;\n" > sysun
120 printf "#endif\n" > sysun
122 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
123 printf "struct sysent %s[] = {\n",switchname > sysent
125 printf "\n#ifdef _KERNEL\n\n" > sysdcl
126 printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
128 NF == 0 || $1 ~ /^;/ {
129 next
131 $1 ~ /^#[ ]*include/ {
132 print > sysinc
133 next
135 $1 ~ /^#[ ]*if/ {
136 print > sysent
137 print > sysdcl
138 print > sysarg
139 print > syscompat
140 print > sysnames
141 print > sysun
142 savesyscall = syscall
143 next
145 $1 ~ /^#[ ]*else/ {
146 print > sysent
147 print > sysdcl
148 print > sysarg
149 print > sysun
150 print > syscompat
151 print > sysnames
152 syscall = savesyscall
153 next
155 $1 ~ /^#/ {
156 print > sysent
157 print > sysdcl
158 print > sysarg
159 print > sysun
160 print > syscompat
161 print > sysnames
162 next
164 syscall != $1 {
165 printf "%s: line %d: syscall number out of sync at %d\n",
166 infile, NR, syscall
167 printf "line is:\n"
168 print
169 exit 1
171 function align_sysent_comment(column) {
172 printf("\t") > sysent
173 column = column + 8 - column % 8
174 while (column < 56) {
175 printf("\t") > sysent
176 column = column + 8
179 function parserr(was, wanted) {
180 printf "%s: line %d: unexpected %s (expected %s)\n",
181 infile, NR, was, wanted
182 exit 1
184 function parseline() {
185 f=3 # toss number and type
186 argc= 0;
187 argssize = "0"
188 if ($NF != "}") {
189 funcalias=$(NF-2)
190 argalias=$(NF-1)
191 rettype=$NF
192 end=NF-3
193 } else {
194 funcalias=""
195 argalias=""
196 rettype="int"
197 end=NF
199 if ($2 == "NODEF") {
200 funcname=$3
201 argssize = "AS(" $5 ")"
202 return
204 if ($f != "{")
205 parserr($f, "{")
207 if ($end != "}")
208 parserr($end, "}")
209 end--
210 if ($end != ";")
211 parserr($end, ";")
212 end--
213 if ($end != ")")
214 parserr($end, ")")
215 end--
217 f++ #function return type
219 funcname=$f
220 usefuncname=$f
221 if (funcalias == "")
222 funcalias = funcname
223 if (argalias == "") {
224 argalias = funcname "_args"
225 if ($2 == "COMPAT") {
226 argalias = "o" argalias
227 usefuncname = "sys_o" funcname
232 if ($f != "(")
233 parserr($f, ")")
236 if (f == end) {
237 if ($f != "void")
238 parserr($f, "argument definition")
239 return
242 while (f <= end) {
243 argc++
244 argtype[argc]=""
245 oldf=""
246 while (f < end && $(f+1) != ",") {
247 if (argtype[argc] != "" && oldf != "*")
248 argtype[argc] = argtype[argc]" ";
249 argtype[argc] = argtype[argc]$f;
250 oldf = $f;
253 if (argtype[argc] == "")
254 parserr($f, "argument definition")
255 argname[argc]=$f;
256 f += 2; # skip name, and any comma
258 if (argc != 0)
259 argssize = "AS(" argalias ")"
261 { comment = $3
262 if (NF < 6)
263 for (i = 4; i <= NF; i++)
264 comment = comment " " $i
266 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
267 || $2 == "NOIMPL" {
268 parseline()
269 if ((!nosys || funcname != "nosys") && \
270 (funcname != "lkmnosys")) {
271 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
272 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
273 printf("struct\t%s {\n", argalias) > sysarg
274 printf("#ifdef _KERNEL\n") > sysarg
275 printf("\tstruct sysmsg sysmsg;\n") > sysarg
276 printf("#endif\n") > sysarg
277 for (i = 1; i <= argc; i++)
278 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
279 argtype[i], argname[i],
280 argname[i], argtype[i]) > sysarg
281 printf("};\n") > sysarg
283 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
284 $2 != "NODEF") {
285 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
286 printf("struct\t%s {\n", argalias) > sysarg
287 printf("#ifdef _KERNEL\n") > sysarg
288 printf("\tstruct sysmsg sysmsg;\n") > sysarg
289 printf("#endif\n") > sysarg
290 printf("\tregister_t dummy;\n") > sysarg
291 printf("};\n") > sysarg
294 if (($2 != "NOPROTO" && $2 != "NODEF" && \
295 (funcname != "nosys" || !nosys)) || \
296 (funcname == "lkmnosys" && !lkmnosys) || \
297 funcname == "lkmressys") {
298 printf("%s\tsys_%s (struct %s *)",
299 rettype, funcname, argalias) > sysdcl
300 printf(";\n") > sysdcl
302 if (funcname == "nosys")
303 nosys = 1
304 if (funcname == "lkmnosys")
305 lkmnosys = 1
306 printf("\t{ %s, (sy_call_t *)", argssize) > sysent
307 column = 8 + 2 + length(argssize) + 15
308 if ($2 != "NOIMPL") {
309 printf("sys_%s },", funcname) > sysent
310 column = column + length(funcname) + 7
311 } else {
312 printf("sys_%s },", "nosys") > sysent
313 column = column + length("nosys") + 7
315 align_sysent_comment(column)
316 printf("/* %d = %s */\n", syscall, funcalias) > sysent
317 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
318 funcalias, syscall, funcalias) > sysnames
319 if ($2 != "NODEF") {
320 printf("#define\t%s%s\t%d\n", syscallprefix,
321 funcalias, syscall) > syshdr
322 printf(" \\\n\t%s.o", funcalias) > sysmk
324 syscall++
325 next
327 $2 == "COMPAT" || $2 == "CPT_NOA" {
328 ncompat++
329 parseline()
330 if (argc != 0 && $2 != "CPT_NOA") {
331 printf("struct\t%s {\n", argalias) > syscompat
332 printf("#ifdef _KERNEL\n") > syscompat
333 printf("\tstruct sysmsg sysmsg;\n") > syscompat
334 printf("#endif\n") > syscompat
335 for (i = 1; i <= argc; i++)
336 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
337 argtype[i], argname[i],
338 argname[i], argtype[i]) > syscompat
339 printf("};\n") > syscompat
341 else if($2 != "CPT_NOA") {
342 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
343 printf("struct\t%s {\n", argalias) > sysarg
344 printf("#ifdef _KERNEL\n") > sysarg
345 printf("\tstruct sysmsg sysmsg;\n") > sysarg
346 printf("#endif\n") > sysarg
347 printf("\tregister_t dummy;\n") > sysarg
348 printf("};\n") > sysarg
350 printf("%s\tsys_o%s (struct %s *);\n",
351 rettype, funcname, argalias) > syscompatdcl
352 printf("\t{ compat(%s,%s) },",
353 argssize, funcname) > sysent
354 align_sysent_comment(8 + 9 + \
355 length(argssize) + 1 + length(funcname) + 4)
356 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
357 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
358 funcalias, syscall, funcalias) > sysnames
359 printf("\t\t\t\t/* %d is old %s */\n",
360 syscall, funcalias) > syshdr
361 syscall++
362 next
364 $2 == "LIBCOMPAT" {
365 ncompat++
366 parseline()
367 printf("%s\tsys_o%s();\n", rettype, funcname) > syscompatdcl
368 printf("\t{ compat(%s,%s) },",
369 argssize, funcname) > sysent
370 align_sysent_comment(8 + 9 + \
371 length(argssize) + 1 + length(funcname) + 4)
372 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
373 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
374 funcalias, syscall, funcalias) > sysnames
375 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
376 syscallprefix, funcalias, syscall) > syshdr
377 printf(" \\\n\t%s.o", funcalias) > sysmk
378 syscall++
379 next
381 $2 == "OBSOL" {
382 printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
383 align_sysent_comment(37)
384 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
385 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
386 $3, syscall, comment) > sysnames
387 printf("\t\t\t\t/* %d is obsolete %s */\n",
388 syscall, comment) > syshdr
389 syscall++
390 next
392 $2 == "UNIMPL" {
393 printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
394 syscall, comment) > sysent
395 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
396 syscall, syscall, comment) > sysnames
397 syscall++
398 next
401 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
402 exit 1
404 END {
405 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
406 if (ncompat != 0)
407 printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
409 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
411 printf("\n") > sysmk
412 printf("};\n") > sysent
413 printf("};\n") > sysnames
414 printf("};\n") > sysun
415 printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
416 printf("#undef PAD_\n") > sysdcl
417 printf("\n#endif /* _KERNEL */\n") > sysdcl
418 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
419 > syshdr
422 cat $sysinc $sysent >> $syssw
423 cat $sysarg $syscompat $syscompatdcl $sysdcl > $sysproto
424 cat $sysun > $sysunion