[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Xen-devel] [PATCH] make XenFreeBSD trapframe the same as native i386


  • To: xen-devel@xxxxxxxxxxxxxxxxxxx
  • From: Kip Macy <kmacy@xxxxxxxxxx>
  • Date: Sun, 1 May 2005 17:08:28 -0700 (PDT)
  • Delivery-date: Mon, 02 May 2005 00:08:23 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xensource.com>


# This is a BitKeeper generated diff -Nru style patch.
#
# ChangeSet
#   2005/05/01 16:04:24-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx 
#   Make trapframe the same size as on native i386
#   Signed-off-by: Kip Macy <kmacy@xxxxxxxxxxx>
# 
# freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h
#   2005/05/01 16:04:20-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +3 -2
#   add per-cpu fields for evtchn and page faults
# 
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/trap.c
#   2005/05/01 16:04:20-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +1 -9
#   remove STACK_DEBUGGING cruft
#   fetch cr2 from pcpu area
# 
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/genassym.c
#   2005/05/01 16:04:20-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +1 -2
#   remove unused trap_nesting
#   add cr2 field
# 
# freebsd-5.3-xen-sparse/i386-xen/i386-xen/exception.s
#   2005/05/01 16:04:20-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +41 -31
#   Save CR2 after trap frame then move to pcpu area
# 
# BitKeeper/deleted/.del-ucontext.h~6f534fc91cb2d96b
#   2005/05/01 15:56:03-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +0 -1
#   Delete: freebsd-5.3-xen-sparse/i386-xen/include/ucontext.h
# 
# BitKeeper/deleted/.del-frame.h~fbfe41b49597c684
#   2005/05/01 15:55:59-07:00 kmacy@xxxxxxxxxxxxxxxxxxxx +3 -3
#   Delete: freebsd-5.3-xen-sparse/i386-xen/include/frame.h
# 
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/exception.s 
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/exception.s
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/exception.s      2005-04-30 
17:06:50 -07:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/exception.s      2005-04-30 
17:06:50 -07:00
@@ -91,47 +91,52 @@
 MCOUNT_LABEL(btrap)
 
 IDTVEC(div)
-       pushl $0; pushl $0; TRAP(T_DIVIDE)
+       pushl $0; TRAP(T_DIVIDE)
 IDTVEC(dbg)
-       pushl $0; pushl $0; TRAP(T_TRCTRAP)
+       pushl $0; TRAP(T_TRCTRAP)
 IDTVEC(nmi)
-       pushl $0; pushl $0; TRAP(T_NMI)
+       pushl $0; TRAP(T_NMI)
 IDTVEC(bpt)
-       pushl $0; pushl $0; TRAP(T_BPTFLT)
+       pushl $0; TRAP(T_BPTFLT)
 IDTVEC(ofl)
-       pushl $0; pushl $0; TRAP(T_OFLOW)
+       pushl $0; TRAP(T_OFLOW)
 IDTVEC(bnd)
-       pushl $0; pushl $0; TRAP(T_BOUND)
+       pushl $0; TRAP(T_BOUND)
 IDTVEC(ill)
-       pushl $0; pushl $0; TRAP(T_PRIVINFLT)
+       pushl $0; TRAP(T_PRIVINFLT)
 IDTVEC(dna)
-       pushl $0; pushl $0; TRAP(T_DNA)
+       pushl $0; TRAP(T_DNA)
 IDTVEC(fpusegm)
-       pushl $0; pushl $0; TRAP(T_FPOPFLT)
+       pushl $0; TRAP(T_FPOPFLT)
 IDTVEC(tss)
-       pushl $0; TRAP(T_TSSFLT)
+       TRAP(T_TSSFLT)
 IDTVEC(missing)
-       pushl $0; TRAP(T_SEGNPFLT)
+       TRAP(T_SEGNPFLT)
 IDTVEC(stk)
-       pushl $0; TRAP(T_STKFLT)
+       TRAP(T_STKFLT)
 IDTVEC(prot)
-       pushl $0; TRAP(T_PROTFLT)
+       TRAP(T_PROTFLT)
 IDTVEC(page)
+       pushl %eax 
+       movl  4(%esp),%eax
+       movl  %eax,-44(%esp)    # move cr2 after trap frame
+       popl %eax
+       addl $4,%esp
        TRAP(T_PAGEFLT)
 IDTVEC(mchk)
-       pushl $0; pushl $0; TRAP(T_MCHK)
+       pushl $0; TRAP(T_MCHK)
 IDTVEC(rsvd)
-       pushl $0; pushl $0; TRAP(T_RESERVED)
+       pushl $0; TRAP(T_RESERVED)
 IDTVEC(fpu)
