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.4 2003/06/23 17:55:41 dillon Exp $
8 # name of compat option:
13 sysproto="../sys/sysproto.h"
14 sysproto_h=_SYS_SYSPROTO_H_
15 syshdr="../sys/syscall.h"
16 sysmk="../sys/syscall.mk"
18 syshide="../sys/syscall-hide.h"
21 namesname="syscallnames"
24 sysdcl="sysent.dcl.$$"
25 syscompat="sysent.compat.$$"
26 syscompatdcl="sysent.compatdcl.$$"
27 sysent="sysent.switch.$$"
28 sysinc="sysinc.switch.$$"
29 sysarg="sysarg.switch.$$"
31 trap "rm $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg" 0
33 touch $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg
36 0) echo "Usage: $0 input-file <config-file>" 1>&2
41 if [ -n "$2" -a -f "$2" ]; then
55 /^#/!s/\([{}()*,]\)/ \1 /g
60 sysproto = \"$sysproto\"
61 sysproto_h = \"$sysproto_h\"
62 syscompat = \"$syscompat\"
63 syscompatdcl = \"$syscompatdcl\"
68 sysnames = \"$sysnames\"
72 syshide = \"$syshide\"
73 syscallprefix = \"$syscallprefix\"
74 switchname = \"$switchname\"
75 namesname = \"$namesname\"
79 printf "/*\n * System call switch table.\n *\n" > syssw
80 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
81 printf " * \$\TurtleBSD\$\n" > syssw
83 printf "/*\n * System call prototypes.\n *\n" > sysarg
84 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
85 printf " * \$\TurtleBSD\$\n" > sysarg
87 printf "\n#ifdef %s\n\n", compat > syscompat
89 printf "/*\n * System call names.\n *\n" > sysnames
90 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
91 printf " * \$\TurtleBSD\$\n" > sysnames
93 printf "/*\n * System call numbers.\n *\n" > syshdr
94 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
95 printf " * \$\TurtleBSD\$\n" > syshdr
96 printf "# TurtleBSD system call names.\n" > sysmk
97 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
98 printf "# \$\TurtleBSD\$\n" > sysmk
99 printf "/*\n * System call hiders.\n *\n" > syshide
100 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
101 printf " * \$\TurtleBSD\$\n" > syshide
104 gsub("[$]TurtleBSD: ", "", $0)
107 printf " * created from%s\n */\n\n", $0 > syssw
109 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
110 printf "struct sysent %s[] = {\n",switchname > sysent
112 printf " * created from%s\n */\n\n", $0 > sysarg
113 printf "#ifndef %s\n", sysproto_h > sysarg
114 printf "#define\t%s\n\n", sysproto_h > sysarg
115 printf "#include <sys/signal.h>\n\n" > sysarg
116 printf "#include <sys/acl.h>\n\n" > sysarg
117 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
118 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
120 printf " * created from%s\n */\n\n", $0 > sysnames
121 printf "char *%s[] = {\n", namesname > sysnames
123 printf " * created from%s\n */\n\n", $0 > syshdr
125 printf "# created from%s\nMIASM = ", $0 > sysmk
127 printf " * created from%s\n */\n\n", $0 > syshide
130 NF == 0 || $1 ~ /^;/ {
133 $1 ~ /^#[ ]*include/ {
144 savesyscall = syscall
154 syscall = savesyscall
167 printf "%s: line %d: syscall number out of sync at %d\n",
173 function align_sysent_comment(column) {
174 printf("\t") > sysent
175 column = column + 8 - column % 8
176 while (column < 56) {
177 printf("\t") > sysent
181 function parserr(was, wanted) {
182 printf "%s: line %d: unexpected %s (expected %s)\n",
183 infile, NR, was, wanted
186 function parseline() {
187 f=4 # toss number and type
203 argssize = "AS(" $6 ")"
219 f++ #function return type
224 if (argalias == "") {
225 argalias = funcname "_args"
227 argalias = "o" argalias
237 parserr($f, "argument definition")
245 while (f < end && $(f+1) != ",") {
246 if (argtype[argc] != "" && oldf != "*")
247 argtype[argc] = argtype[argc]" ";
248 argtype[argc] = argtype[argc]$f;
252 if (argtype[argc] == "")
253 parserr($f, "argument definition")
255 f += 2; # skip name, and any comma
258 argssize = "AS(" argalias ")"
262 for (i = 5; i <= NF; i++)
263 comment = comment " " $i
265 # if the "MPSAFE" keyword is found, note it and shift the line
268 for (i = 2; i <= NF; i++)
271 mpsafe = "SYF_MPSAFE | "
273 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
276 if ((!nosys || funcname != "nosys") && \
277 (funcname != "lkmnosys")) {
278 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
279 printf("struct\t%s {\n", argalias) > sysarg
280 for (i = 1; i <= argc; i++)
281 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
282 argtype[i], argname[i],
283 argname[i], argtype[i]) > sysarg
284 printf("};\n") > sysarg
286 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
288 printf("struct\t%s {\n\tregister_t dummy;\n};\n",
291 if (($2 != "NOPROTO" && $2 != "NODEF" && \
292 (funcname != "nosys" || !nosys)) || \
293 (funcname == "lkmnosys" && !lkmnosys) || \
294 funcname == "lkmressys") {
295 printf("%s\t%s __P((struct %s *))",
296 rettype, funcname, argalias) > sysdcl
297 printf(";\n") > sysdcl
299 if (funcname == "nosys")
301 if (funcname == "lkmnosys")
303 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
304 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
305 if ($2 != "NOIMPL") {
306 printf("%s },", funcname) > sysent
307 column = column + length(funcname) + 3
309 printf("%s },", "nosys") > sysent
310 column = column + length("nosys") + 3
312 align_sysent_comment(column)
313 printf("/* %d = %s */\n", syscall, funcalias) > sysent
314 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
315 funcalias, syscall, funcalias) > sysnames
317 printf("#define\t%s%s\t%d\n", syscallprefix,
318 funcalias, syscall) > syshdr
319 printf(" \\\n\t%s.o", funcalias) > sysmk
322 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
326 $2 == "COMPAT" || $2 == "CPT_NOA" {
329 if (argc != 0 && $2 != "CPT_NOA") {
330 printf("struct\t%s {\n", argalias) > syscompat
331 for (i = 1; i <= argc; i++)
332 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
333 argtype[i], argname[i],
334 argname[i], argtype[i]) > syscompat
335 printf("};\n") > syscompat
337 else if($2 != "CPT_NOA")
338 printf("struct\t%s {\n\tregister_t dummy;\n};\n",
340 printf("%s\to%s __P((struct %s *));\n",
341 rettype, funcname, argalias) > syscompatdcl
342 printf("\t{ compat(%s%s,%s) },",
343 mpsafe, argssize, funcname) > sysent
344 align_sysent_comment(8 + 9 + length(mpsafe) + \
345 length(argssize) + 1 + length(funcname) + 4)
346 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
347 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
348 funcalias, syscall, funcalias) > sysnames
349 printf("\t\t\t\t/* %d is old %s */\n",
350 syscall, funcalias) > syshdr
352 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
359 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
360 printf("\t{ compat(%s%s,%s) },",
361 mpsafe, argssize, funcname) > sysent
362 align_sysent_comment(8 + 9 + length(mpsafe) + \
363 length(argssize) + 1 + length(funcname) + 4)
364 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
365 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
366 funcalias, syscall, funcalias) > sysnames
367 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
368 syscallprefix, funcalias, syscall) > syshdr
369 printf(" \\\n\t%s.o", funcalias) > sysmk
371 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
376 printf("\t{ 0, (sy_call_t *)nosys },") > sysent
377 align_sysent_comment(34)
378 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
379 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
380 $4, syscall, comment) > sysnames
381 printf("\t\t\t\t/* %d is obsolete %s */\n",
382 syscall, comment) > syshdr
384 printf("HIDE_%s(%s)\n", $3, $4) > syshide
389 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = %s */\n",
390 syscall, comment) > sysent
391 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
392 syscall, syscall, comment) > sysnames
394 printf("HIDE_%s(%s)\n", $3, $4) > syshide
399 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
403 printf "\n#define AS(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
405 printf "#include \"opt_compat.h\"\n\n" > syssw
406 printf "\n#ifdef %s\n", compat > sysinc
407 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
408 printf "#else\n" > sysinc
409 printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
410 printf "#endif\n" > sysinc
413 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
414 printf("#undef PAD_\n") > syscompatdcl
415 printf("\n#endif /* !%s */\n", sysproto_h) > syscompatdcl
418 printf("};\n") > sysent
419 printf("};\n") > sysnames
420 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
424 cat $sysinc $sysent >> $syssw
425 cat $sysarg $sysdcl $syscompat $syscompatdcl > $sysproto