Home | History | Annotate | Line # | Download | only in kern
makesyscalls.sh revision 1.10
      1 #! /bin/sh -
      2 #	$NetBSD: makesyscalls.sh,v 1.10 1994/06/30 16:43:01 cgd Exp $
      3 #
      4 #	@(#)makesyscalls.sh	8.1 (Berkeley) 6/10/93
      5 
      6 set -e
      7 
      8 # name of compat option:
      9 compat=COMPAT_43
     10 ncompat=COMPAT_09
     11 
     12 # output files:
     13 sysnames="syscalls.c"
     14 syshdr="../sys/syscall.h"
     15 syssw="init_sysent.c"
     16 
     17 # tmp files:
     18 sysdcl="sysent.dcl"
     19 syscompat="sysent.compat"
     20 sysncompat="sysent.ncompat"
     21 sysent="sysent.switch"
     22 
     23 trap "rm $sysdcl $syscompat $sysncompat $sysent" 0
     24 
     25 case $# in
     26     0)	echo "Usage: $0 input-file" 1>&2
     27 	exit 1
     28 	;;
     29 esac
     30 
     31 awk < $1 "
     32 	BEGIN {
     33 		sysdcl = \"$sysdcl\"
     34 		syscompat = \"$syscompat\"
     35 		sysncompat = \"$sysncompat\"
     36 		sysent = \"$sysent\"
     37 		sysnames = \"$sysnames\"
     38 		syshdr = \"$syshdr\"
     39 		compat = \"$compat\"
     40 		ncompat = \"$ncompat\"
     41 		infile = \"$1\"
     42 		"'
     43 
     44 		printf "/*\n * System call switch table.\n *\n" > sysdcl
     45 		printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
     46 
     47 		printf "\n#ifdef %s\n", compat > syscompat
     48 		printf "#define compat(n, name) n, __CONCAT(o,name)\n\n" > syscompat
     49 
     50 		printf "\n#ifdef %s\n", ncompat > sysncompat
     51 		printf "#define ncompat(n, name) n, __CONCAT(o,name)\n\n" > sysncompat
     52 
     53 		printf "/*\n * System call names.\n *\n" > sysnames
     54 		printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
     55 
     56 		printf "/*\n * System call numbers.\n *\n" > syshdr
     57 		printf " * DO NOT EDIT-- this file is automatically generated.\n" > syshdr
     58 	}
     59 	NR == 1 {
     60 		printf " * created from: NetBSD %s %s %s %s\n */\n\n",$2,$3,$4,$5 > sysdcl
     61 		printf "#include <sys/param.h>\n" > sysdcl
     62 		printf "#include <sys/systm.h>\n\n" > sysdcl
     63 		printf "int\tnosys();\n\n" > sysdcl
     64 
     65 		printf "struct sysent sysent[] = {\n" > sysent
     66 
     67 		printf " * created from: NetBSD %s %s %s %s\n */\n\n",$2,$3,$4,$5 > sysnames
     68 		printf "char *syscallnames[] = {\n" > sysnames
     69 
     70 		printf " * created from: NetBSD %s %s %s %s\n */\n\n",$2,$3,$4,$5 > syshdr
     71 		next
     72 	}
     73 	NF == 0 || $1 ~ /^;/ {
     74 		next
     75 	}
     76 	$1 ~ /^#[ 	]*if/ {
     77 		print > sysent
     78 		print > sysdcl
     79 		print > syscompat
     80 		print > sysnames
     81 		savesyscall = syscall
     82 		next
     83 	}
     84 	$1 ~ /^#[ 	]*else/ {
     85 		print > sysent
     86 		print > sysdcl
     87 		print > syscompat
     88 		print > sysnames
     89 		syscall = savesyscall
     90 		next
     91 	}
     92 	$1 ~ /^#/ {
     93 		print > sysent
     94 		print > sysdcl
     95 		print > syscompat
     96 		print > sysnames
     97 		next
     98 	}
     99 	syscall != $1 {
    100 		printf "%s: line %d: syscall number out of sync at %d\n", \
    101 		   infile, NR, syscall
    102 		printf "line is:\n"
    103 		print
    104 		exit 1
    105 	}
    106 	{	comment = $4
    107 		for (i = 5; i <= NF; i++)
    108 			comment = comment " " $i
    109 		if (NF < 5)
    110 			$5 = $4
    111 	}
    112 	$2 == "STD" || $2 == "NODEF" {
    113 		printf("int\t%s();\n", $4) > sysdcl
    114 		printf("\t{ %d, %s },\t\t\t/* %d = %s */\n", \
    115 		    $3, $4, syscall, $5) > sysent
    116 		printf("\t\"%s\",\t\t\t/* %d = %s */\n", \
    117 		    $5, syscall, $5) > sysnames
    118 		if ($2 == "STD")
    119 			printf("#define\tSYS_%s\t%d\n", \
    120 			    $5, syscall) > syshdr
    121 		syscall++
    122 		next
    123 	}
    124 	$2 == "COMPAT" {
    125 		printf("int\to%s();\n", $4) > syscompat
    126 		printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
    127 		    $3, $4, syscall, $5) > sysent
    128 		printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
    129 		    $5, syscall, $5) > sysnames
    130 		printf("\t\t\t\t/* %d is old %s */\n", \
    131 		    syscall, comment) > syshdr
    132 		syscall++
    133 		next
    134 	}
    135 	$2 == "NCOMPAT" {
    136 		printf("int\to%s();\n", $4) > sysncompat
    137 		printf("\t{ ncompat(%d,%s) },\t\t/* %d = old %s */\n", \
    138 		    $3, $4, syscall, $5) > sysent
    139 		printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
    140 		    $5, syscall, $5) > sysnames
    141 		printf("\t\t\t\t/* %d is old %s */\n", \
    142 		    syscall, comment) > syshdr
    143 		syscall++
    144 		next
    145 	}
    146 	$2 == "LIBCOMPAT" {
    147 		printf("int\to%s();\n", $4) > syscompat
    148 		printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
    149 		    $3, $4, syscall, $5) > sysent
    150 		printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
    151 		    $5, syscall, $5) > sysnames
    152 		printf("#define\tSYS_%s\t%d\t/* compatibility; still used by libc */\n", \
    153 		    $5, syscall) > syshdr
    154 		syscall++
    155 		next
    156 	}
    157 	$2 == "OBSOL" {
    158 		printf("\t{ 0, nosys },\t\t\t/* %d = obsolete %s */\n", \
    159 		    syscall, comment) > sysent
    160 		printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n", \
    161 		    $4, syscall, comment) > sysnames
    162 		printf("\t\t\t\t/* %d is obsolete %s */\n", \
    163 		    syscall, comment) > syshdr
    164 		syscall++
    165 		next
    166 	}
    167 	$2 == "UNIMPL" {
    168 		printf("\t{ 0, nosys },\t\t\t/* %d = %s */\n", \
    169 		    syscall, comment) > sysent
    170 		printf("\t\"#%d\",\t\t\t/* %d = %s */\n", \
    171 		    syscall, syscall, comment) > sysnames
    172 		syscall++
    173 		next
    174 	}
    175 	{
    176 		printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
    177 		exit 1
    178 	}
    179 	END {
    180 		printf("\n#else /* %s */\n", compat) > syscompat
    181 		printf("#define compat(n, name) 0, nosys\n") > syscompat
    182 		printf("#endif /* %s */\n\n", compat) > syscompat
    183 
    184 		printf("\n#else /* %s */\n", compat) > sysncompat
    185 		printf("#define ncompat(n, name) 0, nosys\n") > sysncompat
    186 		printf("#endif /* %s */\n\n", compat) > sysncompat
    187 
    188 		printf("};\n\n") > sysent
    189 		printf("int\tnsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
    190 
    191 		printf("};\n") > sysnames
    192 	} '
    193 
    194 cat $sysdcl $syscompat $sysncompat $sysent >$syssw
    195 
    196 #chmod 444 $sysnames $syshdr $syssw
    197