PERFORCE change 147595 for review
Julian Elischer
julian at FreeBSD.org
Sat Aug 16 20:58:08 UTC 2008
http://perforce.freebsd.org/chv.cgi?CH=147595
Change 147595 by julian at julian_trafmon1 on 2008/08/16 20:58:07
IFC at 147590
Affected files ...
.. //depot/projects/vimage/src/sys/conf/files#35 integrate
.. //depot/projects/vimage/src/sys/conf/files.i386#16 integrate
.. //depot/projects/vimage/src/sys/conf/options.i386#7 integrate
.. //depot/projects/vimage/src/sys/dev/pci/pci_pci.c#8 integrate
.. //depot/projects/vimage/src/sys/dev/pci/pcib_private.h#7 integrate
.. //depot/projects/vimage/src/sys/i386/conf/DEFAULTS#8 integrate
.. //depot/projects/vimage/src/sys/i386/conf/XEN#1 branch
.. //depot/projects/vimage/src/sys/i386/i386/busdma_machdep.c#9 integrate
.. //depot/projects/vimage/src/sys/i386/i386/genassym.c#8 integrate
.. //depot/projects/vimage/src/sys/i386/i386/machdep.c#12 integrate
.. //depot/projects/vimage/src/sys/i386/i386/support.s#6 integrate
.. //depot/projects/vimage/src/sys/i386/i386/sys_machdep.c#6 integrate
.. //depot/projects/vimage/src/sys/i386/i386/trap.c#12 integrate
.. //depot/projects/vimage/src/sys/i386/i386/vm_machdep.c#8 integrate
.. //depot/projects/vimage/src/sys/i386/include/asmacros.h#3 integrate
.. //depot/projects/vimage/src/sys/i386/include/cpufunc.h#5 integrate
.. //depot/projects/vimage/src/sys/i386/include/pcpu.h#5 integrate
.. //depot/projects/vimage/src/sys/i386/include/pmap.h#8 integrate
.. //depot/projects/vimage/src/sys/i386/include/segments.h#2 integrate
.. //depot/projects/vimage/src/sys/i386/include/trap.h#2 integrate
.. //depot/projects/vimage/src/sys/i386/include/vmparam.h#8 integrate
.. //depot/projects/vimage/src/sys/i386/isa/npx.c#4 integrate
.. //depot/projects/vimage/src/sys/i386/pci/pci_cfgreg.c#4 integrate
.. //depot/projects/vimage/src/sys/i386/pci/pci_pir.c#3 integrate
.. //depot/projects/vimage/src/sys/kern/init_main.c#20 integrate
.. //depot/projects/vimage/src/sys/netinet/udp_usrreq.c#29 integrate
.. //depot/projects/vimage/src/sys/netinet6/ip6_input.c#31 integrate
.. //depot/projects/vimage/src/sys/netinet6/ip6_var.h#13 integrate
.. //depot/projects/vimage/src/sys/xen/features.c#1 branch
Differences ...
==== //depot/projects/vimage/src/sys/conf/files#35 (text+ko) ====
@@ -1,4 +1,4 @@
-# $FreeBSD: src/sys/conf/files,v 1.1329 2008/08/14 21:26:29 imp Exp $
+# $FreeBSD: src/sys/conf/files,v 1.1330 2008/08/15 20:58:57 kmacy Exp $
#
# The long compile-with and dependency lines are required because of
# limitations in config: backslash-newline doesn't work in strings, and
@@ -1726,6 +1726,7 @@
libkern/strcat.c standard
libkern/strcmp.c standard
libkern/strcpy.c standard
+libkern/strcspn.c standard
libkern/strdup.c standard
libkern/strlcat.c standard
libkern/strlcpy.c standard
@@ -2342,3 +2343,18 @@
compile-with "${NORMAL_C} -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs"
gnu/fs/xfs/xfs_behavior.c optional xfs \
compile-with "${NORMAL_C} -I$S/gnu/fs/xfs/FreeBSD -I$S/gnu/fs/xfs/FreeBSD/support -I$S/gnu/fs/xfs"
+
+xen/gnttab.c optional xen
+xen/features.c optional xen
+xen/evtchn/evtchn.c optional xen
+xen/evtchn/evtchn_dev.c optional xen
+xen/xenbus/xenbus_client.c optional xen
+xen/xenbus/xenbus_comms.c optional xen
+xen/xenbus/xenbus_dev.c optional xen
+xen/xenbus/xenbus_probe.c optional xen
+xen/xenbus/xenbus_probe_backend.c optional xen
+xen/xenbus/xenbus_xs.c optional xen
+dev/xen/console/console.c optional xen
+dev/xen/console/xencons_ring.c optional xen
+dev/xen/blkfront/blkfront.c optional xen
+dev/xen/netfront/netfront.c optional xen
==== //depot/projects/vimage/src/sys/conf/files.i386#16 (text+ko) ====
@@ -1,7 +1,7 @@
# This file tells config what files go into building a kernel,
# files marked standard are always included.
#
-# $FreeBSD: src/sys/conf/files.i386,v 1.602 2008/08/09 14:52:31 philip Exp $
+# $FreeBSD: src/sys/conf/files.i386,v 1.603 2008/08/15 20:58:57 kmacy Exp $
#
# The long compile-with and dependency lines are required because of
# limitations in config: backslash-newline doesn't work in strings, and
@@ -254,8 +254,8 @@
i386/i386/atomic.c standard \
compile-with "${CC} -c ${CFLAGS} ${DEFINED_PROF:S/^$/-fomit-frame-pointer/} ${.IMPSRC}"
i386/i386/autoconf.c standard
-i386/i386/bios.c standard
-i386/i386/bioscall.s standard
+i386/i386/bios.c optional native
+i386/i386/bioscall.s optional native
i386/i386/bpf_jit_machdep.c optional bpf_jitter
i386/i386/busdma_machdep.c standard
i386/i386/db_disasm.c optional ddb
@@ -264,7 +264,8 @@
i386/i386/dump_machdep.c standard
i386/i386/elan-mmcr.c optional cpu_elan | cpu_soekris
i386/i386/elf_machdep.c standard
-i386/i386/exception.s standard
+i386/i386/exception.s optional native
+i386/xen/exception.s optional xen
i386/i386/gdb_machdep.c optional gdb
i386/i386/geode.c optional cpu_geode
i386/i386/i686_mem.c optional mem
@@ -277,9 +278,11 @@
i386/i386/k6_mem.c optional mem
i386/i386/legacy.c standard
i386/i386/local_apic.c optional apic
-i386/i386/locore.s standard no-obj
+i386/i386/locore.s optional native no-obj
+i386/xen/locore.s optional xen no-obj
i386/i386/longrun.c optional cpu_enable_longrun
i386/i386/machdep.c standard
+i386/xen/xen_machdep.c optional xen
i386/i386/mem.c optional mem
i386/i386/minidump_machdep.c standard
i386/i386/mp_clock.c optional smp
@@ -291,7 +294,8 @@
i386/i386/msi.c optional apic pci
i386/i386/nexus.c standard
i386/i386/perfmon.c optional perfmon
-i386/i386/pmap.c standard
+i386/i386/pmap.c optional native
+i386/xen/pmap.c optional xen
i386/i386/ptrace_machdep.c standard
i386/i386/stack_machdep.c optional ddb | stack
i386/i386/support.s standard
@@ -321,9 +325,10 @@
i386/ibcs2/ibcs2_xenix.c optional ibcs2
i386/ibcs2/ibcs2_xenix_sysent.c optional ibcs2
i386/ibcs2/imgact_coff.c optional ibcs2
-i386/isa/atpic.c standard
+i386/isa/atpic.c optional atpic
#i386/isa/atpic_vector.s standard
-i386/isa/clock.c standard
+i386/isa/clock.c optional native
+i386/xen/clock.c optional xen
i386/isa/elcr.c standard
i386/isa/elink.c optional ep | ie
i386/isa/isa.c optional isa
@@ -346,13 +351,13 @@
i386/linux/linux_sysvec.c optional compat_linux
i386/pci/pci_bus.c optional pci
i386/pci/pci_cfgreg.c optional pci
-i386/pci/pci_pir.c optional pci
+i386/pci/pci_pir.c optional pci
i386/svr4/svr4_locore.s optional compat_svr4 \
dependency "svr4_assym.h" \
warning "COMPAT_SVR4 is broken and should be avoided"
i386/svr4/svr4_machdep.c optional compat_svr4
#
-isa/atrtc.c standard
+isa/atrtc.c optional atpic
isa/syscons_isa.c optional sc
isa/vga_isa.c optional vga
kern/imgact_aout.c optional compat_aout
==== //depot/projects/vimage/src/sys/conf/options.i386#7 (text+ko) ====
@@ -1,4 +1,4 @@
-# $FreeBSD: src/sys/conf/options.i386,v 1.242 2008/06/14 12:51:44 wkoszek Exp $
+# $FreeBSD: src/sys/conf/options.i386,v 1.243 2008/08/15 20:58:57 kmacy Exp $
# Options specific to the i386 platform kernels
AUTO_EOI_1 opt_auto_eoi.h
@@ -111,3 +111,6 @@
# BPF just-in-time compiler
BPF_JITTER opt_bpf.h
+
+NATIVE opt_global.h
+XEN opt_global.h
==== //depot/projects/vimage/src/sys/dev/pci/pci_pci.c#8 (text+ko) ====
@@ -29,7 +29,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/dev/pci/pci_pci.c,v 1.51 2008/07/23 09:44:36 luoqi Exp $");
+__FBSDID("$FreeBSD: src/sys/dev/pci/pci_pci.c,v 1.52 2008/08/16 20:18:40 imp Exp $");
/*
* PCI:PCI bridge support.
@@ -139,6 +139,8 @@
{
struct pcib_softc *sc;
uint8_t iolow;
+ struct sysctl_ctx_list *sctx;
+ struct sysctl_oid *soid;
sc = device_get_softc(dev);
sc->dev = dev;
@@ -148,6 +150,7 @@
*/
sc->command = pci_read_config(dev, PCIR_COMMAND, 1);
sc->domain = pci_get_domain(dev);
+ sc->pribus = pci_read_config(dev, PCIR_PRIBUS_1, 1);
sc->secbus = pci_read_config(dev, PCIR_SECBUS_1, 1);
sc->subbus = pci_read_config(dev, PCIR_SUBBUS_1, 1);
sc->secstat = pci_read_config(dev, PCIR_SECSTAT_1, 2);
@@ -155,6 +158,20 @@
sc->seclat = pci_read_config(dev, PCIR_SECLAT_1, 1);
/*
+ * Setup sysctl reporting nodes
+ */
+ sctx = device_get_sysctl_ctx(dev);
+ soid = device_get_sysctl_tree(dev);
+ SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "domain",
+ CTLFLAG_RD, &sc->domain, 0, "Domain number");
+ SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "pribus",
+ CTLFLAG_RD, &sc->pribus, 0, "Primary bus number");
+ SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "secbus",
+ CTLFLAG_RD, &sc->secbus, 0, "Secondary bus number");
+ SYSCTL_ADD_UINT(sctx, SYSCTL_CHILDREN(soid), OID_AUTO, "subbus",
+ CTLFLAG_RD, &sc->subbus, 0, "Subordinate bus number");
+
+ /*
* Determine current I/O decode.
*/
if (sc->command & PCIM_CMD_PORTEN) {
==== //depot/projects/vimage/src/sys/dev/pci/pcib_private.h#7 (text+ko) ====
@@ -27,7 +27,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/sys/dev/pci/pcib_private.h,v 1.13 2007/09/30 11:05:15 marius Exp $
+ * $FreeBSD: src/sys/dev/pci/pcib_private.h,v 1.14 2008/08/16 20:18:40 imp Exp $
*/
#ifndef __PCIB_PRIVATE_H__
@@ -48,9 +48,10 @@
#define PCIB_SUBTRACTIVE 0x1
#define PCIB_DISABLE_MSI 0x2
uint16_t command; /* command register */
- uint32_t domain; /* domain number */
- uint8_t secbus; /* secondary bus number */
- uint8_t subbus; /* subordinate bus number */
+ u_int domain; /* domain number */
+ u_int pribus; /* primary bus number */
+ u_int secbus; /* secondary bus number */
+ u_int subbus; /* subordinate bus number */
pci_addr_t pmembase; /* base address of prefetchable memory */
pci_addr_t pmemlimit; /* topmost address of prefetchable memory */
pci_addr_t membase; /* base address of memory window */
==== //depot/projects/vimage/src/sys/i386/conf/DEFAULTS#8 (text+ko) ====
@@ -1,7 +1,7 @@
#
# DEFAULTS -- Default kernel configuration file for FreeBSD/i386
#
-# $FreeBSD: src/sys/i386/conf/DEFAULTS,v 1.13 2008/03/12 10:11:57 jeff Exp $
+# $FreeBSD: src/sys/i386/conf/DEFAULTS,v 1.14 2008/08/15 20:58:57 kmacy Exp $
machine i386
@@ -22,3 +22,7 @@
# Default partitioning schemes
options GEOM_BSD
options GEOM_MBR
+
+# enable support for native hardware
+options NATIVE
+device atpic
==== //depot/projects/vimage/src/sys/i386/i386/busdma_machdep.c#9 (text+ko) ====
@@ -25,7 +25,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.93 2008/07/15 03:34:49 alc Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/busdma_machdep.c,v 1.94 2008/08/15 20:51:31 kmacy Exp $");
#include <sys/param.h>
#include <sys/kdb.h>
@@ -144,6 +144,11 @@
int _bus_dmamap_count_pages(bus_dma_tag_t dmat, bus_dmamap_t map, void *buf,
bus_size_t buflen, int flags);
+#ifdef XEN
+#undef pmap_kextract
+#define pmap_kextract pmap_kextract_ma
+#endif
+
/*
* Return true if a match is made.
*
==== //depot/projects/vimage/src/sys/i386/i386/genassym.c#8 (text+ko) ====
@@ -33,7 +33,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/genassym.c,v 1.162 2008/05/16 13:23:47 attilio Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/genassym.c,v 1.163 2008/08/15 20:51:31 kmacy Exp $");
#include "opt_apic.h"
#include "opt_compat.h"
@@ -228,3 +228,9 @@
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
+#include <machine/xen/hypervisor.h>
+ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3));
+ASSYM(HYPERVISOR_VIRT_START, __HYPERVISOR_VIRT_START);
+#endif
==== //depot/projects/vimage/src/sys/i386/i386/machdep.c#12 (text+ko) ====
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/machdep.c,v 1.670 2008/04/25 05:18:48 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/machdep.c,v 1.671 2008/08/15 20:51:31 kmacy Exp $");
#include "opt_apic.h"
#include "opt_atalk.h"
@@ -141,6 +141,25 @@
uint32_t arch_i386_xbox_memsize = 0;
#endif
+#ifdef XEN
+/* XEN includes */
+#include <machine/xen/xen-os.h>
+#include <machine/xen/hypervisor.h>
+#include <machine/xen/xen-os.h>
+#include <machine/xen/xenvar.h>
+#include <machine/xen/xenfunc.h>
+#include <machine/xen/xen_intr.h>
+
+void Xhypervisor_callback(void);
+void failsafe_callback(void);
+
+extern trap_info_t trap_table[];
+struct proc_ldt default_proc_ldt;
+extern int init_first;
+int running_xen = 1;
+extern unsigned long physfree;
+#endif /* XEN */
+
/* Sanity check for __curthread() */
CTASSERT(offsetof(struct pcpu, pc_curthread) == 0);
@@ -287,8 +306,9 @@
*/
bufinit();
vm_pager_bufferinit();
-
+#ifndef XEN
cpu_setregs();
+#endif
}
/*
@@ -1118,6 +1138,24 @@
return (0);
}
+
+void (*cpu_idle_hook)(void) = NULL; /* ACPI idle hook. */
+
+#ifdef XEN
+
+void
+cpu_halt(void)
+{
+ HYPERVISOR_shutdown(SHUTDOWN_poweroff);
+}
+
+static void
+cpu_idle_hlt(int busy)
+{
+ idle_block();
+}
+
+#else
/*
* Shutdown the CPU as much as possible
*/
@@ -1128,8 +1166,6 @@
__asm__ ("hlt");
}
-void (*cpu_idle_hook)(void) = NULL; /* ACPI idle hook. */
-
static void
cpu_idle_hlt(int busy)
{
@@ -1143,6 +1179,7 @@
else
__asm __volatile("sti; hlt");
}
+#endif
static void
cpu_idle_acpi(int busy)
@@ -1437,10 +1474,16 @@
*/
int _default_ldt;
+
+#ifdef XEN
+union descriptor *gdt;
+union descriptor *ldt;
+#else
union descriptor gdt[NGDT * MAXCPU]; /* global descriptor table */
+union descriptor ldt[NLDT]; /* local descriptor table */
+#endif
static struct gate_descriptor idt0[NIDT];
struct gate_descriptor *idt = &idt0[0]; /* interrupt descriptor table */
-union descriptor ldt[NLDT]; /* local descriptor table */
struct region_descriptor r_gdt, r_idt; /* table descriptors */
struct mtx dt_lock; /* lock for GDT and LDT */
@@ -1542,6 +1585,7 @@
0, 0,
1, /* default 32 vs 16 bit size */
1 /* limit granularity (byte/page units)*/ },
+#ifndef XEN
/* GPROC0_SEL 9 Proc 0 Tss Descriptor */
{
0x0, /* segment base address */
@@ -1633,6 +1677,7 @@
0, 0,
0, /* default 32 vs 16 bit size */
0 /* limit granularity (byte/page units)*/ },
+#endif /* !XEN */
};
static struct soft_segment_descriptor ldt_segs[] = {
@@ -1870,7 +1915,16 @@
goto physmap_done;
}
#endif
-
+#if defined(XEN)
+ has_smap = 0;
+ Maxmem = xen_start_info->nr_pages - init_first;
+ physmem = Maxmem;
+ basemem = 0;
+ physmap[0] = init_first << PAGE_SHIFT;
+ physmap[1] = ptoa(Maxmem) - round_page(MSGBUF_SIZE);
+ physmap_idx = 0;
+ goto physmap_done;
+#endif
hasbrokenint12 = 0;
TUNABLE_INT_FETCH("hw.hasbrokenint12", &hasbrokenint12);
bzero(&vmf, sizeof(vmf));
@@ -2032,7 +2086,7 @@
vmf.vmf_ah = 0x88;
vm86_intcall(0x15, &vmf);
extmem = vmf.vmf_ax;
-#else
+#elif !defined(XEN)
/*
* Prefer the RTC value for extended memory.
*/
@@ -2123,6 +2177,7 @@
getenv_quad("dcons.size", &dcons_size) == 0)
dcons_addr = 0;
+#ifndef XEN
/*
* physmap is in bytes, so when converting to page boundaries,
* round up the start address and round down the end address.
@@ -2240,7 +2295,11 @@
}
*pte = 0;
invltlb();
-
+#else
+ phys_avail[0] = physfree;
+ phys_avail[1] = xen_start_info->nr_pages*PAGE_SIZE;
+#endif
+
/*
* XXX
* The last chunk must contain at least one page plus the message
@@ -2265,6 +2324,246 @@
off);
}
+#ifdef XEN
+#define MTOPSIZE (1<<(14 + PAGE_SHIFT))
+
+void
+init386(first)
+ int first;
+{
+ struct gate_descriptor *gdp;
+ unsigned long gdtmachpfn;
+ int error, gsel_tss, metadata_missing, x;
+ struct pcpu *pc;
+ struct callback_register event = {
+ .type = CALLBACKTYPE_event,
+ .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)Xhypervisor_callback },
+ };
+ struct callback_register failsafe = {
+ .type = CALLBACKTYPE_failsafe,
+ .address = {GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback },
+ };
+
+ thread0.td_kstack = proc0kstack;
+ thread0.td_pcb = (struct pcb *)
+ (thread0.td_kstack + KSTACK_PAGES * PAGE_SIZE) - 1;
+
+ /*
+ * This may be done better later if it gets more high level
+ * components in it. If so just link td->td_proc here.
+ */
+ proc_linkup0(&proc0, &thread0);
+
+ metadata_missing = 0;
+ if (xen_start_info->mod_start) {
+ preload_metadata = (caddr_t)xen_start_info->mod_start;
+ preload_bootstrap_relocate(KERNBASE);
+ } else {
+ metadata_missing = 1;
+ }
+ if (envmode == 1)
+ kern_envp = static_env;
+ else if (bootinfo.bi_envp)
+ kern_envp = (caddr_t)bootinfo.bi_envp + KERNBASE;
+
+ /* Init basic tunables, hz etc */
+ init_param1();
+
+ /*
+ * XEN occupies a portion of the upper virtual address space
+ * At its base it manages an array mapping machine page frames
+ * to physical page frames - hence we need to be able to
+ * access 4GB - (64MB - 4MB + 64k)
+ */
+ gdt_segs[GPRIV_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GUFS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GUGS_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GUCODE_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GUDATA_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GBIOSLOWMEM_SEL].ssd_limit = atop(HYPERVISOR_VIRT_START + MTOPSIZE);
+ gdt_segs[GCODE_SEL].ssd_limit = atop(0 - 1);
+ gdt_segs[GDATA_SEL].ssd_limit = atop(0 - 1);
+ gdt_segs[GUCODE_SEL].ssd_limit = atop(0 - 1);
+ gdt_segs[GUDATA_SEL].ssd_limit = atop(0 - 1);
+ gdt_segs[GUFS_SEL].ssd_limit = atop(0 - 1);
+ gdt_segs[GUGS_SEL].ssd_limit = atop(0 - 1);
+
+ pc = &__pcpu[0];
+ gdt_segs[GPRIV_SEL].ssd_base = (int) pc;
+ gdt_segs[GPROC0_SEL].ssd_base = (int) &pc->pc_common_tss;
+
+ PT_SET_MA(gdt, xpmap_ptom(VTOP(gdt)) | PG_V | PG_RW);
+ bzero(gdt, PAGE_SIZE);
+ for (x = 0; x < NGDT; x++)
+ ssdtosd(&gdt_segs[x], &gdt[x].sd);
+
+ mtx_init(&dt_lock, "descriptor tables", NULL, MTX_SPIN);
+
+ gdtmachpfn = vtomach(gdt) >> PAGE_SHIFT;
+ PT_SET_MA(gdt, *vtopte((unsigned long)gdt) & ~(PG_RW|PG_M|PG_A));
+ PANIC_IF(HYPERVISOR_set_gdt(&gdtmachpfn, 512) != 0);
+ lgdt(&r_gdt);
+ gdtset = 1;
+
+ if ((error = HYPERVISOR_set_trap_table(trap_table)) != 0) {
+ panic("set_trap_table failed - error %d\n", error);
+ }
+
+ error = HYPERVISOR_callback_op(CALLBACKOP_register, &event);
+ if (error == 0)
+ error = HYPERVISOR_callback_op(CALLBACKOP_register, &failsafe);
+#if CONFIG_XEN_COMPAT <= 0x030002
+ if (error == -ENOXENSYS)
+ HYPERVISOR_set_callbacks(GSEL(GCODE_SEL, SEL_KPL),
+ (unsigned long)Xhypervisor_callback,
+ GSEL(GCODE_SEL, SEL_KPL), (unsigned long)failsafe_callback);
+#endif
+ pcpu_init(pc, 0, sizeof(struct pcpu));
+ PCPU_SET(prvspace, pc);
+ PCPU_SET(curthread, &thread0);
+ PCPU_SET(curpcb, thread0.td_pcb);
+
+ /*
+ * Initialize mutexes.
+ *
+ * icu_lock: in order to allow an interrupt to occur in a critical
+ * section, to set pcpu->ipending (etc...) properly, we
+ * must be able to get the icu lock, so it can't be
+ * under witness.
+ */
+ mutex_init();
+ mtx_init(&icu_lock, "icu", NULL, MTX_SPIN | MTX_NOWITNESS | MTX_NOPROFILE);
+
+ /* make ldt memory segments */
+ ldt_segs[LUCODE_SEL].ssd_limit = atop(0 - 1);
+ ldt_segs[LUDATA_SEL].ssd_limit = atop(0 - 1);
+ for (x = 0; x < sizeof ldt_segs / sizeof ldt_segs[0]; x++)
+ ssdtosd(&ldt_segs[x], &ldt[x].sd);
+
+ default_proc_ldt.ldt_base = (caddr_t)ldt;
+ default_proc_ldt.ldt_len = 6;
+ _default_ldt = (int)&default_proc_ldt;
+ PCPU_SET(currentldt, _default_ldt)
+ PT_SET_MA(ldt, *vtopte((unsigned long)ldt) & ~PG_RW);
+ xen_set_ldt((unsigned long) ldt, (sizeof ldt_segs / sizeof ldt_segs[0]));
+
+#if defined(XEN_PRIVILEGED)
+ /*
+ * Initialize the i8254 before the console so that console
+ * initialization can use DELAY().
+ */
+ i8254_init();
+#endif
+
+ /*
+ * Initialize the console before we print anything out.
+ */
+ cninit();
+
+ if (metadata_missing)
+ printf("WARNING: loader(8) metadata is missing!\n");
+
+#ifdef DEV_ISA
+ elcr_probe();
+ atpic_startup();
+#endif
+
+#ifdef DDB
+ ksym_start = bootinfo.bi_symtab;
+ ksym_end = bootinfo.bi_esymtab;
+#endif
+
+ kdb_init();
+
+#ifdef KDB
+ if (boothowto & RB_KDB)
+ kdb_enter(KDB_WHY_BOOTFLAGS, "Boot flags requested debugger");
+#endif
+
+ finishidentcpu(); /* Final stage of CPU initialization */
+ setidt(IDT_UD, &IDTVEC(ill), SDT_SYS386TGT, SEL_KPL,
+ GSEL(GCODE_SEL, SEL_KPL));
+ setidt(IDT_GP, &IDTVEC(prot), SDT_SYS386TGT, SEL_KPL,
+ GSEL(GCODE_SEL, SEL_KPL));
+ initializecpu(); /* Initialize CPU registers */
+
+ /* make an initial tss so cpu can get interrupt stack on syscall! */
+ /* Note: -16 is so we can grow the trapframe if we came from vm86 */
+ PCPU_SET(common_tss.tss_esp0, thread0.td_kstack +
+ KSTACK_PAGES * PAGE_SIZE - sizeof(struct pcb) - 16);
+ PCPU_SET(common_tss.tss_ss0, GSEL(GDATA_SEL, SEL_KPL));
+ gsel_tss = GSEL(GPROC0_SEL, SEL_KPL);
+ PCPU_SET(tss_gdt, &gdt[GPROC0_SEL].sd);
+ PCPU_SET(common_tssd, *PCPU_GET(tss_gdt));
+ PCPU_SET(common_tss.tss_ioopt, (sizeof (struct i386tss)) << 16);
+ ltr(gsel_tss);
+
+ /* pointer to selector slot for %fs/%gs */
+ PCPU_SET(fsgs_gdt, &gdt[GUFS_SEL].sd);
+
+ dblfault_tss.tss_esp = dblfault_tss.tss_esp0 = dblfault_tss.tss_esp1 =
+ dblfault_tss.tss_esp2 = (int)&dblfault_stack[sizeof(dblfault_stack)];
+ dblfault_tss.tss_ss = dblfault_tss.tss_ss0 = dblfault_tss.tss_ss1 =
+ dblfault_tss.tss_ss2 = GSEL(GDATA_SEL, SEL_KPL);
+#ifdef PAE
+ dblfault_tss.tss_cr3 = (int)IdlePDPT;
+#else
+ dblfault_tss.tss_cr3 = (int)IdlePTD;
+#endif
+ dblfault_tss.tss_eip = (int)dblfault_handler;
+ dblfault_tss.tss_eflags = PSL_KERNEL;
+ dblfault_tss.tss_ds = dblfault_tss.tss_es =
+ dblfault_tss.tss_gs = GSEL(GDATA_SEL, SEL_KPL);
+ dblfault_tss.tss_fs = GSEL(GPRIV_SEL, SEL_KPL);
+ dblfault_tss.tss_cs = GSEL(GCODE_SEL, SEL_KPL);
+ dblfault_tss.tss_ldt = GSEL(GLDT_SEL, SEL_KPL);
+
+ vm86_initialize();
+ getmemsize(first);
+ init_param2(physmem);
+
+ /* now running on new page tables, configured,and u/iom is accessible */
+
+ msgbufinit(msgbufp, MSGBUF_SIZE);
+
+ /* make a call gate to reenter kernel with */
+ gdp = &ldt[LSYS5CALLS_SEL].gd;
+
+ x = (int) &IDTVEC(lcall_syscall);
+ gdp->gd_looffset = x;
+ gdp->gd_selector = GSEL(GCODE_SEL,SEL_KPL);
+ gdp->gd_stkcpy = 1;
+ gdp->gd_type = SDT_SYS386CGT;
+ gdp->gd_dpl = SEL_UPL;
+ gdp->gd_p = 1;
+ gdp->gd_hioffset = x >> 16;
+
+ /* XXX does this work? */
+ /* XXX yes! */
+ ldt[LBSDICALLS_SEL] = ldt[LSYS5CALLS_SEL];
+ ldt[LSOL26CALLS_SEL] = ldt[LSYS5CALLS_SEL];
+
+ /* transfer to user mode */
+
+ _ucodesel = GSEL(GUCODE_SEL, SEL_UPL);
+ _udatasel = GSEL(GUDATA_SEL, SEL_UPL);
+
+ /* setup proc 0's pcb */
+ thread0.td_pcb->pcb_flags = 0;
+#ifdef PAE
+ thread0.td_pcb->pcb_cr3 = (int)IdlePDPT;
+#else
+ thread0.td_pcb->pcb_cr3 = (int)IdlePTD;
+#endif
+ thread0.td_pcb->pcb_ext = 0;
+ thread0.td_frame = &proc0_tf;
+ thread0.td_pcb->pcb_fsd = PCPU_GET(fsgs_gdt)[0];
+ thread0.td_pcb->pcb_gsd = PCPU_GET(fsgs_gdt)[1];
+}
+
+#else
void
init386(first)
int first;
@@ -2527,6 +2826,7 @@
thread0.td_pcb->pcb_ext = 0;
thread0.td_frame = &proc0_tf;
}
+#endif
void
cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size)
==== //depot/projects/vimage/src/sys/i386/i386/support.s#6 (text+ko) ====
@@ -26,7 +26,7 @@
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*
- * $FreeBSD: src/sys/i386/i386/support.s,v 1.120 2008/08/08 16:26:53 stas Exp $
+ * $FreeBSD: src/sys/i386/i386/support.s,v 1.121 2008/08/15 20:51:31 kmacy Exp $
*/
#include "opt_npx.h"
@@ -1459,10 +1459,12 @@
*/
/* 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/vimage/src/sys/i386/i386/sys_machdep.c#6 (text+ko) ====
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.113 2008/03/12 10:11:57 jeff Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/sys_machdep.c,v 1.114 2008/08/15 20:51:31 kmacy Exp $");
#include "opt_kstack_pages.h"
#include "opt_mac.h"
@@ -58,6 +58,20 @@
#include <security/audit/audit.h>
+#ifdef XEN
+#include <machine/xen/xenfunc.h>
+
+void i386_reset_ldt(struct proc_ldt *pldt);
+
+void
+i386_reset_ldt(struct proc_ldt *pldt)
+{
+ xen_set_ldt((vm_offset_t)pldt->ldt_base, pldt->ldt_len);
+}
+#else
+#define i386_reset_ldt(x)
+#endif
+
#include <vm/vm_kern.h> /* for kernel_map */
#define MAX_LD 8192
@@ -164,7 +178,12 @@
*/
sd.sd_lobase = base & 0xffffff;
sd.sd_hibase = (base >> 24) & 0xff;
+#ifdef XEN
+ /* need to do nosegneg like Linux */
+ sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
+#else
sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
+#endif
sd.sd_hilimit = 0xf;
sd.sd_type = SDT_MEMRWA;
sd.sd_dpl = SEL_UPL;
@@ -174,7 +193,12 @@
sd.sd_gran = 1;
critical_enter();
td->td_pcb->pcb_fsd = sd;
+#ifdef XEN
+ HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[0]),
+ *(uint64_t *)&sd);
+#else
PCPU_GET(fsgs_gdt)[0] = sd;
+#endif
critical_exit();
td->td_frame->tf_fs = GSEL(GUFS_SEL, SEL_UPL);
}
@@ -194,7 +218,13 @@
*/
sd.sd_lobase = base & 0xffffff;
sd.sd_hibase = (base >> 24) & 0xff;
+
+#ifdef XEN
+ /* need to do nosegneg like Linux */
+ sd.sd_lolimit = (HYPERVISOR_VIRT_START >> 12) & 0xffff;
+#else
sd.sd_lolimit = 0xffff; /* 4GB limit, wraps around */
+#endif
sd.sd_hilimit = 0xf;
sd.sd_type = SDT_MEMRWA;
sd.sd_dpl = SEL_UPL;
@@ -204,7 +234,12 @@
sd.sd_gran = 1;
critical_enter();
td->td_pcb->pcb_gsd = sd;
+#ifdef XEN
+ HYPERVISOR_update_descriptor(vtomach(&PCPU_GET(fsgs_gdt)[1]),
+ *(uint64_t *)&sd);
+#else
PCPU_GET(fsgs_gdt)[1] = sd;
+#endif
critical_exit();
load_gs(GSEL(GUGS_SEL, SEL_UPL));
}
@@ -360,6 +395,10 @@
}
pldt = mdp->md_ldt;
+#ifdef XEN
+ i386_reset_ldt(pldt);
+ PCPU_SET(currentldt, (int)pldt);
+#else
#ifdef SMP
gdt[PCPU_GET(cpuid) * NGDT + GUSERLDT_SEL].sd = pldt->ldt_sd;
#else
@@ -367,6 +406,7 @@
#endif
lldt(GSEL(GUSERLDT_SEL, SEL_KPL));
PCPU_SET(currentldt, GSEL(GUSERLDT_SEL, SEL_KPL));
+#endif /* XEN */
if (dtlocked)
mtx_unlock_spin(&dt_lock);
}
@@ -385,6 +425,44 @@
}
#endif
+#ifdef XEN
+
+/*
+ * dt_lock must be held. Returns with dt_lock held.
+ */
+struct proc_ldt *
+user_ldt_alloc(struct mdproc *mdp, int len)
+{
+ struct proc_ldt *pldt, *new_ldt;
+
+ mtx_assert(&dt_lock, MA_OWNED);
+ mtx_unlock_spin(&dt_lock);
+ 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,
+ 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;
+
+ 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;
+}
+#else
/*
* dt_lock must be held. Returns with dt_lock held.
*/
@@ -423,6 +501,7 @@
return (new_ldt);
}
+#endif /* !XEN */
/*
* Must be called with dt_lock held. Returns with dt_lock unheld.
@@ -667,7 +746,23 @@
td->td_retval[0] = uap->start;
return (error);
}
+#ifdef XEN
+static int
+i386_set_ldt_data(struct thread *td, int start, int num,
+ union descriptor *descs)
+{
+ struct mdproc *mdp = &td->td_proc->p_md;
+ struct proc_ldt *pldt = mdp->md_ldt;
+
+ mtx_assert(&dt_lock, MA_OWNED);
+ /* Fill in range */
+ bcopy(descs,
+ &((union descriptor *)(pldt->ldt_base))[start],
+ num * sizeof(union descriptor));
+ return (0);
+}
+#else
static int
i386_set_ldt_data(struct thread *td, int start, int num,
union descriptor *descs)
@@ -683,6 +778,7 @@
num * sizeof(union descriptor));
return (0);
}
+#endif /* !XEN */
static int
i386_ldt_grow(struct thread *td, int len)
==== //depot/projects/vimage/src/sys/i386/i386/trap.c#12 (text+ko) ====
@@ -38,7 +38,7 @@
*/
#include <sys/cdefs.h>
-__FBSDID("$FreeBSD: src/sys/i386/i386/trap.c,v 1.315 2008/08/13 18:29:29 attilio Exp $");
+__FBSDID("$FreeBSD: src/sys/i386/i386/trap.c,v 1.316 2008/08/15 20:51:31 kmacy Exp $");
/*
* 386 Trap and System call handling
@@ -123,6 +123,14 @@
systrace_probe_func_t systrace_probe_func;
#endif
+#ifdef XEN
+#include <sys/syslog.h>
+#include <machine/xen/xenfunc.h>
+#include <machine/xen/hypervisor.h>
+#include <machine/xen/xenvar.h>
+#include <machine/xen/evtchn.h>
+#endif
+
extern void trap(struct trapframe *frame);
extern void syscall(struct trapframe *frame);
@@ -151,7 +159,11 @@
"alignment fault", /* 14 T_ALIGNFLT */
"", /* 15 unused */
"", /* 16 unused */
+#ifdef XEN
+ "hypervisor callback", /* 17 T_HYPCALLBACK*/
+#else
"", /* 17 unused */
+#endif
"integer divide fault", /* 18 T_DIVIDE */
"non-maskable interrupt trap", /* 19 T_NMI */
"overflow trap", /* 20 T_OFLOW */
@@ -258,6 +270,7 @@
goto out;
>>> TRUNCATED FOR MAIL (1000 lines) <<<
More information about the p4-projects
mailing list