1#!/bin/sh
2# SPDX-License-Identifier: GPL-2.0
3#
4# Generate system call table for perf. Derived from
5# powerpc script.
6#
7# Copyright IBM Corp. 2017
8# Author(s):  Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
9# Changed by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
10# Changed by: Kim Phillips <kim.phillips@arm.com>
11
12gcc=$1
13hostcc=$2
14incpath=$3
15input=$4
16
17if ! test -r $input; then
18	echo "Could not read input file" >&2
19	exit 1
20fi
21
22create_table_from_c()
23{
24	local sc nr last_sc
25
26	while read sc nr; do
27		printf "%s\n" "	[$nr] = \"$sc\","
28		last_sc=$sc
29	done
30
31	printf "%s\n" "#define SYSCALLTBL_ARM64_MAX_ID __NR_$last_sc"
32}
33
34create_table()
35{
36	echo "#include \"$input\""
37	echo "static const char *syscalltbl_arm64[] = {"
38	create_table_from_c
39	echo "};"
40}
41
42$gcc -E -dM -x c -I $incpath/include/uapi $input \
43	|sed -ne 's/^#define __NR_//p' \
44	|sort -t' ' -k2 -n	       \
45	|create_table
46