-       pushl $0; pushl $0; TRAP(T_ARITHTRAP)
+       pushl $0; TRAP(T_ARITHTRAP)
 IDTVEC(align)
-       pushl $0; TRAP(T_ALIGNFLT)
+       TRAP(T_ALIGNFLT)
 
 IDTVEC(xmm)
-       pushl $0; pushl $0; TRAP(T_XMMFLT)
+       pushl $0; TRAP(T_XMMFLT)
 
 IDTVEC(hypervisor_callback)
-        pushl $T_HYPCALLBACK;  pushl %eax; TRAP(T_HYPCALLBACK)
+       pushl %eax; TRAP(T_HYPCALLBACK)
 
 hypervisor_callback_pending:
        movl    $T_HYPCALLBACK,TF_TRAPNO(%esp)
@@ -161,6 +166,12 @@
        movl    $KPSEL,%eax
        movl    %eax,%fs
        FAKE_MCOUNT(TF_EIP(%esp))
+save_cr2:
+       movl    TF_TRAPNO(%esp),%eax
+       cmpl    $T_PAGEFLT,%eax
+       jne     calltrap
+       movl    -4(%esp),%eax
+       movl    %eax,PCPU(CR2)
 calltrap:
        movl    TF_EIP(%esp),%eax
        cmpl    $scrit,%eax
@@ -217,8 +228,7 @@
        SUPERALIGN_TEXT
 IDTVEC(int0x80_syscall)
        pushl   $2                      /* sizeof "int 0x80" */
-       pushl   $0xCAFE
-       pushl   $0xDEAD
+       pushl   $0xBEEF
        pushal
        pushl   %ds
        pushl   %es
@@ -324,7 +334,7 @@
 doreti_popl_ds:
        popl    %ds
        POPA
-       addl    $12,%esp
+       addl    $8,%esp
        .globl  doreti_iret
 doreti_iret:
        iret
@@ -341,7 +351,7 @@
        ALIGN_TEXT
        .globl  doreti_iret_fault
 doreti_iret_fault:
-       subl    $12,%esp
+       subl    $8,%esp
        pushal
        pushl   %ds
        .globl  doreti_popl_ds_fault
@@ -376,7 +386,7 @@
         movl  %esp,%esi
         add  %eax,%esi        # %esi points at end of src region
         movl  %esp,%edi
-        add  $0x44,%edi       # %edi points at end of dst region
+        add  $0x40,%edi       # %edi points at end of dst region
         movl  %eax,%ecx
         shr  $2,%ecx          # convert bytes to words
         je   16f              # skip loop if nothing to copy
@@ -403,8 +413,8 @@
 .byte   0x20                           #pop    %edx
 .byte   0x24                           #pop    %ecx
 .byte   0x28                           #pop    %eax
-.byte   0x2c,0x2c,0x2c                  #add    $0xc,%esp
-.byte   0x38                           #iret   
+.byte   0x2c,0x2c,0x2c                  #add    $0x8,%esp
+.byte   0x34                           #iret   
 
        
 /* # Hypervisor uses this for application faults while it executes.*/
@@ -412,17 +422,17 @@
        pushal
        call xen_failsafe_handler
 /*#    call install_safe_pf_handler */
-        movl 32(%esp),%ebx
+        movl 28(%esp),%ebx
 1:      movl %ebx,%ds
-        movl 36(%esp),%ebx
+        movl 32(%esp),%ebx
 2:      movl %ebx,%es
-        movl 40(%esp),%ebx
+        movl 36(%esp),%ebx
 3:      movl %ebx,%fs
-        movl 44(%esp),%ebx
+        movl 40(%esp),%ebx
 4:      movl %ebx,%gs
 /*#        call install_normal_pf_handler */
        popal
-       addl $16,%esp
+       addl $12,%esp
        iret
 
 
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/genassym.c 
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/genassym.c
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/genassym.c       2005-04-30 
17:06:50 -07:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/genassym.c       2005-04-30 
17:06:50 -07:00
@@ -200,8 +200,7 @@
 ASSYM(PC_CURRENTLDT, offsetof(struct pcpu, pc_currentldt));
 ASSYM(PC_CPUID, offsetof(struct pcpu, pc_cpuid));
 ASSYM(PC_CURPMAP, offsetof(struct pcpu, pc_curpmap));
