syscalltbl.sh 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #!/bin/sh
  2. # SPDX-License-Identifier: GPL-2.0
  3. in="$1"
  4. out="$2"
  5. syscall_macro() {
  6. abi="$1"
  7. nr="$2"
  8. entry="$3"
  9. # Entry can be either just a function name or "function/qualifier"
  10. real_entry="${entry%%/*}"
  11. if [ "$entry" = "$real_entry" ]; then
  12. qualifier=
  13. else
  14. qualifier=${entry#*/}
  15. fi
  16. echo "__SYSCALL_${abi}($nr, $real_entry, $qualifier)"
  17. }
  18. emit() {
  19. abi="$1"
  20. nr="$2"
  21. entry="$3"
  22. compat="$4"
  23. umlentry=""
  24. if [ "$abi" = "64" -a -n "$compat" ]; then
  25. echo "a compat entry for a 64-bit syscall makes no sense" >&2
  26. exit 1
  27. fi
  28. # For CONFIG_UML, we need to strip the __x64_sys prefix
  29. if [ "$abi" = "64" -a "${entry}" != "${entry#__x64_sys}" ]; then
  30. umlentry="sys${entry#__x64_sys}"
  31. fi
  32. if [ -z "$compat" ]; then
  33. if [ -n "$entry" -a -z "$umlentry" ]; then
  34. syscall_macro "$abi" "$nr" "$entry"
  35. elif [ -n "$umlentry" ]; then # implies -n "$entry"
  36. echo "#ifdef CONFIG_X86"
  37. syscall_macro "$abi" "$nr" "$entry"
  38. echo "#else /* CONFIG_UML */"
  39. syscall_macro "$abi" "$nr" "$umlentry"
  40. echo "#endif"
  41. fi
  42. else
  43. echo "#ifdef CONFIG_X86_32"
  44. if [ -n "$entry" ]; then
  45. syscall_macro "$abi" "$nr" "$entry"
  46. fi
  47. echo "#else"
  48. syscall_macro "$abi" "$nr" "$compat"
  49. echo "#endif"
  50. fi
  51. }
  52. grep '^[0-9]' "$in" | sort -n | (
  53. while read nr abi name entry compat; do
  54. abi=`echo "$abi" | tr '[a-z]' '[A-Z]'`
  55. if [ "$abi" = "COMMON" -o "$abi" = "64" ]; then
  56. # COMMON is the same as 64, except that we don't expect X32
  57. # programs to use it. Our expectation has nothing to do with
  58. # any generated code, so treat them the same.
  59. emit 64 "$nr" "$entry" "$compat"
  60. elif [ "$abi" = "X32" ]; then
  61. # X32 is equivalent to 64 on an X32-compatible kernel.
  62. echo "#ifdef CONFIG_X86_X32_ABI"
  63. emit 64 "$nr" "$entry" "$compat"
  64. echo "#endif"
  65. elif [ "$abi" = "I386" ]; then
  66. emit "$abi" "$nr" "$entry" "$compat"
  67. else
  68. echo "Unknown abi $abi" >&2
  69. exit 1
  70. fi
  71. done
  72. ) > "$out"