asm.h 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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 SZREG __REG_SEL(8, 4)
  22. #define LGREG __REG_SEL(3, 2)
  23. #if __SIZEOF_POINTER__ == 8
  24. #ifdef __ASSEMBLY__
  25. #define RISCV_PTR .dword
  26. #define RISCV_SZPTR 8
  27. #define RISCV_LGPTR 3
  28. #else
  29. #define RISCV_PTR ".dword"
  30. #define RISCV_SZPTR "8"
  31. #define RISCV_LGPTR "3"
  32. #endif
  33. #elif __SIZEOF_POINTER__ == 4
  34. #ifdef __ASSEMBLY__
  35. #define RISCV_PTR .word
  36. #define RISCV_SZPTR 4
  37. #define RISCV_LGPTR 2
  38. #else
  39. #define RISCV_PTR ".word"
  40. #define RISCV_SZPTR "4"
  41. #define RISCV_LGPTR "2"
  42. #endif
  43. #else
  44. #error "Unexpected __SIZEOF_POINTER__"
  45. #endif
  46. #if (__SIZEOF_INT__ == 4)
  47. #define RISCV_INT __ASM_STR(.word)
  48. #define RISCV_SZINT __ASM_STR(4)
  49. #define RISCV_LGINT __ASM_STR(2)
  50. #else
  51. #error "Unexpected __SIZEOF_INT__"
  52. #endif
  53. #if (__SIZEOF_SHORT__ == 2)
  54. #define RISCV_SHORT __ASM_STR(.half)
  55. #define RISCV_SZSHORT __ASM_STR(2)
  56. #define RISCV_LGSHORT __ASM_STR(1)
  57. #else
  58. #error "Unexpected __SIZEOF_SHORT__"
  59. #endif
  60. #endif /* _ASM_RISCV_ASM_H */