devfs - Change make_dev_covering to use dev_ops
[dragonfly.git] / sys / kern / makesyscalls.sh
blobe033b7448310093056448ac9c78fb9ddd278360c
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 # if the "MPSAFE" keyword is found, note it and shift the line
292 mpsafe = ""
293 $2 == "MPSAFE" {
294 for (i = 2; i <= NF; i++)
295 $i = $(i + 1);
296 NF -= 1;
297 mpsafe = "SYF_MPSAFE | "
299 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
300 || $2 == "NOIMPL" {
301 parseline()
302 if ((!nosys || funcname != "nosys") && \
303 (funcname != "lkmnosys")) {
304 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
305 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
306 printf("struct\t%s {\n", argalias) > sysarg
307 printf("#ifdef _KERNEL\n") > sysarg
308 printf("\tstruct sysmsg sysmsg;\n") > sysarg
309 printf("#endif\n") > sysarg
310 for (i = 1; i <= argc; i++)
311 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
312 argtype[i], argname[i],
313 argname[i], argtype[i]) > sysarg
314 printf("};\n") > sysarg
316 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
317 $2 != "NODEF") {
318 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
319 printf("struct\t%s {\n", argalias) > sysarg
320 printf("#ifdef _KERNEL\n") > sysarg
321 printf("\tstruct sysmsg sysmsg;\n") > sysarg
322 printf("#endif\n") > sysarg
323 printf("\tregister_t dummy;\n") > sysarg
324 printf("};\n") > sysarg
327 if (($2 != "NOPROTO" && $2 != "NODEF" && \
328 (funcname != "nosys" || !nosys)) || \
329 (funcname == "lkmnosys" && !lkmnosys) || \
330 funcname == "lkmressys") {
331 printf("%s\tsys_%s (struct %s *)",
332 rettype, funcname, argalias) > sysdcl
333 printf(";\n") > sysdcl
335 if (funcname == "nosys")
336 nosys = 1
337 if (funcname == "lkmnosys")
338 lkmnosys = 1
339 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
340 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
341 if ($2 != "NOIMPL") {
342 printf("sys_%s },", funcname) > sysent
343 column = column + length(funcname) + 7
344 } else {
345 printf("sys_%s },", "nosys") > sysent
346 column = column + length("nosys") + 7
348 align_sysent_comment(column)
349 printf("/* %d = %s */\n", syscall, funcalias) > sysent
350 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
351 funcalias, syscall, funcalias) > sysnames
352 if ($2 != "NODEF") {
353 printf("#define\t%s%s\t%d\n", syscallprefix,
354 funcalias, syscall) > syshdr
355 printf(" \\\n\t%s.o", funcalias) > sysmk
357 if ($3 != "NOHIDE")
358 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
359 syscall++
360 next
362 $2 == "COMPAT" || $2 == "CPT_NOA" {
363 ncompat++
364 parseline()
365 if (argc != 0 && $2 != "CPT_NOA") {
366 printf("#ifdef %s\n", compat) > sysun
367 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
368 printf("#endif\n") > sysun
369 printf("struct\t%s {\n", argalias) > syscompat
370 printf("#ifdef _KERNEL\n") > syscompat
371 printf("\tstruct sysmsg sysmsg;\n") > syscompat
372 printf("#endif\n") > syscompat
373 for (i = 1; i <= argc; i++)
374 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
375 argtype[i], argname[i],
376 argname[i], argtype[i]) > syscompat
377 printf("};\n") > syscompat
379 else if($2 != "CPT_NOA") {
380 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
381 printf("struct\t%s {\n", argalias) > sysarg
382 printf("#ifdef _KERNEL\n") > sysarg
383 printf("\tstruct sysmsg sysmsg;\n") > sysarg
384 printf("#endif\n") > sysarg
385 printf("\tregister_t dummy;\n") > sysarg
386 printf("};\n") > sysarg
388 printf("%s\tsys_o%s (struct %s *);\n",
389 rettype, funcname, argalias) > syscompatdcl
390 printf("\t{ compat(%s%s,%s) },",
391 mpsafe, argssize, funcname) > sysent
392 align_sysent_comment(8 + 9 + length(mpsafe) + \
393 length(argssize) + 1 + length(funcname) + 4)
394 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
395 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
396 funcalias, syscall, funcalias) > sysnames
397 printf("\t\t\t\t/* %d is old %s */\n",
398 syscall, funcalias) > syshdr
399 if ($3 != "NOHIDE")
400 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
401 syscall++
402 next
404 $2 == "COMPAT_DF12" {
405 ncompatdf12++
406 parseline()
407 if (argc != 0) {
408 printf("#ifdef %s\n", compatdf12) > sysun
409 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
410 printf("#endif\n") > sysun
411 printf("struct\t%s {\n", argalias) > syscompatdf12
412 printf("#ifdef _KERNEL\n") > syscompatdf12
413 printf("\tstruct sysmsg sysmsg;\n") > syscompatdf12
414 printf("#endif\n") > syscompatdf12
415 for (i = 1; i <= argc; i++)
416 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
417 argtype[i], argname[i],
418 argname[i], argtype[i]) > syscompatdf12
419 printf("};\n") > syscompatdf12
421 else {
422 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
423 printf("struct\t%s {\n", argalias) > sysarg
424 printf("#ifdef _KERNEL\n") > sysarg
425 printf("\tstruct sysmsg sysmsg;\n") > sysarg
426 printf("#endif\n") > sysarg
427 printf("\tregister_t dummy;\n") > sysarg
428 printf("};\n") > sysarg
430 printf("%s\tsys_dfbsd12_%s (struct %s *);\n",
431 rettype, funcname, argalias) > syscompatdcldf12
432 printf("\t{ compatdf12(%s%s,%s) },",
433 mpsafe, argssize, funcname) > sysent
434 align_sysent_comment(8 + 9 + length(mpsafe) + \
435 length(argssize) + 1 + length(funcname) + 4)
436 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
437 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
438 funcalias, syscall, funcalias) > sysnames
439 printf("\t\t\t\t/* %d is old %s */\n",
440 syscall, funcalias) > syshdr
441 if ($3 != "NOHIDE")
442 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
443 syscall++
444 next
446 $2 == "LIBCOMPAT" {
447 ncompat++
448 parseline()
449 printf("%s\tsys_o%s();\n", rettype, funcname) > syscompatdcl
450 printf("\t{ compat(%s%s,%s) },",
451 mpsafe, argssize, funcname) > sysent
452 align_sysent_comment(8 + 9 + length(mpsafe) + \
453 length(argssize) + 1 + length(funcname) + 4)
454 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
455 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
456 funcalias, syscall, funcalias) > sysnames
457 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
458 syscallprefix, funcalias, syscall) > syshdr
459 printf(" \\\n\t%s.o", funcalias) > sysmk
460 if ($3 != "NOHIDE")
461 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
462 syscall++
463 next
465 $2 == "OBSOL" {
466 printf("\t{ 0, (sy_call_t *)sys_nosys },") > sysent
467 align_sysent_comment(37)
468 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
469 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
470 $4, syscall, comment) > sysnames
471 printf("\t\t\t\t/* %d is obsolete %s */\n",
472 syscall, comment) > syshdr
473 if ($3 != "NOHIDE")
474 printf("HIDE_%s(%s)\n", $3, $4) > syshide
475 syscall++
476 next
478 $2 == "UNIMPL" {
479 printf("\t{ 0, (sy_call_t *)sys_nosys },\t\t\t/* %d = %s */\n",
480 syscall, comment) > sysent
481 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
482 syscall, syscall, comment) > sysnames
483 if ($3 != "NOHIDE")
484 printf("HIDE_%s(%s)\n", $3, $4) > syshide
485 syscall++
486 next
489 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
490 exit 1
492 END {
493 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(struct sysmsg)) / sizeof(register_t))\n" > sysinc
494 if (ncompat != 0) {
495 printf "#include \"opt_compat.h\"\n\n" > syssw
496 printf "\n#ifdef %s\n", compat > sysinc
497 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(o,name))\n" > sysinc
498 printf "#else\n" > sysinc
499 printf "#define compat(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
500 printf "#endif\n" > sysinc
503 if (ncompatdf12 != 0) {
504 printf "#include \"opt_compatdf12.h\"\n\n" > syssw
505 printf "\n#ifdef %s\n", compatdf12 > sysinc
506 printf "#define compatdf12(n, name) n, (sy_call_t *)__CONCAT(sys_,__CONCAT(dfbsd12_,name))\n" > sysinc
507 printf "#else\n" > sysinc
508 printf "#define compatdf12(n, name) 0, (sy_call_t *)sys_nosys\n" > sysinc
509 printf "#endif\n" > sysinc
512 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
513 printf("\n#endif /* _KERNEL */\n") > syscompatdcldf12
514 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
515 printf("\n#endif /* %s */\n\n", compatdf12) > syscompatdcldf12
517 printf("\n") > sysmk
518 printf("};\n") > sysent
519 printf("};\n") > sysnames
520 printf("};\n") > sysun
521 printf("\n#endif /* !%s */\n", sysproto_h) > sysdcl
522 printf("#undef PAD_\n") > sysdcl
523 printf("\n#endif /* _KERNEL */\n") > sysdcl
524 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
525 > syshdr
528 cat $sysinc $sysent >> $syssw
529 cat $sysarg $syscompat $syscompatdcl $syscompatdf12 $syscompatdcldf12 $sysdcl > $sysproto
530 cat $sysun > $sysunion