kvm_locore.S 17 KB

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