]> rtime.felk.cvut.cz Git - jailhouse.git/blob - hypervisor/arch/arm/traps.c
arm: dispatch hypercalls
[jailhouse.git] / hypervisor / arch / arm / traps.c
1 /*
2  * Jailhouse, a Linux-based partitioning hypervisor
3  *
4  * Copyright (c) ARM Limited, 2014
5  *
6  * Authors:
7  *  Jean-Philippe Brucker <jean-philippe.brucker@arm.com>
8  *
9  * This work is licensed under the terms of the GNU GPL, version 2.  See
10  * the COPYING file in the top-level directory.
11  */
12
13 #include <asm/control.h>
14 #include <asm/traps.h>
15 #include <asm/sysregs.h>
16 #include <jailhouse/printk.h>
17 #include <jailhouse/control.h>
18
19 static int arch_handle_hvc(struct per_cpu *cpu_data, struct trap_context *ctx)
20 {
21         unsigned long *regs = ctx->regs;
22
23         regs[0] = hypercall(regs[0], regs[1], regs[2]);
24
25         return TRAP_HANDLED;
26 }
27
28 static const trap_handler trap_handlers[38] =
29 {
30         [ESR_EC_HVC]            = arch_handle_hvc,
31 };
32
33 void arch_handle_trap(struct per_cpu *cpu_data, struct registers *guest_regs)
34 {
35         struct trap_context ctx;
36         u32 exception_class;
37         int ret = TRAP_UNHANDLED;
38
39         arm_read_banked_reg(SPSR_hyp, ctx.cpsr);
40         arm_read_sysreg(ESR_EL2, ctx.esr);
41         exception_class = ESR_EC(ctx.esr);
42         ctx.regs = guest_regs->usr;
43
44         if (trap_handlers[exception_class])
45                 ret = trap_handlers[exception_class](cpu_data, &ctx);
46
47         if (ret != TRAP_HANDLED) {
48                 panic_printk("CPU%d: Unhandled HYP trap, syndrome 0x%x\n",
49                                 cpu_data->cpu_id, ctx.esr);
50                 while(1);
51         }
52 }