#include <palacios/vmm_cpuid.h>
#include <palacios/vmm_direct_paging.h>
+#ifndef V3_CONFIG_DEBUG_SVM
+#undef PrintDebug
+#define PrintDebug(fmt, args...)
+#endif
-#ifdef CONFIG_TELEMETRY
+#ifdef V3_CONFIG_TELEMETRY
#include <palacios/vmm_telemetry.h>
#endif
-
+#ifdef V3_CONFIG_EXT_SW_INTERRUPTS
+#include <gears/sw_intr.h>
+#endif
int v3_handle_svm_exit(struct guest_info * info, addr_t exit_code, addr_t exit_info1, addr_t exit_info2) {
-#ifdef CONFIG_TELEMETRY
+#ifdef V3_CONFIG_TELEMETRY
if (info->vm_info->enable_telemetry) {
v3_telemetry_start_exit(info);
}
#endif
-#if 0
- if (info->cpu_id==1) {
- V3_Print("Core 1 SVM Exit: %s rip=0x%p\n", vmexit_code_to_str(exit_code), (void *) get_addr_linear(info, info->rip, &(info->segments.cs)));
- }
-#endif
- //PrintDebug("SVM Returned: Exit Code: %x\n",exit_code);
+
+ // PrintDebug("SVM Returned: Exit Code: %p\n", (void *)exit_code);
switch (exit_code) {
case VMEXIT_IOIO: {
break;
case VMEXIT_CR0_WRITE:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR0 Write\n");
#endif
if (v3_handle_cr0_write(info) == -1) {
}
break;
case VMEXIT_CR0_READ:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR0 Read\n");
#endif
if (v3_handle_cr0_read(info) == -1) {
}
break;
case VMEXIT_CR3_WRITE:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR3 Write\n");
#endif
if (v3_handle_cr3_write(info) == -1) {
break;
case VMEXIT_CR3_READ:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR3 Read\n");
#endif
if (v3_handle_cr3_read(info) == -1) {
}
break;
case VMEXIT_CR4_WRITE:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR4 Write\n");
#endif
if (v3_handle_cr4_write(info) == -1) {
}
break;
case VMEXIT_CR4_READ:
-#ifdef CONFIG_DEBUG_CTRL_REGS
+#ifdef V3_CONFIG_DEBUG_CTRL_REGS
PrintDebug("CR4 Read\n");
#endif
if (v3_handle_cr4_read(info) == -1) {
case VMEXIT_EXCP14: {
addr_t fault_addr = exit_info2;
pf_error_t * error_code = (pf_error_t *)&(exit_info1);
-#ifdef CONFIG_DEBUG_SHADOW_PAGING
+#ifdef V3_CONFIG_DEBUG_SHADOW_PAGING
PrintDebug("PageFault at %p (error=%d)\n",
(void *)fault_addr, *(uint_t *)error_code);
#endif
-#if 0
- if (info->cpu_id==1) {
- V3_Print("SVM Core 1: PageFault at %p (error=%d)\n",
- (void *)fault_addr, *(uint_t *)error_code);
- }
-#endif
if (info->shdw_pg_mode == SHADOW_PAGING) {
if (v3_handle_shadow_pagefault(info, fault_addr, *error_code) == -1) {
return -1;
}
case VMEXIT_INVLPG:
if (info->shdw_pg_mode == SHADOW_PAGING) {
-#ifdef CONFIG_DEBUG_SHADOW_PAGING
+#ifdef V3_CONFIG_DEBUG_SHADOW_PAGING
PrintDebug("Invlpg\n");
#endif
if (v3_handle_shadow_invlpg(info) == -1) {
return -1;
}
- break;
+ break;
+ case VMEXIT_NMI:
+ // handled by interrupt dispatcher
+ break;
case VMEXIT_INTR:
// handled by interrupt dispatch earlier
break;
// handle_svm_smi(info); // ignored for now
break;
case VMEXIT_HLT:
-#ifdef CONFIG_DEBUG_HALT
+#ifdef V3_CONFIG_DEBUG_HALT
PrintDebug("Guest halted\n");
#endif
if (v3_handle_halt(info) == -1) {
}
break;
case VMEXIT_WBINVD:
-#ifdef CONFIG_DEBUG_EMULATOR
+#ifdef V3_CONFIG_DEBUG_EMULATOR
PrintDebug("WBINVD\n");
#endif
if (v3_handle_svm_wbinvd(info) == -1) {
return -1;
}
break;
-
+ case VMEXIT_RDTSC:
+#ifdef V3_CONFIG_DEBUG_TIME
+ PrintDebug("RDTSC/RDTSCP\n");
+#endif
+ if (v3_handle_rdtsc(info) == -1) {
+ PrintError("Error Handling RDTSC instruction\n");
+ return -1;
+ }
+ break;
+ case VMEXIT_RDTSCP:
+#ifdef V3_CONFIG_DEBUG_TIME
+ PrintDebug("RDTSCP\n");
+#endif
+ if (v3_handle_rdtscp(info) == -1) {
+ PrintError("Error Handling RDTSCP instruction\n");
+ return -1;
+ }
+ break;
+ case VMEXIT_SHUTDOWN:
+ PrintDebug("Guest-initiated shutdown\n");
+
+ info->vm_info->run_state = VM_STOPPED;
+ // Force exit on other cores
+ break;
+#ifdef V3_CONFIG_EXT_SW_INTERRUPTS
+ case VMEXIT_SWINT:
+#ifdef V3_CONFIG_DEBUG_EXT_SW_INTERRUPTS
+ PrintDebug("Intercepted a software interrupt\n");
+#endif
+ if (v3_handle_swintr(info) == -1) {
+ PrintError("Error handling software interrupt\n");
+ return -1;
+ }
+ break;
+#endif
/* Exits Following this line are NOT HANDLED */
addr_t rip_addr;
- PrintDebug("Unhandled SVM Exit: %s\n", vmexit_code_to_str(exit_code));
+ PrintError("Unhandled SVM Exit: %s\n", vmexit_code_to_str(exit_code));
rip_addr = get_addr_linear(info, info->rip, &(info->segments.cs));
PrintError("SVM Returned: Exit Code: %p\n", (void *)(addr_t)exit_code);
PrintError("io_info1 low = 0x%.8x\n", *(uint_t*)&(exit_info1));
- PrintError("io_info1 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(exit_info1)) + 4));
+ PrintError("io_info1 high = 0x%.8x\n", *(uint_t *)(((uint8_t *)&(exit_info1)) + 4));
PrintError("io_info2 low = 0x%.8x\n", *(uint_t*)&(exit_info2));
- PrintError("io_info2 high = 0x%.8x\n", *(uint_t *)(((uchar_t *)&(exit_info2)) + 4));
+ PrintError("io_info2 high = 0x%.8x\n", *(uint_t *)(((uint8_t *)&(exit_info2)) + 4));
if (info->shdw_pg_mode == SHADOW_PAGING) {
}
// END OF SWITCH (EXIT_CODE)
-#ifdef CONFIG_TELEMETRY
+#ifdef V3_CONFIG_TELEMETRY
if (info->vm_info->enable_telemetry) {
v3_telemetry_end_exit(info, exit_code);
}