makesyscalls.sh revision 1.1.1.2 1 1.1 glass #! /bin/sh -
2 1.1.1.2 fvdl #
3 1.1.1.2 fvdl # @(#)makesyscalls.sh 8.2 (Berkeley) 2/14/95
4 1.1 glass
5 1.1 glass set -e
6 1.1 glass
7 1.1.1.2 fvdl case $# in
8 1.1.1.2 fvdl 2) ;;
9 1.1.1.2 fvdl *) echo "Usage: $0 config-file input-file" 1>&2
10 1.1.1.2 fvdl exit 1
11 1.1.1.2 fvdl ;;
12 1.1.1.2 fvdl esac
13 1.1 glass
14 1.1.1.2 fvdl # source the config file.
15 1.1.1.2 fvdl . $1
16 1.1.1.2 fvdl
17 1.1.1.2 fvdl # the config file sets the following variables:
18 1.1.1.2 fvdl # sysnames the syscall names file
19 1.1.1.2 fvdl # sysnumhdr the syscall numbers file
20 1.1.1.2 fvdl # syssw the syscall switch file
21 1.1.1.2 fvdl # sysarghdr the syscall argument struct definitions
22 1.1.1.2 fvdl # compatopts those syscall types that are for 'compat' syscalls
23 1.1.1.2 fvdl # switchname the name for the 'struct sysent' we define
24 1.1.1.2 fvdl # namesname the name for the 'char *[]' we define
25 1.1.1.2 fvdl # constprefix the prefix for the system call constants
26 1.1.1.2 fvdl #
27 1.1.1.2 fvdl # NOTE THAT THIS makesyscalls.sh DOES NOT SUPPORT 'LIBCOMPAT'.
28 1.1 glass
29 1.1 glass # tmp files:
30 1.1 glass sysdcl="sysent.dcl"
31 1.1.1.2 fvdl syscompat_pref="sysent."
32 1.1 glass sysent="sysent.switch"
33 1.1 glass
34 1.1.1.2 fvdl syscompat_files=""
35 1.1.1.2 fvdl for file in $compatopts; do
36 1.1.1.2 fvdl syscompat_files="$syscompat_files $syscompat_pref$file"
37 1.1.1.2 fvdl done
38 1.1.1.2 fvdl
39 1.1.1.2 fvdl trap "rm $sysdcl $syscompat_files $sysent" 0
40 1.1.1.2 fvdl
41 1.1.1.2 fvdl # Awk program (must support nawk extensions)
42 1.1.1.2 fvdl # Use "awk" at Berkeley, "nawk" or "gawk" elsewhere.
43 1.1.1.2 fvdl awk=${AWK:-awk}
44 1.1.1.2 fvdl
45 1.1.1.2 fvdl # Does this awk have a "toupper" function? (i.e. is it GNU awk)
46 1.1.1.2 fvdl isgawk=`$awk 'BEGIN { print toupper("true"); exit; }' 2>/dev/null`
47 1.1.1.2 fvdl
48 1.1.1.2 fvdl # If this awk does not define "toupper" then define our own.
49 1.1.1.2 fvdl if [ "$isgawk" = TRUE ] ; then
50 1.1.1.2 fvdl # GNU awk provides it.
51 1.1.1.2 fvdl toupper=
52 1.1.1.2 fvdl else
53 1.1.1.2 fvdl # Provide our own toupper()
54 1.1.1.2 fvdl toupper='
55 1.1.1.2 fvdl function toupper(str) {
56 1.1.1.2 fvdl _toupper_cmd = "echo "str" |tr a-z A-Z"
57 1.1.1.2 fvdl _toupper_cmd | getline _toupper_str;
58 1.1.1.2 fvdl close(_toupper_cmd);
59 1.1.1.2 fvdl return _toupper_str;
60 1.1.1.2 fvdl }'
61 1.1.1.2 fvdl fi
62 1.1.1.2 fvdl
63 1.1.1.2 fvdl # before handing it off to awk, make a few adjustments:
64 1.1.1.2 fvdl # (1) insert spaces around {, }, (, ), *, and commas.
65 1.1.1.2 fvdl # (2) get rid of any and all dollar signs (so that rcs id use safe)
66 1.1.1.2 fvdl #
67 1.1.1.2 fvdl # The awk script will deal with blank lines and lines that
68 1.1.1.2 fvdl # start with the comment character (';').
69 1.1.1.2 fvdl
70 1.1.1.2 fvdl sed -e '
71 1.1.1.2 fvdl s/\$//g
72 1.1.1.2 fvdl :join
73 1.1.1.2 fvdl /\\$/{a\
74 1.1.1.2 fvdl
75 1.1.1.2 fvdl N
76 1.1.1.2 fvdl s/\\\n//
77 1.1.1.2 fvdl b join
78 1.1.1.2 fvdl }
79 1.1.1.2 fvdl 2,${
80 1.1.1.2 fvdl /^#/!s/\([{}()*,]\)/ \1 /g
81 1.1.1.2 fvdl }
82 1.1.1.2 fvdl ' < $2 | $awk "
83 1.1.1.2 fvdl $toupper
84 1.1.1.2 fvdl BEGIN {
85 1.1.1.2 fvdl sysnames = \"$sysnames\"
86 1.1.1.2 fvdl sysnumhdr = \"$sysnumhdr\"
87 1.1.1.2 fvdl sysarghdr = \"$sysarghdr\"
88 1.1.1.2 fvdl switchname = \"$switchname\"
89 1.1.1.2 fvdl namesname = \"$namesname\"
90 1.1.1.2 fvdl constprefix = \"$constprefix\"
91 1.1.1.2 fvdl
92 1.1.1.2 fvdl sysdcl = \"$sysdcl\"
93 1.1.1.2 fvdl syscompat_pref = \"$syscompat_pref\"
94 1.1.1.2 fvdl sysent = \"$sysent\"
95 1.1.1.2 fvdl infile = \"$2\"
96 1.1.1.2 fvdl
97 1.1.1.2 fvdl compatopts = \"$compatopts\"
98 1.1.1.2 fvdl "'
99 1.1.1.2 fvdl
100 1.1.1.2 fvdl printf "/*\n * System call switch table.\n *\n" > sysdcl
101 1.1.1.2 fvdl printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysdcl
102 1.1.1.2 fvdl
103 1.1.1.2 fvdl ncompat = split(compatopts,compat)
104 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++) {
105 1.1.1.2 fvdl compat_upper[i] = toupper(compat[i])
106 1.1.1.2 fvdl compat_file[i] = sprintf("%s%s", syscompat_pref, compat[i])
107 1.1.1.2 fvdl
108 1.1.1.2 fvdl printf "\n#ifdef %s\n", compat_upper[i] > compat_file[i]
109 1.1.1.2 fvdl printf "#define %s(func) __CONCAT(%s_,func)\n\n", \
110 1.1.1.2 fvdl compat[i], compat[i] > compat_file[i]
111 1.1.1.2 fvdl }
112 1.1.1.2 fvdl
113 1.1.1.2 fvdl printf "/*\n * System call names.\n *\n" > sysnames
114 1.1.1.2 fvdl printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnames
115 1.1.1.2 fvdl
116 1.1.1.2 fvdl printf "/*\n * System call numbers.\n *\n" > sysnumhdr
117 1.1.1.2 fvdl printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysnumhdr
118 1.1.1.2 fvdl
119 1.1.1.2 fvdl printf "/*\n * System call argument lists.\n *\n" > sysarghdr
120 1.1.1.2 fvdl printf " * DO NOT EDIT-- this file is automatically generated.\n" > sysarghdr
121 1.1.1.2 fvdl }
122 1.1.1.2 fvdl NR == 1 {
123 1.1.1.2 fvdl printf " * created from%s\n */\n\n", $0 > sysdcl
124 1.1.1.2 fvdl
125 1.1.1.2 fvdl printf "#define\ts(type)\tsizeof(type)\n\n" > sysent
126 1.1.1.2 fvdl printf "struct sysent %s[] = {\n",switchname > sysent
127 1.1.1.2 fvdl
128 1.1.1.2 fvdl printf " * created from%s\n */\n\n", $0 > sysnames
129 1.1.1.2 fvdl printf "char *%s[] = {\n",namesname > sysnames
130 1.1.1.2 fvdl
131 1.1.1.2 fvdl printf " * created from%s\n */\n\n", $0 > sysnumhdr
132 1.1.1.2 fvdl
133 1.1.1.2 fvdl printf " * created from%s\n */\n\n", $0 > sysarghdr
134 1.1.1.2 fvdl printf "#define\tsyscallarg(x)\tunion { x datum; register_t pad; }\n" \
135 1.1.1.2 fvdl > sysarghdr
136 1.1.1.2 fvdl next
137 1.1.1.2 fvdl }
138 1.1.1.2 fvdl NF == 0 || $1 ~ /^;/ {
139 1.1.1.2 fvdl next
140 1.1.1.2 fvdl }
141 1.1.1.2 fvdl $1 ~ /^#[ ]*include/ {
142 1.1.1.2 fvdl print > sysdcl
143 1.1.1.2 fvdl next
144 1.1.1.2 fvdl }
145 1.1.1.2 fvdl $1 ~ /^#[ ]*if/ {
146 1.1.1.2 fvdl print > sysent
147 1.1.1.2 fvdl print > sysdcl
148 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++)
149 1.1.1.2 fvdl print > compat_file[i]
150 1.1.1.2 fvdl print > sysnames
151 1.1.1.2 fvdl savesyscall = syscall
152 1.1.1.2 fvdl next
153 1.1.1.2 fvdl }
154 1.1.1.2 fvdl $1 ~ /^#[ ]*else/ {
155 1.1.1.2 fvdl print > sysent
156 1.1.1.2 fvdl print > sysdcl
157 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++)
158 1.1.1.2 fvdl print > compat_file[i]
159 1.1.1.2 fvdl print > sysnames
160 1.1.1.2 fvdl syscall = savesyscall
161 1.1.1.2 fvdl next
162 1.1.1.2 fvdl }
163 1.1.1.2 fvdl $1 ~ /^#/ {
164 1.1.1.2 fvdl print > sysent
165 1.1.1.2 fvdl print > sysdcl
166 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++)
167 1.1.1.2 fvdl print > compat_file[i]
168 1.1.1.2 fvdl print > sysnames
169 1.1.1.2 fvdl next
170 1.1.1.2 fvdl }
171 1.1.1.2 fvdl syscall != $1 {
172 1.1.1.2 fvdl printf "%s: line %d: syscall number out of sync at %d\n", \
173 1.1.1.2 fvdl infile, NR, syscall
174 1.1.1.2 fvdl printf "line is:\n"
175 1.1.1.2 fvdl print
176 1.1 glass exit 1
177 1.1.1.2 fvdl }
178 1.1.1.2 fvdl function parserr(was, wanted) {
179 1.1.1.2 fvdl printf "%s: line %d: unexpected %s (expected %s)\n", \
180 1.1.1.2 fvdl infile, NR, was, wanted
181 1.1.1.2 fvdl exit 1
182 1.1.1.2 fvdl }
183 1.1.1.2 fvdl function parseline() {
184 1.1.1.2 fvdl f=3 # toss number and type
185 1.1.1.2 fvdl if ($NF != "}") {
186 1.1.1.2 fvdl funcalias=$NF
187 1.1.1.2 fvdl end=NF-1
188 1.1.1.2 fvdl } else {
189 1.1.1.2 fvdl funcalias=""
190 1.1.1.2 fvdl end=NF
191 1.1.1.2 fvdl }
192 1.1.1.2 fvdl if ($f != "{")
193 1.1.1.2 fvdl parserr($f, "{")
194 1.1.1.2 fvdl f++
195 1.1.1.2 fvdl if ($end != "}")
196 1.1.1.2 fvdl parserr($end, "}")
197 1.1.1.2 fvdl end--
198 1.1.1.2 fvdl if ($end != ";")
199 1.1.1.2 fvdl parserr($end, ";")
200 1.1.1.2 fvdl end--
201 1.1.1.2 fvdl if ($end != ")")
202 1.1.1.2 fvdl parserr($end, ")")
203 1.1.1.2 fvdl end--
204 1.1.1.2 fvdl
205 1.1.1.2 fvdl f++ # toss return type
206 1.1.1.2 fvdl
207 1.1.1.2 fvdl funcname=$f
208 1.1.1.2 fvdl if (funcalias == "")
209 1.1.1.2 fvdl funcalias=funcname
210 1.1.1.2 fvdl f++
211 1.1.1.2 fvdl
212 1.1.1.2 fvdl if ($f != "(")
213 1.1.1.2 fvdl parserr($f, ")")
214 1.1.1.2 fvdl f++
215 1.1.1.2 fvdl
216 1.1.1.2 fvdl argc= 0;
217 1.1.1.2 fvdl if (f == end) {
218 1.1.1.2 fvdl if ($f != "void")
219 1.1.1.2 fvdl parserr($f, "argument definition")
220 1.1.1.2 fvdl return
221 1.1.1.2 fvdl }
222 1.1.1.2 fvdl
223 1.1.1.2 fvdl while (f <= end) {
224 1.1.1.2 fvdl argc++
225 1.1.1.2 fvdl argtype[argc]=""
226 1.1.1.2 fvdl oldf=""
227 1.1.1.2 fvdl while (f < end && $(f+1) != ",") {
228 1.1.1.2 fvdl if (argtype[argc] != "" && oldf != "*")
229 1.1.1.2 fvdl argtype[argc] = argtype[argc]" ";
230 1.1.1.2 fvdl argtype[argc] = argtype[argc]$f;
231 1.1.1.2 fvdl oldf = $f;
232 1.1.1.2 fvdl f++
233 1.1.1.2 fvdl }
234 1.1.1.2 fvdl if (argtype[argc] == "")
235 1.1.1.2 fvdl parserr($f, "argument definition")
236 1.1.1.2 fvdl argname[argc]=$f;
237 1.1.1.2 fvdl f += 2; # skip name, and any comma
238 1.1.1.2 fvdl }
239 1.1.1.2 fvdl }
240 1.1.1.2 fvdl function putent(nodefs, declfile, compatwrap) {
241 1.1.1.2 fvdl # output syscall declaration for switch table
242 1.1.1.2 fvdl if (compatwrap == "")
243 1.1.1.2 fvdl printf("int\t%s();\n", funcname) > declfile
244 1.1.1.2 fvdl else
245 1.1.1.2 fvdl printf("int\t%s(%s)();\n", compatwrap, funcname) > declfile
246 1.1.1.2 fvdl
247 1.1.1.2 fvdl # output syscall switch entry
248 1.1.1.2 fvdl # printf("\t{ { %d", argc) > sysent
249 1.1.1.2 fvdl # for (i = 1; i <= argc; i++) {
250 1.1.1.2 fvdl # if (i == 5) # wrap the line
251 1.1.1.2 fvdl # printf(",\n\t ") > sysent
252 1.1.1.2 fvdl # else
253 1.1.1.2 fvdl # printf(", ") > sysent
254 1.1.1.2 fvdl # printf("s(%s)", argtypenospc[i]) > sysent
255 1.1.1.2 fvdl # }
256 1.1.1.2 fvdl printf("\t{ %d, ", argc) > sysent
257 1.1.1.2 fvdl if (argc == 0)
258 1.1.1.2 fvdl printf("0") > sysent
259 1.1.1.2 fvdl else if (compatwrap == "")
260 1.1.1.2 fvdl printf("s(struct %s_args)", funcname) > sysent
261 1.1.1.2 fvdl else
262 1.1.1.2 fvdl printf("s(struct %s_%s_args)", compatwrap, funcname) > sysent
263 1.1.1.2 fvdl if (compatwrap == "")
264 1.1.1.2 fvdl wfn = sprintf("%s", funcname);
265 1.1.1.2 fvdl else
266 1.1.1.2 fvdl wfn = sprintf("%s(%s)", compatwrap, funcname);
267 1.1.1.2 fvdl printf(",\n\t %s },", wfn) > sysent
268 1.1.1.2 fvdl for (i = 0; i < (33 - length(wfn)) / 8; i++)
269 1.1.1.2 fvdl printf("\t") > sysent
270 1.1.1.2 fvdl if (compatwrap == "")
271 1.1.1.2 fvdl printf("/* %d = %s */\n", syscall, funcalias) > sysent
272 1.1.1.2 fvdl else
273 1.1.1.2 fvdl printf("/* %d = %s %s */\n", syscall, compatwrap,
274 1.1.1.2 fvdl funcalias) > sysent
275 1.1.1.2 fvdl
276 1.1.1.2 fvdl # output syscall name for names table
277 1.1.1.2 fvdl if (compatwrap == "")
278 1.1.1.2 fvdl printf("\t\"%s\",\t\t\t/* %d = %s */\n", funcalias, syscall,
279 1.1.1.2 fvdl funcalias) > sysnames
280 1.1.1.2 fvdl else
281 1.1.1.2 fvdl printf("\t\"%s_%s\",\t/* %d = %s %s */\n", compatwrap,
282 1.1.1.2 fvdl funcalias, syscall, compatwrap, funcalias) > sysnames
283 1.1.1.2 fvdl
284 1.1.1.2 fvdl # output syscall number of header, if appropriate
285 1.1.1.2 fvdl if (nodefs == "" || nodefs == "NOARGS")
286 1.1.1.2 fvdl printf("#define\t%s%s\t%d\n", constprefix, funcalias,
287 1.1.1.2 fvdl syscall) > sysnumhdr
288 1.1.1.2 fvdl else if (nodefs != "NODEF")
289 1.1.1.2 fvdl printf("\t\t\t\t/* %d is %s %s */\n", syscall,
290 1.1.1.2 fvdl compatwrap, funcalias) > sysnumhdr
291 1.1.1.2 fvdl
292 1.1.1.2 fvdl # output syscall argument structure, if it has arguments
293 1.1.1.2 fvdl if (argc != 0 && nodefs != "NOARGS") {
294 1.1.1.2 fvdl if (compatwrap == "")
295 1.1.1.2 fvdl printf("\nstruct %s_args {\n", funcname) > sysarghdr
296 1.1.1.2 fvdl else
297 1.1.1.2 fvdl printf("\nstruct %s_%s_args {\n", compatwrap,
298 1.1.1.2 fvdl funcname) > sysarghdr
299 1.1.1.2 fvdl for (i = 1; i <= argc; i++)
300 1.1.1.2 fvdl printf("\tsyscallarg(%s) %s;\n", argtype[i],
301 1.1.1.2 fvdl argname[i]) > sysarghdr
302 1.1.1.2 fvdl printf("};\n") > sysarghdr
303 1.1.1.2 fvdl }
304 1.1.1.2 fvdl }
305 1.1.1.2 fvdl $2 == "STD" {
306 1.1.1.2 fvdl parseline()
307 1.1.1.2 fvdl putent("", sysdcl, "")
308 1.1.1.2 fvdl syscall++
309 1.1.1.2 fvdl next
310 1.1.1.2 fvdl }
311 1.1.1.2 fvdl $2 == "NODEF" || $2 == "NOARGS" {
312 1.1.1.2 fvdl parseline()
313 1.1.1.2 fvdl putent($2, sysdcl, "")
314 1.1.1.2 fvdl syscall++
315 1.1.1.2 fvdl next
316 1.1.1.2 fvdl }
317 1.1.1.2 fvdl $2 == "OBSOL" || $2 == "UNIMPL" {
318 1.1.1.2 fvdl if ($2 == "OBSOL")
319 1.1.1.2 fvdl comment="obsolete"
320 1.1.1.2 fvdl else
321 1.1.1.2 fvdl comment="unimplemented"
322 1.1.1.2 fvdl for (i = 3; i <= NF; i++)
323 1.1.1.2 fvdl comment=comment " " $i
324 1.1.1.2 fvdl
325 1.1.1.2 fvdl printf("\t{ 0, 0,\n\t nosys },\t\t\t\t/* %d = %s */\n", \
326 1.1.1.2 fvdl syscall, comment) > sysent
327 1.1.1.2 fvdl printf("\t\"#%d (%s)\",\t\t/* %d = %s */\n", \
328 1.1.1.2 fvdl syscall, comment, syscall, comment) > sysnames
329 1.1.1.2 fvdl if ($2 != "UNIMPL")
330 1.1.1.2 fvdl printf("\t\t\t\t/* %d is %s */\n", syscall, comment) > sysnumhdr
331 1.1.1.2 fvdl syscall++
332 1.1.1.2 fvdl next
333 1.1.1.2 fvdl }
334 1.1.1.2 fvdl {
335 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++) {
336 1.1.1.2 fvdl if ($2 == compat_upper[i]) {
337 1.1.1.2 fvdl parseline();
338 1.1.1.2 fvdl putent("COMMENT", compat_file[i], compat[i])
339 1.1.1.2 fvdl syscall++
340 1.1.1.2 fvdl next
341 1.1.1.2 fvdl }
342 1.1.1.2 fvdl }
343 1.1.1.2 fvdl printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
344 1.1.1.2 fvdl exit 1
345 1.1.1.2 fvdl }
346 1.1.1.2 fvdl END {
347 1.1.1.2 fvdl printf "\n#undef\tsyscallarg\n" > sysarghdr
348 1.1.1.2 fvdl
349 1.1.1.2 fvdl for (i = 1; i <= ncompat; i++) {
350 1.1.1.2 fvdl printf("\n#else /* %s */\n", compat_upper[i]) > compat_file[i]
351 1.1.1.2 fvdl printf("#define %s(func) nosys\n", compat[i]) > \
352 1.1.1.2 fvdl compat_file[i]
353 1.1.1.2 fvdl printf("#endif /* %s */\n\n", compat_upper[i]) > compat_file[i]
354 1.1.1.2 fvdl }
355 1.1.1.2 fvdl
356 1.1.1.2 fvdl printf("};\n\n") > sysent
357 1.1.1.2 fvdl printf("int\tn%s= sizeof(%s) / sizeof(%s[0]);\n", switchname,
358 1.1.1.2 fvdl switchname, switchname) > sysent
359 1.1 glass
360 1.1.1.2 fvdl printf("};\n") > sysnames
361 1.1.1.2 fvdl } '
362 1.1 glass
363 1.1.1.2 fvdl cat $sysdcl $syscompat_files $sysent > $syssw
364 1.1 glass
365 1.1.1.2 fvdl #chmod 444 $sysnames $syshdr $syssw
366