perf tools: Don't clone maps from parent when synthesizing forks
[linux/fpc-iii.git] / arch / s390 / kernel / syscalls / syscalltbl
blobfbac1732f874e8d117b9c4aaf0a66b203370b933
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
4 # Generate system call table and header files
6 # Copyright IBM Corp. 2018
7 # Author(s): Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
10 # File path to the system call table definition.
11 # You can set the path with the -i option. If omitted,
12 # system call table definitions are read from standard input.
14 SYSCALL_TBL=""
17 create_syscall_table_entries()
19 local nr abi name entry64 entry32 _ignore
20 local temp=$(mktemp ${TMPDIR:-/tmp}/syscalltbl-common.XXXXXXXXX)
24 # Initialize with 0 to create an NI_SYSCALL for 0
26 local prev_nr=0 prev_32=sys_ni_syscall prev_64=sys_ni_syscall
27 while read nr abi name entry64 entry32 _ignore; do
28 test x$entry32 = x- && entry32=sys_ni_syscall
29 test x$entry64 = x- && entry64=sys_ni_syscall
31 if test $prev_nr -eq $nr; then
33 # Same syscall but different ABI, just update
34 # the respective entry point
36 case $abi in
37 32)
38 prev_32=$entry32
40 64)
41 prev_64=$entry64
43 esac
44 continue;
45 else
46 printf "%d\t%s\t%s\n" $prev_nr $prev_64 $prev_32
49 prev_nr=$nr
50 prev_64=$entry64
51 prev_32=$entry32
52 done
53 printf "%d\t%s\t%s\n" $prev_nr $prev_64 $prev_32
54 ) >> $temp
57 # Check for duplicate syscall numbers
59 if ! cat $temp |cut -f1 |uniq -d 2>&1; then
60 echo "Error: generated system call table contains duplicate entries: $temp" >&2
61 exit 1
65 # Generate syscall table
67 prev_nr=0
68 while read nr entry64 entry32; do
69 while test $prev_nr -lt $((nr - 1)); do
70 printf "NI_SYSCALL\n"
71 prev_nr=$((prev_nr + 1))
72 done
73 if test x$entry64 = xsys_ni_syscall &&
74 test x$entry32 = xsys_ni_syscall; then
75 printf "NI_SYSCALL\n"
76 else
77 printf "SYSCALL(%s,%s)\n" $entry64 $entry32
79 prev_nr=$nr
80 done < $temp
81 rm $temp
84 generate_syscall_table()
86 cat <<-EoHEADER
87 /* SPDX-License-Identifier: GPL-2.0 */
89 * Definitions for sys_call_table, each line represents an
90 * entry in the table in the form
91 * SYSCALL(64 bit syscall, 31 bit emulated syscall)
93 * This file is meant to be included from entry.S.
96 #define NI_SYSCALL SYSCALL(sys_ni_syscall,sys_ni_syscall)
98 EoHEADER
99 grep -Ev '^(#|[[:blank:]]*$)' $SYSCALL_TBL \
100 |sort -k1 -n \
101 |create_syscall_table_entries
104 create_header_defines()
106 local nr abi name _ignore
108 while read nr abi name _ignore; do
109 printf "#define __NR_%s %d\n" $name $nr
110 done
113 normalize_fileguard()
115 local fileguard="$1"
117 echo "$1" |tr '[[:lower:]]' '[[:upper:]]' \
118 |sed -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g'
121 generate_syscall_header()
123 local abis=$(echo "($1)" | tr ',' '|')
124 local filename="$2"
125 local fileguard suffix
127 if test "$filename"; then
128 fileguard=$(normalize_fileguard "__UAPI_ASM_S390_$2")
129 else
130 case "$abis" in
131 *64*) suffix=64 ;;
132 *32*) suffix=32 ;;
133 esac
134 fileguard=$(normalize_fileguard "__UAPI_ASM_S390_SYSCALLS_$suffix")
137 cat <<-EoHEADER
138 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
139 #ifndef ${fileguard}
140 #define ${fileguard}
142 EoHEADER
144 grep -E "^[[:digit:]]+[[:space:]]+${abis}" $SYSCALL_TBL \
145 |sort -k1 -n \
146 |create_header_defines
148 cat <<-EoFOOTER
150 #endif /* ${fileguard} */
151 EoFOOTER
154 __max_syscall_nr()
156 local abis=$(echo "($1)" | tr ',' '|')
158 grep -E "^[[:digit:]]+[[:space:]]+${abis}" $SYSCALL_TBL \
159 |sed -ne 's/^\([[:digit:]]*\)[[:space:]].*/\1/p' \
160 |sort -n \
161 |tail -1
165 generate_syscall_nr()
167 local abis="$1"
168 local max_syscall_nr num_syscalls
170 max_syscall_nr=$(__max_syscall_nr "$abis")
171 num_syscalls=$((max_syscall_nr + 1))
173 cat <<-EoHEADER
174 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
175 #ifndef __ASM_S390_SYSCALLS_NR
176 #define __ASM_S390_SYSCALLS_NR
178 #define NR_syscalls ${num_syscalls}
180 #endif /* __ASM_S390_SYSCALLS_NR */
181 EoHEADER
186 # Parse command line arguments
188 do_syscall_header=""
189 do_syscall_table=""
190 do_syscall_nr=""
191 output_file=""
192 abi_list="common,64"
193 filename=""
194 while getopts ":HNSXi:a:f:" arg; do
195 case $arg in
197 abi_list="$OPTARG"
200 SYSCALL_TBL="$OPTARG"
203 filename=${OPTARG##*/}
206 do_syscall_header=1
209 do_syscall_nr=1
212 do_syscall_table=1
215 set -x
218 echo "Missing argument for -$OPTARG" >&2
219 exit 1
222 echo "Invalid option specified" >&2
223 exit 1
225 esac
226 done
228 test "$do_syscall_header" && generate_syscall_header "$abi_list" "$filename"
229 test "$do_syscall_table" && generate_syscall_table
230 test "$do_syscall_nr" && generate_syscall_nr "$abi_list"
232 exit 0