ia64/xen-unstable

changeset 4138:a4136a26fa6d

bitkeeper revision 1.1236.25.21 (4235d857_qyCkzeGWIe4csiWvPwPYQ)

Reduce reliance on complicated pre-exception system in 32-bit and
64-bit entry.S files. Various x86/64 cleanups, and we now flag to the
kernel whether it is interrupting a kernel or user context using saved
RFLAGS[63:56] (equivalently, the byte at RFLAGS+7(%rsp)). Non-zero byte
indicates kernel context.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kaf24@firebug.cl.cam.ac.uk
date Mon Mar 14 18:30:47 2005 +0000 (2005-03-14)
parents 095b6204d7f7
children 6a7120b3405b
files xen/arch/x86/domain.c xen/arch/x86/mm.c xen/arch/x86/x86_32/entry.S xen/arch/x86/x86_64/entry.S xen/include/asm-x86/processor.h xen/include/public/arch-x86_32.h xen/include/public/arch-x86_64.h
line diff
     1.1 --- a/xen/arch/x86/domain.c	Mon Mar 14 11:34:53 2005 +0000
     1.2 +++ b/xen/arch/x86/domain.c	Mon Mar 14 18:30:47 2005 +0000
     1.3 @@ -655,6 +655,12 @@ static void switch_segments(
     1.4              (unsigned long *)regs->rsp : 
     1.5              (unsigned long *)n->arch.kernel_sp;
     1.6  
     1.7 +        /* Set the kernel-mode indicator byte at the top of RFLAGS. */
     1.8 +        ((char *)regs->rflags)[7] = !!(n->arch.flags & TF_kernel_mode);
     1.9 +
    1.10 +        if ( !(n->arch.flags & TF_kernel_mode) )
    1.11 +            toggle_guest_mode(n);
    1.12 +
    1.13          if ( put_user(regs->ss,     rsp- 1) |
    1.14               put_user(regs->rsp,    rsp- 2) |
    1.15               put_user(regs->rflags, rsp- 3) |
    1.16 @@ -671,9 +677,6 @@ static void switch_segments(
    1.17              domain_crash();
    1.18          }
    1.19  
    1.20 -        if ( !(n->arch.flags & TF_kernel_mode) )
    1.21 -            toggle_guest_mode(n);
    1.22 -
    1.23          regs->entry_vector  = TRAP_syscall;
    1.24          regs->rflags       &= 0xFFFCBEFFUL;
    1.25          regs->ss            = __GUEST_SS;
    1.26 @@ -762,20 +765,14 @@ void context_switch(struct exec_domain *
    1.27              loaddebug(&next_p->arch, 7);
    1.28          }
    1.29  
    1.30 -#ifdef CONFIG_VMX
    1.31          if ( VMX_DOMAIN(next_p) )
    1.32          {
    1.33 -            /* Switch page tables. */
    1.34              write_ptbase(next_p);
    1.35 - 
    1.36              set_current(next_p);
    1.37 -            /* Switch GDT and LDT. */
    1.38              __asm__ __volatile__ ("lgdt %0" : "=m" (*next_p->arch.gdt));
    1.39 -
    1.40              __sti();
    1.41              goto done;
    1.42          }
    1.43 -#endif
    1.44   
    1.45          SET_FAST_TRAP(&next_p->arch);
    1.46  
     2.1 --- a/xen/arch/x86/mm.c	Mon Mar 14 11:34:53 2005 +0000
     2.2 +++ b/xen/arch/x86/mm.c	Mon Mar 14 18:30:47 2005 +0000
     2.3 @@ -256,11 +256,22 @@ int map_ldt_shadow_page(unsigned int off
     2.4      struct domain *d = ed->domain;
     2.5      unsigned long l1e;
     2.6  
     2.7 +#if defined(__x86_64__)
     2.8 +    /* If in user mode, switch to kernel mode just to read LDT mapping. */
     2.9 +    extern void toggle_guest_mode(struct exec_domain *);
    2.10 +    int user_mode = !(ed->arch.flags & TF_kernel_mode);
    2.11 +#define TOGGLE_MODE() if ( user_mode ) toggle_guest_mode(ed)
    2.12 +#elif defined(__i386__)
    2.13 +#define TOGGLE_MODE() ((void)0)
    2.14 +#endif
    2.15 +
    2.16      if ( unlikely(in_irq()) )
    2.17          BUG();
    2.18  
    2.19 +    TOGGLE_MODE();
    2.20      __get_user(l1e, (unsigned long *)
    2.21                 &linear_pg_table[l1_linear_offset(ed->arch.ldt_base) + off]);
    2.22 +    TOGGLE_MODE();
    2.23  
    2.24      if ( unlikely(!(l1e & _PAGE_PRESENT)) ||
    2.25           unlikely(!get_page_and_type(
     3.1 --- a/xen/arch/x86/x86_32/entry.S	Mon Mar 14 11:34:53 2005 +0000
     3.2 +++ b/xen/arch/x86/x86_32/entry.S	Mon Mar 14 18:30:47 2005 +0000
     3.3 @@ -134,7 +134,7 @@ ENTRY(vmx_asm_do_launch)
     3.4  ENTRY(vmx_asm_do_resume)
     3.5  vmx_test_all_events:
     3.6          GET_CURRENT(%ebx)
     3.7 -/* test_all_events: */
     3.8 +/*test_all_events:*/
     3.9          xorl %ecx,%ecx
    3.10          notl %ecx
    3.11          cli                             # tests must not race interrupts
    3.12 @@ -174,8 +174,6 @@ vmx_process_softirqs:
    3.13  
    3.14          ALIGN
    3.15  restore_all_guest:
    3.16 -        btr  $_TF_failsafe_return,EDOMAIN_thread_flags(%ebx)
    3.17 -        jc   failsafe_callback
    3.18          testl $X86_EFLAGS_VM,XREGS_eflags(%esp)
    3.19          jnz  restore_all_vm86
    3.20  FLT1:   movl XREGS_ds(%esp),%ds
    3.21 @@ -216,10 +214,20 @@ FIX1:   SET_XEN_SEGMENTS(a)
    3.22          jmp   error_code
    3.23  DBLFLT1:GET_CURRENT(%ebx)
    3.24          jmp   test_all_events
    3.25 -DBLFIX1:GET_CURRENT(%ebx)
    3.26 -        bts   $_TF_failsafe_return,EDOMAIN_thread_flags(%ebx)
    3.27 -        jc    domain_crash             # cannot reenter failsafe code
    3.28 -        jmp   test_all_events          # will return via failsafe code
    3.29 +failsafe_callback:
    3.30 +        GET_CURRENT(%ebx)
    3.31 +        leal  EDOMAIN_trap_bounce(%ebx),%edx
    3.32 +        movl  EDOMAIN_failsafe_addr(%ebx),%eax
    3.33 +        movl  EDOMAIN_failsafe_sel(%ebx),%eax
    3.34 +        movw  %ax,TRAPBOUNCE_cs(%edx)
    3.35 +        movw  $TBF_FAILSAFE,TRAPBOUNCE_flags(%edx)
    3.36 +        call  create_bounce_frame
    3.37 +        xorl  %eax,%eax
    3.38 +        movl  %eax,XREGS_ds(%esp)
    3.39 +        movl  %eax,XREGS_es(%esp)
    3.40 +        movl  %eax,XREGS_fs(%esp)
    3.41 +        movl  %eax,XREGS_gs(%esp)
    3.42 +        jmp   test_all_events
    3.43  .previous
    3.44  .section __pre_ex_table,"a"
    3.45  	.long FLT1,FIX1
    3.46 @@ -229,37 +237,7 @@ DBLFIX1:GET_CURRENT(%ebx)
    3.47  	.long FLT5,FIX5
    3.48  .previous
    3.49  .section __ex_table,"a"
    3.50 -        .long DBLFLT1,DBLFIX1
    3.51 -.previous
    3.52 -
    3.53 -/* No special register assumptions */
    3.54 -failsafe_callback:
    3.55 -        GET_CURRENT(%ebx)
    3.56 -        leal EDOMAIN_trap_bounce(%ebx),%edx
    3.57 -        movl EDOMAIN_failsafe_addr(%ebx),%eax
    3.58 -        movl %eax,TRAPBOUNCE_eip(%edx)
    3.59 -        movl EDOMAIN_failsafe_sel(%ebx),%eax
    3.60 -        movw %ax,TRAPBOUNCE_cs(%edx)
    3.61 -        movw $TBF_FAILSAFE,TRAPBOUNCE_flags(%edx)
    3.62 -        call create_bounce_frame
    3.63 -        popl %ebx
    3.64 -        popl %ecx
    3.65 -        popl %edx
    3.66 -        popl %esi
    3.67 -        popl %edi
    3.68 -        popl %ebp
    3.69 -        popl %eax
    3.70 -        addl $4,%esp
    3.71 -FLT6:   iret 
    3.72 -.section .fixup,"ax"
    3.73 -FIX6:   pushl %ebx
    3.74 -        GET_CURRENT(%ebx)
    3.75 -        orb   $TF_failsafe_return,EDOMAIN_thread_flags(%ebx)
    3.76 -        pop   %ebx
    3.77 -        jmp   FIX5
    3.78 -.previous
    3.79 -.section __pre_ex_table,"a"
    3.80 -	.long FLT6,FIX6
    3.81 +        .long DBLFLT1,failsafe_callback
    3.82  .previous
    3.83  
    3.84          ALIGN
    3.85 @@ -301,6 +279,7 @@ test_all_events:
    3.86          testb $0xFF,VCPUINFO_upcall_pending(%eax)
    3.87          jz   restore_all_guest
    3.88  /*process_guest_events:*/
    3.89 +        sti
    3.90          leal EDOMAIN_trap_bounce(%ebx),%edx
    3.91          movl EDOMAIN_event_addr(%ebx),%eax
    3.92          movl %eax,TRAPBOUNCE_eip(%edx)
    3.93 @@ -310,7 +289,7 @@ test_all_events:
    3.94          call create_bounce_frame
    3.95          movl EDOMAIN_vcpu_info(%ebx),%eax
    3.96          movb $1,VCPUINFO_upcall_mask(%eax) # Upcalls are masked during delivery
    3.97 -        jmp  restore_all_guest
    3.98 +        jmp  test_all_events
    3.99  
   3.100          ALIGN
   3.101  process_softirqs:
   3.102 @@ -336,67 +315,66 @@ create_bounce_frame:
   3.103          addl %ecx,%eax
   3.104          addl $init_tss + 12,%eax
   3.105          movl (%eax),%esi /* tss->esp1 */
   3.106 -FLT7:   movl 4(%eax),%gs /* tss->ss1  */
   3.107 +FLT6:   movl 4(%eax),%gs /* tss->ss1  */
   3.108          testl $X86_EFLAGS_VM,XREGS_eflags+4(%esp)
   3.109          jz   nvm86_1
   3.110 -	subl $16,%esi       /* push ES/DS/FS/GS (VM86 stack frame) */
   3.111 -	movl XREGS_es+4(%esp),%eax
   3.112 -FLT8:   movl %eax,%gs:(%esi)
   3.113 -	movl XREGS_ds+4(%esp),%eax
   3.114 -FLT9:   movl %eax,%gs:4(%esi)
   3.115 -	movl XREGS_fs+4(%esp),%eax
   3.116 -FLT10:  movl %eax,%gs:8(%esi)
   3.117 -	movl XREGS_gs+4(%esp),%eax
   3.118 -FLT11:  movl %eax,%gs:12(%esi)
   3.119 +        subl $16,%esi       /* push ES/DS/FS/GS (VM86 stack frame) */
   3.120 +        movl XREGS_es+4(%esp),%eax
   3.121 +FLT7:   movl %eax,%gs:(%esi)
   3.122 +        movl XREGS_ds+4(%esp),%eax
   3.123 +FLT8:   movl %eax,%gs:4(%esi)
   3.124 +        movl XREGS_fs+4(%esp),%eax
   3.125 +FLT9:   movl %eax,%gs:8(%esi)
   3.126 +        movl XREGS_gs+4(%esp),%eax
   3.127 +FLT10:  movl %eax,%gs:12(%esi)
   3.128  nvm86_1:subl $8,%esi        /* push SS/ESP (inter-priv iret) */
   3.129          movl XREGS_esp+4(%esp),%eax
   3.130 -FLT12:  movl %eax,%gs:(%esi) 
   3.131 +FLT11:  movl %eax,%gs:(%esi) 
   3.132          movl XREGS_ss+4(%esp),%eax
   3.133 -FLT13:  movl %eax,%gs:4(%esi) 
   3.134 +FLT12:  movl %eax,%gs:4(%esi) 
   3.135          jmp 1f
   3.136  ring1:  /* obtain ss/esp from oldss/oldesp -- a ring-1 activation exists */
   3.137          movl XREGS_esp+4(%esp),%esi
   3.138 -FLT14:  movl XREGS_ss+4(%esp),%gs 
   3.139 +FLT13:  movl XREGS_ss+4(%esp),%gs 
   3.140  1:      /* Construct a stack frame: EFLAGS, CS/EIP */
   3.141          subl $12,%esi
   3.142          movl XREGS_eip+4(%esp),%eax
   3.143 -FLT15:  movl %eax,%gs:(%esi) 
   3.144 +FLT14:  movl %eax,%gs:(%esi) 
   3.145          movl XREGS_cs+4(%esp),%eax
   3.146 -FLT16:  movl %eax,%gs:4(%esi) 
   3.147 +FLT15:  movl %eax,%gs:4(%esi) 
   3.148          movl XREGS_eflags+4(%esp),%eax
   3.149 -FLT17:  movl %eax,%gs:8(%esi)
   3.150 +FLT16:  movl %eax,%gs:8(%esi)
   3.151          movb TRAPBOUNCE_flags(%edx),%cl
   3.152          test $TBF_EXCEPTION_ERRCODE,%cl
   3.153          jz   1f
   3.154          subl $4,%esi                    # push error_code onto guest frame
   3.155          movl TRAPBOUNCE_error_code(%edx),%eax
   3.156 -FLT18:  movl %eax,%gs:(%esi)
   3.157 +FLT17:  movl %eax,%gs:(%esi)
   3.158          testb $TBF_EXCEPTION_CR2,%cl
   3.159          jz   2f
   3.160          subl $4,%esi                    # push %cr2 onto guest frame
   3.161          movl TRAPBOUNCE_cr2(%edx),%eax
   3.162 -FLT19:  movl %eax,%gs:(%esi)
   3.163 +FLT18:  movl %eax,%gs:(%esi)
   3.164  1:      testb $TBF_FAILSAFE,%cl
   3.165          jz   2f
   3.166          subl $16,%esi                # add DS/ES/FS/GS to failsafe stack frame
   3.167          testl $X86_EFLAGS_VM,XREGS_eflags+4(%esp)
   3.168          jz   nvm86_2
   3.169          xorl %eax,%eax               # VM86: we write zero selector values
   3.170 -FLT20:  movl %eax,%gs:(%esi) 
   3.171 -FLT21:  movl %eax,%gs:4(%esi)
   3.172 -FLT22:  movl %eax,%gs:8(%esi) 
   3.173 -FLT23:  movl %eax,%gs:12(%esi)
   3.174 +FLT19:  movl %eax,%gs:(%esi) 
   3.175 +FLT20:  movl %eax,%gs:4(%esi)
   3.176 +FLT21:  movl %eax,%gs:8(%esi) 
   3.177 +FLT22:  movl %eax,%gs:12(%esi)
   3.178          jmp  2f
   3.179  nvm86_2:movl XREGS_ds+4(%esp),%eax   # non-VM86: write real selector values
   3.180 -FLT24:  movl %eax,%gs:(%esi) 
   3.181 +FLT23:  movl %eax,%gs:(%esi) 
   3.182          movl XREGS_es+4(%esp),%eax
   3.183 -FLT25:  movl %eax,%gs:4(%esi)
   3.184 +FLT24:  movl %eax,%gs:4(%esi)
   3.185          movl XREGS_fs+4(%esp),%eax
   3.186 -FLT26:  movl %eax,%gs:8(%esi) 
   3.187 +FLT25:  movl %eax,%gs:8(%esi) 
   3.188          movl XREGS_gs+4(%esp),%eax
   3.189 -FLT27:  movl %eax,%gs:12(%esi)
   3.190 -2:      movb $0,TRAPBOUNCE_flags(%edx)
   3.191 -        testl $X86_EFLAGS_VM,XREGS_eflags+4(%esp)
   3.192 +FLT26:  movl %eax,%gs:12(%esi)
   3.193 +2:      testl $X86_EFLAGS_VM,XREGS_eflags+4(%esp)
   3.194          jz   nvm86_3
   3.195          xorl %eax,%eax      /* zero DS-GS, just as a real CPU would */
   3.196          movl %eax,XREGS_ds+4(%esp)
   3.197 @@ -412,29 +390,16 @@ nvm86_3:/* Rewrite our stack frame and r
   3.198          movl %eax,XREGS_cs+4(%esp)
   3.199          movl TRAPBOUNCE_eip(%edx),%eax
   3.200          movl %eax,XREGS_eip+4(%esp)
   3.201 +        movb $0,TRAPBOUNCE_flags(%edx)
   3.202          ret
   3.203 -.section .fixup,"ax"
   3.204 -FIX7:   sti
   3.205 -        popl  %esi
   3.206 -        addl  $4,%esp                  # Discard create_b_frame return address
   3.207 -        pushfl                         # EFLAGS
   3.208 -        movl  $__HYPERVISOR_CS,%eax
   3.209 -        pushl %eax                     # CS
   3.210 -        movl  $DBLFLT2,%eax
   3.211 -        pushl %eax                     # EIP
   3.212 -        pushl %esi                     # error_code/entry_vector
   3.213 -        jmp   error_code
   3.214 -DBLFLT2:jmp   process_guest_exception_and_events
   3.215 -.previous
   3.216 -.section __pre_ex_table,"a"
   3.217 -	.long  FLT7,FIX7 ,  FLT8,FIX7 ,  FLT9,FIX7 , FLT10,FIX7
   3.218 -	.long FLT11,FIX7 , FLT12,FIX7 , FLT13,FIX7 , FLT14,FIX7
   3.219 -	.long FLT15,FIX7 , FLT16,FIX7 , FLT17,FIX7 , FLT18,FIX7
   3.220 -	.long FLT19,FIX7 , FLT20,FIX7 , FLT21,FIX7 , FLT22,FIX7
   3.221 -	.long FLT23,FIX7 , FLT24,FIX7 , FLT25,FIX7 , FLT26,FIX7 , FLT27,FIX7
   3.222 -.previous
   3.223  .section __ex_table,"a"
   3.224 -        .long DBLFLT2,domain_crash
   3.225 +	.long  FLT6,domain_crash ,  FLT7,domain_crash ,  FLT8,domain_crash
   3.226 +        .long  FLT9,domain_crash , FLT10,domain_crash , FLT11,domain_crash
   3.227 +        .long FLT12,domain_crash , FLT13,domain_crash , FLT14,domain_crash
   3.228 +        .long FLT15,domain_crash , FLT16,domain_crash , FLT17,domain_crash
   3.229 +	.long FLT18,domain_crash , FLT19,domain_crash , FLT20,domain_crash
   3.230 +        .long FLT21,domain_crash , FLT22,domain_crash , FLT23,domain_crash
   3.231 +        .long FLT24,domain_crash , FLT25,domain_crash , FLT26,domain_crash
   3.232  .previous
   3.233  
   3.234          ALIGN
   3.235 @@ -442,7 +407,6 @@ process_guest_exception_and_events:
   3.236          leal EDOMAIN_trap_bounce(%ebx),%edx
   3.237          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%edx)
   3.238          jz   test_all_events
   3.239 -        cli  # create_bounce_frame needs CLI for pre-exceptions to work
   3.240          call create_bounce_frame
   3.241          jmp  test_all_events
   3.242  
     4.1 --- a/xen/arch/x86/x86_64/entry.S	Mon Mar 14 11:34:53 2005 +0000
     4.2 +++ b/xen/arch/x86/x86_64/entry.S	Mon Mar 14 18:30:47 2005 +0000
     4.3 @@ -21,8 +21,6 @@
     4.4          ALIGN
     4.5  /* %rbx: struct exec_domain */
     4.6  restore_all_guest:
     4.7 -        btr   $_TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
     4.8 -        jc    failsafe_callback
     4.9          RESTORE_ALL
    4.10          testw $TRAP_syscall,4(%rsp)
    4.11          jz    iret_exit_to_guest
    4.12 @@ -59,39 +57,20 @@ FIX1:   popq  -15*8-8(%rsp)            #
    4.13          jmp   error_code
    4.14  DBLFLT1:GET_CURRENT(%rbx)
    4.15          jmp   test_all_events
    4.16 -DBLFIX1:GET_CURRENT(%rbx)
    4.17 -        bts   $_TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    4.18 -        jc    domain_crash             # cannot reenter failsafe code
    4.19 -        jmp   test_all_events          # will return via failsafe code
    4.20 +failsafe_callback:
    4.21 +        GET_CURRENT(%rbx)
    4.22 +        leaq  EDOMAIN_trap_bounce(%rbx),%rdx
    4.23 +        movq  EDOMAIN_failsafe_addr(%rbx),%rax
    4.24 +        movq  %rax,TRAPBOUNCE_eip(%rdx)
    4.25 +        movw  $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
    4.26 +        call  create_bounce_frame
    4.27 +        jmp   test_all_events
    4.28  .previous
    4.29  .section __pre_ex_table,"a"
    4.30  	.quad FLT1,FIX1
    4.31  .previous
    4.32  .section __ex_table,"a"
    4.33 -        .quad DBLFLT1,DBLFIX1
    4.34 -.previous
    4.35 -
    4.36 -/* No special register assumptions */
    4.37 -failsafe_callback:
    4.38 -        GET_CURRENT(%rbx)
    4.39 -        leaq EDOMAIN_trap_bounce(%rbx),%rdx
    4.40 -        movq EDOMAIN_failsafe_addr(%rbx),%rax
    4.41 -        movq %rax,TRAPBOUNCE_eip(%rdx)
    4.42 -        movw $TBF_FAILSAFE,TRAPBOUNCE_flags(%rdx)
    4.43 -        call create_bounce_frame
    4.44 -        RESTORE_ALL
    4.45 -        addq $8,%rsp
    4.46 -FLT2:   iret 
    4.47 -
    4.48 -.section .fixup,"ax"
    4.49 -FIX2:   pushq %rbx
    4.50 -        GET_CURRENT(%rbx)
    4.51 -        orb   $TF_failsafe_return,EDOMAIN_thread_flags(%rbx)
    4.52 -        popq  %rbx
    4.53 -        jmp   FIX1
    4.54 -.previous
    4.55 -.section __pre_ex_table,"a"
    4.56 -	.quad FLT2,FIX2
    4.57 +        .quad DBLFLT1,failsafe_callback
    4.58  .previous
    4.59  
    4.60          ALIGN
    4.61 @@ -124,6 +103,7 @@ ENTRY(syscall_enter)
    4.62          pushq $0
    4.63          movl  $TRAP_syscall,4(%rsp)
    4.64          SAVE_ALL
    4.65 +        sti
    4.66          GET_CURRENT(%rbx)
    4.67          testb $TF_kernel_mode,EDOMAIN_thread_flags(%rbx)
    4.68          jnz   hypercall
    4.69 @@ -137,7 +117,6 @@ ENTRY(syscall_enter)
    4.70  
    4.71  /* %rbx: struct exec_domain */
    4.72  hypercall:
    4.73 -        sti
    4.74          movq  %r10,%rcx
    4.75          andq  $(NR_hypercalls-1),%rax
    4.76          leaq  SYMBOL_NAME(hypercall_table)(%rip),%r10
    4.77 @@ -161,6 +140,7 @@ test_all_events:
    4.78          testb $0xFF,VCPUINFO_upcall_pending(%rax)
    4.79          jz    restore_all_guest
    4.80  /*process_guest_events:*/
    4.81 +        sti
    4.82          leaq  EDOMAIN_trap_bounce(%rbx),%rdx
    4.83          movq  EDOMAIN_event_addr(%rbx),%rax
    4.84          movq  %rax,TRAPBOUNCE_eip(%rdx)
    4.85 @@ -168,7 +148,7 @@ test_all_events:
    4.86          call  create_bounce_frame
    4.87          movq  EDOMAIN_vcpu_info(%rbx),%rax
    4.88          movb  $1,VCPUINFO_upcall_mask(%rax) # Upcalls masked during delivery
    4.89 -        jmp   restore_all_guest
    4.90 +        jmp   test_all_events
    4.91  
    4.92          ALIGN
    4.93  /* %rbx: struct exec_domain */
    4.94 @@ -176,7 +156,7 @@ process_softirqs:
    4.95          sti       
    4.96          call SYMBOL_NAME(do_softirq)
    4.97          jmp  test_all_events
    4.98 -                
    4.99 +
   4.100  /* CREATE A BASIC EXCEPTION FRAME ON GUEST OS STACK:                     */
   4.101  /*   { RCX, R11, [DS-GS,] [CR2,] [ERRCODE,] RIP, CS, RFLAGS, RSP, SS }   */
   4.102  /* %rdx: trap_bounce, %rbx: struct exec_domain                           */
   4.103 @@ -185,9 +165,16 @@ create_bounce_frame:
   4.104          /* Push new frame at existing %rsp if already in guest-OS mode. */
   4.105          movq  XREGS_rsp+8(%rsp),%rsi
   4.106          testb $TF_kernel_mode,EDOMAIN_thread_flags(%rbx)
   4.107 +        /* Set kernel-mode indicator byte (RFLAGS[63:56]). */
   4.108 +        setnz XREGS_eflags+15(%rsp)
   4.109          jnz   1f
   4.110          /* Push new frame at registered guest-OS stack base. */
   4.111 +        /* Then call to C: toggle_guest_mode(current) */
   4.112          movq  EDOMAIN_kernel_sp(%rbx),%rsi
   4.113 +        movq  %rbx,%rdi
   4.114 +        pushq %rdx
   4.115 +        call  SYMBOL_NAME(toggle_guest_mode)
   4.116 +        popq  %rdx
   4.117  1:      movq  $HYPERVISOR_VIRT_START,%rax
   4.118          cmpq  %rax,%rsi
   4.119          jb    1f                        # In +ve address space? Then okay.
   4.120 @@ -196,78 +183,59 @@ 1:      movq  $HYPERVISOR_VIRT_START,%ra
   4.121          jb    domain_crash              # Above Xen private area? Then okay.
   4.122  1:      subq  $40,%rsi
   4.123          movq  XREGS_ss+8(%rsp),%rax
   4.124 -FLT3:   movq  %rax,32(%rsi)             # SS
   4.125 +FLT2:   movq  %rax,32(%rsi)             # SS
   4.126          movq  XREGS_rsp+8(%rsp),%rax
   4.127 -FLT4:   movq  %rax,24(%rsi)             # RSP
   4.128 +FLT3:   movq  %rax,24(%rsi)             # RSP
   4.129          movq  XREGS_eflags+8(%rsp),%rax
   4.130 -FLT5:   movq  %rax,16(%rsi)             # RFLAGS
   4.131 +FLT4:   movq  %rax,16(%rsi)             # RFLAGS
   4.132          movq  XREGS_cs+8(%rsp),%rax
   4.133 -FLT6:   movq  %rax,8(%rsi)              # CS
   4.134 +FLT5:   movq  %rax,8(%rsi)              # CS
   4.135          movq  XREGS_rip+8(%rsp),%rax
   4.136 -FLT7:   movq  %rax,(%rsi)               # RIP
   4.137 +FLT6:   movq  %rax,(%rsi)               # RIP
   4.138          movb  TRAPBOUNCE_flags(%rdx),%cl
   4.139          testb $TBF_EXCEPTION_ERRCODE,%cl
   4.140          jz    1f
   4.141          subq  $8,%rsi
   4.142 -        movq  TRAPBOUNCE_error_code(%rdx),%rax
   4.143 -FLT8:   movq  %rax,(%rsi)               # ERROR CODE
   4.144 +        movl  TRAPBOUNCE_error_code(%rdx),%eax
   4.145 +FLT7:   movq  %rax,(%rsi)               # ERROR CODE
   4.146          testb $TBF_EXCEPTION_CR2,%cl
   4.147          jz    2f
   4.148          subq  $8,%rsi
   4.149          movq  TRAPBOUNCE_cr2(%rdx),%rax
   4.150 -FLT9:   movq  %rax,(%rsi)               # CR2
   4.151 +FLT8:   movq  %rax,(%rsi)               # CR2
   4.152  1:      testb $TBF_FAILSAFE,%cl
   4.153          jz    2f
   4.154          subq  $32,%rsi
   4.155          movl  %gs,%eax
   4.156 -FLT10:  movq  %rax,24(%rsi)             # GS
   4.157 +FLT9:   movq  %rax,24(%rsi)             # GS
   4.158          movl  %fs,%eax
   4.159 -FLT11:  movq  %rax,16(%rsi)             # FS
   4.160 +FLT10:  movq  %rax,16(%rsi)             # FS
   4.161          movl  %es,%eax
   4.162 -FLT12:  movq  %rax,8(%rsi)              # ES
   4.163 +FLT11:  movq  %rax,8(%rsi)              # ES
   4.164          movl  %ds,%eax
   4.165 -FLT13:  movq  %rax,(%rsi)               # DS
   4.166 +FLT12:  movq  %rax,(%rsi)               # DS
   4.167  2:      subq  $16,%rsi
   4.168          movq  XREGS_r11+8(%rsp),%rax
   4.169 -FLT14:  movq  %rax,(%rsi)               # R11
   4.170 +FLT13:  movq  %rax,(%rsi)               # R11
   4.171          movq  XREGS_rcx+8(%rsp),%rax
   4.172 -FLT15:  movq  %rax,(%rsi)               # RCX
   4.173 +FLT14:  movq  %rax,(%rsi)               # RCX
   4.174          /* Rewrite our stack frame and return to guest-OS mode. */
   4.175          /* IA32 Ref. Vol. 3: TF, VM, RF and NT flags are cleared on trap. */
   4.176 -        movl  $TRAP_syscall,XREGS_entry_vector+8(%rsp)
   4.177 +        movq  $TRAP_syscall,XREGS_entry_vector+8(%rsp)
   4.178          andl  $0xfffcbeff,XREGS_eflags+8(%rsp)
   4.179 -        movl  $__GUEST_SS,XREGS_ss+8(%rsp)
   4.180 +        movq  $__GUEST_SS,XREGS_ss+8(%rsp)
   4.181          movq  %rsi,XREGS_rsp+8(%rsp)
   4.182 -        movl  $__GUEST_CS,XREGS_cs+8(%rsp)
   4.183 +        movq  $__GUEST_CS,XREGS_cs+8(%rsp)
   4.184          movq  TRAPBOUNCE_eip(%rdx),%rax
   4.185          movq  %rax,XREGS_rip+8(%rsp)
   4.186          movb  $0,TRAPBOUNCE_flags(%rdx)
   4.187 -        testb $TF_kernel_mode,EDOMAIN_thread_flags(%rbx)
   4.188 -        movq  %rbx,%rdi # toggle_guest_mode(current)
   4.189 -        jz    SYMBOL_NAME(toggle_guest_mode)
   4.190          ret
   4.191 -.section .fixup,"ax"
   4.192 -FIX3:   sti
   4.193 -        popq  %rsi
   4.194 -        addq  $8,%rsp                  # Discard create_b_frame return address
   4.195 -        pushq $__HYPERVISOR_DS         # SS
   4.196 -        leaq  8(%rsp),%rax
   4.197 -        pushq %rax                     # RSP
   4.198 -        pushf                          # RFLAGS
   4.199 -        pushq $__HYPERVISOR_CS         # CS
   4.200 -        leaq  DBLFLT2(%rip),%rax
   4.201 -        pushq %rax                     # RIP
   4.202 -        pushq %rsi                     # error_code/entry_vector
   4.203 -        jmp   error_code
   4.204 -DBLFLT2:jmp   process_guest_exception_and_events
   4.205 -.previous
   4.206 -.section __pre_ex_table,"a"
   4.207 -	.quad  FLT3,FIX3 ,  FLT4,FIX3 ,  FLT5,FIX3 ,  FLT6,FIX3
   4.208 -	.quad  FLT7,FIX3 ,  FLT8,FIX3 ,  FLT9,FIX3 , FLT10,FIX3
   4.209 -	.quad FLT11,FIX3 , FLT12,FIX3 , FLT13,FIX3 , FLT14,FIX3 , FLT15,FIX3
   4.210 -.previous
   4.211  .section __ex_table,"a"
   4.212 -        .quad DBLFLT2,domain_crash
   4.213 +        .quad  FLT2,domain_crash ,  FLT3,domain_crash ,  FLT4,domain_crash
   4.214 +        .quad  FLT5,domain_crash ,  FLT6,domain_crash ,  FLT7,domain_crash
   4.215 +        .quad  FLT8,domain_crash ,  FLT9,domain_crash , FLT10,domain_crash
   4.216 +        .quad FLT11,domain_crash , FLT12,domain_crash , FLT13,domain_crash
   4.217 +        .quad FLT14,domain_crash
   4.218  .previous
   4.219  
   4.220          ALIGN
   4.221 @@ -276,7 +244,6 @@ process_guest_exception_and_events:
   4.222          leaq  EDOMAIN_trap_bounce(%rbx),%rdx
   4.223          testb $TBF_EXCEPTION,TRAPBOUNCE_flags(%rdx)
   4.224          jz    test_all_events
   4.225 -        cli   # create_bounce_frame needs CLI for pre-exceptions to work
   4.226          call  create_bounce_frame
   4.227          jmp   test_all_events
   4.228  
     5.1 --- a/xen/include/asm-x86/processor.h	Mon Mar 14 11:34:53 2005 +0000
     5.2 +++ b/xen/include/asm-x86/processor.h	Mon Mar 14 18:30:47 2005 +0000
     5.3 @@ -110,7 +110,8 @@
     5.4  #define TRAP_deferred_nmi     31
     5.5  
     5.6  /* Set for entry via SYSCALL. Informs return code to use SYSRETQ not IRETQ. */
     5.7 -#define TRAP_syscall         256 /* NB. Same as ECF_IN_SYSCALL */
     5.8 +/* NB. Same as ECF_IN_SYSCALL. No bits in common with any other TRAP_* defn. */
     5.9 +#define TRAP_syscall         256
    5.10  
    5.11  /*
    5.12   * Non-fatal fault/trap handlers return an error code to the caller. If the
    5.13 @@ -128,10 +129,8 @@
    5.14  #define TBF_INTERRUPT          8
    5.15  #define TBF_FAILSAFE          16
    5.16  
    5.17 -/* arch_exec_domain' flags values */
    5.18 -#define _TF_failsafe_return    0
    5.19 -#define _TF_kernel_mode        1
    5.20 -#define TF_failsafe_return     (1<<_TF_failsafe_return)
    5.21 +/* 'arch_exec_domain' flags values */
    5.22 +#define _TF_kernel_mode        0
    5.23  #define TF_kernel_mode         (1<<_TF_kernel_mode)
    5.24  
    5.25  #ifndef __ASSEMBLY__
     6.1 --- a/xen/include/public/arch-x86_32.h	Mon Mar 14 11:34:53 2005 +0000
     6.2 +++ b/xen/include/public/arch-x86_32.h	Mon Mar 14 18:30:47 2005 +0000
     6.3 @@ -103,11 +103,8 @@ typedef struct xen_regs
     6.4      u32 edi;
     6.5      u32 ebp;
     6.6      u32 eax;
     6.7 -    u16 error_code;        /* private */
     6.8 -    union { 
     6.9 -        u16 entry_vector;  /* private */
    6.10 -        u16 flags;
    6.11 -    } PACKED;
    6.12 +    u16 error_code;    /* private */
    6.13 +    u16 entry_vector;  /* private */
    6.14      u32 eip;
    6.15      u32 cs;
    6.16      u32 eflags;
     7.1 --- a/xen/include/public/arch-x86_64.h	Mon Mar 14 11:34:53 2005 +0000
     7.2 +++ b/xen/include/public/arch-x86_64.h	Mon Mar 14 18:30:47 2005 +0000
     7.3 @@ -104,6 +104,8 @@
     7.4   *   Restore RAX, R11, RCX, CS:RIP, RFLAGS, SS:RSP.
     7.5   * All other registers are saved on hypercall entry and restored to user.
     7.6   */
     7.7 +/* Guest exited in SYSCALL context? Return to guest with SYSRET? */
     7.8 +#define ECF_IN_SYSCALL (1<<8)
     7.9  struct switch_to_user {
    7.10      /* Top of stack (%rsp at point of hypercall). */
    7.11      u64 rax, r11, rcx, flags, rip, cs, rflags, rsp, ss;
    7.12 @@ -153,12 +155,8 @@ typedef struct xen_regs
    7.13      union { u64 rdx, edx; } PACKED;
    7.14      union { u64 rsi, esi; } PACKED;
    7.15      union { u64 rdi, edi; } PACKED;
    7.16 -    u32 error_code;        /* private */
    7.17 -    union { 
    7.18 -        u32 entry_vector;  /* private */
    7.19 -#define ECF_IN_SYSCALL (1<<8) /* Guest synchronously interrupted by SYSCALL? */
    7.20 -        u32 flags;
    7.21 -    } PACKED;
    7.22 +    u32 error_code;    /* private */
    7.23 +    u32 entry_vector;  /* private */
    7.24      union { u64 rip, eip; } PACKED;
    7.25      u64 cs;
    7.26      union { u64 rflags, eflags; } PACKED;