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