All of lore.kernel.org
 help / color / mirror / Atom feed
From: Peter Maydell <peter.maydell@linaro.org>
To: qemu-devel@nongnu.org
Cc: "Peter Crosthwaite" <peter.crosthwaite@xilinx.com>,
	patches@linaro.org, "Michael Matz" <matz@suse.de>,
	"Alexander Graf" <agraf@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 v2 14/25] target-arm: A64: Implement MRS/MSR/SYS/SYSL
Date: Sun, 22 Dec 2013 22:49:56 +0000	[thread overview]
Message-ID: <1387752607-23755-15-git-send-email-peter.maydell@linaro.org> (raw)
In-Reply-To: <1387752607-23755-1-git-send-email-peter.maydell@linaro.org>

The AArch64 equivalent of the traditional AArch32
cp15 coprocessor registers is the set of instructions
MRS/MSR/SYS/SYSL, which cover between them both true
system registers and the "operations with side effects"
such as cache maintenance which in AArch32 are mixed
in with other cp15 registers. Implement these instructions
to look in the cpregs hashtable for the register or
operation.

Since we don't yet populate the cpregs hashtable with
any registers with the "AA64" bit set, everything will
still UNDEF at this point.

MSR/MRS is the first user of is_jmp = DISAS_UPDATE, so
fix an infelicity in its handling where the main loop
was requiring the caller to do the update of PC rather
than just doing it itself.

Signed-off-by: Peter Maydell <peter.maydell@linaro.org>
Reviewed-by: Richard Henderson <rth@twiddle.net>
---
 target-arm/translate-a64.c | 112 +++++++++++++++++++++++++++++++++------------
 1 file changed, 82 insertions(+), 30 deletions(-)

diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
index e35d2f3..7a9ee82 100644
--- a/target-arm/translate-a64.c
+++ b/target-arm/translate-a64.c
@@ -733,28 +733,88 @@ static void handle_msr_i(DisasContext *s, uint32_t insn,
     unsupported_encoding(s, insn);
 }
 
-/* C5.6.204 SYS */
-static void handle_sys(DisasContext *s, uint32_t insn, unsigned int l,
-                       unsigned int op1, unsigned int op2,
+/* C5.6.129 MRS - move from system register
+ * C5.6.131 MSR (register) - move to system register
+ * C5.6.204 SYS
+ * C5.6.205 SYSL
+ * These are all essentially the same insn in 'read' and 'write'
+ * versions, with varying op0 fields.
+ */
+static void handle_sys(DisasContext *s, uint32_t insn, bool isread,
+                       unsigned int op0, unsigned int op1, unsigned int op2,
                        unsigned int crn, unsigned int crm, unsigned int rt)
 {
-    unsupported_encoding(s, insn);
-}
+    const ARMCPRegInfo *ri;
+    TCGv_i64 tcg_rt;
 
-/* C5.6.129 MRS - move from system register */
-static void handle_mrs(DisasContext *s, uint32_t insn, unsigned int op0,
-                       unsigned int op1, unsigned int op2,
-                       unsigned int crn, unsigned int crm, unsigned int rt)
-{
-    unsupported_encoding(s, insn);
-}
+    ri = get_arm_cp_reginfo(s->cp_regs,
+                            ENCODE_AA64_CP_REG(CP_REG_ARM64_SYSREG_CP,
+                                               crn, crm, op0, op1, op2));
 
-/* C5.6.131 MSR (register) - move to system register */
-static void handle_msr(DisasContext *s, uint32_t insn, unsigned int op0,
-                       unsigned int op1, unsigned int op2,
-                       unsigned int crn, unsigned int crm, unsigned int rt)
-{
-    unsupported_encoding(s, insn);
+    if (!ri) {
+        /* Unknown register */
+        unallocated_encoding(s);
+        return;
+    }
+
+    /* Check access permissions */
+    if (!cp_access_ok(s->current_pl, ri, isread)) {
+        unallocated_encoding(s);
+        return;
+    }
+
+    /* Handle special cases first */
+    switch (ri->type & ~(ARM_CP_FLAG_MASK & ~ARM_CP_SPECIAL)) {
+    case ARM_CP_NOP:
+        return;
+    default:
+        break;
+    }
+
+    if (use_icount && (ri->type & ARM_CP_IO)) {
+        gen_io_start();
+    }
+
+    tcg_rt = cpu_reg(s, rt);
+
+    if (isread) {
+        if (ri->type & ARM_CP_CONST) {
+            tcg_gen_movi_i64(tcg_rt, ri->resetvalue);
+        } else if (ri->readfn) {
+            TCGv_ptr tmpptr;
+            gen_a64_set_pc_im(s->pc - 4);
+            tmpptr = tcg_const_ptr(ri);
+            gen_helper_get_cp_reg64(tcg_rt, cpu_env, tmpptr);
+            tcg_temp_free_ptr(tmpptr);
+        } else {
+            tcg_gen_ld_i64(tcg_rt, cpu_env, ri->fieldoffset);
+        }
+    } else {
+        if (ri->type & ARM_CP_CONST) {
+            /* If not forbidden by access permissions, treat as WI */
+            return;
+        } else if (ri->writefn) {
+            TCGv_ptr tmpptr;
+            gen_a64_set_pc_im(s->pc - 4);
+            tmpptr = tcg_const_ptr(ri);
+            gen_helper_set_cp_reg64(cpu_env, tmpptr, tcg_rt);
+            tcg_temp_free_ptr(tmpptr);
+        } else {
+            tcg_gen_st_i64(tcg_rt, cpu_env, ri->fieldoffset);
+        }
+    }
+
+    if (use_icount && (ri->type & ARM_CP_IO)) {
+        /* I/O operations must end the TB here (whether read or write) */
+        gen_io_end();
+        s->is_jmp = DISAS_UPDATE;
+    } else if (!isread && !(ri->type & ARM_CP_SUPPRESS_TB_END)) {
+        /* We default to ending the TB on a coprocessor register write,
+         * but allow this to be suppressed by the register definition
+         * (usually only necessary to work around guest bugs).
+         */
+        s->is_jmp = DISAS_UPDATE;
+    }
 }
 
 /* C3.2.4 System
@@ -795,17 +855,7 @@ static void disas_system(DisasContext *s, uint32_t insn)
         }
         return;
     }
-
-    if (op0 == 1) {
-        /* C5.6.204 SYS */
-        handle_sys(s, insn, l, op1, op2, crn, crm, rt);
-    } else if (l) { /* op0 > 1 */
-        /* C5.6.129 MRS - move from system register */
-        handle_mrs(s, insn, op0, op1, op2, crn, crm, rt);
-    } else {
-        /* C5.6.131 MSR (register) - move to system register */
-        handle_msr(s, insn, op0, op1, op2, crn, crm, rt);
-    }
+    handle_sys(s, insn, l, op0, op1, op2, crn, crm, rt);
 }
 
 /* C3.2.3 Exception generation
@@ -3098,8 +3148,10 @@ void gen_intermediate_code_internal_a64(ARMCPU *cpu,
             gen_goto_tb(dc, 1, dc->pc);
             break;
         default:
-        case DISAS_JUMP:
         case DISAS_UPDATE:
+            gen_a64_set_pc_im(dc->pc);
+            /* fall through */
+        case DISAS_JUMP:
             /* indicate that the hash table must be used to find the next TB */
             tcg_gen_exit_tb(0);
             break;
