From patchwork Fri Feb 1 16:06:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 157279 Delivered-To: patch@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp643121jaa; Fri, 1 Feb 2019 08:28:07 -0800 (PST) X-Google-Smtp-Source: AHgI3IaFUz15vAnhJsLsHNF9hvaDnU6e03Skn6LVp8+wA6/At76FOKr/E9jHde25j6ZoY+BPzUbV X-Received: by 2002:a25:83d2:: with SMTP id v18mr16379803ybm.492.1549038487227; Fri, 01 Feb 2019 08:28:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549038487; cv=none; d=google.com; s=arc-20160816; b=gtYAY/XqitKNcFkYqaOAHob7LSum4PLJhfQ1A2G0pciaS6UTupldoOP7le8d2nwZD0 5hmsRfAQ9V5gb6DSbdpC82PJ3CERHqj/b3bClzY2zWCoWYBvjfZAUMoQEoN/svDz3jPY 7vQj+x7dEokvlqXsMQj4w05wuY+MPKu/XBUlTRHV2+129kKWpSXwujDQYGaCMsziBlRf GSi3GwnhohaBafQ4u4Y4KXqPbabIy2sxVnSpLa28v2cOnHJw8pntefgHZ57+ggGBITqT B5eRlvwYJq7lh+P3NUl18AXAjR5p+4jhni6R83dp/T68jA+779K01otXlkZYX4U1Y0au /UcQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=65hoE87QzTlx1RgWe4e2mzsptT81YWQ8G4GnPJjUlTY=; b=QADxj5g0aO1NDV7hKxuvqosslkIeqPc1U5AcKJUrDA3udQGDAlkuMvKuPCIEjBrSt0 nmy09gsaxq2w6oqtSAkSusvP/G37kKhyq3gvnECfVBoThnbMWd7v990d2WCPfZhTSn/K zXofnzCCBaUY8CimcdEnmKpHyIg/5o5qcn3lj3mwUrZ+Oyq/Z2V97xvPXiVU6r4cbBm7 y5czBVpnpBn9htAyXhzZbf/jTRCWKLH3epzoOWCLdkI0wP+jbKk6vZXYsc6CxyMXhfAD ZkaJcS8aJfAapX9qtpVk25ElM/EC1WkxnDu17pdhL0rVjSy9zqu9cQLOcuTCf1UtiNyI hUvA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IAtYVHth; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id d140si4842206ybh.456.2019.02.01.08.28.07 for (version=TLS1 cipher=AES128-SHA bits=128/128); Fri, 01 Feb 2019 08:28:07 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IAtYVHth; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:57534 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbfi-0000Bt-Kl for patch@linaro.org; Fri, 01 Feb 2019 11:28:06 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59021) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gpbMD-0008Gq-TK for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:08:10 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gpbM9-0003hB-Nc for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:07:57 -0500 Received: from mail-wm1-x344.google.com ([2a00:1450:4864:20::344]:35370) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gpbM9-0003dJ-DA for qemu-devel@nongnu.org; Fri, 01 Feb 2019 11:07:53 -0500 Received: by mail-wm1-x344.google.com with SMTP id t200so6822773wmt.0 for ; Fri, 01 Feb 2019 08:07:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=65hoE87QzTlx1RgWe4e2mzsptT81YWQ8G4GnPJjUlTY=; b=IAtYVHthd7imcY10dPHHw7DQDYrRm5PpcLmkLB8S89Y8n/uBQ4Fpe+fApce7udGrvf NK8eTsNH2Myi4pIDkaL3difA9UdHz5trCrC81jKowyV2ePAernWiHZ5pWKNAqCESroiQ Wc6Tqe/EHpa2LW6aRelg03/Lliyn6pe7fPyec= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=65hoE87QzTlx1RgWe4e2mzsptT81YWQ8G4GnPJjUlTY=; b=aFZaPqRrTkrNPLiwli2se6tvgVl0ZjWp8dzYvVmP5ZPgCS/zhSPH8J+pteLfM7bmRF 1mhFXidfTAO3Bfj1vkzP0gSVMKYzqCbXfNW+bQh8uXPFDF8gJd1NVHsabjybHVHwbZeR a0KTSgoqGeerdEPyFpREcCIdpKSjWFbgEgYmgTC7qU3/2glPskItbI0J5KfVx3aoYHCR kYTb0x712FfVdiu7chbMDrR0jpFN9p51PqGW5cPUaYBKc4pyaA+wkz58bAvlcNQDSajc XkDHR8kk/+bCiChW2cGtOP6GEOtDTIGCCdOmZKnGaH1WVbZCoqWpIxadPPbJ1KdtJx70 h2Hw== X-Gm-Message-State: AHQUAub5f/EabnD+6gUVNdSgO26ZjBStauuWWZv9pCD2o0WThEjeTf+V EJfsFYoEEhfOMox1wQQlqGH+huYpKDz6Pg== X-Received: by 2002:a1c:9c15:: with SMTP id f21mr2896264wme.94.1549037263898; Fri, 01 Feb 2019 08:07:43 -0800 (PST) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id n6sm2847250wmk.9.2019.02.01.08.07.42 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 01 Feb 2019 08:07:43 -0800 (PST) From: Peter Maydell To: qemu-devel@nongnu.org Date: Fri, 1 Feb 2019 16:06:44 +0000 Message-Id: <20190201160653.13829-39-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190201160653.13829-1-peter.maydell@linaro.org> References: <20190201160653.13829-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::344 Subject: [Qemu-devel] [PULL 38/47] arm: Clarify the logic of set_pc() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" From: Julia Suvorova Until now, the set_pc logic was unclear, which raised questions about whether it should be used directly, applying a value to PC or adding additional checks, for example, set the Thumb bit in Arm cpu. Let's set the set_pc logic for “Configure the PC, as was done in the ELF file” and implement synchronize_with_tb hook for preserving PC to cpu_tb_exec. Signed-off-by: Julia Suvorova Acked-by: Stefan Hajnoczi Message-id: 20190129121817.7109-1-jusual@mail.ru Reviewed-by: Peter Maydell Signed-off-by: Peter Maydell --- include/qom/cpu.h | 16 ++++++++++++++-- hw/arm/boot.c | 4 ---- target/arm/arm-powerctl.c | 3 --- target/arm/cpu.c | 26 +++++++++++++++++++++++++- target/arm/cpu64.c | 15 --------------- 5 files changed, 39 insertions(+), 25 deletions(-) -- 2.20.1 diff --git a/include/qom/cpu.h b/include/qom/cpu.h index 4c2feb9c17b..1d6099e5d4b 100644 --- a/include/qom/cpu.h +++ b/include/qom/cpu.h @@ -103,9 +103,21 @@ struct TranslationBlock; * @get_arch_id: Callback for getting architecture-dependent CPU ID. * @get_paging_enabled: Callback for inquiring whether paging is enabled. * @get_memory_mapping: Callback for obtaining the memory mappings. - * @set_pc: Callback for setting the Program Counter register. + * @set_pc: Callback for setting the Program Counter register. This + * should have the semantics used by the target architecture when + * setting the PC from a source such as an ELF file entry point; + * for example on Arm it will also set the Thumb mode bit based + * on the least significant bit of the new PC value. + * If the target behaviour here is anything other than "set + * the PC register to the value passed in" then the target must + * also implement the synchronize_from_tb hook. * @synchronize_from_tb: Callback for synchronizing state from a TCG - * #TranslationBlock. + * #TranslationBlock. This is called when we abandon execution + * of a TB before starting it, and must set all parts of the CPU + * state which the previous TB in the chain may not have updated. + * This always includes at least the program counter; some targets + * will need to do more. If this hook is not implemented then the + * default is to call @set_pc(tb->pc). * @handle_mmu_fault: Callback for handling an MMU fault. * @get_phys_page_debug: Callback for obtaining a physical address. * @get_phys_page_attrs_debug: Callback for obtaining a physical address and the diff --git a/hw/arm/boot.c b/hw/arm/boot.c index c7a67af7a97..05762d0fc1b 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -697,10 +697,6 @@ static void do_cpu_reset(void *opaque) g_assert_not_reached(); } - if (!env->aarch64) { - env->thumb = info->entry & 1; - entry &= 0xfffffffe; - } cpu_set_pc(cs, entry); } else { /* If we are booting Linux then we need to check whether we are diff --git a/target/arm/arm-powerctl.c b/target/arm/arm-powerctl.c index 2b856930fb7..f9de5164e55 100644 --- a/target/arm/arm-powerctl.c +++ b/target/arm/arm-powerctl.c @@ -120,11 +120,8 @@ static void arm_set_cpu_on_async_work(CPUState *target_cpu_state, if (info->target_aa64) { target_cpu->env.xregs[0] = info->context_id; - target_cpu->env.thumb = false; } else { target_cpu->env.regs[0] = info->context_id; - target_cpu->env.thumb = info->entry & 1; - info->entry &= 0xfffffffe; } /* Start the new CPU at the requested address */ diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 8a9cd0900d2..f00d450d0bd 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -40,8 +40,31 @@ static void arm_cpu_set_pc(CPUState *cs, vaddr value) { ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; - cpu->env.regs[15] = value; + if (is_a64(env)) { + env->pc = value; + env->thumb = 0; + } else { + env->regs[15] = value & ~1; + env->thumb = value & 1; + } +} + +static void arm_cpu_synchronize_from_tb(CPUState *cs, TranslationBlock *tb) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + + /* + * It's OK to look at env for the current mode here, because it's + * never possible for an AArch64 TB to chain to an AArch32 TB. + */ + if (is_a64(env)) { + env->pc = tb->pc; + } else { + env->regs[15] = tb->pc; + } } static bool arm_cpu_has_work(CPUState *cs) @@ -2099,6 +2122,7 @@ static void arm_cpu_class_init(ObjectClass *oc, void *data) cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; cc->dump_state = arm_cpu_dump_state; cc->set_pc = arm_cpu_set_pc; + cc->synchronize_from_tb = arm_cpu_synchronize_from_tb; cc->gdb_read_register = arm_cpu_gdb_read_register; cc->gdb_write_register = arm_cpu_gdb_write_register; #ifdef CONFIG_USER_ONLY diff --git a/target/arm/cpu64.c b/target/arm/cpu64.c index e9bc461c362..8653cecd032 100644 --- a/target/arm/cpu64.c +++ b/target/arm/cpu64.c @@ -480,20 +480,6 @@ static void aarch64_cpu_finalizefn(Object *obj) { } -static void aarch64_cpu_set_pc(CPUState *cs, vaddr value) -{ - ARMCPU *cpu = ARM_CPU(cs); - /* It's OK to look at env for the current mode here, because it's - * never possible for an AArch64 TB to chain to an AArch32 TB. - * (Otherwise we would need to use synchronize_from_tb instead.) - */ - if (is_a64(&cpu->env)) { - cpu->env.pc = value; - } else { - cpu->env.regs[15] = value; - } -} - static gchar *aarch64_gdb_arch_name(CPUState *cs) { return g_strdup("aarch64"); @@ -504,7 +490,6 @@ static void aarch64_cpu_class_init(ObjectClass *oc, void *data) CPUClass *cc = CPU_CLASS(oc); cc->cpu_exec_interrupt = arm_cpu_exec_interrupt; - cc->set_pc = aarch64_cpu_set_pc; cc->gdb_read_register = aarch64_cpu_gdb_read_register; cc->gdb_write_register = aarch64_cpu_gdb_write_register; cc->gdb_num_core_regs = 34;