diff --git a/arch/arm64/core/virtualization/trap_handler.c b/arch/arm64/core/virtualization/trap_handler.c index 6f3ca20149fabca0ed6ad9cca9f01b5a991b7698..b93d78c846179d43113cc4e180e6ea01a1fcc69b 100644 --- a/arch/arm64/core/virtualization/trap_handler.c +++ b/arch/arm64/core/virtualization/trap_handler.c @@ -175,13 +175,69 @@ static int cpu_il_exe_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) return 0; } +/* get the hvc 24-0 */ +#define BIT_MASK0(last, first) \ + ((0xffffffffffffffffULL >> (64 - ((last) + 1 - (first)))) << (first)) + +#define GET_FIELD(value, last, first) \ + (((value) & BIT_MASK0((last), (first))) >> (first)) + +#define ESR_ISS(esr) GET_FIELD((esr), 24, 0) + +static struct k_spinlock shell_vmops_lock_hvc; + static int cpu_hvc64_sync(arch_commom_regs_t *arch_ctxt, uint64_t esr_elx) { + k_spinlock_key_t key; + key = k_spin_lock(&shell_vmops_lock_hvc); + int ret = 0; + ARG_UNUSED(arch_ctxt); ARG_UNUSED(esr_elx); + + unsigned long esr_el_2= ESR_ISS(esr_elx); + unsigned long code = GET_FIELD((esr_elx),15,0); + + char *args0[] = {"new", "-t", "zephyr"}; + char *args1[] = {"run", "-n", "0"}; + char *args2[] = {"pause", "-n", "0"}; + char *args3[] = {"delete", "-n", "0"}; + char *args4[] = {"info"}; + + switch (code) + { + case 1: + /* create a zephyr vm */ + ret = zvm_new_guest(3, args0); + /* show zephyr vm information*/ + ret = zvm_info_guest(3, args4); + break; + case 2: + /* run the zephyr vm*/ + ret = zvm_run_guest(3, args1); + break; + case 3: + /* pause the created zephyr vm */ + ret = zvm_pause_guest(3, args2); + break; + case 4: + /* stop the zephyr */ + ZVM_LOG_WARN("CAN NOT DELETE NOW! \n "); + break; + default: + ZVM_LOG_WARN("UNKNOWN CODE\n "); + break; + } + k_spin_unlock(&shell_vmops_lock_hvc, key); #ifdef CONFIG_ZVM_TIME_MEASURE vm_irq_timing_print(); #endif + /**The hvc instruction defaults to adding +0x4 to the PC value, + * but zvm has already performed +0x4 during processing, causing + * a skip of the next assembly instruction. Here, -0x4 is used + * to fix this bug. + */ + arch_ctxt->pc -= 0x4; return 0; } diff --git a/subsys/virtualization/vm_cpu.c b/subsys/virtualization/vm_cpu.c index 35ce98b7307af73741c5689fa559c8a84d868688..a62dced12caad77f6adc2598c0c16c4016ce879c 100644 --- a/subsys/virtualization/vm_cpu.c +++ b/subsys/virtualization/vm_cpu.c @@ -99,7 +99,7 @@ static void vcpu_context_switch(struct k_thread *new_thread, break; } } - ZVM_LOG_INFO("** load_vcpu_context, thread: %p, new vcpu thread? : %d \n ", new_thread, VCPU_THREAD(new_thread)); + if (VCPU_THREAD(new_thread)) { struct vcpu *new_vcpu = new_thread->vcpu_struct;