GNU Linux-libre 4.14.324-gnu1
[releases.git] / arch / x86 / entry / syscalls / syscalltbl.sh
1 #!/bin/sh
2 # SPDX-License-Identifier: GPL-2.0
3
4 in="$1"
5 out="$2"
6
7 syscall_macro() {
8     abi="$1"
9     nr="$2"
10     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     abi="$1"
25     nr="$2"
26     entry="$3"
27     compat="$4"
28
29     if [ "$abi" = "64" -a -n "$compat" ]; then
30         echo "a compat entry for a 64-bit syscall makes no sense" >&2
31         exit 1
32     fi
33
34     if [ -z "$compat" ]; then
35         if [ -n "$entry" ]; then
36             syscall_macro "$abi" "$nr" "$entry"
37         fi
38     else
39         echo "#ifdef CONFIG_X86_32"
40         if [ -n "$entry" ]; then
41             syscall_macro "$abi" "$nr" "$entry"
42         fi
43         echo "#else"
44         syscall_macro "$abi" "$nr" "$compat"
45         echo "#endif"
46     fi
47 }
48
49 grep '^[0-9]' "$in" | sort -n | (
50     while read nr abi name entry compat; do
51         abi=`echo "$abi" | tr '[a-z]' '[A-Z]'`
52         if [ "$abi" = "COMMON" -o "$abi" = "64" ]; then
53             # COMMON is the same as 64, except that we don't expect X32
54             # programs to use it.  Our expectation has nothing to do with
55             # any generated code, so treat them the same.
56             emit 64 "$nr" "$entry" "$compat"
57         elif [ "$abi" = "X32" ]; then
58             # X32 is equivalent to 64 on an X32-compatible kernel.
59             echo "#ifdef CONFIG_X86_X32_ABI"
60             emit 64 "$nr" "$entry" "$compat"
61             echo "#endif"
62         elif [ "$abi" = "I386" ]; then
63             emit "$abi" "$nr" "$entry" "$compat"
64         else
65             echo "Unknown abi $abi" >&2
66             exit 1
67         fi
68     done
69 ) > "$out"