gensyscalls.sh 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  1. #!/bin/sh
  2. #
  3. # Update syscall_nr.h files from linux headers asm-generic/unistd.h
  4. #
  5. # This code is licensed under the GPL version 2 or later. See
  6. # the COPYING file in the top-level directory.
  7. #
  8. linux="$1"
  9. output="$2"
  10. TMP=$(mktemp -d)
  11. if [ "$linux" = "" ] ; then
  12. echo "Needs path to linux source tree" 1>&2
  13. exit 1
  14. fi
  15. if [ "$output" = "" ] ; then
  16. output="$PWD"
  17. fi
  18. upper()
  19. {
  20. echo "$1" | tr "[:lower:]" "[:upper:]" | tr "[:punct:]" "_"
  21. }
  22. qemu_arch()
  23. {
  24. case "$1" in
  25. arm64)
  26. echo "aarch64"
  27. ;;
  28. *)
  29. echo "$1"
  30. ;;
  31. esac
  32. }
  33. read_includes()
  34. {
  35. arch=$1
  36. bits=$2
  37. cpp -P -nostdinc -fdirectives-only \
  38. -D_UAPI_ASM_$(upper ${arch})_BITSPERLONG_H \
  39. -D__BITS_PER_LONG=${bits} \
  40. -I${linux}/arch/${arch}/include/uapi/ \
  41. -I${linux}/include/uapi \
  42. -I${TMP} \
  43. "${linux}/arch/${arch}/include/uapi/asm/unistd.h"
  44. }
  45. filter_defines()
  46. {
  47. grep -e "#define __NR_" -e "#define __NR3264"
  48. }
  49. rename_defines()
  50. {
  51. sed "s/ __NR_/ TARGET_NR_/g;s/(__NR_/(TARGET_NR_/g"
  52. }
  53. evaluate_values()
  54. {
  55. sed "s/#define TARGET_NR_/QEMU TARGET_NR_/" | \
  56. cpp -P -nostdinc | \
  57. sed "s/^QEMU /#define /"
  58. }
  59. generate_syscall_nr()
  60. {
  61. arch=$1
  62. bits=$2
  63. file="$3"
  64. guard="$(upper LINUX_USER_$(qemu_arch $arch)_$(basename "$file"))"
  65. (echo "/*"
  66. echo " * This file contains the system call numbers."
  67. echo " * Do not modify."
  68. echo " * This file is generated by scripts/gensyscalls.sh"
  69. echo " */"
  70. echo "#ifndef ${guard}"
  71. echo "#define ${guard}"
  72. echo
  73. read_includes $arch $bits | filter_defines | rename_defines | \
  74. evaluate_values | sort -n -k 3
  75. echo
  76. echo "#endif /* ${guard} */"
  77. echo) > "$file"
  78. }
  79. mkdir "$TMP/asm"
  80. > "$TMP/asm/bitsperlong.h"
  81. generate_syscall_nr arm64 64 "$output/linux-user/aarch64/syscall_nr.h"
  82. generate_syscall_nr nios2 32 "$output/linux-user/nios2/syscall_nr.h"
  83. generate_syscall_nr openrisc 32 "$output/linux-user/openrisc/syscall_nr.h"
  84. generate_syscall_nr riscv 32 "$output/linux-user/riscv/syscall32_nr.h"
  85. generate_syscall_nr riscv 64 "$output/linux-user/riscv/syscall64_nr.h"
  86. rm -fr "$TMP"