qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: patches@linaro.org, "Michael Matz" <matz@suse.de>,
	"Claudio Fontana" <claudio.fontana@linaro.org>,
	"Dirk Mueller" <dmueller@suse.de>,
	"Will Newton" <will.newton@linaro.org>,
	"Laurent Desnogues" <laurent.desnogues@gmail.com>,
	"Alex Bennée" <alex.bennee@linaro.org>,
	kvmarm@lists.cs.columbia.edu,
	"Christoffer Dall" <christoffer.dall@linaro.org>,
	"Richard Henderson" <rth@twiddle.net>
Subject: [Qemu-devel] [PATCH 15/21] target-arm: Widen thread-local register state fields to 64 bits
Date: Tue, 17 Dec 2013 15:12:18 +0000	[thread overview]
Message-ID: <1387293144-11554-16-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1387293144-11554-1-git-send-email-peter.maydell@linaro.org>

The common pattern for system registers in a 64-bit capable ARM
CPU is that when in AArch32 the cp15 register is a view of the
bottom 32 bits of the 64-bit AArch64 system register; writes in
AArch32 leave the top half unchanged. The most natural way to
model this is to have the state field in the CPU struct be a
64 bit value, and simply have the AArch32 TCG code operate on
a pointer to its lower half.

For aarch64-linux-user the only registers we need to share like
this are the thread-local-storage ones. Widen their fields to
64 bits and provide the 64 bit reginfo struct to make them
visible in AArch64 state.

Since we're touching almost every line in QEMU that uses the
c13_tls* fields in this patch anyway, we take the opportunity
to rename them in line with the standard ARM architectural names
for these registers.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
---
 linux-user/aarch64/target_cpu.h |  5 ++++-
 linux-user/arm/target_cpu.h     |  2 +-
 linux-user/main.c               |  2 +-
 target-arm/cpu.h                | 18 +++++++++++++++---
 target-arm/helper.c             | 15 ++++++++++++---
 5 files changed, 33 insertions(+), 9 deletions(-)

diff --git a/linux-user/aarch64/target_cpu.h b/linux-user/aarch64/target_cpu.h
index 6f5539b..21560ef 100644
--- a/linux-user/aarch64/target_cpu.h
+++ b/linux-user/aarch64/target_cpu.h
@@ -29,7 +29,10 @@ static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
 
 static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
 {
-    env->sr.tpidr_el0 = newtls;
+    /* Note that AArch64 Linux keeps the TLS pointer in TPIDR; this is
+     * different from AArch32 Linux, which uses TPIDRRO.
+     */
+    env->cp15.tpidr_el0 = newtls;
 }
 
 #endif
diff --git a/linux-user/arm/target_cpu.h b/linux-user/arm/target_cpu.h
index ed323c0..39d65b6 100644
--- a/linux-user/arm/target_cpu.h
+++ b/linux-user/arm/target_cpu.h
@@ -29,7 +29,7 @@ static inline void cpu_clone_regs(CPUARMState *env, target_ulong newsp)
 
 static inline void cpu_set_tls(CPUARMState *env, target_ulong newtls)
 {
-    env->cp15.c13_tls2 = newtls;
+    env->cp15.tpidrro_el0 = newtls;
 }
 
 #endif
diff --git a/linux-user/main.c b/linux-user/main.c
index 54f71fe..c0df8b5 100644
--- a/linux-user/main.c
+++ b/linux-user/main.c
@@ -566,7 +566,7 @@ do_kernel_trap(CPUARMState *env)
         end_exclusive();
         break;
     case 0xffff0fe0: /* __kernel_get_tls */
-        env->regs[0] = env->cp15.c13_tls2;
+        env->regs[0] = env->cp15.tpidrro_el0;
         break;
     case 0xffff0f60: /* __kernel_cmpxchg64 */
         arm_kernel_cmpxchg64_helper(env);
diff --git a/target-arm/cpu.h b/target-arm/cpu.h
index 32387b0..81c0b1c 100644
--- a/target-arm/cpu.h
+++ b/target-arm/cpu.h
@@ -66,6 +66,18 @@
 /* ARM-specific interrupt pending bits.  */
 #define CPU_INTERRUPT_FIQ   CPU_INTERRUPT_TGT_EXT_1
 
