Skip to content

Commit f7b11c8

Browse files
fyin1wenlingz
authored andcommitted
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>
1 parent b2dc13d commit f7b11c8

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

hypervisor/arch/x86/guest/vcpu.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,29 @@ void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs)
229229
ctx->cr4 = vcpu_regs->cr4;
230230
}
231231

232+
static struct acrn_vcpu_regs realmode_init_regs = {
233+
.gdt = {
234+
.limit = 0xFFFFU,
235+
.base = 0UL,
236+
},
237+
.idt = {
238+
.limit = 0xFFFFU,
239+
.base = 0UL,
240+
},
241+
.cs_ar = REAL_MODE_CODE_SEG_AR,
242+
.cs_sel = REAL_MODE_BSP_INIT_CODE_SEL,
243+
.cs_base = 0xFFFF0000UL,
244+
.rip = 0xFFF0UL,
245+
.cr0 = CR0_ET | CR0_NE,
246+
.cr3 = 0UL,
247+
.cr4 = 0UL,
248+
};
249+
250+
void reset_vcpu_regs(struct vcpu *vcpu)
251+
{
252+
set_vcpu_regs(vcpu, &realmode_init_regs);
253+
}
254+
232255
/***********************************************************************
233256
*
234257
* @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)
314337
vcpu->pending_pre_work = 0U;
315338
vcpu->state = VCPU_INIT;
316339

340+
reset_vcpu_regs(vcpu);
317341
(void)memset(&vcpu->req, 0U, sizeof(struct io_request));
318342

319343
return 0;
@@ -486,6 +510,8 @@ void reset_vcpu(struct vcpu *vcpu)
486510

487511
vlapic = vcpu_vlapic(vcpu);
488512
vlapic_reset(vlapic);
513+
514+
reset_vcpu_regs(vcpu);
489515
}
490516

491517
void pause_vcpu(struct vcpu *vcpu, enum vcpu_state new_state)

hypervisor/include/arch/x86/guest/vcpu.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -286,6 +286,7 @@ void vcpu_set_cr4(struct vcpu *vcpu, uint64_t val);
286286
uint64_t vcpu_get_pat_ext(struct vcpu *vcpu);
287287
void vcpu_set_pat_ext(struct vcpu *vcpu, uint64_t val);
288288
void set_vcpu_regs(struct vcpu *vcpu, struct acrn_vcpu_regs *vcpu_regs);
289+
void reset_vcpu_regs(struct vcpu *vcpu);
289290

290291
static inline bool is_long_mode(struct vcpu *vcpu)
291292
{

0 commit comments

Comments
 (0)