Skip to content

Commit 12726db

Browse files
KaigeFulijinxia
authored andcommitted
HV: instr_emul: Make vie_read/write_bytereg as non-failed function
vie_read/write_bytereg call vm_get/set_register to get/set byteregs. We have make vm_get/set_register as non-failed function in previous patch. So, this patch make the vie_read/write_bytereg as non-failed function too. Signed-off-by: Kaige Fu <kaige.fu@intel.com> Acked-by: Eddie Dong <eddie.dong@intel.com>
1 parent 59c0f35 commit 12726db

File tree

1 file changed

+24
-27
lines changed

1 file changed

+24
-27
lines changed

hypervisor/arch/x86/guest/instr_emul.c

Lines changed: 24 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -597,11 +597,11 @@ static void vie_calc_bytereg(struct instr_emul_vie *vie,
597597
}
598598
}
599599

600-
static int vie_read_bytereg(struct vcpu *vcpu, struct instr_emul_vie *vie,
601-
uint8_t *rval)
600+
static uint8_t vie_read_bytereg(struct vcpu *vcpu, struct instr_emul_vie *vie)
602601
{
602+
int lhbr;
603603
uint64_t val;
604-
int error = 0, lhbr;
604+
uint8_t reg_val;
605605
enum cpu_reg_name reg;
606606

607607
vie_calc_bytereg(vie, &reg, &lhbr);
@@ -612,37 +612,36 @@ static int vie_read_bytereg(struct vcpu *vcpu, struct instr_emul_vie *vie,
612612
* base register right by 8 bits (%ah = %rax >> 8).
613613
*/
614614
if (lhbr != 0) {
615-
*rval = (uint8_t)(val >> 8);
615+
reg_val = (uint8_t)(val >> 8);
616616
} else {
617-
*rval = (uint8_t)val;
617+
reg_val = (uint8_t)val;
618618
}
619-
return error;
619+
620+
return reg_val;
620621
}
621622

622-
static int vie_write_bytereg(struct vcpu *vcpu, struct instr_emul_vie *vie,
623+
static void vie_write_bytereg(struct vcpu *vcpu, struct instr_emul_vie *vie,
623624
uint8_t byte)
624625
{
625626
uint64_t origval, val, mask;
626-
int error = 0, lhbr;
627627
enum cpu_reg_name reg;
628+
int lhbr;
628629

629630
vie_calc_bytereg(vie, &reg, &lhbr);
630631
origval = vm_get_register(vcpu, reg);
631-
if (error == 0) {
632-
val = byte;
633-
mask = 0xffU;
634-
if (lhbr != 0) {
635-
/*
636-
* Shift left by 8 to store 'byte' in a legacy high
637-
* byte register.
638-
*/
639-
val <<= 8;
640-
mask <<= 8;
641-
}
642-
val |= origval & ~mask;
643-
vm_set_register(vcpu, reg, val);
632+
633+
val = byte;
634+
mask = 0xffU;
635+
if (lhbr != 0) {
636+
/*
637+
* Shift left by 8 to store 'byte' in a legacy high
638+
* byte register.
639+
*/
640+
val <<= 8;
641+
mask <<= 8;
644642
}
645-
return error;
643+
val |= origval & ~mask;
644+
vm_set_register(vcpu, reg, val);
646645
}
647646

648647
static int vie_update_register(struct vcpu *vcpu, enum cpu_reg_name reg,
@@ -744,10 +743,8 @@ static int emulate_mov(struct vcpu *vcpu, struct instr_emul_vie *vie)
744743
* REX + 88/r: mov r/m8, r8 (%ah, %ch, %dh, %bh not available)
745744
*/
746745
size = 1U; /* override for byte operation */
747-
error = vie_read_bytereg(vcpu, vie, &byte);
748-
if (error == 0) {
749-
error = mmio_write(vcpu, byte);
750-
}
746+
byte = vie_read_bytereg(vcpu, vie);
747+
error = mmio_write(vcpu, byte);
751748
break;
752749
case 0x89U:
753750
/*
@@ -771,7 +768,7 @@ static int emulate_mov(struct vcpu *vcpu, struct instr_emul_vie *vie)
771768
size = 1U; /* override for byte operation */
772769
error = mmio_read(vcpu, &val);
773770
if (error == 0) {
774-
error = vie_write_bytereg(vcpu, vie, (uint8_t)val);
771+
vie_write_bytereg(vcpu, vie, (uint8_t)val);
775772
}
776773
break;
777774
case 0x8BU:

0 commit comments

Comments
 (0)