asm.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (C) 2015 Regents of the University of California
  4. */
  5. #ifndef _ASM_RISCV_ASM_H
  6. #define _ASM_RISCV_ASM_H
  7. #ifdef __ASSEMBLY__
  8. #define __ASM_STR(x) x
  9. #else
  10. #define __ASM_STR(x) #x
  11. #endif
  12. #if __riscv_xlen == 64
  13. #define __REG_SEL(a, b) __ASM_STR(a)
  14. #elif __riscv_xlen == 32
  15. #define __REG_SEL(a, b) __ASM_STR(b)
  16. #else
  17. #error "Unexpected __riscv_xlen"
  18. #endif
  19. #define REG_L __REG_SEL(ld, lw)
  20. #define REG_S __REG_SEL(sd, sw)
  21. #define REG_SC __REG_SEL(sc.d, sc.w)
  22. #define SZREG __REG_SEL(8, 4)
  23. #define LGREG __REG_SEL(3, 2)
  24. #if __SIZEOF_POINTER__ == 8
  25. #ifdef __ASSEMBLY__
  26. #define RISCV_PTR .dword
  27. #define RISCV_SZPTR 8
  28. #define RISCV_LGPTR 3
  29. #else
  30. #define RISCV_PTR ".dword"
  31. #define RISCV_SZPTR "8"
  32. #define RISCV_LGPTR "3"
  33. #endif
  34. #elif __SIZEOF_POINTER__ == 4
  35. #ifdef __ASSEMBLY__
  36. #define RISCV_PTR .word
  37. #define RISCV_SZPTR 4
  38. #define RISCV_LGPTR 2
  39. #else
  40. #define RISCV_PTR ".word"
  41. #define RISCV_SZPTR "4"
  42. #define RISCV_LGPTR "2"
  43. #endif
  44. #else
  45. #error "Unexpected __SIZEOF_POINTER__"
  46. #endif
  47. #if (__SIZEOF_INT__ == 4)
  48. #define RISCV_INT __ASM_STR(.word)
  49. #define RISCV_SZINT __ASM_STR(4)
  50. #define RISCV_LGINT __ASM_STR(2)
  51. #else
  52. #error "Unexpected __SIZEOF_INT__"
  53. #endif
  54. #if (__SIZEOF_SHORT__ == 2)
  55. #define RISCV_SHORT __ASM_STR(.half)
  56. #define RISCV_SZSHORT __ASM_STR(2)
  57. #define RISCV_LGSHORT __ASM_STR(1)
  58. #else
  59. #error "Unexpected __SIZEOF_SHORT__"
  60. #endif
  61. #endif /* _ASM_RISCV_ASM_H */