kern - Convert aio from zalloc to objcache
[dragonfly.git] / sys / kern / makesyscalls.sh
blobc5e839d03bafe4df6ed13ba64374334a8839c07a
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 $
4 # $DragonFly: src/sys/kern/makesyscalls.sh,v 1.17 2008/05/19 10:19:49 corecode Exp $
6 set -e
8 # name of compat option:
9 compat=COMPAT_43
10 # name of DragonFly 1.2 compat option
11 compatdf12=COMPAT_DF12
13 # output files:
14 sysnames="syscalls.c"
15 sysproto="../sys/sysproto.h"
16 sysunion="../sys/sysunion.h"
17 sysproto_h=_SYS_SYSPROTO_H_
18 syshdr="../sys/syscall.h"
19 sysmk="../sys/syscall.mk"
20 syssw="init_sysent.c"
21 syshide="../sys/syscall-hide.h"
22 syscallprefix="SYS_"
23 switchname="sysent"
24 namesname="syscallnames"
26 # tmp files:
27 sysdcl="sysent.dcl.$$"
28 syscompat="sysent.compat.$$"
29 syscompatdf12="sysent.compatdf12.$$"
30 syscompatdcl="sysent.compatdcl.$$"
31 syscompatdcldf12="sysent.compatdcldf12.$$"
32 sysent="sysent.switch.$$"
33 sysinc="sysinc.switch.$$"
34 sysarg="sysarg.switch.$$"
35 sysun="sysunion.switch.$$"
37 trap "rm $sysdcl $syscompat $syscompatdf12 $syscompatdcl $syscompatdcldf12 $sysent $sysinc $sysarg $sysun" 0
39 touch $sysdcl $syscompat $syscompatdf12 $syscompatdcl $syscompatdcldf12 $sysent $sysinc $sysarg $sysun
41 case $# in
42 0) echo "Usage: $0 input-file <config-file>" 1>&2
43 exit 1
45 esac
47 if [ -n "$2" -a -f "$2" ]; then
48 . $2
51 sed -e '
52 s/\$//g
53 :join
54 /\\$/{a\
57 s/\\\n//
58 b join
60 2,${
61 /^#/!s/\([{}()*,]\)/ \1 /g
63 ' < $1 | awk "
64 BEGIN {
65 sysdcl = \"$sysdcl\"
66 sysproto = \"$sysproto\"
67 sysproto_h = \"$sysproto_h\"
68 syscompat = \"$syscompat\"
69 syscompatdf12 = \"$syscompatdf12\"
70 syscompatdcl = \"$syscompatdcl\"
71 syscompatdcldf12 = \"$syscompatdcldf12\"
72 sysent = \"$sysent\"
73 syssw = \"$syssw\"
74 sysinc = \"$sysinc\"
75 sysarg = \"$sysarg\"
76 sysun = \"$sysun\"
77 sysnames = \"$sysnames\"
78 syshdr = \"$syshdr\"
79 sysmk = \"$sysmk\"
80 compat = \"$compat\"
81 compatdf12 = \"$compatdf12\"
82 syshide = \"$syshide\"
83 syscallprefix = \"$syscallprefix\"
84 switchname = \"$switchname\"
85 namesname = \"$namesname\"
86 infile = \"$1\"
89 printf "/*\n * System call switch table.\n *\n" > syssw
90 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
91 printf " */\n\n" > syssw
93 printf "/*\n * System call prototypes.\n *\n" > sysarg
94 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
95 printf " */\n\n" > sysarg
96 printf "#ifndef %s\n", sysproto_h > sysarg
97 printf "#define\t%s\n\n", sysproto_h > sysarg
98 printf "#include <sys/select.h>\n\n" > sysarg
99 printf "#include <sys/signal.h>\n\n" > sysarg
100 printf "#include <sys/acl.h>\n\n" > sysarg
101 printf "#include <sys/msgport.h>\n\n" > sysarg
102 printf "#include <sys/sysmsg.h>\n\n" > sysarg
103 printf "#include <sys/syslink.h>\n\n" > sysarg
104 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
105 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
107 printf "\n#ifdef %s\n\n", compat > syscompat
108 printf "\n#ifdef %s\n\n", compatdf12 > syscompatdf12
110 printf "/*\n * System call names.\n *\n" > sysnames
111 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
112 printf " */\n\n" > sysnames
113 printf "const char *%s[] = {\n", namesname > sysnames
115 printf "/*\n * System call numbers.\n *\n" > syshdr
116 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
117 printf " */\n\n" > syshdr
119 printf "# DragonFly system call names.\n" > sysmk
120 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
121 printf "MIASM = " > sysmk
123 printf "/*\n * System call hiders.\n *\n" > syshide
124 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
125 printf " */\n\n" > syshide
127 printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
128 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysun
129 printf " */\n\n" > sysun
130 printf "union sysunion {\n" > sysun
131 printf "#ifdef _KERNEL /* header only applies in kernel */\n" > sysun
132 printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
133 printf "\tstruct\tsysmsg sysmsg;\n" > sysun
134 printf "#endif\n" > sysun
136 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
137 printf "struct sysent %s[] = {\n",switchname > sysent
139 printf "\n#ifdef _KERNEL\n\n" > sysdcl
140 printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
141 printf "\n#ifdef _KERNEL\n\n" > syscompatdcldf12
143 NF == 0 || $1 ~ /^;/ {
144 next
146 $1 ~ /^#[ ]*include/ {
147 print > sysinc
148 next
150 $1 ~ /^#[ ]*if/ {
151 print > sysent
152 print > sysdcl
153 print > sysarg
154 print > syscompat
155 print > syscompatdf12
156 print > sysnames
157 print > syshide
158 print > sysun
159 savesyscall = syscall
160 next
162 $1 ~ /^#[ ]*else/ {
163 print > sysent
164 print > sysdcl
165 print > sysarg
166 print > sysun
167 print > syscompat
168 print > syscompatdf12
169 print > sysnames
170 print > syshide
171 syscall = savesyscall
172 next
174 $1 ~ /^#/ {
175 print > sysent
176 print > sysdcl
177 print > sysarg
178 print > sysun
179 print > syscompat
180 print > syscompatdf12
181 print > sysnames
182 print > syshide
183 next
185 syscall != $1 {
186 printf "%s: line %d: syscall number out of sync at %d\n",
187 infile, NR, syscall
188 printf "line is:\n"
189 print
190 exit 1
192 function align_sysent_comment(column) {
193 printf("\t") > sysent
194 column = column + 8 - column % 8
195 while (column < 56) {
196 printf("\t") > sysent
197 column = column + 8
200 function parserr(was, wanted) {
201 printf "%s: line %d: unexpected %s (expected %s)\n",
202 infile, NR, was, wanted
203 exit 1
205 function parseline() {
206 f=4 # toss number and type
207 argc= 0;
208 argssize = "0"
209 if ($NF != "}") {
210 funcalias=$(NF-2)
211 argalias=$(NF-1)
212 rettype=$NF
213 end=NF-3
214 } else {
215 funcalias=""
216 argalias=""
217 rettype="int"
218 end=NF
220 if ($2 == "NODEF") {
221 funcname=$4
222 argssize = "AS(" $6 ")"
223 return
225 if ($f != "{")
226 parserr($f, "{")
228 if ($end != "}")
229 parserr($end, "}")
230 end--
231 if ($end != ";")
232 parserr($end, ";")
233 end--
234 if ($end != ")")
235 parserr($end, ")")
236 end--
238 f++ #function return type
240 funcname=$f
241 usefuncname=$f
242 if (funcalias == "")
243 funcalias = funcname
244 if (argalias == "") {
245 argalias = funcname "_args"
246 if ($2 == "COMPAT") {
247 argalias = "o" argalias
248 usefuncname = "sys_o" funcname
250 if ($2 == "COMPAT_DF12") {
251 argalias = "dfbsd12_" argalias
252 usefuncname = "sys_dfbsd12_" funcname
257 if ($f != "(")
258 parserr($f, ")")
261 if (f == end) {
262 if ($f != "void")
263 parserr($f, "argument definition")
264 return
267 while (f <= end) {
268 argc++
269 argtype[argc]=""
270 oldf=""
271 while (f < end && $(f+1) != ",") {
272 if (argtype[argc] != "" && oldf != "*")
273 argtype[argc] = argtype[argc]" ";
274 argtype[argc] = argtype[argc]$f;
275 oldf = $f;
278 if (argtype[argc] == "")
279 parserr($f, "argument definition")
280 argname[argc]=$f;
281 f += 2; # skip name, and any comma
283 if (argc != 0)
284 argssize = "AS(" argalias ")"
286 { comment = $4
287 if (NF < 7)
288 for (i = 5; i <= NF; i++)
289 comment = comment " " $i
291 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
292 || $2 == "NOIMPL" {
293 parseline()
294 if ((!nosys || funcname != "nosys") && \
295 (funcname != "lkmnosys")) {
296 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
297 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
298 printf("struct\t%s {\n", argalias) > sysarg
299 printf("#ifdef _KERNEL\n") > sysarg
300 printf("\tstruct sysmsg sysmsg;\n") > sysarg
301 printf("#endif\n") > sysarg
302 for (i = 1; i <= argc; i++)
303 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
304 argtype[i], argname[i],
305 argname[i], argtype[i]) > sysarg
306 printf("};\n") > sysarg
308 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
309 $2 != "NODEF") {
310 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
311 printf("struct\t%s {\n", argalias) > sysarg
312 printf("#ifdef _KERNEL\n") > sysarg
313 printf("\tstruct sysmsg sysmsg;\n") > sysarg
314 printf("#endif\n") > sysarg
315 printf("\tregister_t dummy;\n") > sysarg
316 printf("};\n") > sysarg
319 if (($2 != "NOPROTO" && $2 != "NODEF" && \
320 (funcname != "nosys" || !nosys)) || \
321 (funcname == "lkmnosys" && !lkmnosys) || \
322 funcname == "lkmressys") {
323 printf("%s\tsys_%s (struct %s *)",
324 rettype, funcname, argalias) > sysdcl
325 printf(";\n") > sysdcl
327 if (funcname == "nosys")
328 nosys = 1
329 if (funcname == "lkmnosys")
330 lkmnosys = 1
331 printf("\t{ %s, (sy_call_t *)", argssize) > sysent
332 column = 8 + 2 + length(argssize) + 15
333 if ($2 != "NOIMPL") {
334 printf("sys_%s },", funcname) > sysent
335 column = column + length(funcname) + 7
336 } else {
337 printf("sys_%s },", "nosys") > sysent
338 column = column + length("nosys") + 7
340 align_sysent_comment(column)
341 printf("/* %d = %s */\n", syscall, funcalias) > sysent
342 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
343 funcalias, syscall, funcalias) > sysnames
344 if ($2 != "NODEF") {
345 printf("#define\t%s%s\t%d\n", syscallprefix,
346 funcalias, syscall) > syshdr
347 printf(" \\\n\t%s.o", funcalias) > sysmk
349 if ($3 != "NOHIDE")
350 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
351 syscall++
352 next
354 $2 == "COMPAT" || $2 == "CPT_NOA" {
355 ncompat++
356 parseline()
357 if (argc != 0 && $2 != "CPT_NOA") {
358 printf("#ifdef %s\n", compat) > sysun
359 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
360 printf("#endif\n") > sysun
361 printf("struct\t%s {\n", argalias) > syscompat
362 printf("#ifdef _KERNEL\n") > syscompat
363 printf("\tstruct sysmsg sysmsg;\n") > syscompat
364 printf("#endif\n") > syscompat
365 for (i = 1; i <= argc; i++)
366 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
367 argtype[i], argname[i],
368 argname[i], argtype[i]) > syscompat
369 printf("};\n") > syscompat
371 else if($2 != "CPT_NOA") {
372 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
373 printf("struct\t%s {\n", argalias) > sysarg
374 printf("#ifdef _KERNEL\n") > sysarg
375 printf("\tstruct sysmsg sysmsg;\n") > sysarg
376 printf("#endif\n") > sysarg
377 printf("\tregister_t dummy;\n") > sysarg
378 printf("};\n") > sysarg
380 printf("%s\tsys_o%s (struct %s *);\n",
381 rettype, funcname, argalias) > syscompatdcl
382 printf("\t{ compat(%s,%s) },",
383 argssize, funcname) > sysent
384 align_sysent_comment(8 + 9 + \
385 length(argssize) + 1 + length(funcname) + 4)
386 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
387 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
388 funcalias, syscall, funcalias) > sysnames
389 printf("\t\t\t\t/* %d is old %s */\n",
390 syscall, funcalias) > syshdr
391 if ($3 != "NOHIDE")
392 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
393 syscall++
394 next
396 $2 == "COMPAT_DF12" {
397 ncompatdf12++
398 parseline()
399 if (argc != 0) {
400 printf("#ifdef %s\n", compatdf12) > sysun
401 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
402 printf("#endif\n") > sysun
403 printf("struct\t%s {\n", argalias) > syscompatdf12
404 printf("#ifdef _KERNEL\n") > syscompatdf12
405 printf("\tstruct sysmsg sysmsg;\n") > syscompatdf12
406 printf("#endif\n") > syscompatdf12
407 for (i = 1; i <= argc; i++)
408 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
409 argtype[i], argname[i],
410 argname[i], argtype[i]) > syscompatdf12
411 printf("};\n") > syscompatdf12
413 else {
414 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
415 printf("struct\t%s {\n", argalias) > sysarg
416 printf("#ifdef _KERNEL\n") > sysarg
417 printf("\tstruct sysmsg sysmsg;\n") > sysarg
418 printf("#endif\n") > sysarg
419 printf("\tregister_t dummy;\n") > sysarg
420 printf("};\n") > sysarg
422 printf("%s\tsys_dfbsd12_%s (struct %s *);\n",
423 rettype, funcname, argalias) > syscompatdcldf12
424 printf("\t{ compatdf12(%s,%s) },",
425 argssize, funcname) > sysent
426 align_sysent_comment(8 + 9 + \
427 length(argssize) + 1 + length(funcname) + 4)
428 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
429 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
430 funcalias, syscall, funcalias) > sysnames
431 printf("\t\t\t\t/* %d is old %s */\n",
432 syscall, funcalias) > syshdr
433 if ($3 != "NOHIDE")
434 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
435 syscall++
436 next
438 $2 == "LIBCOMPAT" {
439 ncompat++
440 parseline()
441 printf("%s\tsys_o%s();\n", rettype, funcname) > syscompatdcl
442 printf("\t{ compat(%s,%s) },",
443 argssize, funcname) > sysent
444 align_sysent_comment(8 + 9 + \
445 length(argssize) + 1 + length(funcname) + 4)
446 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
447 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
448 funcalias, syscall, funcalias) > sysnames
449 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
450 syscallprefix, funcalias, syscall) > syshdr
451 printf(" \\\n\t%s.o", funcalias) > sysmk
452 if ($3 != "NOHIDE")
453 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
454 syscall++
455 next
457 $2 == "OBSOL" {
458 printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
459 align_sysent_comment(37)
460 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
461 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
462 $4, syscall, comment) > sysnames
463 printf("\t\t\t\t/* %d is obsolete %s */\n",
464 syscall, comment) > syshdr
465 if ($3 != "NOHIDE")
466 printf("HIDE_%s(%s)\n", $3, $4) > syshide
467 syscall++
468 next
470 $2 == "UNIMPL" {
471 printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
472 syscall, comment) > sysent
473 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
474 syscall, syscall, comment) > sysnames
475 if ($3 != "NOHIDE")
476 printf("HIDE_%s(%s)\n", $3, $4) > syshide
477 syscall++
478 next
481 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
482 exit 1
484 END {
485 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
486 if (ncompat != 0) {
487 printf "#include \"opt_compat.h\"\n\n" > syssw
488 printf "\n#ifdef %s\n", compat > sysinc
489 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(o,name))\n" > sysinc
490 printf "#else\n" > sysinc
491 printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
492 printf "#endif\n" > sysinc
495 if (ncompatdf12 != 0) {
496 printf "#include \"opt_compatdf12.h\"\n\n" > syssw
497 printf "\n#ifdef %s\n", compatdf12 > sysinc
498 printf "#define compatdf12(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(dfbsd12_,name))\n" > sysinc
499 printf "#else\n" > sysinc
500 printf "#define compatdf12(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
501 printf "#endif\n" > sysinc
504 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
505 printf("\n#endif /* _KERNEL */\n") > syscompatdcldf12
506 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
507 printf("\n#endif /* %s */\n\n", compatdf12) > syscompatdcldf12
509 printf("\n") > sysmk
510 printf("};\n") > sysent
511 printf("};\n") > sysnames
512 printf("};\n") > sysun
513 printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
514 printf("#undef PAD_\n") > sysdcl
515 printf("\n#endif /* _KERNEL */\n") > sysdcl
516 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
517 > syshdr
520 cat $sysinc $sysent >> $syssw
521 cat $sysarg $syscompat $syscompatdcl $syscompatdf12 $syscompatdcldf12 $sysdcl > $sysproto
522 cat $sysun > $sysunion