vm_entry.S 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270
  1. /*
  2. * Event entry/exit for Hexagon
  3. *
  4. * Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License version 2 and
  8. * only version 2 as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program; if not, write to the Free Software
  17. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  18. * 02110-1301, USA.
  19. */
  20. #include <asm/asm-offsets.h> /* assembly-safer versions of C defines */
  21. #include <asm/mem-layout.h> /* sigh, except for page_offset */
  22. #include <asm/hexagon_vm.h>
  23. #include <asm/thread_info.h>
  24. /*
  25. * Entry into guest-mode Linux under Hexagon Virtual Machine.
  26. * Stack pointer points to event record - build pt_regs on top of it,
  27. * set up a plausible C stack frame, and dispatch to the C handler.
  28. * On return, do vmrte virtual instruction with SP where we started.
  29. *
  30. * VM Spec 0.5 uses a trap to fetch HVM record now.
  31. */
  32. /*
  33. * Save full register state, while setting up thread_info struct
  34. * pointer derived from kernel stack pointer in THREADINFO_REG
  35. * register, putting prior thread_info.regs pointer in a callee-save
  36. * register (R24, which had better not ever be assigned to THREADINFO_REG),
  37. * and updating thread_info.regs to point to current stack frame,
  38. * so as to support nested events in kernel mode.
  39. *
  40. * As this is common code, we set the pt_regs system call number
  41. * to -1 for all events. It will be replaced with the system call
  42. * number in the case where we decode a system call (trap0(#1)).
  43. */
  44. #define save_pt_regs()\
  45. memd(R0 + #_PT_R3130) = R31:30; \
  46. { memw(R0 + #_PT_R2928) = R28; \
  47. R31 = memw(R0 + #_PT_ER_VMPSP); }\
  48. { memw(R0 + #(_PT_R2928 + 4)) = R31; \
  49. R31 = ugp; } \
  50. { memd(R0 + #_PT_R2726) = R27:26; \
  51. R30 = gp ; } \
  52. memd(R0 + #_PT_R2524) = R25:24; \
  53. memd(R0 + #_PT_R2322) = R23:22; \
  54. memd(R0 + #_PT_R2120) = R21:20; \
  55. memd(R0 + #_PT_R1918) = R19:18; \
  56. memd(R0 + #_PT_R1716) = R17:16; \
  57. memd(R0 + #_PT_R1514) = R15:14; \
  58. memd(R0 + #_PT_R1312) = R13:12; \
  59. { memd(R0 + #_PT_R1110) = R11:10; \
  60. R15 = lc0; } \
  61. { memd(R0 + #_PT_R0908) = R9:8; \
  62. R14 = sa0; } \
  63. { memd(R0 + #_PT_R0706) = R7:6; \
  64. R13 = lc1; } \
  65. { memd(R0 + #_PT_R0504) = R5:4; \
  66. R12 = sa1; } \
  67. { memd(R0 + #_PT_UGPGP) = R31:30; \
  68. R11 = m1; \
  69. R2.H = #HI(_THREAD_SIZE); } \
  70. { memd(R0 + #_PT_LC0SA0) = R15:14; \
  71. R10 = m0; \
  72. R2.L = #LO(_THREAD_SIZE); } \
  73. { memd(R0 + #_PT_LC1SA1) = R13:12; \
  74. R15 = p3:0; \
  75. R2 = neg(R2); } \
  76. { memd(R0 + #_PT_M1M0) = R11:10; \
  77. R14 = usr; \
  78. R2 = and(R0,R2); } \
  79. { memd(R0 + #_PT_PREDSUSR) = R15:14; \
  80. THREADINFO_REG = R2; } \
  81. { r24 = memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS); \
  82. memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R0; \
  83. R2 = #-1; } \
  84. { memw(R0 + #_PT_SYSCALL_NR) = R2; \
  85. R30 = #0; }
  86. /*
  87. * Restore registers and thread_info.regs state. THREADINFO_REG
  88. * is assumed to still be sane, and R24 to have been correctly
  89. * preserved. Don't restore R29 (SP) until later.
  90. */
  91. #define restore_pt_regs() \
  92. { memw(THREADINFO_REG + #_THREAD_INFO_PT_REGS) = R24; \
  93. R15:14 = memd(R0 + #_PT_PREDSUSR); } \
  94. { R11:10 = memd(R0 + #_PT_M1M0); \
  95. p3:0 = R15; } \
  96. { R13:12 = memd(R0 + #_PT_LC1SA1); \
  97. usr = R14; } \
  98. { R15:14 = memd(R0 + #_PT_LC0SA0); \
  99. m1 = R11; } \
  100. { R3:2 = memd(R0 + #_PT_R0302); \
  101. m0 = R10; } \
  102. { R5:4 = memd(R0 + #_PT_R0504); \
  103. lc1 = R13; } \
  104. { R7:6 = memd(R0 + #_PT_R0706); \
  105. sa1 = R12; } \
  106. { R9:8 = memd(R0 + #_PT_R0908); \
  107. lc0 = R15; } \
  108. { R11:10 = memd(R0 + #_PT_R1110); \
  109. sa0 = R14; } \
  110. { R13:12 = memd(R0 + #_PT_R1312); \
  111. R15:14 = memd(R0 + #_PT_R1514); } \
  112. { R17:16 = memd(R0 + #_PT_R1716); \
  113. R19:18 = memd(R0 + #_PT_R1918); } \
  114. { R21:20 = memd(R0 + #_PT_R2120); \
  115. R23:22 = memd(R0 + #_PT_R2322); } \
  116. { R25:24 = memd(R0 + #_PT_R2524); \
  117. R27:26 = memd(R0 + #_PT_R2726); } \
  118. R31:30 = memd(R0 + #_PT_UGPGP); \
  119. { R28 = memw(R0 + #_PT_R2928); \
  120. ugp = R31; } \
  121. { R31:30 = memd(R0 + #_PT_R3130); \
  122. gp = R30; }
  123. /*
  124. * Clears off enough space for the rest of pt_regs; evrec is a part
  125. * of pt_regs in HVM mode. Save R0/R1, set handler's address in R1.
  126. * R0 is the address of pt_regs and is the parameter to save_pt_regs.
  127. */
  128. /*
  129. * Since the HVM isn't automagically pushing the EVREC onto the stack anymore,
  130. * we'll subract the entire size out and then fill it in ourselves.
  131. * Need to save off R0, R1, R2, R3 immediately.
  132. */
  133. #define vm_event_entry(CHandler) \
  134. { \
  135. R29 = add(R29, #-(_PT_REGS_SIZE)); \
  136. memd(R29 + #(_PT_R0100 + -_PT_REGS_SIZE)) = R1:0; \
  137. } \
  138. { \
  139. memd(R29 +#_PT_R0302) = R3:2; \
  140. } \
  141. trap1(#HVM_TRAP1_VMGETREGS); \
  142. { \
  143. memd(R29 + #_PT_ER_VMEL) = R1:0; \
  144. R0 = R29; \
  145. R1.L = #LO(CHandler); \
  146. } \
  147. { \
  148. memd(R29 + #_PT_ER_VMPSP) = R3:2; \
  149. R1.H = #HI(CHandler); \
  150. jump event_dispatch; \
  151. }
  152. .text
  153. /*
  154. * Do bulk save/restore in one place.
  155. * Adds a jump to dispatch latency, but
  156. * saves hundreds of bytes.
  157. */
  158. event_dispatch:
  159. save_pt_regs()
  160. callr r1
  161. /*
  162. * If we were in kernel mode, we don't need to check scheduler
  163. * or signals if CONFIG_PREEMPT is not set. If set, then it has
  164. * to jump to a need_resched kind of block.
  165. * BTW, CONFIG_PREEMPT is not supported yet.
  166. */
  167. #ifdef CONFIG_PREEMPT
  168. R0 = #VM_INT_DISABLE
  169. trap1(#HVM_TRAP1_VMSETIE)
  170. #endif
  171. /* "Nested control path" -- if the previous mode was kernel */
  172. R0 = memw(R29 + #_PT_ER_VMEST);
  173. P0 = tstbit(R0, #HVM_VMEST_UM_SFT);
  174. if !P0 jump restore_all;
  175. /*
  176. * Returning from system call, normally coming back from user mode
  177. */
  178. return_from_syscall:
  179. /* Disable interrupts while checking TIF */
  180. R0 = #VM_INT_DISABLE
  181. trap1(#HVM_TRAP1_VMSETIE)
  182. /*
  183. * Coming back from the C-world, our thread info pointer
  184. * should be in the designated register (usually R19)
  185. */
  186. R1.L = #LO(_TIF_ALLWORK_MASK)
  187. {
  188. R1.H = #HI(_TIF_ALLWORK_MASK);
  189. R0 = memw(THREADINFO_REG + #_THREAD_INFO_FLAGS);
  190. }
  191. /*
  192. * Compare against the "return to userspace" _TIF_WORK_MASK
  193. */
  194. R1 = and(R1,R0);
  195. { P0 = cmp.eq(R1,#0); if (!P0.new) jump:t work_pending;}
  196. jump restore_all; /* we're outta here! */
  197. work_pending:
  198. {
  199. P0 = tstbit(R1, #TIF_NEED_RESCHED);
  200. if (!P0.new) jump:nt work_notifysig;
  201. }
  202. call schedule
  203. jump return_from_syscall; /* check for more work */
  204. work_notifysig:
  205. /* this is the part that's kind of fuzzy. */
  206. R1 = and(R0, #(_TIF_SIGPENDING | _TIF_NOTIFY_RESUME));
  207. P0 = cmp.eq(R1, #0);
  208. if P0 jump restore_all
  209. R1 = R0; /* unsigned long thread_info_flags */
  210. R0 = R29; /* regs should still be at top of stack */
  211. call do_notify_resume
  212. restore_all:
  213. /* Disable interrupts, if they weren't already, before reg restore. */
  214. R0 = #VM_INT_DISABLE
  215. trap1(#HVM_TRAP1_VMSETIE)
  216. /* do the setregs here for VM 0.5 */
  217. /* R29 here should already be pointing at pt_regs */
  218. R1:0 = memd(R29 + #_PT_ER_VMEL);
  219. R3:2 = memd(R29 + #_PT_ER_VMPSP);
  220. trap1(#HVM_TRAP1_VMSETREGS);
  221. R0 = R29
  222. restore_pt_regs()
  223. R1:0 = memd(R29 + #_PT_R0100);
  224. R29 = add(R29, #_PT_REGS_SIZE);
  225. trap1(#HVM_TRAP1_VMRTE)
  226. /* Notreached */
  227. .globl _K_enter_genex
  228. _K_enter_genex:
  229. vm_event_entry(do_genex)
  230. .globl _K_enter_interrupt
  231. _K_enter_interrupt:
  232. vm_event_entry(arch_do_IRQ)
  233. .globl _K_enter_trap0
  234. _K_enter_trap0:
  235. vm_event_entry(do_trap0)
  236. .globl _K_enter_machcheck
  237. _K_enter_machcheck:
  238. vm_event_entry(do_machcheck)
  239. .globl ret_from_fork
  240. ret_from_fork:
  241. call schedule_tail
  242. jump return_from_syscall