Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 1 | /* |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 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 | */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 11 | |
| 12 | #include <asm/asm.h> |
| 13 | #include <asm/asmmacro.h> |
| 14 | #include <asm/regdef.h> |
| 15 | #include <asm/mipsregs.h> |
| 16 | #include <asm/stackframe.h> |
| 17 | #include <asm/asm-offsets.h> |
| 18 | |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 19 | #define _C_LABEL(x) x |
| 20 | #define MIPSX(name) mips32_ ## name |
| 21 | #define CALLFRAME_SIZ 32 |
| 22 | |
| 23 | /* |
| 24 | * VECTOR |
| 25 | * exception vector entrypoint |
| 26 | */ |
| 27 | #define VECTOR(x, regmask) \ |
| 28 | .ent _C_LABEL(x),0; \ |
| 29 | EXPORT(x); |
| 30 | |
| 31 | #define VECTOR_END(x) \ |
| 32 | EXPORT(x); |
| 33 | |
| 34 | /* Overload, Danger Will Robinson!! */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 35 | #define PT_HOST_USERLOCAL PT_EPC |
| 36 | |
| 37 | #define CP0_DDATA_LO $28,3 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 38 | |
| 39 | /* Resume Flags */ |
| 40 | #define RESUME_FLAG_HOST (1<<1) /* Resume host? */ |
| 41 | |
| 42 | #define RESUME_GUEST 0 |
| 43 | #define RESUME_HOST RESUME_FLAG_HOST |
| 44 | |
| 45 | /* |
| 46 | * __kvm_mips_vcpu_run: entry point to the guest |
| 47 | * a0: run |
| 48 | * a1: vcpu |
| 49 | */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 50 | .set noreorder |
| 51 | .set noat |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 52 | |
David Daney | bb48c2f | 2013-08-01 13:22:34 -0700 | [diff] [blame] | 53 | FEXPORT(__kvm_mips_vcpu_run) |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 54 | /* k0/k1 not being used in host kernel context */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 55 | INT_ADDIU k1, sp, -PT_SIZE |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 56 | LONG_S $0, PT_R0(k1) |
| 57 | LONG_S $1, PT_R1(k1) |
| 58 | LONG_S $2, PT_R2(k1) |
| 59 | LONG_S $3, PT_R3(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 60 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 61 | LONG_S $4, PT_R4(k1) |
| 62 | LONG_S $5, PT_R5(k1) |
| 63 | LONG_S $6, PT_R6(k1) |
| 64 | LONG_S $7, PT_R7(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 65 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 66 | LONG_S $8, PT_R8(k1) |
| 67 | LONG_S $9, PT_R9(k1) |
| 68 | LONG_S $10, PT_R10(k1) |
| 69 | LONG_S $11, PT_R11(k1) |
| 70 | LONG_S $12, PT_R12(k1) |
| 71 | LONG_S $13, PT_R13(k1) |
| 72 | LONG_S $14, PT_R14(k1) |
| 73 | LONG_S $15, PT_R15(k1) |
| 74 | LONG_S $16, PT_R16(k1) |
| 75 | LONG_S $17, PT_R17(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 76 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 77 | LONG_S $18, PT_R18(k1) |
| 78 | LONG_S $19, PT_R19(k1) |
| 79 | LONG_S $20, PT_R20(k1) |
| 80 | LONG_S $21, PT_R21(k1) |
| 81 | LONG_S $22, PT_R22(k1) |
| 82 | LONG_S $23, PT_R23(k1) |
| 83 | LONG_S $24, PT_R24(k1) |
| 84 | LONG_S $25, PT_R25(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 85 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 86 | /* |
| 87 | * XXXKYMA k0/k1 not saved, not being used if we got here through |
| 88 | * an ioctl() |
| 89 | */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 90 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 91 | LONG_S $28, PT_R28(k1) |
| 92 | LONG_S $29, PT_R29(k1) |
| 93 | LONG_S $30, PT_R30(k1) |
| 94 | LONG_S $31, PT_R31(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 95 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 96 | /* Save hi/lo */ |
| 97 | mflo v0 |
| 98 | LONG_S v0, PT_LO(k1) |
| 99 | mfhi v1 |
| 100 | LONG_S v1, PT_HI(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 101 | |
| 102 | /* Save host status */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 103 | mfc0 v0, CP0_STATUS |
| 104 | LONG_S v0, PT_STATUS(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 105 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 106 | /* Save DDATA_LO, will be used to store pointer to vcpu */ |
| 107 | mfc0 v1, CP0_DDATA_LO |
| 108 | LONG_S v1, PT_HOST_USERLOCAL(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 109 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 110 | /* DDATA_LO has pointer to vcpu */ |
| 111 | mtc0 a1, CP0_DDATA_LO |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 112 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 113 | /* Offset into vcpu->arch */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 114 | INT_ADDIU k1, a1, VCPU_HOST_ARCH |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 115 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 116 | /* |
| 117 | * Save the host stack to VCPU, used for exception processing |
| 118 | * when we exit from the Guest |
| 119 | */ |
| 120 | LONG_S sp, VCPU_HOST_STACK(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 121 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 122 | /* Save the kernel gp as well */ |
| 123 | LONG_S gp, VCPU_HOST_GP(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 124 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 125 | /* |
| 126 | * Setup status register for running the guest in UM, interrupts |
| 127 | * are disabled |
| 128 | */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 129 | li k0, (ST0_EXL | KSU_USER | ST0_BEV) |
| 130 | mtc0 k0, CP0_STATUS |
| 131 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 132 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 133 | /* load up the new EBASE */ |
| 134 | LONG_L k0, VCPU_GUEST_EBASE(k1) |
| 135 | mtc0 k0, CP0_EBASE |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 136 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 137 | /* |
| 138 | * Now that the new EBASE has been loaded, unset BEV, set |
| 139 | * interrupt mask as it was but make sure that timer interrupts |
| 140 | * are enabled |
| 141 | */ |
| 142 | li k0, (ST0_EXL | KSU_USER | ST0_IE) |
| 143 | andi v0, v0, ST0_IM |
| 144 | or k0, k0, v0 |
| 145 | mtc0 k0, CP0_STATUS |
| 146 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 147 | |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 148 | /* Set Guest EPC */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 149 | LONG_L t0, VCPU_PC(k1) |
| 150 | mtc0 t0, CP0_EPC |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 151 | |
| 152 | FEXPORT(__kvm_mips_load_asid) |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 153 | /* Set the ASID for the Guest Kernel */ |
James Hogan | 002374f | 2015-11-11 14:21:18 +0000 | [diff] [blame] | 154 | PTR_L t0, VCPU_COP0(k1) |
| 155 | LONG_L t0, COP0_STATUS(t0) |
| 156 | andi t0, KSU_USER | ST0_ERL | ST0_EXL |
| 157 | xori t0, KSU_USER |
| 158 | bnez t0, 1f /* If kernel */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 159 | INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ |
| 160 | INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID /* else user */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 161 | 1: |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 162 | /* t1: contains the base of the ASID array, need to get the cpu id */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 163 | LONG_L t2, TI_CPU($28) /* smp_processor_id */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 164 | INT_SLL t2, t2, 2 /* x4 */ |
| 165 | REG_ADDU t3, t1, t2 |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 166 | LONG_L k0, (t3) |
James Hogan | 9b5c339 | 2016-05-06 14:36:19 +0100 | [diff] [blame^] | 167 | andi k0, k0, MIPS_ENTRYHI_ASID |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 168 | mtc0 k0, CP0_ENTRYHI |
| 169 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 170 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 171 | /* Disable RDHWR access */ |
| 172 | mtc0 zero, CP0_HWRENA |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 173 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 174 | /* Now load up the Guest Context from VCPU */ |
| 175 | LONG_L $1, VCPU_R1(k1) |
| 176 | LONG_L $2, VCPU_R2(k1) |
| 177 | LONG_L $3, VCPU_R3(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 178 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 179 | LONG_L $4, VCPU_R4(k1) |
| 180 | LONG_L $5, VCPU_R5(k1) |
| 181 | LONG_L $6, VCPU_R6(k1) |
| 182 | LONG_L $7, VCPU_R7(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 183 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 184 | LONG_L $8, VCPU_R8(k1) |
| 185 | LONG_L $9, VCPU_R9(k1) |
| 186 | LONG_L $10, VCPU_R10(k1) |
| 187 | LONG_L $11, VCPU_R11(k1) |
| 188 | LONG_L $12, VCPU_R12(k1) |
| 189 | LONG_L $13, VCPU_R13(k1) |
| 190 | LONG_L $14, VCPU_R14(k1) |
| 191 | LONG_L $15, VCPU_R15(k1) |
| 192 | LONG_L $16, VCPU_R16(k1) |
| 193 | LONG_L $17, VCPU_R17(k1) |
| 194 | LONG_L $18, VCPU_R18(k1) |
| 195 | LONG_L $19, VCPU_R19(k1) |
| 196 | LONG_L $20, VCPU_R20(k1) |
| 197 | LONG_L $21, VCPU_R21(k1) |
| 198 | LONG_L $22, VCPU_R22(k1) |
| 199 | LONG_L $23, VCPU_R23(k1) |
| 200 | LONG_L $24, VCPU_R24(k1) |
| 201 | LONG_L $25, VCPU_R25(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 202 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 203 | /* k0/k1 loaded up later */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 204 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 205 | LONG_L $28, VCPU_R28(k1) |
| 206 | LONG_L $29, VCPU_R29(k1) |
| 207 | LONG_L $30, VCPU_R30(k1) |
| 208 | LONG_L $31, VCPU_R31(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 209 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 210 | /* Restore hi/lo */ |
| 211 | LONG_L k0, VCPU_LO(k1) |
| 212 | mtlo k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 213 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 214 | LONG_L k0, VCPU_HI(k1) |
| 215 | mthi k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 216 | |
| 217 | FEXPORT(__kvm_mips_load_k0k1) |
| 218 | /* Restore the guest's k0/k1 registers */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 219 | LONG_L k0, VCPU_R26(k1) |
| 220 | LONG_L k1, VCPU_R27(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 221 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 222 | /* Jump to guest */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 223 | eret |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 224 | |
| 225 | VECTOR(MIPSX(exception), unknown) |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 226 | /* Find out what mode we came from and jump to the proper handler. */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 227 | mtc0 k0, CP0_ERROREPC #01: Save guest k0 |
| 228 | ehb #02: |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 229 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 230 | mfc0 k0, CP0_EBASE #02: Get EBASE |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 231 | INT_SRL k0, k0, 10 #03: Get rid of CPUNum |
| 232 | INT_SLL k0, k0, 10 #04 |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 233 | LONG_S k1, 0x3000(k0) #05: Save k1 @ offset 0x3000 |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 234 | INT_ADDIU k0, k0, 0x2000 #06: Exception handler is |
| 235 | # installed @ offset 0x2000 |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 236 | j k0 #07: jump to the function |
| 237 | nop #08: branch delay slot |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 238 | VECTOR_END(MIPSX(exceptionEnd)) |
| 239 | .end MIPSX(exception) |
| 240 | |
| 241 | /* |
| 242 | * Generic Guest exception handler. We end up here when the guest |
| 243 | * does something that causes a trap to kernel mode. |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 244 | */ |
| 245 | NESTED (MIPSX(GuestException), CALLFRAME_SIZ, ra) |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 246 | /* Get the VCPU pointer from DDTATA_LO */ |
| 247 | mfc0 k1, CP0_DDATA_LO |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 248 | INT_ADDIU k1, k1, VCPU_HOST_ARCH |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 249 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 250 | /* Start saving Guest context to VCPU */ |
| 251 | LONG_S $0, VCPU_R0(k1) |
| 252 | LONG_S $1, VCPU_R1(k1) |
| 253 | LONG_S $2, VCPU_R2(k1) |
| 254 | LONG_S $3, VCPU_R3(k1) |
| 255 | LONG_S $4, VCPU_R4(k1) |
| 256 | LONG_S $5, VCPU_R5(k1) |
| 257 | LONG_S $6, VCPU_R6(k1) |
| 258 | LONG_S $7, VCPU_R7(k1) |
| 259 | LONG_S $8, VCPU_R8(k1) |
| 260 | LONG_S $9, VCPU_R9(k1) |
| 261 | LONG_S $10, VCPU_R10(k1) |
| 262 | LONG_S $11, VCPU_R11(k1) |
| 263 | LONG_S $12, VCPU_R12(k1) |
| 264 | LONG_S $13, VCPU_R13(k1) |
| 265 | LONG_S $14, VCPU_R14(k1) |
| 266 | LONG_S $15, VCPU_R15(k1) |
| 267 | LONG_S $16, VCPU_R16(k1) |
| 268 | LONG_S $17, VCPU_R17(k1) |
| 269 | LONG_S $18, VCPU_R18(k1) |
| 270 | LONG_S $19, VCPU_R19(k1) |
| 271 | LONG_S $20, VCPU_R20(k1) |
| 272 | LONG_S $21, VCPU_R21(k1) |
| 273 | LONG_S $22, VCPU_R22(k1) |
| 274 | LONG_S $23, VCPU_R23(k1) |
| 275 | LONG_S $24, VCPU_R24(k1) |
| 276 | LONG_S $25, VCPU_R25(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 277 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 278 | /* Guest k0/k1 saved later */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 279 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 280 | LONG_S $28, VCPU_R28(k1) |
| 281 | LONG_S $29, VCPU_R29(k1) |
| 282 | LONG_S $30, VCPU_R30(k1) |
| 283 | LONG_S $31, VCPU_R31(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 284 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 285 | /* We need to save hi/lo and restore them on the way out */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 286 | mfhi t0 |
| 287 | LONG_S t0, VCPU_HI(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 288 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 289 | mflo t0 |
| 290 | LONG_S t0, VCPU_LO(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 291 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 292 | /* Finally save guest k0/k1 to VCPU */ |
| 293 | mfc0 t0, CP0_ERROREPC |
| 294 | LONG_S t0, VCPU_R26(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 295 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 296 | /* Get GUEST k1 and save it in VCPU */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 297 | PTR_LI t1, ~0x2ff |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 298 | mfc0 t0, CP0_EBASE |
| 299 | and t0, t0, t1 |
| 300 | LONG_L t0, 0x3000(t0) |
| 301 | LONG_S t0, VCPU_R27(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 302 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 303 | /* Now that context has been saved, we can use other registers */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 304 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 305 | /* Restore vcpu */ |
| 306 | mfc0 a1, CP0_DDATA_LO |
| 307 | move s1, a1 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 308 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 309 | /* Restore run (vcpu->run) */ |
| 310 | LONG_L a0, VCPU_RUN(a1) |
| 311 | /* Save pointer to run in s0, will be saved by the compiler */ |
| 312 | move s0, a0 |
| 313 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 314 | /* |
| 315 | * Save Host level EPC, BadVaddr and Cause to VCPU, useful to |
| 316 | * process the exception |
| 317 | */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 318 | mfc0 k0,CP0_EPC |
| 319 | LONG_S k0, VCPU_PC(k1) |
| 320 | |
| 321 | mfc0 k0, CP0_BADVADDR |
| 322 | LONG_S k0, VCPU_HOST_CP0_BADVADDR(k1) |
| 323 | |
| 324 | mfc0 k0, CP0_CAUSE |
| 325 | LONG_S k0, VCPU_HOST_CP0_CAUSE(k1) |
| 326 | |
| 327 | mfc0 k0, CP0_ENTRYHI |
| 328 | LONG_S k0, VCPU_HOST_ENTRYHI(k1) |
| 329 | |
| 330 | /* Now restore the host state just enough to run the handlers */ |
| 331 | |
James Hogan | caa1faa | 2015-12-16 23:49:26 +0000 | [diff] [blame] | 332 | /* Switch EBASE to the one used by Linux */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 333 | /* load up the host EBASE */ |
| 334 | mfc0 v0, CP0_STATUS |
| 335 | |
| 336 | .set at |
| 337 | or k0, v0, ST0_BEV |
| 338 | .set noat |
| 339 | |
| 340 | mtc0 k0, CP0_STATUS |
| 341 | ehb |
| 342 | |
| 343 | LONG_L k0, VCPU_HOST_EBASE(k1) |
| 344 | mtc0 k0,CP0_EBASE |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 345 | |
James Hogan | 98e91b8 | 2014-11-18 14:09:12 +0000 | [diff] [blame] | 346 | /* |
| 347 | * If FPU is enabled, save FCR31 and clear it so that later ctc1's don't |
| 348 | * trigger FPE for pending exceptions. |
| 349 | */ |
| 350 | .set at |
| 351 | and v1, v0, ST0_CU1 |
| 352 | beqz v1, 1f |
| 353 | nop |
| 354 | .set push |
| 355 | SET_HARDFLOAT |
| 356 | cfc1 t0, fcr31 |
| 357 | sw t0, VCPU_FCR31(k1) |
| 358 | ctc1 zero,fcr31 |
| 359 | .set pop |
| 360 | .set noat |
| 361 | 1: |
| 362 | |
James Hogan | 539cb89fb | 2015-03-05 11:43:36 +0000 | [diff] [blame] | 363 | #ifdef CONFIG_CPU_HAS_MSA |
| 364 | /* |
| 365 | * If MSA is enabled, save MSACSR and clear it so that later |
| 366 | * instructions don't trigger MSAFPE for pending exceptions. |
| 367 | */ |
| 368 | mfc0 t0, CP0_CONFIG3 |
| 369 | ext t0, t0, 28, 1 /* MIPS_CONF3_MSAP */ |
| 370 | beqz t0, 1f |
| 371 | nop |
| 372 | mfc0 t0, CP0_CONFIG5 |
| 373 | ext t0, t0, 27, 1 /* MIPS_CONF5_MSAEN */ |
| 374 | beqz t0, 1f |
| 375 | nop |
| 376 | _cfcmsa t0, MSA_CSR |
| 377 | sw t0, VCPU_MSA_CSR(k1) |
| 378 | _ctcmsa MSA_CSR, zero |
| 379 | 1: |
| 380 | #endif |
| 381 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 382 | /* Now that the new EBASE has been loaded, unset BEV and KSU_USER */ |
| 383 | .set at |
| 384 | and v0, v0, ~(ST0_EXL | KSU_USER | ST0_IE) |
| 385 | or v0, v0, ST0_CU0 |
| 386 | .set noat |
| 387 | mtc0 v0, CP0_STATUS |
| 388 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 389 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 390 | /* Load up host GP */ |
| 391 | LONG_L gp, VCPU_HOST_GP(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 392 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 393 | /* Need a stack before we can jump to "C" */ |
| 394 | LONG_L sp, VCPU_HOST_STACK(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 395 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 396 | /* Saved host state */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 397 | INT_ADDIU sp, sp, -PT_SIZE |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 398 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 399 | /* |
| 400 | * XXXKYMA do we need to load the host ASID, maybe not because the |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 401 | * kernel entries are marked GLOBAL, need to verify |
| 402 | */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 403 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 404 | /* Restore host DDATA_LO */ |
| 405 | LONG_L k0, PT_HOST_USERLOCAL(sp) |
| 406 | mtc0 k0, CP0_DDATA_LO |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 407 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 408 | /* Restore RDHWR access */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 409 | PTR_LI k0, 0x2000000F |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 410 | mtc0 k0, CP0_HWRENA |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 411 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 412 | /* Jump to handler */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 413 | FEXPORT(__kvm_mips_jump_to_handler) |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 414 | /* |
| 415 | * XXXKYMA: not sure if this is safe, how large is the stack?? |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 416 | * Now jump to the kvm_mips_handle_exit() to see if we can deal |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 417 | * with this in the kernel |
| 418 | */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 419 | PTR_LA t9, kvm_mips_handle_exit |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 420 | jalr.hb t9 |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 421 | INT_ADDIU sp, sp, -CALLFRAME_SIZ /* BD Slot */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 422 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 423 | /* Return from handler Make sure interrupts are disabled */ |
| 424 | di |
| 425 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 426 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 427 | /* |
| 428 | * XXXKYMA: k0/k1 could have been blown away if we processed |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 429 | * an exception while we were handling the exception from the |
| 430 | * guest, reload k1 |
| 431 | */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 432 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 433 | move k1, s1 |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 434 | INT_ADDIU k1, k1, VCPU_HOST_ARCH |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 435 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 436 | /* |
| 437 | * Check return value, should tell us if we are returning to the |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 438 | * host (handle I/O etc)or resuming the guest |
| 439 | */ |
| 440 | andi t0, v0, RESUME_HOST |
| 441 | bnez t0, __kvm_mips_return_to_host |
| 442 | nop |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 443 | |
| 444 | __kvm_mips_return_to_guest: |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 445 | /* Put the saved pointer to vcpu (s1) back into the DDATA_LO Register */ |
| 446 | mtc0 s1, CP0_DDATA_LO |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 447 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 448 | /* Load up the Guest EBASE to minimize the window where BEV is set */ |
| 449 | LONG_L t0, VCPU_GUEST_EBASE(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 450 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 451 | /* Switch EBASE back to the one used by KVM */ |
| 452 | mfc0 v1, CP0_STATUS |
| 453 | .set at |
| 454 | or k0, v1, ST0_BEV |
| 455 | .set noat |
| 456 | mtc0 k0, CP0_STATUS |
| 457 | ehb |
| 458 | mtc0 t0, CP0_EBASE |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 459 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 460 | /* Setup status register for running guest in UM */ |
| 461 | .set at |
| 462 | or v1, v1, (ST0_EXL | KSU_USER | ST0_IE) |
James Hogan | f798217 | 2015-02-04 17:06:37 +0000 | [diff] [blame] | 463 | and v1, v1, ~(ST0_CU0 | ST0_MX) |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 464 | .set noat |
| 465 | mtc0 v1, CP0_STATUS |
| 466 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 467 | |
| 468 | /* Set Guest EPC */ |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 469 | LONG_L t0, VCPU_PC(k1) |
| 470 | mtc0 t0, CP0_EPC |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 471 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 472 | /* Set the ASID for the Guest Kernel */ |
James Hogan | 002374f | 2015-11-11 14:21:18 +0000 | [diff] [blame] | 473 | PTR_L t0, VCPU_COP0(k1) |
| 474 | LONG_L t0, COP0_STATUS(t0) |
| 475 | andi t0, KSU_USER | ST0_ERL | ST0_EXL |
| 476 | xori t0, KSU_USER |
| 477 | bnez t0, 1f /* If kernel */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 478 | INT_ADDIU t1, k1, VCPU_GUEST_KERNEL_ASID /* (BD) */ |
| 479 | INT_ADDIU t1, k1, VCPU_GUEST_USER_ASID /* else user */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 480 | 1: |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 481 | /* t1: contains the base of the ASID array, need to get the cpu id */ |
| 482 | LONG_L t2, TI_CPU($28) /* smp_processor_id */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 483 | INT_SLL t2, t2, 2 /* x4 */ |
| 484 | REG_ADDU t3, t1, t2 |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 485 | LONG_L k0, (t3) |
James Hogan | 9b5c339 | 2016-05-06 14:36:19 +0100 | [diff] [blame^] | 486 | andi k0, k0, MIPS_ENTRYHI_ASID |
James Hogan | caa1faa | 2015-12-16 23:49:26 +0000 | [diff] [blame] | 487 | mtc0 k0, CP0_ENTRYHI |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 488 | ehb |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 489 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 490 | /* Disable RDHWR access */ |
James Hogan | caa1faa | 2015-12-16 23:49:26 +0000 | [diff] [blame] | 491 | mtc0 zero, CP0_HWRENA |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 492 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 493 | /* load the guest context from VCPU and return */ |
| 494 | LONG_L $0, VCPU_R0(k1) |
| 495 | LONG_L $1, VCPU_R1(k1) |
| 496 | LONG_L $2, VCPU_R2(k1) |
| 497 | LONG_L $3, VCPU_R3(k1) |
| 498 | LONG_L $4, VCPU_R4(k1) |
| 499 | LONG_L $5, VCPU_R5(k1) |
| 500 | LONG_L $6, VCPU_R6(k1) |
| 501 | LONG_L $7, VCPU_R7(k1) |
| 502 | LONG_L $8, VCPU_R8(k1) |
| 503 | LONG_L $9, VCPU_R9(k1) |
| 504 | LONG_L $10, VCPU_R10(k1) |
| 505 | LONG_L $11, VCPU_R11(k1) |
| 506 | LONG_L $12, VCPU_R12(k1) |
| 507 | LONG_L $13, VCPU_R13(k1) |
| 508 | LONG_L $14, VCPU_R14(k1) |
| 509 | LONG_L $15, VCPU_R15(k1) |
| 510 | LONG_L $16, VCPU_R16(k1) |
| 511 | LONG_L $17, VCPU_R17(k1) |
| 512 | LONG_L $18, VCPU_R18(k1) |
| 513 | LONG_L $19, VCPU_R19(k1) |
| 514 | LONG_L $20, VCPU_R20(k1) |
| 515 | LONG_L $21, VCPU_R21(k1) |
| 516 | LONG_L $22, VCPU_R22(k1) |
| 517 | LONG_L $23, VCPU_R23(k1) |
| 518 | LONG_L $24, VCPU_R24(k1) |
| 519 | LONG_L $25, VCPU_R25(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 520 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 521 | /* $/k1 loaded later */ |
| 522 | LONG_L $28, VCPU_R28(k1) |
| 523 | LONG_L $29, VCPU_R29(k1) |
| 524 | LONG_L $30, VCPU_R30(k1) |
| 525 | LONG_L $31, VCPU_R31(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 526 | |
| 527 | FEXPORT(__kvm_mips_skip_guest_restore) |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 528 | LONG_L k0, VCPU_HI(k1) |
| 529 | mthi k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 530 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 531 | LONG_L k0, VCPU_LO(k1) |
| 532 | mtlo k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 533 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 534 | LONG_L k0, VCPU_R26(k1) |
| 535 | LONG_L k1, VCPU_R27(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 536 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 537 | eret |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 538 | |
| 539 | __kvm_mips_return_to_host: |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 540 | /* EBASE is already pointing to Linux */ |
| 541 | LONG_L k1, VCPU_HOST_STACK(k1) |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 542 | INT_ADDIU k1,k1, -PT_SIZE |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 543 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 544 | /* Restore host DDATA_LO */ |
| 545 | LONG_L k0, PT_HOST_USERLOCAL(k1) |
| 546 | mtc0 k0, CP0_DDATA_LO |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 547 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 548 | /* Load context saved on the host stack */ |
| 549 | LONG_L $0, PT_R0(k1) |
| 550 | LONG_L $1, PT_R1(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 551 | |
Deng-Cheng Zhu | d116e81 | 2014-06-26 12:11:34 -0700 | [diff] [blame] | 552 | /* |
| 553 | * r2/v0 is the return code, shift it down by 2 (arithmetic) |
| 554 | * to recover the err code |
| 555 | */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 556 | INT_SRA k0, v0, 2 |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 557 | move $2, k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 558 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 559 | LONG_L $3, PT_R3(k1) |
| 560 | LONG_L $4, PT_R4(k1) |
| 561 | LONG_L $5, PT_R5(k1) |
| 562 | LONG_L $6, PT_R6(k1) |
| 563 | LONG_L $7, PT_R7(k1) |
| 564 | LONG_L $8, PT_R8(k1) |
| 565 | LONG_L $9, PT_R9(k1) |
| 566 | LONG_L $10, PT_R10(k1) |
| 567 | LONG_L $11, PT_R11(k1) |
| 568 | LONG_L $12, PT_R12(k1) |
| 569 | LONG_L $13, PT_R13(k1) |
| 570 | LONG_L $14, PT_R14(k1) |
| 571 | LONG_L $15, PT_R15(k1) |
| 572 | LONG_L $16, PT_R16(k1) |
| 573 | LONG_L $17, PT_R17(k1) |
| 574 | LONG_L $18, PT_R18(k1) |
| 575 | LONG_L $19, PT_R19(k1) |
| 576 | LONG_L $20, PT_R20(k1) |
| 577 | LONG_L $21, PT_R21(k1) |
| 578 | LONG_L $22, PT_R22(k1) |
| 579 | LONG_L $23, PT_R23(k1) |
| 580 | LONG_L $24, PT_R24(k1) |
| 581 | LONG_L $25, PT_R25(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 582 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 583 | /* Host k0/k1 were not saved */ |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 584 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 585 | LONG_L $28, PT_R28(k1) |
| 586 | LONG_L $29, PT_R29(k1) |
| 587 | LONG_L $30, PT_R30(k1) |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 588 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 589 | LONG_L k0, PT_HI(k1) |
| 590 | mthi k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 591 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 592 | LONG_L k0, PT_LO(k1) |
| 593 | mtlo k0 |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 594 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 595 | /* Restore RDHWR access */ |
David Daney | ea69f28 | 2013-08-01 13:22:35 -0700 | [diff] [blame] | 596 | PTR_LI k0, 0x2000000F |
James Hogan | caa1faa | 2015-12-16 23:49:26 +0000 | [diff] [blame] | 597 | mtc0 k0, CP0_HWRENA |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 598 | |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 599 | /* Restore RA, which is the address we will return to */ |
James Hogan | caa1faa | 2015-12-16 23:49:26 +0000 | [diff] [blame] | 600 | LONG_L ra, PT_R31(k1) |
| 601 | j ra |
David Daney | 2c07ebb | 2013-08-01 13:22:33 -0700 | [diff] [blame] | 602 | nop |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 603 | |
Sanjay Lal | b680f70 | 2012-11-21 18:34:01 -0800 | [diff] [blame] | 604 | VECTOR_END(MIPSX(GuestExceptionEnd)) |
| 605 | .end MIPSX(GuestException) |
| 606 | |
| 607 | MIPSX(exceptions): |
| 608 | #### |
| 609 | ##### The exception handlers. |
| 610 | ##### |
| 611 | .word _C_LABEL(MIPSX(GuestException)) # 0 |
| 612 | .word _C_LABEL(MIPSX(GuestException)) # 1 |
| 613 | .word _C_LABEL(MIPSX(GuestException)) # 2 |
| 614 | .word _C_LABEL(MIPSX(GuestException)) # 3 |
| 615 | .word _C_LABEL(MIPSX(GuestException)) # 4 |
| 616 | .word _C_LABEL(MIPSX(GuestException)) # 5 |
| 617 | .word _C_LABEL(MIPSX(GuestException)) # 6 |
| 618 | .word _C_LABEL(MIPSX(GuestException)) # 7 |
| 619 | .word _C_LABEL(MIPSX(GuestException)) # 8 |
| 620 | .word _C_LABEL(MIPSX(GuestException)) # 9 |
| 621 | .word _C_LABEL(MIPSX(GuestException)) # 10 |
| 622 | .word _C_LABEL(MIPSX(GuestException)) # 11 |
| 623 | .word _C_LABEL(MIPSX(GuestException)) # 12 |
| 624 | .word _C_LABEL(MIPSX(GuestException)) # 13 |
| 625 | .word _C_LABEL(MIPSX(GuestException)) # 14 |
| 626 | .word _C_LABEL(MIPSX(GuestException)) # 15 |
| 627 | .word _C_LABEL(MIPSX(GuestException)) # 16 |
| 628 | .word _C_LABEL(MIPSX(GuestException)) # 17 |
| 629 | .word _C_LABEL(MIPSX(GuestException)) # 18 |
| 630 | .word _C_LABEL(MIPSX(GuestException)) # 19 |
| 631 | .word _C_LABEL(MIPSX(GuestException)) # 20 |
| 632 | .word _C_LABEL(MIPSX(GuestException)) # 21 |
| 633 | .word _C_LABEL(MIPSX(GuestException)) # 22 |
| 634 | .word _C_LABEL(MIPSX(GuestException)) # 23 |
| 635 | .word _C_LABEL(MIPSX(GuestException)) # 24 |
| 636 | .word _C_LABEL(MIPSX(GuestException)) # 25 |
| 637 | .word _C_LABEL(MIPSX(GuestException)) # 26 |
| 638 | .word _C_LABEL(MIPSX(GuestException)) # 27 |
| 639 | .word _C_LABEL(MIPSX(GuestException)) # 28 |
| 640 | .word _C_LABEL(MIPSX(GuestException)) # 29 |
| 641 | .word _C_LABEL(MIPSX(GuestException)) # 30 |
| 642 | .word _C_LABEL(MIPSX(GuestException)) # 31 |