xref: /linux/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl (revision 71e2f4dd5a65bd8dbca0b77661e75eea471168f8)
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	create_table_exe=`mktemp ${TMPDIR:-/tmp}/create-table-XXXXXX`
27
28	{
29
30	cat <<-_EoHEADER
31		#include <stdio.h>
32		#include "$input"
33		int main(int argc, char *argv[])
34		{
35	_EoHEADER
36
37	while read sc nr; do
38		printf "%s\n" "	printf(\"\\t[%d] = \\\"$sc\\\",\\n\", __NR_$sc);"
39		last_sc=$sc
40	done
41
42	printf "%s\n" "	printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);"
43	printf "}\n"
44
45	} | $hostcc -I $incpath/include/uapi -o $create_table_exe -x c -
46
47	$create_table_exe
48
49	rm -f $create_table_exe
50}
51
52create_table()
53{
54	echo "static const char *syscalltbl_arm64[] = {"
55	create_table_from_c
56	echo "};"
57}
58
59$gcc -E -dM -x c -I $incpath/include/uapi $input \
60	|sed -ne 's/^#define __NR_//p' \
61	|sort -t' ' -k2 -nu	       \
62	|create_table
63