xref: /linux/tools/perf/arch/loongarch/entry/syscalls/mksyscalltbl (revision c532de5a67a70f8533d495f8f2aaa9a0491c3ad0)
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# Author(s):  Ming Wang <wangming01@loongson.cn>
8# Author(s):  Huacai Chen <chenhuacai@loongson.cn>
9# Copyright (C) 2020-2023 Loongson Technology Corporation Limited
10
11gcc=$1
12hostcc=$2
13incpath=$3
14input=$4
15
16if ! test -r $input; then
17	echo "Could not read input file" >&2
18	exit 1
19fi
20
21create_sc_table()
22{
23	local sc nr max_nr
24
25	while read sc nr; do
26		printf "%s\n" "	[$nr] = \"$sc\","
27		max_nr=$nr
28	done
29
30	echo "#define SYSCALLTBL_LOONGARCH_MAX_ID $max_nr"
31}
32
33create_table()
34{
35	echo "#include \"$input\""
36	echo "static const char *const syscalltbl_loongarch[] = {"
37	create_sc_table
38	echo "};"
39}
40
41$gcc -E -dM -x c -I $incpath/include/uapi $input \
42	|awk '$2 ~ "__NR" && $3 !~ "__NR3264_" {
43		sub("^#define __NR(3264)?_", "");
44		print | "sort -k2 -n"}' \
45	|create_table
46