socsvn commit: r238304 - soc2012/syuu/bhyve-bios/lib/libvmmapi

syuu at FreeBSD.org syuu at FreeBSD.org
Mon Jun 25 23:08:37 UTC 2012


Author: syuu
Date: Mon Jun 25 23:08:35 2012
New Revision: 238304
URL: http://svnweb.FreeBSD.org/socsvn/?view=rev&rev=238304

Log:
  remove unnecessary codes, set entry point to 0x0 temporarily, set up registers as initial value of PC startup(referencing Intel SDM vol.3 section 9.1)

Modified:
  soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi.h
  soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi_bios.c

Modified: soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi.h
==============================================================================
--- soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi.h	Mon Jun 25 23:05:03 2012	(r238303)
+++ soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi.h	Mon Jun 25 23:08:35 2012	(r238304)
@@ -101,8 +101,5 @@
 /*
  * BIOS boot specific APIs
  */
-int	vm_setup_bios_registers(struct vmctx *ctx, int vcpu,
-				uint64_t rip, uint64_t cr3, uint64_t gdtbase,
-				uint64_t rsp);
-void	vm_setup_bios_gdt(uint64_t *gdtr);
+int	vm_setup_bios_registers(struct vmctx *ctx, int vcpu);
 #endif	/* _VMMAPI_H_ */

Modified: soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi_bios.c
==============================================================================
--- soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi_bios.c	Mon Jun 25 23:05:03 2012	(r238303)
+++ soc2012/syuu/bhyve-bios/lib/libvmmapi/vmmapi_bios.c	Mon Jun 25 23:08:35 2012	(r238304)
@@ -37,145 +37,189 @@
 
 #include "vmmapi.h"
 
-#ifndef	CR4_VMXE
-#define	CR4_VMXE	(1UL << 13)
-#endif
-
-#define	DESC_UNUSABLE		0x00010000
-
-#define	GUEST_NULL_SEL		0
-#define	GUEST_CODE_SEL		1
-#define	GUEST_DATA_SEL		2
-#define	GUEST_GDTR_LIMIT	(3 * 8 - 1)
-
-void     
-vm_setup_bios_gdt(uint64_t *gdtr)
-{       
-	gdtr[GUEST_NULL_SEL] = 0;
-	gdtr[GUEST_CODE_SEL] = 0x0020980000000000;
-	gdtr[GUEST_DATA_SEL] = 0x0000900000000000;
-}
-
 /*
  * Setup the 'vcpu' register set such that it will begin execution at
  * 'rip' in long mode.
  */
 int
-vm_setup_bios_registers(struct vmctx *vmctx, int vcpu,
-			uint64_t rip, uint64_t cr3, uint64_t gdtbase,
-			uint64_t rsp)
+vm_setup_bios_registers(struct vmctx *vmctx, int vcpu)
 {
 	int error;
-	uint64_t cr0, cr4, efer, rflags, desc_base;
+	uint64_t rip, cr0, cr3, cr4, efer, rflags, rax, rbx, rcx, rdx;
+	uint64_t rsi, rdi, rbp, rsp, desc_base;
 	uint32_t desc_access, desc_limit;
+	uint16_t gsel;
 
-	cr0 = CR0_NE;
+#if 0
+	rip = 0xfff0;
+#endif
+	rip = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, rip)) != 0)
+		goto done;
+
+	rflags = 0x2;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags))	!= 0)
+		goto done;
+
+	cr0 = 0x60000010;
 	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR0, cr0)) != 0)
 		goto done;
 
+	cr3 = 0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR3, cr3)) != 0)
+		goto done;
+
 	cr4 = 0;
 	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR4, cr4)) != 0)
 		goto done;
 
-	efer = 0;
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_EFER, efer)))
+#if 0
+	desc_base = 0xffff0000;
+#endif
+	desc_base = 0x0;
+	desc_limit = 0xffff;
+	/* PRESENT | DESC_TYPE_CODEDATA | SEG_TYPE_DATA_RW_ACCESSED */
+	desc_access = 0x00000093;
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS,
+			    desc_base, desc_limit, desc_access);
+	if (error)
 		goto done;
 
-	rflags = 0x2;
-	error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RFLAGS, rflags);
-	if (error)
+#if 0
+	gsel = 0xf000;
+#endif
+	gsel = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, gsel)) != 0)
 		goto done;
 
