xref: /linux/tools/perf/arch/arm64/entry/syscalls/mksyscalltbl (revision 2b5882435606c209ebc052230f03505ea477a252)
1*2b588243SKim Phillips#!/bin/sh
2*2b588243SKim Phillips# SPDX-License-Identifier: GPL-2.0
3*2b588243SKim Phillips#
4*2b588243SKim Phillips# Generate system call table for perf. Derived from
5*2b588243SKim Phillips# powerpc script.
6*2b588243SKim Phillips#
7*2b588243SKim Phillips# Copyright IBM Corp. 2017
8*2b588243SKim Phillips# Author(s):  Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
9*2b588243SKim Phillips# Changed by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
10*2b588243SKim Phillips# Changed by: Kim Phillips <kim.phillips@arm.com>
11*2b588243SKim Phillips
12*2b588243SKim Phillipsgcc=$1
13*2b588243SKim Phillipshostcc=$2
14*2b588243SKim Phillipsinput=$3
15*2b588243SKim Phillips
16*2b588243SKim Phillipsif ! test -r $input; then
17*2b588243SKim Phillips	echo "Could not read input file" >&2
18*2b588243SKim Phillips	exit 1
19*2b588243SKim Phillipsfi
20*2b588243SKim Phillips
21*2b588243SKim Phillipscreate_table_from_c()
22*2b588243SKim Phillips{
23*2b588243SKim Phillips	local sc nr last_sc
24*2b588243SKim Phillips
25*2b588243SKim Phillips	create_table_exe=`mktemp /tmp/create-table-XXXXXX`
26*2b588243SKim Phillips
27*2b588243SKim Phillips	{
28*2b588243SKim Phillips
29*2b588243SKim Phillips	cat <<-_EoHEADER
30*2b588243SKim Phillips		#include <stdio.h>
31*2b588243SKim Phillips		#define __ARCH_WANT_RENAMEAT
32*2b588243SKim Phillips		#include "$input"
33*2b588243SKim Phillips		int main(int argc, char *argv[])
34*2b588243SKim Phillips		{
35*2b588243SKim Phillips	_EoHEADER
36*2b588243SKim Phillips
37*2b588243SKim Phillips	while read sc nr; do
38*2b588243SKim Phillips		printf "%s\n" "	printf(\"\\t[%d] = \\\"$sc\\\",\\n\", __NR_$sc);"
39*2b588243SKim Phillips		last_sc=$sc
40*2b588243SKim Phillips	done
41*2b588243SKim Phillips
42*2b588243SKim Phillips	printf "%s\n" "	printf(\"#define SYSCALLTBL_ARM64_MAX_ID %d\\n\", __NR_$last_sc);"
43*2b588243SKim Phillips	printf "}\n"
44*2b588243SKim Phillips
45*2b588243SKim Phillips	} | $hostcc -o $create_table_exe -x c -
46*2b588243SKim Phillips
47*2b588243SKim Phillips	$create_table_exe
48*2b588243SKim Phillips
49*2b588243SKim Phillips	rm -f $create_table_exe
50*2b588243SKim Phillips}
51*2b588243SKim Phillips
52*2b588243SKim Phillipscreate_table()
53*2b588243SKim Phillips{
54*2b588243SKim Phillips	echo "static const char *syscalltbl_arm64[] = {"
55*2b588243SKim Phillips	create_table_from_c
56*2b588243SKim Phillips	echo "};"
57*2b588243SKim Phillips}
58*2b588243SKim Phillips
59*2b588243SKim Phillips$gcc -E -dM -x c  $input	       \
60*2b588243SKim Phillips	|sed -ne 's/^#define __NR_//p' \
61*2b588243SKim Phillips	|sort -t' ' -k2 -nu	       \
62*2b588243SKim Phillips	|create_table
63