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