kvm_locore.S 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645
  1. /*
  2. * This file is subject to the terms and conditions of the GNU General Public
  3. * License. See the file "COPYING" in the main directory of this archive
  4. * for more details.
  5. *
  6. * Main entry point for the guest, exception handling.
  7. *
  8. * Copyright (C) 2012 MIPS Technologies, Inc. All rights reserved.
  9. * Authors: Sanjay Lal <sanjayl@kymasys.com>
  10. */
  11. #include <asm/asm.h>
  12. #include <asm/asmmacro.h>
  13. #include <asm/regdef.h>
  14. #include <asm/mipsregs.h>
  15. #include <asm/stackframe.h>
  16. #include <asm/asm-offsets.h>
  17. #define _C_LABEL(x) x
  18. #define MIPSX(name) mips32_ ## name
  19. #define CALLFRAME_SIZ 32
  20. /*
  21. * VECTOR
  22. * exception vector entrypoint
  23. */
  24. #define VECTOR(x, regmask) \
  25. .ent _C_LABEL(x),0; \
  26. EXPORT(x);
  27. #define VECTOR_END(x) \
  28. EXPORT(x);
  29. /* Overload, Danger Will Robinson!! */
  30. #define PT_HOST_ASID PT_BVADDR
  31. #define PT_HOST_USERLOCAL PT_EPC
  32. #define CP0_DDATA_LO $28,3
  33. #define CP0_EBASE $15,1
  34. #define CP0_INTCTL $12,1
  35. #define CP0_SRSCTL $12,2
  36. #define CP0_SRSMAP $12,3
  37. #define CP0_HWRENA $7,0
  38. /* Resume Flags */
  39. #define RESUME_FLAG_HOST (1<<1) /* Resume host? */
  40. #define RESUME_GUEST 0
  41. #define RESUME_HOST RESUME_FLAG_HOST
  42. /*
  43. * __kvm_mips_vcpu_run: entry point to the guest
  44. * a0: run
  45. * a1: vcpu
  46. */
  47. .set noreorder
  48. .set noat
  49. FEXPORT(__kvm_mips_vcpu_run)
  50. /* k0/k1 not being used in host kernel context */
  51. INT_ADDIU k1, sp, -PT_SIZE
  52. LONG_S $0, PT_R0(k1)
  53. LONG_S $1, PT_R1(k1)
  54. LONG_S $2, PT_R2(k1)
  55. LONG_S $3, PT_R3(k1)
  56. LONG_S $4, PT_R4(k1)
  57. LONG_S $5, PT_R5(k1)
  58. LONG_S $6, PT_R6(k1)
  59. LONG_S $7, PT_R7(k1)
  60. LONG_S $8, PT_R8(k1)
  61. LONG_S $9, PT_R9(k1)
  62. LONG_S $10, PT_R10(k1)
  63. LONG_S $11, PT_R11(k1)
  64. LONG_S $12, PT_R12(k1)
  65. LONG_S $13, PT_R13(k1)
  66. LONG_S $14, PT_R14(k1)
  67. LONG_S $15, PT_R15(k1)
  68. LONG_S $16, PT_R16(k1)
  69. LONG_S $17, PT_R17(k1)
  70. LONG_S $18, PT_R18(k1)
  71. LONG_S $19, PT_R19(k1)
  72. LONG_S $20, PT_R20(k1)
  73. LONG_S $21, PT_R21(k1)
  74. LONG_S $22, PT_R22(k1)
  75. LONG_S $23, PT_R23(k1)
  76. LONG_S $24, PT_R24(k1)
  77. LONG_S $25, PT_R25(k1)
  78. /* XXXKYMA k0/k1 not saved, not being used if we got here through an ioctl() */
  79. LONG_S $28, PT_R28(k1)
  80. LONG_S $29, PT_R29(k1)
  81. LONG_S $30, PT_R30(k1)
  82. LONG_S $31, PT_R31(k1)
  83. /* Save hi/lo */
  84. mflo v0
  85. LONG_S v0, PT_LO(k1)
  86. mfhi v1
  87. LONG_S v1, PT_HI(k1)
  88. /* Save host status */
  89. mfc0 v0, CP0_STATUS
  90. LONG_S v0, PT_STATUS(k1)
  91. /* Save host ASID, shove it into the BVADDR location */
  92. mfc0 v1, CP0_ENTRYHI
  93. andi v1, 0xff
  94. LONG_S v1, PT_HOST_ASID(k1)
  95. /* Save DDATA_LO, will be used to store pointer to vcpu */
  96. mfc0 v1, CP0_DDATA_LO
  97. LONG_S v1, PT_HOST_USERLOCAL(k1)
  98. /* DDATA_LO has pointer to vcpu */
  99. mtc0 a1, CP0_DDATA_LO
  100. /* Offset into vcpu->arch */
  101. INT_ADDIU k1, a1, VCPU_HOST_ARCH
  102. /*
  103. * Save the host stack to VCPU, used for exception processing
  104. * when we exit from the Guest
  105. */
  106. LONG_S sp, VCPU_HOST_STACK(k1)
  107. /* Save the kernel gp as well */
  108. LONG_S gp, VCPU_HOST_GP(k1)
  109. /* Setup status register for running the guest in UM, interrupts are disabled */
  110. li k0, (ST0_EXL | KSU_USER | ST0_BEV)
  111. mtc0 k0, CP0_STATUS
  112. ehb
  113. /* load up the new EBASE */
  114. LONG_L k0, VCPU_GUEST_EBASE(k1)
  115. mtc0 k0, CP0_EBASE
  116. /*
  117. * Now that the new EBASE has been loaded, unset BEV, set
  118. * interrupt mask as it was but make sure that timer interrupts
  119. * are enabled
  120. */
  121. li k0, (ST0_EXL | KSU_USER | ST0_IE)
  122. andi v0, v0, ST0_IM
  123. or k0, k0, v0
  124. mtc0 k0, CP0_STATUS
  125. ehb
  126. /* Set Guest EPC */
  127. LONG_L t0, VCPU_PC(k1)
  128. mtc0 t0, CP0_EPC
  129. FEXPORT(__kvm_mips_load_asid)
  130. /* Set the ASID for the Guest Kernel */
  131. INT_SLL t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */
  132. /* addresses shift to 0x80000000 */
  133. bltz t0, 1f /* If kernel */
  134. INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */
  135. INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID /* else user */
  136. 1:
  137. /* t1: contains the base of the ASID array, need to get the cpu id */
  138. LONG_L t2, TI_CPU($28) /* smp_processor_id */
  139. INT_SLL t2, t2, 2 /* x4 */
  140. REG_ADDU t3, t1, t2
  141. LONG_L k0, (t3)
  142. andi k0, k0, 0xff
  143. mtc0 k0, CP0_ENTRYHI
  144. ehb
  145. /* Disable RDHWR access */
  146. mtc0 zero, CP0_HWRENA
  147. /* Now load up the Guest Context from VCPU */
  148. LONG_L $1, VCPU_R1(k1)
  149. LONG_L $2, VCPU_R2(k1)
  150. LONG_L $3, VCPU_R3(k1)
  151. LONG_L $4, VCPU_R4(k1)
  152. LONG_L $5, VCPU_R5(k1)
  153. LONG_L $6, VCPU_R6(k1)
  154. LONG_L $7, VCPU_R7(k1)
  155. LONG_L $8, VCPU_R8(k1)
  156. LONG_L $9, VCPU_R9(k1)
  157. LONG_L $10, VCPU_R10(k1)
  158. LONG_L $11, VCPU_R11(k1)
  159. LONG_L $12, VCPU_R12(k1)
  160. LONG_L $13, VCPU_R13(k1)
  161. LONG_L $14, VCPU_R14(k1)
  162. LONG_L $15, VCPU_R15(k1)
  163. LONG_L $16, VCPU_R16(k1)
  164. LONG_L $17, VCPU_R17(k1)
  165. LONG_L $18, VCPU_R18(k1)
  166. LONG_L $19, VCPU_R19(k1)
  167. LONG_L $20, VCPU_R20(k1)
  168. LONG_L $21, VCPU_R21(k1)
  169. LONG_L $22, VCPU_R22(k1)
  170. LONG_L $23, VCPU_R23(k1)
  171. LONG_L $24, VCPU_R24(k1)
  172. LONG_L $25, VCPU_R25(k1)
  173. /* k0/k1 loaded up later */
  174. LONG_L $28, VCPU_R28(k1)
  175. LONG_L $29, VCPU_R29(k1)
  176. LONG_L $30, VCPU_R30(k1)
  177. LONG_L $31, VCPU_R31(k1)
  178. /* Restore hi/lo */
  179. LONG_L k0, VCPU_LO(k1)
  180. mtlo k0
  181. LONG_L k0, VCPU_HI(k1)
  182. mthi k0
  183. FEXPORT(__kvm_mips_load_k0k1)
  184. /* Restore the guest's k0/k1 registers */
  185. LONG_L k0, VCPU_R26(k1)
  186. LONG_L k1, VCPU_R27(k1)
  187. /* Jump to guest */
  188. eret
  189. VECTOR(MIPSX(exception), unknown)
  190. /*
  191. * Find out what mode we came from and jump to the proper handler.
  192. */
  193. mtc0 k0, CP0_ERROREPC #01: Save guest k0
  194. ehb #02:
  195. mfc0 k0, CP0_EBASE #02: Get EBASE
  196. INT_SRL k0, k0, 10 #03: Get rid of CPUNum
  197. INT_SLL k0, k0, 10 #04
  198. LONG_S k1, 0x3000(k0) #05: Save k1 @ offset 0x3000
  199. INT_ADDIU k0, k0, 0x2000 #06: Exception handler is installed @ offset 0x2000
  200. j k0 #07: jump to the function
  201. nop #08: branch delay slot
  202. VECTOR_END(MIPSX(exceptionEnd))
  203. .end MIPSX(exception)
  204. /*
  205. * Generic Guest exception handler. We end up here when the guest
  206. * does something that causes a trap to kernel mode.
  207. *
  208. */
  209. NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra)
  210. /* Get the VCPU pointer from DDTATA_LO */
  211. mfc0 k1, CP0_DDATA_LO
  212. INT_ADDIU k1, k1, VCPU_HOST_ARCH
  213. /* Start saving Guest context to VCPU */
  214. LONG_S $0, VCPU_R0(k1)
  215. LONG_S $1, VCPU_R1(k1)
  216. LONG_S $2, VCPU_R2(k1)
  217. LONG_S $3, VCPU_R3(k1)
  218. LONG_S $4, VCPU_R4(k1)
  219. LONG_S $5, VCPU_R5(k1)
  220. LONG_S $6, VCPU_R6(k1)
  221. LONG_S $7, VCPU_R7(k1)
  222. LONG_S $8, VCPU_R8(k1)
  223. LONG_S $9, VCPU_R9(k1)
  224. LONG_S $10, VCPU_R10(k1)
  225. LONG_S $11, VCPU_R11(k1)
  226. LONG_S $12, VCPU_R12(k1)
  227. LONG_S $13, VCPU_R13(k1)
  228. LONG_S $14, VCPU_R14(k1)
  229. LONG_S $15, VCPU_R15(k1)
  230. LONG_S $16, VCPU_R16(k1)
  231. LONG_S $17, VCPU_R17(k1)
  232. LONG_S $18, VCPU_R18(k1)
  233. LONG_S $19, VCPU_R19(k1)
  234. LONG_S $20, VCPU_R20(k1)
  235. LONG_S $21, VCPU_R21(k1)
  236. LONG_S $22, VCPU_R22(k1)
  237. LONG_S $23, VCPU_R23(k1)
  238. LONG_S $24, VCPU_R24(k1)
  239. LONG_S $25, VCPU_R25(k1)
  240. /* Guest k0/k1 saved later */
  241. LONG_S $28, VCPU_R28(k1)
  242. LONG_S $29, VCPU_R29(k1)
  243. LONG_S $30, VCPU_R30(k1)
  244. LONG_S $31, VCPU_R31(k1)
  245. /* We need to save hi/lo and restore them on
  246. * the way out
  247. */
  248. mfhi t0
  249. LONG_S t0, VCPU_HI(k1)
  250. mflo t0
  251. LONG_S t0, VCPU_LO(k1)
  252. /* Finally save guest k0/k1 to VCPU */
  253. mfc0 t0, CP0_ERROREPC
  254. LONG_S t0, VCPU_R26(k1)
  255. /* Get GUEST k1 and save it in VCPU */
  256. PTR_LI t1, ~0x2ff
  257. mfc0 t0, CP0_EBASE
  258. and t0, t0, t1
  259. LONG_L t0, 0x3000(t0)
  260. LONG_S t0, VCPU_R27(k1)
  261. /* Now that context has been saved, we can use other registers */
  262. /* Restore vcpu */
  263. mfc0 a1, CP0_DDATA_LO
  264. move s1, a1
  265. /* Restore run (vcpu->run) */
  266. LONG_L a0, VCPU_RUN(a1)
  267. /* Save pointer to run in s0, will be saved by the compiler */
  268. move s0, a0
  269. /* Save Host level EPC, BadVaddr and Cause to VCPU, useful to
  270. * process the exception */
  271. mfc0 k0,CP0_EPC
  272. LONG_S k0, VCPU_PC(k1)
  273. mfc0 k0, CP0_BADVADDR
  274. LONG_S k0, VCPU_HOST_CP0_BADVADDR(k1)
  275. mfc0 k0, CP0_CAUSE
  276. LONG_S k0, VCPU_HOST_CP0_CAUSE(k1)
  277. mfc0 k0, CP0_ENTRYHI
  278. LONG_S k0, VCPU_HOST_ENTRYHI(k1)
  279. /* Now restore the host state just enough to run the handlers */
  280. /* Swtich EBASE to the one used by Linux */
  281. /* load up the host EBASE */
  282. mfc0 v0, CP0_STATUS
  283. .set at
  284. or k0, v0, ST0_BEV
  285. .set noat
  286. mtc0 k0, CP0_STATUS
  287. ehb
  288. LONG_L k0, VCPU_HOST_EBASE(k1)
  289. mtc0 k0,CP0_EBASE
  290. /* Now that the new EBASE has been loaded, unset BEV and KSU_USER */
  291. .set at
  292. and v0, v0, ~(ST0_EXL | KSU_USER | ST0_IE)
  293. or v0, v0, ST0_CU0
  294. .set noat
  295. mtc0 v0, CP0_STATUS
  296. ehb
  297. /* Load up host GP */
  298. LONG_L gp, VCPU_HOST_GP(k1)
  299. /* Need a stack before we can jump to "C" */
  300. LONG_L sp, VCPU_HOST_STACK(k1)
  301. /* Saved host state */
  302. INT_ADDIU sp, sp, -PT_SIZE
  303. /* XXXKYMA do we need to load the host ASID, maybe not because the
  304. * kernel entries are marked GLOBAL, need to verify
  305. */
  306. /* Restore host DDATA_LO */
  307. LONG_L k0, PT_HOST_USERLOCAL(sp)
  308. mtc0 k0, CP0_DDATA_LO
  309. /* Restore RDHWR access */
  310. PTR_LI k0, 0x2000000F
  311. mtc0 k0, CP0_HWRENA
  312. /* Jump to handler */
  313. FEXPORT(__kvm_mips_jump_to_handler)
  314. /* XXXKYMA: not sure if this is safe, how large is the stack??
  315. * Now jump to the kvm_mips_handle_exit() to see if we can deal
  316. * with this in the kernel */
  317. PTR_LA t9, kvm_mips_handle_exit
  318. jalr.hb t9
  319. INT_ADDIU sp, sp, -CALLFRAME_SIZ /* BD Slot */
  320. /* Return from handler Make sure interrupts are disabled */
  321. di
  322. ehb
  323. /* XXXKYMA: k0/k1 could have been blown away if we processed
  324. * an exception while we were handling the exception from the
  325. * guest, reload k1
  326. */
  327. move k1, s1
  328. INT_ADDIU k1, k1, VCPU_HOST_ARCH
  329. /* Check return value, should tell us if we are returning to the
  330. * host (handle I/O etc)or resuming the guest
  331. */
  332. andi t0, v0, RESUME_HOST
  333. bnez t0, __kvm_mips_return_to_host
  334. nop
  335. __kvm_mips_return_to_guest:
  336. /* Put the saved pointer to vcpu (s1) back into the DDATA_LO Register */
  337. mtc0 s1, CP0_DDATA_LO
  338. /* Load up the Guest EBASE to minimize the window where BEV is set */
  339. LONG_L t0, VCPU_GUEST_EBASE(k1)
  340. /* Switch EBASE back to the one used by KVM */
  341. mfc0 v1, CP0_STATUS
  342. .set at
  343. or k0, v1, ST0_BEV
  344. .set noat
  345. mtc0 k0, CP0_STATUS
  346. ehb
  347. mtc0 t0, CP0_EBASE
  348. /* Setup status register for running guest in UM */
  349. .set at
  350. or v1, v1, (ST0_EXL | KSU_USER | ST0_IE)
  351. and v1, v1, ~ST0_CU0
  352. .set noat
  353. mtc0 v1, CP0_STATUS
  354. ehb
  355. /* Set Guest EPC */
  356. LONG_L t0, VCPU_PC(k1)
  357. mtc0 t0, CP0_EPC
  358. /* Set the ASID for the Guest Kernel */
  359. INT_SLL t0, t0, 1 /* with kseg0 @ 0x40000000, kernel */
  360. /* addresses shift to 0x80000000 */
  361. bltz t0, 1f /* If kernel */
  362. INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */
  363. INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID /* else user */
  364. 1:
  365. /* t1: contains the base of the ASID array, need to get the cpu id */
  366. LONG_L t2, TI_CPU($28) /* smp_processor_id */
  367. INT_SLL t2, t2, 2 /* x4 */
  368. REG_ADDU t3, t1, t2
  369. LONG_L k0, (t3)
  370. andi k0, k0, 0xff
  371. mtc0 k0,CP0_ENTRYHI
  372. ehb
  373. /* Disable RDHWR access */
  374. mtc0 zero, CP0_HWRENA
  375. /* load the guest context from VCPU and return */
  376. LONG_L $0, VCPU_R0(k1)
  377. LONG_L $1, VCPU_R1(k1)
  378. LONG_L $2, VCPU_R2(k1)
  379. LONG_L $3, VCPU_R3(k1)
  380. LONG_L $4, VCPU_R4(k1)
  381. LONG_L $5, VCPU_R5(k1)
  382. LONG_L $6, VCPU_R6(k1)
  383. LONG_L $7, VCPU_R7(k1)
  384. LONG_L $8, VCPU_R8(k1)
  385. LONG_L $9, VCPU_R9(k1)
  386. LONG_L $10, VCPU_R10(k1)
  387. LONG_L $11, VCPU_R11(k1)
  388. LONG_L $12, VCPU_R12(k1)
  389. LONG_L $13, VCPU_R13(k1)
  390. LONG_L $14, VCPU_R14(k1)
  391. LONG_L $15, VCPU_R15(k1)
  392. LONG_L $16, VCPU_R16(k1)
  393. LONG_L $17, VCPU_R17(k1)
  394. LONG_L $18, VCPU_R18(k1)
  395. LONG_L $19, VCPU_R19(k1)
  396. LONG_L $20, VCPU_R20(k1)
  397. LONG_L $21, VCPU_R21(k1)
  398. LONG_L $22, VCPU_R22(k1)
  399. LONG_L $23, VCPU_R23(k1)
  400. LONG_L $24, VCPU_R24(k1)
  401. LONG_L $25, VCPU_R25(k1)
  402. /* $/k1 loaded later */
  403. LONG_L $28, VCPU_R28(k1)
  404. LONG_L $29, VCPU_R29(k1)
  405. LONG_L $30, VCPU_R30(k1)
  406. LONG_L $31, VCPU_R31(k1)
  407. FEXPORT(__kvm_mips_skip_guest_restore)
  408. LONG_L k0, VCPU_HI(k1)
  409. mthi k0
  410. LONG_L k0, VCPU_LO(k1)
  411. mtlo k0
  412. LONG_L k0, VCPU_R26(k1)
  413. LONG_L k1, VCPU_R27(k1)
  414. eret
  415. __kvm_mips_return_to_host:
  416. /* EBASE is already pointing to Linux */
  417. LONG_L k1, VCPU_HOST_STACK(k1)
  418. INT_ADDIU k1,k1, -PT_SIZE
  419. /* Restore host DDATA_LO */
  420. LONG_L k0, PT_HOST_USERLOCAL(k1)
  421. mtc0 k0, CP0_DDATA_LO
  422. /* Restore host ASID */
  423. LONG_L k0, PT_HOST_ASID(sp)
  424. andi k0, 0xff
  425. mtc0 k0,CP0_ENTRYHI
  426. ehb
  427. /* Load context saved on the host stack */
  428. LONG_L $0, PT_R0(k1)
  429. LONG_L $1, PT_R1(k1)
  430. /* r2/v0 is the return code, shift it down by 2 (arithmetic)
  431. * to recover the err code */
  432. INT_SRA k0, v0, 2
  433. move $2, k0
  434. LONG_L $3, PT_R3(k1)
  435. LONG_L $4, PT_R4(k1)
  436. LONG_L $5, PT_R5(k1)
  437. LONG_L $6, PT_R6(k1)
  438. LONG_L $7, PT_R7(k1)
  439. LONG_L $8, PT_R8(k1)
  440. LONG_L $9, PT_R9(k1)
  441. LONG_L $10, PT_R10(k1)
  442. LONG_L $11, PT_R11(k1)
  443. LONG_L $12, PT_R12(k1)
  444. LONG_L $13, PT_R13(k1)
  445. LONG_L $14, PT_R14(k1)
  446. LONG_L $15, PT_R15(k1)
  447. LONG_L $16, PT_R16(k1)
  448. LONG_L $17, PT_R17(k1)
  449. LONG_L $18, PT_R18(k1)
  450. LONG_L $19, PT_R19(k1)
  451. LONG_L $20, PT_R20(k1)
  452. LONG_L $21, PT_R21(k1)
  453. LONG_L $22, PT_R22(k1)
  454. LONG_L $23, PT_R23(k1)
  455. LONG_L $24, PT_R24(k1)
  456. LONG_L $25, PT_R25(k1)
  457. /* Host k0/k1 were not saved */
  458. LONG_L $28, PT_R28(k1)
  459. LONG_L $29, PT_R29(k1)
  460. LONG_L $30, PT_R30(k1)
  461. LONG_L k0, PT_HI(k1)
  462. mthi k0
  463. LONG_L k0, PT_LO(k1)
  464. mtlo k0
  465. /* Restore RDHWR access */
  466. PTR_LI k0, 0x2000000F
  467. mtc0 k0, CP0_HWRENA
  468. /* Restore RA, which is the address we will return to */
  469. LONG_L ra, PT_R31(k1)
  470. j ra
  471. nop
  472. VECTOR_END(MIPSX(GuestExceptionEnd))
  473. .end MIPSX(GuestException)
  474. MIPSX(exceptions):
  475. ####
  476. ##### The exception handlers.
  477. #####
  478. .word _C_LABEL(MIPSX(GuestException)) # 0
  479. .word _C_LABEL(MIPSX(GuestException)) # 1
  480. .word _C_LABEL(MIPSX(GuestException)) # 2
  481. .word _C_LABEL(MIPSX(GuestException)) # 3
  482. .word _C_LABEL(MIPSX(GuestException)) # 4
  483. .word _C_LABEL(MIPSX(GuestException)) # 5
  484. .word _C_LABEL(MIPSX(GuestException)) # 6
  485. .word _C_LABEL(MIPSX(GuestException)) # 7
  486. .word _C_LABEL(MIPSX(GuestException)) # 8
  487. .word _C_LABEL(MIPSX(GuestException)) # 9
  488. .word _C_LABEL(MIPSX(GuestException)) # 10
  489. .word _C_LABEL(MIPSX(GuestException)) # 11
  490. .word _C_LABEL(MIPSX(GuestException)) # 12
  491. .word _C_LABEL(MIPSX(GuestException)) # 13
  492. .word _C_LABEL(MIPSX(GuestException)) # 14
  493. .word _C_LABEL(MIPSX(GuestException)) # 15
  494. .word _C_LABEL(MIPSX(GuestException)) # 16
  495. .word _C_LABEL(MIPSX(GuestException)) # 17
  496. .word _C_LABEL(MIPSX(GuestException)) # 18
  497. .word _C_LABEL(MIPSX(GuestException)) # 19
  498. .word _C_LABEL(MIPSX(GuestException)) # 20
  499. .word _C_LABEL(MIPSX(GuestException)) # 21
  500. .word _C_LABEL(MIPSX(GuestException)) # 22
  501. .word _C_LABEL(MIPSX(GuestException)) # 23
  502. .word _C_LABEL(MIPSX(GuestException)) # 24
  503. .word _C_LABEL(MIPSX(GuestException)) # 25
  504. .word _C_LABEL(MIPSX(GuestException)) # 26
  505. .word _C_LABEL(MIPSX(GuestException)) # 27
  506. .word _C_LABEL(MIPSX(GuestException)) # 28
  507. .word _C_LABEL(MIPSX(GuestException)) # 29
  508. .word _C_LABEL(MIPSX(GuestException)) # 30
  509. .word _C_LABEL(MIPSX(GuestException)) # 31
  510. /* This routine makes changes to the instruction stream effective to the hardware.
  511. * It should be called after the instruction stream is written.
  512. * On return, the new instructions are effective.
  513. * Inputs:
  514. * a0 = Start address of new instruction stream
  515. * a1 = Size, in bytes, of new instruction stream
  516. */
  517. #define HW_SYNCI_Step $1
  518. LEAF(MIPSX(SyncICache))
  519. .set push
  520. .set mips32r2
  521. beq a1, zero, 20f
  522. nop
  523. REG_ADDU a1, a0, a1
  524. rdhwr v0, HW_SYNCI_Step
  525. beq v0, zero, 20f
  526. nop
  527. 10:
  528. synci 0(a0)
  529. REG_ADDU a0, a0, v0
  530. sltu v1, a0, a1
  531. bne v1, zero, 10b
  532. nop
  533. sync
  534. 20:
  535. jr.hb ra
  536. nop
  537. .set pop
  538. END(MIPSX(SyncICache))