asm.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  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. #include <asm/asm-offsets.h>
  65. /* Common assembly source macros */
  66. /*
  67. * NOP sequence
  68. */
  69. .macro nops, num
  70. .rept \num
  71. nop
  72. .endr
  73. .endm
  74. /* save all GPs except x1 ~ x5 */
  75. .macro save_from_x6_to_x31
  76. REG_S x6, PT_T1(sp)
  77. REG_S x7, PT_T2(sp)
  78. REG_S x8, PT_S0(sp)
  79. REG_S x9, PT_S1(sp)
  80. REG_S x10, PT_A0(sp)
  81. REG_S x11, PT_A1(sp)
  82. REG_S x12, PT_A2(sp)
  83. REG_S x13, PT_A3(sp)
  84. REG_S x14, PT_A4(sp)
  85. REG_S x15, PT_A5(sp)
  86. REG_S x16, PT_A6(sp)
  87. REG_S x17, PT_A7(sp)
  88. REG_S x18, PT_S2(sp)
  89. REG_S x19, PT_S3(sp)
  90. REG_S x20, PT_S4(sp)
  91. REG_S x21, PT_S5(sp)
  92. REG_S x22, PT_S6(sp)
  93. REG_S x23, PT_S7(sp)
  94. REG_S x24, PT_S8(sp)
  95. REG_S x25, PT_S9(sp)
  96. REG_S x26, PT_S10(sp)
  97. REG_S x27, PT_S11(sp)
  98. REG_S x28, PT_T3(sp)
  99. REG_S x29, PT_T4(sp)
  100. REG_S x30, PT_T5(sp)
  101. REG_S x31, PT_T6(sp)
  102. .endm
  103. /* restore all GPs except x1 ~ x5 */
  104. .macro restore_from_x6_to_x31
  105. REG_L x6, PT_T1(sp)
  106. REG_L x7, PT_T2(sp)
  107. REG_L x8, PT_S0(sp)
  108. REG_L x9, PT_S1(sp)
  109. REG_L x10, PT_A0(sp)
  110. REG_L x11, PT_A1(sp)
  111. REG_L x12, PT_A2(sp)
  112. REG_L x13, PT_A3(sp)
  113. REG_L x14, PT_A4(sp)
  114. REG_L x15, PT_A5(sp)
  115. REG_L x16, PT_A6(sp)
  116. REG_L x17, PT_A7(sp)
  117. REG_L x18, PT_S2(sp)
  118. REG_L x19, PT_S3(sp)
  119. REG_L x20, PT_S4(sp)
  120. REG_L x21, PT_S5(sp)
  121. REG_L x22, PT_S6(sp)
  122. REG_L x23, PT_S7(sp)
  123. REG_L x24, PT_S8(sp)
  124. REG_L x25, PT_S9(sp)
  125. REG_L x26, PT_S10(sp)
  126. REG_L x27, PT_S11(sp)
  127. REG_L x28, PT_T3(sp)
  128. REG_L x29, PT_T4(sp)
  129. REG_L x30, PT_T5(sp)
  130. REG_L x31, PT_T6(sp)
  131. .endm
  132. #endif /* __ASSEMBLY__ */
  133. #endif /* _ASM_RISCV_ASM_H */