Date: Sat, 1 Mar 2008 08:29:43 GMT From: Colin Percival <cperciva@FreeBSD.org> To: Perforce Change Reviews <perforce@freebsd.org> Subject: PERFORCE change 136559 for review Message-ID: <200803010829.m218Thfx081202@repoman.freebsd.org>
index | next in thread | raw e-mail
http://perforce.freebsd.org/chv.cgi?CH=136559 Change 136559 by cperciva@cperciva_freefall on 2008/03/01 08:29:41 Backport Xen bits. Affected files ... .. //depot/projects/xen31_7_0/etc/Makefile#2 edit .. //depot/projects/xen31_7_0/etc/etc.xen/ttys#1 add .. //depot/projects/xen31_7_0/sys/conf/files#2 edit .. //depot/projects/xen31_7_0/sys/conf/files.i386#2 edit .. //depot/projects/xen31_7_0/sys/conf/options.i386#2 edit .. //depot/projects/xen31_7_0/sys/dev/sound/pcm/sound.h#2 edit .. //depot/projects/xen31_7_0/sys/dev/xen/balloon/balloon.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/blkback/blkback.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/blkfront/blkfront.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/blkfront/block.h#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/console/console.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/console/xencons_ring.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/console/xencons_ring.h#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/evtchn/evtchn_dev.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/netback/netback.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/netfront/mbufq.h#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/netfront/netfront.c#1 add .. //depot/projects/xen31_7_0/sys/dev/xen/pcifront/pcifront.c#1 add .. //depot/projects/xen31_7_0/sys/i386/conf/DEFAULTS#2 edit .. //depot/projects/xen31_7_0/sys/i386/conf/XEN#1 add .. //depot/projects/xen31_7_0/sys/i386/i386/genassym.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/intr_machdep.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/machdep.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/support.s#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/swtch.s#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/sys_machdep.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/trap.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/i386/vm_machdep.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/asmacros.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/cpufunc.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/pcpu.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/pmap.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/psl.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/segments.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/trap.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/vmparam.h#2 edit .. //depot/projects/xen31_7_0/sys/i386/include/xen/evtchn.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/features.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/hypercall.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/hypervisor.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/synch_bitops.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xen-os.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xen_intr.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xenbus.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xenfunc.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xenpmap.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xenstored.h#1 add .. //depot/projects/xen31_7_0/sys/i386/include/xen/xenvar.h#1 add .. //depot/projects/xen31_7_0/sys/i386/isa/npx.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/pci/pci_cfgreg.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/pci/pci_pir.c#2 edit .. //depot/projects/xen31_7_0/sys/i386/xen/clock.c#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/exception.s#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/locore.s#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/machdep.c#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/pmap.c#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/xen_bus.c#1 add .. //depot/projects/xen31_7_0/sys/i386/xen/xen_machdep.c#1 add .. //depot/projects/xen31_7_0/sys/kern/init_main.c#2 edit .. //depot/projects/xen31_7_0/sys/kern/kern_fork.c#2 edit .. //depot/projects/xen31_7_0/sys/kern/kern_switch.c#2 edit .. //depot/projects/xen31_7_0/sys/kern/subr_kdb.c#2 edit .. //depot/projects/xen31_7_0/sys/kern/subr_trap.c#2 edit .. //depot/projects/xen31_7_0/sys/libkern/strcspn.c#1 add .. //depot/projects/xen31_7_0/sys/sys/cdefs.h#2 edit .. //depot/projects/xen31_7_0/sys/sys/libkern.h#2 edit .. //depot/projects/xen31_7_0/sys/vm/pmap.h#2 edit .. //depot/projects/xen31_7_0/sys/vm/vm_fault.c#2 edit .. //depot/projects/xen31_7_0/sys/vm/vm_page.c#2 edit .. //depot/projects/xen31_7_0/sys/xen/evtchn/evtchn.c#1 add .. //depot/projects/xen31_7_0/sys/xen/evtchn/evtchn_dev.c#1 add .. //depot/projects/xen31_7_0/sys/xen/features.c#1 add .. //depot/projects/xen31_7_0/sys/xen/gnttab.c#1 add .. //depot/projects/xen31_7_0/sys/xen/gnttab.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/COPYING#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/acm.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/acm_ops.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-ia64.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-powerpc.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-x86/xen-x86_32.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-x86/xen-x86_64.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-x86/xen.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-x86_32.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/arch-x86_64.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/callback.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/dom0_ops.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/domctl.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/elfnote.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/elfstructs.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/event_channel.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/features.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/foreign/Makefile#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/foreign/mkchecker.py#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/foreign/mkheader.py#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/foreign/reference.size#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/foreign/structs.py#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/grant_table.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/e820.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/hvm_info_table.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/hvm_op.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/ioreq.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/params.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/save.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/hvm/vmx_assist.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/blkif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/console.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/fbif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/kbdif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/netif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/pciif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/protocols.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/ring.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/tpmif.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/xenbus.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/io/xs_wire.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/kexec.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/libelf.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/memory.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/nmi.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/physdev.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/platform.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/sched.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/sysctl.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/trace.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/vcpu.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/version.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/xen-compat.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/xen.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/xencomm.h#1 add .. //depot/projects/xen31_7_0/sys/xen/interface/xenoprof.h#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/init.txt#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_client.c#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_comms.c#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_comms.h#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_dev.c#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_probe.c#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_probe_backend.c#1 add .. //depot/projects/xen31_7_0/sys/xen/xenbus/xenbus_xs.c#1 add Differences ... ==== //depot/projects/xen31_7_0/etc/Makefile#2 (text+ko) ==== @@ -7,6 +7,8 @@ SUBDIR= sendmail .endif +TTY_ARCH?= ${MACHINE_ARCH} + BIN1= amd.map apmd.conf auth.conf \ crontab csh.cshrc csh.login csh.logout devd.conf devfs.conf \ dhclient.conf disktab fbtab freebsd-update.conf \ @@ -19,7 +21,7 @@ rc.sendmail rc.shutdown \ rc.subr remote rpc services shells \ snmpd.config sysctl.conf syslog.conf \ - etc.${MACHINE_ARCH}/ttys \ + etc.${TTY_ARCH}/ttys \ ${.CURDIR}/../gnu/usr.bin/man/manpath/manpath.config \ ${.CURDIR}/../usr.bin/mail/misc/mail.rc \ ${.CURDIR}/../usr.bin/locate/locate/locate.rc ==== //depot/projects/xen31_7_0/sys/conf/files#2 (text+ko) ==== @@ -1583,6 +1583,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 @@ -2105,6 +2106,21 @@ vm/vm_unix.c standard vm/vm_zeroidle.c standard vm/vnode_pager.c standard +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 + # gnu/fs/xfs/xfs_alloc.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" \ ==== //depot/projects/xen31_7_0/sys/conf/files.i386#2 (text+ko) ==== @@ -259,8 +259,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 @@ -269,7 +269,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 @@ -282,9 +283,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 @@ -296,7 +299,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/support.s standard i386/i386/swtch.s standard @@ -306,6 +310,7 @@ i386/i386/uio_machdep.c standard i386/i386/vm86.c standard i386/i386/vm_machdep.c standard +i386/xen/xen_bus.c optional xen i386/ibcs2/ibcs2_errno.c optional ibcs2 i386/ibcs2/ibcs2_fcntl.c optional ibcs2 i386/ibcs2/ibcs2_ioctl.c optional ibcs2 @@ -325,9 +330,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 ==== //depot/projects/xen31_7_0/sys/conf/options.i386#2 (text+ko) ==== @@ -36,6 +36,9 @@ # Physical address extensions and support for >4G ram. As above. PAE opt_global.h +XEN opt_global.h +NATIVE opt_global.h + CLK_CALIBRATION_LOOP opt_clock.h CLK_USE_I8254_CALIBRATION opt_clock.h TIMER_FREQ opt_clock.h ==== //depot/projects/xen31_7_0/sys/dev/sound/pcm/sound.h#2 (text+ko) ==== @@ -31,12 +31,13 @@ * first, include kernel header files. */ -#ifndef _OS_H_ -#define _OS_H_ +#ifndef _SOUND_IS_A_PAIN_IN_MY_ASS_H_ +#define _SOUND_IS_A_PAIN_IN_MY_ASS_H_ #ifdef _KERNEL #include <sys/param.h> #include <sys/systm.h> +#include <sys/module.h> #include <sys/ioccom.h> #include <sys/filio.h> #include <sys/sockio.h> @@ -545,17 +546,14 @@ int sndstat_unregister(device_t dev); int sndstat_unregisterfile(char *str); -#define SND_DECLARE_FILE(version) \ - _SND_DECLARE_FILE(__LINE__, version) - -#define _SND_DECLARE_FILE(uniq, version) \ - __SND_DECLARE_FILE(uniq, version) - #define __SND_DECLARE_FILE(uniq, version) \ - static char sndstat_vinfo[] = version; \ + static char sndstat_vinfo[] = version; \ SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); +#define SND_DECLARE_FILE(version) \ + __SND_DECLARE_FILE(__LINE__, (version)) + /* usage of flags in device config entry (config file) */ #define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ #define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ ==== //depot/projects/xen31_7_0/sys/i386/conf/DEFAULTS#2 (text+ko) ==== @@ -15,6 +15,7 @@ # Pseudo devices. device mem # Memory and kernel memory devices device io # I/O device +device atpic # UART chips on this platform device uart_ns8250 @@ -23,5 +24,4 @@ options GEOM_BSD options GEOM_MBR -# KSE support went from being default to a kernel option -options KSE +options NATIVE ==== //depot/projects/xen31_7_0/sys/i386/i386/genassym.c#2 (text+ko) ==== @@ -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/xen31_7_0/sys/i386/i386/intr_machdep.c#2 (text+ko) ==== @@ -395,7 +395,8 @@ /* Schedule the ithread if needed. */ if (thread) { error = intr_event_schedule_thread(ie); - KASSERT(error == 0, ("bad stray interrupt")); + if (error != 0) + log(LOG_CRIT, "bad stray interrupt %d", vector); } critical_exit(); td->td_intr_nesting_level--; ==== //depot/projects/xen31_7_0/sys/i386/i386/machdep.c#2 (text+ko) ==== @@ -54,6 +54,7 @@ #include "opt_npx.h" #include "opt_perfmon.h" #include "opt_xbox.h" +#include "opt_global.h" #include <sys/param.h> #include <sys/proc.h> @@ -142,6 +143,25 @@ uint32_t arch_i386_xbox_memsize = 0; #endif +#ifdef XEN +/* XEN includes */ +#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); + +int gdt_set; +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 + /* Sanity check for __curthread() */ CTASSERT(offsetof(struct pcpu, pc_curthread) == 0); @@ -286,8 +306,9 @@ */ bufinit(); vm_pager_bufferinit(); - +#ifndef XEN cpu_setregs(); +#endif } /* @@ -1117,6 +1138,25 @@ return (0); } +static int cpu_idle_hlt = 1; +TUNABLE_INT("machdep.cpu_idle_hlt", &cpu_idle_hlt); +SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, + &cpu_idle_hlt, 0, "Idle loop HLT enable"); + +#ifdef XEN +void +cpu_halt(void) +{ + HYPERVISOR_shutdown(SHUTDOWN_poweroff); +} + +static void +cpu_idle_default(void) +{ + idle_block(); +} + +#else /* * Shutdown the CPU as much as possible */ @@ -1142,10 +1182,6 @@ * XXX I'm turning it on for SMP as well by default for now. It seems to * help lock contention somewhat, and this is critical for HTT. -Peter */ -static int cpu_idle_hlt = 1; -TUNABLE_INT("machdep.cpu_idle_hlt", &cpu_idle_hlt); -SYSCTL_INT(_machdep, OID_AUTO, cpu_idle_hlt, CTLFLAG_RW, - &cpu_idle_hlt, 0, "Idle loop HLT enable"); static void cpu_idle_default(void) @@ -1157,7 +1193,7 @@ */ __asm __volatile("sti; hlt"); } - +#endif /* * Note that we have to be careful here to avoid a race between checking * sched_runnable() and actually halting. If we don't do this, we may waste @@ -1307,10 +1343,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 */ @@ -1344,7 +1386,7 @@ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1371,7 +1413,7 @@ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMERA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1380,7 +1422,7 @@ { 0x0, /* segment base address */ 0xfffff, /* length - all address space */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1407,17 +1449,18 @@ { 0x400, /* segment base address */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 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 */ sizeof(struct i386tss)-1,/* length */ SDT_SYS386TSS, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* unused - default 32 vs 16 bit size */ @@ -1430,12 +1473,12 @@ 1, /* segment descriptor present */ 0, 0, 0, /* unused - default 32 vs 16 bit size */ - 0 /* limit granularity (byte/page units)*/ }, + 0 /* limit granularity (byte/page units)*/ }, /* GUSERLDT_SEL 11 User LDT Descriptor per process */ { (int) ldt, /* segment base address */ (512 * sizeof(union descriptor)-1), /* length */ SDT_SYSLDT, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* unused - default 32 vs 16 bit size */ @@ -1444,7 +1487,7 @@ { (int) &dblfault_tss, /* segment base address */ sizeof(struct i386tss)-1,/* length - all address space */ SDT_SYS386TSS, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* unused - default 32 vs 16 bit size */ @@ -1453,7 +1496,7 @@ { 0, /* segment base address (overwritten) */ 0xfffff, /* length */ SDT_MEMERA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* default 32 vs 16 bit size */ @@ -1462,7 +1505,7 @@ { 0, /* segment base address (overwritten) */ 0xfffff, /* length */ SDT_MEMERA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* default 32 vs 16 bit size */ @@ -1471,7 +1514,7 @@ { 0, /* segment base address (overwritten) */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 1, /* default 32 vs 16 bit size */ @@ -1480,7 +1523,7 @@ { 0, /* segment base address (overwritten) */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* default 32 vs 16 bit size */ @@ -1489,7 +1532,7 @@ { 0, /* segment base address (overwritten) */ 0xfffff, /* length */ SDT_MEMRWA, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 1, /* segment descriptor present */ 0, 0, 0, /* default 32 vs 16 bit size */ @@ -1498,11 +1541,12 @@ { 0x0, /* segment base address */ 0x0, /* length */ 0, /* segment type */ - 0, /* segment descriptor priority level */ + SEL_KPL, /* segment descriptor priority level */ 0, /* segment descriptor present */ 0, 0, 0, /* default 32 vs 16 bit size */ 0 /* limit granularity (byte/page units)*/ }, +#endif /* !XEN */ }; static struct soft_segment_descriptor ldt_segs[] = { @@ -1687,7 +1731,16 @@ goto physmap_done; } #endif - +#if defined(XEN) + 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)); @@ -1864,7 +1917,7 @@ vmf.vmf_ah = 0x88; vm86_intcall(0x15, &vmf); extmem = vmf.vmf_ax; -#else +#elif !defined(XEN) /* * Prefer the RTC value for extended memory. */ @@ -1955,6 +2008,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. @@ -2072,7 +2126,11 @@ } *pte = 0; invltlb(); - +#else + phys_avail[0] = physfree; + phys_avail[1] = xen_start_info->nr_pages*PAGE_SIZE; +#endif /* XEN */ + /* * XXX * The last chunk must contain at least one page plus the message @@ -2095,9 +2153,271 @@ for (off = 0; off < round_page(MSGBUF_SIZE); off += PAGE_SIZE) pmap_kenter((vm_offset_t)msgbufp + off, phys_avail[pa_indx] + off); + + PT_UPDATES_FLUSH(); } +#ifdef XEN +extern vm_paddr_t *pdir_shadow; + + +#define MTOPSIZE (1<<(14 + PAGE_SHIFT)) void +init386(int first) +{ + int error, gsel_tss, metadata_missing, x; + unsigned long gdtmachpfn; + 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 ((caddr_t)xen_start_info->cmd_line) + kern_envp = xen_setbootenv((caddr_t)xen_start_info->cmd_line); + + boothowto |= xen_boothowto(kern_envp); + + /* 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); + +#ifdef SMP + pc = &SMP_prvspace[0].pcpu; +#else + pc = &__pcpu; +#endif + + 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); + + printk("gdt=%p\n", gdt); + printk("PTmap=%p\n", PTmap); + printk("addr=%p\n", *vtopte((unsigned long)gdt) & ~PG_RW); + + 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 /* unused */); + gdt_set = 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); + PCPU_SET(pdir, (unsigned long)IdlePTD); + PCPU_SET(pdir_shadow, pdir_shadow); + + /* + * 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 */ + PT_SET_MA(ldt, xpmap_ptom(VTOP(ldt)) | PG_V | PG_RW); + bzero(ldt, PAGE_SIZE); + 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])); + +#ifdef XBOX + /* + * The following code queries the PCI ID of 0:0:0. For the XBOX, + * This should be 0x10de / 0x02a5. + * + * This is exactly what Linux does. + */ + outl(0xcf8, 0x80000000); + if (inl(0xcfc) == 0x02a510de) { + arch_i386_is_xbox = 1; + pic16l_setled(XBOX_LED_GREEN); + + /* + * We are an XBOX, but we may have either 64MB or 128MB of + * memory. The PCI host bridge should be programmed for this, + * so we just query it. + */ + outl(0xcf8, 0x80000084); + arch_i386_xbox_memsize = (inl(0xcfc) == 0x7FFFFFF) ? 128 : 64; + } +#endif /* XBOX */ +#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 + if (xen_start_info->flags & SIF_PRIVILEGED) { + elcr_probe(); +#ifdef DEV_ATPIC + atpic_startup(); +#endif + } +#endif + +#ifdef DDB + ksym_start = bootinfo.bi_symtab; + ksym_end = bootinfo.bi_esymtab; +#endif + + kdb_init(); + +#ifdef KDB + if (boothowto & RB_KDB) + kdb_enter("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); + HYPERVISOR_stack_switch(GSEL(GDATA_SEL, SEL_KPL), + PCPU_GET(common_tss.tss_esp0)); + + + /* 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(); + PCPU_SET(pdir_shadow, pdir_shadow); + getmemsize(first); + init_param2(physmem); + + /* now running on new page tables, configured,and u/iom is accessible */ + + msgbufinit(msgbufp, MSGBUF_SIZE); + + /* 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; { @@ -2363,6 +2683,7 @@ thread0.td_pcb->pcb_ext = 0; thread0.td_frame = &proc0_tf; } +#endif /* !XEN */ void cpu_pcpu_init(struct pcpu *pcpu, int cpuid, size_t size) ==== //depot/projects/xen31_7_0/sys/i386/i386/support.s#2 (text+ko) ==== @@ -1459,10 +1459,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/xen31_7_0/sys/i386/i386/swtch.s#2 (text+ko) ==== @@ -88,7 +88,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 @@ -181,10 +181,10 @@ cmpl %eax,IdlePTD /* Kernel address space? */ #endif je sw0 - movl %cr3,%ebx /* The same address space? */ + READ_CR3(%ebx) /* The same address space? */ cmpl %ebx,%eax je sw0 - movl %eax,%cr3 /* new address space */ + LOAD_CR3(%eax) /* new address space */ movl %esi,%eax movl PCPU(CPUID),%esi SETOP %eax,TD_LOCK(%edi) /* Switchout td_lock */ @@ -211,6 +211,18 @@ SETOP %esi,TD_LOCK(%edi) /* Switchout td_lock */ sw1: BLOCK_SPIN(%ecx) +#ifdef XEN + pushl %eax + pushl %ecx + pushl %edx + call xen_handle_thread_switch + popl %edx + popl %ecx + popl %eax + /* + * XXX set IOPL + */ +#else /* * At this point, we've switched address spaces and are ready * to load up the rest of the next context. @@ -259,7 +271,7 @@ movl 12(%esi), %ebx movl %eax, 8(%edi) >>> TRUNCATED FOR MAIL (1000 lines) <<<help
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200803010829.m218Thfx081202>
