Index: i386/genassym.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/genassym.c,v retrieving revision 1.151 diff -a -u -r1.151 genassym.c --- i386/genassym.c 13 Apr 2005 22:57:17 -0000 1.151 +++ i386/genassym.c 13 Dec 2005 02:03:43 -0000 @@ -199,6 +199,7 @@ ASSYM(PC_CPUID, offsetof(struct pcpu, pc_cpuid)); ASSYM(PC_CURPMAP, offsetof(struct pcpu, pc_curpmap)); + #ifdef DEV_APIC ASSYM(LA_VER, offsetof(struct LAPIC, version)); ASSYM(LA_TPR, offsetof(struct LAPIC, tpr)); @@ -226,3 +227,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 +ASSYM(PC_CR2, offsetof(struct pcpu, pc_cr2)); +ASSYM(PC_CR3, offsetof(struct pcpu, pc_cr3)); +ASSYM(HYPERVISOR_STACK_SWITCH, __HYPERVISOR_stack_switch); +#endif Index: i386/i686_mem.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/i686_mem.c,v retrieving revision 1.24 diff -a -u -r1.24 i686_mem.c --- i386/i686_mem.c 1 Jul 2004 07:46:28 -0000 1.24 +++ i386/i686_mem.c 8 Dec 2005 13:13:40 -0000 @@ -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) Index: i386/initcpu.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/initcpu.c,v retrieving revision 1.53 diff -a -u -r1.53 initcpu.c --- i386/initcpu.c 14 Oct 2005 22:52:00 -0000 1.53 +++ i386/initcpu.c 8 Dec 2005 13:40:13 -0000 @@ -545,6 +545,9 @@ initializecpu(void) { +#ifdef XEN + return; +#endif switch (cpu) { #ifdef I486_CPU case CPU_BLUE: Index: i386/locore.s =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/locore.s,v retrieving revision 1.186 diff -a -u -r1.186 locore.s --- i386/locore.s 16 May 2005 09:47:53 -0000 1.186 +++ i386/locore.s 23 Dec 2005 02:40:39 -0000 @@ -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 @@ -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 Index: i386/support.s =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/support.s,v retrieving revision 1.107 diff -a -u -r1.107 support.s --- i386/support.s 21 Apr 2005 23:07:20 -0000 1.107 +++ i386/support.s 23 Dec 2005 03:05:32 -0000 @@ -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 Index: i386/swtch.s =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/swtch.s,v retrieving revision 1.149 diff -a -u -r1.149 swtch.s --- i386/swtch.s 16 Aug 2005 18:15:17 -0000 1.149 +++ i386/swtch.s 26 Dec 2005 08:58:41 -0000 @@ -33,11 +33,11 @@ */ #include "opt_npx.h" - +#include "opt_global.h" #include #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) /* Check to see if we need to call a switchout function. */ movl PCB_SWITCHOUT(%edx),%eax @@ -168,10 +168,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 @@ -191,6 +191,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. @@ -225,8 +227,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 @@ -238,7 +255,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 @@ -248,11 +265,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. @@ -263,7 +278,7 @@ movl _default_ldt,%eax cmpl PCPU(CURRENTLDT),%eax je 2f - lldt _default_ldt + LLDT(_default_ldt) movl %eax,PCPU(CURRENTLDT) jmp 2f 1: @@ -340,7 +355,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) @@ -349,7 +364,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 @@ -365,8 +380,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 @@ -388,7 +403,7 @@ call bcopy addl $12,%esp 1: - popfl + popfl /* XXX */ #endif /* DEV_NPX */ ret Index: i386/sys_machdep.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/sys_machdep.c,v retrieving revision 1.103 diff -a -u -r1.103 sys_machdep.c --- i386/sys_machdep.c 15 Sep 2005 17:30:07 -0000 1.103 +++ i386/sys_machdep.c 8 Dec 2005 13:40:59 -0000 @@ -55,6 +55,13 @@ #include #include #include +#ifdef XEN +#include +void i386_reset_ldt(struct proc_ldt *pldt); +#else +#define i386_reset_ldt(x) + +#endif #include /* for kernel_map */ @@ -364,6 +371,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 +379,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 +398,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 +416,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 +482,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 +501,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 +692,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 +743,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 +795,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 +808,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)); Index: i386/trap.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/trap.c,v retrieving revision 1.285 diff -a -u -r1.285 trap.c --- i386/trap.c 18 Nov 2005 19:26:46 -0000 1.285 +++ i386/trap.c 13 Dec 2005 01:35:07 -0000 @@ -38,7 +38,7 @@ */ #include -__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 #endif +#ifdef XEN +#include +#include +#include +#include +#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 Index: i386/vm_machdep.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/i386/vm_machdep.c,v retrieving revision 1.267 diff -a -u -r1.267 vm_machdep.c --- i386/vm_machdep.c 14 Nov 2005 00:43:44 -0000 1.267 +++ i386/vm_machdep.c 8 Dec 2005 13:47:54 -0000 @@ -41,7 +41,7 @@ */ #include -__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 +#endif static void cpu_reset_real(void); #ifdef SMP static void cpu_reset_proxy(void); @@ -780,6 +782,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); } Index: include/asmacros.h =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/include/asmacros.h,v retrieving revision 1.27 diff -a -u -r1.27 asmacros.h --- include/asmacros.h 5 Dec 2005 21:44:47 -0000 1.27 +++ include/asmacros.h 23 Dec 2005 00:55:32 -0000 @@ -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_ */ Index: include/pcpu.h =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/include/pcpu.h,v retrieving revision 1.44 diff -a -u -r1.44 pcpu.h --- include/pcpu.h 13 Apr 2005 22:57:17 -0000 1.44 +++ include/pcpu.h 13 Dec 2005 01:29:55 -0000 @@ -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; \ @@ -54,8 +55,29 @@ struct segment_descriptor *pc_fsgs_gdt; \ int pc_currentldt; \ u_int pc_acpi_id; \ - u_int pc_apic_id - + u_int pc_apic_id; +#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_ipi_to_evtchn; \ + int *pc_virq_to_irq; \ + u_int pc_cr2; \ + u_int pc_cr3; \ + u_int pc_pdir; \ + u_int pc_lazypmap; \ + u_int pc_rendezvous; \ + u_int pc_cpuast; \ + u_int pc_time_irq; \ + uint64_t pc_processed_system_time; +#endif #if defined(lint) extern struct pcpu *pcpup; Index: include/pmap.h =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/include/pmap.h,v retrieving revision 1.118 diff -a -u -r1.118 pmap.h --- include/pmap.h 6 Dec 2005 21:09:01 -0000 1.118 +++ include/pmap.h 13 Dec 2005 02:17:19 -0000 @@ -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_ */ Index: include/segments.h =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/include/segments.h,v retrieving revision 1.38 diff -a -u -r1.38 segments.h --- include/segments.h 13 Apr 2005 22:57:17 -0000 1.38 +++ include/segments.h 8 Dec 2005 14:03:10 -0000 @@ -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 4 +#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); Index: include/trap.h =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/include/trap.h,v retrieving revision 1.15 diff -a -u -r1.15 trap.h --- include/trap.h 14 Oct 2005 03:01:14 -0000 1.15 +++ include/trap.h 13 Dec 2005 01:33:06 -0000 @@ -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 */ Index: isa/npx.c =================================================================== RCS file: /usr/home/kmacy/ncvs/src/sys/i386/isa/npx.c,v retrieving revision 1.163 diff -a -u -r1.163 npx.c --- isa/npx.c 5 Dec 2005 22:11:44 -0000 1.163 +++ isa/npx.c 23 Dec 2005 03:43:03 -0000 @@ -101,9 +101,14 @@ #define fxsave(addr) __asm __volatile("fxsave %0" : "=m" (*(addr))) #define ldmxcsr(__csr) __asm __volatile("ldmxcsr %0" : : "m" (__csr)) #endif +#ifdef XEN +#define start_emulating() (HYPERVISOR_fpu_taskswitch(1)) +#define stop_emulating() (HYPERVISOR_fpu_taskswitch(0)) +#else #define start_emulating() __asm("smsw %%ax; orb %0,%%al; lmsw %%ax" \ : : "n" (CR0_TS) : "ax") #define stop_emulating() __asm("clts") +#endif #else /* !(__GNUCLIKE_ASM && !lint) */ @@ -250,6 +255,10 @@ u_short control; u_short status; +#ifdef XEN + return (0); +#endif + save_idt_npxtrap = idt[IDT_MF]; setidt(IDT_MF, probetrap, SDT_SYS386TGT, SEL_KPL, GSEL(GCODE_SEL, SEL_KPL));