syscallnr.sh 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. #
  4. # Generate a syscall number header.
  5. #
  6. # Each line of the syscall table should have the following format:
  7. #
  8. # NR ABI NAME [NATIVE] [COMPAT]
  9. #
  10. # NR syscall number
  11. # ABI ABI name
  12. # NAME syscall name
  13. # NATIVE native entry point (optional)
  14. # COMPAT compat entry point (optional)
  15. set -e
  16. usage() {
  17. echo >&2 "usage: $0 [--abis ABIS] [--prefix PREFIX] INFILE OUTFILE" >&2
  18. echo >&2
  19. echo >&2 " INFILE input syscall table"
  20. echo >&2 " OUTFILE output header file"
  21. echo >&2
  22. echo >&2 "options:"
  23. echo >&2 " --abis ABIS ABI(s) to handle (By default, all lines are handled)"
  24. echo >&2 " --prefix PREFIX The prefix to the macro like __NR_<PREFIX><NAME>"
  25. exit 1
  26. }
  27. # default unless specified by options
  28. abis=
  29. prefix=
  30. while [ $# -gt 0 ]
  31. do
  32. case $1 in
  33. --abis)
  34. abis=$(echo "($2)" | tr ',' '|')
  35. shift 2;;
  36. --prefix)
  37. prefix=$2
  38. shift 2;;
  39. -*)
  40. echo "$1: unknown option" >&2
  41. usage;;
  42. *)
  43. break;;
  44. esac
  45. done
  46. if [ $# -ne 2 ]; then
  47. usage
  48. fi
  49. infile="$1"
  50. outfile="$2"
  51. guard=_ASM_$(basename "$outfile" |
  52. sed -e 'y/abcdefghijklmnopqrstuvwxyz/ABCDEFGHIJKLMNOPQRSTUVWXYZ/' \
  53. -e 's/[^A-Z0-9_]/_/g' -e 's/__/_/g')
  54. grep -E "^[0-9A-Fa-fXx]+[[:space:]]+$abis" "$infile" | sort -n | {
  55. echo "#ifndef $guard"
  56. echo "#define $guard"
  57. echo
  58. max=0
  59. while read nr abi name native compat ; do
  60. max=$nr
  61. done
  62. echo "#define __NR_${prefix}syscalls $(($max + 1))"
  63. echo
  64. echo "#endif /* $guard */"
  65. } > "$outfile"