From: "Jan Beulich" Subject: [PATCH 2/3] x86: consolidate frame state manipulation functions Date: Tue, 02 Oct 2012 16:26:55 +0100 Message-ID: <506B23DF020000780009F29E@nat28.tlf.novell.com> References: <506B2268020000780009F273@nat28.tlf.novell.com> Mime-Version: 1.0 Content-Type: multipart/mixed; boundary="=__PartFBCACDAF.0__=" Return-path: In-Reply-To: <506B2268020000780009F273@nat28.tlf.novell.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: xen-devel , Jan Beulich List-Id: xen-devel@lists.xenproject.org This is a MIME message. If you are reading this text, you may want to consider changing to a mail reader or gateway that understands how to properly handle MIME multipart messages. --=__PartFBCACDAF.0__= Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: quoted-printable Content-Disposition: inline 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 --- 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 =3D current; unsigned long val, *reg; =20 - if ( (reg =3D get_x86_gpr(guest_cpu_user_regs(), gpr)) =3D=3D NULL ) + if ( (reg =3D decode_register(gpr, guest_cpu_user_regs(), 0)) =3D=3D = 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 =3D current; unsigned long val =3D 0, *reg; =20 - if ( (reg =3D get_x86_gpr(guest_cpu_user_regs(), gpr)) =3D=3D NULL ) + if ( (reg =3D decode_register(gpr, guest_cpu_user_regs(), 0)) =3D=3D = 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 =3D 0; + unsigned long *pval =3D decode_register(index, regs, 0); =20 - 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; } =20 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 =3D decode_register(index, regs, 0); + + *pval =3D value; } =20 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); } =20 -unsigned long *get_x86_gpr(struct cpu_user_regs *regs, unsigned int = modrm_reg) -{ - void *p; - - switch ( modrm_reg ) - { - case 0: p =3D ®s->eax; break; - case 1: p =3D ®s->ecx; break; - case 2: p =3D ®s->edx; break; - case 3: p =3D ®s->ebx; break; - case 4: p =3D ®s->esp; break; - case 5: p =3D ®s->ebp; break; - case 6: p =3D ®s->esi; break; - case 7: p =3D ®s->edi; break; - case 8: p =3D ®s->r8; break; - case 9: p =3D ®s->r9; break; - case 10: p =3D ®s->r10; break; - case 11: p =3D ®s->r11; break; - case 12: p =3D ®s->r12; break; - case 13: p =3D ®s->r13; break; - case 14: p =3D ®s->r14; break; - case 15: p =3D ®s->r15; break; - default: p =3D NULL; break; - } - - return p; -} - static char *trapstr(int trapnr) { static char *strings[] =3D {=20 --- 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); =20 -unsigned long *get_x86_gpr(struct cpu_user_regs *regs, unsigned int = modrm_reg); - #endif /* !__ASSEMBLY__ */ =20 #endif /* __ASM_X86_PROCESSOR_H */ --=__PartFBCACDAF.0__= Content-Type: text/plain; name="x86-drop-get_x86_gpr.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="x86-drop-get_x86_gpr.patch" x86: consolidate frame state manipulation functions=0A=0ARather than doing = this in multiple places, have a single central=0Afunction (decode_register(= )) to be used by all other code.=0A=0ASigned-off-by: Jan Beulich =0A=0A--- a/xen/arch/x86/hvm/hvm.c=0A+++ b/xen/arch/x86/hvm/hvm.c= =0A@@ -1585,7 +1585,7 @@ int hvm_mov_to_cr(unsigned int cr, unsig=0A = struct vcpu *curr =3D current;=0A unsigned long val, *reg;=0A =0A- = if ( (reg =3D get_x86_gpr(guest_cpu_user_regs(), gpr)) =3D=3D NULL )=0A+ = if ( (reg =3D decode_register(gpr, guest_cpu_user_regs(), 0)) =3D=3D NULL = )=0A {=0A gdprintk(XENLOG_ERR, "invalid gpr: %u\n", gpr);=0A = goto exit_and_crash;=0A@@ -1627,7 +1627,7 @@ int hvm_mov_from_cr(unsi= gned int cr, uns=0A struct vcpu *curr =3D current;=0A unsigned = long val =3D 0, *reg;=0A =0A- if ( (reg =3D get_x86_gpr(guest_cpu_user_r= egs(), gpr)) =3D=3D NULL )=0A+ if ( (reg =3D decode_register(gpr, = guest_cpu_user_regs(), 0)) =3D=3D NULL )=0A {=0A gdprintk(XENLO= G_ERR, "invalid gpr: %u\n", gpr);=0A goto exit_and_crash;=0A--- = a/xen/arch/x86/hvm/vmx/vvmx.c=0A+++ b/xen/arch/x86/hvm/vmx/vvmx.c=0A@@ = -223,56 +223,18 @@ void __set_vvmcs(void *vvmcs, u32 vmcs_e=0A static = unsigned long reg_read(struct cpu_user_regs *regs,=0A = enum vmx_regs_enc index)=0A {=0A- unsigned long value =3D = 0;=0A+ unsigned long *pval =3D decode_register(index, regs, 0);=0A =0A- = switch ( index ) {=0A- CASE_GET_REG(RAX, eax);=0A- CASE_GET_REG(RC= X, ecx);=0A- CASE_GET_REG(RDX, edx);=0A- CASE_GET_REG(RBX, ebx);=0A- = CASE_GET_REG(RBP, ebp);=0A- CASE_GET_REG(RSI, esi);=0A- CASE_GET_R= EG(RDI, edi);=0A- CASE_GET_REG(RSP, esp);=0A- CASE_GET_REG(R8, = r8);=0A- CASE_GET_REG(R9, r9);=0A- CASE_GET_REG(R10, r10);=0A- = CASE_GET_REG(R11, r11);=0A- CASE_GET_REG(R12, r12);=0A- CASE_GET_REG(= R13, r13);=0A- CASE_GET_REG(R14, r14);=0A- CASE_GET_REG(R15, = r15);=0A- default:=0A- break;=0A- }=0A-=0A- return = value;=0A+ return *pval;=0A }=0A =0A static void reg_write(struct = cpu_user_regs *regs,=0A enum vmx_regs_enc index,=0A = unsigned long value)=0A {=0A- switch ( index ) = {=0A- CASE_SET_REG(RAX, eax);=0A- CASE_SET_REG(RCX, ecx);=0A- = CASE_SET_REG(RDX, edx);=0A- CASE_SET_REG(RBX, ebx);=0A- CASE_SET_REG(= RBP, ebp);=0A- CASE_SET_REG(RSI, esi);=0A- CASE_SET_REG(RDI, = edi);=0A- CASE_SET_REG(RSP, esp);=0A- CASE_SET_REG(R8, r8);=0A- = CASE_SET_REG(R9, r9);=0A- CASE_SET_REG(R10, r10);=0A- CASE_SET_REG(R1= 1, r11);=0A- CASE_SET_REG(R12, r12);=0A- CASE_SET_REG(R13, r13);=0A- = CASE_SET_REG(R14, r14);=0A- CASE_SET_REG(R15, r15);=0A- = default:=0A- break;=0A- }=0A+ unsigned long *pval =3D = decode_register(index, regs, 0);=0A+=0A+ *pval =3D value;=0A }=0A =0A = static inline u32 __n2_exec_control(struct vcpu *v)=0A--- a/xen/arch/x86/tr= aps.c=0A+++ b/xen/arch/x86/traps.c=0A@@ -367,34 +367,6 @@ void vcpu_show_ex= ecution_state(struct vc=0A vcpu_unpause(v);=0A }=0A =0A-unsigned long = *get_x86_gpr(struct cpu_user_regs *regs, unsigned int modrm_reg)=0A-{=0A- = void *p;=0A-=0A- switch ( modrm_reg )=0A- {=0A- case 0: p =3D = ®s->eax; break;=0A- case 1: p =3D ®s->ecx; break;=0A- case = 2: p =3D ®s->edx; break;=0A- case 3: p =3D ®s->ebx; break;=0A- = case 4: p =3D ®s->esp; break;=0A- case 5: p =3D ®s->ebp; = break;=0A- case 6: p =3D ®s->esi; break;=0A- case 7: p =3D = ®s->edi; break;=0A- case 8: p =3D ®s->r8; break;=0A- case = 9: p =3D ®s->r9; break;=0A- case 10: p =3D ®s->r10; break;=0A- = case 11: p =3D ®s->r11; break;=0A- case 12: p =3D ®s->r12; = break;=0A- case 13: p =3D ®s->r13; break;=0A- case 14: p =3D = ®s->r14; break;=0A- case 15: p =3D ®s->r15; break;=0A- = default: p =3D NULL; break;=0A- }=0A-=0A- return p;=0A-}=0A-=0A = static char *trapstr(int trapnr)=0A {=0A static char *strings[] =3D { = =0A--- a/xen/include/asm-x86/processor.h=0A+++ b/xen/include/asm-x86/proces= sor.h=0A@@ -552,8 +552,6 @@ void microcode_set_module(unsigned int);=0A = int microcode_update(XEN_GUEST_HANDLE(const_void), unsigned long len);=0A = int microcode_resume_cpu(int cpu);=0A =0A-unsigned long *get_x86_gpr(struct= cpu_user_regs *regs, unsigned int modrm_reg);=0A-=0A #endif /* !__ASSEMBLY= __ */=0A =0A #endif /* __ASM_X86_PROCESSOR_H */=0A --=__PartFBCACDAF.0__= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Disposition: inline _______________________________________________ Xen-devel mailing list Xen-devel@lists.xen.org http://lists.xen.org/xen-devel --=__PartFBCACDAF.0__=--