@@ -24,6 +24,149 @@ __sfence_vma:
2424 sfence.vma a0 , a1
2525 ret
2626
27+ // RISC-V hypervisor instructions.
28+
29+ // The switch for enabling LLVM support for asm generation.
30+ // #define LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
31+
32+
33+ .section .text .__hfence_gvma
34+ .global __hfence_gvma
35+ __hfence_gvma:
36+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
37+ hfence.gvma a0 , a1
38+ #else
39+ .word 1656029299
40+ #endif
41+ ret
42+ .section .text .__hfence_vvma
43+ .global __hfence_vvma
44+ __hfence_vvma:
45+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
46+ hfence.vvma a0 , a1
47+ #else
48+ .word 582287475
49+ #endif
50+ ret
51+ .section .text .__hlv_b
52+ .global __hlv_b
53+ __hlv_b:
54+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
55+ hlv.b a0 , a0
56+ #else
57+ .word 1610958195
58+ #endif
59+ ret
60+ .section .text .__hlv_bu
61+ .global __hlv_bu
62+ __hlv_bu:
63+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
64+ hlv.bu a0 , a0
65+ #else
66+ .word 1612006771
67+ #endif
68+ ret
69+ .section .text .__hlv_h
70+ .global __hlv_h
71+ __hlv_h:
72+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
73+ hlv.h a0 , a0
74+ #else
75+ .word 1678067059
76+ #endif
77+ ret
78+ .section .text .__hlv_hu
79+ .global __hlv_hu
80+ __hlv_hu:
81+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
82+ hlv.hu a0 , a0
83+ #else
84+ .word 1679115635
85+ #endif
86+ ret
87+ .section .text .__hlvx_hu
88+ .global __hlvx_hu
89+ __hlvx_hu:
90+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
91+ hlvx.hu a0 , a0
92+ #else
93+ .word 1681212787
94+ #endif
95+ ret
96+ .section .text .__hlv_w
97+ .global __hlv_w
98+ __hlv_w:
99+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
100+ hlv.w a0 , a0
101+ #else
102+ .word 1745175923
103+ #endif
104+ ret
105+ .section .text .__hlvx_wu
106+ .global __hlvx_wu
107+ __hlvx_wu:
108+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
109+ hlvx.wu a0 , a0
110+ #else
111+ .word 1748321651
112+ #endif
113+ ret
114+ .section .text .__hsv_b
115+ .global __hsv_b
116+ __hsv_b:
117+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
118+ hsv.b a0 , a1
119+ #else
120+ .word 1656045683
121+ #endif
122+ ret
123+ .section .text .__hsv_h
124+ .global __hsv_h
125+ __hsv_h:
126+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
127+ hsv.h a0 , a1
128+ #else
129+ .word 1723154547
130+ #endif
131+ ret
132+ .section .text .__hsv_w
133+ .global __hsv_w
134+ __hsv_w:
135+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
136+ hsv.w a0 , a1
137+ #else
138+ .word 1790263411
139+ #endif
140+ ret
141+ .section .text .__hlv_wu
142+ .global __hlv_wu
143+ __hlv_wu:
144+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
145+ hlv.wu a0 , a0
146+ #else
147+ .word 1746224499
148+ #endif
149+ ret
150+ .section .text .__hlv_d
151+ .global __hlv_d
152+ __hlv_d:
153+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
154+ hlv.d a0 , a0
155+ #else
156+ .word 1812284787
157+ #endif
158+ ret
159+ .section .text .__hsv_d
160+ .global __hsv_d
161+ __hsv_d:
162+ #ifdef LLVM_RISCV_HYPERVISOR_EXTENSION_SUPPORT
163+ hsv.d a0 , a1
164+ #else
165+ .word 1857372275
166+ #endif
167+ ret
168+
169+
27170// User Trap Setup
28171RW (0x000, ustatus) // User status register
29172RW (0x004, uie) // User interrupt-enable register
@@ -273,3 +416,39 @@ RW(0x7A3, tdata3) // Third Debug/Trace trigger data register
273416RW (0x7B0, dcsr) // Debug control and status register
274417RW (0x7B1, dpc) // Debug PC
275418RW (0x7B2, dscratch) // Debug scratch register
419+
420+ // Hypervisor Trap Setup
421+ RW (0x600, hstatus) // Hypervisor status register
422+ RW (0x602, hedeleg) // Hypervisor exception delegation register
423+ RW (0x603, hideleg) // Hypervisor interrupt delegation register
424+ RW (0x604, hie) // Hypervisor interrupt-enable register
425+ RW (0x606, hcounteren) // Hypervisor counter enable
426+ RW (0x607, hgeie) // Hypervisor guest external interrupt-enable register
427+
428+ // Hypervisor Trap Handling
429+ RW (0x643, htval) // Hypervisor bad guest physical address
430+ RW (0x644, hip) // Hypervisor interrupt pending
431+ RW (0x645, hvip) // Hypervisor virtual interrupt pending
432+ RW (0x64a, htinst) // Hypervisor trap instruction (transformed)
433+ RW (0xe12, hgeip) // Hypervisor guest external interrupt pending
434+
435+ // Hypervisor Protection and Translation
436+ RO (0x680, hgatp) // Hypervisor guest address translation and protection
437+
438+ // Debug/Trace Registers
439+ RW (0x6a8, hcontext) // Hypervisor-mode context register
440+
441+ // Hypervisor Counter/Timer Virtualization Registers
442+ RW (0x605, htimedelta) // Delta for VS /VU-mode timer
443+ RW32 (0x615, htimedeltah) // Upper 32 bits of {\tt htimedelta}, RV32 only
444+
445+ // Virtual Supervisor Registers
446+ RW (0x200, vsstatus) // Virtual supervisor status register
447+ RW (0x204, vsie) // Virtual supervisor interrupt-enable register
448+ RW (0x205, vstvec) // Virtual supervisor trap handler base address
449+ RW (0x240, vsscratch) // Virtual supervisor scratch register
450+ RW (0x241, vsepc) // Virtual supervisor exception program counter
451+ RW (0x242, vscause) // Virtual supervisor trap cause
452+ RW (0x243, vstval) // Virtual supervisor bad address or instruction
453+ RW (0x244, vsip) // Virtual supervisor interrupt pending
454+ RW (0x280, vsatp) // Virtual supervisor address translation and protection
0 commit comments