From: John Rigby <john.rigby@linaro.org>
To: qemu-devel@nongnu.org
Cc: 'Peter Maydell <peter.maydell@linaro.org>,
John Rigby <john.rigby@linaro.org>,
'Alexander Graf <agraf@suse.de>,
Paul Brook <paul@codesourcery.com>
Subject: [Qemu-devel] [PATCH v4 04/12] ARM: Add AArch64 translation stub
Date: Mon, 13 May 2013 22:32:52 -0600 [thread overview]
Message-ID: <1368505980-17151-5-git-send-email-john.rigby@linaro.org> (raw)
In-Reply-To: <1368505980-17151-1-git-send-email-john.rigby@linaro.org>
From: Alexander Graf <agraf@suse.de>
We should translate AArch64 mode separately from AArch32 mode. In AArch64 mode,
registers look vastly different, instruction encoding is completely different,
basically the system turns into a different machine.
So let's do a simple if() in translate.c to decide whether we can handle the
current code in the legacy AArch32 code or in the new AArch64 code.
So far, the translation always complains about unallocated instructions. There
is no emulator functionality in this patch!
Signed-off-by: Alexander Graf <agraf@suse.de>
Signed-off-by: John Rigby <john.rigby@linaro.org>
---
Changes in v2:
- Remove uses of is_a64 that are not needed because arch choice happens at
a higher level.
- aarch64 register arrays now only have 31 entries with sp and xzr treated as
special cases.
Changes in v3:
- Register arrays back to 32 entries with sp as register 31.
- Fix some checkpatch.pl issues
target-arm/Makefile.objs | 1 +
target-arm/translate-a64.c | 137 +++++++++++++++++++++++++++++++++++++++++++++
target-arm/translate.c | 9 +++
target-arm/translate.h | 6 ++
4 files changed, 153 insertions(+)
create mode 100644 target-arm/translate-a64.c
diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs
index d89b57c..e488edb 100644
--- a/target-arm/Makefile.objs
+++ b/target-arm/Makefile.objs
@@ -3,3 +3,4 @@ obj-$(CONFIG_SOFTMMU) += machine.o
obj-$(CONFIG_KVM) += kvm.o
obj-y += translate.o op_helper.o helper.o cpu.o
obj-y += neon_helper.o iwmmxt_helper.o
+obj-$(TARGET_AARCH64) += translate-a64.o
diff --git a/target-arm/translate-a64.c b/target-arm/translate-a64.c
new file mode 100644
index 0000000..29e8937
--- /dev/null
+++ b/target-arm/translate-a64.c
@@ -0,0 +1,137 @@
+/*
+ * AArch64 translation
+ *
+ * Copyright (c) 2013 Alexander Graf <agraf@suse.de>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include <stdarg.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <inttypes.h>
+
+#include "cpu.h"
+#include "tcg-op.h"
+#include "qemu/log.h"
+#include "translate.h"
+#include "qemu/host-utils.h"
+
+#include "helper.h"
+#define GEN_HELPER 1
+#include "helper.h"
+
+static TCGv_i64 cpu_X[32];
+static TCGv_i64 cpu_pc;
+static TCGv_i32 pstate;
+
+static const char *regnames[] = {
+ "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7",
+ "x8", "x9", "x10", "x11", "x12", "x13", "x14", "x15",
+ "x16", "x17", "x18", "x19", "x20", "x21", "x22", "x23",
+ "x24", "x25", "x26", "x27", "x28", "x29", "lr", "sp"
+};
+
+/* initialize TCG globals. */
+void a64_translate_init(void)
+{
+ int i;
+
+ cpu_pc = tcg_global_mem_new_i64(TCG_AREG0,
+ offsetof(CPUARMState, pc),
+ "pc");
+ for (i = 0; i < 32; i++) {
+ cpu_X[i] = tcg_global_mem_new_i64(TCG_AREG0,
+ offsetof(CPUARMState, xregs[i]),
+ regnames[i]);
+ }
+
+ pstate = tcg_global_mem_new_i32(TCG_AREG0,
+ offsetof(CPUARMState, pstate),
+ "pstate");
+}
+
+void cpu_dump_state_a64(CPUARMState *env, FILE *f, fprintf_function cpu_fprintf,
+ int flags)
+{
+ int i;
+
+ cpu_fprintf(f, "PC=%016"PRIx64" SP=%016"PRIx64"\n",
+ env->pc, env->xregs[31]);
+ for (i = 0; i < 31; i++) {
+ cpu_fprintf(f, "X%02d=%016"PRIx64, i, env->xregs[i]);
+ if ((i % 4) == 3) {
+ cpu_fprintf(f, "\n");
+ } else {
+ cpu_fprintf(f, " ");
+ }
+ }
+ cpu_fprintf(f, "PSTATE=%c%c%c%c\n",
+ env->pstate & PSTATE_N ? 'n' : '.',
+ env->pstate & PSTATE_Z ? 'z' : '.',
+ env->pstate & PSTATE_C ? 'c' : '.',
+ env->pstate & PSTATE_V ? 'v' : '.');
+ cpu_fprintf(f, "\n");
+}
+
+void gen_a64_set_pc_im(uint64_t val)
+{
+ tcg_gen_movi_i64(cpu_pc, val);
+}
+
+static void gen_exception(int excp)
+{
+ TCGv_i32 tmp = tcg_temp_new_i32();
+ tcg_gen_movi_i32(tmp, excp);
+ gen_helper_exception(cpu_env, tmp);
+ tcg_temp_free_i32(tmp);
+}
+
+static void gen_exception_insn(DisasContext *s, int offset, int excp)
+{
+ gen_a64_set_pc_im(s->pc - offset);
+ gen_exception(excp);
+ s->is_jmp = DISAS_JUMP;
+}
+
+static void real_unallocated_encoding(DisasContext *s)
+{
+ fprintf(stderr, "Unknown instruction: %#x\n",
+ arm_ldl_code(cpu_single_env, s->pc - 4, s->bswap_code));
+ gen_exception_insn(s, 4, EXCP_UDEF);
+}
+
+#define unallocated_encoding(s) do { \
+ fprintf(stderr, "unallocated encoding at line: %d\n", __LINE__); \
+ real_unallocated_encoding(s); \
+ } while (0)
+
+void disas_a64_insn(CPUARMState *env, DisasContext *s)
+{
+ uint32_t insn;
+
+ insn = arm_ldl_code(env, s->pc, s->bswap_code);
+ s->pc += 4;
+
+ switch ((insn >> 24) & 0x1f) {
+ default:
+ unallocated_encoding(s);
+ break;
+ }
+
+ if (unlikely(s->singlestep_enabled) && (s->is_jmp == DISAS_TB_JUMP)) {
+ /* go through the main loop for single step */
+ s->is_jmp = DISAS_JUMP;
+ }
+}
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 66d4892..02d5a3d 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -112,6 +112,10 @@ void arm_translate_init(void)
offsetof(CPUARMState, exclusive_info), "exclusive_info");
#endif
+#ifdef TARGET_AARCH64
+ a64_translate_init();
+#endif
+
#define GEN_HELPER 2
#include "helper.h"
}
@@ -10038,6 +10042,11 @@ void cpu_dump_state(CPUARMState *env, FILE *f, fprintf_function cpu_fprintf,
int i;
uint32_t psr;
+ if (is_a64(env)) {
+ cpu_dump_state_a64(env, f, cpu_fprintf, flags);
+ return;
+ }
+
for(i=0;i<16;i++) {
cpu_fprintf(f, "R%02d=%08x", i, env->regs[i]);
if ((i % 4) == 3)
diff --git a/target-arm/translate.h b/target-arm/translate.h
index 8ba1433..9086e43 100644
--- a/target-arm/translate.h
+++ b/target-arm/translate.h
@@ -26,4 +26,10 @@ typedef struct DisasContext {
extern TCGv_ptr cpu_env;
+void a64_translate_init(void);
+void cpu_dump_state_a64(CPUARMState *env, FILE *f,
+ fprintf_function cpu_fprintf, int flags);
+void disas_a64_insn(CPUARMState *env, DisasContext *s);
+void gen_a64_set_pc_im(uint64_t val);
+
#endif /* TARGET_ARM_TRANSLATE_H */
--
1.8.2.2
next prev parent reply other threads:[~2013-05-14 4:33 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2013-05-14 4:32 [Qemu-devel] [PATCH v4 00/12] AArch64 preparation patch set John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 01/12] ARM: Extract the disas struct to a header file John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 02/12] ARM: Export cpu_env John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 03/12] ARM: Prepare translation for AArch64 code John Rigby
2013-05-14 4:32 ` John Rigby [this message]
2013-05-20 12:57 ` [Qemu-devel] [PATCH v4 04/12] ARM: Add AArch64 translation stub Peter Maydell
2013-06-16 20:06 ` Andreas Färber
2013-06-16 20:24 ` Peter Maydell
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 05/12] AArch64: Add gdb stub John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 06/12] linux-user: Don't treat aarch64 cpu names specially John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 07/12] linux-user: Add syscall handling for AArch64 John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 08/12] linux-user: Fix up AArch64 syscall handlers John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 09/12] linux-user: Add signal handling for AArch64 John Rigby
2013-05-14 16:31 ` Richard Henderson
2013-05-14 18:51 ` John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 10/12] linux-user: Add AArch64 support John Rigby
2013-05-14 4:32 ` [Qemu-devel] [PATCH v4 11/12] ARM: Add aarch64 target to configure John Rigby
2013-05-14 4:33 ` [Qemu-devel] [PATCH v4 12/12] linux-user: AArch64 requires at least 3.8.0 John Rigby
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=1368505980-17151-5-git-send-email-john.rigby@linaro.org \
--to=john.rigby@linaro.org \
--cc=agraf@suse.de \
--cc=paul@codesourcery.com \
--cc=peter.maydell@linaro.org \
--cc=qemu-devel@nongnu.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).