makesyscalls.sh revision 1.4 1 #! /bin/sh -
2 # from: @(#)makesyscalls.sh 7.6 (Berkeley) 4/20/91
3 # $Id: makesyscalls.sh,v 1.4 1993/05/20 16:17:38 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 %s %s %s\n */\n\n",$2,$3,$4,$5 > 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 %s %s %s\n */\n\n",$2,$3,$4,$5 > sysnames
60 printf "char *syscallnames[] = {\n" > sysnames
61
62 printf " * created from: %s %s %s %s\n */\n\n",$2,$3,$4,$5 > syshdr
63 printf "#ifndef _SYS_SYSCALL_H\n" > syshdr
64 printf "#define _SYS_SYSCALL_H\n" > syshdr
65 printf "\n" > syshdr
66 next
67 }
68 NF == 0 || $1 ~ /^;/ {
69 next
70 }
71 $1 ~ /^#[ ]*if/ {
72 print > sysent
73 print > sysdcl
74 print > syscompat
75 print > sysnames
76 savesyscall = syscall
77 next
78 }
79 $1 ~ /^#[ ]*else/ {
80 print > sysent
81 print > sysdcl
82 print > syscompat
83 print > sysnames
84 syscall = savesyscall
85 next
86 }
87 $1 ~ /^#/ {
88 print > sysent
89 print > sysdcl
90 print > syscompat
91 print > sysnames
92 next
93 }
94 syscall != $1 {
95 printf "%s: line %d: syscall number out of sync at %d\n", \
96 infile, NR, syscall
97 printf "line is:\n"
98 print
99 exit 1
100 }
101 { comment = $4
102 for (i = 5; i <= NF; i++)
103 comment = comment " " $i
104 if (NF < 5)
105 $5 = $4
106 }
107 $2 == "STD" {
108 printf("int\t%s();\n", $4) > sysdcl
109 printf("\t%d, %s,\t\t\t/* %d = %s */\n", \
110 $3, $4, syscall, $5) > sysent
111 printf("\t\"%s\",\t\t\t/* %d = %s */\n", \
112 $5, syscall, $5) > sysnames
113 printf("#define\tSYS_%s\t%d\n", \
114 $5, syscall) > syshdr
115 syscall++
116 next
117 }
118 $2 == "COMPAT" {
119 printf("int\to%s();\n", $4) > syscompat
120 printf("\tcompat(%d,%s),\t\t/* %d = old %s */\n", \
121 $3, $4, syscall, $5) > sysent
122 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
123 $5, syscall, $5) > sysnames
124 printf("\t\t\t\t/* %d is old %s */\n", \
125 syscall, comment) > syshdr
126 syscall++
127 next
128 }
129 $2 == "LIBCOMPAT" {
130 printf("int\to%s();\n", $4) > syscompat
131 printf("\tcompat(%d,%s),\t\t/* %d = old %s */\n", \
132 $3, $4, syscall, $5) > sysent
133 printf("\t\"old.%s\",\t\t/* %d = old %s */\n", \
134 $5, syscall, $5) > sysnames
135 printf("#define\tSYS_%s\t%d\t/* compatibility; still used by libc */\n", \
136 $5, syscall) > syshdr
137 syscall++
138 next
139 }
140 $2 == "OBSOL" {
141 printf("\t0, nosys,\t\t\t/* %d = obsolete %s */\n", \
142 syscall, comment) > sysent
143 printf("\t\"obs_%s\",\t\t\t/* %d = obsolete %s */\n", \
144 $4, syscall, comment) > sysnames
145 printf("\t\t\t\t/* %d is obsolete %s */\n", \
146 syscall, comment) > syshdr
147 syscall++
148 next
149 }
150 $2 == "UNIMPL" {
151 printf("\t0, nosys,\t\t\t/* %d = %s */\n", \
152 syscall, comment) > sysent
153 printf("\t\"#%d\",\t\t\t/* %d = %s */\n", \
154 syscall, syscall, comment) > sysnames
155 syscall++
156 next
157 }
158 {
159 printf "%s: line %d: unrecognized keyword %s\n", infile, NR, $2
160 exit 1
161 }
162 END {
163 printf("\n#else /* %s */\n", compat) > syscompat
164 printf("#define compat(n, name) 0, nosys\n") > syscompat
165 printf("#endif /* %s */\n\n", compat) > syscompat
166
167 printf("};\n\n") > sysent
168 printf("int\tnsysent = sizeof(sysent) / sizeof(sysent[0]);\n") > sysent
169
170 printf("};\n") > sysnames
171
172 printf "\n" > syshdr
173 printf "#endif /* _SYS_SYSCALL_H */\n" > syshdr
174 } '
175
176 cat $sysdcl $syscompat $sysent >$syssw
177
178 #chmod 444 $sysnames $syshdr $syssw
179