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