xref: /linux/arch/x86/include/asm/kvm_vcpu_regs.h (revision a50eba1e778ad4da5b6f9ddbbf57dabbea59bc05)
1 /* SPDX-License-Identifier: GPL-2.0 */
2 #ifndef _ASM_X86_KVM_VCPU_REGS_H
3 #define _ASM_X86_KVM_VCPU_REGS_H
4 
5 #define __VCPU_REGS_RAX  0
6 #define __VCPU_REGS_RCX  1
7 #define __VCPU_REGS_RDX  2
8 #define __VCPU_REGS_RBX  3
9 #define __VCPU_REGS_RSP  4
10 #define __VCPU_REGS_RBP  5
11 #define __VCPU_REGS_RSI  6
12 #define __VCPU_REGS_RDI  7
13 
14 #ifdef __ASSEMBLER__
15 
16 #define REG_NUM_INVALID		100
17 
18 	# convert the 32-bit register operand \r32 into a register number;
19 	# store it in the value whose name is in \opd.
20 	# only for !CONFIG_X86_64 (does not support r8d-r15d)
21 	.macro R32_NUM opd r32
22 	\opd = REG_NUM_INVALID
23 	.ifc \r32,%eax
24 	\opd = __VCPU_REGS_RAX
25 	.endif
26 	.ifc \r32,%ecx
27 	\opd = __VCPU_REGS_RCX
28 	.endif
29 	.ifc \r32,%edx
30 	\opd = __VCPU_REGS_RDX
31 	.endif
32 	.ifc \r32,%ebx
33 	\opd = __VCPU_REGS_RBX
34 	.endif
35 	.ifc \r32,%esp
36 	\opd = __VCPU_REGS_RSP
37 	.endif
38 	.ifc \r32,%ebp
39 	\opd = __VCPU_REGS_RBP
40 	.endif
41 	.ifc \r32,%esi
42 	\opd = __VCPU_REGS_RSI
43 	.endif
44 	.ifc \r32,%edi
45 	\opd = __VCPU_REGS_RDI
46 	.endif
47 	.endm
48 
49 	# convert the 64-bit register operand \r64 into a register number;
50 	# store it in the value whose name is in \opd.
51 	.macro R64_NUM opd r64
52 	\opd = REG_NUM_INVALID
53 #ifdef CONFIG_X86_64
54 	.ifc \r64,%rax
55 	\opd = __VCPU_REGS_RAX
56 	.endif
57 	.ifc \r64,%rcx
58 	\opd = __VCPU_REGS_RCX
59 	.endif
60 	.ifc \r64,%rdx
61 	\opd = __VCPU_REGS_RDX
62 	.endif
63 	.ifc \r64,%rbx
64 	\opd = __VCPU_REGS_RBX
65 	.endif
66 	.ifc \r64,%rsp
67 	\opd = __VCPU_REGS_RSP
68 	.endif
69 	.ifc \r64,%rbp
70 	\opd = __VCPU_REGS_RBP
71 	.endif
72 	.ifc \r64,%rsi
73 	\opd = __VCPU_REGS_RSI
74 	.endif
75 	.ifc \r64,%rdi
76 	\opd = __VCPU_REGS_RDI
77 	.endif
78 	.ifc \r64,%r8
79 	\opd = 8
80 	.endif
81 	.ifc \r64,%r9
82 	\opd = 9
83 	.endif
84 	.ifc \r64,%r10
85 	\opd = 10
86 	.endif
87 	.ifc \r64,%r11
88 	\opd = 11
89 	.endif
90 	.ifc \r64,%r12
91 	\opd = 12
92 	.endif
93 	.ifc \r64,%r13
94 	\opd = 13
95 	.endif
96 	.ifc \r64,%r14
97 	\opd = 14
98 	.endif
99 	.ifc \r64,%r15
100 	\opd = 15
101 	.endif
102 #endif
103 	.endm
104 
105 .macro REG_NUM reg_num reg
106 #ifdef CONFIG_X86_64
107 	R64_NUM \reg_num \reg
108 #else
109 	R32_NUM \reg_num \reg
110 #endif
111 	.if \reg_num == REG_NUM_INVALID
112 	.error "invalid register"
113 	.endif
114 .endm
115 
116 #endif
117 
118 #endif /* _ASM_X86_KVM_VCPU_REGS_H */
119