makesyscalls.sh revision 1.8 1 #! /bin/sh -
2 # from: @(#)makesyscalls.sh 8.1 (Berkeley) 6/10/93
3 # $Id: makesyscalls.sh,v 1.8 1994/05/18 04:15:51 mycroft 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 next
71 }
72 NF == 0 || $1 ~ /^;/ {
73 next
74 }
75 $1 ~ /^#[ ]*if/ {
76 print > sysent
77 print > sysdcl
78 print > syscompat
79 print > sysnames
80 savesyscall = syscall
81 next
82 }
83 $1 ~ /^#[ ]*else/ {
84 print > sysent
85 print > sysdcl
86 print > syscompat
87 print > sysnames
88 syscall = savesyscall
89 next
90 }
91 $1 ~ /^#/ {
92 print > sysent
93 print > sysdcl
94 print > syscompat
95 print > sysnames
96 next
97 }
98 syscall != $1 {
99 printf "%s: line %d: syscall number out of sync at %d\n", \
100 infile, NR, syscall
101 printf "line is:\n"
102 print
103 exit 1
104 }
105 { comment = $4
106 for (i = 5; i <= NF; i++)
107 comment = comment " " $i
108 if (NF < 5)
109 $5 = $4
110 }
111 $2 == "STD" || $2 == "NODEF" {
112 printf("int\t%s();\n", $4) > sysdcl
113 printf("\t{ %d, %s },\t\t\t/* %d = %s */\n", \
114 $3, $4, syscall, $5) > sysent
115 printf("\t\"%s\",\t\t\t/* %d = %s */\n", \
116 $5, syscall, $5) > sysnames
117 if ($2 == "STD")
118 printf("#define\tSYS_%s\t%d\n", \
119 $5, syscall) > syshdr
120 syscall++
121 next
122 }
123 $2 == "COMPAT" {
124 printf("int\to%s();\n", $4) > syscompat
125 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
126 $3, $4, syscall, $5) > sysent
127 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
128 $5, syscall, $5) > sysnames
129 printf("\t\t\t\t/* %d is old %s */\n", \
130 syscall, comment) > syshdr
131 syscall++
132 next
133 }
134 $2 == "NCOMPAT" {
135 printf("int\to%s();\n", $4) > sysncompat
136 printf("\t{ ncompat(%d,%s) },\t\t/* %d = old %s */\n", \
137 $3, $4, syscall, $5) > sysent
138 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
139 $5, syscall, $5) > sysnames
140 printf("\t\t\t\t/* %d is old %s */\n", \
141 syscall, comment) > syshdr
142 syscall++
143 next
144 }
145 $2 == "LIBCOMPAT" {
146 printf("int\to%s();\n", $4) > syscompat
147 printf("\t{ compat(%d,%s) },\t\t/* %d = old %s */\n", \
148 $3, $4, syscall, $5) > sysent
149 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
150 $5, syscall, $5) > sysnames
151 printf("#define\tSYS_%s\t%d\t/* compatibility; still used by libc */\n", \
152 $5, syscall) > syshdr
153 syscall++
154 next
155 }
156 $2 == "OBSOL" {
157 printf("\t{ 0, nosys },\t\t\t/* %d = obsolete %s */\n", \
158 syscall, comment) > sysent
159 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n", \
160 $4, syscall, comment) > sysnames
161 printf("\t\t\t\t/* %d is obsolete %s */\n", \
162 syscall, comment) > syshdr
163 syscall++
164 next
165 }
166 $2 == "UNIMPL" {
167 printf("\t{ 0, nosys },\t\t\t/* %d = %s */\n", \
168 syscall, comment) > sysent
169 printf("\t\"#%d\",\t\t\t/* %d = %s */\n", \
170 syscall, syscall, comment) > sysnames
171 syscall++
172 next
173 }
174 {
175 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
176 exit 1
177 }
178 END {
179 printf("\n#else /* %s */\n", compat) > syscompat
180 printf("#define compat(n, name) 0, nosys\n") > syscompat
181 printf("#endif /* %s */\n\n", compat) > syscompat
182
183 printf("\n#else /* %s */\n", compat) > sysncompat
184 printf("#define ncompat(n, name) 0, nosys\n") > sysncompat
185 printf("#endif /* %s */\n\n", compat) > sysncompat
186
187 printf("};\n\n") > sysent
188 printf("int\tnsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
189
190 printf("};\n") > sysnames
191 } '
192
193 cat $sysdcl $syscompat $sysncompat $sysent >$syssw
194
195 #chmod 444 $sysnames $syshdr $syssw
196