blob: 0f06bddb7c2345c96c4f8201501330029699f68f [file] [log] [blame]
Wedson Almeida Filho22c973a2018-10-27 16:25:42 +01001/*
2 * Copyright 2018 Google LLC
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * https://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010017#include "offsets.h"
Andrew Walbranc55365d2018-12-06 15:45:11 +000018#include "exception_macros.S"
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010019
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +000020/**
21 * Saves the volatile registers into the register buffer of the current vcpu. It
22 * allocates space on the stack for x18 and saves it if "also_save_x18" is
23 * specified; otherwise the caller is expected to have saved x18 in a similar
24 * fashion.
25 */
26.macro save_volatile_to_vcpu also_save_x18
27.ifnb \also_save_x18
Wedson Almeida Filho5bc0b4c2018-07-30 15:31:44 +010028 /*
29 * Save x18 since we're about to clobber it. We subtract 16 instead of
30 * 8 from the stack pointer to keep it 16-byte aligned.
31 */
32 str x18, [sp, #-16]!
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +000033.endif
34 /* Get the current vcpu. */
35 mrs x18, tpidr_el2
36 stp x0, x1, [x18, #VCPU_REGS + 8 * 0]
37 stp x2, x3, [x18, #VCPU_REGS + 8 * 2]
38 stp x4, x5, [x18, #VCPU_REGS + 8 * 4]
39 stp x6, x7, [x18, #VCPU_REGS + 8 * 6]
40 stp x8, x9, [x18, #VCPU_REGS + 8 * 8]
41 stp x10, x11, [x18, #VCPU_REGS + 8 * 10]
42 stp x12, x13, [x18, #VCPU_REGS + 8 * 12]
43 stp x14, x15, [x18, #VCPU_REGS + 8 * 14]
44 stp x16, x17, [x18, #VCPU_REGS + 8 * 16]
45 stp x29, x30, [x18, #VCPU_REGS + 8 * 29]
46
47 /* x18 was saved on the stack, so we move it to vcpu regs buffer. */
48 ldr x0, [sp], #16
49 str x0, [x18, #VCPU_REGS + 8 * 18]
50
51 /* Save return address & mode. */
52 mrs x1, elr_el2
53 mrs x2, spsr_el2
54 stp x1, x2, [x18, #VCPU_REGS + 8 * 31]
55.endm
56
57/**
58 * This is a generic handler for exceptions taken at a lower EL. It saves the
59 * volatile registers to the current vcpu and calls the C handler, which can
60 * select one of two paths: (a) restore volatile registers and return, or
61 * (b) switch to a different vcpu. In the latter case, the handler needs to save
62 * all non-volatile registers (they haven't been saved yet), then restore all
63 * registers from the new vcpu.
64 */
65.macro lower_exception handler:req
66 save_volatile_to_vcpu also_save_x18
67
68 /* Call C handler. */
69 bl \handler
70
71 /* Switch vcpu if requested by handler. */
72 cbnz x0, vcpu_switch
73
74 /* vcpu is not changing. */
75 mrs x0, tpidr_el2
76 b vcpu_restore_volatile_and_run
77.endm
78
79/**
80 * This is the handler for a sync exception taken at a lower EL. If the reason
81 * for the exception is an HVC call, it calls the faster hvc_handler without
82 * saving a lot of the registers, otherwise it goes to slow_sync_lower, which is
83 * the slow path where all registers needs to be saved/restored.
84 */
85.macro lower_sync_exception
86 /* Save x18 as save_volatile_to_vcpu would have. */
87 str x18, [sp, #-16]!
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010088
89 /* Extract the exception class (EC) from exception syndrome register. */
90 mrs x18, esr_el2
91 lsr x18, x18, #26
92
93 /* Take the slow path if exception is not due to an HVC instruction. */
Wedson Almeida Filhod615cdb2018-10-09 13:00:21 +010094 sub x18, x18, #0x16
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +000095 cbnz x18, slow_sync_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +010096
Wedson Almeida Filho87009642018-07-02 10:20:07 +010097 /*
98 * Save x29 and x30, which are not saved by the callee, then jump to
99 * HVC handler.
100 */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100101 stp x29, x30, [sp, #-16]!
102 bl hvc_handler
103 ldp x29, x30, [sp], #16
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000104 cbnz x1, sync_lower_switch
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100105
106 /* Zero out all volatile registers (except x0) and return. */
Wedson Almeida Filhod615cdb2018-10-09 13:00:21 +0100107 stp xzr, xzr, [sp, #-16]!
108 ldp x1, x2, [sp]
109 ldp x3, x4, [sp]
110 ldp x5, x6, [sp]
111 ldp x7, x8, [sp]
112 ldp x9, x10, [sp]
113 ldp x11, x12, [sp]
114 ldp x13, x14, [sp]
115 ldp x15, x16, [sp], #16
Wedson Almeida Filho5bc0b4c2018-07-30 15:31:44 +0100116 mov x17, xzr
Wedson Almeida Filho450ccb82018-08-12 16:25:36 +0100117
118 /* Restore x18, which was saved on the stack. */
119 ldr x18, [sp], #16
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100120 eret
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000121.endm
122
123/**
124 * The following is the exception table. A pointer to it will be stored in
125 * register vbar_el2.
126 */
127.section .text.vector_table_el2, "ax"
128.global vector_table_el2
129.balign 0x800
130vector_table_el2:
131sync_cur_sp0:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000132 current_exception_sp0 el2 sync_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000133
134.balign 0x80
135irq_cur_sp0:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000136 current_exception_sp0 el2 irq_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000137
138.balign 0x80
139fiq_cur_sp0:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000140 current_exception_sp0 el2 fiq_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000141
142.balign 0x80
143serr_cur_sp0:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000144 current_exception_sp0 el2 serr_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000145
146.balign 0x80
147sync_cur_spx:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000148 current_exception_spx el2 sync_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000149
150.balign 0x80
151irq_cur_spx:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000152 current_exception_spx el2 irq_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000153
154.balign 0x80
155fiq_cur_spx:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000156 current_exception_spx el2 fiq_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000157
158.balign 0x80
159serr_cur_spx:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000160 current_exception_spx el2 serr_current_exception
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000161
162.balign 0x80
163sync_lower_64:
164 lower_sync_exception
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100165
166.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000167irq_lower_64:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000168 lower_exception irq_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100169
170.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000171fiq_lower_64:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000172 lower_exception fiq_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100173
174.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000175serr_lower_64:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000176 lower_exception serr_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100177
178.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000179sync_lower_32:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000180 lower_sync_exception
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100181
182.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000183irq_lower_32:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000184 lower_exception irq_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100185
186.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000187fiq_lower_32:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000188 lower_exception fiq_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100189
190.balign 0x80
Andrew Walbran83f61322018-11-12 13:29:30 +0000191serr_lower_32:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000192 lower_exception serr_lower
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100193
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000194.balign 0x40
195slow_sync_lower:
196 /* The caller must have saved x18, so we don't save it here. */
197 save_volatile_to_vcpu
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100198
199 /* Read syndrome register and call C handler. */
200 mrs x0, esr_el2
201 bl sync_lower_exception
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100202 cbnz x0, vcpu_switch
203
204 /* vcpu is not changing. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000205 mrs x0, tpidr_el2
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100206 b vcpu_restore_volatile_and_run
207
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000208sync_lower_switch:
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100209 /* We'll have to switch, so save volatile state before doing so. */
210 mrs x18, tpidr_el2
211
212 /* Store zeroes in volatile register storage, except x0. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000213 stp x0, xzr, [x18, #VCPU_REGS + 8 * 0]
214 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 2]
215 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 4]
216 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 6]
217 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 8]
218 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 10]
219 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 12]
220 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 14]
221 stp xzr, xzr, [x18, #VCPU_REGS + 8 * 16]
222 stp x29, x30, [x18, #VCPU_REGS + 8 * 29]
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100223
224 /* x18 was saved on the stack, so we move it to vcpu regs buffer. */
225 ldr x2, [sp], #16
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000226 str x2, [x18, #VCPU_REGS + 8 * 18]
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100227
228 /* Save return address & mode. */
229 mrs x2, elr_el2
230 mrs x3, spsr_el2
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000231 stp x2, x3, [x18, #VCPU_REGS + 8 * 31]
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100232
233 /* Save lazy state, then switch to new vcpu. */
234 mov x0, x1
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100235
236 /* Intentional fallthrough. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100237/**
238 * Switch to a new vcpu.
239 *
240 * All volatile registers from the old vcpu have already been saved. We need
241 * to save only non-volatile ones from the old vcpu, and restore all from the
242 * new one.
243 *
244 * x0 is a pointer to the new vcpu.
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100245 */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100246vcpu_switch:
247 /* Save non-volatile registers. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000248 mrs x1, tpidr_el2
249 stp x19, x20, [x1, #VCPU_REGS + 8 * 19]
250 stp x21, x22, [x1, #VCPU_REGS + 8 * 21]
251 stp x23, x24, [x1, #VCPU_REGS + 8 * 23]
252 stp x25, x26, [x1, #VCPU_REGS + 8 * 25]
253 stp x27, x28, [x1, #VCPU_REGS + 8 * 27]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100254
255 /* Save lazy state. */
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100256 mrs x24, vmpidr_el2
257 mrs x25, csselr_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000258 stp x24, x25, [x1, #VCPU_LAZY + 16 * 0]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100259
260 mrs x2, sctlr_el1
261 mrs x3, actlr_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000262 stp x2, x3, [x1, #VCPU_LAZY + 16 * 1]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100263
264 mrs x4, cpacr_el1
265 mrs x5, ttbr0_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000266 stp x4, x5, [x1, #VCPU_LAZY + 16 * 2]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100267
268 mrs x6, ttbr1_el1
269 mrs x7, tcr_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000270 stp x6, x7, [x1, #VCPU_LAZY + 16 * 3]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100271
272 mrs x8, esr_el1
273 mrs x9, afsr0_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000274 stp x8, x9, [x1, #VCPU_LAZY + 16 * 4]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100275
276 mrs x10, afsr1_el1
277 mrs x11, far_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000278 stp x10, x11, [x1, #VCPU_LAZY + 16 * 5]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100279
280 mrs x12, mair_el1
281 mrs x13, vbar_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000282 stp x12, x13, [x1, #VCPU_LAZY + 16 * 6]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100283
284 mrs x14, contextidr_el1
285 mrs x15, tpidr_el0
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000286 stp x14, x15, [x1, #VCPU_LAZY + 16 * 7]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100287
288 mrs x16, tpidrro_el0
289 mrs x17, tpidr_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000290 stp x16, x17, [x1, #VCPU_LAZY + 16 * 8]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100291
292 mrs x18, amair_el1
293 mrs x19, cntkctl_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000294 stp x18, x19, [x1, #VCPU_LAZY + 16 * 9]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100295
296 mrs x20, sp_el0
297 mrs x21, sp_el1
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000298 stp x20, x21, [x1, #VCPU_LAZY + 16 * 10]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100299
300 mrs x22, par_el1
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100301 mrs x23, hcr_el2
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000302 stp x22, x23, [x1, #VCPU_LAZY + 16 * 11]
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100303
304 mrs x24, cptr_el2
305 mrs x25, cnthctl_el2
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000306 stp x24, x25, [x1, #VCPU_LAZY + 16 * 12]
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100307
308 mrs x26, vttbr_el2
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000309 str x26, [x1, #VCPU_LAZY + 16 * 13]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100310
Wedson Almeida Filho03306112018-11-26 00:08:03 +0000311 /* Save new vcpu pointer in non-volatile register. */
312 mov x19, x0
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100313
Wedson Almeida Filho03306112018-11-26 00:08:03 +0000314 /* Inform the arch-independent sections that regs have been saved. */
315 mov x0, x1
316 bl api_regs_state_saved
317 mov x0, x19
318
319 /* Intentional fallthrough. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100320.globl vcpu_restore_all_and_run
321vcpu_restore_all_and_run:
Wedson Almeida Filho59978322018-10-24 15:13:33 +0100322 /* Update pointer to current vcpu. */
Wedson Almeida Filho00df6c72018-10-18 11:19:24 +0100323 msr tpidr_el2, x0
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100324
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000325 /* Restore lazy registers. */
326 ldp x24, x25, [x0, #VCPU_LAZY + 16 * 0]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100327 msr vmpidr_el2, x24
328 msr csselr_el1, x25
329
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000330 ldp x2, x3, [x0, #VCPU_LAZY + 16 * 1]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100331 msr sctlr_el1, x2
332 msr actlr_el1, x3
333
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000334 ldp x4, x5, [x0, #VCPU_LAZY + 16 * 2]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100335 msr cpacr_el1, x4
336 msr ttbr0_el1, x5
337
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000338 ldp x6, x7, [x0, #VCPU_LAZY + 16 * 3]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100339 msr ttbr1_el1, x6
340 msr tcr_el1, x7
341
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000342 ldp x8, x9, [x0, #VCPU_LAZY + 16 * 4]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100343 msr esr_el1, x8
344 msr afsr0_el1, x9
345
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000346 ldp x10, x11, [x0, #VCPU_LAZY + 16 * 5]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100347 msr afsr1_el1, x10
348 msr far_el1, x11
349
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000350 ldp x12, x13, [x0, #VCPU_LAZY + 16 * 6]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100351 msr mair_el1, x12
352 msr vbar_el1, x13
353
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000354 ldp x14, x15, [x0, #VCPU_LAZY + 16 * 7]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100355 msr contextidr_el1, x14
356 msr tpidr_el0, x15
357
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000358 ldp x16, x17, [x0, #VCPU_LAZY + 16 * 8]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100359 msr tpidrro_el0, x16
360 msr tpidr_el1, x17
361
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000362 ldp x18, x19, [x0, #VCPU_LAZY + 16 * 9]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100363 msr amair_el1, x18
364 msr cntkctl_el1, x19
365
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000366 ldp x20, x21, [x0, #VCPU_LAZY + 16 * 10]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100367 msr sp_el0, x20
368 msr sp_el1, x21
369
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000370 ldp x22, x23, [x0, #VCPU_LAZY + 16 * 11]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100371 msr par_el1, x22
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100372 msr hcr_el2, x23
373
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000374 ldp x24, x25, [x0, #VCPU_LAZY + 16 * 12]
Andrew Walbran570f9b72018-11-13 17:51:50 +0000375 msr cptr_el2, x24
376 msr cnthctl_el2, x25
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100377
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000378 ldr x26, [x0, #VCPU_LAZY + 16 * 13]
Wedson Almeida Filho1f81b752018-10-24 15:15:49 +0100379 msr vttbr_el2, x26
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100380
381 /* Restore non-volatile registers. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000382 ldp x19, x20, [x0, #VCPU_REGS + 8 * 19]
383 ldp x21, x22, [x0, #VCPU_REGS + 8 * 21]
384 ldp x23, x24, [x0, #VCPU_REGS + 8 * 23]
385 ldp x25, x26, [x0, #VCPU_REGS + 8 * 25]
386 ldp x27, x28, [x0, #VCPU_REGS + 8 * 27]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100387
Wedson Almeida Filhod615cdb2018-10-09 13:00:21 +0100388 /* Intentional fallthrough. */
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100389/**
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100390 * Restore volatile registers and run the given vcpu.
Wedson Almeida Filhod615cdb2018-10-09 13:00:21 +0100391 *
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000392 * x0 is a pointer to the target vcpu.
Wedson Almeida Filho87009642018-07-02 10:20:07 +0100393 */
394vcpu_restore_volatile_and_run:
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000395 ldp x4, x5, [x0, #VCPU_REGS + 8 * 4]
396 ldp x6, x7, [x0, #VCPU_REGS + 8 * 6]
397 ldp x8, x9, [x0, #VCPU_REGS + 8 * 8]
398 ldp x10, x11, [x0, #VCPU_REGS + 8 * 10]
399 ldp x12, x13, [x0, #VCPU_REGS + 8 * 12]
400 ldp x14, x15, [x0, #VCPU_REGS + 8 * 14]
401 ldp x16, x17, [x0, #VCPU_REGS + 8 * 16]
402 ldr x18, [x0, #VCPU_REGS + 8 * 18]
403 ldp x29, x30, [x0, #VCPU_REGS + 8 * 29]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100404
405 /* Restore return address & mode. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000406 ldp x1, x2, [x0, #VCPU_REGS + 8 * 31]
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100407 msr elr_el2, x1
408 msr spsr_el2, x2
409
410 /* Restore x0..x3, which we have used as scratch before. */
Wedson Almeida Filho9d5040f2018-10-29 08:41:27 +0000411 ldp x2, x3, [x0, #VCPU_REGS + 8 * 2]
412 ldp x0, x1, [x0, #VCPU_REGS + 8 * 0]
413 eret
414
415.balign 0x40
416/**
417 * Restores volatile registers from stack and returns.
418 */
419restore_from_stack_and_return:
Andrew Walbranc55365d2018-12-06 15:45:11 +0000420 restore_volatile_from_stack el2
Wedson Almeida Filho987c0ff2018-06-20 16:34:38 +0100421 eret