hv: add function to reset vcpu registers

This reset_vcpu_regs function will reset the vcpu registers to
default value: realmode with entry 0xFFFFFFF0

Make call to reset_vcpu_regs during create_vcpu and reset_vcpu

Tracked-On: #1231
Signed-off-by: Yin Fengwei <fengwei.yin@intel.com>
Acked-by: Eddie Dong <eddie.dong@intel.com>
This commit is contained in:
Yin Fengwei 2018-09-29 20:45:46 +08:00 committed by wenlingz
parent b2dc13d763
commit f7b11c8341
2 changed files with 27 additions and 0 deletions

View File

@ -229,6 +229,29 @@ void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs)
ctx->cr4 = vcpu_regs->cr4;
}
static struct acrn_vcpu_regs realmode_init_regs = {
.gdt = {
.limit = 0xFFFFU,
.base = 0UL,
},
.idt = {
.limit = 0xFFFFU,
.base = 0UL,
},
.cs_ar = REAL_MODE_CODE_SEG_AR,
.cs_sel = REAL_MODE_BSP_INIT_CODE_SEL,
.cs_base = 0xFFFF0000UL,
.rip = 0xFFF0UL,
.cr0 = CR0_ET | CR0_NE,
.cr3 = 0UL,
.cr4 = 0UL,
};
void reset_vcpu_regs(struct vcpu *vcpu)
{
set_vcpu_regs(vcpu, &realmode_init_regs);
}
/***********************************************************************
*
* @pre vm != NULL && rtn_vcpu_handle != NULL
@ -314,6 +337,7 @@ int create_vcpu(uint16_t pcpu_id, struct vm *vm, struct vcpu **rtn_vcpu_handle)
vcpu->pending_pre_work = 0U;
vcpu->state = VCPU_INIT;
reset_vcpu_regs(vcpu);
(void)memset(&vcpu->req, 0U, sizeof(struct io_request));
return 0;
@ -486,6 +510,8 @@ void reset_vcpu(struct vcpu *vcpu)
vlapic = vcpu_vlapic(vcpu);
vlapic_reset(vlapic);
reset_vcpu_regs(vcpu);
}
void pause_vcpu(struct vcpu *vcpu, enum vcpu_state new_state)

View File

@ -286,6 +286,7 @@ void vcpu_set_cr4(struct vcpu *vcpu, uint64_t val);
uint64_t vcpu_get_pat_ext(struct vcpu *vcpu);
void vcpu_set_pat_ext(struct vcpu *vcpu, uint64_t val);
void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs);
void reset_vcpu_regs(struct vcpu *vcpu);
static inline bool is_long_mode(struct vcpu *vcpu)
{