PERFORCE change 89079 for review
Scott Long
scottl at FreeBSD.org
Tue Jan 3 00:08:51 PST 2006
http://perforce.freebsd.org/chv.cgi?CH=89079
Change 89079 by scottl at scottl-junior on 2006/01/03 08:08:13
Import the Xen3 code as of Jan 2, 2006
Affected files ...
.. //depot/projects/xen3/src/sys/conf/Makefile.i386-xen#1 add
.. //depot/projects/xen3/src/sys/conf/files#2 edit
.. //depot/projects/xen3/src/sys/conf/files.i386-xen#1 add
.. //depot/projects/xen3/src/sys/conf/ldscript.i386-xen#1 add
.. //depot/projects/xen3/src/sys/conf/options.i386-xen#1 add
.. //depot/projects/xen3/src/sys/dev/xen/blkfront/blkfront.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/blkfront/block.h#1 add
.. //depot/projects/xen3/src/sys/dev/xen/console/console.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/console/xencons_ring.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/console/xencons_ring.h#1 add
.. //depot/projects/xen3/src/sys/dev/xen/evtchn/evtchn_dev.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/netfront/netfront.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/init.txt#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_client.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_comms.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_comms.h#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_dev.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_probe.c#1 add
.. //depot/projects/xen3/src/sys/dev/xen/xenbus/xenbus_xs.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/conf/XENCONF#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/clock.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/evtchn.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/gnttab.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/hypervisor.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/machdep.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/pmap.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_bus.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/i386-xen/xen_machdep.c#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/_bus.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/_inttypes.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/_limits.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/_stdint.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/_types.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/acpica_machdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/apicreg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/apicvar.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/apm_bios.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/apm_segments.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/asm.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/asmacros.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/atomic.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/bootinfo.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/bus.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/bus_dma.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/clock.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/cpu.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/cpufunc.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/cputypes.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/cserial.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/db_machdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/elan_mmcr.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/elf.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/endian.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/evtchn.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/exec.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/float.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/floatingpoint.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/frame.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/gdb_machdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/gnttab.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/hypercall.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/hypervisor-ifs.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/hypervisor.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_cause.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_debug.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_ioctl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_rbch_ioctl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_tel_ioctl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/i4b_trace.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ieeefp.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/if_wl_wavelan.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/in_cksum.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/intr_machdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ioctl_bt848.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ioctl_meteor.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/iodev.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/kdb.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/legacyvar.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/limits.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/macros.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/md_var.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/memdev.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/metadata.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/mp_watchdog.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/mptable.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/multicall.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/mutex.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/npx.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/param.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pcaudioio.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pcb.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pcb_ext.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pci_cfgreg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pcpu.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pcvt_ioctl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pecoff_machdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/perfmon.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pmap.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/pmc_mdep.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ppireg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/privatespace.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/proc.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/profile.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/psl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ptrace.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/reg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/reloc.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/resource.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/runq.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/segments.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/setjmp.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/sf_buf.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/sigframe.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/signal.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/smapi.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/smp.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/smptests.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/speaker.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/specialreg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/stdarg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/synch_bitops.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/sysarch.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/timerreg.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/trap.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/tss.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/ucontext.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/varargs.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/vm86.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/vmparam.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xbox.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-os.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/COPYING#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/acm.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/acm_ops.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/arch-ia64.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/arch-x86_32.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/arch-x86_64.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/dom0_ops.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/event_channel.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/grant_table.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/blkif.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/console.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/ioreq.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/netif.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/ring.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/tpmif.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/xenbus.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/io/xs_wire.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/memory.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/physdev.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/sched.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/sched_ctl.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/trace.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/vcpu.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/version.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/vmx_assist.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen-public/xen.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xen_intr.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xenbus.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xenfunc.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xenpmap.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xenstored.h#1 add
.. //depot/projects/xen3/src/sys/i386-xen/include/xenvar.h#1 add
.. //depot/projects/xen3/src/sys/i386/i386/genassym.c#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/i686_mem.c#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/initcpu.c#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/locore.s#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/support.s#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/swtch.s#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/sys_machdep.c#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/trap.c#2 edit
.. //depot/projects/xen3/src/sys/i386/i386/vm_machdep.c#2 edit
.. //depot/projects/xen3/src/sys/i386/include/asmacros.h#2 edit
.. //depot/projects/xen3/src/sys/i386/include/pcpu.h#2 edit
.. //depot/projects/xen3/src/sys/i386/include/pmap.h#2 edit
.. //depot/projects/xen3/src/sys/i386/include/segments.h#2 edit
.. //depot/projects/xen3/src/sys/i386/include/trap.h#2 edit
.. //depot/projects/xen3/src/sys/i386/isa/npx.c#2 edit
Differences ...
==== //depot/projects/xen3/src/sys/conf/files#2 (text+ko) ====
@@ -1399,6 +1399,7 @@
libkern/strncpy.c standard
libkern/strsep.c standard
libkern/strspn.c standard
+libkern/strcspn.c standard
libkern/strtol.c standard
libkern/strtoq.c standard
libkern/strtoul.c standard
==== //depot/projects/xen3/src/sys/i386/i386/genassym.c#2 (text+ko) ====
@@ -199,6 +199,7 @@
ASSYM(PC_CURPMAP, offsetof(struct pcpu, pc_curpmap));
ASSYM(PC_PRIVATE_TSS, offsetof(struct pcpu, pc_private_tss));
+
#ifdef DEV_APIC
ASSYM(LA_VER, offsetof(struct LAPIC, version));
ASSYM(LA_TPR, offsetof(struct LAPIC, tpr));
@@ -226,3 +227,8 @@
ASSYM(BUS_SPACE_HANDLE_BASE, offsetof(struct bus_space_handle, bsh_base));
ASSYM(BUS_SPACE_HANDLE_IAT, offsetof(struct bus_space_handle, bsh_iat));
#endif
+
+#ifdef XEN
+ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3));
+ASSYM(HYPERVISOR_STACK_SWITCH, __HYPERVISOR_stack_switch);
+#endif
==== //depot/projects/xen3/src/sys/i386/i386/i686_mem.c#2 (text+ko) ====
@@ -609,12 +609,16 @@
i686_mem_drvinit(void *unused)
{
/* Try for i686 MTRRs */
+#ifndef XEN
if (!mtrrs_disabled && (cpu_feature & CPUID_MTRR) &&
((cpu_id & 0xf00) == 0x600 || (cpu_id & 0xf00) == 0xf00) &&
((strcmp(cpu_vendor, "GenuineIntel") == 0) ||
(strcmp(cpu_vendor, "AuthenticAMD") == 0))) {
mem_range_softc.mr_op = &i686_mrops;
}
+#else
+ i686_mrops.init = NULL; /* XXX make "defined but not used" warning go away */
+#endif
}
SYSINIT(i686memdev,SI_SUB_DRIVERS,SI_ORDER_FIRST,i686_mem_drvinit,NULL)
==== //depot/projects/xen3/src/sys/i386/i386/initcpu.c#2 (text+ko) ====
@@ -545,6 +545,9 @@
initializecpu(void)
{
+#ifdef XEN
+ return;
+#endif
switch (cpu) {
#ifdef I486_CPU
case CPU_BLUE:
==== //depot/projects/xen3/src/sys/i386/i386/locore.s#2 (text+ko) ====
@@ -42,6 +42,7 @@
#include "opt_bootp.h"
#include "opt_compat.h"
#include "opt_nfsroot.h"
+#include "opt_global.h"
#include "opt_pmap.h"
#include <sys/syscall.h>
@@ -55,6 +56,11 @@
#include "assym.s"
+#ifdef XEN
+.section __xen_guest
+ .asciz "LOADER=generic,GUEST_OS=freebsd,GUEST_VER=7.0,XEN_VER=xen-3.0,BSD_SYMTAB"
+#endif
+
/*
* XXX
*
@@ -152,9 +158,15 @@
* Some handy macros
*
*/
-
+#ifdef XEN
+/*
+ * We're already in protected mode
+ */
+#define R(foo) (foo)
+#else
#define R(foo) ((foo)-KERNBASE)
-
+#endif
+
#define ALLOCPAGES(foo) \
movl R(physfree), %esi ; \
movl $((foo)*PAGE_SIZE), %eax ; \
@@ -202,8 +214,7 @@
* This is where the bootblocks start us, set the ball rolling...
*
*/
-NON_GPROF_ENTRY(btext)
-
+NON_GPROF_ENTRY(btext)
#ifdef PC98
/* save SYSTEM PARAMETER for resume (NS/T or other) */
movl $0xa1400,%esi
@@ -212,6 +223,19 @@
cld
rep
movsb
+#elif defined(XEN)
+ pushl %esi
+ call initvalues
+ popl %esi
+ call identify_cpu
+ movl proc0kstack,%eax
+ leal (KSTACK_PAGES*PAGE_SIZE-PCB_SIZE)(%eax),%esp
+ xorl %ebp,%ebp /* mark end of frames */
+ movl IdlePTD,%esi
+ movl %esi,(KSTACK_PAGES*PAGE_SIZE-PCB_SIZE+PCB_CR3)(%eax)
+ call init386
+ call mi_startup
+ int $3
#else /* IBM-PC */
/* Tell the bios to warmboot next time */
movw $0x1234,0x472
==== //depot/projects/xen3/src/sys/i386/i386/support.s#2 (text+ko) ====
@@ -1426,10 +1426,11 @@
*/
/* void lgdt(struct region_descriptor *rdp); */
ENTRY(lgdt)
+#ifndef XEN
/* reload the descriptor table */
movl 4(%esp),%eax
lgdt (%eax)
-
+#endif
/* flush the prefetch q */
jmp 1f
nop
==== //depot/projects/xen3/src/sys/i386/i386/swtch.s#2 (text+ko) ====
@@ -33,11 +33,11 @@
*/
#include "opt_npx.h"
-
+#include "opt_global.h"
#include <machine/asmacros.h>
#include "assym.s"
-
+
/*****************************************************************************/
/* Scheduling */
/*****************************************************************************/
@@ -71,7 +71,7 @@
movl 8(%esp),%ecx /* New thread */
movl TD_PCB(%ecx),%edx
movl PCB_CR3(%edx),%eax
- movl %eax,%cr3 /* new address space */
+ LOAD_CR3(%eax)
/* set bit in new pm_active */
movl TD_PROC(%ecx),%eax
movl P_VMSPACE(%eax), %ebx
@@ -112,7 +112,7 @@
movl %esi,PCB_ESI(%edx)
movl %edi,PCB_EDI(%edx)
movl %gs,PCB_GS(%edx)
- pushfl /* PSL */
+ pushfl /* XXX */ /* PSL */
popl PCB_PSL(%edx)
/* Test if debug registers should be saved. */
testl $PCB_DBREGS,PCB_FLAGS(%edx)
@@ -162,10 +162,10 @@
cmpl %eax,IdlePTD /* Kernel address space? */
#endif
je sw1
- movl %cr3,%ebx /* The same address space? */
+ READ_CR3(%ebx)
cmpl %ebx,%eax
je sw1
- movl %eax,%cr3 /* new address space */
+ LOAD_CR3(%eax) /* new address space */
/* Release bit from old pmap->pm_active */
movl PCPU(CURPMAP), %ebx
@@ -185,6 +185,8 @@
btsl %esi, PM_ACTIVE(%ebx) /* set new */
sw1:
+ /* only one task selector under Xen */
+#ifndef XEN
/*
* At this point, we've switched address spaces and are ready
* to load up the rest of the next context.
@@ -220,8 +222,23 @@
movl %esi, 4(%ebx)
movl $GPROC0_SEL*8, %esi /* GSEL(GPROC0_SEL, SEL_KPL) */
ltr %si
+#else
+ /* notify Xen of task switch */
+ pushl %edx /* &pcb is the new stack base */
+ pushl $KDSEL
+ pushl $HYPERVISOR_STACK_SWITCH
+ call ni_queue_multicall2
+ addl $12,%esp
+ /* XXX handle DOM0 IOPL case here (KMM) */
+ /* we currently don't support running FreeBSD */
+ /* in DOM0 so we can skip for now */
+
+ call ni_execute_multicall_list
+
+#endif /* XEN */
3:
+#ifndef XEN /* XXX skip updating selectors for the moment */
/* Copy the %fs and %gs selectors into this pcpu gdt */
leal PCB_FSD(%edx), %esi
movl PCPU(FSGS_GDT), %edi
@@ -233,7 +250,7 @@
movl 12(%esi), %ebx
movl %eax, 8(%edi)
movl %ebx, 12(%edi)
-
+#endif
/* Restore context. */
movl PCB_EBX(%edx),%ebx
movl PCB_ESP(%edx),%esp
@@ -243,11 +260,9 @@
movl PCB_EIP(%edx),%eax
movl %eax,(%esp)
pushl PCB_PSL(%edx)
- popfl
-
+ popfl /* XXX */
movl %edx, PCPU(CURPCB)
movl %ecx, PCPU(CURTHREAD) /* into next thread */
-
/*
* Determine the LDT to use and load it if is the default one and
* that is not the current one.
@@ -258,7 +273,7 @@
movl _default_ldt,%eax
cmpl PCPU(CURRENTLDT),%eax
je 2f
- lldt _default_ldt
+ LLDT(_default_ldt)
movl %eax,PCPU(CURRENTLDT)
jmp 2f
1:
@@ -335,7 +350,7 @@
movl (%esp),%eax
movl %eax,PCB_EIP(%ecx)
- movl %cr3,%eax
+ READ_CR3(%eax)
movl %eax,PCB_CR3(%ecx)
movl %ebx,PCB_EBX(%ecx)
@@ -344,7 +359,7 @@
movl %esi,PCB_ESI(%ecx)
movl %edi,PCB_EDI(%ecx)
movl %gs,PCB_GS(%ecx)
- pushfl
+ pushfl /* XXX */
popl PCB_PSL(%ecx)
#ifdef DEV_NPX
@@ -360,8 +375,8 @@
* have to handle h/w bugs for reloading. We used to lose the
* parent's npx state for forks by forgetting to reload.
*/
- pushfl
- cli
+ pushfl /* XXX */
+ CLI
movl PCPU(FPCURTHREAD),%eax
testl %eax,%eax
je 1f
@@ -383,7 +398,7 @@
call bcopy
addl $12,%esp
1:
- popfl
+ popfl /* XXX */
#endif /* DEV_NPX */
ret
==== //depot/projects/xen3/src/sys/i386/i386/sys_machdep.c#2 (text+ko) ====
@@ -55,6 +55,13 @@
#include <machine/pcb_ext.h>
#include <machine/proc.h>
#include <machine/sysarch.h>
+#ifdef XEN
+#include <machine/xenfunc.h>
+void i386_reset_ldt(struct proc_ldt *pldt);
+#else
+#define i386_reset_ldt(x)
+
+#endif
#include <vm/vm_kern.h> /* for kernel_map */
@@ -163,7 +170,11 @@
*/
sd.sd_lobase = base & 0xffffff;
sd.sd_hibase = (base >> 24) & 0xff;
+#ifndef XEN
sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
+#else
+ sd.sd_lolimit = 0x0; /* 4GB limit, wraps around */
+#endif
sd.sd_hilimit = 0xf;
sd.sd_type = SDT_MEMRWA;
sd.sd_dpl = SEL_UPL;
@@ -173,7 +184,11 @@
sd.sd_gran = 1;
critical_enter();
td->td_pcb->pcb_fsd = sd;
+#ifndef XEN
PCPU_GET(fsgs_gdt)[0] = sd;
+#else
+ HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[1]), *(uint64_t *)&sd);
+#endif
critical_exit();
td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
}
@@ -193,7 +208,11 @@
*/
sd.sd_lobase = base & 0xffffff;
sd.sd_hibase = (base >> 24) & 0xff;
+#ifndef XEN
sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
+#else
+ sd.sd_lolimit = 0x0; /* 4GB limit, wraps around */
+#endif
sd.sd_hilimit = 0xf;
sd.sd_type = SDT_MEMRWA;
sd.sd_dpl = SEL_UPL;
@@ -203,7 +222,11 @@
sd.sd_gran = 1;
critical_enter();
td->td_pcb->pcb_gsd = sd;
+#ifndef XEN
PCPU_GET(fsgs_gdt)[1] = sd;
+#else
+ HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[1]), *(uint64_t *)&sd);
+#endif
critical_exit();
load_gs(GSEL(GUGS_SEL, SEL_UPL));
}
@@ -364,6 +387,7 @@
struct proc_ldt *pldt;
pldt = mdp->md_ldt;
+#ifndef XEN
#ifdef SMP
gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd;
#else
@@ -371,6 +395,11 @@
#endif
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL));
+
+#else
+ i386_reset_ldt(pldt);
+ PCPU_SET(currentldt, (int)pldt);
+#endif
}
#ifdef SMP
@@ -385,6 +414,7 @@
}
#endif
+#ifdef XEN
/*
* Must be called with either sched_lock free or held but not recursed.
* If it does not return NULL, it will return with it owned.
@@ -402,6 +432,48 @@
new_ldt->ldt_len = len = NEW_MAX_LD(len);
new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
+ round_page(len * sizeof(union descriptor)));
+ if (new_ldt->ldt_base == NULL) {
+ FREE(new_ldt, M_SUBPROC);
+ return NULL;
+ }
+ new_ldt->ldt_refcnt = 1;
+ new_ldt->ldt_active = 0;
+
+ mtx_lock_spin(&sched_lock);
+
+ if ((pldt = mdp->md_ldt)) {
+ if (len > pldt->ldt_len)
+ len = pldt->ldt_len;
+ bcopy(pldt->ldt_base, new_ldt->ldt_base,
+ len * sizeof(union descriptor));
+ } else {
+ bcopy(ldt, new_ldt->ldt_base, PAGE_SIZE);
+ }
+ pmap_map_readonly(kernel_pmap, (vm_offset_t)new_ldt->ldt_base,
+ new_ldt->ldt_len*sizeof(union descriptor));
+ return new_ldt;
+}
+void
+i386_reset_ldt(struct proc_ldt *pldt)
+{
+ xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len);
+}
+
+#else
+struct proc_ldt *
+user_ldt_alloc(struct mdproc *mdp, int len)
+{
+ struct proc_ldt *pldt, *new_ldt;
+
+ if (mtx_owned(&sched_lock))
+ mtx_unlock_spin(&sched_lock);
+ mtx_assert(&sched_lock, MA_NOTOWNED);
+ MALLOC(new_ldt, struct proc_ldt *, sizeof(struct proc_ldt),
+ M_SUBPROC, M_WAITOK);
+
+ new_ldt->ldt_len = len = NEW_MAX_LD(len);
+ new_ldt->ldt_base = (caddr_t)kmem_alloc(kernel_map,
len * sizeof(union descriptor));
if (new_ldt->ldt_base == NULL) {
FREE(new_ldt, M_SUBPROC);
@@ -426,6 +498,8 @@
return new_ldt;
}
+#endif
+
/*
* Must be called either with sched_lock free or held but not recursed.
* If md_ldt is not NULL, it will return with sched_lock released.
@@ -443,13 +517,18 @@
mtx_lock_spin(&sched_lock);
mtx_assert(&sched_lock, MA_OWNED | MA_NOTRECURSED);
if (td == PCPU_GET(curthread)) {
+#ifndef XEN
lldt(_default_ldt);
+#endif
PCPU_SET(currentldt, _default_ldt);
+ i386_reset_ldt((struct proc_ldt *)_default_ldt);
}
mdp->md_ldt = NULL;
if (--pldt->ldt_refcnt == 0) {
mtx_unlock_spin(&sched_lock);
+ pmap_map_readwrite(kernel_pmap, (vm_offset_t)pldt->ldt_base,
+ pldt->ldt_len*sizeof(union descriptor));
kmem_free(kernel_map, (vm_offset_t)pldt->ldt_base,
pldt->ldt_len * sizeof(union descriptor));
FREE(pldt, M_SUBPROC);
@@ -629,6 +708,9 @@
/* Allocate a free slot */
pldt = mdp->md_ldt;
if (pldt == NULL) {
+#ifdef XEN
+ load_gs(0); /* XXX check if we really still need this */
+#endif
error = i386_ldt_grow(td, NLDT + 1);
if (error)
return (error);
@@ -677,13 +759,23 @@
{
struct mdproc *mdp = &td->td_proc->p_md;
struct proc_ldt *pldt = mdp->md_ldt;
-
+#ifdef XEN
+ int i, error;
+#endif
mtx_assert(&sched_lock, MA_OWNED);
-
+#ifndef XEN
/* Fill in range */
bcopy(descs,
&((union descriptor *)(pldt->ldt_base))[start],
num * sizeof(union descriptor));
+#else
+ for (i = 0; i < num; i++) {
+ error = HYPERVISOR_update_descriptor(vtomach(&((union descriptor *)(pldt->ldt_base))[start + i]),
+ *(uint64_t *)(descs + i));
+ if (error)
+ panic("failed to update ldt: %d", error);
+ }
+#endif
return (0);
}
@@ -719,6 +811,9 @@
pldt->ldt_base = new_ldt->ldt_base;
pldt->ldt_len = new_ldt->ldt_len;
mtx_unlock_spin(&sched_lock);
+ pmap_map_readwrite(kernel_pmap,
+ (vm_offset_t)old_ldt_base,
+ old_ldt_len*sizeof(union descriptor));
kmem_free(kernel_map, (vm_offset_t)old_ldt_base,
old_ldt_len * sizeof(union descriptor));
FREE(new_ldt, M_SUBPROC);
@@ -729,6 +824,9 @@
* do nothing.
*/
mtx_unlock_spin(&sched_lock);
+ pmap_map_readwrite(kernel_pmap,
+ (vm_offset_t)new_ldt->ldt_base,
+ new_ldt->ldt_len*sizeof(union descriptor));
kmem_free(kernel_map,
(vm_offset_t)new_ldt->ldt_base,
new_ldt->ldt_len * sizeof(union descriptor));
==== //depot/projects/xen3/src/sys/i386/i386/trap.c#2 (text+ko) ====
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/trap.c,v 1.285 2005/11/18 19:26:46 jhb Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/trap.c,v 1.284 2005/11/05 10:42:40 phk Exp $");
/*
* 386 Trap and System call handling
@@ -101,6 +101,13 @@
#include <machine/clock.h>
#endif
+#ifdef XEN
+#include <machine/xenfunc.h>
+#include <machine/hypervisor.h>
+#include <machine/xenvar.h>
+#include <machine/hypervisor-ifs.h>
+#endif
+
extern void trap(struct trapframe frame);
extern void syscall(struct trapframe frame);
@@ -129,7 +136,7 @@
"alignment fault", /* 14 T_ALIGNFLT */
"", /* 15 unused */
"", /* 16 unused */
- "", /* 17 unused */
+ "hypervisor callback", /* 17 T_HYPCALLBACK */
"integer divide fault", /* 18 T_DIVIDE */
"non-maskable interrupt trap", /* 19 T_NMI */
"overflow trap", /* 20 T_OFLOW */
@@ -217,7 +224,7 @@
TRAPF_USERMODE(&frame)))
goto out;
#endif
-
+#ifndef XEN
if ((frame.tf_eflags & PSL_I) == 0) {
/*
* Buggy application or kernel code has disabled
@@ -248,9 +255,18 @@
enable_intr();
}
}
-
+#endif
eva = 0;
code = frame.tf_err;
+#ifdef XEN
+ if (type == T_HYPCALLBACK) {
+ evtchn_do_upcall(&frame);
+ if (ISPL(frame.tf_cs) == SEL_KPL)
+ goto out;
+ goto userout;
+ } else if (type == 0)
+ panic("invalid trap type/code %d/%d\n",type, code);
+#endif
if (type == T_PAGEFLT) {
/*
* For some Cyrix CPUs, %cr2 is clobbered by
@@ -788,8 +804,9 @@
code = frame->tf_err;
type = frame->tf_trapno;
+#ifndef XEN
sdtossd(&gdt[IDXSEL(frame->tf_cs & 0xffff)].sd, &softseg);
-
+#endif
if (type <= MAX_TRAP_MSG)
msg = trap_msg[type];
else
==== //depot/projects/xen3/src/sys/i386/i386/vm_machdep.c#2 (text+ko) ====
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.267 2005/11/14 00:43:44 imp Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/vm_machdep.c,v 1.266 2005/11/09 12:22:26 nyan Exp $");
#include "opt_isa.h"
#include "opt_npx.h"
@@ -102,7 +102,9 @@
#ifndef NSFBUFS
#define NSFBUFS (512 + maxusers * 16)
#endif
-
+#ifdef XEN
+#include <machine/xenfunc.h>
+#endif
static void cpu_reset_real(void);
#ifdef SMP
static void cpu_reset_proxy(void);
@@ -728,8 +730,11 @@
*/
ptep = vtopte(sf->kva);
opte = *ptep;
+#ifndef XEN
*ptep = VM_PAGE_TO_PHYS(m) | pgeflag | PG_RW | PG_V;
-
+#else
+ PT_SET_VA(ptep, VM_PAGE_TO_PHYS(m) | pgeflag | PG_RW | PG_V, TRUE);
+#endif
/*
* Avoid unnecessary TLB invalidations: If the sf_buf's old
* virtual-to-physical mapping was not used, then any processor
@@ -780,6 +785,11 @@
if (sf->ref_count == 0) {
TAILQ_INSERT_TAIL(&sf_buf_freelist, sf, free_entry);
nsfbufsused--;
+#ifdef XEN
+ pmap_qremove(sf->kva, 1);
+ sf->m = NULL;
+ LIST_REMOVE(sf, list_entry);
+#endif
if (sf_buf_alloc_want > 0)
wakeup_one(&sf_buf_freelist);
}
==== //depot/projects/xen3/src/sys/i386/include/asmacros.h#2 (text+ko) ====
@@ -172,6 +172,36 @@
movl $KPSEL, %eax ; /* reload with per-CPU data segment */ \
movl %eax, %fs
+#ifdef XEN
+#define LOAD_CR3(reg) \
+ movl reg,PCPU(CR3); \
+ pushl %ecx ; \
+ pushl %edx ; \
+ pushl %esi ; \
+ pushl reg ; \
+ call xen_load_cr3 ; \
+ addl $4,%esp ; \
+ popl %esi ; \
+ popl %edx ; \
+ popl %ecx ; \
+
+#define READ_CR3(reg) movl PCPU(CR3),reg;
+#define LLDT(arg) \
+ pushl %edx ; \
+ pushl %eax ; \
+ xorl %eax,%eax ; \
+ movl %eax,%gs ; \
+ call i386_reset_ldt ; \
+ popl %eax ; \
+ popl %edx
+#define CLI call ni_cli
+#else
+#define LOAD_CR3(reg) movl reg,%cr3;
+#define READ_CR3(reg) movl %cr3,reg;
+#define LLDT(arg) lldt arg;
+#define CLI cli
+#endif
+
#endif /* LOCORE */
#endif /* !_MACHINE_ASMACROS_H_ */
==== //depot/projects/xen3/src/sys/i386/include/pcpu.h#2 (text+ko) ====
@@ -45,6 +45,7 @@
* to each CPU's data can be set up for things like "check curproc on all
* other processors"
*/
+#ifndef XEN
#define PCPU_MD_FIELDS \
struct pcpu *pc_prvspace; /* Self-reference */ \
struct pmap *pc_curpmap; \
@@ -57,6 +58,25 @@
u_int pc_apic_id; \
int pc_private_tss /* flag indicating private tss */
+
+#else
+#define PCPU_MD_FIELDS \
+ struct pcpu *pc_prvspace; /* Self-reference */ \
+ struct pmap *pc_curpmap; \
+ struct i386tss pc_common_tss; \
+ struct segment_descriptor pc_common_tssd; \
+ struct segment_descriptor *pc_tss_gdt; \
+ struct segment_descriptor *pc_fsgs_gdt; \
+ int pc_currentldt; \
+ u_int pc_acpi_id; \
+ u_int pc_apic_id; \
+ int pc_private_tss; /* flag indicating private tss */ \
+ u_int pc_cr3; \
+ u_int pc_pdir; \
+ u_int pc_lazypmap; \
+ u_int pc_rendezvous; \
+ u_int pc_cpuast;
+#endif
#if defined(lint)
extern struct pcpu *pcpup;
==== //depot/projects/xen3/src/sys/i386/include/pmap.h#2 (text+ko) ====
@@ -368,6 +368,8 @@
#endif /* _KERNEL */
+static __inline void pmap_map_readonly(pmap_t pmap, vm_offset_t va, int len) {}
+static __inline void pmap_map_readwrite(pmap_t pmap, vm_offset_t va, int len) {}
#endif /* !LOCORE */
#endif /* !_MACHINE_PMAP_H_ */
==== //depot/projects/xen3/src/sys/i386/include/segments.h#2 (text+ko) ====
@@ -47,7 +47,11 @@
*/
#define ISPL(s) ((s)&3) /* what is the priority level of a selector */
+#ifdef XEN
+#define SEL_KPL 1 /* kernel priority level */
+#else
#define SEL_KPL 0 /* kernel priority level */
+#endif
#define SEL_UPL 3 /* user priority level */
#define ISLDT(s) ((s)&SEL_LDT) /* is it local or global */
#define SEL_LDT 4 /* local descriptor table */
@@ -206,8 +210,13 @@
#define GPRIV_SEL 1 /* SMP Per-Processor Private Data */
#define GUFS_SEL 2 /* User %fs Descriptor (order critical: 1) */
#define GUGS_SEL 3 /* User %gs Descriptor (order critical: 2) */
+#ifdef XEN
+#define GCODE_SEL (__KERNEL_CS >> 3) /* Kernel Code Descriptor (order critical: 1) */
+#define GDATA_SEL (__KERNEL_DS >> 3) /* Kernel Data Descriptor (order critical: 2) */
+#else
#define GCODE_SEL 4 /* Kernel Code Descriptor (order critical: 1) */
#define GDATA_SEL 5 /* Kernel Data Descriptor (order critical: 2) */
+#endif
#define GUCODE_SEL 6 /* User Code Descriptor (order critical: 3) */
#define GUDATA_SEL 7 /* User Data Descriptor (order critical: 4) */
#define GBIOSLOWMEM_SEL 8 /* BIOS low memory access (must be entry 8) */
@@ -222,8 +231,11 @@
#define GBIOSARGS_SEL 17 /* BIOS interface (Arguments) */
#define GNDIS_SEL 18 /* For the NDIS layer */
+#ifdef XEN
+#define NGDT 8
+#else
#define NGDT 19
-
+#endif
/*
* Entries in the Local Descriptor Table (LDT)
*/
@@ -240,10 +252,15 @@
#ifdef _KERNEL
extern int _default_ldt;
+#ifdef XEN
+extern union descriptor *gdt;
+extern union descriptor *ldt;
+#else
extern union descriptor gdt[];
+extern union descriptor ldt[NLDT];
+#endif
extern struct soft_segment_descriptor gdt_segs[];
extern struct gate_descriptor *idt;
-extern union descriptor ldt[NLDT];
extern struct region_descriptor r_gdt, r_idt;
void lgdt(struct region_descriptor *rdp);
==== //depot/projects/xen3/src/sys/i386/include/trap.h#2 (text+ko) ====
@@ -49,6 +49,7 @@
#define T_PAGEFLT 12 /* page fault */
#define T_ALIGNFLT 14 /* alignment fault */
+#define T_HYPCALLBACK 17 /* hypervisor callback */
#define T_DIVIDE 18 /* integer divide fault */
#define T_NMI 19 /* non-maskable trap */
#define T_OFLOW 20 /* overflow trap */
==== //depot/projects/xen3/src/sys/i386/isa/npx.c#2 (text+ko) ====
@@ -101,9 +101,14 @@
#define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr)))
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list