AArch64 EL2 hypervisor for QEMU virt that boots at EL2
1.section .text.entry, "ax"
2.global _guest_start
3.type _guest_start, %function
4_guest_start:
5 ldr x0, =__guest_stack_top
6 mov sp, x0
7 ldr x0, =__guest_bss_start
8 ldr x1, =__guest_bss_end
91: cmp x0, x1
10 b.hs 2f
11 str xzr, [x0], #8
12 b 1b
132: ldr x0, =guest_vectors
14 msr vbar_el1, x0
15 isb
16 bl guest_main
173: hvc #3
18 wfe
19 b 3b
20
21.global guest_hvc_call
22.type guest_hvc_call, %function
23guest_hvc_call:
24 hvc #0
25 ret
26
27.section .text.vectors, "ax"
28.align 11
29guest_vectors:
30 b guest_exception
31 .org guest_vectors + 0x080
32 b guest_exception
33 .org guest_vectors + 0x100
34 b guest_exception
35 .org guest_vectors + 0x180
36 b guest_exception
37 .org guest_vectors + 0x200
38 b guest_exception
39 .org guest_vectors + 0x280
40 b guest_exception
41 .org guest_vectors + 0x300
42 b guest_exception
43 .org guest_vectors + 0x380
44 b guest_exception
45 .org guest_vectors + 0x400
46 b guest_exception
47 .org guest_vectors + 0x480
48 b guest_exception
49 .org guest_vectors + 0x500
50 b guest_exception
51 .org guest_vectors + 0x580
52 b guest_exception
53 .org guest_vectors + 0x600
54 b guest_exception
55 .org guest_vectors + 0x680
56 b guest_exception
57 .org guest_vectors + 0x700
58 b guest_exception
59 .org guest_vectors + 0x780
60 b guest_exception
61
62guest_exception:
63 mrs x4, esr_el1
64 mrs x5, elr_el1
65 mrs x6, far_el1
66 mov x0, #5
67 mov x1, x4
68 mov x2, x5
69 mov x3, x6
70 hvc #0
71 mov x0, #4
72 ldr x1, =guest_exception_msg
73 mov x2, #(guest_exception_msg_end - guest_exception_msg)
74 hvc #0
75 add x5, x5, #4
76 msr elr_el1, x5
77 isb
78 eret
79
80.section .rodata
81guest_exception_msg:
82 .ascii "guest exception vector"
83guest_exception_msg_end:
84
85.section .bss.stack, "aw", %nobits
86.align 12
87__guest_stack:
88 .skip 0x10000
89__guest_stack_top: