Received: from eggs.gnu.org ([2001:4830:134:3::10]:50876) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoEsb-0003sG-1f for qemu-devel@nongnu.org; Mon, 19 Oct 2015 14:09:54 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZoEsX-000526-OX for qemu-devel@nongnu.org; Mon, 19 Oct 2015 14:09:52 -0400 Received: from mail-bn1on0088.outbound.protection.outlook.com ([157.56.110.88]:2880 helo=na01-bn1-obe.outbound.protection.outlook.com) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZoEsX-000521-J2 for qemu-devel@nongnu.org; Mon, 19 Oct 2015 14:09:49 -0400 From: Soren Brinkmann Date: Mon, 19 Oct 2015 11:09:34 -0700 Message-ID: <1445278174-9089-1-git-send-email-soren.brinkmann@xilinx.com> MIME-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Subject: [Qemu-devel] [RFC] target-arm: Add and use symbolic names for register banks List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Peter Maydell Cc: qemu-devel@nongnu.org, Soren Brinkmann Add ARM_BANK_ #defines to index banked registers. Suggested-by: Peter Maydell Signed-off-by: Soren Brinkmann --- This change was suggested by Peter in the submission of "target-arm: Add support for SPSR_(ABT|UND|IRQ|FIQ)", which this patch depends on. I applied this to the banked_(spsr|r13|r14) registers. There seem to be more banked registers (e.g. elr_el), but they might require a different mapping. Thanks, S=C3=B6ren --- target-arm/cpu.h | 10 ++++++++++ target-arm/helper.c | 37 ++++++++++++++++++++++--------------- target-arm/internals.h | 6 +++--- target-arm/kvm32.c | 34 +++++++++++++++++----------------- target-arm/op_helper.c | 8 ++++---- 5 files changed, 56 insertions(+), 39 deletions(-) diff --git a/target-arm/cpu.h b/target-arm/cpu.h index 3daa7f58f92b..6353f8c23bf8 100644 --- a/target-arm/cpu.h +++ b/target-arm/cpu.h @@ -862,6 +862,16 @@ enum arm_cpu_mode { #define ARM_IWMMXT_wCGR2 10 #define ARM_IWMMXT_wCGR3 11 =20 +/* register banks for CPU modes */ +#define ARM_BANK_USRSYS 0 +#define ARM_BANK_SVC 1 +#define ARM_BANK_ABT 2 +#define ARM_BANK_UND 3 +#define ARM_BANK_IRQ 4 +#define ARM_BANK_FIQ 5 +#define ARM_BANK_HYP 6 +#define ARM_BANK_MON 7 + /* If adding a feature bit which corresponds to a Linux ELF * HWCAP bit, remember to update the feature-bit-to-hwcap * mapping in linux-user/elfload.c:get_elf_hwcap(). diff --git a/target-arm/helper.c b/target-arm/helper.c index aba5025403a7..0cb47f7561a5 100644 --- a/target-arm/helper.c +++ b/target-arm/helper.c @@ -3122,7 +3122,8 @@ static const ARMCPRegInfo v8_cp_reginfo[] =3D { { .name =3D "SPSR_EL1", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 0, .crn =3D 4, .crm =3D 0, .opc2 =3D 0, - .access =3D PL1_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[1]) }, + .access =3D PL1_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_SVC]) }, /* We rely on the access checks not allowing the guest to write to the * state field when SPSel indicates that it's being used as the stack * pointer. @@ -3287,23 +3288,28 @@ static const ARMCPRegInfo el2_cp_reginfo[] =3D { { .name =3D "SPSR_EL2", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 4, .crm =3D 0, .opc2 =3D 0, - .access =3D PL2_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[6]) }, + .access =3D PL2_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_HYP]) }, { .name =3D "SPSR_IRQ", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 4, .crm =3D 3, .opc2 =3D 0, - .access =3D PL2_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[4]) }, + .access =3D PL2_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_IRQ]) }, { .name =3D "SPSR_ABT", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 4, .crm =3D 3, .opc2 =3D 1, - .access =3D PL2_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[2]) }, + .access =3D PL2_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_ABT]) }, { .name =3D "SPSR_UND", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 4, .crm =3D 3, .opc2 =3D 2, - .access =3D PL2_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[3]) }, + .access =3D PL2_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_UND]) }, { .name =3D "SPSR_FIQ", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 4, .crm =3D 3, .opc2 =3D 3, - .access =3D PL2_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[5]) }, + .access =3D PL2_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_FIQ]) }, { .name =3D "VBAR_EL2", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 4, .crn =3D 12, .crm =3D 0, .opc2 =3D 0, .access =3D PL2_RW, .writefn =3D vbar_write, @@ -3532,7 +3538,8 @@ static const ARMCPRegInfo el3_cp_reginfo[] =3D { { .name =3D "SPSR_EL3", .state =3D ARM_CP_STATE_AA64, .type =3D ARM_CP_ALIAS, .opc0 =3D 3, .opc1 =3D 6, .crn =3D 4, .crm =3D 0, .opc2 =3D 0, - .access =3D PL3_RW, .fieldoffset =3D offsetof(CPUARMState, banked_sp= sr[7]) }, + .access =3D PL3_RW, + .fieldoffset =3D offsetof(CPUARMState, banked_spsr[ARM_BANK_MON]) }, { .name =3D "VBAR_EL3", .state =3D ARM_CP_STATE_AA64, .opc0 =3D 3, .opc1 =3D 6, .crn =3D 12, .crm =3D 0, .opc2 =3D 0, .access =3D PL3_RW, .writefn =3D vbar_write, @@ -5163,21 +5170,21 @@ int bank_number(int mode) switch (mode) { case ARM_CPU_MODE_USR: case ARM_CPU_MODE_SYS: - return 0; + return ARM_BANK_USRSYS; case ARM_CPU_MODE_SVC: - return 1; + return ARM_BANK_SVC; case ARM_CPU_MODE_ABT: - return 2; + return ARM_BANK_ABT; case ARM_CPU_MODE_UND: - return 3; + return ARM_BANK_UND; case ARM_CPU_MODE_IRQ: - return 4; + return ARM_BANK_IRQ; case ARM_CPU_MODE_FIQ: - return 5; + return ARM_BANK_FIQ; case ARM_CPU_MODE_HYP: - return 6; + return ARM_BANK_HYP; case ARM_CPU_MODE_MON: - return 7; + return ARM_BANK_MON; } g_assert_not_reached(); } diff --git a/target-arm/internals.h b/target-arm/internals.h index 36a56aadb0b5..c2cf9dc36e1b 100644 --- a/target-arm/internals.h +++ b/target-arm/internals.h @@ -91,9 +91,9 @@ static inline void arm_log_exception(int idx) static inline unsigned int aarch64_banked_spsr_index(unsigned int el) { static const unsigned int map[4] =3D { - [1] =3D 1, /* EL1. */ - [2] =3D 6, /* EL2. */ - [3] =3D 7, /* EL3. */ + [1] =3D ARM_BANK_SVC, /* EL1. */ + [2] =3D ARM_BANK_HYP, /* EL2. */ + [3] =3D ARM_BANK_MON, /* EL3. */ }; assert(el >=3D 1 && el <=3D 3); return map[el]; diff --git a/target-arm/kvm32.c b/target-arm/kvm32.c index 3ae57a6d68db..85b478a60ce4 100644 --- a/target-arm/kvm32.c +++ b/target-arm/kvm32.c @@ -280,30 +280,30 @@ static const Reg regs[] =3D { COREREG(usr_regs.uregs[10], usr_regs[2]), COREREG(usr_regs.uregs[11], usr_regs[3]), COREREG(usr_regs.uregs[12], usr_regs[4]), - COREREG(usr_regs.uregs[13], banked_r13[0]), - COREREG(usr_regs.uregs[14], banked_r14[0]), + COREREG(usr_regs.uregs[13], banked_r13[ARM_BANK_USRSYS]), + COREREG(usr_regs.uregs[14], banked_r14[ARM_BANK_USRSYS]), /* R13, R14, SPSR for SVC, ABT, UND, IRQ banks */ - COREREG(svc_regs[0], banked_r13[1]), - COREREG(svc_regs[1], banked_r14[1]), - COREREG64(svc_regs[2], banked_spsr[1]), - COREREG(abt_regs[0], banked_r13[2]), - COREREG(abt_regs[1], banked_r14[2]), - COREREG64(abt_regs[2], banked_spsr[2]), - COREREG(und_regs[0], banked_r13[3]), - COREREG(und_regs[1], banked_r14[3]), - COREREG64(und_regs[2], banked_spsr[3]), - COREREG(irq_regs[0], banked_r13[4]), - COREREG(irq_regs[1], banked_r14[4]), - COREREG64(irq_regs[2], banked_spsr[4]), + COREREG(svc_regs[0], banked_r13[ARM_BANK_SVC]), + COREREG(svc_regs[1], banked_r14[ARM_BANK_SVC]), + COREREG64(svc_regs[2], banked_spsr[ARM_BANK_SVC]), + COREREG(abt_regs[0], banked_r13[ARM_BANK_ABT]), + COREREG(abt_regs[1], banked_r14[ARM_BANK_ABT]), + COREREG64(abt_regs[2], banked_spsr[ARM_BANK_ABT]), + COREREG(und_regs[0], banked_r13[ARM_BANK_UND]), + COREREG(und_regs[1], banked_r14[ARM_BANK_UND]), + COREREG64(und_regs[2], banked_spsr[ARM_BANK_UND]), + COREREG(irq_regs[0], banked_r13[ARM_BANK_IRQ]), + COREREG(irq_regs[1], banked_r14[ARM_BANK_IRQ]), + COREREG64(irq_regs[2], banked_spsr[ARM_BANK_IRQ]), /* R8_fiq .. R14_fiq and SPSR_fiq */ COREREG(fiq_regs[0], fiq_regs[0]), COREREG(fiq_regs[1], fiq_regs[1]), COREREG(fiq_regs[2], fiq_regs[2]), COREREG(fiq_regs[3], fiq_regs[3]), COREREG(fiq_regs[4], fiq_regs[4]), - COREREG(fiq_regs[5], banked_r13[5]), - COREREG(fiq_regs[6], banked_r14[5]), - COREREG64(fiq_regs[7], banked_spsr[5]), + COREREG(fiq_regs[5], banked_r13[ARM_BANK_FIQ]), + COREREG(fiq_regs[6], banked_r14[ARM_BANK_FIQ]), + COREREG64(fiq_regs[7], banked_spsr[ARM_BANK_FIQ]), /* R15 */ COREREG(usr_regs.uregs[15], regs[15]), /* VFP system registers */ diff --git a/target-arm/op_helper.c b/target-arm/op_helper.c index 7929c71b43bf..c43e6c66212f 100644 --- a/target-arm/op_helper.c +++ b/target-arm/op_helper.c @@ -384,9 +384,9 @@ uint32_t HELPER(get_user_reg)(CPUARMState *env, uint32_= t regno) uint32_t val; =20 if (regno =3D=3D 13) { - val =3D env->banked_r13[0]; + val =3D env->banked_r13[ARM_BANK_USRSYS]; } else if (regno =3D=3D 14) { - val =3D env->banked_r14[0]; + val =3D env->banked_r14[ARM_BANK_USRSYS]; } else if (regno >=3D 8 && (env->uncached_cpsr & 0x1f) =3D=3D ARM_CPU_MODE_FIQ) { val =3D env->usr_regs[regno - 8]; @@ -399,9 +399,9 @@ uint32_t HELPER(get_user_reg)(CPUARMState *env, uint32_= t regno) void HELPER(set_user_reg)(CPUARMState *env, uint32_t regno, uint32_t val) { if (regno =3D=3D 13) { - env->banked_r13[0] =3D val; + env->banked_r13[ARM_BANK_USRSYS] =3D val; } else if (regno =3D=3D 14) { - env->banked_r14[0] =3D val; + env->banked_r14[ARM_BANK_USRSYS] =3D val; } else if (regno >=3D 8 && (env->uncached_cpsr & 0x1f) =3D=3D ARM_CPU_MODE_FIQ) { env->usr_regs[regno - 8] =3D val; --=20 2.6.2.3.ga463a5b