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