3434#include "include/cpuid.h"
3535#include "include/vcpu.h"
3636#include "include/debug.h"
37- #include "include/dump_vmcs.h"
37+ #include "include/dump.h"
38+ #include "include/name.h"
3839#include "include/vtlb.h"
3940#include "include/intr.h"
4041#include "include/ept.h"
@@ -131,42 +132,23 @@ void cpu_init_vmx(void *arg)
131132 /* get VMX capabilities */
132133 vmx_read_info (& vmx_info );
133134#if 0
134- //hax_log ("-----------cpu %d---------------\n", cpu_data->cpu_id);
135+ //hax_info ("-----------cpu %d---------------\n", cpu_data->cpu_id);
135136
136137 if ((cpu_data -> cpu_id == 0 ||
137138 memcmp (& vmx_info , & hax_cpu_data [0 ]-> vmx_info ,
138139 sizeof (vmx_info )) != 0 )) {
139- hax_log ("HAX: VMCS Rev %d\n" , vmx_info ._vmcs_revision_id );
140-
141- hax_log ("HAX: VMX basic info : %016llx\n" , vmx_info ._basic_info );
142- hax_log ("HAX: VMX misc info : %08llx\n" , vmx_info ._miscellaneous );
143- hax_log ("HAX: VMX revision control: %d\n" , vmx_info ._vmcs_revision_id );
144- hax_log ("HAX: VMX exit ctls : %x, %x\n" , vmx_info .exit_ctls_0 ,
145- vmx_info .exit_ctls_1 );
146- hax_log ("HAX: VMX entry ctls : %x, %x\n" , vmx_info .entry_ctls_0 ,
147- vmx_info .entry_ctls_1 );
148- hax_log ("HAX: VMX pin ctls : %x, %x\n" , vmx_info .pin_ctls_0 ,
149- vmx_info .pin_ctls_1 );
150- hax_log ("HAX: VMX cpu prim ctrls : %x, %x\n" , vmx_info .pcpu_ctls_0 ,
151- vmx_info .pcpu_ctls_1 );
152- hax_log ("HAX: VMX cpu sec ctrl : %x, %x\n" , vmx_info .scpu_ctls_0 ,
153- vmx_info .scpu_ctls_1 );
154- hax_log ("HAX: VMX fixed CR0 bits : %llx, %llx\n" , vmx_info ._cr0_fixed_0 ,
155- vmx_info ._cr0_fixed_1 );
156- hax_log ("HAX: VMX fixed CR4 bits : %llx, %llx\n" , vmx_info ._cr4_fixed_0 ,
157- vmx_info ._cr4_fixed_1 );
158- hax_log ("HAX: VMX EPT/VPID caps : %016llx\n" , vmx_info ._ept_cap );
140+ dump_vmx_info (& vmx_info );
159141 }
160142#endif
161143
162144 if (vmx_info ._vmcs_region_length > HAX_PAGE_SIZE )
163- hax_log ( "HAX: VMCS of %d bytes not supported by this Hypervisor. "
145+ hax_info ( " VMCS of %d bytes not supported by this Hypervisor. "
164146 "Max supported %u bytes\n" ,
165147 vmx_info ._vmcs_region_length , (uint32_t )HAX_PAGE_SIZE );
166148 vmxon = (vmcs_t * )hax_page_va (cpu_data -> vmxon_page );
167149 vmxon -> _revision_id = vmx_info ._vmcs_revision_id ;
168150
169- //hax_log("HAX: enabled VMX mode (vmxon = %p)\n",
151+ //hax_info(" enabled VMX mode (vmxon = %p)\n",
170152 // hax_page_va(cpu_data->vmxon_page));
171153
172154 vmx_read_info (& cpu_data -> vmx_info );
@@ -282,44 +264,6 @@ static int cpu_vmexit_handler(struct vcpu_t *vcpu, exit_reason_t exit_reason,
282264 }
283265 return ret ;
284266}
285- /*Remove this function. It only for debug*/
286- /*void dump_cs_ds(uint16_t cs, uint16_t ds)
287- {
288- struct system_desc_t desc;
289- struct seg_desc_t *seg_desc;
290-
291- get_kernel_gdt(&desc);
292-
293- seg_desc = (struct seg_desc_t *)((mword)desc._base) + (cs >> 3);
294-
295- hax_debug("\nsel: %x\n", cs >> 3);
296- hax_debug("type: %x\n", seg_desc->_type);
297- hax_debug("s: %x\n", seg_desc->_s);
298- hax_debug("present: %x\n", seg_desc->_present);
299- hax_debug("avl: %x\n", seg_desc->_avl);
300- hax_debug("long: %x\n", seg_desc->_longmode);
301- hax_debug("d/b: %x\n", seg_desc->_d);
302- hax_debug("g: %x\n", seg_desc->_granularity);
303- hax_debug("base0: %x\n", seg_desc->_base0);
304- hax_debug("limit: %x\n", seg_desc->_limit0);
305- hax_debug("dpl: %x\n", seg_desc->_limit0);
306-
307- hax_debug("raw: %llx\n", seg_desc->_raw);
308- seg_desc = (struct seg_desc_t *)((mword)desc._base) + (ds >> 3);
309-
310- hax_debug("\nsel: %x\n", ds >> 3);
311- hax_debug("type: %x\n", seg_desc->_type);
312- hax_debug("s: %x\n", seg_desc->_s);
313- hax_debug("present: %x\n", seg_desc->_present);
314- hax_debug("avl: %x\n", seg_desc->_avl);
315- hax_debug("long: %x\n", seg_desc->_longmode);
316- hax_debug("d/b: %x\n", seg_desc->_d);
317- hax_debug("g: %x\n", seg_desc->_granularity);
318- hax_debug("base0: %x\n", seg_desc->_base0);
319- hax_debug("limit: %x\n", seg_desc->_limit0);
320- hax_debug("dpl: %x\n", seg_desc->_dpl);
321- hax_debug("raw: %llx\n", seg_desc->_raw);
322- }*/
323267
324268#ifdef CONFIG_DARWIN
325269__attribute__ ((__noinline__ ))
@@ -450,7 +394,7 @@ int cpu_vmx_execute(struct vcpu_t *vcpu, struct hax_tunnel *htun)
450394
451395 res = cpu_vmx_run (vcpu , htun );
452396 if (res ) {
453- hax_debug ("cpu_vmx_run error, code:%xlx \n" , res );
397+ hax_error ("cpu_vmx_run error, code:%x \n" , res );
454398 if ((vmcs_err = put_vmcs (vcpu , & flags ))) {
455399 hax_panic_vcpu (vcpu , "put_vmcs fail: %x\n" , vmcs_err );
456400 hax_panic_log (vcpu );
@@ -601,7 +545,7 @@ uint32_t load_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
601545
602546
603547 if (asm_vmptrld (& vmcs_phy ) != VMX_SUCCEED ) {
604- hax_error ("HAX: vmptrld failed (%08llx)\n" , vmcs_phy );
548+ hax_error ("vmptrld failed (%08llx)\n" , vmcs_phy );
605549 cpu_vmxroot_leave ();
606550 log_vmxon_err_type3 = 1 ;
607551 hax_enable_preemption (flags );
@@ -625,7 +569,7 @@ void restore_host_cr4_vmxe(struct per_cpu_data *cpu_data)
625569 if (cpu_data -> vmm_flag & VMXON_HAX ) {
626570 // TODO: Need to understand why this happens (on both Windows and
627571 // macOS)
628- hax_debug ("HAX: VMM flag (VMON_HAX) is not clear!\n" );
572+ hax_debug ("VMM flag (VMON_HAX) is not clear!\n" );
629573 }
630574 set_cr4 (get_cr4 () | CR4_VMXE );
631575 } else {
@@ -649,7 +593,7 @@ uint32_t put_vmcs(struct vcpu_t *vcpu, preempt_flag *flags)
649593 vmcs_phy = hax_page_pa (cpu_data -> vmcs_page );
650594
651595 if (asm_vmclear (& vmcs_phy ) != VMX_SUCCEED ) {
652- hax_error ("HAX: vmclear failed (%llx)\n" , vmcs_phy );
596+ hax_error ("vmclear failed (%llx)\n" , vmcs_phy );
653597 log_vmclear_err = 1 ;
654598 }
655599
@@ -700,22 +644,22 @@ void load_vmcs_common(struct vcpu_t *vcpu)
700644
701645static void cpu_vmentry_failed (struct vcpu_t * vcpu , vmx_result_t result )
702646{
703- hax_debug ("HAX: VM entry failed: result=%x RIP=%08lx\n" ,
704- result , (mword )vmread (vcpu , GUEST_RIP ));
647+ uint64_t error , reason ;
648+
649+ hax_error ("VM entry failed: RIP=%08lx\n" ,
650+ (mword )vmread (vcpu , GUEST_RIP ));
705651
706652 //dump_vmcs();
707653
654+ reason = vmread (vcpu , VM_EXIT_INFO_REASON );
708655 if (result == VMX_FAIL_VALID ) {
709- hax_log ( "HAX: Prev exit: %llx error code: %llx\n" ,
710- vmread ( vcpu , VM_EXIT_INFO_REASON ) ,
711- vmread ( vcpu , VMX_INSTRUCTION_ERROR_CODE ));
656+ error = vmread ( vcpu , VMX_INSTRUCTION_ERROR_CODE );
657+ hax_error ( "VMfailValid. Prev exit: %llx. Error code: %llu (%s)\n" ,
658+ reason , error , name_vmx_error ( error ));
712659 } else {
713- hax_log ( "HAX: Prev exit: %llx no error code\n" ,
714- vmread ( vcpu , VM_EXIT_INFO_REASON ) );
660+ hax_error ( "VMfailInvalid. Prev exit: %llx no error code\n" ,
661+ reason );
715662 }
716-
717- hax_log ("HAX: VM entry failed\n" );
718- hax_log ("end of cpu_vmentry_failed\n" );
719663}
720664
721665vmx_result_t cpu_vmxroot_leave (void )
0 commit comments