lbt.S 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. /*
  84. * a0: scr
  85. * a1: eflag
  86. */
  87. SYM_FUNC_START(_restore_lbt_context)
  88. EX ld.d t1, a0, (0 * SCR_REG_WIDTH) # restore scr
  89. movgr2scr $scr0, t1
  90. EX ld.d t1, a0, (1 * SCR_REG_WIDTH)
  91. movgr2scr $scr1, t1
  92. EX ld.d t1, a0, (2 * SCR_REG_WIDTH)
  93. movgr2scr $scr2, t1
  94. EX ld.d t1, a0, (3 * SCR_REG_WIDTH)
  95. movgr2scr $scr3, t1
  96. EX ld.w t1, a1, 0 # restore eflags
  97. x86mtflag t1, 0x3f
  98. li.w a0, 0 # success
  99. jr ra
  100. SYM_FUNC_END(_restore_lbt_context)
  101. /*
  102. * a0: ftop
  103. */
  104. SYM_FUNC_START(_save_ftop_context)
  105. x86mftop t1
  106. st.w t1, a0, 0
  107. li.w a0, 0 # success
  108. jr ra
  109. SYM_FUNC_END(_save_ftop_context)
  110. /*
  111. * a0: ftop
  112. */
  113. SYM_FUNC_START(_restore_ftop_context)
  114. ld.w t1, a0, 0
  115. andi t1, t1, 0x7
  116. la.pcrel a0, 1f
  117. alsl.d a0, t1, a0, 3
  118. jr a0
  119. 1:
  120. x86mttop 0
  121. b 2f
  122. x86mttop 1
  123. b 2f
  124. x86mttop 2
  125. b 2f
  126. x86mttop 3
  127. b 2f
  128. x86mttop 4
  129. b 2f
  130. x86mttop 5
  131. b 2f
  132. x86mttop 6
  133. b 2f
  134. x86mttop 7
  135. 2:
  136. li.w a0, 0 # success
  137. jr ra
  138. SYM_FUNC_END(_restore_ftop_context)
  139. .L_lbt_fault:
  140. li.w a0, -EFAULT # failure
  141. jr ra
  142. STACK_FRAME_NON_STANDARD _restore_ftop_context