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 (C) 2020 Loongson Technology Co., Ltd. 8# Author(s): Ming Wang <wangming01@loongson.cn> 9 10gcc=$1 11hostcc=$2 12incpath=$3 13input=$4 14 15if ! test -r $input; then 16 echo "Could not read input file" >&2 17 exit 1 18fi 19 20create_table_from_c() 21{ 22 local sc nr last_sc 23 24 create_table_exe=`mktemp ${TMPDIR:-/tmp}/create-table-XXXXXX` 25 26 { 27 28 cat <<-_EoHEADER 29 #include <stdio.h> 30 #include "$input" 31 int main(int argc, char *argv[]) 32 { 33 _EoHEADER 34 35 while read sc nr; do 36 printf "%s\n" " printf(\"\\t[%d] = \\\"$sc\\\",\\n\", $nr);" 37 last_sc=$nr 38 done 39 40 printf "%s\n" " printf(\"#define SYSCALLTBL_LOONGARCH_MAX_ID %d\\n\", $last_sc);" 41 printf "}\n" 42 43 } | $hostcc -I $incpath/include/uapi -o $create_table_exe -x c - 44 45 $create_table_exe 46 47 rm -f $create_table_exe 48} 49 50create_table() 51{ 52 echo "static const char *syscalltbl_loongarch[] = {" 53 create_table_from_c 54 echo "};" 55} 56 57$gcc -E -dM -x c -I $incpath/include/uapi $input \ 58 |sed -ne 's/^#define __NR_//p' \ 59 |sort -t' ' -k2 -n \ 60 |create_table 61