From patchwork Mon Apr 24 15:27:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 676573 Delivered-To: patch@linaro.org Received: by 2002:a5d:4a41:0:0:0:0:0 with SMTP id v1csp2221962wrs; Mon, 24 Apr 2023 08:28:55 -0700 (PDT) X-Google-Smtp-Source: AKy350YTmi6ufn5Za1pfP5AcHfQt5LXPt2CnkeA7Ll3yBpNDZqblj1aoTy4Rl5FEAj4gkvxlx+5/ X-Received: by 2002:a05:6214:b6c:b0:5ef:6718:f8c7 with SMTP id ey12-20020a0562140b6c00b005ef6718f8c7mr26555306qvb.38.1682350135135; Mon, 24 Apr 2023 08:28:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682350135; cv=none; d=google.com; s=arc-20160816; b=bFsl/O2Zk5rAKuqh+wg0ePyGHjaoBlBFqY8ZyHsr2AZwe/fkJEny7rYFpxWqKWjsZS 46iuAzJCJXhnkZ2jr0eciF8C50GMCYcqjsTA6bhNA0DtQtcS33NaSviOSBtIqStmB6f1 CfC6tegCoOdyfSSAfcaF+53zBwXBZXAx4JInc6VKSyZe3tKZv3P9XAUasYvA6uYQg2Wu ptJcbK4IY+z4Q7YPILf+BgPGoPE8vhEXs+0qnEvoPe3zER/xwPgBaNQT3nLh4wapfSVW PKb9VKAC8ANF85HgVHM3KDXHzbr9r+SyKU5dhPkDkFpvfT6bxzGmpUUIPGtUJ2KqwB4o BYRw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZZKjYXHyIeMkg0aKSc0TvN58snmM4oHGc16JhGaHgLU=; b=Y1rQdvZVSJj1LsRgtdgq8+LR/+IknhP2s/s532yCEwbRCLTX9LqLFnHv8DVjDo4Gzl JxbU9SjAwNm8UNuBzTIrB5omVNyckCRUAJrFKk8cu4Cpiaf7dn6STG1A+8YpfcMpVZPY SEIZiPweXCi9aE0H5VQM3fIPJynZg5aCzx60UIsOt1Xuvap65woiQRGV8iyIJR//aTiV FmULZ//wuiJZyfV+MifbOWcmHyLHFeMjiCaJ1HR6CF2f8P+cL/alqORd5UJMiV6GnaIZ U8Tci7c95WC4CTwh0Ucwt0iQiNOHxvz3osd5y74m3msRligGEd99E8xTZYvCMekrvYRq 3IcA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aESgrZfJ; 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=pass (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 gg13-20020a056214252d00b005efd3b454ecsi7429542qvb.458.2023.04.24.08.28.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 24 Apr 2023 08:28:55 -0700 (PDT) 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=pass header.i=@linaro.org header.s=google header.b=aESgrZfJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pqy6H-0006lg-ND; Mon, 24 Apr 2023 11:27:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pqy6C-0006jW-0r for qemu-devel@nongnu.org; Mon, 24 Apr 2023 11:27:29 -0400 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pqy66-0006sz-EK for qemu-devel@nongnu.org; Mon, 24 Apr 2023 11:27:27 -0400 Received: by mail-wm1-x329.google.com with SMTP id 5b1f17b1804b1-3f178da21b5so30883185e9.3 for ; Mon, 24 Apr 2023 08:27:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1682350041; x=1684942041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=ZZKjYXHyIeMkg0aKSc0TvN58snmM4oHGc16JhGaHgLU=; b=aESgrZfJrlwqhhiLZA7aRfipgMzYJyYzye0ieW8n3FgJmIFXe4VF0WFI2eXFTLnTBw oDODwCFFs5AnudZ1SulvI+1OcH4dZZciAxI/SjeA9c5jzmwexYuBFrfnv0QKOd3sndtG hsvEwNX+Zr0Z4kYfjkmlGio4oOY9y/1Zy9+I9Z8BJuvs01ntlO9KEodNRjLomgCurxnr rxUJ0DpK50BGrer1UgDMwRNCiLEeGcZN88zv9n6vlCkkw/0UPCv7HZ01vZZwGsruj8OW ipNMJKCg24YalhQCsHAxbLC/9QneiMbLmpvpKZzJ5b76asJ8h+Jl33erygGSi91LJkXw PDxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682350041; x=1684942041; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=ZZKjYXHyIeMkg0aKSc0TvN58snmM4oHGc16JhGaHgLU=; b=eaUWAS0o987HD78qevAuQ/zmwDE3Jko4l7mIh4vptzMlkFAfYHwE4E44Ep8OagbJGs o45Gx3aJUq0R6S2PzIFVuBiQNbednP/0/ZF6Vk3eZzQ0/HuIETzuA+2LikC8AO0FLUf+ K7WN3b9JVXc+PYiBrKgk9+gLFZW5JTnOuyBsluJVE+pPUaMwD1AknidAay6z8cNnnZu2 3xCFXER5PPZ7SamQEBNGRkTrMEbkJWpL96cGQxlqPvLys7Jvw6DlJ/Ime+sL3KkOL1pB R8XoFjPEyo6V2g6ugTpAI2FE79Srp3BfpygxK2vl4BS8M98eaY9YZwEvHCu5egAQFalZ Jp6A== X-Gm-Message-State: AAQBX9e+WO1GA64a8GRldocu7yoKBBUoA6zfrm6nwqRwkcMrXv5YckJR JJESs0t4iAw9qnFyhZPWhQGLnA== X-Received: by 2002:a7b:cb57:0:b0:3f2:507f:25a4 with SMTP id v23-20020a7bcb57000000b003f2507f25a4mr2019118wmj.30.1682350040839; Mon, 24 Apr 2023 08:27:20 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [2001:8b0:1d0::2]) by smtp.gmail.com with ESMTPSA id b1-20020a5d45c1000000b002fdeafcb132sm10971517wrs.107.2023.04.24.08.27.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 Apr 2023 08:27:20 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= , Andrew Jeffery , Joel Stanley , =?utf-8?q?C=C3=A9dric_Le_Goater?= Subject: [PATCH 3/3] hw/arm/raspi: Use arm_write_bootloader() to write boot code Date: Mon, 24 Apr 2023 16:27:17 +0100 Message-Id: <20230424152717.1333930-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230424152717.1333930-1-peter.maydell@linaro.org> References: <20230424152717.1333930-1-peter.maydell@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2a00:1450:4864:20::329; envelope-from=peter.maydell@linaro.org; helo=mail-wm1-x329.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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-bounces+patch=linaro.org@nongnu.org When writing the secondary-CPU stub boot loader code to the guest, use arm_write_bootloader() instead of directly calling rom_add_blob_fixed(). This fixes a bug on big-endian hosts, because arm_write_bootloader() will correctly byte-swap the host-byte-order array values into the guest-byte-order to write into the guest memory. Cc: qemu-stable@nongnu.org Signed-off-by: Peter Maydell --- hw/arm/raspi.c | 64 +++++++++++++++++++++++++++----------------------- 1 file changed, 34 insertions(+), 30 deletions(-) diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index 92d068d1f9d..a7d287b1a8a 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -16,6 +16,7 @@ #include "qemu/units.h" #include "qemu/cutils.h" #include "qapi/error.h" +#include "hw/arm/boot.h" #include "hw/arm/bcm2836.h" #include "hw/registerfields.h" #include "qemu/error-report.h" @@ -124,20 +125,22 @@ static const char *board_type(uint32_t board_rev) static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { - static const uint32_t smpboot[] = { - 0xe1a0e00f, /* mov lr, pc */ - 0xe3a0fe00 + (BOARDSETUP_ADDR >> 4), /* mov pc, BOARDSETUP_ADDR */ - 0xee100fb0, /* mrc p15, 0, r0, c0, c0, 5;get core ID */ - 0xe7e10050, /* ubfx r0, r0, #0, #2 ;extract LSB */ - 0xe59f5014, /* ldr r5, =0x400000CC ;load mbox base */ - 0xe320f001, /* 1: yield */ - 0xe7953200, /* ldr r3, [r5, r0, lsl #4] ;read mbox for our core*/ - 0xe3530000, /* cmp r3, #0 ;spin while zero */ - 0x0afffffb, /* beq 1b */ - 0xe7853200, /* str r3, [r5, r0, lsl #4] ;clear mbox */ - 0xe12fff13, /* bx r3 ;jump to target */ - 0x400000cc, /* (constant: mailbox 3 read/clear base) */ + static const ARMInsnFixup smpboot[] = { + { 0xe1a0e00f }, /* mov lr, pc */ + { 0xe3a0fe00 + (BOARDSETUP_ADDR >> 4) }, /* mov pc, BOARDSETUP_ADDR */ + { 0xee100fb0 }, /* mrc p15, 0, r0, c0, c0, 5;get core ID */ + { 0xe7e10050 }, /* ubfx r0, r0, #0, #2 ;extract LSB */ + { 0xe59f5014 }, /* ldr r5, =0x400000CC ;load mbox base */ + { 0xe320f001 }, /* 1: yield */ + { 0xe7953200 }, /* ldr r3, [r5, r0, lsl #4] ;read mbox for our core */ + { 0xe3530000 }, /* cmp r3, #0 ;spin while zero */ + { 0x0afffffb }, /* beq 1b */ + { 0xe7853200 }, /* str r3, [r5, r0, lsl #4] ;clear mbox */ + { 0xe12fff13 }, /* bx r3 ;jump to target */ + { 0x400000cc }, /* (constant: mailbox 3 read/clear base) */ + { 0, FIXUP_TERMINATOR } }; + static const uint32_t fixupcontext[FIXUP_MAX] = { 0 }; /* check that we don't overrun board setup vectors */ QEMU_BUILD_BUG_ON(SMPBOOT_ADDR + sizeof(smpboot) > MVBAR_ADDR); @@ -145,9 +148,8 @@ static void write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) QEMU_BUILD_BUG_ON((BOARDSETUP_ADDR & 0xf) != 0 || (BOARDSETUP_ADDR >> 4) >= 0x100); - rom_add_blob_fixed_as("raspi_smpboot", smpboot, sizeof(smpboot), - info->smp_loader_start, - arm_boot_address_space(cpu, info)); + arm_write_bootloader("raspi_smpboot", arm_boot_address_space(cpu, info), + info->smp_loader_start, smpboot, fixupcontext); } static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) @@ -161,26 +163,28 @@ static void write_smpboot64(ARMCPU *cpu, const struct arm_boot_info *info) * the primary CPU goes into the kernel. We put these variables inside * a rom blob, so that the reset for ROM contents zeroes them for us. */ - static const uint32_t smpboot[] = { - 0xd2801b05, /* mov x5, 0xd8 */ - 0xd53800a6, /* mrs x6, mpidr_el1 */ - 0x924004c6, /* and x6, x6, #0x3 */ - 0xd503205f, /* spin: wfe */ - 0xf86678a4, /* ldr x4, [x5,x6,lsl #3] */ - 0xb4ffffc4, /* cbz x4, spin */ - 0xd2800000, /* mov x0, #0x0 */ - 0xd2800001, /* mov x1, #0x0 */ - 0xd2800002, /* mov x2, #0x0 */ - 0xd2800003, /* mov x3, #0x0 */ - 0xd61f0080, /* br x4 */ + static const ARMInsnFixup smpboot[] = { + { 0xd2801b05 }, /* mov x5, 0xd8 */ + { 0xd53800a6 }, /* mrs x6, mpidr_el1 */ + { 0x924004c6 }, /* and x6, x6, #0x3 */ + { 0xd503205f }, /* spin: wfe */ + { 0xf86678a4 }, /* ldr x4, [x5,x6,lsl #3] */ + { 0xb4ffffc4 }, /* cbz x4, spin */ + { 0xd2800000 }, /* mov x0, #0x0 */ + { 0xd2800001 }, /* mov x1, #0x0 */ + { 0xd2800002 }, /* mov x2, #0x0 */ + { 0xd2800003 }, /* mov x3, #0x0 */ + { 0xd61f0080 }, /* br x4 */ + { 0, FIXUP_TERMINATOR } }; + static const uint32_t fixupcontext[FIXUP_MAX] = { 0 }; static const uint64_t spintables[] = { 0, 0, 0, 0 }; - rom_add_blob_fixed_as("raspi_smpboot", smpboot, sizeof(smpboot), - info->smp_loader_start, as); + arm_write_bootloader("raspi_smpboot", as, info->smp_loader_start, + smpboot, fixupcontext); rom_add_blob_fixed_as("raspi_spintables", spintables, sizeof(spintables), SPINTABLE_ADDR, as); }