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 
0016 set -e
0017 
0018 usage() {
0019         echo >&2 "usage: $0 [--abis ABIS] [--emit-nr] [--offset OFFSET] [--prefix PREFIX] INFILE OUTFILE" >&2
0020         echo >&2
0021         echo >&2 "  INFILE    input syscall table"
0022         echo >&2 "  OUTFILE   output header file"
0023         echo >&2
0024         echo >&2 "options:"
0025         echo >&2 "  --abis ABIS        ABI(s) to handle (By default, all lines are handled)"
0026         echo >&2 "  --emit-nr          Emit the macro of the number of syscalls (__NR_syscalls)"
0027         echo >&2 "  --offset OFFSET    The offset of syscall numbers"
0028         echo >&2 "  --prefix PREFIX    The prefix to the macro like __NR_<PREFIX><NAME>"
0029         exit 1
0030 }
0031 
0032 # default unless specified by options
0033 abis=
0034 emit_nr=
0035 offset=
0036 prefix=
0037 
0038 while [ $# -gt 0 ]
0039 do
0040         case $1 in
0041         --abis)
0042                 abis=$(echo "($2)" | tr ',' '|')
0043                 shift 2;;
0044         --emit-nr)
0045                 emit_nr=1
0046                 shift 1;;
0047         --offset)
0048                 offset=$2
0049                 shift 2;;
0050         --prefix)
0051                 prefix=$2
0052                 shift 2;;
0053         -*)
0054                 echo "$1: unknown option" >&2
0055                 usage;;
0056         *)
0057                 break;;
0058         esac
0059 done
0060 
0061 if [ $# -ne 2 ]; then
0062         usage
0063 fi
0064 
0065 infile="$1"
0066 outfile="$2"
0067 
0068 guard=_UAPI_ASM_$(basename "$outfile" |
0069         sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
0070         -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g')
0071 
0072 grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | {
0073         echo "#ifndef $guard"
0074         echo "#define $guard"
0075         echo
0076 
0077         max=0
0078         while read nr abi name native compat ; do
0079 
0080                 max=$nr
0081 
0082                 if [ -n "$offset" ]; then
0083                         nr="($offset + $nr)"
0084                 fi
0085 
0086                 echo "#define __NR_$prefix$name $nr"
0087         done
0088 
0089         if [ -n "$emit_nr" ]; then
0090                 echo
0091                 echo "#ifdef __KERNEL__"
0092                 echo "#define __NR_${prefix}syscalls $(($max + 1))"
0093                 echo "#endif"
0094         fi
0095 
0096         echo
0097         echo "#endif /* $guard */"
0098 } > "$outfile"