+/* The usual mapping for an AArch64 system register to its AArch32
+ * counterpart is for the 32 bit world to have access to the lower
+ * half only (with writes leaving the upper half untouched). It's
+ * therefore useful to be able to pass TCG the offset of the least
+ * significant half of a uint64_t struct member.
+ */
+#ifdef HOST_WORDS_BIGENDIAN
+#define offsetoflow32(S, M) (offsetof(S, M + sizeof(uint32_t))
+#else
+#define offsetoflow32(S, M) offsetof(S, M)
+#endif
+
 /* Meanings of the ARMCPU object's two inbound GPIO lines */
 #define ARM_CPU_IRQ 0
 #define ARM_CPU_FIQ 1
@@ -188,9 +200,9 @@ typedef struct CPUARMState {
         uint32_t c12_vbar; /* vector base address register */
         uint32_t c13_fcse; /* FCSE PID.  */
         uint32_t c13_context; /* Context ID.  */
-        uint32_t c13_tls1; /* User RW Thread register.  */
-        uint32_t c13_tls2; /* User RO Thread register.  */
-        uint32_t c13_tls3; /* Privileged Thread register.  */
+        uint64_t tpidr_el0; /* User RW Thread register.  */
+        uint64_t tpidrro_el0; /* User RO Thread register.  */
+        uint64_t tpidr_el1; /* Privileged Thread register.  */
         uint32_t c14_cntfrq; /* Counter Frequency register */
         uint32_t c14_cntkctl; /* Timer Control register */
         ARMGenericTimer c14_timer[NUM_GTIMERS];
diff --git a/target-arm/helper.c b/target-arm/helper.c
index c64f618..0754058 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -742,15 +742,15 @@ static const ARMCPRegInfo t2ee_cp_reginfo[] = {
 static const ARMCPRegInfo v6k_cp_reginfo[] = {
     { .name = "TPIDRURW", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 2,
       .access = PL0_RW,
-      .fieldoffset = offsetof(CPUARMState, cp15.c13_tls1),
+      .fieldoffset = offsetoflow32(CPUARMState, cp15.tpidr_el0),
       .resetvalue = 0 },
     { .name = "TPIDRURO", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 3,
       .access = PL0_R|PL1_W,
-      .fieldoffset = offsetof(CPUARMState, cp15.c13_tls2),
+      .fieldoffset = offsetoflow32(CPUARMState, cp15.tpidrro_el0),
       .resetvalue = 0 },
     { .name = "TPIDRPRW", .cp = 15, .crn = 13, .crm = 0, .opc1 = 0, .opc2 = 4,
       .access = PL1_RW,
-      .fieldoffset = offsetof(CPUARMState, cp15.c13_tls3),
+      .fieldoffset = offsetoflow32(CPUARMState, cp15.tpidr_el1),
       .resetvalue = 0 },
     REGINFO_SENTINEL
 };
@@ -1612,6 +1612,15 @@ static const ARMCPRegInfo aarch64_cp_reginfo[] = {
     { .name = "DCZID_EL0", .opc0 = 3, .opc1 = 3, .opc2 = 7, .crn = 0, .crm = 0,
       .access = PL0_R, .type = ARM_CP_CONST | ARM_CP_AA64,
       .resetvalue = 0x10 },
+    { .name = "TPIDR_EL0", .opc0 = 3, .opc1 = 3, .opc2 = 2, .crn = 13, .crm = 0,
+      .access = PL0_RW, .type = ARM_CP_AA64,
+      .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el0), .resetvalue = 0 },
+    { .name = "TPIDRRO_EL0", .opc0 = 3, .opc1 = 3, .opc2 = 3,
+      .crn = 13, .crm = 0, .access = PL0_R|PL1_W, .type = ARM_CP_AA64,
+      .fieldoffset = offsetof(CPUARMState, cp15.tpidrro_el0), .resetvalue = 0 },
+    { .name = "TPIDR_EL1", .opc0 = 3, .opc1 = 0, .opc2 = 4, .crn = 13, .crm = 0,
+      .access = PL1_RW, .type = ARM_CP_AA64,
+      .fieldoffset = offsetof(CPUARMState, cp15.tpidr_el1), .resetvalue = 0 },
     REGINFO_SENTINEL
 };
 
-- 
1.8.5

  parent reply	other threads:[~2013-12-17 15:27 UTC|newest]

Thread overview: 70+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-17 15:12 [Qemu-devel] [PATCH 00/21] target-arm: A64 decoder sets 3 and 4: everything but fp & simd Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 01/21] target-arm: A64: add support for ld/st pair Peter Maydell
2013-12-19 16:58   ` Richard Henderson
2013-12-19 17:25     ` Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 02/21] target-arm: A64: add support for ld/st unsigned imm Peter Maydell
2013-12-19 17:46   ` Richard Henderson
2013-12-20 16:08     ` Peter Maydell
2013-12-20 16:26       ` Richard Henderson
2013-12-20 16:29         ` Peter Maydell
2013-12-20 16:44           ` Richard Henderson
2013-12-20 16:52             ` Peter Maydell
2013-12-20 16:57               ` Richard Henderson
2013-12-20 17:16                 ` Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 03/21] target-arm: A64: add support for ld/st with reg offset Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 04/21] target-arm: A64: add support for ld/st with index Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 05/21] target-arm: A64: add support for add, addi, sub, subi Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 06/21] target-arm: A64: add support for move wide instructions Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 07/21] target-arm: A64: add support for 3 src data proc insns Peter Maydell
2013-12-19 19:29   ` Richard Henderson
2013-12-20 13:18     ` Peter Maydell
2013-12-20 14:10       ` Richard Henderson
2013-12-20 14:19         ` Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 08/21] target-arm: A64: implement SVC, BRK Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 09/21] target-arm: A64: Add decoder skeleton for FP instructions Peter Maydell
2013-12-19 20:00   ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 10/21] target-arm: A64: implement FMOV Peter Maydell
2013-12-19 20:18   ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 11/21] target-arm: Update generic cpreg code for AArch64 Peter Maydell
2013-12-19  6:01   ` Peter Crosthwaite
2013-12-19  9:11     ` Peter Maydell
2013-12-20  4:24       ` Peter Crosthwaite
2013-12-20 10:00         ` Peter Maydell
2013-12-20 18:16           ` Peter Maydell
2013-12-20 21:41             ` Peter Crosthwaite
2013-12-20 22:07               ` Peter Maydell
2013-12-20 22:16                 ` Peter Maydell
2013-12-22 19:50                   ` Peter Maydell
2013-12-20 22:29                 ` Peter Crosthwaite
2013-12-20 23:04                   ` Peter Maydell
2013-12-20 17:41         ` Peter Maydell
2013-12-20  4:25   ` Peter Crosthwaite
2013-12-20 16:43   ` Peter Maydell
2013-12-20 18:53     ` Christoffer Dall
2013-12-17 15:12 ` [Qemu-devel] [PATCH 12/21] target-arm: Remove ARMCPU/CPUARMState from cpregs APIs used by decoder Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 13/21] target-arm: A64: Implement MRS/MSR/SYS/SYSL Peter Maydell
2013-12-19 20:30   ` Richard Henderson
2013-12-20 13:27     ` Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 14/21] target-arm: A64: Implement minimal set of EL0-visible sysregs Peter Maydell
2013-12-19 20:35   ` Richard Henderson
2013-12-21 22:56   ` Peter Maydell
2013-12-17 15:12 ` Peter Maydell [this message]
2013-12-19 20:53   ` [Qemu-devel] [PATCH 15/21] target-arm: Widen thread-local register state fields to 64 bits Richard Henderson
2013-12-19 21:04     ` Peter Maydell
2013-12-19 21:09       ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 16/21] target-arm: A64: add support for add/sub with carry Peter Maydell
2013-12-19 20:57   ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 17/21] target-arm: A64: add support for conditional compare insns Peter Maydell
2013-12-19 21:04   ` Richard Henderson
2013-12-19 21:23     ` Peter Maydell
2013-12-19 21:26       ` Richard Henderson
2013-12-19 21:31         ` Peter Maydell
2013-12-20 16:19     ` Peter Maydell
2013-12-20 16:22       ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 18/21] target-arm: aarch64: add support for ld lit Peter Maydell
2013-12-19 21:07   ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 19/21] target-arm: Widen exclusive-access support struct fields to 64 bits Peter Maydell
2013-12-17 15:12 ` [Qemu-devel] [PATCH 20/21] target-arm: A64: support for ld/st/cl exclusive Peter Maydell
2013-12-19 21:15   ` Richard Henderson
2013-12-17 15:12 ` [Qemu-devel] [PATCH 21/21] default-configs: Add config for aarch64-linux-user Peter Maydell
2013-12-19 21:15   ` Richard Henderson

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1387293144-11554-16-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=alex.bennee@linaro.org \
    --cc=christoffer.dall@linaro.org \
    --cc=claudio.fontana@linaro.org \
    --cc=dmueller@suse.de \
    --cc=kvmarm@lists.cs.columbia.edu \
    --cc=laurent.desnogues@gmail.com \
    --cc=matz@suse.de \
    --cc=patches@linaro.org \
    --cc=qemu-devel@nongnu.org \
    --cc=rth@twiddle.net \
    --cc=will.newton@linaro.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).