diff --git a/Cargo.toml b/Cargo.toml index 7c7aa9c..5dd89e5 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -27,7 +27,9 @@ run-args = [ "none", "-cpu", "host", - "-enable-kvm" + "-enable-kvm", + "-monitor", + "telnet:127.0.0.1:5555,server,nowait" ] test-args = [ "-device", diff --git a/src/main.rs b/src/main.rs index da24ab8..fbe8103 100644 --- a/src/main.rs +++ b/src/main.rs @@ -59,12 +59,13 @@ fn kernel_main(boot_info: &'static BootInfo) -> ! { let mut vcpu = VCpu::new(phys_mem_offset.as_u64(), &mut frame_allocator); vcpu.activate(); - info!("vmlaunch..."); + info!("Starting the Virtual Machine..."); unsafe { - asm!("cli"); let vmlaunch = vmx::vmlaunch(); + info!("VMLaunch: {:?}", vmlaunch); + if vmlaunch.is_err() { let error = InstructionError::read(); let error = error.as_str(); diff --git a/src/vmm/vcpu.rs b/src/vmm/vcpu.rs index dfcc34d..27e3d70 100644 --- a/src/vmm/vcpu.rs +++ b/src/vmm/vcpu.rs @@ -81,7 +81,7 @@ impl VCpu { primary_exec_ctrl.0 |= (reserved_bits & 0xFFFFFFFF) as u32; primary_exec_ctrl.0 &= (reserved_bits >> 32) as u32; - primary_exec_ctrl.set_hlt(false); + primary_exec_ctrl.set_hlt(true); primary_exec_ctrl.set_activate_secondary_controls(false); primary_exec_ctrl.write(); @@ -284,6 +284,7 @@ impl VCpu { }; vmwrite(vmcs::guest::LDTR_ACCESS_RIGHTS, ldtr_rights.0 as u64)?; + info!("RIP: {:#x}", Self::guest as u64); vmwrite(vmcs::guest::RIP, Self::guest as u64)?; vmwrite(vmcs::guest::IA32_EFER_FULL, rdmsr(IA32_EFER))?; vmwrite(vmcs::guest::RFLAGS, 0x2)?; @@ -298,9 +299,18 @@ impl VCpu { self.vmcs.reset() } + fn guest_fn() -> ! { + loop { + unsafe { + halt(); + } + } + } + #[naked] unsafe extern "C" fn guest() -> ! { naked_asm!("hlt"); + //naked_asm!("call {guest_fn}", guest_fn = sym Self::guest_fn); } fn vmexit_handler(&mut self) -> ! {