From patchwork Mon Jul 1 17:35:06 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 18218 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qc0-f199.google.com (mail-qc0-f199.google.com [209.85.216.199]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 7A19B2774F for ; Mon, 1 Jul 2013 17:35:39 +0000 (UTC) Received: by mail-qc0-f199.google.com with SMTP id a1sf7094420qcx.10 for ; Mon, 01 Jul 2013 10:35:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-beenthere:x-forwarded-to:x-forwarded-for :delivered-to:from:to:cc:subject:date:message-id:x-mailer :in-reply-to:references:x-gm-message-state:x-original-sender :x-original-authentication-results:precedence:mailing-list:list-id :x-google-group-id:list-post:list-help:list-archive:list-unsubscribe; bh=+VuR2Kkd/O5k8J/Aea4FVQXU4NKJznNwrq+wpdagzsY=; b=fO6LsV1ki4qxI8eY4fqwq9YAICkrj5/0CwJLM4qO1eC92eU0d3qqv2MAUFN0A5EIXl J7F/cL3wv3gHVidaB47LfAuqouZLVsaRySlnNGUkX8Jprs6z/9Wwv3CutBuXw+SjUbYf eaVD4bhj7wCkNpjsSY+zkt6U21Yl6q5LbBTppMH5drnmjDJi9DQfflr+bRZwUFVZq7LP Re0nUEpcO30cYv871kFhMVPefkcLknPnYssjCeH8hdnEwYnsnUh/luHLlUIciIvPy9LC JJnnCo5lD0iZHaoS3ENS/l8j8Zmd/YHNysPGB00apivfCKCYWo6lDEeJBJafCPavqEsB CspQ== X-Received: by 10.236.149.113 with SMTP id w77mr15852933yhj.2.1372700139244; Mon, 01 Jul 2013 10:35:39 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.49.71.210 with SMTP id x18ls2331203qeu.85.gmail; Mon, 01 Jul 2013 10:35:39 -0700 (PDT) X-Received: by 10.220.164.138 with SMTP id e10mr9953610vcy.27.1372700139125; Mon, 01 Jul 2013 10:35:39 -0700 (PDT) Received: from mail-ve0-f175.google.com (mail-ve0-f175.google.com [209.85.128.175]) by mx.google.com with ESMTPS id ex7si4992680vdb.57.2013.07.01.10.35.39 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 01 Jul 2013 10:35:39 -0700 (PDT) Received-SPF: neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.175; Received: by mail-ve0-f175.google.com with SMTP id da11so3980702veb.20 for ; Mon, 01 Jul 2013 10:35:39 -0700 (PDT) X-Received: by 10.58.119.233 with SMTP id kx9mr10078324veb.3.1372700138959; Mon, 01 Jul 2013 10:35:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patches@linaro.org Received: by 10.58.165.8 with SMTP id yu8csp289816veb; Mon, 1 Jul 2013 10:35:38 -0700 (PDT) X-Received: by 10.14.202.70 with SMTP id c46mr22515258eeo.28.1372700131649; Mon, 01 Jul 2013 10:35:31 -0700 (PDT) Received: from mnementh.archaic.org.uk (1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.d.1.0.0.b.8.0.1.0.0.2.ip6.arpa. [2001:8b0:1d0::1]) by mx.google.com with ESMTPS id s8si11984013ees.178.2013.07.01.10.35.30 for (version=TLSv1.2 cipher=RC4-SHA bits=128/128); Mon, 01 Jul 2013 10:35:31 -0700 (PDT) Received-SPF: neutral (google.com: 2001:8b0:1d0::1 is neither permitted nor denied by best guess record for domain of pm215@archaic.org.uk) client-ip=2001:8b0:1d0::1; Received: from pm215 by mnementh.archaic.org.uk with local (Exim 4.80) (envelope-from ) id 1Uti0X-0002KP-QP; Mon, 01 Jul 2013 18:35:21 +0100 From: Peter Maydell To: qemu-devel@nongnu.org Cc: patches@linaro.org, Alexander Graf , Andreas Schwab , "Mian M. Hamayun" Subject: [PATCH v5 07/21] target-arm: Add AArch64 translation stub Date: Mon, 1 Jul 2013 18:35:06 +0100 Message-Id: <1372700120-8896-8-git-send-email-peter.maydell@linaro.org> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1372700120-8896-1-git-send-email-peter.maydell@linaro.org> References: <1372700120-8896-1-git-send-email-peter.maydell@linaro.org> X-Gm-Message-State: ALoCoQkP3KiAZRNSDw7VyMfYZK1xn3OFqKynW+bSDf2o3yMAsVmgznHk1pECusA2P6ZbeoADZusZ X-Original-Sender: peter.maydell@linaro.org X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Precedence: list Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org List-ID: X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , From: Alexander Graf 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 Signed-off-by: John Rigby Message-id: 1368505980-17151-5-git-send-email-john.rigby@linaro.org [PMM: * provide no-op versions of a64 functions ifndef TARGET_AARCH64; this lets us avoid #ifdefs in translate.c * insert the missing call to disas_a64_insn() ] Signed-off-by: Peter Maydell --- target-arm/Makefile.objs | 1 + target-arm/translate-a64.c | 137 ++++++++++++++++++++++++++++++++++++++++++++ target-arm/translate.c | 19 +++++- target-arm/translate.h | 25 ++++++++ 4 files changed, 179 insertions(+), 3 deletions(-) create mode 100644 target-arm/translate-a64.c diff --git a/target-arm/Makefile.objs b/target-arm/Makefile.objs index 4a6e52e..3378eb8 100644 --- a/target-arm/Makefile.objs +++ b/target-arm/Makefile.objs @@ -4,3 +4,4 @@ obj-$(CONFIG_KVM) += kvm.o obj-$(CONFIG_NO_KVM) += kvm-stub.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 + * + * 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 . + */ +#include +#include +#include +#include +#include + +#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 2935cea..93fcc8d 100644 --- a/target-arm/translate.c +++ b/target-arm/translate.c @@ -112,6 +112,8 @@ void arm_translate_init(void) offsetof(CPUARMState, exclusive_info), "exclusive_info"); #endif + a64_translate_init(); + #define GEN_HELPER 2 #include "helper.h" } @@ -905,7 +907,11 @@ DO_GEN_ST(st32) static inline void gen_set_pc_im(DisasContext *s, target_ulong val) { - tcg_gen_movi_i32(cpu_R[15], val); + if (s->aarch64) { + gen_a64_set_pc_im(val); + } else { + tcg_gen_movi_i32(cpu_R[15], val); + } } /* Force a TB lookup after an instruction that changes the CPU state. */ @@ -9971,7 +9977,7 @@ static inline void gen_intermediate_code_internal(CPUARMState *env, do { #ifdef CONFIG_USER_ONLY /* Intercept jump to the magic kernel page. */ - if (dc->pc >= 0xffff0000) { + if (!dc->aarch64 && dc->pc >= 0xffff0000) { /* We always get here via a jump, so know we are not in a conditional execution block. */ gen_exception(EXCP_KERNEL_TRAP); @@ -10019,7 +10025,9 @@ static inline void gen_intermediate_code_internal(CPUARMState *env, tcg_gen_debug_insn_start(dc->pc); } - if (dc->thumb) { + if (dc->aarch64) { + disas_a64_insn(env, dc); + } else if (dc->thumb) { disas_thumb_insn(env, dc); if (dc->condexec_mask) { dc->condexec_cond = (dc->condexec_cond & 0xe) @@ -10174,6 +10182,11 @@ void arm_cpu_dump_state(CPUState *cs, 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 5be2eed..79aa715 100644 --- a/target-arm/translate.h +++ b/target-arm/translate.h @@ -27,4 +27,29 @@ typedef struct DisasContext { extern TCGv_ptr cpu_env; +#ifdef TARGET_AARCH64 +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); +#else +static inline void a64_translate_init(void) +{ +} + +static inline void cpu_dump_state_a64(CPUARMState *env, FILE *f, + fprintf_function cpu_fprintf, int flags) +{ +} + +static inline void disas_a64_insn(CPUARMState *env, DisasContext *s) +{ +} + +static inline void gen_a64_set_pc_im(uint64_t val) +{ +} +#endif + #endif /* TARGET_ARM_TRANSLATE_H */