asm.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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 REG_AMOSWAP_AQ __REG_SEL(amoswap.d.aq, amoswap.w.aq)
  23. #define REG_ASM __REG_SEL(.dword, .word)
  24. #define SZREG __REG_SEL(8, 4)
  25. #define LGREG __REG_SEL(3, 2)
  26. #if __SIZEOF_POINTER__ == 8
  27. #ifdef __ASSEMBLY__
  28. #define RISCV_PTR .dword
  29. #define RISCV_SZPTR 8
  30. #define RISCV_LGPTR 3
  31. #else
  32. #define RISCV_PTR ".dword"
  33. #define RISCV_SZPTR "8"
  34. #define RISCV_LGPTR "3"
  35. #endif
  36. #elif __SIZEOF_POINTER__ == 4
  37. #ifdef __ASSEMBLY__
  38. #define RISCV_PTR .word
  39. #define RISCV_SZPTR 4
  40. #define RISCV_LGPTR 2
  41. #else
  42. #define RISCV_PTR ".word"
  43. #define RISCV_SZPTR "4"
  44. #define RISCV_LGPTR "2"
  45. #endif
  46. #else
  47. #error "Unexpected __SIZEOF_POINTER__"
  48. #endif
  49. #if (__SIZEOF_INT__ == 4)
  50. #define RISCV_INT __ASM_STR(.word)
  51. #define RISCV_SZINT __ASM_STR(4)
  52. #define RISCV_LGINT __ASM_STR(2)
  53. #else
  54. #error "Unexpected __SIZEOF_INT__"
  55. #endif
  56. #if (__SIZEOF_SHORT__ == 2)
  57. #define RISCV_SHORT __ASM_STR(.half)
  58. #define RISCV_SZSHORT __ASM_STR(2)
  59. #define RISCV_LGSHORT __ASM_STR(1)
  60. #else
  61. #error "Unexpected __SIZEOF_SHORT__"
  62. #endif
  63. #ifdef __ASSEMBLY__
  64. /* Common assembly source macros */
  65. /*
  66. * NOP sequence
  67. */
  68. .macro nops, num
  69. .rept \num
  70. nop
  71. .endr
  72. .endm
  73. #endif /* __ASSEMBLY__ */
  74. #endif /* _ASM_RISCV_ASM_H */