-	desc_base = 0;
-	desc_limit = 0;
-	desc_access = 0x0000209B;
-	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_CS,
+	desc_base = 0x0;
+	desc_limit = 0xffff;
+	/* PRESENT | DESC_TYPE_CODEDATA | SEG_TYPE_DATA_RW_ACCESSED */
+	desc_access = 0x00000093;
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS,
 			    desc_base, desc_limit, desc_access);
 	if (error)
 		goto done;
 
-	desc_access = 0x00000093;
+	gsel = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, gsel)) != 0)
+		goto done;
+
+	/* same as SS */
 	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_DS,
 			    desc_base, desc_limit, desc_access);
 	if (error)
 		goto done;
 
+	/* same as SS */
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, gsel)) != 0)
+		goto done;
+
+	/* same as SS */
 	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_ES,
 			    desc_base, desc_limit, desc_access);
 	if (error)
 		goto done;
 
+	/* same as SS */
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, gsel)) != 0)
+		goto done;
+
+	/* same as SS */
 	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_FS,
 			    desc_base, desc_limit, desc_access);
 	if (error)
 		goto done;
 
+	/* same as SS */
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, gsel)) != 0)
+		goto done;
+
+	/* same as SS */
 	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GS,
 			    desc_base, desc_limit, desc_access);
 	if (error)
 		goto done;
 
-	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_SS,
-			    desc_base, desc_limit, desc_access);
-	if (error)
+	/* same as SS */
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, gsel)) != 0)
 		goto done;
 
-	/*
-	 * XXX TR is pointing to null selector even though we set the
-	 * TSS segment to be usable with a base address and limit of 0.
-	 */
-	desc_access = 0x0000008b;
-	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR, 0, 0, desc_access);
-	if (error)
+	rdx = 0xf00;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDX, rdx)) != 0)
 		goto done;
 
-	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR, 0, 0,
-			    DESC_UNUSABLE);
-	if (error)
+	rax = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RAX, rax)) != 0)
 		goto done;
 
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CS, 0)) != 0)
+	rbx = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBX, rbx)) != 0)
 		goto done;
-	
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_DS, 0)) != 0)
+
+	rcx = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RCX, rcx)) != 0)
 		goto done;
-	
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_ES, 0)) != 0)
+
+	rsi = 0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSI, rsi)) != 0)
 		goto done;
 
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_FS, 0)) != 0)
+	rdi = 0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RDI, rdi)) != 0)
 		goto done;
-	
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_GS, 0)) != 0)
+
+	rbp = 0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RBP, rbp)) != 0)
 		goto done;
-	
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_SS, 0)) != 0)
+
+	rsp = 0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, rsp)) != 0)
 		goto done;
 
-	/* XXX TR is pointing to the null selector */
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, 0)) != 0)
+	desc_base = 0x0;
+	desc_limit = 0xffff;
+	/* PRESENT | DESC_TYPE_CODEDATA | SEG_TYPE_DATA_RW */
+	desc_access = 0x00000092;
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR,
+			    desc_base, desc_limit, desc_access);
+	if (error != 0)
 		goto done;
 
-	/* LDTR is pointing to the null selector */
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, 0)) != 0)
+	/* same as GDTR */
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_IDTR,
+			    desc_base, desc_limit, desc_access);
+	if (error != 0)
 		goto done;
 
-	/* entry point */
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RIP, rip)) != 0)
+	desc_base = 0x0;
+	desc_limit = 0xffff;
+	/* PRESENT | SEG_TYPE_16BIT_BUSY_TSS */
+	desc_access = 0x00000083;
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_TR,
+			    desc_base, desc_limit, desc_access);
+	if (error)
 		goto done;
 
-	/* page table base */
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_CR3, 0)) != 0)
+	gsel = 0x0;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_TR, gsel)) != 0)
 		goto done;
 
-	desc_base = gdtbase;
-	desc_limit = GUEST_GDTR_LIMIT;
-	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_GDTR,
-			    desc_base, desc_limit, 0);
-	if (error != 0)
+	desc_base = 0x0;
+	desc_limit = 0xffff;
+	/* PRESENT | SEG_TYPE_LDT */
+	desc_access = 0x00000082;
+	error = vm_set_desc(vmctx, vcpu, VM_REG_GUEST_LDTR,
+			    desc_base, desc_limit, desc_access);
+	if (error)
 		goto done;
 
-	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_RSP, rsp)) != 0)
+	/* same as TR */
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_LDTR, gsel)) != 0)
+		goto done;
+
+	efer = 0x9;
+	if ((error = vm_set_register(vmctx, vcpu, VM_REG_GUEST_EFER, efer)) != 0)
 		goto done;
 
 	error = 0;


More information about the svn-soc-all mailing list