svn commit: r237299 - in projects/amd64_xen_pv/sys/amd64: include xen

Cherry G. Mathew cherry at FreeBSD.org
Wed Jun 20 11:30:16 UTC 2012


Author: cherry
Date: Wed Jun 20 11:30:15 2012
New Revision: 237299
URL: http://svn.freebsd.org/changeset/base/237299

Log:
  Add more Xen interface primitives to privileged ops (eg: cli, load_cr3 etc )
  
  Approved by:	gibbs (implicit)

Modified:
  projects/amd64_xen_pv/sys/amd64/include/cpufunc.h
  projects/amd64_xen_pv/sys/amd64/xen/machdep.c
  projects/amd64_xen_pv/sys/amd64/xen/mm.c

Modified: projects/amd64_xen_pv/sys/amd64/include/cpufunc.h
==============================================================================
--- projects/amd64_xen_pv/sys/amd64/include/cpufunc.h	Wed Jun 20 10:59:11 2012	(r237298)
+++ projects/amd64_xen_pv/sys/amd64/include/cpufunc.h	Wed Jun 20 11:30:15 2012	(r237299)
@@ -46,9 +46,11 @@
 #ifdef XEN
 extern void xen_cli(void);
 extern void xen_sti(void);
-extern void xen_load_cr3(u_int data);
+extern u_long xen_rcr2(void);
+extern void xen_load_cr3(u_long data);
 extern void xen_tlb_flush(void);
 extern void xen_invlpg(vm_offset_t addr);
+extern void write_rflags(u_long rflags);
 extern u_long read_rflags(void);
 #endif /* XEN */
 
@@ -118,7 +120,11 @@ clflush(u_long addr)
 static __inline void
 disable_intr(void)
 {
+#ifdef XEN
+	xen_cli();
+#else
 	__asm __volatile("cli" : : : "memory");
+#endif
 }
 
 static __inline void
@@ -355,7 +361,11 @@ wbinvd(void)
 }
 
 static __inline void
+#ifdef XEN
+_write_rflags(u_long rf)
+#else
 write_rflags(u_long rf)
+#endif
 {
 	__asm __volatile("pushq %0;  popfq" : : "r" (rf));
 }
@@ -391,6 +401,9 @@ rcr2(void)
 {
 	u_long	data;
 
+#ifdef XEN
+	return (xen_rcr2());
+#endif
 	__asm __volatile("movq %%cr2,%0" : "=r" (data));
 	return (data);
 }
@@ -398,8 +411,11 @@ rcr2(void)
 static __inline void
 load_cr3(u_long data)
 {
-
+#ifdef XEN
+	xen_load_cr3(data);
+#else
 	__asm __volatile("movq %0,%%cr3" : : "r" (data) : "memory");
+#endif
 }
 
 static __inline u_long
@@ -443,8 +459,11 @@ invltlb(void)
 static __inline void
 invlpg(u_long addr)
 {
-
+#ifdef XEN
+	xen_invlpg(addr);
+#else
 	__asm __volatile("invlpg %0" : : "m" (*(char *)addr) : "memory");
+#endif
 }
 
 static __inline u_short

Modified: projects/amd64_xen_pv/sys/amd64/xen/machdep.c
==============================================================================
--- projects/amd64_xen_pv/sys/amd64/xen/machdep.c	Wed Jun 20 10:59:11 2012	(r237298)
+++ projects/amd64_xen_pv/sys/amd64/xen/machdep.c	Wed Jun 20 11:30:15 2012	(r237299)
@@ -367,7 +367,7 @@ initxen(struct start_info *si)
 
 	if (si->mod_start != 0) { /* we have a ramdisk or kernel module */
 		preload_metadata = (caddr_t)(si->mod_start);
-		// preload_bootstrap_relocate(KERNBASE); XXX: not sure this is needed.
+		preload_bootstrap_relocate(KERNBASE);
 	}
 
 	kmdp = preload_search_by_type("elf kernel");
@@ -376,8 +376,7 @@ initxen(struct start_info *si)
 
 #ifdef notyet
 	boothowto = MD_FETCH(kmdp, MODINFOMD_HOWTO, int);
