ia64/xen-unstable

changeset 3754:2318bacbb21e

bitkeeper revision 1.1159.1.560 (420a3937bsia3-KUKXK3oI9TTu7gaA)

Loads more x86_64 work. entry.S is now done so we reflect exceptions
and interrupts to the guest. The only missing parts are new hypercalls
to set FS_BASE, GS_BASE_KERN, GS_BASE_USER. Also the concept of two
L4 pagetable bases -- one for user, one for kernel.
Signed-off-by: keir.fraser@cl.cam.ac.uk
author kaf24@scramble.cl.cam.ac.uk
date Wed Feb 09 16:24:23 2005 +0000 (2005-02-09)
parents 0d53bdb43b1c
children 1494093616a3
files xen/arch/x86/dom0_ops.c xen/arch/x86/domain.c xen/arch/x86/traps.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_32/traps.c xen/arch/x86/x86_64/asm-offsets.c xen/arch/x86/x86_64/entry.S xen/include/asm-x86/config.h xen/include/asm-x86/processor.h xen/include/asm-x86/regs.h xen/include/asm-x86/x86_32/regs.h xen/include/asm-x86/x86_64/current.h xen/include/asm-x86/x86_64/regs.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h
line diff
     1.1 --- a/xen/arch/x86/dom0_ops.c	Wed Feb 09 10:16:50 2005 +0000
     1.2 +++ b/xen/arch/x86/dom0_ops.c	Wed Feb 09 16:24:23 2005 +0000
     1.3 @@ -355,6 +355,8 @@ void arch_getdomaininfo_ctxt(
     1.4             sizeof(ed->arch.user_ctxt));
     1.5      if ( test_bit(EDF_DONEFPUINIT, &ed->ed_flags) )
     1.6          c->flags |= ECF_I387_VALID;
     1.7 +    if ( GUESTOS_MODE(ed, &ed->arch.user_ctxt) )
     1.8 +        c->flags |= ECF_IN_GUESTOS;
     1.9      memcpy(&c->fpu_ctxt,
    1.10             &ed->arch.i387,
    1.11             sizeof(ed->arch.i387));
     2.1 --- a/xen/arch/x86/domain.c	Wed Feb 09 10:16:50 2005 +0000
     2.2 +++ b/xen/arch/x86/domain.c	Wed Feb 09 16:24:23 2005 +0000
     2.3 @@ -36,6 +36,7 @@
     2.4  #include <xen/elf.h>
     2.5  #include <asm/vmx.h>
     2.6  #include <asm/vmx_vmcs.h>
     2.7 +#include <asm/msr.h>
     2.8  #include <xen/kernel.h>
     2.9  #include <public/io/ioreq.h>
    2.10  #include <xen/multicall.h>
    2.11 @@ -286,6 +287,8 @@ void arch_do_createdomain(struct exec_do
    2.12          d->arch.mm_perdomain_l3[l3_table_offset(PERDOMAIN_VIRT_START)] = 
    2.13              mk_l3_pgentry(__pa(d->arch.mm_perdomain_l2) | __PAGE_HYPERVISOR);
    2.14  #endif
    2.15 +
    2.16 +        ed->arch.flags = TF_guestos_mode;
    2.17      }
    2.18  }
    2.19  
    2.20 @@ -295,6 +298,7 @@ void arch_do_boot_vcpu(struct exec_domai
    2.21      ed->arch.schedule_tail = d->exec_domain[0]->arch.schedule_tail;
    2.22      ed->arch.perdomain_ptes = 
    2.23          d->arch.mm_perdomain_pt + (ed->eid << PDPT_VCPU_SHIFT);
    2.24 +    ed->arch.flags = TF_guestos_mode;
    2.25  }
    2.26  
    2.27  #ifdef CONFIG_VMX
    2.28 @@ -445,6 +449,10 @@ int arch_final_setup_guestos(
    2.29      if ( c->flags & ECF_I387_VALID )
    2.30          set_bit(EDF_DONEFPUINIT, &d->ed_flags);
    2.31  
    2.32 +    d->arch.flags &= ~TF_guestos_mode;
    2.33 +    if ( c->flags & ECF_IN_GUESTOS )
    2.34 +        d->arch.flags |= TF_guestos_mode;
    2.35 +
    2.36      memcpy(&d->arch.user_ctxt,
    2.37             &c->cpu_ctxt,
    2.38             sizeof(d->arch.user_ctxt));
    2.39 @@ -558,12 +566,21 @@ void switch_to(struct exec_domain *prev_
    2.40  #ifdef CONFIG_VMX
    2.41      unsigned long vmx_domain = next_p->arch.arch_vmx.flags; 
    2.42  #endif
    2.43 +#ifdef __x86_64__
    2.44 +    int all_segs_okay = 1;
    2.45 +#endif
    2.46  
    2.47      __cli();
    2.48  
    2.49      /* Switch guest general-register state. */
    2.50      if ( !is_idle_task(prev_p->domain) )
    2.51      {
    2.52 +#ifdef __x86_64__
    2.53 +        __asm__ __volatile__ ( "movl %%ds,%0" : "=m" (stack_ec->ds) );
    2.54 +        __asm__ __volatile__ ( "movl %%es,%0" : "=m" (stack_ec->es) );
    2.55 +        __asm__ __volatile__ ( "movl %%fs,%0" : "=m" (stack_ec->fs) );
    2.56 +        __asm__ __volatile__ ( "movl %%gs,%0" : "=m" (stack_ec->gs) );
    2.57 +#endif
    2.58          memcpy(&prev_p->arch.user_ctxt,
    2.59                 stack_ec, 
    2.60                 sizeof(*stack_ec));
    2.61 @@ -642,6 +659,127 @@ void switch_to(struct exec_domain *prev_
    2.62      load_LDT(next_p);
    2.63  
    2.64      __sti();
    2.65 +
    2.66 +#ifdef __x86_64__
    2.67 +
    2.68 +#define loadsegment(seg,value) ({               \
    2.69 +    int __r = 1;                                \
    2.70 +    __asm__ __volatile__ (                      \
    2.71 +        "1: movl %k1,%%" #seg "\n2:\n"          \
    2.72 +        ".section .fixup,\"ax\"\n"              \
    2.73 +        "3: xorl %k0,%k0\n"                     \
    2.74 +        "   movl %k0,%%" #seg "\n"              \
    2.75 +        "   jmp 2b\n"                           \
    2.76 +        ".previous\n"                           \
    2.77 +        ".section __ex_table,\"a\"\n"           \
    2.78 +        "   .align 8\n"                         \
    2.79 +        "   .quad 1b,3b\n"                      \
    2.80 +        ".previous"                             \
    2.81 +        : "=r" (__r) : "r" (value), "0" (__r) );\
    2.82 +    __r; })
    2.83 +
    2.84 +    /* Either selector != 0 ==> reload. */
    2.85 +    if ( unlikely(prev_p->arch.user_ctxt.ds) ||
    2.86 +         unlikely(next_p->arch.user_ctxt.ds) )
    2.87 +        all_segs_okay &= loadsegment(ds, next_p->arch.user_ctxt.ds);
    2.88 +
    2.89 +    /* Either selector != 0 ==> reload. */
    2.90 +    if ( unlikely(prev_p->arch.user_ctxt.es) ||
    2.91 +         unlikely(next_p->arch.user_ctxt.es) )
    2.92 +        all_segs_okay &= loadsegment(es, next_p->arch.user_ctxt.es);
    2.93 +
    2.94 +    /*
    2.95 +     * Either selector != 0 ==> reload.
    2.96 +     * Also reload to reset FS_BASE if it was non-zero.
    2.97 +     */
    2.98 +    if ( unlikely(prev_p->arch.user_ctxt.fs) ||
    2.99 +         unlikely(prev_p->arch.user_ctxt.fs_base) ||
   2.100 +         unlikely(next_p->arch.user_ctxt.fs) )
   2.101 +    {
   2.102 +        all_segs_okay &= loadsegment(fs, next_p->arch.user_ctxt.fs);
   2.103 +        if ( prev_p->arch.user_ctxt.fs ) /* != 0 selector kills fs_base */
   2.104 +            prev_p->arch.user_ctxt.fs_base = 0;
   2.105 +    }
   2.106 +
   2.107 +    /*
   2.108 +     * Either selector != 0 ==> reload.
   2.109 +     * Also reload to reset GS_BASE if it was non-zero.
   2.110 +     */
   2.111 +    if ( unlikely(prev_p->arch.user_ctxt.gs) ||
   2.112 +         unlikely(prev_p->arch.user_ctxt.gs_base_os) ||
   2.113 +         unlikely(prev_p->arch.user_ctxt.gs_base_app) ||
   2.114 +         unlikely(next_p->arch.user_ctxt.gs) )
   2.115 +    {
   2.116 +        /* Reset GS_BASE with user %gs. */
   2.117 +        all_segs_okay &= loadsegment(gs, next_p->arch.user_ctxt.gs);
   2.118 +        /* Reset KERNEL_GS_BASE if we won't be doing it later. */
   2.119 +        if ( !next_p->arch.user_ctxt.gs_base_os )
   2.120 +            wrmsr(MSR_KERNEL_GS_BASE, 0, 0);
   2.121 +        if ( prev_p->arch.user_ctxt.gs ) /* != 0 selector kills app gs_base */
   2.122 +            prev_p->arch.user_ctxt.gs_base_app = 0;
   2.123 +    }
   2.124 +
   2.125 +    /* This can only be non-zero if selector is NULL. */
   2.126 +    if ( next_p->arch.user_ctxt.fs_base )
   2.127 +        wrmsr(MSR_FS_BASE,
   2.128 +              next_p->arch.user_ctxt.fs_base,
   2.129 +              next_p->arch.user_ctxt.fs_base>>32);
   2.130 +
   2.131 +    /* This can only be non-zero if selector is NULL. */
   2.132 +    if ( next_p->arch.user_ctxt.gs_base_os )
   2.133 +        wrmsr(MSR_KERNEL_GS_BASE,
   2.134 +              next_p->arch.user_ctxt.gs_base_os,
   2.135 +              next_p->arch.user_ctxt.gs_base_os>>32);
   2.136 +
   2.137 +    /* This can only be non-zero if selector is NULL. */
   2.138 +    if ( next_p->arch.user_ctxt.gs_base_app )
   2.139 +        wrmsr(MSR_GS_BASE,
   2.140 +              next_p->arch.user_ctxt.gs_base_app,
   2.141 +              next_p->arch.user_ctxt.gs_base_app>>32);
   2.142 +
   2.143 +    /* If in guest-OS mode, switch the GS bases around. */
   2.144 +    if ( next_p->arch.flags & TF_guestos_mode )
   2.145 +        __asm__ __volatile__ ( "swapgs" );
   2.146 +
   2.147 +    if ( unlikely(!all_segs_okay) )
   2.148 +    {
   2.149 +        unsigned long *rsp =
   2.150 +            (next_p->arch.flags & TF_guestos_mode) ?
   2.151 +            (unsigned long *)stack_ec->rsp : 
   2.152 +            (unsigned long *)next_p->arch.guestos_sp;
   2.153 +
   2.154 +        if ( put_user(stack_ec->ss,     rsp- 1) |
   2.155 +             put_user(stack_ec->rsp,    rsp- 2) |
   2.156 +             put_user(stack_ec->rflags, rsp- 3) |
   2.157 +             put_user(stack_ec->cs,     rsp- 4) |
   2.158 +             put_user(stack_ec->rip,    rsp- 5) |
   2.159 +             put_user(stack_ec->gs,     rsp- 6) |
   2.160 +             put_user(stack_ec->fs,     rsp- 7) |
   2.161 +             put_user(stack_ec->es,     rsp- 8) |
   2.162 +             put_user(stack_ec->ds,     rsp- 9) |
   2.163 +             put_user(stack_ec->r11,    rsp-10) |
   2.164 +             put_user(stack_ec->rcx,    rsp-11) )
   2.165 +        {
   2.166 +            DPRINTK("Error while creating failsafe callback frame.\n");
   2.167 +            domain_crash();
   2.168 +        }
   2.169 +
   2.170 +        if ( !(next_p->arch.flags & TF_guestos_mode) )
   2.171 +        {
   2.172 +            next_p->arch.flags |= TF_guestos_mode;
   2.173 +            __asm__ __volatile__ ( "swapgs" );
   2.174 +            /* XXX switch page tables XXX */
   2.175 +        }
   2.176 +
   2.177 +        stack_ec->entry_vector  = TRAP_syscall;
   2.178 +        stack_ec->rflags       &= 0xFFFCBEFFUL;
   2.179 +        stack_ec->ss            = __GUEST_SS;
   2.180 +        stack_ec->rsp           = (unsigned long)(rsp-11);
   2.181 +        stack_ec->cs            = __GUEST_CS;
   2.182 +        stack_ec->rip           = next_p->arch.failsafe_address;
   2.183 +    }
   2.184 +
   2.185 +#endif /* __x86_64__ */
   2.186  }
   2.187  
   2.188  
     3.1 --- a/xen/arch/x86/traps.c	Wed Feb 09 10:16:50 2005 +0000
     3.2 +++ b/xen/arch/x86/traps.c	Wed Feb 09 16:24:23 2005 +0000
     3.3 @@ -146,7 +146,7 @@ static inline int do_trap(int trapnr, ch
     3.4  
     3.5      DEBUGGER_trap_entry(trapnr, regs);
     3.6  
     3.7 -    if ( !GUEST_FAULT(regs) )
     3.8 +    if ( !GUEST_MODE(regs) )
     3.9          goto xen_fault;
    3.10  
    3.11  #ifndef NDEBUG
    3.12 @@ -217,7 +217,7 @@ asmlinkage int do_int3(struct xen_regs *
    3.13  
    3.14      DEBUGGER_trap_entry(TRAP_int3, regs);
    3.15  
    3.16 -    if ( !GUEST_FAULT(regs) )
    3.17 +    if ( !GUEST_MODE(regs) )
    3.18      {
    3.19          DEBUGGER_trap_fatal(TRAP_int3, regs);
    3.20          show_registers(regs);
    3.21 @@ -316,7 +316,7 @@ asmlinkage int do_page_fault(struct xen_
    3.22              return EXCRET_fault_fixed; /* successfully copied the mapping */
    3.23      }
    3.24  
    3.25 -    if ( !GUEST_FAULT(regs) )
    3.26 +    if ( !GUEST_MODE(regs) )
    3.27          goto xen_fault;
    3.28  
    3.29  #ifndef NDEBUG
    3.30 @@ -485,7 +485,7 @@ asmlinkage int do_general_protection(str
    3.31      if ( regs->error_code & 1 )
    3.32          goto hardware_gp;
    3.33  
    3.34 -    if ( !GUEST_FAULT(regs) )
    3.35 +    if ( !GUEST_MODE(regs) )
    3.36          goto gp_in_kernel;
    3.37  
    3.38      /*
    3.39 @@ -522,7 +522,7 @@ asmlinkage int do_general_protection(str
    3.40  
    3.41      /* Emulate some simple privileged instructions when exec'ed in ring 1. */
    3.42      if ( (regs->error_code == 0) &&
    3.43 -         GUESTOS_FAULT(regs) &&
    3.44 +         GUESTOS_MODE(ed, regs) &&
    3.45           emulate_privileged_op(regs) )
    3.46          return 0;
    3.47  
    3.48 @@ -685,7 +685,7 @@ asmlinkage int do_debug(struct xen_regs 
    3.49          goto out;
    3.50      }
    3.51  
    3.52 -    if ( !GUEST_FAULT(regs) )
    3.53 +    if ( !GUEST_MODE(regs) )
    3.54      {
    3.55          /* Clear TF just for absolute sanity. */
    3.56          regs->eflags &= ~EF_TF;
     4.1 --- a/xen/arch/x86/x86_32/entry.S	Wed Feb 09 10:16:50 2005 +0000
     4.2 +++ b/xen/arch/x86/x86_32/entry.S	Wed Feb 09 16:24:23 2005 +0000
     4.3 @@ -58,12 +58,13 @@
     4.4  #include <xen/softirq.h>
     4.5  #include <asm/asm_defns.h>
     4.6  #include <asm/apicdef.h>
     4.7 +#include <asm/page.h>
     4.8  #include <public/xen.h>
     4.9  
    4.10 -#define GET_CURRENT(reg)   \
    4.11 -        movl $8192-4, reg; \
    4.12 -        orl  %esp, reg;    \
    4.13 -        andl $~3,reg;      \
    4.14 +#define GET_CURRENT(reg)         \
    4.15 +        movl $STACK_SIZE-4, reg; \
    4.16 +        orl  %esp, reg;          \
    4.17 +        andl $~3,reg;            \
    4.18          movl (reg),reg;
    4.19  
    4.20  #ifdef CONFIG_VMX
    4.21 @@ -169,10 +170,6 @@ vmx_process_softirqs:
    4.22          call SYMBOL_NAME(do_softirq)
    4.23          jmp  vmx_test_all_events
    4.24  #endif
    4.25 -        
    4.26 -ENTRY(continue_nonidle_task)
    4.27 -        GET_CURRENT(%ebx)
    4.28 -        jmp test_all_events
    4.29  
    4.30          ALIGN
    4.31  restore_all_guest:
     5.1 --- a/xen/arch/x86/x86_32/traps.c	Wed Feb 09 10:16:50 2005 +0000
     5.2 +++ b/xen/arch/x86/x86_32/traps.c	Wed Feb 09 16:24:23 2005 +0000
     5.3 @@ -88,7 +88,7 @@ void show_registers(struct xen_regs *reg
     5.4      unsigned long esp;
     5.5      unsigned short ss, ds, es, fs, gs;
     5.6  
     5.7 -    if ( GUEST_FAULT(regs) )
     5.8 +    if ( GUEST_MODE(regs) )
     5.9      {
    5.10          esp = regs->esp;
    5.11          ss  = regs->ss & 0xffff;
     6.1 --- a/xen/arch/x86/x86_64/asm-offsets.c	Wed Feb 09 10:16:50 2005 +0000
     6.2 +++ b/xen/arch/x86/x86_64/asm-offsets.c	Wed Feb 09 16:24:23 2005 +0000
     6.3 @@ -37,6 +37,8 @@ void __dummy__(void)
     6.4      OFFSET(XREGS_eflags, struct xen_regs, eflags);
     6.5      OFFSET(XREGS_rsp, struct xen_regs, rsp);
     6.6      OFFSET(XREGS_ss, struct xen_regs, ss);
     6.7 +    OFFSET(XREGS_kernel_sizeof, struct xen_regs, es);
     6.8 +    DEFINE(XREGS_user_sizeof, sizeof(struct xen_regs));
     6.9      BLANK();
    6.10  
    6.11      OFFSET(EDOMAIN_processor, struct exec_domain, processor);
    6.12 @@ -47,12 +49,11 @@ void __dummy__(void)
    6.13      OFFSET(EDOMAIN_failsafe_addr, struct exec_domain, arch.failsafe_address);
    6.14      OFFSET(EDOMAIN_trap_bounce, struct exec_domain, arch.trap_bounce);
    6.15      OFFSET(EDOMAIN_thread_flags, struct exec_domain, arch.flags);
    6.16 +    OFFSET(EDOMAIN_guestos_sp, struct exec_domain, arch.guestos_sp);
    6.17      BLANK();
    6.18  
    6.19 -    OFFSET(SHINFO_upcall_pending, shared_info_t, 
    6.20 -           vcpu_data[0].evtchn_upcall_pending);
    6.21 -    OFFSET(SHINFO_upcall_mask, shared_info_t, 
    6.22 -           vcpu_data[0].evtchn_upcall_mask);
    6.23 +    OFFSET(VCPUINFO_upcall_pending, vcpu_info_t, evtchn_upcall_pending);
    6.24 +    OFFSET(VCPUINFO_upcall_mask, vcpu_info_t, evtchn_upcall_mask);
    6.25      BLANK();
    6.26  
    6.27      OFFSET(TRAPBOUNCE_error_code, struct trap_bounce, error_code);
     7.1 --- a/xen/arch/x86/x86_64/entry.S	Wed Feb 09 10:16:50 2005 +0000
     7.2 +++ b/xen/arch/x86/x86_64/entry.S	Wed Feb 09 16:24:23 2005 +0000
     7.3 @@ -9,8 +9,86 @@
     7.4  #include <xen/softirq.h>
     7.5  #include <asm/asm_defns.h>
     7.6  #include <asm/apicdef.h>
     7.7 +#include <asm/page.h>
     7.8  #include <public/xen.h>
     7.9  
    7.10 +#define GET_CURRENT(reg)         \
    7.11 +        movq $STACK_SIZE-8, reg; \
    7.12 +        orq  %rsp, reg;          \
    7.13 +        andq $~7,reg;            \
    7.14 +        movq (reg),reg;
    7.15 +
    7.16 +        ALIGN
    7.17 +restore_all_guest:
    7.18 +        testb $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    7.19 +        jnz   failsafe_callback
    7.20 +        RESTORE_ALL
    7.21 +        testw $TRAP_syscall,4(%rsp)
    7.22 +        jz    1f
    7.23 +        addq  $8,%rsp
    7.24 +        popq  %rcx
    7.25 +        addq  $8,%rsp
    7.26 +        popq  %r11
    7.27 +        popq  %rsp
    7.28 +        sysretq
    7.29 +1:      addq  $8,%rsp
    7.30 +FLT1:   iretq
    7.31 +.section .fixup,"ax"
    7.32 +FIX1:   popq  -15*8-8(%rsp)            # error_code/entry_vector
    7.33 +        SAVE_ALL                       # 15*8 bytes pushed
    7.34 +        movq  -8(%rsp),%rsi            # error_code/entry_vector
    7.35 +        sti                            # after stack abuse (-1024(%rsp))
    7.36 +        pushq $__HYPERVISOR_DS         # SS
    7.37 +        leaq  8(%rsp),%rax
    7.38 +        pushq %rax                     # RSP
    7.39 +        pushf                          # RFLAGS
    7.40 +        pushq $__HYPERVISOR_CS         # CS
    7.41 +        leaq  DBLFLT1(%rip),%rax
    7.42 +        pushq %rax                     # RIP
    7.43 +        pushq %rsi                     # error_code/entry_vector
    7.44 +        jmp   error_code
    7.45 +DBLFLT1:GET_CURRENT(%rbx)
    7.46 +        jmp   test_all_events
    7.47 +DBLFIX1:GET_CURRENT(%rbx)
    7.48 +        testb $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    7.49 +        jnz   domain_crash             # cannot reenter failsafe code
    7.50 +        orb   $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    7.51 +        jmp   test_all_events          # will return via failsafe code
    7.52 +.previous
    7.53 +.section __pre_ex_table,"a"
    7.54 +	.quad FLT1,FIX1
    7.55 +.previous
    7.56 +.section __ex_table,"a"
    7.57 +        .quad DBLFLT1,DBLFIX1
    7.58 +.previous
    7.59 +
    7.60 +/* No special register assumptions */
    7.61 +failsafe_callback:
    7.62 +        GET_CURRENT(%rbx)
    7.63 +        andb $~TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    7.64 +        leaq EDOMAIN_trap_bounce(%rbx),%rdx
    7.65 +        movq EDOMAIN_failsafe_addr(%rbx),%rax
    7.66 +        movq %rax,TRAPBOUNCE_eip(%rdx)
    7.67 +        movw $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
    7.68 +        call create_bounce_frame
    7.69 +        RESTORE_ALL
    7.70 +        addq $8,%rsp
    7.71 +FLT2:   iret 
    7.72 +.section .fixup,"ax"
    7.73 +FIX2:   pushq %rbx
    7.74 +        GET_CURRENT(%rbx)
    7.75 +        orb   $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    7.76 +        popq  %rbx
    7.77 +        jmp   FIX1
    7.78 +.section __pre_ex_table,"a"
    7.79 +	.quad FLT2,FIX2
    7.80 +.previous
    7.81 +
    7.82 +        ALIGN
    7.83 +restore_all_xen:
    7.84 +        RESTORE_ALL
    7.85 +        addq  $8,%rsp
    7.86 +        iretq
    7.87  
    7.88  /*
    7.89   * %rax                            = hypercall vector
    7.90 @@ -18,6 +96,7 @@
    7.91   * %r11, %rcx                      = SYSCALL-saved %rflags and %rip
    7.92   * NB. We must move %r10 to %rcx for C function-calling ABI.
    7.93   */
    7.94 +        ALIGN
    7.95  ENTRY(hypercall)
    7.96          sti
    7.97          movl  $__GUEST_SS,8(%rsp)
    7.98 @@ -25,35 +104,194 @@ ENTRY(hypercall)
    7.99          pushq $__GUEST_CS
   7.100          pushq %rcx
   7.101          pushq $0
   7.102 +        movl  $TRAP_syscall,4(%rsp)
   7.103          SAVE_ALL
   7.104          movq  %r10,%rcx
   7.105          andq  $(NR_hypercalls-1),%rax
   7.106          leaq  SYMBOL_NAME(hypercall_table)(%rip),%rbx
   7.107          callq *(%rbx,%rax,8)
   7.108 -        RESTORE_ALL
   7.109 -        addq  $8,%rsp
   7.110 -        popq  %rcx
   7.111 -        addq  $8,%rsp
   7.112 -        popq  %r11
   7.113 -        cli
   7.114 -        popq  %rsp
   7.115 -        sysretq
   7.116 -        
   7.117 +        GET_CURRENT(%rbx)
   7.118 +
   7.119 +ret_from_hypercall:
   7.120 +        movq %rax,XREGS_rax(%rsp)       # save the return value
   7.121 +
   7.122 +test_all_events:
   7.123 +        cli                             # tests must not race interrupts
   7.124 +/*test_softirqs:*/  
   7.125 +        movl  EDOMAIN_processor(%rbx),%eax
   7.126 +        shl   $6,%rax                    # sizeof(irq_cpustat) == 64
   7.127 +        leaq  SYMBOL_NAME(irq_stat)(%rip),%rcx
   7.128 +        testl $~0,(%rcx,%rax,1)
   7.129 +        jnz   process_softirqs
   7.130 +/*test_guest_events:*/
   7.131 +        movq  EDOMAIN_vcpu_info(%rbx),%rax
   7.132 +        testb $0xFF,VCPUINFO_upcall_mask(%rax)
   7.133 +        jnz   restore_all_guest
   7.134 +        testb $0xFF,VCPUINFO_upcall_pending(%rax)
   7.135 +        jz    restore_all_guest
   7.136 +/*process_guest_events:*/
   7.137 +        leaq  EDOMAIN_trap_bounce(%rbx),%rdx
   7.138 +        movq  EDOMAIN_event_addr(%rbx),%rax
   7.139 +        movq  %rax,TRAPBOUNCE_eip(%rdx)
   7.140 +        movw  $TBF_INTERRUPT,TRAPBOUNCE_flags(%rdx)
   7.141 +        call  create_bounce_frame
   7.142 +        movq  EDOMAIN_vcpu_info(%rbx),%rax
   7.143 +        movb  $1,VCPUINFO_upcall_mask(%rax) # Upcalls masked during delivery
   7.144 +        jmp   restore_all_guest
   7.145 +
   7.146 +        ALIGN
   7.147 +process_softirqs:
   7.148 +        sti       
   7.149 +        call SYMBOL_NAME(do_softirq)
   7.150 +        jmp  test_all_events
   7.151 +                
   7.152 +/* CREATE A BASIC EXCEPTION FRAME ON GUEST OS STACK:                     */
   7.153 +/*   { RCX, R11, [DS-GS,] [CR2,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS }   */
   7.154 +/* %rdx == trap_bounce, %rbx == task_struct                              */
   7.155 +/* %rax,%rcx are clobbered. %rsi contains new XREGS_rsp.                 */
   7.156 +create_bounce_frame:
   7.157 +        /* Push new frame at existing %rsp if already in guest-OS mode. */
   7.158 +        movq  XREGS_rsp+8(%rsp),%rsi
   7.159 +        testb $TF_guestos_mode,EDOMAIN_thread_flags(%rbx)
   7.160 +        jnz   1f
   7.161 +        /* Push new frame at registered guest-OS stack top. */
   7.162 +        movq  EDOMAIN_guestos_sp(%rbx),%rsi
   7.163 +1:      movq  $HYPERVISOR_VIRT_START,%rax
   7.164 +        cmpq  %rax,%rsi
   7.165 +        jb    1f                        # In +ve address space? Then okay.
   7.166 +        movq  $HYPERVISOR_VIRT_END+60,%rax
   7.167 +        cmpq  %rax,%rsi
   7.168 +        jb    domain_crash              # Above Xen private area? Then okay.
   7.169 +1:      subq  $40,%rsi
   7.170 +        movq  XREGS_ss+8(%rsp),%rax
   7.171 +FLT3:   movq  %rax,32(%rsi)             # SS
   7.172 +        movq  XREGS_rsp+8(%rsp),%rax
   7.173 +FLT4:   movq  %rax,24(%rsi)             # RSP
   7.174 +        movq  XREGS_eflags+8(%rsp),%rax
   7.175 +FLT5:   movq  %rax,16(%rsi)             # RFLAGS
   7.176 +        movq  XREGS_cs+8(%rsp),%rax
   7.177 +FLT6:   movq  %rax,8(%rsi)              # CS
   7.178 +        movq  XREGS_rip+8(%rsp),%rax
   7.179 +FLT7:   movq  %rax,(%rsi)               # RIP
   7.180 +        movb  TRAPBOUNCE_flags(%rdx),%cl
   7.181 +        testb $TBF_EXCEPTION_ERRCODE,%cl
   7.182 +        jz    1f
   7.183 +        subq  $8,%rsi
   7.184 +        movq  TRAPBOUNCE_error_code(%rdx),%rax
   7.185 +FLT8:   movq  %rax,(%rsi)               # ERROR CODE
   7.186 +        testb $TBF_EXCEPTION_CR2,%cl
   7.187 +        jz    2f
   7.188 +        subq  $8,%rsi
   7.189 +        movq  TRAPBOUNCE_cr2(%rdx),%rax
   7.190 +FLT9:   movq  %rax,(%rsi)               # CR2
   7.191 +1:      testb $TBF_FAILSAFE,%cl
   7.192 +        jz    2f
   7.193 +        subq  $32,%rsi
   7.194 +        movl  %gs,%eax
   7.195 +FLT10:  movq  %rax,24(%rsi)             # GS
   7.196 +        movl  %fs,%eax
   7.197 +FLT11:  movq  %rax,16(%rsi)             # FS
   7.198 +        movl  %es,%eax
   7.199 +FLT12:  movq  %rax,8(%rsi)              # ES
   7.200 +        movl  %ds,%eax
   7.201 +FLT13:  movq  %rax,(%rsi)               # DS
   7.202 +2:      subq  $16,%rsi
   7.203 +        movq  XREGS_r11+8(%rsp),%rax
   7.204 +FLT14:  movq  %rax,(%rsi)               # R11
   7.205 +        movq  XREGS_rcx+8(%rsp),%rax
   7.206 +FLT15:  movq  %rax,(%rsi)               # RCX
   7.207 +        /* Rewrite our stack frame and return to guest-OS mode. */
   7.208 +        /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
   7.209 +        movb  $0,TRAPBOUNCE_flags(%rdx)
   7.210 +        testb $TF_guestos_mode,EDOMAIN_thread_flags(%rbx)
   7.211 +        jnz   1f
   7.212 +        orb   $TF_guestos_mode,EDOMAIN_thread_flags(%rbx)
   7.213 +        swapgs
   7.214 +        /* XXX switch page tables XXX */
   7.215 +1:      movl  $TRAP_syscall,XREGS_entry_vector+8(%rsp)
   7.216 +        andl  $0xfffcbeff,XREGS_eflags+8(%rsp)
   7.217 +        movl  $__GUEST_SS,XREGS_ss+8(%rsp)
   7.218 +        movq  %rsi,XREGS_rsp+8(%rsp)
   7.219 +        movl  $__GUEST_CS,XREGS_cs+8(%rsp)
   7.220 +        movq  TRAPBOUNCE_eip(%rdx),%rax
   7.221 +        movq  %rax,XREGS_rip+8(%rsp)
   7.222 +        ret
   7.223 +.section .fixup,"ax"
   7.224 +FIX3:   sti
   7.225 +        popq  %rsi
   7.226 +        addq  $8,%rsp                  # Discard create_b_frame return address
   7.227 +        pushq $__HYPERVISOR_DS         # SS
   7.228 +        leaq  8(%rsp),%rax
   7.229 +        pushq %rax                     # RSP
   7.230 +        pushf                          # RFLAGS
   7.231 +        pushq $__HYPERVISOR_CS         # CS
   7.232 +        leaq  DBLFLT2(%rip),%rax
   7.233 +        pushq %rax                     # RIP
   7.234 +        pushq %rsi                     # error_code/entry_vector
   7.235 +        jmp   error_code
   7.236 +DBLFLT2:jmp   process_guest_exception_and_events
   7.237 +.previous
   7.238 +.section __pre_ex_table,"a"
   7.239 +	.quad  FLT3,FIX3 ,  FLT4,FIX3 ,  FLT5,FIX3 ,  FLT6,FIX3
   7.240 +	.quad  FLT7,FIX3 ,  FLT8,FIX3 ,  FLT9,FIX3 , FLT10,FIX3
   7.241 +	.quad FLT11,FIX3 , FLT12,FIX3 , FLT13,FIX3 , FLT14,FIX3 , FLT15,FIX3
   7.242 +.previous
   7.243 +.section __ex_table,"a"
   7.244 +        .quad DBLFLT2,domain_crash
   7.245 +.previous
   7.246 +
   7.247 +        ALIGN
   7.248 +process_guest_exception_and_events:
   7.249 +        leaq  EDOMAIN_trap_bounce(%rbx),%rdx
   7.250 +        testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
   7.251 +        jz    test_all_events
   7.252 +        cli   # create_bounce_frame needs CLI for pre-exceptions to work
   7.253 +        call  create_bounce_frame
   7.254 +        jmp   test_all_events
   7.255 +
   7.256 +        ALIGN
   7.257  ENTRY(ret_from_intr)
   7.258 -restore_all_xen:
   7.259 -        RESTORE_ALL
   7.260 -        addq  $8,%rsp
   7.261 -        iretq
   7.262 +        GET_CURRENT(%rbx)
   7.263 +        testb $3,XREGS_cs(%rsp)
   7.264 +        jnz   test_all_events
   7.265 +        jmp   restore_all_xen
   7.266  
   7.267 +        ALIGN
   7.268  error_code:
   7.269          SAVE_ALL
   7.270 -        sti
   7.271 +        testb $X86_EFLAGS_IF>>8,XREGS_eflags+1(%rsp)
   7.272 +        jz    exception_with_ints_disabled
   7.273 +1:      sti
   7.274          movq  %rsp,%rdi
   7.275          movl  XREGS_entry_vector(%rsp),%eax
   7.276          leaq  SYMBOL_NAME(exception_table)(%rip),%rdx
   7.277          callq *(%rdx,%rax,8)
   7.278          jmp   restore_all_xen
   7.279  
   7.280 +exception_with_ints_disabled:
   7.281 +        testb $3,XREGS_cs(%rsp)         # interrupts disabled outside Xen?
   7.282 +        jnz   1b                        # it really does happen!
   7.283 +                                        #  (e.g., DOM0 X server)
   7.284 +        movq  XREGS_rip(%rsp),%rdi
   7.285 +        call  search_pre_exception_table
   7.286 +        testq %rax,%rax                 # no fixup code for faulting EIP?
   7.287 +        jz    FATAL_exception_with_ints_disabled
   7.288 +        movq  %rax,XREGS_rip(%rsp)
   7.289 +        movq  %rsp,%rsi
   7.290 +        subq  $8,%rsp
   7.291 +        movq  %rsp,%rdi
   7.292 +        movq  $XREGS_kernel_sizeof/8,%rcx
   7.293 +        rep;  movsq                     # make room for error_code/entry_vector
   7.294 +        movq  XREGS_error_code(%rsp),%rax # error_code/entry_vector
   7.295 +        movq  %rax,XREGS_kernel_sizeof(%rsp)
   7.296 +        jmp   restore_all_xen           # return to fixup code
   7.297 +
   7.298 +FATAL_exception_with_ints_disabled:
   7.299 +        movl  XREGS_entry_vector(%rsp),%edi
   7.300 +        movq  %rsp,%rsi
   7.301 +        call  SYMBOL_NAME(fatal_trap)
   7.302 +        ud2
   7.303 +
   7.304  ENTRY(divide_error)
   7.305          pushq $0
   7.306          movl  $TRAP_divide_error,4(%rsp)
     8.1 --- a/xen/include/asm-x86/config.h	Wed Feb 09 10:16:50 2005 +0000
     8.2 +++ b/xen/include/asm-x86/config.h	Wed Feb 09 16:24:23 2005 +0000
     8.3 @@ -111,10 +111,16 @@ extern void __out_of_line_bug(int line) 
     8.4  #define XENHEAP_DEFAULT_MB (16)
     8.5  
     8.6  #define PML4_ENTRY_BITS  39
     8.7 +#ifndef __ASSEMBLY__
     8.8  #define PML4_ENTRY_BYTES (1UL << PML4_ENTRY_BITS)
     8.9  #define PML4_ADDR(_slot)                             \
    8.10      ((((_slot ## UL) >> 8) * 0xffff000000000000UL) | \
    8.11       (_slot ## UL << PML4_ENTRY_BITS))
    8.12 +#else
    8.13 +#define PML4_ENTRY_BYTES (1 << PML4_ENTRY_BITS)
    8.14 +#define PML4_ADDR(_slot)                             \
    8.15 +    (((_slot >> 8) * 0xffff000000000000) | (_slot << PML4_ENTRY_BITS))
    8.16 +#endif
    8.17  
    8.18  /*
    8.19   * Memory layout:
     9.1 --- a/xen/include/asm-x86/processor.h	Wed Feb 09 10:16:50 2005 +0000
     9.2 +++ b/xen/include/asm-x86/processor.h	Wed Feb 09 16:24:23 2005 +0000
     9.3 @@ -88,27 +88,30 @@
     9.4  /*
     9.5   * Trap/fault mnemonics.
     9.6   */
     9.7 -#define TRAP_divide_error     0
     9.8 -#define TRAP_debug            1
     9.9 -#define TRAP_nmi              2
    9.10 -#define TRAP_int3             3
    9.11 -#define TRAP_overflow         4
    9.12 -#define TRAP_bounds           5
    9.13 -#define TRAP_invalid_op       6
    9.14 -#define TRAP_no_device        7
    9.15 -#define TRAP_double_fault     8
    9.16 -#define TRAP_copro_seg        9
    9.17 -#define TRAP_invalid_tss     10
    9.18 -#define TRAP_no_segment      11
    9.19 -#define TRAP_stack_error     12
    9.20 -#define TRAP_gp_fault        13
    9.21 -#define TRAP_page_fault      14
    9.22 -#define TRAP_spurious_int    15
    9.23 -#define TRAP_copro_error     16
    9.24 -#define TRAP_alignment_check 17
    9.25 -#define TRAP_machine_check   18
    9.26 -#define TRAP_simd_error      19
    9.27 -#define TRAP_deferred_nmi    31
    9.28 +#define TRAP_divide_error      0
    9.29 +#define TRAP_debug             1
    9.30 +#define TRAP_nmi               2
    9.31 +#define TRAP_int3              3
    9.32 +#define TRAP_overflow          4
    9.33 +#define TRAP_bounds            5
    9.34 +#define TRAP_invalid_op        6
    9.35 +#define TRAP_no_device         7
    9.36 +#define TRAP_double_fault      8
    9.37 +#define TRAP_copro_seg         9
    9.38 +#define TRAP_invalid_tss      10
    9.39 +#define TRAP_no_segment       11
    9.40 +#define TRAP_stack_error      12
    9.41 +#define TRAP_gp_fault         13
    9.42 +#define TRAP_page_fault       14
    9.43 +#define TRAP_spurious_int     15
    9.44 +#define TRAP_copro_error      16
    9.45 +#define TRAP_alignment_check  17
    9.46 +#define TRAP_machine_check    18
    9.47 +#define TRAP_simd_error       19
    9.48 +#define TRAP_deferred_nmi     31
    9.49 +
    9.50 +/* Set for entry via SYSCALL. Informs return code to use SYSRETQ not IRETQ. */
    9.51 +#define TRAP_syscall         256 /* NB. Same as ECF_IN_SYSCALL */
    9.52  
    9.53  /*
    9.54   * Non-fatal fault/trap handlers return an error code to the caller. If the
    9.55 @@ -119,19 +122,16 @@
    9.56  #define EXCRET_not_a_fault 1 /* It was a trap. No instruction replay needed. */
    9.57  #define EXCRET_fault_fixed 1 /* It was fault that we fixed: try a replay. */
    9.58  
    9.59 -/*
    9.60 - * 'trap_bounce' flags values.
    9.61 - */
    9.62 +/* 'trap_bounce' flags values */
    9.63  #define TBF_EXCEPTION          1
    9.64  #define TBF_EXCEPTION_ERRCODE  2
    9.65  #define TBF_EXCEPTION_CR2      4
    9.66  #define TBF_INTERRUPT          8
    9.67  #define TBF_FAILSAFE          16
    9.68  
    9.69 -/*
    9.70 - * thread.flags values.
    9.71 - */
    9.72 -#define TF_failsafe_return 1
    9.73 +/* arch_exec_domain' flags values */
    9.74 +#define TF_failsafe_return     1
    9.75 +#define TF_guestos_mode        2
    9.76  
    9.77  #ifndef __ASSEMBLY__
    9.78  
    10.1 --- a/xen/include/asm-x86/regs.h	Wed Feb 09 10:16:50 2005 +0000
    10.2 +++ b/xen/include/asm-x86/regs.h	Wed Feb 09 16:24:23 2005 +0000
    10.3 @@ -31,6 +31,6 @@ enum EFLAGS {
    10.4      EF_ID   = 0x00200000,   /* id */
    10.5  };
    10.6  
    10.7 -#define GUEST_FAULT(_r) (likely(VM86_MODE(_r) || !RING_0(_r)))
    10.8 +#define GUEST_MODE(_r) (likely(VM86_MODE(_r) || !RING_0(_r)))
    10.9  
   10.10  #endif /* __X86_REGS_H__ */
    11.1 --- a/xen/include/asm-x86/x86_32/regs.h	Wed Feb 09 10:16:50 2005 +0000
    11.2 +++ b/xen/include/asm-x86/x86_32/regs.h	Wed Feb 09 16:24:23 2005 +0000
    11.3 @@ -1,37 +1,8 @@
    11.4  #ifndef _I386_REGS_H
    11.5  #define _I386_REGS_H
    11.6  
    11.7 -#include <asm/types.h>
    11.8 -
    11.9 -/* So that we can use 'l' modifier in printf-style format strings. */
   11.10 -#define u32 unsigned long
   11.11 -
   11.12 -struct xen_regs
   11.13 -{
   11.14 -    /* All saved activations contain the following fields. */
   11.15 -    u32 ebx;
   11.16 -    u32 ecx;
   11.17 -    u32 edx;
   11.18 -    u32 esi;
   11.19 -    u32 edi;
   11.20 -    u32 ebp;
   11.21 -    u32 eax;
   11.22 -    u16 error_code;
   11.23 -    u16 entry_vector;
   11.24 -    u32 eip;
   11.25 -    u32 cs;
   11.26 -    u32 eflags;
   11.27 -
   11.28 -    /* Only saved guest activations contain the following fields. */
   11.29 -    u32 esp;
   11.30 -    u32 ss;
   11.31 -    u32 es;
   11.32 -    u32 ds;
   11.33 -    u32 fs;
   11.34 -    u32 gs;
   11.35 -} __attribute__ ((packed));
   11.36 -
   11.37 -#undef u32
   11.38 +#include <xen/types.h>
   11.39 +#include <public/xen.h>
   11.40  
   11.41  #define VM86_MODE(_r) ((_r)->eflags & EF_VM)
   11.42  #define RING_0(_r)    (((_r)->cs & 3) == 0)
   11.43 @@ -39,6 +10,6 @@ struct xen_regs
   11.44  #define RING_2(_r)    (((_r)->cs & 3) == 2)
   11.45  #define RING_3(_r)    (((_r)->cs & 3) == 3)
   11.46  
   11.47 -#define GUESTOS_FAULT(_r) (!VM86_MODE(_r) && RING_1(_r))
   11.48 +#define GUESTOS_MODE(_e, _r) (!VM86_MODE(_r) && RING_1(_r))
   11.49  
   11.50  #endif
    12.1 --- a/xen/include/asm-x86/x86_64/current.h	Wed Feb 09 10:16:50 2005 +0000
    12.2 +++ b/xen/include/asm-x86/x86_64/current.h	Wed Feb 09 16:24:23 2005 +0000
    12.3 @@ -33,11 +33,16 @@ static inline execution_context_t *get_e
    12.4      return execution_context;
    12.5  }
    12.6  
    12.7 +/*
    12.8 + * Get the top-of-stack, as stored in the per-CPU TSS. This is actually
    12.9 + * 64 bytes below the real top of the stack to allow space for:
   12.10 + *  domain pointer, DS, ES, FS, GS, FS_BASE, GS_BASE_OS, GS_BASE_APP
   12.11 + */
   12.12  static inline unsigned long get_stack_top(void)
   12.13  {
   12.14      unsigned long p;
   12.15      __asm__ ( "orq %%rsp,%0; andq $~7,%0" 
   12.16 -              : "=r" (p) : "0" (STACK_SIZE-8) );
   12.17 +              : "=r" (p) : "0" (STACK_SIZE-64) );
   12.18      return p;
   12.19  }
   12.20  
    13.1 --- a/xen/include/asm-x86/x86_64/regs.h	Wed Feb 09 10:16:50 2005 +0000
    13.2 +++ b/xen/include/asm-x86/x86_64/regs.h	Wed Feb 09 16:24:23 2005 +0000
    13.3 @@ -1,41 +1,15 @@
    13.4  #ifndef _X86_64_REGS_H
    13.5  #define _X86_64_REGS_H
    13.6  
    13.7 -#include <asm/types.h>
    13.8 +#include <xen/types.h>
    13.9 +#include <public/xen.h>
   13.10  
   13.11 -struct xen_regs
   13.12 -{
   13.13 -    u64 r15;
   13.14 -    u64 r14;
   13.15 -    u64 r13;
   13.16 -    u64 r12;
   13.17 -    union { u64 rbp; u64 ebp; } __attribute__ ((packed));
   13.18 -    union { u64 rbx; u64 ebx; } __attribute__ ((packed));
   13.19 -    /* NB. Above here is C callee-saves. */
   13.20 -    u64 r11;
   13.21 -    u64 r10;	
   13.22 -    u64 r9;
   13.23 -    u64 r8;
   13.24 -    union { u64 rax; u64 eax; } __attribute__ ((packed));
   13.25 -    union { u64 rcx; u64 ecx; } __attribute__ ((packed));
   13.26 -    union { u64 rdx; u64 edx; } __attribute__ ((packed));
   13.27 -    union { u64 rsi; u64 esi; } __attribute__ ((packed));
   13.28 -    union { u64 rdi; u64 edi; } __attribute__ ((packed));
   13.29 -    u32 error_code;
   13.30 -    u32 entry_vector;
   13.31 -    union { u64 rip; u64 eip; } __attribute__ ((packed));
   13.32 -    u64 cs;
   13.33 -    union { u64 rflags; u64 eflags; } __attribute__ ((packed));
   13.34 -    union { u64 rsp; u64 esp; } __attribute__ ((packed));
   13.35 -    u64 ss;
   13.36 -} __attribute__ ((packed));
   13.37 -
   13.38 -#define VM86_MODE(_r) ((_r)->eflags & EF_VM)
   13.39 +#define VM86_MODE(_r) (0) /* No VM86 support in long mode. */
   13.40  #define RING_0(_r)    (((_r)->cs & 3) == 0)
   13.41  #define RING_1(_r)    (((_r)->cs & 3) == 1)
   13.42  #define RING_2(_r)    (((_r)->cs & 3) == 2)
   13.43  #define RING_3(_r)    (((_r)->cs & 3) == 3)
   13.44  
   13.45 -#define GUESTOS_FAULT(_r) (!VM86_MODE(_r) && RING_3(_r))
   13.46 +#define GUESTOS_MODE(_e, _r) ((_e)->arch.flags & TF_guestos_mode)
   13.47  
   13.48  #endif
    14.1 --- a/xen/include/public/arch-x86_32.h	Wed Feb 09 10:16:50 2005 +0000
    14.2 +++ b/xen/include/public/arch-x86_32.h	Wed Feb 09 16:24:23 2005 +0000
    14.3 @@ -94,27 +94,36 @@ typedef struct {
    14.4      memory_t address; /* 4: code address                                  */
    14.5  } PACKED trap_info_t; /* 8 bytes */
    14.6  
    14.7 -typedef struct
    14.8 +/* So that we can use 'l' modifier in printf-style format strings. */
    14.9 +#define u32 unsigned long
   14.10 +
   14.11 +typedef struct xen_regs
   14.12  {
   14.13 -    unsigned long ebx;
   14.14 -    unsigned long ecx;
   14.15 -    unsigned long edx;
   14.16 -    unsigned long esi;
   14.17 -    unsigned long edi;
   14.18 -    unsigned long ebp;
   14.19 -    unsigned long eax;
   14.20 -    unsigned long _unused;
   14.21 -    unsigned long eip;
   14.22 -    unsigned long cs;
   14.23 -    unsigned long eflags;
   14.24 -    unsigned long esp;
   14.25 -    unsigned long ss;
   14.26 -    unsigned long es;
   14.27 -    unsigned long ds;
   14.28 -    unsigned long fs;
   14.29 -    unsigned long gs;
   14.30 +    u32 ebx;
   14.31 +    u32 ecx;
   14.32 +    u32 edx;
   14.33 +    u32 esi;
   14.34 +    u32 edi;
   14.35 +    u32 ebp;
   14.36 +    u32 eax;
   14.37 +    u16 error_code;        /* private */
   14.38 +    union { 
   14.39 +        u16 entry_vector;  /* private */
   14.40 +        u16 flags;
   14.41 +    } PACKED;
   14.42 +    u32 eip;
   14.43 +    u32 cs;
   14.44 +    u32 eflags;
   14.45 +    u32 esp;
   14.46 +    u32 ss;
   14.47 +    u32 es;
   14.48 +    u32 ds;
   14.49 +    u32 fs;
   14.50 +    u32 gs;
   14.51  } PACKED execution_context_t;
   14.52  
   14.53 +#undef u32
   14.54 +
   14.55  typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
   14.56  
   14.57  /*
   14.58 @@ -123,7 +132,8 @@ typedef u64 tsc_timestamp_t; /* RDTSC ti
   14.59   */
   14.60  typedef struct {
   14.61  #define ECF_I387_VALID (1<<0)
   14.62 -#define ECF_VMX_GUEST  (2<<0)
   14.63 +#define ECF_VMX_GUEST  (1<<1)
   14.64 +#define ECF_IN_GUESTOS (1<<2)
   14.65      unsigned long flags;
   14.66      execution_context_t cpu_ctxt;           /* User-level CPU registers     */
   14.67      char          fpu_ctxt[256];            /* User-level FPU registers     */
    15.1 --- a/xen/include/public/arch-x86_64.h	Wed Feb 09 10:16:50 2005 +0000
    15.2 +++ b/xen/include/public/arch-x86_64.h	Wed Feb 09 16:24:23 2005 +0000
    15.3 @@ -103,33 +103,41 @@ typedef struct {
    15.4      memory_t address; /* 8: code address                                  */
    15.5  } PACKED trap_info_t; /* 16 bytes */
    15.6  
    15.7 -typedef struct
    15.8 +typedef struct xen_regs
    15.9  {
   15.10 -    unsigned long r15;
   15.11 -    unsigned long r14;
   15.12 -    unsigned long r13;
   15.13 -    unsigned long r12;
   15.14 -    union { unsigned long rbp, ebp; } PACKED;
   15.15 -    union { unsigned long rbx, ebx; } PACKED;
   15.16 -    unsigned long r11;
   15.17 -    unsigned long r10;
   15.18 -    unsigned long r9;
   15.19 -    unsigned long r8;
   15.20 -    union { unsigned long rax, eax; } PACKED;
   15.21 -    union { unsigned long rcx, ecx; } PACKED;
   15.22 -    union { unsigned long rdx, edx; } PACKED;
   15.23 -    union { unsigned long rsi, esi; } PACKED;
   15.24 -    union { unsigned long rdi, edi; } PACKED;
   15.25 -    unsigned long _unused;
   15.26 -    union { unsigned long rip, eip; } PACKED;
   15.27 -    unsigned long cs;
   15.28 -    union { unsigned long rflags, eflags; } PACKED;
   15.29 -    union { unsigned long rsp, esp; } PACKED;
   15.30 -    unsigned long ss;
   15.31 -    unsigned long es;
   15.32 -    unsigned long ds;
   15.33 -    unsigned long fs;
   15.34 -    unsigned long gs;
   15.35 +    u64 r15;
   15.36 +    u64 r14;
   15.37 +    u64 r13;
   15.38 +    u64 r12;
   15.39 +    union { u64 rbp, ebp; } PACKED;
   15.40 +    union { u64 rbx, ebx; } PACKED;
   15.41 +    u64 r11;
   15.42 +    u64 r10;
   15.43 +    u64 r9;
   15.44 +    u64 r8;
   15.45 +    union { u64 rax, eax; } PACKED;
   15.46 +    union { u64 rcx, ecx; } PACKED;
   15.47 +    union { u64 rdx, edx; } PACKED;
   15.48 +    union { u64 rsi, esi; } PACKED;
   15.49 +    union { u64 rdi, edi; } PACKED;
   15.50 +    u32 error_code;        /* private */
   15.51 +    union { 
   15.52 +        u32 entry_vector;  /* private */
   15.53 +#define ECF_IN_SYSCALL (1<<8) /* Guest synchronously interrupted by SYSCALL? */
   15.54 +        u32 flags;
   15.55 +    } PACKED;
   15.56 +    union { u64 rip, eip; } PACKED;
   15.57 +    u64 cs;
   15.58 +    union { u64 rflags, eflags; } PACKED;
   15.59 +    union { u64 rsp, esp; } PACKED;
   15.60 +    u64 ss;
   15.61 +    u64 es;
   15.62 +    u64 ds;
   15.63 +    u64 fs;      /* Non-zero => takes precedence over fs_base.     */
   15.64 +    u64 gs;      /* Non-zero => takes precedence over gs_base_app. */
   15.65 +    u64 fs_base;
   15.66 +    u64 gs_base_os;
   15.67 +    u64 gs_base_app;
   15.68  } PACKED execution_context_t;
   15.69  
   15.70  typedef u64 tsc_timestamp_t; /* RDTSC timestamp */
   15.71 @@ -140,7 +148,8 @@ typedef u64 tsc_timestamp_t; /* RDTSC ti
   15.72   */
   15.73  typedef struct {
   15.74  #define ECF_I387_VALID (1<<0)
   15.75 -#define ECF_VMX_GUEST  (2<<0)
   15.76 +#define ECF_VMX_GUEST  (1<<1)
   15.77 +#define ECF_IN_GUESTOS (1<<2)
   15.78      unsigned long flags;
   15.79      execution_context_t cpu_ctxt;           /* User-level CPU registers     */
   15.80      char          fpu_ctxt[512];            /* User-level FPU registers     */