x86/syscalls: Split the x32 syscalls into their own table
[sfrench/cifs-2.6.git] / arch / x86 / entry / syscalls / syscalltbl.sh
1 #!/bin/bash
2 # SPDX-License-Identifier: GPL-2.0
3
4 in="$1"
5 out="$2"
6
7 syscall_macro() {
8     local abi="$1"
9     local nr="$2"
10     local entry="$3"
11
12     # Entry can be either just a function name or "function/qualifier"
13     real_entry="${entry%%/*}"
14     if [ "$entry" = "$real_entry" ]; then
15         qualifier=
16     else
17         qualifier=${entry#*/}
18     fi
19
20     echo "__SYSCALL_${abi}($nr, $real_entry, $qualifier)"
21 }
22
23 emit() {
24     local abi="$1"
25     local nr="$2"
26     local entry="$3"
27     local compat="$4"
28     local umlentry=""
29
30     if [ "$abi" != "I386" -a -n "$compat" ]; then
31         echo "a compat entry ($abi: $compat) for a 64-bit syscall makes no sense" >&2
32         exit 1
33     fi
34
35     # For CONFIG_UML, we need to strip the __x64_sys prefix
36     if [ "$abi" = "64" -a "${entry}" != "${entry#__x64_sys}" ]; then
37             umlentry="sys${entry#__x64_sys}"
38     fi
39
40     if [ -z "$compat" ]; then
41         if [ -n "$entry" -a -z "$umlentry" ]; then
42             syscall_macro "$abi" "$nr" "$entry"
43         elif [ -n "$umlentry" ]; then # implies -n "$entry"
44             echo "#ifdef CONFIG_X86"
45             syscall_macro "$abi" "$nr" "$entry"
46             echo "#else /* CONFIG_UML */"
47             syscall_macro "$abi" "$nr" "$umlentry"
48             echo "#endif"
49         fi
50     else
51         echo "#ifdef CONFIG_X86_32"
52         if [ -n "$entry" ]; then
53             syscall_macro "$abi" "$nr" "$entry"
54         fi
55         echo "#else"
56         syscall_macro "$abi" "$nr" "$compat"
57         echo "#endif"
58     fi
59 }
60
61 grep '^[0-9]' "$in" | sort -n | (
62     while read nr abi name entry compat; do
63         abi=`echo "$abi" | tr '[a-z]' '[A-Z]'`
64         if [ "$abi" = "COMMON" -o "$abi" = "64" ]; then
65             emit 64 "$nr" "$entry" "$compat"
66             if [ "$abi" = "COMMON" ]; then
67                 # COMMON means that this syscall exists in the same form for
68                 # 64-bit and X32.
69                 echo "#ifdef CONFIG_X86_X32_ABI"
70                 emit X32 "$nr" "$entry" "$compat"
71                 echo "#endif"
72             fi
73         elif [ "$abi" = "X32" ]; then
74             echo "#ifdef CONFIG_X86_X32_ABI"
75             emit X32 "$nr" "$entry" "$compat"
76             echo "#endif"
77         elif [ "$abi" = "I386" ]; then
78             emit "$abi" "$nr" "$entry" "$compat"
79         else
80             echo "Unknown abi $abi" >&2
81             exit 1
82         fi
83     done
84 ) > "$out"