From patchwork Thu Jun 29 09:28:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: KONRAD Frederic X-Patchwork-Id: 782126 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3wyvd72gGdz9s3T for ; Thu, 29 Jun 2017 19:34:35 +1000 (AEST) Received: from localhost ([::1]:37981 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVqL-000632-22 for incoming@patchwork.ozlabs.org; Thu, 29 Jun 2017 05:34:33 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:57584) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dQVlQ-0002Ac-9d for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:29:29 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dQVlM-0001Xh-MT for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:29:28 -0400 Received: from mel.act-europe.fr ([194.98.77.210]:43365 helo=smtp.eu.adacore.com) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1dQVlM-0001Wq-Fq for qemu-devel@nongnu.org; Thu, 29 Jun 2017 05:29:24 -0400 Received: from localhost (localhost [127.0.0.1]) by filtered-smtp.eu.adacore.com (Postfix) with ESMTP id C55C681443; Thu, 29 Jun 2017 11:29:22 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at eu.adacore.com Received: from smtp.eu.adacore.com ([127.0.0.1]) by localhost (smtp.eu.adacore.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id GX42rPfiKgSr; Thu, 29 Jun 2017 11:29:22 +0200 (CEST) Received: from wifi-guest-252.act-europe.fr (wifi-guest-252.act-europe.fr [10.10.126.252]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.eu.adacore.com (Postfix) with ESMTPSA id AB61B81463; Thu, 29 Jun 2017 11:29:22 +0200 (CEST) From: KONRAD Frederic To: qemu-devel@nongnu.org Date: Thu, 29 Jun 2017 11:28:52 +0200 Message-Id: <1498728533-23160-3-git-send-email-frederic.konrad@adacore.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1498728533-23160-1-git-send-email-frederic.konrad@adacore.com> References: <1498728533-23160-1-git-send-email-frederic.konrad@adacore.com> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x [fuzzy] X-Received-From: 194.98.77.210 Subject: [Qemu-devel] [PATCH v1 2/3] arm: fix the armv7m reset state 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: , Cc: peter.maydell@linaro.org, frederic.konrad@adacore.com, alistair@alistair23.me, alex.bennee@linaro.org, pbonzini@redhat.com Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This fixes an odd bug when a ROM is present somewhere and an alias @0x00000000 is pointing to the ROM. The "if (rom)" test fails and we don't get a valid reset state. QEMU later crashes with an exception because the ARMv7-M starts with the ARM instruction set. (eg: PC & 0x01 is 0). This patch uses memory_region_get_offset_within_address_space introduced before to check if an alias doesn't point to a flash somewhere. Signed-off-by: KONRAD Frederic --- target/arm/cpu.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 28a9141..b8afd97 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -201,6 +201,20 @@ static void arm_cpu_reset(CPUState *s) /* Load the initial SP and PC from the vector table at address 0 */ rom = rom_ptr(0); + + if (!rom) { + /* Sometimes address 0x00000000 is an alias to a flash which + * actually have a ROM. + */ + MemoryRegionSection section; + hwaddr offset = 0; + + section = memory_region_find(s->as->root, 0, 8); + offset = memory_region_get_offset_within_address_space(section.mr); + memory_region_unref(section.mr); + rom = rom_ptr(offset); + } + if (rom) { /* Address zero is covered by ROM which hasn't yet been * copied into physical memory.