lbt.S 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. /*
  3. * Author: Qi Hu <huqi@loongson.cn>
  4. * Huacai Chen <chenhuacai@loongson.cn>
  5. *
  6. * Copyright (C) 2020-2023 Loongson Technology Corporation Limited
  7. */
  8. #include <asm/asm.h>
  9. #include <asm/asmmacro.h>
  10. #include <asm/asm-extable.h>
  11. #include <asm/asm-offsets.h>
  12. #include <asm/errno.h>
  13. #include <asm/regdef.h>
  14. #include <asm/unwind_hints.h>
  15. #define SCR_REG_WIDTH 8
  16. .macro EX insn, reg, src, offs
  17. .ex\@: \insn \reg, \src, \offs
  18. _asm_extable .ex\@, .L_lbt_fault
  19. .endm
  20. /*
  21. * Save a thread's lbt context.
  22. */
  23. SYM_FUNC_START(_save_lbt)
  24. movscr2gr t1, $scr0 # save scr
  25. stptr.d t1, a0, THREAD_SCR0
  26. movscr2gr t1, $scr1
  27. stptr.d t1, a0, THREAD_SCR1
  28. movscr2gr t1, $scr2
  29. stptr.d t1, a0, THREAD_SCR2
  30. movscr2gr t1, $scr3
  31. stptr.d t1, a0, THREAD_SCR3
  32. x86mfflag t1, 0x3f # save eflags
  33. stptr.d t1, a0, THREAD_EFLAGS
  34. jr ra
  35. SYM_FUNC_END(_save_lbt)
  36. EXPORT_SYMBOL(_save_lbt)
  37. /*
  38. * Restore a thread's lbt context.
  39. */
  40. SYM_FUNC_START(_restore_lbt)
  41. ldptr.d t1, a0, THREAD_SCR0 # restore scr
  42. movgr2scr $scr0, t1
  43. ldptr.d t1, a0, THREAD_SCR1
  44. movgr2scr $scr1, t1
  45. ldptr.d t1, a0, THREAD_SCR2
  46. movgr2scr $scr2, t1
  47. ldptr.d t1, a0, THREAD_SCR3
  48. movgr2scr $scr3, t1
  49. ldptr.d t1, a0, THREAD_EFLAGS # restore eflags
  50. x86mtflag t1, 0x3f
  51. jr ra
  52. SYM_FUNC_END(_restore_lbt)
  53. EXPORT_SYMBOL(_restore_lbt)
  54. /*
  55. * Load scr/eflag with zero.
  56. */
  57. SYM_FUNC_START(_init_lbt)
  58. movgr2scr $scr0, zero
  59. movgr2scr $scr1, zero
  60. movgr2scr $scr2, zero
  61. movgr2scr $scr3, zero
  62. x86mtflag zero, 0x3f
  63. jr ra
  64. SYM_FUNC_END(_init_lbt)
  65. /*
  66. * a0: scr
  67. * a1: eflag
  68. */
  69. SYM_FUNC_START(_save_lbt_context)
  70. movscr2gr t1, $scr0 # save scr
  71. EX st.d t1, a0, (0 * SCR_REG_WIDTH)
  72. movscr2gr t1, $scr1
  73. EX st.d t1, a0, (1 * SCR_REG_WIDTH)
  74. movscr2gr t1, $scr2
  75. EX st.d t1, a0, (2 * SCR_REG_WIDTH)
  76. movscr2gr t1, $scr3
  77. EX st.d t1, a0, (3 * SCR_REG_WIDTH)
  78. x86mfflag t1, 0x3f # save eflags
  79. EX st.w t1, a1, 0
  80. li.w a0, 0 # success
  81. jr ra
  82. SYM_FUNC_END(_save_lbt_context)
  83. EXPORT_SYMBOL_GPL(_save_lbt_context)
  84. /*
  85. * a0: scr
  86. * a1: eflag
  87. */
  88. SYM_FUNC_START(_restore_lbt_context)
  89. EX ld.d t1, a0, (0 * SCR_REG_WIDTH) # restore scr
  90. movgr2scr $scr0, t1
  91. EX ld.d t1, a0, (1 * SCR_REG_WIDTH)
  92. movgr2scr $scr1, t1
  93. EX ld.d t1, a0, (2 * SCR_REG_WIDTH)
  94. movgr2scr $scr2, t1
  95. EX ld.d t1, a0, (3 * SCR_REG_WIDTH)
  96. movgr2scr $scr3, t1
  97. EX ld.w t1, a1, 0 # restore eflags
  98. x86mtflag t1, 0x3f
  99. li.w a0, 0 # success
  100. jr ra
  101. SYM_FUNC_END(_restore_lbt_context)
  102. EXPORT_SYMBOL_GPL(_restore_lbt_context)
  103. /*
  104. * a0: ftop
  105. */
  106. SYM_FUNC_START(_save_ftop_context)
  107. x86mftop t1
  108. st.w t1, a0, 0
  109. li.w a0, 0 # success
  110. jr ra
  111. SYM_FUNC_END(_save_ftop_context)
  112. EXPORT_SYMBOL_GPL(_save_ftop_context)
  113. /*
  114. * a0: ftop
  115. */
  116. SYM_FUNC_START(_restore_ftop_context)
  117. ld.w t1, a0, 0
  118. andi t1, t1, 0x7
  119. la.pcrel a0, 1f
  120. alsl.d a0, t1, a0, 3
  121. jr a0
  122. 1:
  123. x86mttop 0
  124. b 2f
  125. x86mttop 1
  126. b 2f
  127. x86mttop 2
  128. b 2f
  129. x86mttop 3
  130. b 2f
  131. x86mttop 4
  132. b 2f
  133. x86mttop 5
  134. b 2f
  135. x86mttop 6
  136. b 2f
  137. x86mttop 7
  138. 2:
  139. li.w a0, 0 # success
  140. jr ra
  141. SYM_FUNC_END(_restore_ftop_context)
  142. EXPORT_SYMBOL_GPL(_restore_ftop_context)
  143. .L_lbt_fault:
  144. li.w a0, -EFAULT # failure
  145. jr ra
  146. STACK_FRAME_NON_STANDARD _restore_ftop_context