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

[Xen-devel] [PATCH 2/3] x86: consolidate frame state manipulation functions



Rather than doing this in multiple places, have a single central
function (decode_register()) to be used by all other code.

Signed-off-by: Jan Beulich <jbeulich@xxxxxxxx>

--- a/xen/arch/x86/hvm/hvm.c
+++ b/xen/arch/x86/hvm/hvm.c
@@ -1585,7 +1585,7 @@ int hvm_mov_to_cr(unsigned int cr, unsig
     struct vcpu *curr = current;
     unsigned long val, *reg;
 
-    if ( (reg = get_x86_gpr(guest_cpu_user_regs(), gpr)) == NULL )
+    if ( (reg = decode_register(gpr, guest_cpu_user_regs(), 0)) == NULL )
     {
         gdprintk(XENLOG_ERR, "invalid gpr: %u\n", gpr);
         goto exit_and_crash;
@@ -1627,7 +1627,7 @@ int hvm_mov_from_cr(unsigned int cr, uns
     struct vcpu *curr = current;
     unsigned long val = 0, *reg;
 
-    if ( (reg = get_x86_gpr(guest_cpu_user_regs(), gpr)) == NULL )
+    if ( (reg = decode_register(gpr, guest_cpu_user_regs(), 0)) == NULL )
     {
         gdprintk(XENLOG_ERR, "invalid gpr: %u\n", gpr);
         goto exit_and_crash;
--- a/xen/arch/x86/hvm/vmx/vvmx.c
+++ b/xen/arch/x86/hvm/vmx/vvmx.c
@@ -223,56 +223,18 @@ void __set_vvmcs(void *vvmcs, u32 vmcs_e
 static unsigned long reg_read(struct cpu_user_regs *regs,
                               enum vmx_regs_enc index)
 {
-    unsigned long value = 0;
+    unsigned long *pval = decode_register(index, regs, 0);
 
-    switch ( index ) {
-    CASE_GET_REG(RAX, eax);
-    CASE_GET_REG(RCX, ecx);
-    CASE_GET_REG(RDX, edx);
-    CASE_GET_REG(RBX, ebx);
-    CASE_GET_REG(RBP, ebp);
-    CASE_GET_REG(RSI, esi);
-    CASE_GET_REG(RDI, edi);
-    CASE_GET_REG(RSP, esp);
-    CASE_GET_REG(R8, r8);
-    CASE_GET_REG(R9, r9);
-    CASE_GET_REG(R10, r10);
-    CASE_GET_REG(R11, r11);
-    CASE_GET_REG(R12, r12);
-    CASE_GET_REG(R13, r13);
-    CASE_GET_REG(R14, r14);
-    CASE_GET_REG(R15, r15);
-    default:
-        break;
-    }
-
-    return value;
+    return *pval;
 }
 
 static void reg_write(struct cpu_user_regs *regs,
                       enum vmx_regs_enc index,
                       unsigned long value)
 {
-    switch ( index ) {
-    CASE_SET_REG(RAX, eax);
-    CASE_SET_REG(RCX, ecx);
-    CASE_SET_REG(RDX, edx);
-    CASE_SET_REG(RBX, ebx);
-    CASE_SET_REG(RBP, ebp);
-    CASE_SET_REG(RSI, esi);
-    CASE_SET_REG(RDI, edi);
-    CASE_SET_REG(RSP, esp);
-    CASE_SET_REG(R8, r8);
-    CASE_SET_REG(R9, r9);
-    CASE_SET_REG(R10, r10);
-    CASE_SET_REG(R11, r11);
-    CASE_SET_REG(R12, r12);
-    CASE_SET_REG(R13, r13);
-    CASE_SET_REG(R14, r14);
-    CASE_SET_REG(R15, r15);
-    default:
-        break;
-    }
+    unsigned long *pval = decode_register(index, regs, 0);
+
+    *pval = value;
 }
 
 static inline u32 __n2_exec_control(struct vcpu *v)
--- a/xen/arch/x86/traps.c
+++ b/xen/arch/x86/traps.c
@@ -367,34 +367,6 @@ void vcpu_show_execution_state(struct vc
     vcpu_unpause(v);
 }
 
-unsigned long *get_x86_gpr(struct cpu_user_regs *regs, unsigned int modrm_reg)
-{
-    void *p;
-
-    switch ( modrm_reg )
-    {
-    case  0: p = &regs->eax; break;
-    case  1: p = &regs->ecx; break;
-    case  2: p = &regs->edx; break;
-    case  3: p = &regs->ebx; break;
-    case  4: p = &regs->esp; break;
-    case  5: p = &regs->ebp; break;
-    case  6: p = &regs->esi; break;
-    case  7: p = &regs->edi; break;
-    case  8: p = &regs->r8;  break;
-    case  9: p = &regs->r9;  break;
-    case 10: p = &regs->r10; break;
-    case 11: p = &regs->r11; break;
-    case 12: p = &regs->r12; break;
-    case 13: p = &regs->r13; break;
-    case 14: p = &regs->r14; break;
-    case 15: p = &regs->r15; break;
-    default: p = NULL; break;
-    }
-
-    return p;
-}
-
 static char *trapstr(int trapnr)
 {
     static char *strings[] = { 
--- a/xen/include/asm-x86/processor.h
+++ b/xen/include/asm-x86/processor.h
@@ -552,8 +552,6 @@ void microcode_set_module(unsigned int);
 int microcode_update(XEN_GUEST_HANDLE(const_void), unsigned long len);
 int microcode_resume_cpu(int cpu);
 
-unsigned long *get_x86_gpr(struct cpu_user_regs *regs, unsigned int modrm_reg);
-
 #endif /* !__ASSEMBLY__ */
 
 #endif /* __ASM_X86_PROCESSOR_H */


Attachment: x86-drop-get_x86_gpr.patch
Description: Text document

_______________________________________________
Xen-devel mailing list
Xen-devel@xxxxxxxxxxxxx
http://lists.xen.org/xen-devel

 


Rackspace

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