-ASSYM(PC_TRAP_NESTING, offsetof(struct pcpu, pc_trap_nesting));
-
+ASSYM(PC_CR2, offsetof(struct pcpu, pc_cr2));
 ASSYM(PC_CR3, offsetof(struct pcpu, pc_pdir));
 
 #ifdef DEV_APIC
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/trap.c 
b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/trap.c
--- a/freebsd-5.3-xen-sparse/i386-xen/i386-xen/trap.c   2005-04-30 17:06:49 
-07:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/i386-xen/trap.c   2005-04-30 17:06:49 
-07:00
@@ -181,11 +181,6 @@
        u_int sticks = 0;
        int i = 0, ucode = 0, type, code;
        vm_offset_t eva;
-#ifdef STACK_DEBUGGING
-       int nesting, current_sp;
-       static int prev_csp = 0, prev_ssp = 0;
-       nesting = PCPU_GET(trap_nesting);
-#endif
 
 #ifdef POWERFAIL_NMI
        static int lastalert = 0;
@@ -227,7 +222,7 @@
                 * kernel can print out a useful trap message and even get
                 * to the debugger.
                 */
-               eva = frame.tf_cr2;
+               eva = PCPU_GET(cr2);
 
                if (td->td_critnest != 0)                       
                    trap_fatal(&frame, eva);
@@ -613,9 +608,6 @@
        mtx_assert(&Giant, MA_NOTOWNED);
 userout:
 out:
-#ifdef STACK_DEBUGGING 
-       PCPU_SET(trap_nesting, nesting);
-#endif
        return;
 }
 
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/include/frame.h 
b/freebsd-5.3-xen-sparse/i386-xen/include/frame.h
--- a/freebsd-5.3-xen-sparse/i386-xen/include/frame.h   2005-04-30 17:06:49 
-07:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,129 +0,0 @@
-/*-
- * Copyright (c) 1990 The Regents of the University of California.
- * All rights reserved.
- *
- * This code is derived from software contributed to Berkeley by
- * William Jolitz.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. All advertising materials mentioning features or use of this software
- *    must display the following acknowledgement:
- *     This product includes software developed by the University of
- *     California, Berkeley and its contributors.
- * 4. Neither the name of the University nor the names of its contributors
- *    may be used to endorse or promote products derived from this software
- *    without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- *     from: @(#)frame.h       5.2 (Berkeley) 1/18/91
- * $FreeBSD: src/sys/i386/include/frame.h,v 1.23 2003/07/22 08:11:15 peter Exp 
$
- */
-
-#ifndef _MACHINE_FRAME_H_
-#define _MACHINE_FRAME_H_ 1
-
-/*
- * System stack frames.
- */
-
-/*
- * Exception/Trap Stack Frame
- */
-
-struct trapframe {
-       int     tf_fs;
-       int     tf_es;
-       int     tf_ds;
-       int     tf_edi;
-       int     tf_esi;
-       int     tf_ebp;
-       int     tf_isp;
-       int     tf_ebx;
-       int     tf_edx;
-       int     tf_ecx;
-       int     tf_eax;
-       int     tf_trapno;
-        int     tf_cr2; 
-       /* below portion defined in 386 hardware */
-       int     tf_err;
-       int     tf_eip;
-       int     tf_cs;
-       int     tf_eflags;
-       /* below only when crossing rings (e.g. user to kernel) */
-       int     tf_esp;
-       int     tf_ss;
-};
-
-/* Interrupt stack frame */
-
-struct intrframe {
-       int     if_fs;
-       int     if_es;
-       int     if_ds;
-       int     if_edi;
-       int     if_esi;
-       int     if_ebp;
-       int     :32;
-       int     if_ebx;
-       int     if_edx;
-       int     if_ecx;
-       int     if_eax;
-       int     :32;            /* for compat with trap frame - trapno */
-        int     if_vec;         /* cr2 in trap frame */
-       int     :32;            /* for compat with trap frame - err */
-       /* below portion defined in 386 hardware */
-       int     if_eip;
-       int     if_cs;
-       int     if_eflags;
-       /* below only when crossing rings (e.g. user to kernel) */
-       int     if_esp;
-       int     if_ss;
-};
-
-/* frame of clock (same as interrupt frame) */
-
-struct clockframe {
-       int     cf_fs;
-       int     cf_es;
-       int     cf_ds;
-       int     cf_edi;
-       int     cf_esi;
-       int     cf_ebp;
-       int     :32;
-       int     cf_ebx;
-       int     cf_edx;
-       int     cf_ecx;
-       int     cf_eax;
-       int     :32;            /* for compat with trap frame - trapno */
-        int     cf_vec;         /* cr2 in trap frame */ 
-       int     :32;            /* for compat with trap frame - err */
-       /* below portion defined in 386 hardware */
-       int     cf_eip;
-       int     cf_cs;
-       int     cf_eflags;
-       /* below only when crossing rings (e.g. user to kernel) */
-       int     cf_esp;
-       int     cf_ss;
-};
-
-#define        INTR_TO_TRAPFRAME(frame) ((struct trapframe *)&(frame)->if_fs)
-
-#endif /* _MACHINE_FRAME_H_ */
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h 
b/freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h
--- a/freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h    2005-04-30 17:06:49 
-07:00
+++ b/freebsd-5.3-xen-sparse/i386-xen/include/pcpu.h    2005-04-30 17:06:49 
-07:00
@@ -50,8 +50,9 @@
        int     pc_currentldt;                                          \
        u_int   pc_acpi_id;                                             \
        u_int   pc_apic_id;                                             \