-- 
1.8.5

  parent reply	other threads:[~2013-12-22 22:56 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-12-22 22:49 [Qemu-devel] [PATCH v2 00/25] target-arm: A64 decoder sets 3 and 4: everything but fp & simd Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 01/25] target-arm: A64: add support for ld/st pair Peter Maydell
2013-12-23 19:49   ` Richard Henderson
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 02/25] target-arm: A64: add support for ld/st unsigned imm Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 03/25] target-arm: A64: add support for ld/st with reg offset Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 04/25] target-arm: A64: add support for ld/st with index Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 05/25] target-arm: A64: add support for add, addi, sub, subi Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 06/25] target-arm: A64: add support for move wide instructions Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 07/25] target-arm: A64: add support for 3 src data proc insns Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 08/25] target-arm: A64: implement SVC, BRK Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 09/25] target-arm: A64: Add decoder skeleton for FP instructions Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 10/25] target-arm: A64: implement FMOV Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 11/25] target-arm: Pull "add one cpreg to hashtable" into its own function Peter Maydell
2013-12-23 19:51   ` Richard Henderson
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 12/25] target-arm: Update generic cpreg code for AArch64 Peter Maydell
2014-01-02  1:51   ` Peter Crosthwaite
2014-01-02 10:23     ` Peter Maydell
2014-01-04 19:58     ` Peter Maydell
2014-01-05  2:44       ` Peter Crosthwaite
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 13/25] target-arm: Remove ARMCPU/CPUARMState from cpregs APIs used by decoder Peter Maydell
2013-12-23 20:11   ` Richard Henderson
2013-12-22 22:49 ` Peter Maydell [this message]
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 15/25] target-arm: A64: Implement minimal set of EL0-visible sysregs Peter Maydell
2014-01-04  2:34   ` Peter Crosthwaite
2014-01-04 11:35     ` Peter Maydell
2014-01-04 13:39       ` Peter Crosthwaite
2014-01-04 13:32   ` Peter Crosthwaite
2014-01-04 14:11     ` Peter Maydell
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 16/25] target-arm: Widen thread-local register state fields to 64 bits Peter Maydell
2013-12-23 20:23   ` Richard Henderson
2013-12-22 22:49 ` [Qemu-devel] [PATCH v2 17/25] target-arm: A64: add support for add/sub with carry Peter Maydell
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 18/25] target-arm: A64: add support for conditional compare insns Peter Maydell
2013-12-23 20:37   ` Richard Henderson
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 19/25] target-arm: aarch64: add support for ld lit Peter Maydell
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 20/25] target-arm: Widen exclusive-access support struct fields to 64 bits Peter Maydell
2013-12-23 21:27   ` Richard Henderson
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 21/25] target-arm: A64: support for ld/st/cl exclusive Peter Maydell
2013-12-23 21:34   ` Richard Henderson
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 22/25] linux-user: AArch64: define TARGET_CLONE_BACKWARDS Peter Maydell
2013-12-23 21:41   ` Richard Henderson
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 23/25] linux-user: AArch64: Use correct values for FPSR/FPCR in sigcontext Peter Maydell
2013-12-23 21:43   ` Richard Henderson
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 24/25] .travis.yml: Add aarch64-* targets Peter Maydell
2013-12-22 22:50 ` [Qemu-devel] [PATCH v2 25/25] default-configs: Add config for aarch64-linux-user Peter Maydell

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=1387752607-23755-15-git-send-email-peter.maydell@linaro.org \
    --to=peter.maydell@linaro.org \
    --cc=agraf@suse.de \
    --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=peter.crosthwaite@xilinx.com \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.