Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 #
0004 # Generate a syscall number header.
0005 #
0006 # Each line of the syscall table should have the following format:
0007 #
0008 # NR ABI NAME [NATIVE] [COMPAT]
0009 #
0010 # NR       syscall number
0011 # ABI      ABI name
0012 # NAME     syscall name
0013 # NATIVE   native entry point (optional)
0014 # COMPAT   compat entry point (optional)
0015 set -e
0016 
0017 usage() {
0018         echo >&2 "usage: $0 [--abis ABIS] [--prefix PREFIX] INFILE OUTFILE" >&2
0019         echo >&2
0020         echo >&2 "  INFILE    input syscall table"
0021         echo >&2 "  OUTFILE   output header file"
0022         echo >&2
0023         echo >&2 "options:"
0024         echo >&2 "  --abis ABIS        ABI(s) to handle (By default, all lines are handled)"
0025         echo >&2 "  --prefix PREFIX    The prefix to the macro like __NR_<PREFIX><NAME>"
0026         exit 1
0027 }
0028 
0029 # default unless specified by options
0030 abis=
0031 prefix=
0032 
0033 while [ $# -gt 0 ]
0034 do
0035         case $1 in
0036         --abis)
0037                 abis=$(echo "($2)" | tr ',' '|')
0038                 shift 2;;
0039         --prefix)
0040                 prefix=$2
0041                 shift 2;;
0042         -*)
0043                 echo "$1: unknown option" >&2
0044                 usage;;
0045         *)
0046                 break;;
0047         esac
0048 done
0049 
0050 if [ $# -ne 2 ]; then
0051         usage
0052 fi
0053 
0054 infile="$1"
0055 outfile="$2"
0056 
0057 guard=_ASM_$(basename "$outfile" |
0058         sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
0059         -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g')
0060 
0061 grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | sort -n | {
0062         echo "#ifndef $guard"
0063         echo "#define $guard"
0064         echo
0065 
0066         max=0
0067         while read nr abi name native compat ; do
0068                 max=$nr
0069         done
0070 
0071         echo "#define __NR_${prefix}syscalls $(($max + 1))"
0072         echo
0073         echo "#endif /* $guard */"
0074 } > "$outfile"