syscalltbl.sh 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0-only
  3. #
  4. # Generate a syscall table 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] 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. exit 1
  25. }
  26. # default unless specified by options
  27. abis=
  28. while [ $# -gt 0 ]
  29. do
  30. case $1 in
  31. --abis)
  32. abis=$(echo "($2)" | tr ',' '|')
  33. shift 2;;
  34. -*)
  35. echo "$1: unknown option" >&2
  36. usage;;
  37. *)
  38. break;;
  39. esac
  40. done
  41. if [ $# -ne 2 ]; then
  42. usage
  43. fi
  44. infile="$1"
  45. outfile="$2"
  46. nxt=0
  47. grep -E "^[0-9]+[[:space:]]+$abis" "$infile" | {
  48. while read nr abi name native compat ; do
  49. if [ $nxt -gt $nr ]; then
  50. echo "error: $infile: syscall table is not sorted or duplicates the same syscall number" >&2
  51. exit 1
  52. fi
  53. while [ $nxt -lt $nr ]; do
  54. echo "__SYSCALL($nxt, sys_ni_syscall)"
  55. nxt=$((nxt + 1))
  56. done
  57. if [ -n "$compat" ]; then
  58. echo "__SYSCALL_WITH_COMPAT($nr, $native, $compat)"
  59. elif [ -n "$native" ]; then
  60. echo "__SYSCALL($nr, $native)"
  61. else
  62. echo "__SYSCALL($nr, sys_ni_syscall)"
  63. fi
  64. nxt=$((nr + 1))
  65. done
  66. } > "$outfile"