Back to home page

OSCL-LXR

 
 

    


0001 #!/bin/sh
0002 # SPDX-License-Identifier: GPL-2.0-only
0003 #
0004 # Generate a syscall table 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] 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         exit 1
0027 }
0028 
0029 # default unless specified by options
0030 abis=
0031 
0032 while [ $# -gt 0 ]
0033 do
0034         case $1 in
0035         --abis)
0036                 abis=$(echo "($2)" | tr ',' '|')
0037                 shift 2;;
0038         -*)
0039                 echo "$1: unknown option" >&2
0040                 usage;;
0041         *)
0042                 break;;
0043         esac
0044 done
0045 
0046 if [ $# -ne 2 ]; then
0047         usage
0048 fi
0049 
0050 infile="$1"
0051 outfile="$2"
0052 
0053 nxt=0
0054 
0055 grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | {
0056 
0057         while read nr abi name native compat ; do
0058 
0059                 if [ $nxt -gt $nr ]; then
0060                         echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2
0061                         exit 1
0062                 fi
0063 
0064                 while [ $nxt -lt $nr ]; do
0065                         echo "__SYSCALL($nxt, sys_ni_syscall)"
0066                         nxt=$((nxt + 1))
0067                 done
0068 
0069                 if [ -n "$compat" ]; then
0070                         echo "__SYSCALL_WITH_COMPAT($nr, $native, $compat)"
0071                 elif [ -n "$native" ]; then
0072                         echo "__SYSCALL($nr, $native)"
0073                 else
0074                         echo "__SYSCALL($nr, sys_ni_syscall)"
0075                 fi
0076                 nxt=$((nr + 1))
0077         done
0078 } > "$outfile"