-	kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *); // XXX: +
-						    // KERNBASE;
+	kern_envp = MD_FETCH(kmdp, MODINFOMD_ENVP, char *);
 #endif /* notyet */
 
 #ifdef DDB
@@ -446,8 +445,8 @@ initxen(struct start_info *si)
 
 	init_param2(physmem);
 
-	//msgbufinit(msgbufp, msgbufsize);
-	//fpuinit();
+	msgbufinit(msgbufp, msgbufsize);
+	//fpuinit(); XXX: TODO
 
 	/*
 	 * Set up thread0 pcb after fpuinit calculated pcb + fpu save
@@ -466,9 +465,6 @@ initxen(struct start_info *si)
 	_ufssel = GSEL(GUFS32_SEL, SEL_UPL);
 	_ugssel = GSEL(GUGS32_SEL, SEL_UPL);
 
-	/* console */
-	printk("Hello world!\n");
-
 	return (u_int64_t) thread0.td_pcb;
 }
 
@@ -1053,19 +1049,30 @@ printk(const char *fmt, ...)
 
 
 static __inline void
-cpu_write_rflags(u_int ef)
+cpu_write_rflags(u_long rf)
 {
-	__asm __volatile("pushl %0; popfl" : : "r" (ef));
+	__asm __volatile("pushq %0; popfq" : : "r" (rf));
 }
 
-static __inline u_int
+static __inline u_long
 cpu_read_rflags(void)
 {
-	u_int	ef;
+	u_long	rf;
+
+	__asm __volatile("pushfq; popq %0" : "=r" (rf));
+	return (rf);
+}
+
+#ifdef KTR
+static __inline u_long
+rrbp(void)
+{
+	u_long	data;
 
-	__asm __volatile("pushfl; popl %0" : "=r" (ef));
-	return (ef);
+	__asm __volatile("movq 4(%%rbp),%0" : "=r" (data));	
+	return (data);
 }
+#endif
 
 u_long
 read_rflags(void)
@@ -1082,6 +1089,17 @@ read_rflags(void)
 }
 
 void
+write_rflags(u_long rflags)
+{
+	u_int intr;
+
+	CTR2(KTR_SPARE2, "%x xen_restore_flags rflags %x", rrbp(), rflags);
+	intr = ((rflags & PSL_I) == 0);
+	__restore_flags(intr);
+	_write_rflags(rflags);
+}
+
+void
 xen_cli(void)
 {
 	CTR1(KTR_SPARE2, "%x xen_cli disabling interrupts", rrbp());
@@ -1095,6 +1113,13 @@ xen_sti(void)
 	__sti();
 }
 
+u_long
+xen_rcr2(void)
+{
+
+	return (HYPERVISOR_shared_info->vcpu_info[curcpu].arch.cr2);
+}
+
 char *console_page;
 #include <machine/tss.h>
 struct amd64tss common_tss[MAXCPU];

Modified: projects/amd64_xen_pv/sys/amd64/xen/mm.c
==============================================================================
--- projects/amd64_xen_pv/sys/amd64/xen/mm.c	Wed Jun 20 10:59:11 2012	(r237298)
+++ projects/amd64_xen_pv/sys/amd64/xen/mm.c	Wed Jun 20 11:30:15 2012	(r237299)
@@ -158,6 +158,12 @@ xen_invlpg(vm_offset_t va)
 	PANIC_IF(HYPERVISOR_mmuext_op(&op, 1, NULL, DOMID_SELF) < 0);
 }
 
+inline void
+xen_load_cr3(u_long val)
+{
+	xen_pt_switch(val);
+}
+
 void
 xen_pt_switch(vm_paddr_t kpml4phys)
 {
@@ -195,8 +201,10 @@ _xen_queue_pt_update(vm_paddr_t ptr, vm_
 {
 	SET_VCPU();
 
+#ifdef revisit
 	if (__predict_true(gdtset))	
 		mtx_assert(&vm_page_queue_mtx, MA_OWNED);
+#endif
 
 	KASSERT((ptr & 7) == 0, ("misaligned update"));
 	


More information about the svn-src-projects mailing list