scripts: add generic syscalltbl.sh
Most of architectures generate syscall headers at the compile time
in a similar way.
The syscall table has the same format for all architectures. Each line
has up to 5 fields; syscall number, ABI, syscall name, native entry
point, and compat entry point. The syscall table is processed by
syscalltbl.sh script into header files.
Despite the same pattern, scripts are maintained per architecture,
which results in code duplication and bad maintainability.
As of v5.11-rc1, 12 architectures duplicate similar shell scripts:
$ find arch -name syscalltbl.sh | sort
arch/alpha/kernel/syscalls/syscalltbl.sh
arch/arm/tools/syscalltbl.sh
arch/ia64/kernel/syscalls/syscalltbl.sh
arch/m68k/kernel/syscalls/syscalltbl.sh
arch/microblaze/kernel/syscalls/syscalltbl.sh
arch/mips/kernel/syscalls/syscalltbl.sh
arch/parisc/kernel/syscalls/syscalltbl.sh
arch/powerpc/kernel/syscalls/syscalltbl.sh
arch/sh/kernel/syscalls/syscalltbl.sh
arch/sparc/kernel/syscalls/syscalltbl.sh
arch/x86/entry/syscalls/syscalltbl.sh
arch/xtensa/kernel/syscalls/syscalltbl.sh
My goal is to unify them into scripts/syscalltbl.sh.
__SYSCALL_WITH_COMPAT should be defined as follows:
32-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
64-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-02-16 05:04:11 +03:00
#!/bin/sh
# SPDX-License-Identifier: GPL-2.0-only
#
# Generate a syscall table header.
#
# Each line of the syscall table should have the following format:
#
# NR ABI NAME [NATIVE] [COMPAT]
#
# NR syscall number
# ABI ABI name
# NAME syscall name
# NATIVE native entry point (optional)
# COMPAT compat entry point (optional)
set -e
usage( ) {
echo >& 2 " usage: $0 [--abis ABIS] INFILE OUTFILE " >& 2
echo >& 2
echo >& 2 " INFILE input syscall table"
echo >& 2 " OUTFILE output header file"
echo >& 2
echo >& 2 "options:"
echo >& 2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
exit 1
}
# default unless specified by options
abis =
while [ $# -gt 0 ]
do
case $1 in
--abis)
abis = $( echo " ( $2 ) " | tr ',' '|' )
shift 2; ;
-*)
echo " $1 : unknown option " >& 2
usage; ;
*)
break; ;
esac
done
if [ $# -ne 2 ] ; then
usage
fi
infile = " $1 "
outfile = " $2 "
nxt = 0
2021-07-05 09:06:54 +03:00
grep -E " ^[0-9]+[[:space:]]+ $abis " " $infile " | {
scripts: add generic syscalltbl.sh
Most of architectures generate syscall headers at the compile time
in a similar way.
The syscall table has the same format for all architectures. Each line
has up to 5 fields; syscall number, ABI, syscall name, native entry
point, and compat entry point. The syscall table is processed by
syscalltbl.sh script into header files.
Despite the same pattern, scripts are maintained per architecture,
which results in code duplication and bad maintainability.
As of v5.11-rc1, 12 architectures duplicate similar shell scripts:
$ find arch -name syscalltbl.sh | sort
arch/alpha/kernel/syscalls/syscalltbl.sh
arch/arm/tools/syscalltbl.sh
arch/ia64/kernel/syscalls/syscalltbl.sh
arch/m68k/kernel/syscalls/syscalltbl.sh
arch/microblaze/kernel/syscalls/syscalltbl.sh
arch/mips/kernel/syscalls/syscalltbl.sh
arch/parisc/kernel/syscalls/syscalltbl.sh
arch/powerpc/kernel/syscalls/syscalltbl.sh
arch/sh/kernel/syscalls/syscalltbl.sh
arch/sparc/kernel/syscalls/syscalltbl.sh
arch/x86/entry/syscalls/syscalltbl.sh
arch/xtensa/kernel/syscalls/syscalltbl.sh
My goal is to unify them into scripts/syscalltbl.sh.
__SYSCALL_WITH_COMPAT should be defined as follows:
32-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
64-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-02-16 05:04:11 +03:00
while read nr abi name native compat ; do
2021-07-05 09:06:54 +03:00
if [ $nxt -gt $nr ] ; then
echo " error: $infile : syscall table is not sorted or duplicates the same syscall number " >& 2
exit 1
fi
scripts: add generic syscalltbl.sh
Most of architectures generate syscall headers at the compile time
in a similar way.
The syscall table has the same format for all architectures. Each line
has up to 5 fields; syscall number, ABI, syscall name, native entry
point, and compat entry point. The syscall table is processed by
syscalltbl.sh script into header files.
Despite the same pattern, scripts are maintained per architecture,
which results in code duplication and bad maintainability.
As of v5.11-rc1, 12 architectures duplicate similar shell scripts:
$ find arch -name syscalltbl.sh | sort
arch/alpha/kernel/syscalls/syscalltbl.sh
arch/arm/tools/syscalltbl.sh
arch/ia64/kernel/syscalls/syscalltbl.sh
arch/m68k/kernel/syscalls/syscalltbl.sh
arch/microblaze/kernel/syscalls/syscalltbl.sh
arch/mips/kernel/syscalls/syscalltbl.sh
arch/parisc/kernel/syscalls/syscalltbl.sh
arch/powerpc/kernel/syscalls/syscalltbl.sh
arch/sh/kernel/syscalls/syscalltbl.sh
arch/sparc/kernel/syscalls/syscalltbl.sh
arch/x86/entry/syscalls/syscalltbl.sh
arch/xtensa/kernel/syscalls/syscalltbl.sh
My goal is to unify them into scripts/syscalltbl.sh.
__SYSCALL_WITH_COMPAT should be defined as follows:
32-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, native)
64-bit kernel:
#define __SYSCALL_WITH_COMPAT(nr, native, compat) __SYSCALL(nr, compat)
Signed-off-by: Masahiro Yamada <masahiroy@kernel.org>
2021-02-16 05:04:11 +03:00
while [ $nxt -lt $nr ] ; do
echo " __SYSCALL( $nxt , sys_ni_syscall) "
nxt = $(( nxt + 1 ))
done
if [ -n " $compat " ] ; then
echo " __SYSCALL_WITH_COMPAT( $nr , $native , $compat ) "
elif [ -n " $native " ] ; then
echo " __SYSCALL( $nr , $native ) "
else
echo " __SYSCALL( $nr , sys_ni_syscall) "
fi
nxt = $(( nr + 1 ))
done
} > " $outfile "