-        u_int   pc_faultaddr;                                           \
-        u_int   pc_trap_nesting;                                        \
+        int     *pc_ipi_to_evtchn;                                      \
+        int     *pc_virq_to_irq;                                        \
+        u_int   pc_cr2;                                                 \
         u_int   pc_pdir                                        
 
 #if defined(lint)
diff -Nru a/freebsd-5.3-xen-sparse/i386-xen/include/ucontext.h 
b/freebsd-5.3-xen-sparse/i386-xen/include/ucontext.h
--- a/freebsd-5.3-xen-sparse/i386-xen/include/ucontext.h        2005-04-30 
17:06:49 -07:00
+++ /dev/null   Wed Dec 31 16:00:00 196900
@@ -1,105 +0,0 @@
-/*-
- * Copyright (c) 1999 Marcel Moolenaar
- * All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer 
- *    in this position and unchanged.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- * 3. The name of the author may not be used to endorse or promote products
- *    derived from this software without specific prior written permission.
- *
- * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
- * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
- * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
- * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
- * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
- * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
- * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
- *
- * $FreeBSD: src/sys/i386/include/ucontext.h,v 1.10 2002/12/02 19:58:55 
deischen Exp $
- */
-
-#ifndef _MACHINE_UCONTEXT_H_
-#define        _MACHINE_UCONTEXT_H_
-
-typedef struct __mcontext {
-       /*
-        * The first 20 fields must match the definition of
-        * sigcontext. So that we can support sigcontext
-        * and ucontext_t at the same time.
-        */
-       int     mc_onstack;             /* XXX - sigcontext compat. */
-       int     mc_gs;                  /* machine state (struct trapframe) */
-       int     mc_fs;
-       int     mc_es;
-       int     mc_ds;
-       int     mc_edi;
-       int     mc_esi;
-       int     mc_ebp;
-       int     mc_isp;
-       int     mc_ebx;
-       int     mc_edx;
-       int     mc_ecx;
-       int     mc_eax;
-       int     mc_trapno;
-        int     mc_cr2;
-       int     mc_err;
-       int     mc_eip;
-       int     mc_cs;
-       int     mc_eflags;
-       int     mc_esp;
-       int     mc_ss;
-
-       int     mc_len;                 /* sizeof(mcontext_t) */
-#define        _MC_FPFMT_NODEV         0x10000 /* device not present or 
configured */
-#define        _MC_FPFMT_387           0x10001
-#define        _MC_FPFMT_XMM           0x10002
-       int     mc_fpformat;
-#define        _MC_FPOWNED_NONE        0x20000 /* FP state not used */
-#define        _MC_FPOWNED_FPU         0x20001 /* FP state came from FPU */
-#define        _MC_FPOWNED_PCB         0x20002 /* FP state came from PCB */
-       int     mc_ownedfp;
-       /*
-        * See <machine/npx.h> for the internals of mc_fpstate[].
-        */
-       int     mc_fpstate[128] __aligned(16);
-       int     mc_spare2[8];
-} mcontext_t;
-
-#if defined(_KERNEL) && defined(COMPAT_FREEBSD4)
-struct mcontext4 {
-       int     mc_onstack;             /* XXX - sigcontext compat. */
-       int     mc_gs;                  /* machine state (struct trapframe) */
-       int     mc_fs;
-       int     mc_es;
-       int     mc_ds;
-       int     mc_edi;
-       int     mc_esi;
-       int     mc_ebp;
-       int     mc_isp;
-       int     mc_ebx;
-       int     mc_edx;
-       int     mc_ecx;
-       int     mc_eax;
-       int     mc_trapno;
-       int     mc_err;
-       int     mc_eip;
-       int     mc_cs;
-       int     mc_eflags;
-       int     mc_esp;                 /* machine state */
-       int     mc_ss;
-       int     mc_fpregs[28];          /* env87 + fpacc87 + u_long */
-       int     __spare__[17];
-};
-#endif
-
-#endif /* !_MACHINE_UCONTEXT_H_ */


_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxxxxxxxx
http://lists.xensource.com/xen-devel


 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.