We only need to determine the softlink_dir when no filesystem is
[dragonfly.git] / sys / kern / makesyscalls.sh
blob507676930f762712b64ccee721817d50b64e6ad6
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 $syscompatdf12 $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 " * \$\DragonFly\$\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 " * \$\DragonFly\$\n" > sysarg
97 printf "\n#ifdef %s\n\n", compat > syscompat
98 printf "\n#ifdef %s\n\n", compatdf12 > syscompatdf12
100 printf "/*\n * System call names.\n *\n" > sysnames
101 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
102 printf " * \$\DragonFly\$\n" > sysnames
104 printf "/*\n * System call numbers.\n *\n" > syshdr
105 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
106 printf " * \$\DragonFly\$\n" > syshdr
107 printf "# DragonFly system call names.\n" > sysmk
108 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
109 printf "# \$\DragonFly\$\n" > sysmk
110 printf "/*\n * System call hiders.\n *\n" > syshide
111 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
112 printf " * \$\DragonFly\$\n" > syshide
114 printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
115 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysun
116 printf " * \$\DragonFly\$\n" > sysun
117 printf "\n#ifdef _KERNEL\n\n" > sysdcl
118 printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
119 printf "\n#ifdef _KERNEL\n\n" > syscompatdcldf12
121 NR == 1 {
122 gsub("[$]DragonFly: ", "", $0)
123 gsub(" [$]", "", $0)
125 printf " * created from%s\n */\n\n", $0 > syssw
127 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
128 printf "struct sysent %s[] = {\n",switchname > sysent
130 printf " * created from%s\n */\n\n", $0 > sysarg
131 printf "#ifndef %s\n", sysproto_h > sysarg
132 printf "#define\t%s\n\n", sysproto_h > sysarg
133 printf "#include <sys/select.h>\n\n" > sysarg
134 printf "#include <sys/signal.h>\n\n" > sysarg
135 printf "#include <sys/acl.h>\n\n" > sysarg
136 printf "#include <sys/msgport.h>\n\n" > sysarg
137 printf "#include <sys/sysmsg.h>\n\n" > sysarg
138 printf "#include <sys/syslink.h>\n\n" > sysarg
139 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
140 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
142 printf " * created from%s\n */\n\n", $0 > sysnames
143 printf "char *%s[] = {\n", namesname > sysnames
145 printf " * created from%s\n */\n\n", $0 > syshdr
147 printf "# created from%s\nMIASM = ", $0 > sysmk
149 printf " * created from%s\n */\n\n", $0 > syshide
150 printf " * created from%s\n */\n\n", $0 > sysun
151 printf "union sysunion {\n" > sysun
152 printf "#ifdef _KERNEL /* header only applies in kernel */\n" > sysun
153 printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
154 printf "\tstruct\tsysmsg sysmsg;\n" > sysun
155 printf "#endif\n" > sysun
157 next
159 NF == 0 || $1 ~ /^;/ {
160 next
162 $1 ~ /^#[ ]*include/ {
163 print > sysinc
164 next
166 $1 ~ /^#[ ]*if/ {
167 print > sysent
168 print > sysdcl
169 print > sysarg
170 print > syscompat
171 print > syscompatdf12
172 print > sysnames
173 print > syshide
174 print > sysun
175 savesyscall = syscall
176 next
178 $1 ~ /^#[ ]*else/ {
179 print > sysent
180 print > sysdcl
181 print > sysarg
182 print > sysun
183 print > syscompat
184 print > syscompatdf12
185 print > sysnames
186 print > syshide
187 syscall = savesyscall
188 next
190 $1 ~ /^#/ {
191 print > sysent
192 print > sysdcl
193 print > sysarg
194 print > sysun
195 print > syscompat
196 print > syscompatdf12
197 print > sysnames
198 print > syshide
199 next
201 syscall != $1 {
202 printf "%s: line %d: syscall number out of sync at %d\n",
203 infile, NR, syscall
204 printf "line is:\n"
205 print
206 exit 1
208 function align_sysent_comment(column) {
209 printf("\t") > sysent
210 column = column + 8 - column % 8
211 while (column < 56) {
212 printf("\t") > sysent
213 column = column + 8
216 function parserr(was, wanted) {
217 printf "%s: line %d: unexpected %s (expected %s)\n",
218 infile, NR, was, wanted
219 exit 1
221 function parseline() {
222 f=4 # toss number and type
223 argc= 0;
224 argssize = "0"
225 if ($NF != "}") {
226 funcalias=$(NF-2)
227 argalias=$(NF-1)
228 rettype=$NF
229 end=NF-3
230 } else {
231 funcalias=""
232 argalias=""
233 rettype="int"
234 end=NF
236 if ($2 == "NODEF") {
237 funcname=$4
238 argssize = "AS(" $6 ")"
239 return
241 if ($f != "{")
242 parserr($f, "{")
244 if ($end != "}")
245 parserr($end, "}")
246 end--
247 if ($end != ";")
248 parserr($end, ";")
249 end--
250 if ($end != ")")
251 parserr($end, ")")
252 end--
254 f++ #function return type
256 funcname=$f
257 usefuncname=$f
258 if (funcalias == "")
259 funcalias = funcname
260 if (argalias == "") {
261 argalias = funcname "_args"
262 if ($2 == "COMPAT") {
263 argalias = "o" argalias
264 usefuncname = "sys_o" funcname
266 if ($2 == "COMPAT_DF12") {
267 argalias = "dfbsd12_" argalias
268 usefuncname = "sys_dfbsd12_" funcname
273 if ($f != "(")
274 parserr($f, ")")
277 if (f == end) {
278 if ($f != "void")
279 parserr($f, "argument definition")
280 return
283 while (f <= end) {
284 argc++
285 argtype[argc]=""
286 oldf=""
287 while (f < end && $(f+1) != ",") {
288 if (argtype[argc] != "" && oldf != "*")
289 argtype[argc] = argtype[argc]" ";
290 argtype[argc] = argtype[argc]$f;
291 oldf = $f;
294 if (argtype[argc] == "")
295 parserr($f, "argument definition")
296 argname[argc]=$f;
297 f += 2; # skip name, and any comma
299 if (argc != 0)
300 argssize = "AS(" argalias ")"
302 { comment = $4
303 if (NF < 7)
304 for (i = 5; i <= NF; i++)
305 comment = comment " " $i
307 # if the "MPSAFE" keyword is found, note it and shift the line
308 mpsafe = ""
309 $2 == "MPSAFE" {
310 for (i = 2; i <= NF; i++)
311 $i = $(i + 1);
312 NF -= 1;
313 mpsafe = "SYF_MPSAFE | "
315 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
316 || $2 == "NOIMPL" {
317 parseline()
318 if ((!nosys || funcname != "nosys") && \
319 (funcname != "lkmnosys")) {
320 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
321 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
322 printf("struct\t%s {\n", argalias) > sysarg
323 printf("#ifdef _KERNEL\n") > sysarg
324 printf("\tstruct sysmsg sysmsg;\n") > sysarg
325 printf("#endif\n") > sysarg
326 for (i = 1; i <= argc; i++)
327 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
328 argtype[i], argname[i],
329 argname[i], argtype[i]) > sysarg
330 printf("};\n") > sysarg
332 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
333 $2 != "NODEF") {
334 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
335 printf("struct\t%s {\n", argalias) > sysarg
336 printf("#ifdef _KERNEL\n") > sysarg
337 printf("\tstruct sysmsg sysmsg;\n") > sysarg
338 printf("#endif\n") > sysarg
339 printf("\tregister_t dummy;\n") > sysarg
340 printf("};\n") > sysarg
343 if (($2 != "NOPROTO" && $2 != "NODEF" && \
344 (funcname != "nosys" || !nosys)) || \
345 (funcname == "lkmnosys" && !lkmnosys) || \
346 funcname == "lkmressys") {
347 printf("%s\tsys_%s (struct %s *)",
348 rettype, funcname, argalias) > sysdcl
349 printf(";\n") > sysdcl
351 if (funcname == "nosys")
352 nosys = 1
353 if (funcname == "lkmnosys")
354 lkmnosys = 1
355 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
356 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
357 if ($2 != "NOIMPL") {
358 printf("sys_%s },", funcname) > sysent
359 column = column + length(funcname) + 7
360 } else {
361 printf("sys_%s },", "nosys") > sysent
362 column = column + length("nosys") + 7
364 align_sysent_comment(column)
365 printf("/* %d = %s */\n", syscall, funcalias) > sysent
366 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
367 funcalias, syscall, funcalias) > sysnames
368 if ($2 != "NODEF") {
369 printf("#define\t%s%s\t%d\n", syscallprefix,
370 funcalias, syscall) > syshdr
371 printf(" \\\n\t%s.o", funcalias) > sysmk
373 if ($3 != "NOHIDE")
374 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
375 syscall++
376 next
378 $2 == "COMPAT" || $2 == "CPT_NOA" {
379 ncompat++
380 parseline()
381 if (argc != 0 && $2 != "CPT_NOA") {
382 printf("#ifdef %s\n", compat) > sysun
383 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
384 printf("#endif\n") > sysun
385 printf("struct\t%s {\n", argalias) > syscompat
386 printf("#ifdef _KERNEL\n") > syscompat
387 printf("\tstruct sysmsg sysmsg;\n") > syscompat
388 printf("#endif\n") > syscompat
389 for (i = 1; i <= argc; i++)
390 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
391 argtype[i], argname[i],
392 argname[i], argtype[i]) > syscompat
393 printf("};\n") > syscompat
395 else if($2 != "CPT_NOA") {
396 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
397 printf("struct\t%s {\n", argalias) > sysarg
398 printf("#ifdef _KERNEL\n") > sysarg
399 printf("\tstruct sysmsg sysmsg;\n") > sysarg
400 printf("#endif\n") > sysarg
401 printf("\tregister_t dummy;\n") > sysarg
402 printf("};\n") > sysarg
404 printf("%s\tsys_o%s (struct %s *);\n",
405 rettype, funcname, argalias) > syscompatdcl
406 printf("\t{ compat(%s%s,%s) },",
407 mpsafe, argssize, funcname) > sysent
408 align_sysent_comment(8 + 9 + length(mpsafe) + \
409 length(argssize) + 1 + length(funcname) + 4)
410 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
411 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
412 funcalias, syscall, funcalias) > sysnames
413 printf("\t\t\t\t/* %d is old %s */\n",
414 syscall, funcalias) > syshdr
415 if ($3 != "NOHIDE")
416 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
417 syscall++
418 next
420 $2 == "COMPAT_DF12" {
421 ncompatdf12++
422 parseline()
423 if (argc != 0) {
424 printf("#ifdef %s\n", compatdf12) > sysun
425 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
426 printf("#endif\n") > sysun
427 printf("struct\t%s {\n", argalias) > syscompatdf12
428 printf("#ifdef _KERNEL\n") > syscompatdf12
429 printf("\tstruct sysmsg sysmsg;\n") > syscompatdf12
430 printf("#endif\n") > syscompatdf12
431 for (i = 1; i <= argc; i++)
432 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
433 argtype[i], argname[i],
434 argname[i], argtype[i]) > syscompatdf12
435 printf("};\n") > syscompatdf12
437 else {
438 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
439 printf("struct\t%s {\n", argalias) > sysarg
440 printf("#ifdef _KERNEL\n") > sysarg
441 printf("\tstruct sysmsg sysmsg;\n") > sysarg
442 printf("#endif\n") > sysarg
443 printf("\tregister_t dummy;\n") > sysarg
444 printf("};\n") > sysarg
446 printf("%s\tsys_dfbsd12_%s (struct %s *);\n",
447 rettype, funcname, argalias) > syscompatdcldf12
448 printf("\t{ compatdf12(%s%s,%s) },",
449 mpsafe, argssize, funcname) > sysent
450 align_sysent_comment(8 + 9 + length(mpsafe) + \
451 length(argssize) + 1 + length(funcname) + 4)
452 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
453 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
454 funcalias, syscall, funcalias) > sysnames
455 printf("\t\t\t\t/* %d is old %s */\n",
456 syscall, funcalias) > syshdr
457 if ($3 != "NOHIDE")
458 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
459 syscall++
460 next
462 $2 == "LIBCOMPAT" {
463 ncompat++
464 parseline()
465 printf("%s\tsys_o%s();\n", rettype, funcname) > syscompatdcl
466 printf("\t{ compat(%s%s,%s) },",
467 mpsafe, argssize, funcname) > sysent
468 align_sysent_comment(8 + 9 + length(mpsafe) + \
469 length(argssize) + 1 + length(funcname) + 4)
470 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
471 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
472 funcalias, syscall, funcalias) > sysnames
473 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
474 syscallprefix, funcalias, syscall) > syshdr
475 printf(" \\\n\t%s.o", funcalias) > sysmk
476 if ($3 != "NOHIDE")
477 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
478 syscall++
479 next
481 $2 == "OBSOL" {
482 printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
483 align_sysent_comment(37)
484 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
485 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
486 $4, syscall, comment) > sysnames
487 printf("\t\t\t\t/* %d is obsolete %s */\n",
488 syscall, comment) > syshdr
489 if ($3 != "NOHIDE")
490 printf("HIDE_%s(%s)\n", $3, $4) > syshide
491 syscall++
492 next
494 $2 == "UNIMPL" {
495 printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
496 syscall, comment) > sysent
497 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
498 syscall, syscall, comment) > sysnames
499 if ($3 != "NOHIDE")
500 printf("HIDE_%s(%s)\n", $3, $4) > syshide
501 syscall++
502 next
505 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
506 exit 1
508 END {
509 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
510 if (ncompat != 0) {
511 printf "#include \"opt_compat.h\"\n\n" > syssw
512 printf "\n#ifdef %s\n", compat > sysinc
513 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(o,name))\n" > sysinc
514 printf "#else\n" > sysinc
515 printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
516 printf "#endif\n" > sysinc
519 if (ncompatdf12 != 0) {
520 printf "#include \"opt_compatdf12.h\"\n\n" > syssw
521 printf "\n#ifdef %s\n", compatdf12 > sysinc
522 printf "#define compatdf12(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(dfbsd12_,name))\n" > sysinc
523 printf "#else\n" > sysinc
524 printf "#define compatdf12(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
525 printf "#endif\n" > sysinc
528 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
529 printf("\n#endif /* _KERNEL */\n") > syscompatdcldf12
530 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
531 printf("\n#endif /* %s */\n\n", compatdf12) > syscompatdcldf12
533 printf("\n") > sysmk
534 printf("};\n") > sysent
535 printf("};\n") > sysnames
536 printf("};\n") > sysun
537 printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
538 printf("#undef PAD_\n") > sysdcl
539 printf("\n#endif /* _KERNEL */\n") > sysdcl
540 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
541 > syshdr
544 cat $sysinc $sysent >> $syssw
545 cat $sysarg $syscompat $syscompatdcl $syscompatdf12 $syscompatdcldf12 $sysdcl > $sysproto
546 cat $sysun > $sysunion