]> git.saurik.com Git - apple/xnu.git/blame - bsd/kern/makesyscalls.sh
xnu-792.17.14.tar.gz
[apple/xnu.git] / bsd / kern / makesyscalls.sh
CommitLineData
91447636
A
1#! /bin/sh -
2# @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3# $FreeBSD: src/sys/kern/makesyscalls.sh,v 1.60 2003/04/01 01:12:24 jeff Exp $
4#
5d5c5d0d 5# Copyright (c) 2004 Apple Computer, Inc. All rights reserved.
91447636 6#
8f6c56a5 7# @APPLE_LICENSE_HEADER_START@
91447636 8#
8f6c56a5
A
9# The contents of this file constitute Original Code as defined in and
10# are subject to the Apple Public Source License Version 1.1 (the
11# "License"). You may not use this file except in compliance with the
12# License. Please obtain a copy of the License at
13# http://www.apple.com/publicsource and read it before using this file.
14#
15# This Original Code and all software distributed under the License are
16# distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17# EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18# INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19# FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
20# License for the specific language governing rights and limitations
21# under the License.
22#
23# @APPLE_LICENSE_HEADER_END@
91447636
A
24#
25
26set -e
27
28# output files:
29syscallnamesfile="syscalls.c"
30sysprotofile="../sys/sysproto.h"
31sysproto_h=_SYS_SYSPROTO_H_
32syshdrfile="../sys/syscall.h"
33syscall_h=_SYS_SYSCALL_H_
34syscalltablefile="init_sysent.c"
35syscallprefix="SYS_"
36switchname="sysent"
37namesname="syscallnames"
38
39# tmp files:
40syslegal="sysent.syslegal.$$"
41sysent="sysent.switch.$$"
42sysinc="sysinc.switch.$$"
43sysarg="sysarg.switch.$$"
44sysprotoend="sysprotoend.$$"
45syscallnamestempfile="syscallnamesfile.$$"
46syshdrtempfile="syshdrtempfile.$$"
47
48trap "rm $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile" 0
49
50touch $syslegal $sysent $sysinc $sysarg $sysprotoend $syscallnamestempfile $syshdrtempfile
51
52case $# in
53 0) echo "usage: $0 input-file <config-file>" 1>&2
54 exit 1
55 ;;
56esac
57
58if [ -n "$2" -a -f "$2" ]; then
59 . $2
60fi
61
62sed -e '
63s/\$//g
64:join
65 /\\$/{a\
66
67 N
68 s/\\\n//
69 b join
70 }
712,${
72 /^#/!s/\([{}()*,]\)/ \1 /g
73}
74' < $1 | awk "
75 BEGIN {
76 syslegal = \"$syslegal\"
77 sysprotofile = \"$sysprotofile\"
78 sysprotoend = \"$sysprotoend\"
79 sysproto_h = \"$sysproto_h\"
80 syscall_h = \"$syscall_h\"
81 sysent = \"$sysent\"
82 syscalltablefile = \"$syscalltablefile\"
83 sysinc = \"$sysinc\"
84 sysarg = \"$sysarg\"
85 syscallnamesfile = \"$syscallnamesfile\"
86 syscallnamestempfile = \"$syscallnamestempfile\"
87 syshdrfile = \"$syshdrfile\"
88 syshdrtempfile = \"$syshdrtempfile\"
89 syscallprefix = \"$syscallprefix\"
90 switchname = \"$switchname\"
91 namesname = \"$namesname\"
92 infile = \"$1\"
93 "'
94
95 printf "/*\n" > syslegal
8f6c56a5 96 printf " * Copyright (c) 2004 Apple Computer, Inc. All rights reserved.\n" > syslegal
91447636 97 printf " * \n" > syslegal
8f6c56a5 98 printf " * @APPLE_LICENSE_HEADER_START@ \n" > syslegal
91447636 99 printf " * \n" > syslegal
8f6c56a5
A
100 printf " * The contents of this file constitute Original Code as defined in and \n" > syslegal
101 printf " * are subject to the Apple Public Source License Version 1.1 (the \n" > syslegal
102 printf " * \"License\"). You may not use this file except in compliance with the \n" > syslegal
103 printf " * License. Please obtain a copy of the License at \n" > syslegal
104 printf " * http://www.apple.com/publicsource and read it before using this file. \n" > syslegal
91447636 105 printf " * \n" > syslegal
8f6c56a5 106 printf " * This Original Code and all software distributed under the License are \n" > syslegal
91447636
A
107 printf " * distributed on an \"AS IS\" basis, WITHOUT WARRANTY OF ANY KIND, EITHER \n" > syslegal
108 printf " * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, \n" > syslegal
109 printf " * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY, \n" > syslegal
8f6c56a5
A
110 printf " * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the \n" > syslegal
111 printf " * License for the specific language governing rights and limitations \n" > syslegal
112 printf " * under the License. \n" > syslegal
91447636 113 printf " * \n" > syslegal
8f6c56a5 114 printf " * @APPLE_LICENSE_HEADER_END@ \n" > syslegal
91447636
A
115 printf " * \n" > syslegal
116 printf " * \n" > syslegal
117 printf " * System call switch table.\n *\n" > syslegal
118 printf " * DO NOT EDIT-- this file is automatically generated.\n" > syslegal
119 printf " * created from %s\n */\n\n", infile > syslegal
120 }
121 NR == 1 {
122 printf "\n/* The casts are bogus but will do for now. */\n" > sysent
123 printf "__private_extern__ struct sysent %s[] = {\n",switchname > sysent
124
125 printf "#ifndef %s\n", sysproto_h > sysarg
126 printf "#define\t%s\n\n", sysproto_h > sysarg
127 printf "#ifndef %s\n", syscall_h > syshdrtempfile
128 printf "#define\t%s\n\n", syscall_h > syshdrtempfile
129 printf "#include <sys/appleapiopts.h>\n" > syshdrtempfile
130 printf "#ifdef __APPLE_API_PRIVATE\n" > syshdrtempfile
131 printf "#include <sys/appleapiopts.h>\n" > sysarg
132 printf "#include <sys/cdefs.h>\n" > sysarg
133 printf "#include <sys/mount_internal.h>\n" > sysarg
134 printf "#include <sys/types.h>\n" > sysarg
135 printf "#include <sys/sem_internal.h>\n" > sysarg
136 printf "#include <sys/semaphore.h>\n" > sysarg
137 printf "#include <sys/wait.h>\n" > sysarg
138 printf "#include <mach/shared_memory_server.h>\n" > sysarg
139 printf "\n#ifdef KERNEL\n" > sysarg
140 printf "#ifdef __APPLE_API_PRIVATE\n" > sysarg
8f6c56a5 141 printf "#ifdef __ppc__\n" > sysarg
91447636
A
142 printf "#define\tPAD_(t)\t(sizeof(uint64_t) <= sizeof(t) \\\n " > sysarg
143 printf "\t\t? 0 : sizeof(uint64_t) - sizeof(t))\n" > sysarg
8f6c56a5
A
144 printf "#else\n" > sysarg
145 printf "#define\tPAD_(t)\t(sizeof(register_t) <= sizeof(t) \\\n " > sysarg
146 printf "\t\t? 0 : sizeof(register_t) - sizeof(t))\n" > sysarg
147 printf "#endif\n" > sysarg
91447636
A
148 printf "#if BYTE_ORDER == LITTLE_ENDIAN\n"> sysarg
149 printf "#define\tPADL_(t)\t0\n" > sysarg
150 printf "#define\tPADR_(t)\tPAD_(t)\n" > sysarg
151 printf "#else\n" > sysarg
152 printf "#define\tPADL_(t)\tPAD_(t)\n" > sysarg
153 printf "#define\tPADR_(t)\t0\n" > sysarg
154 printf "#endif\n" > sysarg
155 printf "\n__BEGIN_DECLS\n" > sysarg
156 printf "#ifndef __MUNGE_ONCE\n" > sysarg
157 printf "#define __MUNGE_ONCE\n" > sysarg
8f6c56a5 158 printf "#ifdef __ppc__\n" > sysarg
91447636
A
159 printf "void munge_w(const void *, void *); \n" > sysarg
160 printf "void munge_ww(const void *, void *); \n" > sysarg
161 printf "void munge_www(const void *, void *); \n" > sysarg
162 printf "void munge_wwww(const void *, void *); \n" > sysarg
163 printf "void munge_wwwww(const void *, void *); \n" > sysarg
164 printf "void munge_wwwwww(const void *, void *); \n" > sysarg
165 printf "void munge_wwwwwww(const void *, void *); \n" > sysarg
166 printf "void munge_wwwwwwww(const void *, void *); \n" > sysarg
5d5c5d0d
A
167 printf "void munge_d(const void *, void *); \n" > sysarg
168 printf "void munge_dd(const void *, void *); \n" > sysarg
169 printf "void munge_ddd(const void *, void *); \n" > sysarg
170 printf "void munge_dddd(const void *, void *); \n" > sysarg
171 printf "void munge_ddddd(const void *, void *); \n" > sysarg
172 printf "void munge_dddddd(const void *, void *); \n" > sysarg
173 printf "void munge_ddddddd(const void *, void *); \n" > sysarg
174 printf "void munge_dddddddd(const void *, void *); \n" > sysarg
8f6c56a5
A
175 printf "void munge_wl(const void *, void *); \n" > sysarg
176 printf "void munge_wlw(const void *, void *); \n" > sysarg
177 printf "void munge_wwwl(const void *, void *); \n" > sysarg
178 printf "void munge_wwwwl(const void *, void *); \n" > sysarg
179 printf "void munge_wwwwwl(const void *, void *); \n" > sysarg
180 printf "void munge_wsw(const void *, void *); \n" > sysarg
181 printf "void munge_wws(const void *, void *); \n" > sysarg
182 printf "void munge_wwwsw(const void *, void *); \n" > sysarg
91447636 183 printf "#else \n" > sysarg
8f6c56a5
A
184 printf "#define munge_w NULL \n" > sysarg
185 printf "#define munge_ww NULL \n" > sysarg
186 printf "#define munge_www NULL \n" > sysarg
187 printf "#define munge_wwww NULL \n" > sysarg
188 printf "#define munge_wwwww NULL \n" > sysarg
189 printf "#define munge_wwwwww NULL \n" > sysarg
190 printf "#define munge_wwwwwww NULL \n" > sysarg
191 printf "#define munge_wwwwwwww NULL \n" > sysarg
91447636
A
192 printf "#define munge_d NULL \n" > sysarg
193 printf "#define munge_dd NULL \n" > sysarg
194 printf "#define munge_ddd NULL \n" > sysarg
195 printf "#define munge_dddd NULL \n" > sysarg
196 printf "#define munge_ddddd NULL \n" > sysarg
197 printf "#define munge_dddddd NULL \n" > sysarg
198 printf "#define munge_ddddddd NULL \n" > sysarg
199 printf "#define munge_dddddddd NULL \n" > sysarg
8f6c56a5
A
200 printf "#define munge_wl NULL \n" > sysarg
201 printf "#define munge_wlw NULL \n" > sysarg
202 printf "#define munge_wwwl NULL \n" > sysarg
203 printf "#define munge_wwwwl NULL \n" > sysarg
204 printf "#define munge_wwwwwl NULL \n" > sysarg
205 printf "#define munge_wsw NULL \n" > sysarg
206 printf "#define munge_wws NULL \n" > sysarg
207 printf "#define munge_wwwsw NULL \n" > sysarg
91447636
A
208 printf "#endif // __ppc__\n" > sysarg
209 printf "#endif /* !__MUNGE_ONCE */\n" > sysarg
210
211 printf "\n" > sysarg
212
213 printf "const char *%s[] = {\n", namesname > syscallnamestempfile
214 next
215 }
216 NF == 0 || $1 ~ /^;/ {
217 next
218 }
219 $1 ~ /^#[ ]*include/ {
220 print > sysinc
221 next
222 }
223 $1 ~ /^#[ ]*if/ {
224 print > sysent
225 print > sysarg
226 print > syscallnamestempfile
227 print > syshdrtempfile
228 print > sysprotoend
229 savesyscall = syscall
230 next
231 }
232 $1 ~ /^#[ ]*else/ {
233 print > sysent
234 print > sysarg
235 print > syscallnamestempfile
236 print > syshdrtempfile
237 print > sysprotoend
238 syscall = savesyscall
239 next
240 }
241 $1 ~ /^#/ {
242 print > sysent
243 print > sysarg
244 print > syscallnamestempfile
245 print > syshdrtempfile
246 print > sysprotoend
247 next
248 }
249 syscall != $1 {
250 printf "%s: line %d: syscall number out of sync at %d\n",
251 infile, NR, syscall
252 printf "line is:\n"
253 print
254 exit 1
255 }
256 function align_comment(linesize, location, thefile) {
257 printf(" ") > thefile
258 while (linesize < location) {
259 printf(" ") > thefile
260 linesize++
261 }
262 }
263 function parserr(was, wanted) {
264 printf "%s: line %d: unexpected %s (expected %s)\n",
265 infile, NR, was, wanted
266 exit 1
267 }
268
269 function parseline() {
270 funcname = ""
271 current_field = 5
272 args_start = 0
273 args_end = 0
274 comments_start = 0
275 comments_end = 0
276 argc = 0
277 argssize = "0"
278 additional_comments = " "
279
280 # find start and end of call name and arguments
281 if ($current_field != "{")
282 parserr($current_field, "{")
283 args_start = current_field
284 current_field++
285 while (current_field <= NF) {
286 if ($current_field == "}") {
287 args_end = current_field
288 break
289 }
290 current_field++
291 }
292 if (args_end == 0) {
293 printf "%s: line %d: invalid call name and arguments\n",
294 infile, NR
295 exit 1
296 }
297
298 # find start and end of optional comments
299 current_field++
300 if (current_field < NF && $current_field == "{") {
301 comments_start = current_field
302 while (current_field <= NF) {
303 if ($current_field == "}") {
304 comments_end = current_field
305 break
306 }
307 current_field++
308 }
309 if (comments_end == 0) {
310 printf "%s: line %d: invalid comments \n",
311 infile, NR
312 exit 1
313 }
314 }
315
316 if ($args_end != "}")
317 parserr($args_end, "}")
318 args_end--
319 if ($args_end != ";")
320 parserr($args_end, ";")
321 args_end--
322 if ($args_end != ")")
323 parserr($args_end, ")")
324 args_end--
325
326 # extract additional comments
327 if (comments_start != 0) {
328 current_field = comments_start + 1
329 while (current_field < comments_end) {
330 additional_comments = additional_comments $current_field " "
331 current_field++
332 }
333 }
334
335 # get function return type
336 current_field = args_start + 1
337 returntype = $current_field
338
339 # get function name and set up to get arguments
340 current_field++
341 funcname = $current_field
342 argalias = funcname "_args"
343 current_field++ # bump past function name
344
345 if ($current_field != "(")
346 parserr($current_field, "(")
347 current_field++
348
349 if (current_field == args_end) {
350 if ($current_field != "void")
351 parserr($current_field, "argument definition")
352 return
353 }
354
355 # extract argument types and names
356 while (current_field <= args_end) {
357 argc++
358 argtype[argc]=""
359 ext_argtype[argc]=""
360 oldf=""
361 while (current_field < args_end && $(current_field + 1) != ",") {
362 if (argtype[argc] != "" && oldf != "*") {
363 argtype[argc] = argtype[argc] " ";
364 }
365 argtype[argc] = argtype[argc] $current_field;
366 ext_argtype[argc] = argtype[argc];
367 oldf = $current_field;
368 current_field++
369 }
370 if (argtype[argc] == "")
371 parserr($current_field, "argument definition")
372 argname[argc] = $current_field;
373 current_field += 2; # skip name, and any comma
374 }
375 if (argc > 8) {
376 printf "%s: line %d: too many arguments!\n", infile, NR
377 exit 1
378 }
379 if (argc != 0)
380 argssize = "AC(" argalias ")"
381 }
382
383 {
384 add_sysent_entry = 1
385 add_sysnames_entry = 1
386 add_sysheader_entry = 1
387 add_sysproto_entry = 1
388 add_64bit_unsafe = 0
389 add_64bit_fakesafe = 0
390 add_cancel_enable = "0"
391
392 if ($2 == "NONE") {
393 add_cancel_enable = "_SYSCALL_CANCEL_NONE"
394 }
395 else if ($2 == "PRE") {
396 add_cancel_enable = "_SYSCALL_CANCEL_PRE"
397 }
398 else if ($2 == "POST") {
399 add_cancel_enable = "_SYSCALL_CANCEL_POST"
400 }
401 else {
402 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
403 exit 1
404
405 }
406
407 if ($3 == "KERN") {
408 my_funnel = "KERNEL_FUNNEL"
409 }
410 else if ($3 == "NONE") {
411 my_funnel = "NO_FUNNEL"
412 }
413 else {
414 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $3
415 exit 1
416 }
417
418 if ($4 != "ALL" && $4 != "UALL") {
419 files_keyword_OK = 0
420 add_sysent_entry = 0
421 add_sysnames_entry = 0
422 add_sysheader_entry = 0
423 add_sysproto_entry = 0
424
425 if (match($4, "[T]") != 0) {
426 add_sysent_entry = 1
427 files_keyword_OK = 1
428 }
429 if (match($4, "[N]") != 0) {
430 add_sysnames_entry = 1
431 files_keyword_OK = 1
432 }
433 if (match($4, "[H]") != 0) {
434 add_sysheader_entry = 1
435 files_keyword_OK = 1
436 }
437 if (match($4, "[P]") != 0) {
438 add_sysproto_entry = 1
439 files_keyword_OK = 1
440 }
441 if (match($4, "[U]") != 0) {
442 add_64bit_unsafe = 1
443 }
444 if (match($4, "[F]") != 0) {
445 add_64bit_fakesafe = 1
446 }
447
448 if (files_keyword_OK == 0) {
449 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $4
450 exit 1
451 }
452 }
453 else if ($4 == "UALL") {
454 add_64bit_unsafe = 1;
455 }
456
457
458 parseline()
459
460 # output function argument structures to sysproto.h and build the
461 # name of the appropriate argument mungers
462 munge32 = "NULL"
463 munge64 = "NULL"
464 if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
465 if (argc != 0) {
466 if (add_sysproto_entry == 1) {
467 printf("struct %s {\n", argalias) > sysarg
468 }
469 munge32 = "munge_"
470 munge64 = "munge_"
471 for (i = 1; i <= argc; i++) {
472 # Build name of argument munger.
473 # We account for all sys call argument types here.
474 # This is where you add any new types. With LP64 support
475 # each argument consumes 64-bits.
476 # see .../xnu/bsd/dev/ppc/munge.s for munge argument types.
477 if (argtype[i] == "long") {
478 if (add_64bit_unsafe == 0)
479 ext_argtype[i] = "user_long_t";
480 munge32 = munge32 "s"
481 munge64 = munge64 "d"
482 }
483 else if (argtype[i] == "u_long") {
484 if (add_64bit_unsafe == 0)
485 ext_argtype[i] = "user_ulong_t";
486 munge32 = munge32 "w"
487 munge64 = munge64 "d"
488 }
489 else if (argtype[i] == "size_t") {
490 if (add_64bit_unsafe == 0)
491 ext_argtype[i] = "user_size_t";
492 munge32 = munge32 "w"
493 munge64 = munge64 "d"
494 }
495 else if (argtype[i] == "ssize_t") {
496 if (add_64bit_unsafe == 0)
497 ext_argtype[i] = "user_ssize_t";
498 munge32 = munge32 "s"
499 munge64 = munge64 "d"
500 }
501 else if (argtype[i] == "user_ssize_t" || argtype[i] == "user_long_t") {
502 munge32 = munge32 "s"
503 munge64 = munge64 "d"
504 }
505 else if (argtype[i] == "user_addr_t" || argtype[i] == "user_size_t" ||
506 argtype[i] == "user_ulong_t") {
507 munge32 = munge32 "w"
508 munge64 = munge64 "d"
509 }
510 else if (argtype[i] == "caddr_t" || argtype[i] == "semun_t" ||
511 match(argtype[i], "[\*]") != 0) {
512 if (add_64bit_unsafe == 0)
513 ext_argtype[i] = "user_addr_t";
514 munge32 = munge32 "w"
515 munge64 = munge64 "d"
516 }
517 else if (argtype[i] == "int" || argtype[i] == "u_int" ||
518 argtype[i] == "uid_t" || argtype[i] == "pid_t" ||
519 argtype[i] == "id_t" || argtype[i] == "idtype_t" ||
520 argtype[i] == "socklen_t" || argtype[i] == "uint32_t" || argtype[i] == "int32_t" ||
521 argtype[i] == "sigset_t" || argtype[i] == "gid_t" ||
37839358 522 argtype[i] == "mode_t" || argtype[i] == "key_t" || argtype[i] == "time_t") {
91447636
A
523 munge32 = munge32 "w"
524 munge64 = munge64 "d"
525 }
526 else if (argtype[i] == "off_t" || argtype[i] == "int64_t" || argtype[i] == "uint64_t") {
527 munge32 = munge32 "l"
528 munge64 = munge64 "d"
529 }
530 else {
531 printf "%s: line %d: invalid type \"%s\" \n",
532 infile, NR, argtype[i]
533 printf "You need to add \"%s\" into the type checking code. \n",
534 argtype[i]
535 exit 1
536 }
537 if (add_sysproto_entry == 1) {
538 printf("\tchar %s_l_[PADL_(%s)]; " \
539 "%s %s; char %s_r_[PADR_(%s)];\n",
540 argname[i], ext_argtype[i],
541 ext_argtype[i], argname[i],
542 argname[i], ext_argtype[i]) > sysarg
543 }
544 }
545 if (add_sysproto_entry == 1) {
546 printf("};\n") > sysarg
547 }
548 }
549 else if (add_sysproto_entry == 1) {
550 printf("struct %s {\n\tregister_t dummy;\n};\n", argalias) > sysarg
551 }
552 }
553
554 # output to init_sysent.c
555 tempname = funcname
556 if (add_sysent_entry == 0) {
557 argssize = "0"
558 munge32 = "NULL"
559 munge64 = "NULL"
560 munge_ret = "_SYSCALL_RET_NONE"
561 tempname = "nosys"
562 }
563 else {
564 # figure out which return value type to munge
565 if (returntype == "user_addr_t") {
566 munge_ret = "_SYSCALL_RET_ADDR_T"
567 }
568 else if (returntype == "user_ssize_t") {
569 munge_ret = "_SYSCALL_RET_SSIZE_T"
570 }
571 else if (returntype == "user_size_t") {
572 munge_ret = "_SYSCALL_RET_SIZE_T"
573 }
574 else if (returntype == "int") {
575 munge_ret = "_SYSCALL_RET_INT_T"
576 }
577 else if (returntype == "u_int") {
578 munge_ret = "_SYSCALL_RET_UINT_T"
579 }
580 else if (returntype == "off_t") {
581 munge_ret = "_SYSCALL_RET_OFF_T"
582 }
583 else if (returntype == "void") {
584 munge_ret = "_SYSCALL_RET_NONE"
585 }
586 else {
587 printf "%s: line %d: invalid return type \"%s\" \n",
588 infile, NR, returntype
589 printf "You need to add \"%s\" into the return type checking code. \n",
590 returntype
591 exit 1
592 }
593 }
594
595 if (add_64bit_unsafe == 1 && add_64bit_fakesafe == 0)
596 my_funnel = my_funnel "|UNSAFE_64BIT";
597
598 printf("\t{%s, %s, %s, \(sy_call_t *\)%s, %s, %s, %s},",
599 argssize, add_cancel_enable, my_funnel, tempname, munge32, munge64, munge_ret) > sysent
600 linesize = length(argssize) + length(add_cancel_enable) + length(my_funnel) + length(tempname) + \
601 length(munge32) + length(munge64) + length(munge_ret) + 28
602 align_comment(linesize, 88, sysent)
603 printf("/* %d = %s%s*/\n", syscall, funcname, additional_comments) > sysent
604
605 # output to syscalls.c
606 if (add_sysnames_entry == 1) {
607 tempname = funcname
608 if (funcname == "nosys") {
609 if (syscall == 0)
610 tempname = "syscall"
611 else
612 tempname = "#" syscall
613 }
614 printf("\t\"%s\", ", tempname) > syscallnamestempfile
615 linesize = length(tempname) + 8
616 align_comment(linesize, 25, syscallnamestempfile)
617 if (substr(tempname,1,1) == "#") {
618 printf("/* %d =%s*/\n", syscall, additional_comments) > syscallnamestempfile
619 }
620 else {
621 printf("/* %d = %s%s*/\n", syscall, tempname, additional_comments) > syscallnamestempfile
622 }
623 }
624
625 # output to syscalls.h
626 if (add_sysheader_entry == 1) {
627 tempname = funcname
628 if (syscall == 0) {
629 tempname = "syscall"
630 }
631 if (tempname != "nosys") {
632 printf("#define\t%s%s", syscallprefix, tempname) > syshdrtempfile
633 linesize = length(syscallprefix) + length(tempname) + 12
634 align_comment(linesize, 30, syshdrtempfile)
635 printf("%d\n", syscall) > syshdrtempfile
636 # special case for gettimeofday on ppc - cctools project uses old name
637 if (tempname == "ppc_gettimeofday") {
638 printf("#define\t%s%s", syscallprefix, "gettimeofday") > syshdrtempfile
639 linesize = length(syscallprefix) + length(tempname) + 12
640 align_comment(linesize, 30, syshdrtempfile)
641 printf("%d\n", syscall) > syshdrtempfile
642 }
643 }
644 else {
645 printf("\t\t\t/* %d %s*/\n", syscall, additional_comments) > syshdrtempfile
646 }
647 }
648
649 # output function prototypes to sysproto.h
650 if (add_sysproto_entry == 1) {
651 if (funcname =="exit") {
652 printf("void %s(struct proc *, struct %s *, int *);\n",
653 funcname, argalias) > sysprotoend
654 }
655 else if (funcname != "nosys" || (syscall == 0 && funcname == "nosys")) {
656 printf("int %s(struct proc *, struct %s *, %s *);\n",
657 funcname, argalias, returntype) > sysprotoend
658 }
659 }
660
661 syscall++
662 next
663 }
664
665 END {
8f6c56a5 666 printf "#ifdef __ppc__\n" > sysinc
91447636 667 printf "#define AC(name) (sizeof(struct name) / sizeof(uint64_t))\n" > sysinc
8f6c56a5
A
668 printf "#else\n" > sysinc
669 printf "#define AC(name) (sizeof(struct name) / sizeof(register_t))\n" > sysinc
670 printf "#endif\n" > sysinc
91447636
A
671 printf "\n" > sysinc
672
673 printf("\n__END_DECLS\n") > sysprotoend
674 printf("#undef PAD_\n") > sysprotoend
675 printf("#undef PADL_\n") > sysprotoend
676 printf("#undef PADR_\n") > sysprotoend
677 printf "\n#endif /* __APPLE_API_PRIVATE */\n" > sysprotoend
678 printf "#endif /* KERNEL */\n" > sysprotoend
679 printf("\n#endif /* !%s */\n", sysproto_h) > sysprotoend
680
681 printf("};\n") > sysent
682 printf("int nsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
683
684 printf("};\n") > syscallnamestempfile
685 printf("#define\t%sMAXSYSCALL\t%d\n", syscallprefix, syscall) \
686 > syshdrtempfile
687 printf("\n#endif /* __APPLE_API_PRIVATE */\n") > syshdrtempfile
688 printf("#endif /* !%s */\n", syscall_h) > syshdrtempfile
689 } '
690
691cat $syslegal $sysinc $sysent > $syscalltablefile
692cat $syslegal $sysarg $sysprotoend > $sysprotofile
693cat $syslegal $syscallnamestempfile > $syscallnamesfile
694cat $syslegal $syshdrtempfile > $syshdrfile