syscall messaging 3: Expand the 'header' that goes in front of the syscall
[dragonfly.git] / sys / kern / makesyscalls.sh
CommitLineData
984263bc
MD
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 $
c7114eea 4# $DragonFly: src/sys/kern/makesyscalls.sh,v 1.7 2003/07/30 00:19:14 dillon Exp $
984263bc
MD
5
6set -e
7
8# name of compat option:
9compat=COMPAT_43
10
11# output files:
12sysnames="syscalls.c"
13sysproto="../sys/sysproto.h"
a64ba182 14sysunion="../sys/sysunion.h"
984263bc
MD
15sysproto_h=_SYS_SYSPROTO_H_
16syshdr="../sys/syscall.h"
17sysmk="../sys/syscall.mk"
18syssw="init_sysent.c"
19syshide="../sys/syscall-hide.h"
20syscallprefix="SYS_"
21switchname="sysent"
22namesname="syscallnames"
23
24# tmp files:
25sysdcl="sysent.dcl.$$"
26syscompat="sysent.compat.$$"
27syscompatdcl="sysent.compatdcl.$$"
28sysent="sysent.switch.$$"
29sysinc="sysinc.switch.$$"
30sysarg="sysarg.switch.$$"
a64ba182 31sysun="sysunion.switch.$$"
984263bc 32
a64ba182 33trap "rm $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun" 0
984263bc 34
a64ba182 35touch $sysdcl $syscompat $syscompatdcl $sysent $sysinc $sysarg $sysun
984263bc
MD
36
37case $# in
38 0) echo "Usage: $0 input-file <config-file>" 1>&2
39 exit 1
40 ;;
41esac
42
43if [ -n "$2" -a -f "$2" ]; then
44 . $2
45fi
46
47sed -e '
48s/\$//g
49:join
50 /\\$/{a\
51
52 N
53 s/\\\n//
54 b join
55 }
562,${
57 /^#/!s/\([{}()*,]\)/ \1 /g
58}
59' < $1 | awk "
60 BEGIN {
61 sysdcl = \"$sysdcl\"
62 sysproto = \"$sysproto\"
63 sysproto_h = \"$sysproto_h\"
64 syscompat = \"$syscompat\"
65 syscompatdcl = \"$syscompatdcl\"
66 sysent = \"$sysent\"
67 syssw = \"$syssw\"
68 sysinc = \"$sysinc\"
69 sysarg = \"$sysarg\"
a64ba182 70 sysun = \"$sysun\"
984263bc
MD
71 sysnames = \"$sysnames\"
72 syshdr = \"$syshdr\"
73 sysmk = \"$sysmk\"
74 compat = \"$compat\"
75 syshide = \"$syshide\"
76 syscallprefix = \"$syscallprefix\"
77 switchname = \"$switchname\"
78 namesname = \"$namesname\"
79 infile = \"$1\"
80 "'
81
82 printf "/*\n * System call switch table.\n *\n" > syssw
83 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syssw
a64ba182 84 printf " * \$\DragonFly\$\n" > syssw
984263bc
MD
85
86 printf "/*\n * System call prototypes.\n *\n" > sysarg
87 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarg
a64ba182 88 printf " * \$\DragonFly\$\n" > sysarg
984263bc
MD
89
90 printf "\n#ifdef %s\n\n", compat > syscompat
91
92 printf "/*\n * System call names.\n *\n" > sysnames
93 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
a64ba182 94 printf " * \$\DragonFly\$\n" > sysnames
984263bc
MD
95
96 printf "/*\n * System call numbers.\n *\n" > syshdr
97 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
a64ba182
MD
98 printf " * \$\DragonFly\$\n" > syshdr
99 printf "# DragonFly system call names.\n" > sysmk
984263bc 100 printf "# DO NOT EDIT-- this file is automatically generated.\n" > sysmk
a64ba182 101 printf "# \$\DragonFly\$\n" > sysmk
984263bc
MD
102 printf "/*\n * System call hiders.\n *\n" > syshide
103 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshide
a64ba182
MD
104 printf " * \$\DragonFly\$\n" > syshide
105
106 printf "/*\n * Union of syscall args for messaging.\n *\n" > sysun
107 printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysun
108 printf " * \$\DragonFly\$\n" > sysun
4fd10eb6
MD
109 printf "\n#ifdef _KERNEL\n\n" > sysdcl
110 printf "\n#ifdef _KERNEL\n\n" > syscompatdcl
984263bc
MD
111 }
112 NR == 1 {
a64ba182 113 gsub("[$]DragonFly: ", "", $0)
984263bc
MD
114 gsub(" [$]", "", $0)
115
116 printf " * created from%s\n */\n\n", $0 > syssw
117
118 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
119 printf "struct sysent %s[] = {\n",switchname > sysent
120
121 printf " * created from%s\n */\n\n", $0 > sysarg
122 printf "#ifndef %s\n", sysproto_h > sysarg
123 printf "#define\t%s\n\n", sysproto_h > sysarg
124 printf "#include <sys/signal.h>\n\n" > sysarg
125 printf "#include <sys/acl.h>\n\n" > sysarg
a64ba182 126 printf "#include <sys/msgport.h>\n\n" > sysarg
c7114eea 127 printf "#include <sys/sysmsg.h>\n\n" > sysarg
984263bc
MD
128 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) ? \\\n" > sysarg
129 printf "\t\t0 : sizeof(register_t) - sizeof(t))\n\n" > sysarg
130
131 printf " * created from%s\n */\n\n", $0 > sysnames
132 printf "char *%s[] = {\n", namesname > sysnames
133
134 printf " * created from%s\n */\n\n", $0 > syshdr
135
136 printf "# created from%s\nMIASM = ", $0 > sysmk
137
138 printf " * created from%s\n */\n\n", $0 > syshide
a64ba182
MD
139 printf " * created from%s\n */\n\n", $0 > sysun
140 printf "union sysunion {\n" > sysun
c7114eea
MD
141 printf "\tstruct\tlwkt_msg lmsg;\n" > sysun
142 printf "\tunion\tsysmsg sysmsg;\n" > sysun
984263bc
MD
143 next
144 }
145 NF == 0 || $1 ~ /^;/ {
146 next
147 }
148 $1 ~ /^#[ ]*include/ {
149 print > sysinc
150 next
151 }
152 $1 ~ /^#[ ]*if/ {
153 print > sysent
154 print > sysdcl
155 print > sysarg
156 print > syscompat
157 print > sysnames
158 print > syshide
a64ba182 159 print > sysun
984263bc
MD
160 savesyscall = syscall
161 next
162 }
163 $1 ~ /^#[ ]*else/ {
164 print > sysent
165 print > sysdcl
166 print > sysarg
a64ba182 167 print > sysun
984263bc
MD
168 print > syscompat
169 print > sysnames
170 print > syshide
171 syscall = savesyscall
172 next
173 }
174 $1 ~ /^#/ {
175 print > sysent
176 print > sysdcl
177 print > sysarg
a64ba182 178 print > sysun
984263bc
MD
179 print > syscompat
180 print > sysnames
181 print > syshide
182 next
183 }
184 syscall != $1 {
185 printf "%s: line %d: syscall number out of sync at %d\n",
186 infile, NR, syscall
187 printf "line is:\n"
188 print
189 exit 1
190 }
191 function align_sysent_comment(column) {
192 printf("\t") > sysent
193 column = column + 8 - column % 8
194 while (column < 56) {
195 printf("\t") > sysent
196 column = column + 8
197 }
198 }
199 function parserr(was, wanted) {
200 printf "%s: line %d: unexpected %s (expected %s)\n",
201 infile, NR, was, wanted
202 exit 1
203 }
204 function parseline() {
205 f=4 # toss number and type
206 argc= 0;
207 argssize = "0"
208 if ($NF != "}") {
209 funcalias=$(NF-2)
210 argalias=$(NF-1)
211 rettype=$NF
212 end=NF-3
213 } else {
214 funcalias=""
215 argalias=""
216 rettype="int"
217 end=NF
218 }
219 if ($2 == "NODEF") {
220 funcname=$4
221 argssize = "AS(" $6 ")"
222 return
223 }
224 if ($f != "{")
225 parserr($f, "{")
226 f++
227 if ($end != "}")
228 parserr($end, "}")
229 end--
230 if ($end != ";")
231 parserr($end, ";")
232 end--
233 if ($end != ")")
234 parserr($end, ")")
235 end--
236
237 f++ #function return type
238
239 funcname=$f
a64ba182 240 usefuncname=$f
984263bc
MD
241 if (funcalias == "")
242 funcalias = funcname
243 if (argalias == "") {
244 argalias = funcname "_args"
a64ba182 245 if ($2 == "COMPAT") {
984263bc 246 argalias = "o" argalias
a64ba182
MD
247 usefuncname = "o" funcname
248 }
984263bc
MD
249 }
250 f++
251
252 if ($f != "(")
253 parserr($f, ")")
254 f++
255
256 if (f == end) {
257 if ($f != "void")
258 parserr($f, "argument definition")
259 return
260 }
261
262 while (f <= end) {
263 argc++
264 argtype[argc]=""
265 oldf=""
266 while (f < end && $(f+1) != ",") {
267 if (argtype[argc] != "" && oldf != "*")
268 argtype[argc] = argtype[argc]" ";
269 argtype[argc] = argtype[argc]$f;
270 oldf = $f;
271 f++
272 }
273 if (argtype[argc] == "")
274 parserr($f, "argument definition")
275 argname[argc]=$f;
276 f += 2; # skip name, and any comma
277 }
278 if (argc != 0)
279 argssize = "AS(" argalias ")"
280 }
281 { comment = $4
282 if (NF < 7)
283 for (i = 5; i <= NF; i++)
284 comment = comment " " $i
285 }
286 # if the "MPSAFE" keyword is found, note it and shift the line
287 mpsafe = ""
288 $2 == "MPSAFE" {
289 for (i = 2; i <= NF; i++)
290 $i = $(i + 1);
291 NF -= 1;
292 mpsafe = "SYF_MPSAFE | "
293 }
294 $2 == "STD" || $2 == "NODEF" || $2 == "NOARGS" || $2 == "NOPROTO" \
295 || $2 == "NOIMPL" {
296 parseline()
297 if ((!nosys || funcname != "nosys") && \
298 (funcname != "lkmnosys")) {
299 if (argc != 0 && $2 != "NOARGS" && $2 != "NOPROTO") {
a64ba182 300 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
984263bc 301 printf("struct\t%s {\n", argalias) > sysarg
c7114eea 302 printf("\tunion sysmsg sysmsg;\n") > sysarg
984263bc
MD
303 for (i = 1; i <= argc; i++)
304 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
305 argtype[i], argname[i],
306 argname[i], argtype[i]) > sysarg
307 printf("};\n") > sysarg
308 }
309 else if ($2 != "NOARGS" && $2 != "NOPROTO" && \
a64ba182
MD
310 $2 != "NODEF") {
311 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
312 printf("struct\t%s {\n", argalias) > sysarg
c7114eea 313 printf("\tunion sysmsg sysmsg;\n") > sysarg
a64ba182
MD
314 printf("\tregister_t dummy;\n") > sysarg
315 printf("};\n") > sysarg
316 }
984263bc
MD
317 }
318 if (($2 != "NOPROTO" && $2 != "NODEF" && \
319 (funcname != "nosys" || !nosys)) || \
320 (funcname == "lkmnosys" && !lkmnosys) || \
321 funcname == "lkmressys") {
41c20dac 322 printf("%s\t%s __P((struct %s *))",
984263bc
MD
323 rettype, funcname, argalias) > sysdcl
324 printf(";\n") > sysdcl
325 }
326 if (funcname == "nosys")
327 nosys = 1
328 if (funcname == "lkmnosys")
329 lkmnosys = 1
330 printf("\t{ %s%s, (sy_call_t *)", mpsafe, argssize) > sysent
331 column = 8 + 2 + length(mpsafe) + length(argssize) + 15
332 if ($2 != "NOIMPL") {
333 printf("%s },", funcname) > sysent
334 column = column + length(funcname) + 3
335 } else {
336 printf("%s },", "nosys") > sysent
337 column = column + length("nosys") + 3
338 }
339 align_sysent_comment(column)
340 printf("/* %d = %s */\n", syscall, funcalias) > sysent
341 printf("\t\"%s\",\t\t\t/* %d = %s */\n",
342 funcalias, syscall, funcalias) > sysnames
343 if ($2 != "NODEF") {
344 printf("#define\t%s%s\t%d\n", syscallprefix,
345 funcalias, syscall) > syshdr
346 printf(" \\\n\t%s.o", funcalias) > sysmk
347 }
348 if ($3 != "NOHIDE")
349 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
350 syscall++
351 next
352 }
353 $2 == "COMPAT" || $2 == "CPT_NOA" {
354 ncompat++
355 parseline()
356 if (argc != 0 && $2 != "CPT_NOA") {
a64ba182
MD
357 printf("#ifdef %s\n", compat) > sysun
358 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
359 printf("#endif\n") > sysun
984263bc 360 printf("struct\t%s {\n", argalias) > syscompat
c7114eea 361 printf("\tunion sysmsg sysmsg;\n") > syscompat
984263bc
MD
362 for (i = 1; i <= argc; i++)
363 printf("\t%s\t%s;\tchar %s_[PAD_(%s)];\n",
364 argtype[i], argname[i],
365 argname[i], argtype[i]) > syscompat
366 printf("};\n") > syscompat
367 }
a64ba182
MD
368 else if($2 != "CPT_NOA") {
369 printf("\tstruct\t%s %s;\n", argalias, usefuncname) > sysun
370 printf("struct\t%s {\n", argalias) > sysarg
c7114eea 371 printf("\tunion sysmsg sysmsg;\n") > sysarg
a64ba182
MD
372 printf("\tregister_t dummy;\n") > sysarg
373 printf("};\n") > sysarg
374 }
41c20dac 375 printf("%s\to%s __P((struct %s *));\n",
984263bc
MD
376 rettype, funcname, argalias) > syscompatdcl
377 printf("\t{ compat(%s%s,%s) },",
378 mpsafe, argssize, funcname) > sysent
379 align_sysent_comment(8 + 9 + length(mpsafe) + \
380 length(argssize) + 1 + length(funcname) + 4)
381 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
382 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
383 funcalias, syscall, funcalias) > sysnames
384 printf("\t\t\t\t/* %d is old %s */\n",
385 syscall, funcalias) > syshdr
386 if ($3 != "NOHIDE")
387 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
388 syscall++
389 next
390 }
391 $2 == "LIBCOMPAT" {
392 ncompat++
393 parseline()
394 printf("%s\to%s();\n", rettype, funcname) > syscompatdcl
395 printf("\t{ compat(%s%s,%s) },",
396 mpsafe, argssize, funcname) > sysent
397 align_sysent_comment(8 + 9 + length(mpsafe) + \
398 length(argssize) + 1 + length(funcname) + 4)
399 printf("/* %d = old %s */\n", syscall, funcalias) > sysent
400 printf("\t\"old.%s\",\t\t/* %d = old %s */\n",
401 funcalias, syscall, funcalias) > sysnames
402 printf("#define\t%s%s\t%d\t/* compatibility; still used by libc */\n",
403 syscallprefix, funcalias, syscall) > syshdr
404 printf(" \\\n\t%s.o", funcalias) > sysmk
405 if ($3 != "NOHIDE")
406 printf("HIDE_%s(%s)\n", $3, funcname) > syshide
407 syscall++
408 next
409 }
410 $2 == "OBSOL" {
411 printf("\t{ 0, (sy_call_t *)nosys },") > sysent
412 align_sysent_comment(34)
413 printf("/* %d = obsolete %s */\n", syscall, comment) > sysent
414 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n",
415 $4, syscall, comment) > sysnames
416 printf("\t\t\t\t/* %d is obsolete %s */\n",
417 syscall, comment) > syshdr
418 if ($3 != "NOHIDE")
419 printf("HIDE_%s(%s)\n", $3, $4) > syshide
420 syscall++
421 next
422 }
423 $2 == "UNIMPL" {
424 printf("\t{ 0, (sy_call_t *)nosys },\t\t\t/* %d = %s */\n",
425 syscall, comment) > sysent
426 printf("\t\"#%d\",\t\t\t/* %d = %s */\n",
427 syscall, syscall, comment) > sysnames
428 if ($3 != "NOHIDE")
429 printf("HIDE_%s(%s)\n", $3, $4) > syshide
430 syscall++
431 next
432 }
433 {
434 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
435 exit 1
436 }
437 END {
c7114eea 438 printf "\n#define AS(name) ((sizeof(struct name) - sizeof(union sysmsg)) / sizeof(register_t))\n" > sysinc
984263bc
MD
439 if (ncompat != 0) {
440 printf "#include \"opt_compat.h\"\n\n" > syssw
441 printf "\n#ifdef %s\n", compat > sysinc
442 printf "#define compat(n, name) n, (sy_call_t *)__CONCAT(o,name)\n" > sysinc
443 printf "#else\n" > sysinc
444 printf "#define compat(n, name) 0, (sy_call_t *)nosys\n" > sysinc
445 printf "#endif\n" > sysinc
446 }
447
4fd10eb6 448 printf("\n#endif /* _KERNEL */\n") > syscompatdcl
984263bc
MD
449 printf("\n#endif /* %s */\n\n", compat) > syscompatdcl
450 printf("#undef PAD_\n") > syscompatdcl
451 printf("\n#endif /* !%s */\n", sysproto_h) > syscompatdcl
452
453 printf("\n") > sysmk
454 printf("};\n") > sysent
455 printf("};\n") > sysnames
a64ba182 456 printf("};\n") > sysun
4fd10eb6 457 printf("\n#endif /* _KERNEL */\n") > sysdcl
984263bc
MD
458 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
459 > syshdr
460 } '
461
462cat $sysinc $sysent >> $syssw
463cat $sysarg $sysdcl $syscompat $syscompatdcl > $sysproto
a64ba182 464cat $sysun > $sysunion