12fa5ebe3SHuacai Chen#!/bin/sh 22fa5ebe3SHuacai Chen# SPDX-License-Identifier: GPL-2.0 32fa5ebe3SHuacai Chen# 42fa5ebe3SHuacai Chen# Generate system call table for perf. Derived from 52fa5ebe3SHuacai Chen# powerpc script. 62fa5ebe3SHuacai Chen# 72fa5ebe3SHuacai Chen# Author(s): Ming Wang <wangming01@loongson.cn> 82fa5ebe3SHuacai Chen# Author(s): Huacai Chen <chenhuacai@loongson.cn> 92fa5ebe3SHuacai Chen# Copyright (C) 2020-2023 Loongson Technology Corporation Limited 102fa5ebe3SHuacai Chen 112fa5ebe3SHuacai Chengcc=$1 122fa5ebe3SHuacai Chenhostcc=$2 132fa5ebe3SHuacai Chenincpath=$3 142fa5ebe3SHuacai Cheninput=$4 152fa5ebe3SHuacai Chen 162fa5ebe3SHuacai Chenif ! test -r $input; then 172fa5ebe3SHuacai Chen echo "Could not read input file" >&2 182fa5ebe3SHuacai Chen exit 1 192fa5ebe3SHuacai Chenfi 202fa5ebe3SHuacai Chen 21*269f49f9STiezhu Yangcreate_sc_table() 222fa5ebe3SHuacai Chen{ 23*269f49f9STiezhu Yang local sc nr max_nr 242fa5ebe3SHuacai Chen 252fa5ebe3SHuacai Chen while read sc nr; do 26*269f49f9STiezhu Yang printf "%s\n" " [$nr] = \"$sc\"," 27*269f49f9STiezhu Yang max_nr=$nr 282fa5ebe3SHuacai Chen done 292fa5ebe3SHuacai Chen 30*269f49f9STiezhu Yang echo "#define SYSCALLTBL_LOONGARCH_MAX_ID $max_nr" 312fa5ebe3SHuacai Chen} 322fa5ebe3SHuacai Chen 332fa5ebe3SHuacai Chencreate_table() 342fa5ebe3SHuacai Chen{ 35*269f49f9STiezhu Yang echo "#include \"$input\"" 3649f3806dSTiezhu Yang echo "static const char *const syscalltbl_loongarch[] = {" 37*269f49f9STiezhu Yang create_sc_table 382fa5ebe3SHuacai Chen echo "};" 392fa5ebe3SHuacai Chen} 402fa5ebe3SHuacai Chen 412fa5ebe3SHuacai Chen$gcc -E -dM -x c -I $incpath/include/uapi $input \ 42*269f49f9STiezhu Yang |awk '$2 ~ "__NR" && $3 !~ "__NR3264_" { 43*269f49f9STiezhu Yang sub("^#define __NR(3264)?_", ""); 44*269f49f9STiezhu Yang print | "sort -k2 -n"}' \ 452fa5ebe3SHuacai Chen |create_table 46