fkvm_get_regs: missing break in switch statement
[freebsd-src/fkvm-freebsd.git] / sys / kern / makesyscalls.sh
blob74737f2d2df36d81d5e60ed8bbfb7c8d483f270b
1 #! /bin/sh -
2 # @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3 # $FreeBSD$
5 set -e
7 # name of compat options:
8 compat=COMPAT_43
9 compat4=COMPAT_FREEBSD4
10 compat6=COMPAT_FREEBSD6
12 # output files:
13 sysnames="syscalls.c"
14 sysproto="../sys/sysproto.h"
15 sysproto_h=_SYS_SYSPROTO_H_
16 syshdr="../sys/syscall.h"
17 sysmk="../sys/syscall.mk"
18 syssw="init_sysent.c"
19 syscallprefix="SYS_"
20 switchname="sysent"
21 namesname="syscallnames"
22 systrace="systrace_args.c"
24 # tmp files:
25 sysaue="sysent.aue.$$"
26 sysdcl="sysent.dcl.$$"
27 syscompat="sysent.compat.$$"
28 syscompatdcl="sysent.compatdcl.$$"
29 syscompat4="sysent.compat4.$$"
30 syscompat4dcl="sysent.compat4dcl.$$"
31 syscompat6="sysent.compat6.$$"
32 syscompat6dcl="sysent.compat6dcl.$$"
33 sysent="sysent.switch.$$"
34 sysinc="sysinc.switch.$$"
35 sysarg="sysarg.switch.$$"
36 sysprotoend="sysprotoend.$$"
37 systracetmp="systrace.$$"
39 trap "rm $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp" 0
41 touch $sysaue $sysdcl $syscompat $syscompatdcl $syscompat4 $syscompat4dcl $syscompat6 $syscompat6dcl $sysent $sysinc $sysarg $sysprotoend $systracetmp
43 case $# in
44 0) echo "usage: $0 input-file <config-file>" 1>&2
45 exit 1
47 esac
49 if [ -n "$2" -a -f "$2" ]; then
50 . $2
53 sed -e '
54 s/\$//g
55 :join
56 /\\$/{a\
59 s/\\\n//
60 b join
62 2,${
63 /^#/!s/\([{}()*,]\)/ \1 /g
65 ' < $1 | awk "
66 BEGIN {
67 sysaue = \"$sysaue\"
68 sysdcl = \"$sysdcl\"
69 sysproto = \"$sysproto\"
70 sysprotoend = \"$sysprotoend\"
71 sysproto_h = \"$sysproto_h\"
72 syscompat = \"$syscompat\"
73 syscompatdcl = \"$syscompatdcl\"
74 syscompat4 = \"$syscompat4\"
75 syscompat4dcl = \"$syscompat4dcl\"
76 syscompat6 = \"$syscompat6\"
77 syscompat6dcl = \"$syscompat6dcl\"
78 sysent = \"$sysent\"
79 syssw = \"$syssw\"
80 sysinc = \"$sysinc\"
81 sysarg = \"$sysarg\"
82 sysnames = \"$sysnames\"
83 syshdr = \"$syshdr\"
84 sysmk = \"$sysmk\"
85 systrace = \"$systrace\"
86 systracetmp = \"$systracetmp\"
87 compat = \"$compat\"
88 compat4 = \"$compat4\"
89 compat6 = \"$compat6\"
90 syscallprefix = \"$syscallprefix\"
91 switchname = \"$switchname\"
92 namesname = \"$namesname\"
93 infile = \"$1\"
96 printf "/*\n * System call switch table.\n *\n" > syssw
97 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
98 printf " * $%s$\n", "FreeBSD" > syssw
100 printf "/*\n * System call prototypes.\n *\n" > sysarg
101 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
102 printf " * $%s$\n", "FreeBSD" > sysarg
104 printf "\n#ifdef %s\n\n", compat > syscompat
105 printf "\n#ifdef %s\n\n", compat4 > syscompat4
106 printf "\n#ifdef %s\n\n", compat6 > syscompat6
108 printf "/*\n * System call names.\n *\n" > sysnames
109 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
110 printf " * $%s$\n", "FreeBSD" > sysnames
112 printf "/*\n * System call numbers.\n *\n" > syshdr
113 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
114 printf " * $%s$\n", "FreeBSD" > syshdr
115 printf "# FreeBSD system call names.\n" > sysmk
116 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
117 printf "# $%s$\n", "FreeBSD" > sysmk
119 printf "/*\n * System call argument to DTrace register array converstion.\n *\n" > systrace
120 printf " * DO NOT EDIT-- this file is automatically generated.\n" > systrace
121 printf " * $%s$\n", "FreeBSD" > systrace
123 NR == 1 {
124 gsub("[$]FreeBSD: ", "", $0)
125 gsub(" [$]", "", $0)
127 printf " * created from%s\n */\n\n", $0 > syssw
129 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
130 printf "struct sysent %s[] = {\n",switchname > sysent
132 printf " * created from%s\n */\n\n", $0 > sysarg
133 printf "#ifndef %s\n", sysproto_h > sysarg
134 printf "#define\t%s\n\n", sysproto_h > sysarg
135 printf "#include <sys/signal.h>\n" > sysarg
136 printf "#include <sys/acl.h>\n" > sysarg
137 printf "#include <sys/cpuset.h>\n" > sysarg
138 printf "#include <sys/_semaphore.h>\n" > sysarg
139 printf "#include <sys/ucontext.h>\n\n" > sysarg
140 printf "#include <bsm/audit_kevents.h>\n\n" > sysarg
141 printf "struct proc;\n\n" > sysarg
142 printf "struct thread;\n\n" > sysarg
143 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
144 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
145 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
146 printf "#define\tPADL_(t)\t0\n" > sysarg
147 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
148 printf "#else\n" > sysarg
149 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
150 printf "#define\tPADR_(t)\t0\n" > sysarg
151 printf "#endif\n\n" > sysarg
153 printf " * created from%s\n */\n\n", $0 > sysnames
154 printf "const char *%s[] = {\n", namesname > sysnames
156 printf " * created from%s\n */\n\n", $0 > syshdr
158 printf "# created from%s\nMIASM = ", $0 > sysmk
160 printf " * This file is part of the DTrace syscall provider.\n */\n\n" > systrace
161 printf "static void\nsystrace_args(int sysnum, void *params, u_int64_t *uarg, int *n_args)\n{\n" > systrace
162 printf "\tint64_t *iarg = (int64_t *) uarg;\n" > systrace
163 printf "\tswitch (sysnum) {\n" > systrace
165 printf "static void\nsystrace_setargdesc(int sysnum, int ndx, char *desc, size_t descsz)\n{\n\tconst char *p = NULL;\n" > systracetmp
166 printf "\tswitch (sysnum) {\n" > systracetmp
168 next
170 NF == 0 || $1 ~ /^;/ {
171 next
173 $1 ~ /^#[ ]*include/ {
174 print > sysinc
175 next
177 $1 ~ /^#[ ]*if/ {
178 print > sysent
179 print > sysdcl
180 print > sysarg
181 print > syscompat
182 print > syscompat4
183 print > syscompat6
184 print > sysnames
185 savesyscall = syscall
186 next
188 $1 ~ /^#[ ]*else/ {
189 print > sysent
190 print > sysdcl
191 print > sysarg
192 print > syscompat
193 print > syscompat4
194 print > syscompat6
195 print > sysnames
196 syscall = savesyscall
197 next
199 $1 ~ /^#/ {
200 print > sysent
201 print > sysdcl
202 print > sysarg
203 print > syscompat
204 print > syscompat4
205 print > syscompat6
206 print > sysnames
207 next
209 syscall != $1 {
210 printf "%s: line %d: syscall number out of sync at %d\n",
211 infile, NR, syscall
212 printf "line is:\n"
213 print
214 exit 1
216 function align_sysent_comment(column) {
217 printf("\t") > sysent
218 column = column + 8 - column % 8
219 while (column < 56) {
220 printf("\t") > sysent
221 column = column + 8
224 function parserr(was, wanted) {
225 printf "%s: line %d: unexpected %s (expected %s)\n",
226 infile, NR, was, wanted
227 exit 1
229 function parseline() {
230 f=4 # toss number, type, audit event
231 argc= 0;
232 argssize = "0"
233 if ($NF != "}") {
234 funcalias=$(NF-2)
235 argalias=$(NF-1)
236 rettype=$NF
237 end=NF-3
238 } else {
239 funcalias=""
240 argalias=""
241 rettype="int"
242 end=NF
244 if ($3 == "NODEF") {
245 auditev="AUE_NULL"
246 funcname=$4
247 argssize = "AS(" $6 ")"
248 return
250 if ($f != "{")
251 parserr($f, "{")
253 if ($end != "}")
254 parserr($end, "}")
255 end--
256 if ($end != ";")
257 parserr($end, ";")
258 end--
259 if ($end != ")")
260 parserr($end, ")")
261 end--
263 f++ #function return type
265 funcname=$f
266 if (funcalias == "")
267 funcalias = funcname
268 if (argalias == "") {
269 argalias = funcname "_args"
270 if ($3 == "COMPAT")
271 argalias = "o" argalias
272 if ($3 == "COMPAT4")
273 argalias = "freebsd4_" argalias
274 if ($3 == "COMPAT6")
275 argalias = "freebsd6_" argalias
279 if ($f != "(")
280 parserr($f, ")")
283 if (f == end) {
284 if ($f != "void")
285 parserr($f, "argument definition")
286 return
289 while (f <= end) {
290 argc++
291 argtype[argc]=""
292 oldf=""
293 while (f < end && $(f+1) != ",") {
294 if (argtype[argc] != "" && oldf != "*")
295 argtype[argc] = argtype[argc]" ";
296 argtype[argc] = argtype[argc]$f;
297 oldf = $f;
300 if (argtype[argc] == "")
301 parserr($f, "argument definition")
302 argname[argc]=$f;
303 f += 2; # skip name, and any comma
305 if (argc != 0)
306 argssize = "AS(" argalias ")"
308 { comment = $4
309 if (NF < 7)
310 for (i = 5; i <= NF; i++)
311 comment = comment " " $i
315 # The AUE_ audit event identifier.
318 auditev = $2;
321 $3 == "STD" || $3 == "NODEF" || $3 == "NOARGS" || $3 == "NOPROTO" \
322 || $3 == "NOIMPL" || $3 == "NOSTD" {
323 parseline()
324 printf("\t/* %s */\n\tcase %d: {\n", funcname, syscall) > systrace
325 printf("\t/* %s */\n\tcase %d:\n", funcname, syscall) > systracetmp
326 if (argc > 0) {
327 printf("\t\tswitch(ndx) {\n") > systracetmp
328 printf("\t\tstruct %s *p = params;\n", argalias) > systrace
329 for (i = 1; i <= argc; i++) {
330 printf("\t\tcase %d:\n\t\t\tp = \"%s\";\n\t\t\tbreak;\n", i - 1, argtype[i]) > systracetmp
331 if (index(argtype[i], "*") > 0 || argtype[i] == "caddr_t")
332 printf("\t\tuarg[%d] = (intptr_t) p->%s; /* %s */\n", \
333 i - 1, \
334 argname[i], argtype[i]) > systrace
335 else if (substr(argtype[i], 1, 1) == "u" || argtype[i] == "size_t")
336 printf("\t\tuarg[%d] = p->%s; /* %s */\n", \
337 i - 1, \
338 argname[i], argtype[i]) > systrace
339 else
340 printf("\t\tiarg[%d] = p->%s; /* %s */\n", \
341 i - 1, \
342 argname[i], argtype[i]) > systrace
344 printf("\t\tdefault:\n\t\t\tbreak;\n\t\t};\n") > systracetmp
346 printf("\t\t*n_args = %d;\n\t\tbreak;\n\t}\n", argc) > systrace
347 printf("\t\tbreak;\n") > systracetmp
348 if ((!nosys || funcname != "nosys") && \
349 (funcname != "lkmnosys") && (funcname != "lkmressys")) {
350 if (argc != 0 && $3 != "NOARGS" && $3 != "NOPROTO") {
351 printf("struct %s {\n", argalias) > sysarg
352 for (i = 1; i <= argc; i++)
353 printf("\tchar %s_l_[PADL_(%s)]; " \
354 "%s %s; char %s_r_[PADR_(%s)];\n",
355 argname[i], argtype[i],
356 argtype[i], argname[i],
357 argname[i], argtype[i]) > sysarg
358 printf("};\n") > sysarg
360 else if ($3 != "NOARGS" && $3 != "NOPROTO" && \
361 $3 != "NODEF")
362 printf("struct %s {\n\tregister_t dummy;\n};\n",
363 argalias) > sysarg
365 if (($3 != "NOPROTO" && $3 != "NODEF" && \
366 (funcname != "nosys" || !nosys)) || \
367 (funcname == "lkmnosys" && !lkmnosys) || \
368 funcname == "lkmressys") {
369 printf("%s\t%s(struct thread *, struct %s *)",
370 rettype, funcname, argalias) > sysdcl
371 printf(";\n") > sysdcl
372 printf("#define\t%sAUE_%s\t%s\n", syscallprefix,
373 funcalias, auditev) > sysaue
375 if (funcname == "nosys")
376 nosys = 1
377 if (funcname == "lkmnosys")
378 lkmnosys = 1
379 printf("\t{ %s, (sy_call_t *)", argssize) > sysent
380 column = 8 + 2 + length(argssize) + 15
381 if ($3 == "NOIMPL") {
382 printf("%s },", "nosys, AUE_NULL, NULL, 0, 0") > sysent
383 column = column + length("nosys") + 3
384 } else if ($3 == "NOSTD") {
385 printf("%s },", "lkmressys, AUE_NULL, NULL, 0, 0") > sysent
386 column = column + length("lkmressys") + 3
387 } else {
388 printf("%s, %s, NULL, 0, 0 },", funcname, auditev) > sysent
389 column = column + length(funcname) + length(auditev) + 3
391 align_sysent_comment(column)
392 printf("/* %d = %s */\n", syscall, funcalias) > sysent
393 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
394 funcalias, syscall, funcalias) > sysnames
395 if ($3 != "NODEF") {
396 printf("#define\t%s%s\t%d\n", syscallprefix,
397 funcalias, syscall) > syshdr
398 printf(" \\\n\t%s.o", funcalias) > sysmk
400 syscall++
401 next
403 $3 == "COMPAT" || $3 == "COMPAT4" || $3 == "COMPAT6" || $3 == "CPT_NOA" {
404 if ($3 == "COMPAT" || $3 == "CPT_NOA") {
405 ncompat++
406 out = syscompat
407 outdcl = syscompatdcl
408 wrap = "compat"
409 prefix = "o"
410 } else if ($3 == "COMPAT4") {
411 ncompat4++
412 out = syscompat4
413 outdcl = syscompat4dcl
414 wrap = "compat4"
415 prefix = "freebsd4_"
416 } else if ($3 == "COMPAT6") {
417 ncompat6++
418 out = syscompat6
419 outdcl = syscompat6dcl
420 wrap = "compat6"
421 prefix = "freebsd6_"
423 parseline()
424 if (argc != 0 && $3 != "CPT_NOA") {
425 printf("struct %s {\n", argalias) > out
426 for (i = 1; i <= argc; i++)
427 printf("\tchar %s_l_[PADL_(%s)]; %s %s; " \
428 "char %s_r_[PADR_(%s)];\n",
429 argname[i], argtype[i],
430 argtype[i], argname[i],
431 argname[i], argtype[i]) > out
432 printf("};\n") > out
434 else if($3 != "CPT_NOA")
435 printf("struct %s {\n\tregister_t dummy;\n};\n",
436 argalias) > sysarg
437 printf("%s\t%s%s(struct thread *, struct %s *);\n",
438 rettype, prefix, funcname, argalias) > outdcl
439 printf("\t{ %s(%s,%s), %s, NULL, 0, 0 },",
440 wrap, argssize, funcname, auditev) > sysent
441 align_sysent_comment(8 + 9 + \
442 length(argssize) + 1 + length(funcname) + length(auditev) + 4)
443 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
444 printf("\t\"%s.%s\",\t\t/* %d = old %s */\n",
445 wrap, funcalias, syscall, funcalias) > sysnames
446 if ($3 == "COMPAT" || $3 == "CPT_NOA") {
447 printf("\t\t\t\t/* %d is old %s */\n",
448 syscall, funcalias) > syshdr
449 } else {
450 printf("#define\t%s%s%s\t%d\n", syscallprefix,
451 prefix, funcalias, syscall) > syshdr
452 printf(" \\\n\t%s%s.o", prefix, funcalias) > sysmk
454 syscall++
455 next
457 $3 == "LIBCOMPAT" {
458 ncompat++
459 parseline()
460 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
461 printf("\t{ compat(%s,%s), %s, NULL, 0, 0 },",
462 argssize, funcname, auditev) > sysent
463 align_sysent_comment(8 + 9 + \
464 length(argssize) + 1 + length(funcname) + length(auditev) + 4)
465 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
466 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
467 funcalias, syscall, funcalias) > sysnames
468 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
469 syscallprefix, funcalias, syscall) > syshdr
470 printf(" \\\n\t%s.o", funcalias) > sysmk
471 syscall++
472 next
474 $3 == "OBSOL" {
475 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0 },") > sysent
476 align_sysent_comment(34)
477 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
478 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
479 $4, syscall, comment) > sysnames
480 printf("\t\t\t\t/* %d is obsolete %s */\n",
481 syscall, comment) > syshdr
482 syscall++
483 next
485 $3 == "UNIMPL" {
486 printf("\t{ 0, (sy_call_t *)nosys, AUE_NULL, NULL, 0, 0 },\t\t\t/* %d = %s */\n",
487 syscall, comment) > sysent
488 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
489 syscall, syscall, comment) > sysnames
490 syscall++
491 next
494 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
495 exit 1
497 END {
498 printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
500 if (ncompat != 0 || ncompat4 != 0 || ncompat6 != 0)
501 printf "#include \"opt_compat.h\"\n\n" > syssw
503 if (ncompat != 0) {
504 printf "\n#ifdef %s\n", compat > sysinc
505 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
506 printf "#else\n" > sysinc
507 printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
508 printf "#endif\n" > sysinc
511 if (ncompat4 != 0) {
512 printf "\n#ifdef %s\n", compat4 > sysinc
513 printf "#define compat4(n, name) n, (sy_call_t *)__CONCAT(freebsd4_,name)\n" > sysinc
514 printf "#else\n" > sysinc
515 printf "#define compat4(n, name) 0, (sy_call_t *)nosys\n" > sysinc
516 printf "#endif\n" > sysinc
519 if (ncompat6 != 0) {
520 printf "\n#ifdef %s\n", compat6 > sysinc
521 printf "#define compat6(n, name) n, (sy_call_t *)__CONCAT(freebsd6_,name)\n" > sysinc
522 printf "#else\n" > sysinc
523 printf "#define compat6(n, name) 0, (sy_call_t *)nosys\n" > sysinc
524 printf "#endif\n" > sysinc
527 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
528 printf("\n#endif /* %s */\n\n", compat4) > syscompat4dcl
529 printf("\n#endif /* %s */\n\n", compat6) > syscompat6dcl
531 printf("\n#undef PAD_\n") > sysprotoend
532 printf("#undef PADL_\n") > sysprotoend
533 printf("#undef PADR_\n") > sysprotoend
534 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
536 printf("\n") > sysmk
537 printf("};\n") > sysent
538 printf("};\n") > sysnames
539 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
540 > syshdr
541 printf "\tdefault:\n\t\t*n_args = 0;\n\t\tbreak;\n\t};\n}\n" > systrace
542 printf "\tdefault:\n\t\tbreak;\n\t};\n\tif (p != NULL)\n\t\tstrlcpy(desc, p, descsz);\n}\n" > systracetmp
545 cat $sysinc $sysent >> $syssw
546 cat $sysarg $sysdcl \
547 $syscompat $syscompatdcl \
548 $syscompat4 $syscompat4dcl \
549 $syscompat6 $syscompat6dcl \
550 $sysaue $sysprotoend > $sysproto
551 cat $systracetmp >> $systrace