ia64/xen-unstable

changeset 9950:f07676d5c3ab

Fix dr access from or to extended registers on x86_64.
Also some cleanups.
Signed-off-by: Xin Li <xin.b.li@intel.com>
author kaf24@firebug.cl.cam.ac.uk
date Fri May 05 13:59:17 2006 +0100 (2006-05-05)
parents 1d9df2f7030d
children 7801e09f518c
files xen/arch/x86/hvm/vmx/vmx.c
line diff
     1.1 --- a/xen/arch/x86/hvm/vmx/vmx.c	Fri May 05 13:58:13 2006 +0100
     1.2 +++ b/xen/arch/x86/hvm/vmx/vmx.c	Fri May 05 13:59:17 2006 +0100
     1.3 @@ -893,6 +893,20 @@ static void vmx_vmexit_do_cpuid(struct c
     1.4  #define CASE_GET_REG_P(REG, reg)    \
     1.5      case REG_ ## REG: reg_p = (unsigned long *)&(regs->reg); break
     1.6  
     1.7 +#ifdef __i386__
     1.8 +#define CASE_EXTEND_GET_REG_P
     1.9 +#else
    1.10 +#define CASE_EXTEND_GET_REG_P       \
    1.11 +    CASE_GET_REG_P(R8, r8);         \
    1.12 +    CASE_GET_REG_P(R9, r9);         \
    1.13 +    CASE_GET_REG_P(R10, r10);       \
    1.14 +    CASE_GET_REG_P(R11, r11);       \
    1.15 +    CASE_GET_REG_P(R12, r12);       \
    1.16 +    CASE_GET_REG_P(R13, r13);       \
    1.17 +    CASE_GET_REG_P(R14, r14);       \
    1.18 +    CASE_GET_REG_P(R15, r15)
    1.19 +#endif
    1.20 +
    1.21  static void vmx_dr_access (unsigned long exit_qualification, struct cpu_user_regs *regs)
    1.22  {
    1.23      unsigned int reg;
    1.24 @@ -908,14 +922,15 @@ static void vmx_dr_access (unsigned long
    1.25                  "vmx_dr_access : eip=%lx, reg=%d, exit_qualification = %lx",
    1.26                  eip, reg, exit_qualification);
    1.27  
    1.28 -    switch(exit_qualification & DEBUG_REG_ACCESS_REG) {
    1.29 -        CASE_GET_REG_P(EAX, eax);
    1.30 -        CASE_GET_REG_P(ECX, ecx);
    1.31 -        CASE_GET_REG_P(EDX, edx);
    1.32 -        CASE_GET_REG_P(EBX, ebx);
    1.33 -        CASE_GET_REG_P(EBP, ebp);
    1.34 -        CASE_GET_REG_P(ESI, esi);
    1.35 -        CASE_GET_REG_P(EDI, edi);
    1.36 +    switch ( exit_qualification & DEBUG_REG_ACCESS_REG ) {
    1.37 +    CASE_GET_REG_P(EAX, eax);
    1.38 +    CASE_GET_REG_P(ECX, ecx);
    1.39 +    CASE_GET_REG_P(EDX, edx);
    1.40 +    CASE_GET_REG_P(EBX, ebx);
    1.41 +    CASE_GET_REG_P(EBP, ebp);
    1.42 +    CASE_GET_REG_P(ESI, esi);
    1.43 +    CASE_GET_REG_P(EDI, edi);
    1.44 +    CASE_EXTEND_GET_REG_P;
    1.45      case REG_ESP:
    1.46          break;
    1.47      default:
    1.48 @@ -1525,29 +1540,30 @@ static int vmx_set_cr0(unsigned long val
    1.49      return 1;
    1.50  }
    1.51  
    1.52 -#define CASE_GET_REG(REG, reg)  \
    1.53 +#define CASE_SET_REG(REG, reg)      \
    1.54 +    case REG_ ## REG: regs->reg = value; break
    1.55 +#define CASE_GET_REG(REG, reg)      \
    1.56      case REG_ ## REG: value = regs->reg; break
    1.57  
    1.58 -#define CASE_EXTEND_SET_REG \
    1.59 -      CASE_EXTEND_REG(S)
    1.60 -#define CASE_EXTEND_GET_REG \
    1.61 -      CASE_EXTEND_REG(G)
    1.62 +#define CASE_EXTEND_SET_REG         \
    1.63 +    CASE_EXTEND_REG(S)
    1.64 +#define CASE_EXTEND_GET_REG         \
    1.65 +    CASE_EXTEND_REG(G)
    1.66  
    1.67  #ifdef __i386__
    1.68  #define CASE_EXTEND_REG(T)
    1.69  #else
    1.70 -#define CASE_EXTEND_REG(T)    \
    1.71 -    CASE_ ## T ## ET_REG(R8, r8); \
    1.72 -    CASE_ ## T ## ET_REG(R9, r9); \
    1.73 +#define CASE_EXTEND_REG(T)          \
    1.74 +    CASE_ ## T ## ET_REG(R8, r8);   \
    1.75 +    CASE_ ## T ## ET_REG(R9, r9);   \
    1.76      CASE_ ## T ## ET_REG(R10, r10); \
    1.77      CASE_ ## T ## ET_REG(R11, r11); \
    1.78      CASE_ ## T ## ET_REG(R12, r12); \
    1.79      CASE_ ## T ## ET_REG(R13, r13); \
    1.80      CASE_ ## T ## ET_REG(R14, r14); \
    1.81 -    CASE_ ## T ## ET_REG(R15, r15);
    1.82 +    CASE_ ## T ## ET_REG(R15, r15)
    1.83  #endif
    1.84  
    1.85 -
    1.86  /*
    1.87   * Write to control registers
    1.88   */
    1.89 @@ -1557,31 +1573,28 @@ static int mov_to_cr(int gp, int cr, str
    1.90      unsigned long old_cr;
    1.91      struct vcpu *v = current;
    1.92  
    1.93 -    switch (gp) {
    1.94 -        CASE_GET_REG(EAX, eax);
    1.95 -        CASE_GET_REG(ECX, ecx);
    1.96 -        CASE_GET_REG(EDX, edx);
    1.97 -        CASE_GET_REG(EBX, ebx);
    1.98 -        CASE_GET_REG(EBP, ebp);
    1.99 -        CASE_GET_REG(ESI, esi);
   1.100 -        CASE_GET_REG(EDI, edi);
   1.101 -        CASE_EXTEND_GET_REG
   1.102 -            case REG_ESP:
   1.103 -                __vmread(GUEST_RSP, &value);
   1.104 +    switch ( gp ) {
   1.105 +    CASE_GET_REG(EAX, eax);
   1.106 +    CASE_GET_REG(ECX, ecx);
   1.107 +    CASE_GET_REG(EDX, edx);
   1.108 +    CASE_GET_REG(EBX, ebx);
   1.109 +    CASE_GET_REG(EBP, ebp);
   1.110 +    CASE_GET_REG(ESI, esi);
   1.111 +    CASE_GET_REG(EDI, edi);
   1.112 +    CASE_EXTEND_GET_REG;
   1.113 +    case REG_ESP:
   1.114 +        __vmread(GUEST_RSP, &value);
   1.115          break;
   1.116      default:
   1.117          printk("invalid gp: %d\n", gp);
   1.118          __hvm_bug(regs);
   1.119      }
   1.120  
   1.121 -    HVM_DBG_LOG(DBG_LEVEL_1, "mov_to_cr: CR%d, value = %lx,", cr, value);
   1.122 -    HVM_DBG_LOG(DBG_LEVEL_1, "current = %lx,", (unsigned long) current);
   1.123 +    HVM_DBG_LOG(DBG_LEVEL_1, "CR%d, value = %lx", cr, value);
   1.124  
   1.125 -    switch(cr) {
   1.126 +    switch ( cr ) {
   1.127      case 0:
   1.128 -    {
   1.129          return vmx_set_cr0(value);
   1.130 -    }
   1.131      case 3:
   1.132      {
   1.133          unsigned long old_base_mfn, mfn;
   1.134 @@ -1753,11 +1766,6 @@ static int mov_to_cr(int gp, int cr, str
   1.135      return 1;
   1.136  }
   1.137  
   1.138 -#define CASE_SET_REG(REG, reg)      \
   1.139 -    case REG_ ## REG:       \
   1.140 -    regs->reg = value;      \
   1.141 -    break
   1.142 -
   1.143  /*
   1.144   * Read from control registers. CR0 and CR4 are read from the shadow.
   1.145   */
   1.146 @@ -1766,22 +1774,22 @@ static void mov_from_cr(int cr, int gp, 
   1.147      unsigned long value;
   1.148      struct vcpu *v = current;
   1.149  
   1.150 -    if (cr != 3)
   1.151 +    if ( cr != 3 )
   1.152          __hvm_bug(regs);
   1.153  
   1.154      value = (unsigned long) v->arch.hvm_vmx.cpu_cr3;
   1.155  
   1.156 -    switch (gp) {
   1.157 -        CASE_SET_REG(EAX, eax);
   1.158 -        CASE_SET_REG(ECX, ecx);
   1.159 -        CASE_SET_REG(EDX, edx);
   1.160 -        CASE_SET_REG(EBX, ebx);
   1.161 -        CASE_SET_REG(EBP, ebp);
   1.162 -        CASE_SET_REG(ESI, esi);
   1.163 -        CASE_SET_REG(EDI, edi);
   1.164 -        CASE_EXTEND_SET_REG
   1.165 -            case REG_ESP:
   1.166 -                __vmwrite(GUEST_RSP, value);
   1.167 +    switch ( gp ) {
   1.168 +    CASE_SET_REG(EAX, eax);
   1.169 +    CASE_SET_REG(ECX, ecx);
   1.170 +    CASE_SET_REG(EDX, edx);
   1.171 +    CASE_SET_REG(EBX, ebx);
   1.172 +    CASE_SET_REG(EBP, ebp);
   1.173 +    CASE_SET_REG(ESI, esi);
   1.174 +    CASE_SET_REG(EDI, edi);
   1.175 +    CASE_EXTEND_SET_REG;
   1.176 +    case REG_ESP:
   1.177 +        __vmwrite(GUEST_RSP, value);
   1.178          regs->esp = value;
   1.179          break;
   1.180      default:
   1.181 @@ -1789,7 +1797,7 @@ static void mov_from_cr(int cr, int gp, 
   1.182          __hvm_bug(regs);
   1.183      }
   1.184  
   1.185 -    HVM_DBG_LOG(DBG_LEVEL_VMMU, "mov_from_cr: CR%d, value = %lx,", cr, value);
   1.186 +    HVM_DBG_LOG(DBG_LEVEL_VMMU, "CR%d, value = %lx", cr, value);
   1.187  }
   1.188  
   1.189  static int vmx_cr_access(unsigned long exit_qualification, struct cpu_user_regs *regs)