Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This program is free software; you can redistribute it and/or modify |
| 3 | * it under the terms of the GNU General Public License, version 2, as |
| 4 | * published by the Free Software Foundation. |
| 5 | * |
| 6 | * This program is distributed in the hope that it will be useful, |
| 7 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 8 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 9 | * GNU General Public License for more details. |
| 10 | * |
| 11 | * You should have received a copy of the GNU General Public License |
| 12 | * along with this program; if not, write to the Free Software |
| 13 | * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 14 | * |
| 15 | * Copyright SUSE Linux Products GmbH 2009 |
| 16 | * |
| 17 | * Authors: Alexander Graf <agraf@suse.de> |
| 18 | */ |
| 19 | |
| 20 | #include <asm/ppc_asm.h> |
| 21 | #include <asm/kvm_asm.h> |
| 22 | #include <asm/reg.h> |
| 23 | #include <asm/page.h> |
| 24 | #include <asm/asm-offsets.h> |
| 25 | #include <asm/exception-64s.h> |
| 26 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 27 | #if defined(CONFIG_PPC_BOOK3S_64) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 28 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 29 | #define ULONG_SIZE 8 |
| 30 | #define FUNC(name) GLUE(.,name) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 31 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 32 | #elif defined(CONFIG_PPC_BOOK3S_32) |
| 33 | |
| 34 | #define ULONG_SIZE 4 |
| 35 | #define FUNC(name) name |
| 36 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 37 | #endif /* CONFIG_PPC_BOOK3S_XX */ |
| 38 | |
| 39 | |
| 40 | #define VCPU_GPR(n) (VCPU_GPRS + (n * ULONG_SIZE)) |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 41 | #define VCPU_LOAD_NVGPRS(vcpu) \ |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 42 | PPC_LL r14, VCPU_GPR(r14)(vcpu); \ |
| 43 | PPC_LL r15, VCPU_GPR(r15)(vcpu); \ |
| 44 | PPC_LL r16, VCPU_GPR(r16)(vcpu); \ |
| 45 | PPC_LL r17, VCPU_GPR(r17)(vcpu); \ |
| 46 | PPC_LL r18, VCPU_GPR(r18)(vcpu); \ |
| 47 | PPC_LL r19, VCPU_GPR(r19)(vcpu); \ |
| 48 | PPC_LL r20, VCPU_GPR(r20)(vcpu); \ |
| 49 | PPC_LL r21, VCPU_GPR(r21)(vcpu); \ |
| 50 | PPC_LL r22, VCPU_GPR(r22)(vcpu); \ |
| 51 | PPC_LL r23, VCPU_GPR(r23)(vcpu); \ |
| 52 | PPC_LL r24, VCPU_GPR(r24)(vcpu); \ |
| 53 | PPC_LL r25, VCPU_GPR(r25)(vcpu); \ |
| 54 | PPC_LL r26, VCPU_GPR(r26)(vcpu); \ |
| 55 | PPC_LL r27, VCPU_GPR(r27)(vcpu); \ |
| 56 | PPC_LL r28, VCPU_GPR(r28)(vcpu); \ |
| 57 | PPC_LL r29, VCPU_GPR(r29)(vcpu); \ |
| 58 | PPC_LL r30, VCPU_GPR(r30)(vcpu); \ |
| 59 | PPC_LL r31, VCPU_GPR(r31)(vcpu); \ |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 60 | |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 61 | /***************************************************************************** |
| 62 | * * |
| 63 | * Guest entry / exit code that is in kernel module memory (highmem) * |
| 64 | * * |
| 65 | ****************************************************************************/ |
| 66 | |
| 67 | /* Registers: |
| 68 | * r3: kvm_run pointer |
| 69 | * r4: vcpu pointer |
| 70 | */ |
Paul Mackerras | df6909e5 | 2011-06-29 00:19:50 +0000 | [diff] [blame] | 71 | _GLOBAL(__kvmppc_vcpu_run) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 72 | |
| 73 | kvm_start_entry: |
| 74 | /* Write correct stack frame */ |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 75 | mflr r0 |
| 76 | PPC_STL r0,PPC_LR_STKOFF(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 77 | |
| 78 | /* Save host state to the stack */ |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 79 | PPC_STLU r1, -SWITCH_FRAME_SIZE(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 80 | |
| 81 | /* Save r3 (kvm_run) and r4 (vcpu) */ |
| 82 | SAVE_2GPRS(3, r1) |
| 83 | |
| 84 | /* Save non-volatile registers (r14 - r31) */ |
| 85 | SAVE_NVGPRS(r1) |
| 86 | |
Alexander Graf | e1f8acf | 2012-03-05 16:00:28 +0100 | [diff] [blame] | 87 | /* Save CR */ |
| 88 | mfcr r14 |
| 89 | stw r14, _CCR(r1) |
| 90 | |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 91 | /* Save LR */ |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 92 | PPC_STL r0, _LINK(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 93 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 94 | /* Load non-volatile guest state from the vcpu */ |
| 95 | VCPU_LOAD_NVGPRS(r4) |
| 96 | |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 97 | kvm_start_lightweight: |
| 98 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 99 | #ifdef CONFIG_PPC_BOOK3S_64 |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 100 | PPC_LL r3, VCPU_HFLAGS(r4) |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 101 | rldicl r3, r3, 0, 63 /* r3 &= 1 */ |
| 102 | stb r3, HSTATE_RESTORE_HID5(r13) |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 103 | #endif /* CONFIG_PPC_BOOK3S_64 */ |
| 104 | |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 105 | PPC_LL r4, VCPU_SHADOW_MSR(r4) /* get shadow_msr */ |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 106 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 107 | /* Jump to segment patching handler and into our guest */ |
Paul Mackerras | 0214394 | 2011-07-23 17:41:44 +1000 | [diff] [blame] | 108 | bl FUNC(kvmppc_entry_trampoline) |
| 109 | nop |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 110 | |
| 111 | /* |
| 112 | * This is the handler in module memory. It gets jumped at from the |
| 113 | * lowmem trampoline code, so it's basically the guest exit code. |
| 114 | * |
| 115 | */ |
| 116 | |
| 117 | .global kvmppc_handler_highmem |
| 118 | kvmppc_handler_highmem: |
| 119 | |
| 120 | /* |
| 121 | * Register usage at this point: |
| 122 | * |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 123 | * R1 = host R1 |
| 124 | * R2 = host R2 |
| 125 | * R12 = exit handler id |
| 126 | * R13 = PACA |
| 127 | * SVCPU.* = guest * |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 128 | * |
| 129 | */ |
| 130 | |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 131 | /* R7 = vcpu */ |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 132 | PPC_LL r7, GPR4(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 133 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 134 | PPC_STL r14, VCPU_GPR(r14)(r7) |
| 135 | PPC_STL r15, VCPU_GPR(r15)(r7) |
| 136 | PPC_STL r16, VCPU_GPR(r16)(r7) |
| 137 | PPC_STL r17, VCPU_GPR(r17)(r7) |
| 138 | PPC_STL r18, VCPU_GPR(r18)(r7) |
| 139 | PPC_STL r19, VCPU_GPR(r19)(r7) |
| 140 | PPC_STL r20, VCPU_GPR(r20)(r7) |
| 141 | PPC_STL r21, VCPU_GPR(r21)(r7) |
| 142 | PPC_STL r22, VCPU_GPR(r22)(r7) |
| 143 | PPC_STL r23, VCPU_GPR(r23)(r7) |
| 144 | PPC_STL r24, VCPU_GPR(r24)(r7) |
| 145 | PPC_STL r25, VCPU_GPR(r25)(r7) |
| 146 | PPC_STL r26, VCPU_GPR(r26)(r7) |
| 147 | PPC_STL r27, VCPU_GPR(r27)(r7) |
| 148 | PPC_STL r28, VCPU_GPR(r28)(r7) |
| 149 | PPC_STL r29, VCPU_GPR(r29)(r7) |
| 150 | PPC_STL r30, VCPU_GPR(r30)(r7) |
| 151 | PPC_STL r31, VCPU_GPR(r31)(r7) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 152 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 153 | /* Pass the exit number as 3rd argument to kvmppc_handle_exit */ |
Alexander Graf | 7e57cba | 2010-01-08 02:58:03 +0100 | [diff] [blame] | 154 | mr r5, r12 |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 155 | |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 156 | /* Restore r3 (kvm_run) and r4 (vcpu) */ |
| 157 | REST_2GPRS(3, r1) |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 158 | bl FUNC(kvmppc_handle_exit) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 159 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 160 | /* If RESUME_GUEST, get back in the loop */ |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 161 | cmpwi r3, RESUME_GUEST |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 162 | beq kvm_loop_lightweight |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 163 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 164 | cmpwi r3, RESUME_GUEST_NV |
| 165 | beq kvm_loop_heavyweight |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 166 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 167 | kvm_exit_loop: |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 168 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 169 | PPC_LL r4, _LINK(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 170 | mtlr r4 |
| 171 | |
Alexander Graf | e1f8acf | 2012-03-05 16:00:28 +0100 | [diff] [blame] | 172 | lwz r14, _CCR(r1) |
| 173 | mtcr r14 |
| 174 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 175 | /* Restore non-volatile host registers (r14 - r31) */ |
| 176 | REST_NVGPRS(r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 177 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 178 | addi r1, r1, SWITCH_FRAME_SIZE |
| 179 | blr |
| 180 | |
| 181 | kvm_loop_heavyweight: |
| 182 | |
Alexander Graf | b79fcdf | 2010-04-16 00:11:47 +0200 | [diff] [blame] | 183 | PPC_LL r4, _LINK(r1) |
| 184 | PPC_STL r4, (PPC_LR_STKOFF + SWITCH_FRAME_SIZE)(r1) |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 185 | |
| 186 | /* Load vcpu and cpu_run */ |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 187 | REST_2GPRS(3, r1) |
| 188 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 189 | /* Load non-volatile guest state from the vcpu */ |
| 190 | VCPU_LOAD_NVGPRS(r4) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 191 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 192 | /* Jump back into the beginning of this function */ |
| 193 | b kvm_start_lightweight |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 194 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 195 | kvm_loop_lightweight: |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 196 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 197 | /* We'll need the vcpu pointer */ |
| 198 | REST_GPR(4, r1) |
Alexander Graf | 29eb61b | 2009-10-30 05:47:07 +0000 | [diff] [blame] | 199 | |
Alexander Graf | 97c4cfb | 2010-01-04 22:19:25 +0100 | [diff] [blame] | 200 | /* Jump back into the beginning of this function */ |
| 201 | b kvm_start_lightweight |