kvm_cpu__reset_vcpu
guestのcpuの状態の確認と必要箇所の設定
PCの設定 #TODO arch.kern_guest_startはどこ? a0 = cpu id #TODO riscv specにある? a1 = device tree blob(が展開されているアドレス) #TODO これはどこに?riscv specにある? code:riscv/kvm-cpu.c
void kvm_cpu__reset_vcpu(struct kvm_cpu *vcpu)
{
struct kvm *kvm = vcpu->kvm;
struct kvm_mp_state mp_state;
struct kvm_one_reg reg;
unsigned long data;
if (ioctl(vcpu->vcpu_fd, KVM_GET_MP_STATE, &mp_state) < 0)
die_perror("KVM_GET_MP_STATE failed");
/*
* If MP state is stopped then it means Linux KVM RISC-V emulates
* SBI v0.2 (or higher) with HART power managment and give VCPU
* will power-up at boot-time by boot VCPU. For such VCPU, we
* don't update PC, A0 and A1 here.
*/
if (mp_state.mp_state == KVM_MP_STATE_STOPPED)
return;
reg.addr = (unsigned long)&data;
data = kvm->arch.kern_guest_start; // TODO
reg.id = RISCV_CORE_REG(regs.pc);
if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0)
die_perror("KVM_SET_ONE_REG failed (pc)");
data = vcpu->cpu_id;
reg.id = RISCV_CORE_REG(regs.a0);
if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0)
die_perror("KVM_SET_ONE_REG failed (a0)");
data = kvm->arch.dtb_guest_start;
reg.id = RISCV_CORE_REG(regs.a1);
if (ioctl(vcpu->vcpu_fd, KVM_SET_ONE_REG, ®) < 0)
die_perror("KVM_SET_ONE_REG failed (a1)");
}