Define bit_SSE2 and index_SSE2.
[glibc.git] / sysdeps / unix / make-syscalls.sh
bloba8b8a262a7cd20ee9fd4618ddc94120d283a813e
1 #! /bin/sh
3 # Usage: make-syscalls.sh ../sysdeps/unix/common
4 # Expects $sysdirs in environment.
6 ##############################################################################
8 # Syscall Signature Key Letters for BP Thunks:
10 # a: unchecked address (e.g., 1st arg to mmap)
11 # b: non-NULL buffer (e.g., 2nd arg to read; return value from mmap)
12 # B: optionally-NULL buffer (e.g., 4th arg to getsockopt)
13 # f: buffer of 2 ints (e.g., 4th arg to socketpair)
14 # F: 3rd arg to fcntl
15 # i: scalar (any signedness & size: int, long, long long, enum, whatever)
16 # I: 3rd arg to ioctl
17 # n: scalar buffer length (e.g., 3rd arg to read)
18 # N: pointer to value/return scalar buffer length (e.g., 6th arg to recvfrom)
19 # p: non-NULL pointer to typed object (e.g., any non-void* arg)
20 # P: optionally-NULL pointer to typed object (e.g., 2nd argument to gettimeofday)
21 # s: non-NULL string (e.g., 1st arg to open)
22 # S: optionally-NULL string (e.g., 1st arg to acct)
23 # v: vararg scalar (e.g., optional 3rd arg to open)
24 # V: byte-per-page vector (3rd arg to mincore)
25 # W: wait status, optionally-NULL pointer to int (e.g., 2nd arg of wait4)
27 ptr='[abBfFINpPsSWV]' # all pointer keyletters
28 int='[inv]' # all scalar keyletters
29 typ='[ifnNpP]' # typed-arg keyletters: we capture type for use in thunk
31 ##############################################################################
33 thisdir=$1; shift
35 echo ''
36 echo \#### DIRECTORY = $thisdir
37 # Check each sysdep dir with higher priority than this one,
38 # and remove from $calls all the functions found in other dirs.
39 # Punt when we reach the directory defining these syscalls.
40 sysdirs=`for dir in $sysdirs; do
41 test $dir = $thisdir && break; echo $dir; done`
42 echo \#### SYSDIRS = $sysdirs
44 # Get the list of system calls for this directory.
45 calls=`sed 's/#.*$//
46 /^[ ]*$/d' $thisdir/syscalls.list`
48 calls=`echo "$calls" |
49 while read file caller rest; do
50 # Remove each syscall that is implemented by a file in $dir.
51 # If a syscall specified a "caller", then only compile that syscall
52 # if the caller function is also implemented in this directory.
53 srcfile=-;
54 for dir in $sysdirs; do
55 { test -f $dir/$file.c && srcfile=$dir/$file.c; } ||
56 { test -f $dir/$file.S && srcfile=$dir/$file.S; } ||
57 { test -f $dir/$file.s && srcfile=$dir/$file.s; } ||
58 { test x$caller != x- &&
59 { { test -f $dir/$caller.c && srcfile=$dir/$caller.c; } ||
60 { test -f $dir/$caller.S && srcfile=$dir/$caller.S; } ||
61 { test -f $dir/$caller.s && srcfile=$dir/$caller.s; }; }; } && break;
62 done;
63 echo $file $srcfile $caller $rest;
64 done`
66 # Any calls left?
67 test -n "$calls" || exit 0
69 # Emit rules to compile the syscalls remaining in $calls.
70 echo "$calls" |
71 while read file srcfile caller syscall args strong weak; do
73 case x"$syscall" in
74 x-) callnum=_ ;;
76 # Figure out if $syscall is defined with a number in syscall.h.
77 callnum=-
78 eval `{ echo "#include <sysdep.h>";
79 echo "callnum=SYS_ify ($syscall)"; } |
80 $asm_CPP -D__OPTIMIZE__ - |
81 sed -n -e "/^callnum=.*$syscall/d" \
82 -e "/^\(callnum=\)[ ]*\(.*\)/s//\1'\2'/p"`
84 esac
86 cancellable=0
87 noerrno=0
88 errval=0
89 case $args in
90 C*) cancellable=1; args=`echo $args | sed 's/C:\?//'`;;
91 E*) noerrno=1; args=`echo $args | sed 's/E:\?//'`;;
92 V*) errval=1; args=`echo $args | sed 's/V:\?//'`;;
93 esac
95 # Derive the number of arguments from the argument signature
96 case $args in
97 [0-9]) nargs=$args;;
98 ?:) nargs=0;;
99 ?:?) nargs=1;;
100 ?:??) nargs=2;;
101 ?:???) nargs=3;;
102 ?:????) nargs=4;;
103 ?:?????) nargs=5;;
104 ?:??????) nargs=6;;
105 ?:???????) nargs=7;;
106 ?:????????) nargs=8;;
107 ?:?????????) nargs=9;;
108 esac
110 # Make sure only the first syscall rule is used, if multiple dirs
111 # define the same syscall.
112 echo ''
113 echo "#### CALL=$file NUMBER=$callnum ARGS=$args SOURCE=$srcfile"
115 case x$srcfile"$callnum" in
116 x--)
117 # Undefined callnum for an extra syscall.
118 if [ x$caller != x- ]; then
119 if [ $noerrno != 0 ]; then
120 echo >&2 "$0: no number for $fileno, no-error syscall ($strong $weak)"
121 exit 2
123 echo "unix-stub-syscalls += $strong $weak"
126 x*-) ;; ### Do nothing for undefined callnum
127 x-*)
128 echo "ifeq (,\$(filter $file,\$(unix-syscalls)))"
130 case $weak in
131 *@*)
132 # The versioned symbols are only in the shared library.
133 echo "ifneq (,\$(filter .os,\$(object-suffixes)))"
135 esac
136 # Accumulate the list of syscall files for this directory.
137 echo "unix-syscalls += $file"
138 test x$caller = x- || echo "unix-extra-syscalls += $file"
140 # Emit a compilation rule for this syscall.
141 case $weak in
142 *@*)
143 # The versioned symbols are only in the shared library.
144 echo "\
145 shared-only-routines += $file
146 \$(objpfx)${file}.os: \\"
149 echo "\
150 \$(foreach p,\$(sysd-rules-targets),\
151 \$(foreach o,\$(object-suffixes),\$(objpfx)\$(patsubst %,\$p,$file)\$o)): \\"
153 esac
155 echo " \$(..)sysdeps/unix/make-syscalls.sh"
156 case x"$callnum" in
158 echo "\
159 \$(make-target-directory)
160 (echo '/* Dummy module requested by syscalls.list */'; \\"
163 echo "\
164 \$(make-target-directory)
165 (echo '#define SYSCALL_NAME $syscall'; \\
166 echo '#define SYSCALL_NARGS $nargs'; \\
167 echo '#define SYSCALL_SYMBOL $strong'; \\"
168 [ $cancellable = 0 ] || echo "\
169 echo '#define SYSCALL_CANCELLABLE 1'; \\"
170 [ $noerrno = 0 ] || echo "\
171 echo '#define SYSCALL_NOERRNO 1'; \\"
172 [ $errval = 0 ] || echo "\
173 echo '#define SYSCALL_ERRVAL 1'; \\"
174 echo "\
175 echo '#include <syscall-template.S>'; \\"
177 esac
179 # Append any weak aliases or versions defined for this syscall function.
181 # A shortcoming in the current gas is that it will only allow one
182 # version-alias per symbol. So we create new strong aliases as needed.
183 vcount=""
185 for name in $weak; do
186 case $name in
187 *@@*)
188 base=`echo $name | sed 's/@@.*//'`
189 ver=`echo $name | sed 's/.*@@//'`
190 if test -z "$vcount" ; then
191 source=$strong
192 vcount=1
193 else
194 source="${strong}_${vcount}"
195 vcount=`expr $vcount + 1`
196 echo " echo 'strong_alias ($strong, $source)'; \\"
198 echo " echo 'default_symbol_version($source, $base, $ver)'; \\"
200 *@*)
201 base=`echo $name | sed 's/@.*//'`
202 ver=`echo $name | sed 's/.*@//'`
203 if test -z "$vcount" ; then
204 source=$strong
205 vcount=1
206 else
207 source="${strong}_${vcount}"
208 vcount=`expr $vcount + 1`
209 echo " echo 'strong_alias ($strong, $source)'; \\"
211 echo " echo 'symbol_version ($source, $base, $ver)'; \\"
214 name=`echo $name | sed 's/.//'`
215 echo " echo 'strong_alias ($strong, $name)'; \\"
216 echo " echo 'libc_hidden_def ($name)'; \\"
219 echo " echo 'weak_alias ($strong, $name)'; \\"
220 echo " echo 'libc_hidden_weak ($name)'; \\"
222 esac
223 done
225 # And finally, pipe this all into the compiler.
226 echo ' ) | $(compile-syscall) '"\
227 \$(foreach p,\$(patsubst %$file,%,\$(basename \$(@F))),\$(\$(p)CPPFLAGS))"
229 case $weak in
230 *@*)
231 # The versioned symbols are only in the shared library.
232 echo endif
234 esac
236 echo endif
238 esac
240 case x"$callnum",$srcfile,$args in
241 x[_-],-,* | x*,*.[sS],*V*) ;;
242 x*,-,*$ptr* | x*,*.[sS],*$ptr*)
244 nv_weak=`for name in $weak; do
245 case $name in
246 *@*) ;;
247 *) echo $name;;
248 esac; done`
250 # choose the name with the fewest leading underscores, preferably none
251 set `echo $strong $nv_weak |tr '@ \t' ' \n\n' |sort -r`
252 callname=$1
254 # convert signature string to individual numbered arg names
255 # e.g., i:ipbN -> i0 i1 p2 b3 N4
256 set `echo $args |
257 sed -e 's/^\(.\):\(.*\)/\2 <\10>/' \
258 -e 's/^\([^ ]\)\(.*\)/\2 <\11>/' \
259 -e 's/^\([^ ]\)\(.*\)/\2 <\12>/' \
260 -e 's/^\([^ ]\)\(.*\)/\2 <\13>/' \
261 -e 's/^\([^ ]\)\(.*\)/\2 <\14>/' \
262 -e 's/^\([^ ]\)\(.*\)/\2 <\15>/' \
263 -e 's/^\([^ ]\)\(.*\)/\2 <\16>/' \
264 -e 's/^\([^ ]\)\(.*\)/\2 <\17>/' \
265 -e 's/^\([^ ]\)\(.*\)/\2 <\18>/' \
266 -e 's/^\([^ ]\)\(.*\)/\2 <\19>/'`
267 rtn=$1; shift
268 args=$*
269 arglist=`echo $* |sed 's/ /, /g'`
271 # The best way to understand what's going on here is to examine
272 # the output in BUILDDIR/sysd-syscalls.
274 # generate makefile envelope & rule head
275 echo "ifeq (,\$(filter $file,\$(bp-thunks)))"
276 echo "bp-thunks += $file"
277 echo "\$(objpfx)\$(bppfx)$file.ob: \$(common-objpfx)s-proto-bp.d"
279 # generate macro head
280 echo " (echo '#define $callname(`echo $arglist | \
281 sed -e 's/[<>]//g'`) `echo $rtn | \
282 sed -e 's/<\('$typ'0\)>/\1v;/g' \
283 -e 's/<\(b0\)>/x0; extern char \1v;/g'` \\'; \\"
285 # generate extern decls of dummy variables for each arg
286 echo " echo '`echo $args | \
287 sed -e 's/<\('$typ'[1-9]\)>/extern \1, \1v;/g' \
288 -e 's/<\([abBFIsSV][1-9]\)>/extern char \1v;/g' \
289 -e 's/<\([Wv][1-9]\)>/extern int \1v;/g'` \\'; \\"
291 # generate bounded-pointer thunk declarator
292 echo " echo '`echo $rtn | \
293 sed -e 's/<\('$ptr'0\)>/__typeof (\1v) *__bounded/g' \
294 -e 's/<\('$int'0\)>/__typeof (\1v)/g'` BP_SYM ($strong) (`echo $arglist | \
295 sed -e 's/<\('$ptr'[1-9]\)>/__typeof (\1v) *__bounded \1a/g' \
296 -e 's/<\('$int'[1-9]\)>/__typeof (\1v) \1a/g'`) { \\'; \\"
298 # generate extern primitive syscall declaration
299 echo " echo ' extern `echo $rtn | \
300 sed -e 's/<\('$ptr'0\)>/__typeof (\1v) *__unbounded/g' \
301 -e 's/<\('$int'0\)>/__typeof (\1v)/g'` ($callname) (`echo $arglist | \
302 sed -e 's/<\('$ptr'[1-9]\)>/__typeof (\1v) *__unbounded/g' \
303 -e 's/<\('$int'[1-9]\)>/__typeof (\1v)/g'`); \\'; \\"
305 # generate call the primtive system call, optionally wrapping bounds
306 # around the result if the signature's return keyletter is `b'.
307 echo " echo ' return `echo $rtn |
308 sed -e 's/<b0>/BOUNDED_N (/' \
309 -e 's/<.0>//'`($callname) (`echo $arglist | \
310 sed -e 's/<\(a[1-9]\)>/__ptrvalue (\1a)/g' \
311 -e 's/<\(n[1-9]\)>, <\(V[1-9]\)>/\1a, CHECK_N_PAGES (\2a, \1a)/g' \
312 -e 's/<\(b[1-9]\)>, <\(n[1-9]\)>/CHECK_N (\1a, \2a), \2a/g' \
313 -e 's/<\(b[1-9]\)>, <\(N[1-9]\)>/CHECK_N (\1a, *CHECK_1 (\2a)), __ptrvalue (\2a)/g' \
314 -e 's/<\(B[1-9]\)>, <\(n[1-9]\)>/CHECK_N_NULL_OK (\1a, \2a), \2a/g' \
315 -e 's/<\(B[1-9]\)>, <\(N[1-9]\)>/CHECK_N_NULL_OK (\1a, *CHECK_1 (\2a)), __ptrvalue (\2a)/g' \
316 -e 's/<\(f[1-9]\)>/CHECK_N (\1a, 2)/g' \
317 -e 's/<\(i[1-9]\)>, <\(F[1-9]\)>/\1a, CHECK_FCNTL (\2a, \1a)/g' \
318 -e 's/<\(i[1-9]\)>, <\(I[1-9]\)>/\1a, CHECK_IOCTL (\2a, \1a)/g' \
319 -e 's/<\(p[1-9]\)>/CHECK_1 (\1a)/g' \
320 -e 's/<\([PW][1-9]\)>/CHECK_1_NULL_OK (\1a)/g' \
321 -e 's/<\(s[1-9]\)>/CHECK_STRING (\1a)/g' \
322 -e 's/<\(S[1-9]\)>/CHECK_STRING_NULL_OK (\1a)/g' \
323 -e 's/<\([ivn][1-9]\)>/\1a/g'`)`echo $rtn $args |
324 sed -e 's/<b0>.*<\(n[1-9]\)>.*/, \1a)/' \
325 -e 's/<.0>.*//'`; \\'; \\"
327 echo " echo '} \\'; \\"
329 echo " echo 'libc_hidden_def (BP_SYM ($strong)) \\'; \\"
331 # generate thunk aliases
332 for name in $nv_weak; do
333 echo " echo 'weak_alias (BP_SYM ($strong), BP_SYM ($name)) \\'; \\"
334 echo " echo 'libc_hidden_weak (BP_SYM ($name)) \\'; \\"
335 done
337 # wrap up
338 echo "\
339 echo ''; \\
340 echo '#include <bp-thunks.h>'; \\
341 ) | \$(COMPILE.c) -x c -o \$@ -"
342 ### Use this for debugging intermediate output:
343 ### ) >\$(@:.ob=.c)
344 ### \$(subst -c,-E,\$(COMPILE.c)) -o \$(@:.ob=.ib) \$(@:.ob=.c)
345 ### \$(COMPILE.c) -x cpp-output -o \$@ \$(@:.ob=.ib)"
346 echo endif
348 esac
350 done