From patchwork Wed Dec 7 14:48:14 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Julian Brown X-Patchwork-Id: 703604 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3tYhHS0dLWz9t3N for ; Thu, 8 Dec 2016 01:50:12 +1100 (AEDT) Received: from localhost ([::1]:39180 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEdXu-0007Q6-22 for incoming@patchwork.ozlabs.org; Wed, 07 Dec 2016 09:50:10 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:60537) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cEdWL-0006AX-Dn for qemu-devel@nongnu.org; Wed, 07 Dec 2016 09:48:34 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cEdWK-0001LV-Lj for qemu-devel@nongnu.org; Wed, 07 Dec 2016 09:48:33 -0500 Received: from relay1.mentorg.com ([192.94.38.131]:37309) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1cEdWK-0001LL-G3 for qemu-devel@nongnu.org; Wed, 07 Dec 2016 09:48:32 -0500 Received: from nat-ies.mentorg.com ([192.94.31.2] helo=SVR-IES-MBX-04.mgc.mentorg.com) by relay1.mentorg.com with esmtp id 1cEdWJ-0002Fi-Do from Julian_Brown@mentor.com for qemu-devel@nongnu.org; Wed, 07 Dec 2016 06:48:31 -0800 Received: from build4-trusty-cs.sje.mentorg.com (147.34.91.1) by SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) with Microsoft SMTP Server (TLS) id 15.0.1210.3; Wed, 7 Dec 2016 14:48:27 +0000 From: Julian Brown To: Date: Wed, 7 Dec 2016 06:48:14 -0800 Message-ID: <9b13837a216eb358896a11709e7b4befdd5083db.1481121503.git.julian@codesourcery.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: MIME-Version: 1.0 X-ClientProxiedBy: svr-orw-mbx-01.mgc.mentorg.com (147.34.90.201) To SVR-IES-MBX-04.mgc.mentorg.com (139.181.222.4) X-detected-operating-system: by eggs.gnu.org: Windows NT kernel [generic] [fuzzy] X-Received-From: 192.94.38.131 Subject: [Qemu-devel] [PATCH v2 2/6] Infer endianness from SCTLR reset value. 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+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" This patch uses the reset value of the SCTLR register (e.g. as modified by the "cfgend" parameter introduced by the previous patch) to set the endianness used by QEMU when invoked with a null kernel, e.g. from GDB: (gdb) target remote | qemu-arm-system [options] -cpu=cortex-a15,cfgend=yes \ -kernel /dev/null (gdb) load (gdb) [...] In this scenario, the usual method of probing the kernel binary for the correct endianness to use will not work. Signed-off-by: Julian Brown --- hw/arm/boot.c | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 942416d..68a6574 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -894,7 +894,21 @@ static void arm_load_kernel_notify(Notifier *notifier, void *data) entry = info->loader_start + kernel_load_offset; kernel_size = load_image_targphys(info->kernel_filename, entry, info->ram_size - kernel_load_offset); - is_linux = 1; + if (kernel_size > 0) { + is_linux = 1; + } else { + /* We've been launched with a kernel of /dev/null or similar. + * Infer endianness from the reset value of the SCTLR for this + * CPU/board. (This can be altered using the cfgend parameter.) + */ + if (!arm_feature(&cpu->env, ARM_FEATURE_V7) && + (cpu->reset_sctlr & SCTLR_B) != 0) + info->endianness = ARM_ENDIANNESS_BE32; + else if ((cpu->reset_sctlr & SCTLR_EE) != 0) + info->endianness = ARM_ENDIANNESS_BE8; + else + info->endianness = ARM_ENDIANNESS_LE; + } } if (kernel_size < 0) { fprintf(stderr, "qemu: could not load kernel '%s'\n",