18e2ff72aSRavi Bangoria#!/bin/sh
28e2ff72aSRavi Bangoria# SPDX-License-Identifier: GPL-2.0
38e2ff72aSRavi Bangoria#
48e2ff72aSRavi Bangoria# Generate system call table for perf. Derived from
58e2ff72aSRavi Bangoria# s390 script.
68e2ff72aSRavi Bangoria#
78e2ff72aSRavi Bangoria# Copyright IBM Corp. 2017
88e2ff72aSRavi Bangoria# Author(s):  Hendrik Brueckner <brueckner@linux.vnet.ibm.com>
98e2ff72aSRavi Bangoria# Changed by: Ravi Bangoria <ravi.bangoria@linux.vnet.ibm.com>
108e2ff72aSRavi Bangoria
118e2ff72aSRavi Bangoriawordsize=$1
1202061318SRavi BangoriaSYSCALL_TBL=$2
138e2ff72aSRavi Bangoria
1402061318SRavi Bangoriaif ! test -r $SYSCALL_TBL; then
158e2ff72aSRavi Bangoria	echo "Could not read input file" >&2
168e2ff72aSRavi Bangoria	exit 1
178e2ff72aSRavi Bangoriafi
188e2ff72aSRavi Bangoria
198e2ff72aSRavi Bangoriacreate_table()
208e2ff72aSRavi Bangoria{
218e2ff72aSRavi Bangoria	local wordsize=$1
2202061318SRavi Bangoria	local max_nr nr abi sc discard
2302061318SRavi Bangoria	max_nr=-1
2402061318SRavi Bangoria	nr=0
258e2ff72aSRavi Bangoria
26*49f3806dSTiezhu Yang	echo "static const char *const syscalltbl_powerpc_${wordsize}[] = {"
2702061318SRavi Bangoria	while read nr abi sc discard; do
2802061318SRavi Bangoria		if [ "$max_nr" -lt "$nr" ]; then
298e2ff72aSRavi Bangoria			printf '\t[%d] = "%s",\n' $nr $sc
308e2ff72aSRavi Bangoria			max_nr=$nr
3102061318SRavi Bangoria		fi
328e2ff72aSRavi Bangoria	done
338e2ff72aSRavi Bangoria	echo '};'
348e2ff72aSRavi Bangoria	echo "#define SYSCALLTBL_POWERPC_${wordsize}_MAX_ID $max_nr"
358e2ff72aSRavi Bangoria}
368e2ff72aSRavi Bangoria
3702061318SRavi Bangoriagrep -E "^[[:digit:]]+[[:space:]]+(common|spu|nospu|${wordsize})" $SYSCALL_TBL \
3802061318SRavi Bangoria	|sort -k1 -n                                                           \
398e2ff72aSRavi Bangoria	|create_table ${wordsize}
40