/*1* This program is free software; you can redistribute it and/or modify2* it under the terms of the GNU General Public License, version 2, as3* published by the Free Software Foundation.4*5* This program is distributed in the hope that it will be useful,6* but WITHOUT ANY WARRANTY; without even the implied warranty of7* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the8* GNU General Public License for more details.9*10* You should have received a copy of the GNU General Public License11* along with this program; if not, write to the Free Software12* Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.13*14* Copyright SUSE Linux Products GmbH 200915*16* Authors: Alexander Graf <[email protected]>17*/1819/******************************************************************************20* *21* Entry code *22* *23*****************************************************************************/2425.macro LOAD_GUEST_SEGMENTS2627/* Required state:28*29* MSR = ~IR|DR30* R1 = host R131* R2 = host R232* R3 = shadow vcpu33* all other volatile GPRS = free34* SVCPU[CR] = guest CR35* SVCPU[XER] = guest XER36* SVCPU[CTR] = guest CTR37* SVCPU[LR] = guest LR38*/3940#define XCHG_SR(n) lwz r9, (SVCPU_SR+(n*4))(r3); \41mtsr n, r94243XCHG_SR(0)44XCHG_SR(1)45XCHG_SR(2)46XCHG_SR(3)47XCHG_SR(4)48XCHG_SR(5)49XCHG_SR(6)50XCHG_SR(7)51XCHG_SR(8)52XCHG_SR(9)53XCHG_SR(10)54XCHG_SR(11)55XCHG_SR(12)56XCHG_SR(13)57XCHG_SR(14)58XCHG_SR(15)5960/* Clear BATs. */6162#define KVM_KILL_BAT(n, reg) \63mtspr SPRN_IBAT##n##U,reg; \64mtspr SPRN_IBAT##n##L,reg; \65mtspr SPRN_DBAT##n##U,reg; \66mtspr SPRN_DBAT##n##L,reg; \6768li r9, 069KVM_KILL_BAT(0, r9)70KVM_KILL_BAT(1, r9)71KVM_KILL_BAT(2, r9)72KVM_KILL_BAT(3, r9)7374.endm7576/******************************************************************************77* *78* Exit code *79* *80*****************************************************************************/8182.macro LOAD_HOST_SEGMENTS8384/* Register usage at this point:85*86* R1 = host R187* R2 = host R288* R12 = exit handler id89* R13 = shadow vcpu - SHADOW_VCPU_OFF90* SVCPU.* = guest *91* SVCPU[CR] = guest CR92* SVCPU[XER] = guest XER93* SVCPU[CTR] = guest CTR94* SVCPU[LR] = guest LR95*96*/9798/* Restore BATs */99100/* We only overwrite the upper part, so we only restoree101the upper part. */102#define KVM_LOAD_BAT(n, reg, RA, RB) \103lwz RA,(n*16)+0(reg); \104lwz RB,(n*16)+4(reg); \105mtspr SPRN_IBAT##n##U,RA; \106mtspr SPRN_IBAT##n##L,RB; \107lwz RA,(n*16)+8(reg); \108lwz RB,(n*16)+12(reg); \109mtspr SPRN_DBAT##n##U,RA; \110mtspr SPRN_DBAT##n##L,RB; \111112lis r9, BATS@ha113addi r9, r9, BATS@l114tophys(r9, r9)115KVM_LOAD_BAT(0, r9, r10, r11)116KVM_LOAD_BAT(1, r9, r10, r11)117KVM_LOAD_BAT(2, r9, r10, r11)118KVM_LOAD_BAT(3, r9, r10, r11)119120/* Restore Segment Registers */121122/* 0xc - 0xf */123124li r0, 4125mtctr r0126LOAD_REG_IMMEDIATE(r3, 0x20000000 | (0x111 * 0xc))127lis r4, 0xc0001283: mtsrin r3, r4129addi r3, r3, 0x111 /* increment VSID */130addis r4, r4, 0x1000 /* address of next segment */131bdnz 3b132133/* 0x0 - 0xb */134135/* 'current->mm' needs to be in r4 */136tophys(r4, r2)137lwz r4, MM(r4)138tophys(r4, r4)139/* This only clobbers r0, r3, r4 and r5 */140bl switch_mmu_context141142.endm143144145