ia64/xen-unstable

changeset 14063:b010e556fe2c

x86: Extend emulator return codes.
Signed-off-by: Keir Fraser <keir@xensource.com>
author kfraser@localhost.localdomain
date Wed Feb 21 19:58:58 2007 +0000 (2007-02-21)
parents ad3ee81cc8c4
children 4e50678c364c
files tools/tests/test_x86_emulator.c xen/arch/x86/mm.c xen/arch/x86/mm/shadow/common.c xen/arch/x86/mm/shadow/multi.c xen/arch/x86/x86_emulate.c xen/include/asm-x86/x86_emulate.h
line diff
     1.1 --- a/tools/tests/test_x86_emulator.c	Wed Feb 21 11:42:04 2007 -0800
     1.2 +++ b/tools/tests/test_x86_emulator.c	Wed Feb 21 19:58:58 2007 +0000
     1.3 @@ -43,7 +43,7 @@ static int read(
     1.4      case 4: *val = *(u32 *)addr; break;
     1.5      case 8: *val = *(unsigned long *)addr; break;
     1.6      }
     1.7 -    return X86EMUL_CONTINUE;
     1.8 +    return X86EMUL_OKAY;
     1.9  }
    1.10  
    1.11  static int write(
    1.12 @@ -61,7 +61,7 @@ static int write(
    1.13      case 4: *(u32 *)addr = (u32)val; break;
    1.14      case 8: *(unsigned long *)addr = val; break;
    1.15      }
    1.16 -    return X86EMUL_CONTINUE;
    1.17 +    return X86EMUL_OKAY;
    1.18  }
    1.19  
    1.20  static int cmpxchg(
    1.21 @@ -80,7 +80,7 @@ static int cmpxchg(
    1.22      case 4: *(u32 *)addr = (u32)new; break;
    1.23      case 8: *(unsigned long *)addr = new; break;
    1.24      }
    1.25 -    return X86EMUL_CONTINUE;
    1.26 +    return X86EMUL_OKAY;
    1.27  }
    1.28  
    1.29  static int cmpxchg8b(
    1.30 @@ -95,7 +95,7 @@ static int cmpxchg8b(
    1.31      unsigned long addr = offset;
    1.32      ((unsigned long *)addr)[0] = new_lo;
    1.33      ((unsigned long *)addr)[1] = new_hi;
    1.34 -    return X86EMUL_CONTINUE;
    1.35 +    return X86EMUL_OKAY;
    1.36  }
    1.37  
    1.38  static struct x86_emulate_ops emulops = {
    1.39 @@ -138,7 +138,7 @@ int main(int argc, char **argv)
    1.40      regs.eax    = (unsigned long)res;
    1.41      *res        = 0x7FFFFFFF;
    1.42      rc = x86_emulate(&ctxt, &emulops);
    1.43 -    if ( (rc != 0) || 
    1.44 +    if ( (rc != X86EMUL_OKAY) || 
    1.45           (*res != 0x92345677) || 
    1.46           (regs.eflags != 0xa94) ||
    1.47           (regs.eip != (unsigned long)&instr[2]) )
    1.48 @@ -152,7 +152,7 @@ int main(int argc, char **argv)
    1.49      regs.ecx    = 0x12345678;
    1.50      regs.eax    = 0x7FFFFFFF;
    1.51      rc = x86_emulate(&ctxt, &emulops);
    1.52 -    if ( (rc != 0) || 
    1.53 +    if ( (rc != X86EMUL_OKAY) || 
    1.54           (regs.ecx != 0x12345678) ||
    1.55           (regs.eax != 0x92345677) ||
    1.56           (regs.eflags != 0xa94) ||
    1.57 @@ -171,7 +171,7 @@ int main(int argc, char **argv)
    1.58  #endif
    1.59      regs.eax    = (unsigned long)res;
    1.60      rc = x86_emulate(&ctxt, &emulops);
    1.61 -    if ( (rc != 0) || 
    1.62 +    if ( (rc != X86EMUL_OKAY) || 
    1.63           (*res != 0x92345677) || 
    1.64           (regs.ecx != 0x8000000FUL) ||
    1.65           (regs.eip != (unsigned long)&instr[2]) )
    1.66 @@ -185,7 +185,7 @@ int main(int argc, char **argv)
    1.67      regs.ecx    = ~0UL;
    1.68      regs.eax    = (unsigned long)res;
    1.69      rc = x86_emulate(&ctxt, &emulops);
    1.70 -    if ( (rc != 0) || 
    1.71 +    if ( (rc != X86EMUL_OKAY) || 
    1.72           (*res != 0x92345677) || 
    1.73           (regs.ecx != 0x92345677UL) ||
    1.74           (regs.eip != (unsigned long)&instr[2]) )
    1.75 @@ -200,7 +200,7 @@ int main(int argc, char **argv)
    1.76      regs.ecx    = 0xAA;
    1.77      regs.ebx    = (unsigned long)res;
    1.78      rc = x86_emulate(&ctxt, &emulops);
    1.79 -    if ( (rc != 0) || 
    1.80 +    if ( (rc != X86EMUL_OKAY) || 
    1.81           (*res != 0x923456AA) || 
    1.82           (regs.eflags != 0x244) ||
    1.83           (regs.eax != 0x92345677UL) ||
    1.84 @@ -216,7 +216,7 @@ int main(int argc, char **argv)
    1.85      regs.ecx    = 0xFF;
    1.86      regs.ebx    = (unsigned long)res;
    1.87      rc = x86_emulate(&ctxt, &emulops);
    1.88 -    if ( (rc != 0) || 
    1.89 +    if ( (rc != X86EMUL_OKAY) || 
    1.90           (*res != 0x923456AA) || 
    1.91           ((regs.eflags&0x240) != 0x200) ||
    1.92           (regs.eax != 0xAABBCCAA) ||
    1.93 @@ -232,7 +232,7 @@ int main(int argc, char **argv)
    1.94      regs.ecx    = 0x12345678;
    1.95      regs.eax    = (unsigned long)res;
    1.96      rc = x86_emulate(&ctxt, &emulops);
    1.97 -    if ( (rc != 0) || 
    1.98 +    if ( (rc != X86EMUL_OKAY) || 
    1.99           (*res != 0x12345678) || 
   1.100           (regs.eflags != 0x200) ||
   1.101           (regs.ecx != 0x923456AA) ||
   1.102 @@ -249,7 +249,7 @@ int main(int argc, char **argv)
   1.103      regs.ecx    = 0xDDEEFF00L;
   1.104      regs.ebx    = (unsigned long)res;
   1.105      rc = x86_emulate(&ctxt, &emulops);
   1.106 -    if ( (rc != 0) || 
   1.107 +    if ( (rc != X86EMUL_OKAY) || 
   1.108           (*res != 0xDDEEFF00) || 
   1.109           (regs.eflags != 0x244) ||
   1.110           (regs.eax != 0x923456AAUL) ||
   1.111 @@ -266,7 +266,7 @@ int main(int argc, char **argv)
   1.112      regs.esi    = (unsigned long)res + 0;
   1.113      regs.edi    = (unsigned long)res + 2;
   1.114      rc = x86_emulate(&ctxt, &emulops);
   1.115 -    if ( (rc != 0) || 
   1.116 +    if ( (rc != X86EMUL_OKAY) || 
   1.117           (*res != 0x44554455) ||
   1.118           (regs.eflags != 0x200) ||
   1.119           (regs.ecx != 22) || 
   1.120 @@ -283,7 +283,7 @@ int main(int argc, char **argv)
   1.121      regs.eip    = (unsigned long)&instr[0];
   1.122      regs.edi    = (unsigned long)res;
   1.123      rc = x86_emulate(&ctxt, &emulops);
   1.124 -    if ( (rc != 0) ||
   1.125 +    if ( (rc != X86EMUL_OKAY) ||
   1.126           (*res != 0x2233445D) ||
   1.127           ((regs.eflags&0x201) != 0x201) ||
   1.128           (regs.eip != (unsigned long)&instr[4]) )
   1.129 @@ -298,7 +298,7 @@ int main(int argc, char **argv)
   1.130      regs.eax    = -32;
   1.131      regs.edi    = (unsigned long)(res+1);
   1.132      rc = x86_emulate(&ctxt, &emulops);
   1.133 -    if ( (rc != 0) ||
   1.134 +    if ( (rc != X86EMUL_OKAY) ||
   1.135           (*res != 0x2233445E) ||
   1.136           ((regs.eflags&0x201) != 0x201) ||
   1.137           (regs.eip != (unsigned long)&instr[3]) )
   1.138 @@ -318,7 +318,7 @@ int main(int argc, char **argv)
   1.139      regs.eip    = (unsigned long)&instr[0];
   1.140      regs.edi    = (unsigned long)res;
   1.141      rc = x86_emulate(&ctxt, &emulops);
   1.142 -    if ( (rc != 0) ||
   1.143 +    if ( (rc != X86EMUL_OKAY) ||
   1.144           (res[0] != 0x9999AAAA) ||
   1.145           (res[1] != 0xCCCCFFFF) ||
   1.146           ((regs.eflags&0x240) != 0x240) ||
   1.147 @@ -332,7 +332,7 @@ int main(int argc, char **argv)
   1.148      regs.eip    = (unsigned long)&instr[0];
   1.149      regs.edi    = (unsigned long)res;
   1.150      rc = x86_emulate(&ctxt, &emulops);
   1.151 -    if ( (rc != 0) || 
   1.152 +    if ( (rc != X86EMUL_OKAY) || 
   1.153           (res[0] != 0x9999AAAA) ||
   1.154           (res[1] != 0xCCCCFFFF) ||
   1.155           (regs.eax != 0x9999AAAA) ||
   1.156 @@ -350,7 +350,7 @@ int main(int argc, char **argv)
   1.157      regs.eax    = (unsigned long)res;
   1.158      *res        = 0x82;
   1.159      rc = x86_emulate(&ctxt, &emulops);
   1.160 -    if ( (rc != 0) ||
   1.161 +    if ( (rc != X86EMUL_OKAY) ||
   1.162           (*res != 0x82) ||
   1.163           (regs.ecx != 0xFFFFFF82) ||
   1.164           ((regs.eflags&0x240) != 0x200) ||
   1.165 @@ -366,7 +366,7 @@ int main(int argc, char **argv)
   1.166      regs.eax    = (unsigned long)res;
   1.167      *res        = 0x1234aa82;
   1.168      rc = x86_emulate(&ctxt, &emulops);
   1.169 -    if ( (rc != 0) ||
   1.170 +    if ( (rc != X86EMUL_OKAY) ||
   1.171           (*res != 0x1234aa82) ||
   1.172           (regs.ecx != 0xaa82) ||
   1.173           ((regs.eflags&0x240) != 0x200) ||
   1.174 @@ -382,7 +382,7 @@ int main(int argc, char **argv)
   1.175      regs.eax    = 0x12345678;
   1.176      *res        = 0x11111111;
   1.177      rc = x86_emulate(&ctxt, &emulops);
   1.178 -    if ( (rc != 0) ||
   1.179 +    if ( (rc != X86EMUL_OKAY) ||
   1.180           (*res != 0x11116789) ||
   1.181           (regs.eax != 0x12341111) ||
   1.182           ((regs.eflags&0x240) != 0x200) ||
   1.183 @@ -396,7 +396,7 @@ int main(int argc, char **argv)
   1.184      regs.eip    = (unsigned long)&instr[0];
   1.185      regs.eax    = 0x00000000;
   1.186      rc = x86_emulate(&ctxt, &emulops);
   1.187 -    if ( (rc != 0) ||
   1.188 +    if ( (rc != X86EMUL_OKAY) ||
   1.189           (regs.eax != 0x0000ffff) ||
   1.190           ((regs.eflags&0x240) != 0x200) ||
   1.191           (regs.eip != (unsigned long)&instr[2]) )
   1.192 @@ -410,7 +410,7 @@ int main(int argc, char **argv)
   1.193      regs.eax    = 0x12345678;
   1.194      regs.ebp    = 0xaaaaaaaa;
   1.195      rc = x86_emulate(&ctxt, &emulops);
   1.196 -    if ( (rc != 0) ||
   1.197 +    if ( (rc != X86EMUL_OKAY) ||
   1.198           (regs.eax != 0xaaaaaab2) ||
   1.199           ((regs.eflags&0x240) != 0x200) ||
   1.200           (regs.eip != (unsigned long)&instr[3]) )
   1.201 @@ -454,7 +454,7 @@ int main(int argc, char **argv)
   1.202          bcdres_emul |= (regs.eflags & EFLG_SF) ? 0x400 : 0;
   1.203          bcdres_emul |= (regs.eflags & EFLG_CF) ? 0x200 : 0;
   1.204          bcdres_emul |= (regs.eflags & EFLG_AF) ? 0x100 : 0;
   1.205 -        if ( (rc != 0) || (regs.eax > 255) ||
   1.206 +        if ( (rc != X86EMUL_OKAY) || (regs.eax > 255) ||
   1.207               (regs.eip != (unsigned long)&instr[1]) )
   1.208              goto fail;
   1.209  
   1.210 @@ -501,7 +501,7 @@ int main(int argc, char **argv)
   1.211          if ( (i++ & 8191) == 0 )
   1.212              printf(".");
   1.213          rc = x86_emulate(&ctxt, &emulops);
   1.214 -        if ( rc != 0 )
   1.215 +        if ( rc != X86EMUL_OKAY )
   1.216          {
   1.217              printf("failed at %%eip == %08x\n", (unsigned int)regs.eip);
   1.218              return 1;
     2.1 --- a/xen/arch/x86/mm.c	Wed Feb 21 11:42:04 2007 -0800
     2.2 +++ b/xen/arch/x86/mm.c	Wed Feb 21 19:58:58 2007 +0000
     2.3 @@ -3151,10 +3151,10 @@ static int ptwr_emulated_read(
     2.4      if ( (rc = copy_from_user((void *)val, (void *)addr, bytes)) != 0 )
     2.5      {
     2.6          propagate_page_fault(addr + bytes - rc, 0); /* read fault */
     2.7 -        return X86EMUL_PROPAGATE_FAULT;
     2.8 +        return X86EMUL_EXCEPTION;
     2.9      }
    2.10  
    2.11 -    return X86EMUL_CONTINUE;
    2.12 +    return X86EMUL_OKAY;
    2.13  }
    2.14  
    2.15  static int ptwr_emulated_update(
    2.16 @@ -3190,7 +3190,7 @@ static int ptwr_emulated_update(
    2.17          if ( (rc = copy_from_user(&full, (void *)addr, sizeof(paddr_t))) != 0 )
    2.18          {
    2.19              propagate_page_fault(addr+sizeof(paddr_t)-rc, 0); /* read fault */
    2.20 -            return X86EMUL_PROPAGATE_FAULT;
    2.21 +            return X86EMUL_EXCEPTION;
    2.22          }
    2.23          /* Mask out bits provided by caller. */
    2.24          full &= ~((((paddr_t)1 << (bytes*8)) - 1) << (offset*8));
    2.25 @@ -3273,7 +3273,7 @@ static int ptwr_emulated_update(
    2.26      /* Finally, drop the old PTE. */
    2.27      put_page_from_l1e(gl1e_to_ml1e(d, ol1e), d);
    2.28  
    2.29 -    return X86EMUL_CONTINUE;
    2.30 +    return X86EMUL_OKAY;
    2.31  }
    2.32  
    2.33  static int ptwr_emulated_write(
    2.34 @@ -3333,6 +3333,7 @@ int ptwr_do_page_fault(struct vcpu *v, u
    2.35      struct page_info *page;
    2.36      l1_pgentry_t      pte;
    2.37      struct ptwr_emulate_ctxt ptwr_ctxt;
    2.38 +    int rc;
    2.39  
    2.40      LOCK_BIGLOCK(d);
    2.41  
    2.42 @@ -3357,7 +3358,9 @@ int ptwr_do_page_fault(struct vcpu *v, u
    2.43          IS_COMPAT(d) ? 32 : BITS_PER_LONG;
    2.44      ptwr_ctxt.cr2 = addr;
    2.45      ptwr_ctxt.pte = pte;
    2.46 -    if ( x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops) )
    2.47 +
    2.48 +    rc = x86_emulate(&ptwr_ctxt.ctxt, &ptwr_emulate_ops);
    2.49 +    if ( rc == X86EMUL_UNHANDLEABLE )
    2.50          goto bail;
    2.51  
    2.52      UNLOCK_BIGLOCK(d);
     3.1 --- a/xen/arch/x86/mm/shadow/common.c	Wed Feb 21 11:42:04 2007 -0800
     3.2 +++ b/xen/arch/x86/mm/shadow/common.c	Wed Feb 21 19:58:58 2007 +0000
     3.3 @@ -191,7 +191,7 @@ static int hvm_translate_linear_addr(
     3.4   gpf:
     3.5      /* Inject #GP(0). */
     3.6      hvm_inject_exception(TRAP_gp_fault, 0, 0);
     3.7 -    return X86EMUL_PROPAGATE_FAULT;
     3.8 +    return X86EMUL_EXCEPTION;
     3.9  }
    3.10  
    3.11  static int
    3.12 @@ -216,7 +216,7 @@ hvm_read(enum x86_segment seg,
    3.13      //        In this case, that is only a user vs supervisor access check.
    3.14      //
    3.15      if ( (rc = hvm_copy_from_guest_virt(val, addr, bytes)) == 0 )
    3.16 -        return X86EMUL_CONTINUE;
    3.17 +        return X86EMUL_OKAY;
    3.18  
    3.19      /* If we got here, there was nothing mapped here, or a bad GFN 
    3.20       * was mapped here.  This should never happen: we're here because
    3.21 @@ -226,7 +226,7 @@ hvm_read(enum x86_segment seg,
    3.22      if ( access_type == hvm_access_insn_fetch )
    3.23          errcode |= PFEC_insn_fetch;
    3.24      hvm_inject_exception(TRAP_page_fault, errcode, addr + bytes - rc);
    3.25 -    return X86EMUL_PROPAGATE_FAULT;
    3.26 +    return X86EMUL_EXCEPTION;
    3.27  }
    3.28  
    3.29  static int
    3.30 @@ -259,7 +259,7 @@ hvm_emulate_insn_fetch(enum x86_segment 
    3.31      /* Hit the cache. Simple memcpy. */
    3.32      *val = 0;
    3.33      memcpy(val, &sh_ctxt->insn_buf[insn_off], bytes);
    3.34 -    return X86EMUL_CONTINUE;
    3.35 +    return X86EMUL_OKAY;
    3.36  }
    3.37  
    3.38  static int
    3.39 @@ -352,10 +352,10 @@ pv_emulate_read(enum x86_segment seg,
    3.40      if ( (rc = copy_from_user((void *)val, (void *)offset, bytes)) != 0 )
    3.41      {
    3.42          propagate_page_fault(offset + bytes - rc, 0); /* read fault */
    3.43 -        return X86EMUL_PROPAGATE_FAULT;
    3.44 +        return X86EMUL_EXCEPTION;
    3.45      }
    3.46  
    3.47 -    return X86EMUL_CONTINUE;
    3.48 +    return X86EMUL_OKAY;
    3.49  }
    3.50  
    3.51  static int
     4.1 --- a/xen/arch/x86/mm/shadow/multi.c	Wed Feb 21 11:42:04 2007 -0800
     4.2 +++ b/xen/arch/x86/mm/shadow/multi.c	Wed Feb 21 19:58:58 2007 +0000
     4.3 @@ -2911,8 +2911,11 @@ static int sh_page_fault(struct vcpu *v,
     4.4       * page is no longer a page table. This behaviour differs from native, but
     4.5       * it seems very unlikely that any OS grants user access to page tables.
     4.6       */
     4.7 -    if ( (regs->error_code & PFEC_user_mode) ||
     4.8 -         x86_emulate(&emul_ctxt.ctxt, emul_ops) )
     4.9 +    r = X86EMUL_UNHANDLEABLE;
    4.10 +    if ( !(regs->error_code & PFEC_user_mode) )
    4.11 +        r = x86_emulate(&emul_ctxt.ctxt, emul_ops);
    4.12 +
    4.13 +    if ( (r == X86EMUL_UNHANDLEABLE) || (r == X86EMUL_EXCEPTION) )
    4.14      {
    4.15          SHADOW_PRINTK("emulator failure, unshadowing mfn %#lx\n", 
    4.16                         mfn_x(gmfn));
    4.17 @@ -3956,7 +3959,7 @@ sh_x86_emulate_write(struct vcpu *v, uns
    4.18      ASSERT(((vaddr & ~PAGE_MASK) + bytes) <= PAGE_SIZE);
    4.19  
    4.20      if ( (addr = emulate_map_dest(v, vaddr, sh_ctxt, &mfn)) == NULL )
    4.21 -        return X86EMUL_PROPAGATE_FAULT;
    4.22 +        return X86EMUL_EXCEPTION;
    4.23  
    4.24      skip = safe_not_to_verify_write(mfn, addr, src, bytes);
    4.25      memcpy(addr, src, bytes);
    4.26 @@ -3968,7 +3971,7 @@ sh_x86_emulate_write(struct vcpu *v, uns
    4.27  
    4.28      sh_unmap_domain_page(addr);
    4.29      shadow_audit_tables(v);
    4.30 -    return X86EMUL_CONTINUE;
    4.31 +    return X86EMUL_OKAY;
    4.32  }
    4.33  
    4.34  int
    4.35 @@ -3979,7 +3982,7 @@ sh_x86_emulate_cmpxchg(struct vcpu *v, u
    4.36      mfn_t mfn;
    4.37      void *addr;
    4.38      unsigned long prev;
    4.39 -    int rv = X86EMUL_CONTINUE, skip;
    4.40 +    int rv = X86EMUL_OKAY, skip;
    4.41  
    4.42      ASSERT(shadow_locked_by_me(v->domain));
    4.43      ASSERT(bytes <= sizeof(unsigned long));
    4.44 @@ -3988,7 +3991,7 @@ sh_x86_emulate_cmpxchg(struct vcpu *v, u
    4.45          return X86EMUL_UNHANDLEABLE;
    4.46  
    4.47      if ( (addr = emulate_map_dest(v, vaddr, sh_ctxt, &mfn)) == NULL )
    4.48 -        return X86EMUL_PROPAGATE_FAULT;
    4.49 +        return X86EMUL_EXCEPTION;
    4.50  
    4.51      skip = safe_not_to_verify_write(mfn, &new, &old, bytes);
    4.52  
    4.53 @@ -4032,7 +4035,7 @@ sh_x86_emulate_cmpxchg8b(struct vcpu *v,
    4.54      mfn_t mfn;
    4.55      void *addr;
    4.56      u64 old, new, prev;
    4.57 -    int rv = X86EMUL_CONTINUE, skip;
    4.58 +    int rv = X86EMUL_OKAY, skip;
    4.59  
    4.60      ASSERT(shadow_locked_by_me(v->domain));
    4.61  
    4.62 @@ -4040,7 +4043,7 @@ sh_x86_emulate_cmpxchg8b(struct vcpu *v,
    4.63          return X86EMUL_UNHANDLEABLE;
    4.64  
    4.65      if ( (addr = emulate_map_dest(v, vaddr, sh_ctxt, &mfn)) == NULL )
    4.66 -        return X86EMUL_PROPAGATE_FAULT;
    4.67 +        return X86EMUL_EXCEPTION;
    4.68  
    4.69      old = (((u64) old_hi) << 32) | (u64) old_lo;
    4.70      new = (((u64) new_hi) << 32) | (u64) new_lo;
     5.1 --- a/xen/arch/x86/x86_emulate.c	Wed Feb 21 11:42:04 2007 -0800
     5.2 +++ b/xen/arch/x86/x86_emulate.c	Wed Feb 21 19:58:58 2007 +0000
     5.3 @@ -464,10 +464,10 @@ do{ __asm__ __volatile__ (              
     5.4  
     5.5  #define mode_64bit() (def_ad_bytes == 8)
     5.6  
     5.7 -#define fail_if(p)                              \
     5.8 -do {                                            \
     5.9 -    rc = (p) ? X86EMUL_UNHANDLEABLE : 0;        \
    5.10 -    if ( rc ) goto done;                        \
    5.11 +#define fail_if(p)                                      \
    5.12 +do {                                                    \
    5.13 +    rc = (p) ? X86EMUL_UNHANDLEABLE : X86EMUL_OKAY;     \
    5.14 +    if ( rc ) goto done;                                \
    5.15  } while (0)
    5.16  
    5.17  /* In future we will be able to generate arbitrary exceptions. */
    5.18 @@ -726,7 +726,7 @@ x86_emulate(
    5.19      uint8_t modrm, modrm_mod = 0, modrm_reg = 0, modrm_rm = 0;
    5.20      unsigned int op_bytes, def_op_bytes, ad_bytes, def_ad_bytes;
    5.21      unsigned int lock_prefix = 0, rep_prefix = 0;
    5.22 -    int rc = 0;
    5.23 +    int rc = X86EMUL_OKAY;
    5.24      struct operand src, dst;
    5.25  
    5.26      /* Data operand effective address (usually computed from ModRM). */
    5.27 @@ -742,7 +742,7 @@ x86_emulate(
    5.28      {
    5.29          op_bytes = def_op_bytes = 4;
    5.30  #ifndef __x86_64__
    5.31 -        return -1;
    5.32 +        return X86EMUL_UNHANDLEABLE;
    5.33  #endif
    5.34      }
    5.35  
    5.36 @@ -1593,7 +1593,7 @@ x86_emulate(
    5.37      *ctxt->regs = _regs;
    5.38  
    5.39   done:
    5.40 -    return (rc == X86EMUL_UNHANDLEABLE) ? -1 : 0;
    5.41 +    return rc;
    5.42  
    5.43   special_insn:
    5.44      dst.type = OP_NONE;
    5.45 @@ -2383,5 +2383,5 @@ x86_emulate(
    5.46      }
    5.47      printk("\n");
    5.48  #endif
    5.49 -    return -1;
    5.50 +    return X86EMUL_UNHANDLEABLE;
    5.51  }
     6.1 --- a/xen/include/asm-x86/x86_emulate.h	Wed Feb 21 11:42:04 2007 -0800
     6.2 +++ b/xen/include/asm-x86/x86_emulate.h	Wed Feb 21 19:58:58 2007 +0000
     6.3 @@ -46,26 +46,32 @@ enum x86_segment {
     6.4  };
     6.5  
     6.6  /*
     6.7 + * Return codes from state-accessor functions and from x86_emulate().
     6.8 + */
     6.9 + /* Completed successfully. State modified appropriately. */
    6.10 +#define X86EMUL_OKAY           0
    6.11 + /* Unhandleable access or emulation. No state modified. */
    6.12 +#define X86EMUL_UNHANDLEABLE   1
    6.13 + /* Exception raised and requires delivery. */
    6.14 +#define X86EMUL_EXCEPTION      2
    6.15 + /* Retry the emulation for some reason. No state modified. */
    6.16 +#define X86EMUL_RETRY          3
    6.17 + /* (cmpxchg accessor): CMPXCHG failed. Maps to X86EMUL_RETRY in caller. */
    6.18 +#define X86EMUL_CMPXCHG_FAILED 3
    6.19 +
    6.20 +/*
    6.21   * These operations represent the instruction emulator's interface to memory.
    6.22   * 
    6.23   * NOTES:
    6.24   *  1. If the access fails (cannot emulate, or a standard access faults) then
    6.25   *     it is up to the memop to propagate the fault to the guest VM via
    6.26   *     some out-of-band mechanism, unknown to the emulator. The memop signals
    6.27 - *     failure by returning X86EMUL_PROPAGATE_FAULT to the emulator, which will
    6.28 + *     failure by returning X86EMUL_EXCEPTION to the emulator, which will
    6.29   *     then immediately bail.
    6.30   *  2. Valid access sizes are 1, 2, 4 and 8 bytes. On x86/32 systems only
    6.31   *     cmpxchg8b_emulated need support 8-byte accesses.
    6.32   *  3. The emulator cannot handle 64-bit mode emulation on an x86/32 system.
    6.33   */
    6.34 -/* Access completed successfully: continue emulation as normal. */
    6.35 -#define X86EMUL_CONTINUE        0
    6.36 -/* Access is unhandleable: bail from emulation and return error to caller. */
    6.37 -#define X86EMUL_UNHANDLEABLE    1
    6.38 -/* Terminate emulation but return success to the caller. */
    6.39 -#define X86EMUL_PROPAGATE_FAULT 2 /* propagate a generated fault to guest */
    6.40 -#define X86EMUL_RETRY_INSTR     2 /* retry the instruction for some reason */
    6.41 -#define X86EMUL_CMPXCHG_FAILED  2 /* cmpxchg did not see expected value */
    6.42  struct x86_emulate_ops
    6.43  {
    6.44      /*