^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) * Copyright IBM Corp. 2007
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5) * Copyright 2011 Freescale Semiconductor, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) * Authors: Hollis Blanchard <hollisb@us.ibm.com>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <asm/ppc_asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <asm/kvm_asm.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12) #include <asm/reg.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #include <asm/page.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14) #include <asm/asm-offsets.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) /* The host stack layout: */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) #define HOST_R1 0 /* Implied by stwu. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18) #define HOST_CALLEE_LR 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) #define HOST_RUN 8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) /* r2 is special: it holds 'current', and it made nonvolatile in the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) * kernel with the -ffixed-r2 gcc option. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) #define HOST_R2 12
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) #define HOST_CR 16
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24) #define HOST_NV_GPRS 20
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) #define __HOST_NV_GPR(n) (HOST_NV_GPRS + ((n - 14) * 4))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) #define HOST_NV_GPR(n) __HOST_NV_GPR(__REG_##n)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) #define HOST_MIN_STACK_SIZE (HOST_NV_GPR(R31) + 4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) #define HOST_STACK_SIZE (((HOST_MIN_STACK_SIZE + 15) / 16) * 16) /* Align. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29) #define HOST_STACK_LR (HOST_STACK_SIZE + 4) /* In caller stack frame. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) #define NEED_INST_MASK ((1<<BOOKE_INTERRUPT_PROGRAM) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) (1<<BOOKE_INTERRUPT_DEBUG))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) #define NEED_DEAR_MASK ((1<<BOOKE_INTERRUPT_DATA_STORAGE) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36) (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) (1<<BOOKE_INTERRUPT_ALIGNMENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) #define NEED_ESR_MASK ((1<<BOOKE_INTERRUPT_DATA_STORAGE) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) (1<<BOOKE_INTERRUPT_INST_STORAGE) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) (1<<BOOKE_INTERRUPT_PROGRAM) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) (1<<BOOKE_INTERRUPT_DTLB_MISS) | \
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) (1<<BOOKE_INTERRUPT_ALIGNMENT))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) .macro __KVM_HANDLER ivor_nr scratch srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 46) /* Get pointer to vcpu and record exit number. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 47) mtspr \scratch , r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 48) mfspr r4, SPRN_SPRG_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 49) lwz r4, THREAD_KVM_VCPU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 50) stw r3, VCPU_GPR(R3)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 51) stw r5, VCPU_GPR(R5)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 52) stw r6, VCPU_GPR(R6)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 53) mfspr r3, \scratch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 54) mfctr r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 55) stw r3, VCPU_GPR(R4)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 56) stw r5, VCPU_CTR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 57) mfspr r3, \srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 58) lis r6, kvmppc_resume_host@h
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 59) stw r3, VCPU_PC(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 60) li r5, \ivor_nr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 61) ori r6, r6, kvmppc_resume_host@l
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 62) mtctr r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 63) bctr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 64) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 65)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 66) .macro KVM_HANDLER ivor_nr scratch srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 67) _GLOBAL(kvmppc_handler_\ivor_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 68) __KVM_HANDLER \ivor_nr \scratch \srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 69) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 70)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 71) .macro KVM_DBG_HANDLER ivor_nr scratch srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 72) _GLOBAL(kvmppc_handler_\ivor_nr)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 73) mtspr \scratch, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 74) mfspr r4, SPRN_SPRG_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 75) lwz r4, THREAD_KVM_VCPU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 76) stw r3, VCPU_CRIT_SAVE(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 77) mfcr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 78) mfspr r4, SPRN_CSRR1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 79) andi. r4, r4, MSR_PR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 80) bne 1f
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 81) /* debug interrupt happened in enter/exit path */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 82) mfspr r4, SPRN_CSRR1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 83) rlwinm r4, r4, 0, ~MSR_DE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 84) mtspr SPRN_CSRR1, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 85) lis r4, 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 86) ori r4, r4, 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 87) mtspr SPRN_DBSR, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 88) mfspr r4, SPRN_SPRG_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 89) lwz r4, THREAD_KVM_VCPU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 90) mtcr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 91) lwz r3, VCPU_CRIT_SAVE(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 92) mfspr r4, \scratch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 93) rfci
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 94) 1: /* debug interrupt happened in guest */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 95) mtcr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 96) mfspr r4, SPRN_SPRG_THREAD
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 97) lwz r4, THREAD_KVM_VCPU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 98) lwz r3, VCPU_CRIT_SAVE(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 99) mfspr r4, \scratch
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100) __KVM_HANDLER \ivor_nr \scratch \srr0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) .macro KVM_HANDLER_ADDR ivor_nr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) .long kvmppc_handler_\ivor_nr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) .macro KVM_HANDLER_END
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) .long kvmppc_handlers_end
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) .endm
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) _GLOBAL(kvmppc_handlers_start)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) KVM_HANDLER BOOKE_INTERRUPT_CRITICAL SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) KVM_HANDLER BOOKE_INTERRUPT_MACHINE_CHECK SPRN_SPRG_RSCRATCH_MC SPRN_MCSRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) KVM_HANDLER BOOKE_INTERRUPT_DATA_STORAGE SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) KVM_HANDLER BOOKE_INTERRUPT_INST_STORAGE SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) KVM_HANDLER BOOKE_INTERRUPT_EXTERNAL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) KVM_HANDLER BOOKE_INTERRUPT_ALIGNMENT SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) KVM_HANDLER BOOKE_INTERRUPT_PROGRAM SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) KVM_HANDLER BOOKE_INTERRUPT_FP_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) KVM_HANDLER BOOKE_INTERRUPT_SYSCALL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) KVM_HANDLER BOOKE_INTERRUPT_AP_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) KVM_HANDLER BOOKE_INTERRUPT_DECREMENTER SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) KVM_HANDLER BOOKE_INTERRUPT_FIT SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) KVM_HANDLER BOOKE_INTERRUPT_WATCHDOG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) KVM_HANDLER BOOKE_INTERRUPT_DTLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) KVM_HANDLER BOOKE_INTERRUPT_ITLB_MISS SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) KVM_DBG_HANDLER BOOKE_INTERRUPT_DEBUG SPRN_SPRG_RSCRATCH_CRIT SPRN_CSRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) KVM_HANDLER BOOKE_INTERRUPT_SPE_UNAVAIL SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_DATA SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) KVM_HANDLER BOOKE_INTERRUPT_SPE_FP_ROUND SPRN_SPRG_RSCRATCH0 SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) _GLOBAL(kvmppc_handlers_end)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) /* Registers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) * SPRG_SCRATCH0: guest r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) * r4: vcpu pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) * r5: KVM exit number
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) _GLOBAL(kvmppc_resume_host)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) mfcr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) stw r3, VCPU_CR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) stw r7, VCPU_GPR(R7)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) stw r8, VCPU_GPR(R8)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) stw r9, VCPU_GPR(R9)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) li r6, 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) slw r6, r6, r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) #ifdef CONFIG_KVM_EXIT_TIMING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) /* save exit time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) mfspr r7, SPRN_TBRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152) mfspr r8, SPRN_TBRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153) mfspr r9, SPRN_TBRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154) cmpw r9, r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155) bne 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156) stw r8, VCPU_TIMING_EXIT_TBL(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157) stw r9, VCPU_TIMING_EXIT_TBU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) /* Save the faulting instruction and all GPRs for emulation. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) andi. r7, r6, NEED_INST_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) beq ..skip_inst_copy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) mfspr r9, SPRN_SRR0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) mfmsr r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) ori r7, r8, MSR_DS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) mtmsr r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) isync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) lwz r9, 0(r9)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) mtmsr r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) isync
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) stw r9, VCPU_LAST_INST(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) stw r15, VCPU_GPR(R15)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) stw r16, VCPU_GPR(R16)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) stw r17, VCPU_GPR(R17)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) stw r18, VCPU_GPR(R18)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) stw r19, VCPU_GPR(R19)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) stw r20, VCPU_GPR(R20)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179) stw r21, VCPU_GPR(R21)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180) stw r22, VCPU_GPR(R22)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181) stw r23, VCPU_GPR(R23)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182) stw r24, VCPU_GPR(R24)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183) stw r25, VCPU_GPR(R25)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) stw r26, VCPU_GPR(R26)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) stw r27, VCPU_GPR(R27)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) stw r28, VCPU_GPR(R28)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) stw r29, VCPU_GPR(R29)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) stw r30, VCPU_GPR(R30)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) stw r31, VCPU_GPR(R31)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) ..skip_inst_copy:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) /* Also grab DEAR and ESR before the host can clobber them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) andi. r7, r6, NEED_DEAR_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) beq ..skip_dear
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) mfspr r9, SPRN_DEAR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) stw r9, VCPU_FAULT_DEAR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198) ..skip_dear:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200) andi. r7, r6, NEED_ESR_MASK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201) beq ..skip_esr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202) mfspr r9, SPRN_ESR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203) stw r9, VCPU_FAULT_ESR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204) ..skip_esr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) /* Save remaining volatile guest register state to vcpu. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) stw r0, VCPU_GPR(R0)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) stw r1, VCPU_GPR(R1)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) stw r2, VCPU_GPR(R2)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) stw r10, VCPU_GPR(R10)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) stw r11, VCPU_GPR(R11)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) stw r12, VCPU_GPR(R12)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) stw r13, VCPU_GPR(R13)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) stw r14, VCPU_GPR(R14)(r4) /* We need a NV GPR below. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) mflr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) stw r3, VCPU_LR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) mfxer r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) stw r3, VCPU_XER(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) /* Restore host stack pointer and PID before IVPR, since the host
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) * exception handlers use them. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) lwz r1, VCPU_HOST_STACK(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) lwz r3, VCPU_HOST_PID(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) mtspr SPRN_PID, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) #ifdef CONFIG_FSL_BOOKE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /* we cheat and know that Linux doesn't use PID1 which is always 0 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228) lis r3, 0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229) mtspr SPRN_PID1, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232) /* Restore host IVPR before re-enabling interrupts. We cheat and know
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233) * that Linux IVPR is always 0xc0000000. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) lis r3, 0xc000
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) mtspr SPRN_IVPR, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) /* Switch to kernel stack and jump to handler. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) LOAD_REG_ADDR(r3, kvmppc_handle_exit)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) mtctr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) mr r3, r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) lwz r2, HOST_R2(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) mr r14, r4 /* Save vcpu pointer. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) bctrl /* kvmppc_handle_exit() */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) /* Restore vcpu pointer and the nonvolatiles we used. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) mr r4, r14
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) lwz r14, VCPU_GPR(R14)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250) /* Sometimes instruction emulation must restore complete GPR state. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251) andi. r5, r3, RESUME_FLAG_NV
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252) beq ..skip_nv_load
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253) lwz r15, VCPU_GPR(R15)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254) lwz r16, VCPU_GPR(R16)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255) lwz r17, VCPU_GPR(R17)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256) lwz r18, VCPU_GPR(R18)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) lwz r19, VCPU_GPR(R19)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) lwz r20, VCPU_GPR(R20)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) lwz r21, VCPU_GPR(R21)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) lwz r22, VCPU_GPR(R22)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) lwz r23, VCPU_GPR(R23)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) lwz r24, VCPU_GPR(R24)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) lwz r25, VCPU_GPR(R25)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) lwz r26, VCPU_GPR(R26)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) lwz r27, VCPU_GPR(R27)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) lwz r28, VCPU_GPR(R28)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) lwz r29, VCPU_GPR(R29)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) lwz r30, VCPU_GPR(R30)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) lwz r31, VCPU_GPR(R31)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) ..skip_nv_load:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) /* Should we return to the guest? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) andi. r5, r3, RESUME_FLAG_HOST
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) beq lightweight_exit
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) srawi r3, r3, 2 /* Shift -ERR back down. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278) heavyweight_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279) /* Not returning to guest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281) #ifdef CONFIG_SPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282) /* save guest SPEFSCR and load host SPEFSCR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) mfspr r9, SPRN_SPEFSCR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) stw r9, VCPU_SPEFSCR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) lwz r9, VCPU_HOST_SPEFSCR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) mtspr SPRN_SPEFSCR, r9
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) /* We already saved guest volatile register state; now save the
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) * non-volatiles. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) stw r15, VCPU_GPR(R15)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) stw r16, VCPU_GPR(R16)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) stw r17, VCPU_GPR(R17)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) stw r18, VCPU_GPR(R18)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) stw r19, VCPU_GPR(R19)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) stw r20, VCPU_GPR(R20)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) stw r21, VCPU_GPR(R21)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) stw r22, VCPU_GPR(R22)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) stw r23, VCPU_GPR(R23)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) stw r24, VCPU_GPR(R24)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) stw r25, VCPU_GPR(R25)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) stw r26, VCPU_GPR(R26)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) stw r27, VCPU_GPR(R27)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) stw r28, VCPU_GPR(R28)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) stw r29, VCPU_GPR(R29)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) stw r30, VCPU_GPR(R30)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) stw r31, VCPU_GPR(R31)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) /* Load host non-volatile register state from host stack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) lwz r14, HOST_NV_GPR(R14)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) lwz r15, HOST_NV_GPR(R15)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) lwz r16, HOST_NV_GPR(R16)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) lwz r17, HOST_NV_GPR(R17)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) lwz r18, HOST_NV_GPR(R18)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) lwz r19, HOST_NV_GPR(R19)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 316) lwz r20, HOST_NV_GPR(R20)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 317) lwz r21, HOST_NV_GPR(R21)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 318) lwz r22, HOST_NV_GPR(R22)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 319) lwz r23, HOST_NV_GPR(R23)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 320) lwz r24, HOST_NV_GPR(R24)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 321) lwz r25, HOST_NV_GPR(R25)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 322) lwz r26, HOST_NV_GPR(R26)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 323) lwz r27, HOST_NV_GPR(R27)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 324) lwz r28, HOST_NV_GPR(R28)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 325) lwz r29, HOST_NV_GPR(R29)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 326) lwz r30, HOST_NV_GPR(R30)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 327) lwz r31, HOST_NV_GPR(R31)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 328)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 329) /* Return to kvm_vcpu_run(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 330) lwz r4, HOST_STACK_LR(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 331) lwz r5, HOST_CR(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 332) addi r1, r1, HOST_STACK_SIZE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 333) mtlr r4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 334) mtcr r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 335) /* r3 still contains the return code from kvmppc_handle_exit(). */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 336) blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 337)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 338)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 339) /* Registers:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 340) * r3: vcpu pointer
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 341) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 342) _GLOBAL(__kvmppc_vcpu_run)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 343) stwu r1, -HOST_STACK_SIZE(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 344) stw r1, VCPU_HOST_STACK(r3) /* Save stack pointer to vcpu. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 345)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 346) /* Save host state to stack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 347) mr r4, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 348) mflr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 349) stw r3, HOST_STACK_LR(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 350) mfcr r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 351) stw r5, HOST_CR(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 352)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 353) /* Save host non-volatile register state to stack. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 354) stw r14, HOST_NV_GPR(R14)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 355) stw r15, HOST_NV_GPR(R15)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 356) stw r16, HOST_NV_GPR(R16)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 357) stw r17, HOST_NV_GPR(R17)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 358) stw r18, HOST_NV_GPR(R18)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 359) stw r19, HOST_NV_GPR(R19)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 360) stw r20, HOST_NV_GPR(R20)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 361) stw r21, HOST_NV_GPR(R21)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 362) stw r22, HOST_NV_GPR(R22)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 363) stw r23, HOST_NV_GPR(R23)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 364) stw r24, HOST_NV_GPR(R24)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 365) stw r25, HOST_NV_GPR(R25)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 366) stw r26, HOST_NV_GPR(R26)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 367) stw r27, HOST_NV_GPR(R27)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 368) stw r28, HOST_NV_GPR(R28)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 369) stw r29, HOST_NV_GPR(R29)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 370) stw r30, HOST_NV_GPR(R30)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 371) stw r31, HOST_NV_GPR(R31)(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 372)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 373) /* Load guest non-volatiles. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 374) lwz r14, VCPU_GPR(R14)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 375) lwz r15, VCPU_GPR(R15)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 376) lwz r16, VCPU_GPR(R16)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 377) lwz r17, VCPU_GPR(R17)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 378) lwz r18, VCPU_GPR(R18)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 379) lwz r19, VCPU_GPR(R19)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 380) lwz r20, VCPU_GPR(R20)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 381) lwz r21, VCPU_GPR(R21)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 382) lwz r22, VCPU_GPR(R22)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 383) lwz r23, VCPU_GPR(R23)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 384) lwz r24, VCPU_GPR(R24)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 385) lwz r25, VCPU_GPR(R25)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 386) lwz r26, VCPU_GPR(R26)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 387) lwz r27, VCPU_GPR(R27)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 388) lwz r28, VCPU_GPR(R28)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 389) lwz r29, VCPU_GPR(R29)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 390) lwz r30, VCPU_GPR(R30)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 391) lwz r31, VCPU_GPR(R31)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 392)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 393) #ifdef CONFIG_SPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 394) /* save host SPEFSCR and load guest SPEFSCR */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 395) mfspr r3, SPRN_SPEFSCR
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 396) stw r3, VCPU_HOST_SPEFSCR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 397) lwz r3, VCPU_SPEFSCR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 398) mtspr SPRN_SPEFSCR, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 399) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 400)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 401) lightweight_exit:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 402) stw r2, HOST_R2(r1)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 403)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 404) mfspr r3, SPRN_PID
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 405) stw r3, VCPU_HOST_PID(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 406) lwz r3, VCPU_SHADOW_PID(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 407) mtspr SPRN_PID, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 408)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 409) #ifdef CONFIG_FSL_BOOKE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 410) lwz r3, VCPU_SHADOW_PID1(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 411) mtspr SPRN_PID1, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 412) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 413)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 414) /* Load some guest volatiles. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 415) lwz r0, VCPU_GPR(R0)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 416) lwz r2, VCPU_GPR(R2)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 417) lwz r9, VCPU_GPR(R9)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 418) lwz r10, VCPU_GPR(R10)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 419) lwz r11, VCPU_GPR(R11)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 420) lwz r12, VCPU_GPR(R12)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 421) lwz r13, VCPU_GPR(R13)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 422) lwz r3, VCPU_LR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 423) mtlr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 424) lwz r3, VCPU_XER(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 425) mtxer r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 426)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 427) /* Switch the IVPR. XXX If we take a TLB miss after this we're screwed,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 428) * so how do we make sure vcpu won't fault? */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 429) lis r8, kvmppc_booke_handlers@ha
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 430) lwz r8, kvmppc_booke_handlers@l(r8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 431) mtspr SPRN_IVPR, r8
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 432)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 433) lwz r5, VCPU_SHARED(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 434)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 435) /* Can't switch the stack pointer until after IVPR is switched,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 436) * because host interrupt handlers would get confused. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 437) lwz r1, VCPU_GPR(R1)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 438)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 439) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 440) * Host interrupt handlers may have clobbered these
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 441) * guest-readable SPRGs, or the guest kernel may have
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 442) * written directly to the shared area, so we
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 443) * need to reload them here with the guest's values.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 444) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 445) PPC_LD(r3, VCPU_SHARED_SPRG4, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 446) mtspr SPRN_SPRG4W, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 447) PPC_LD(r3, VCPU_SHARED_SPRG5, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 448) mtspr SPRN_SPRG5W, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 449) PPC_LD(r3, VCPU_SHARED_SPRG6, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 450) mtspr SPRN_SPRG6W, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 451) PPC_LD(r3, VCPU_SHARED_SPRG7, r5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 452) mtspr SPRN_SPRG7W, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 453)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 454) #ifdef CONFIG_KVM_EXIT_TIMING
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 455) /* save enter time */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 456) 1:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 457) mfspr r6, SPRN_TBRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 458) mfspr r7, SPRN_TBRL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 459) mfspr r8, SPRN_TBRU
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 460) cmpw r8, r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 461) bne 1b
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 462) stw r7, VCPU_TIMING_LAST_ENTER_TBL(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 463) stw r8, VCPU_TIMING_LAST_ENTER_TBU(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 464) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 465)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 466) /* Finish loading guest volatiles and jump to guest. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 467) lwz r3, VCPU_CTR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 468) lwz r5, VCPU_CR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 469) lwz r6, VCPU_PC(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 470) lwz r7, VCPU_SHADOW_MSR(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 471) mtctr r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 472) mtcr r5
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 473) mtsrr0 r6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 474) mtsrr1 r7
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 475) lwz r5, VCPU_GPR(R5)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 476) lwz r6, VCPU_GPR(R6)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 477) lwz r7, VCPU_GPR(R7)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 478) lwz r8, VCPU_GPR(R8)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 479)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 480) /* Clear any debug events which occurred since we disabled MSR[DE].
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 481) * XXX This gives us a 3-instruction window in which a breakpoint
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 482) * intended for guest context could fire in the host instead. */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 483) lis r3, 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 484) ori r3, r3, 0xffff
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 485) mtspr SPRN_DBSR, r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 486)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 487) lwz r3, VCPU_GPR(R3)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 488) lwz r4, VCPU_GPR(R4)(r4)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 489) rfi
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 490)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 491) .data
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 492) .align 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 493) .globl kvmppc_booke_handler_addr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 494) kvmppc_booke_handler_addr:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 495) KVM_HANDLER_ADDR BOOKE_INTERRUPT_CRITICAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 496) KVM_HANDLER_ADDR BOOKE_INTERRUPT_MACHINE_CHECK
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 497) KVM_HANDLER_ADDR BOOKE_INTERRUPT_DATA_STORAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 498) KVM_HANDLER_ADDR BOOKE_INTERRUPT_INST_STORAGE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 499) KVM_HANDLER_ADDR BOOKE_INTERRUPT_EXTERNAL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 500) KVM_HANDLER_ADDR BOOKE_INTERRUPT_ALIGNMENT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 501) KVM_HANDLER_ADDR BOOKE_INTERRUPT_PROGRAM
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 502) KVM_HANDLER_ADDR BOOKE_INTERRUPT_FP_UNAVAIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 503) KVM_HANDLER_ADDR BOOKE_INTERRUPT_SYSCALL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 504) KVM_HANDLER_ADDR BOOKE_INTERRUPT_AP_UNAVAIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 505) KVM_HANDLER_ADDR BOOKE_INTERRUPT_DECREMENTER
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 506) KVM_HANDLER_ADDR BOOKE_INTERRUPT_FIT
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 507) KVM_HANDLER_ADDR BOOKE_INTERRUPT_WATCHDOG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 508) KVM_HANDLER_ADDR BOOKE_INTERRUPT_DTLB_MISS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 509) KVM_HANDLER_ADDR BOOKE_INTERRUPT_ITLB_MISS
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 510) KVM_HANDLER_ADDR BOOKE_INTERRUPT_DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 511) KVM_HANDLER_ADDR BOOKE_INTERRUPT_SPE_UNAVAIL
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 512) KVM_HANDLER_ADDR BOOKE_INTERRUPT_SPE_FP_DATA
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 513) KVM_HANDLER_ADDR BOOKE_INTERRUPT_SPE_FP_ROUND
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 514) KVM_HANDLER_END /*Always keep this in end*/
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 515)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 516) #ifdef CONFIG_SPE
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 517) _GLOBAL(kvmppc_save_guest_spe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 518) cmpi 0,r3,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 519) beqlr-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 520) SAVE_32EVRS(0, r4, r3, VCPU_EVR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 521) evxor evr6, evr6, evr6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 522) evmwumiaa evr6, evr6, evr6
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 523) li r4,VCPU_ACC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 524) evstddx evr6, r4, r3 /* save acc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 525) blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 526)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 527) _GLOBAL(kvmppc_load_guest_spe)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 528) cmpi 0,r3,0
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 529) beqlr-
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 530) li r4,VCPU_ACC
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 531) evlddx evr6,r4,r3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 532) evmra evr6,evr6 /* load acc */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 533) REST_32EVRS(0, r4, r3, VCPU_EVR)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 534) blr
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 535) #endif