Skip to content

Commit d3b9712

Browse files
wuxyintellijinxia
authored andcommitted
HV:INSTR:Rearrange register names in the enum cpu_reg_name
In the current "enum cpu_reg_name", there are 16-bit segment register names, 16-bit descriptor table register names, and 16-bit task register names. These 16-bit register names are defined among the 64 bit register names. To access these 16-bit fields in VMCS and 32 bit fields in VMCS, more condition statements need to be used. Update 16-bit register names position to simplify conditions in vm_get_register and vm_set_register since different fields size accessing in VMCS by different vmread/vmwrite opreation. Note: After checking the current implementation, the register names of the same kind of registers (general registers, control registers, segment registers etc) need to be defined in order, some code checks the range by using this order. But different kinds of register names as group, this group position can be adjusted to simplify conditions. The follwoing register names group need to be considered in current implemetation: (1) General register names group: CPU_REG_RAX~CPU_REG_RDI; (2) Non-General register names group:CPU_REG_CR0~CPU_REG_LAST; (3) segment register names group:CPU_REG_ES~CPU_REG_GS. V1-->V2: This is new part of this patch serial created in V2 to rearrange register names as needed. V2--V3: Update comment information. V3-->V4: Define CPU_REG_NATURAL_LAST and CPU_REG_64BIT_LAST to make condition more understandable. Signed-off-by: Xiangyang Wu <xiangyang.wu@intel.com> Reviewed-by: Junjie Mao <junjie.mao@intel.com>
1 parent 055153b commit d3b9712

File tree

1 file changed

+28
-7
lines changed

1 file changed

+28
-7
lines changed

hypervisor/arch/x86/guest/instr_emul_wrapper.h

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,27 @@
3131
#define INSTR_EMUL_WRAPPER_H
3232
#include <cpu.h>
3333

34-
/*
34+
/**
35+
*
3536
* Identifiers for architecturally defined registers.
37+
*
38+
* These register names is used in condition statement.
39+
* Within the following groups,register name need to be
40+
* kept in order:
41+
* General register names group (CPU_REG_RAX~CPU_REG_RDI);
42+
* Non general register names group (CPU_REG_CR0~CPU_REG_LAST);
43+
* Segement register names group (CPU_REG_ES~CPU_REG_GS).
44+
*
45+
* CPU_REG_NATURAL_LAST indicates in the non general register names
46+
* group the register name (less than CPU_REG_NATURAL_last) is
47+
* corresponds to the natural width field in VMCS;
48+
*
49+
* CPU_REG_64BIT_LAST indicates in the non general register names
50+
* group the register name (less than CPU_REG_64BIT_LAST and more than
51+
* CPU_REG_NATURAL_last) corresponds to the 64-bit field in VMCS.
52+
*
53+
* CPU_REG_LAST indicates the last register name.
54+
*
3655
*/
3756
enum cpu_reg_name {
3857
CPU_REG_RAX,
@@ -51,12 +70,20 @@ enum cpu_reg_name {
5170
CPU_REG_R15,
5271
CPU_REG_RDI,
5372
CPU_REG_CR0,
73+
CPU_REG_CR2,
5474
CPU_REG_CR3,
5575
CPU_REG_CR4,
5676
CPU_REG_DR7,
5777
CPU_REG_RSP,
5878
CPU_REG_RIP,
5979
CPU_REG_RFLAGS,
80+
CPU_REG_NATURAL_LAST,
81+
CPU_REG_EFER,
82+
CPU_REG_PDPTE0,
83+
CPU_REG_PDPTE1,
84+
CPU_REG_PDPTE2,
85+
CPU_REG_PDPTE3,
86+
CPU_REG_64BIT_LAST,
6087
CPU_REG_ES,
6188
CPU_REG_CS,
6289
CPU_REG_SS,
@@ -67,12 +94,6 @@ enum cpu_reg_name {
6794
CPU_REG_TR,
6895
CPU_REG_IDTR,
6996
CPU_REG_GDTR,
70-
CPU_REG_EFER,
71-
CPU_REG_CR2,
72-
CPU_REG_PDPTE0,
73-
CPU_REG_PDPTE1,
74-
CPU_REG_PDPTE2,
75-
CPU_REG_PDPTE3,
7697
CPU_REG_LAST
7798
};
7899

0 commit comments

Comments
 (0)