AArch64 EL2 hypervisor for QEMU virt that boots at EL2
1#include "hv/arch.h"
2#include "hv/log.h"
3#include "hv/panic.h"
4#include "hv/uart.h"
5#include "hv/vcpu.h"
6
7void panic_dump_value(const char *name, uint64_t value)
8{
9 uart_puts("panic ");
10 uart_puts(name);
11 uart_puts("=");
12 uart_put_hex64(value);
13 uart_puts("\n");
14}
15
16void panic_with_code(const char *reason, uint64_t code)
17{
18 struct log_event ev;
19 ev.seq = 0;
20 ev.cpu = 0;
21 ev.vcpu = vcpu_current() != (struct vcpu *)0 ? vcpu_current()->id : UINT64_MAX;
22 ev.timestamp = 0;
23 ev.kind = LOG_PANIC;
24 ev.ec = 0;
25 ev.iss = code;
26 ev.elr = 0;
27 ev.far = 0;
28 ev.hpfar = 0;
29 ev.sysreg_key = 0;
30 ev.is_read = 0;
31 ev.rt = 0;
32 ev.operand = code;
33 ev.result = 0;
34 ev.action = LOG_ACT_PANIC;
35 ev.reason = 999u;
36 ev.pstate = 0;
37 ev.name = reason;
38 log_event_commit(&ev);
39
40 uart_puts("\nPANIC reason=");
41 uart_puts(reason);
42 uart_puts(" code=");
43 uart_put_hex64(code);
44 uart_puts(" current_el=");
45 uart_put_dec64(arch_current_el());
46 uart_puts("\n");
47 panic_dump_value("code", code);
48 arch_dump_el2_state();
49 vcpu_dump(vcpu_current());
50 uart_puts("recent log:\n");
51 log_dump(32u);
52 arch_halt();
53}
54
55void panic(const char *reason)
56{
57 panic_with_code(reason, 0u);
58}