HV: instr_emul: make SEG_DESC_* macros having type bool

The SEG_DESC_* macros are mostly used as branch conditions though they evaluates
to signed int. This patch simplies their definitions and drop the unnecessary
casts accordingly.

Signed-off-by: Junjie Mao <junjie.mao@intel.com>
This commit is contained in:
Junjie Mao 2018-07-05 00:14:45 +08:00 committed by lijinxia
parent ecce1e6ae4
commit 62865d0397
3 changed files with 10 additions and 10 deletions

View File

@ -1270,7 +1270,7 @@ emulate_stack_op(struct vcpu *vcpu, uint64_t mmio_gpa, struct vie *vie,
error = vm_get_seg_desc(vcpu, CPU_REG_SS, &ss_desc);
ASSERT(error == 0, "%s: error %d getting SS descriptor",
__func__, error);
if ((_Bool)SEG_DESC_DEF32(ss_desc.access))
if (SEG_DESC_DEF32(ss_desc.access))
stackaddrsize = 4U;
else
stackaddrsize = 2U;
@ -1595,7 +1595,7 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
* then the descriptor is unusable and attempting to use
* it results in a #GP(0).
*/
if ((_Bool)SEG_DESC_UNUSABLE(desc->access))
if (SEG_DESC_UNUSABLE(desc->access))
return -1;
/*
@ -1604,7 +1604,7 @@ vie_calculate_gla(enum vm_cpu_mode cpu_mode, enum cpu_reg_name seg,
* descriptor that is not present. If this was the case then
* it would have been checked before the VM-exit.
*/
ASSERT((_Bool)SEG_DESC_PRESENT(desc->access),
ASSERT(SEG_DESC_PRESENT(desc->access),
"segment %d not present: %#x", seg, desc->access);
/*
@ -1818,7 +1818,7 @@ decode_prefixes(struct vie *vie, enum vm_cpu_mode cpu_mode, int cs_d)
vie->opsize = 2U;
else
vie->opsize = 4U;
} else if (cs_d != 0) {
} else if (cs_d) {
/* Default address and operand sizes are 32-bits */
vie->addrsize = vie->addrsize_override != 0U ? 2U : 4U;
vie->opsize = vie->opsize_override != 0U ? 2U : 4U;
@ -2137,7 +2137,7 @@ decode_moffset(struct vie *vie)
}
int
__decode_instruction(enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie)
__decode_instruction(enum vm_cpu_mode cpu_mode, bool cs_d, struct vie *vie)
{
if (decode_prefixes(vie, cpu_mode, cs_d) != 0)
return -1;

View File

@ -87,7 +87,7 @@ int vie_init(struct vie *vie, struct vcpu *vcpu);
*/
#define VIE_INVALID_GLA (1UL << 63) /* a non-canonical address */
int
__decode_instruction(enum vm_cpu_mode cpu_mode, int cs_d, struct vie *vie);
__decode_instruction(enum vm_cpu_mode cpu_mode, bool cs_d, struct vie *vie);
int emulate_instruction(struct vcpu *vcpu);
int decode_instruction(struct vcpu *vcpu);

View File

@ -166,10 +166,10 @@ struct seg_desc {
#define SEG_DESC_TYPE(access) ((access) & 0x001fU)
#define SEG_DESC_DPL(access) (((access) >> 5) & 0x3U)
#define SEG_DESC_PRESENT(access) ((((access) & 0x0080U) != 0U) ? 1 : 0)
#define SEG_DESC_DEF32(access) ((((access) & 0x4000U) != 0U) ? 1 : 0)
#define SEG_DESC_GRANULARITY(access) ((((access) & 0x8000U) != 0U) ? 1 : 0)
#define SEG_DESC_UNUSABLE(access) ((((access) & 0x10000U) != 0U) ? 1 : 0)
#define SEG_DESC_PRESENT(access) (((access) & 0x0080U) != 0U)
#define SEG_DESC_DEF32(access) (((access) & 0x4000U) != 0U)
#define SEG_DESC_GRANULARITY(access) (((access) & 0x8000U) != 0U)
#define SEG_DESC_UNUSABLE(access) (((access) & 0x10000U) != 0U)
struct vm_guest_paging {
uint64_t cr3;