From nobody Sun Nov 24 01:33:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1727734363; cv=none; d=zohomail.com; s=zohoarc; b=kKCgr0SicMUILNULQ8TWl8CVxQoDPdqCrSzgZiqWuAuubGd4auWwkIGkloG1dkUKawwz1fukQFBV1gQDWlkHLwxkRujW4SysXYnNtap17okdP7Bk91xObxJe4wOPwEpVQ0uh11j98+nmfd5sQpX4kKpHmITi+AxEcfYiaCz1n8g= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727734363; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=zYZS2o413t5NEWqhqyvJRLT8+V/Algd2PuxZZg9wbeU=; b=N6LGxRxoQtLJUTmoyFWKs8Ql82vnhUdssdCLNEhiuSGfvXBTdpWYa2aOErWTNpixVarc4o1emR09B0xvv1ypTfu/vpVYrhjngxVG6MPbifIdM9I3657lvZXLq5N/Ss/OsZeZFjZyye8ckzTZlbhg04xB5+DuI5P7G1/ZYBgelqE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 172773436360559.134588538622324; Mon, 30 Sep 2024 15:12:43 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svOcx-00039y-LB; Mon, 30 Sep 2024 18:12:23 -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 1svOcv-000392-NQ for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:21 -0400 Received: from mail-ej1-x62a.google.com ([2a00:1450:4864:20::62a]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svOct-0002eU-Jp for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:21 -0400 Received: by mail-ej1-x62a.google.com with SMTP id a640c23a62f3a-a7aa086b077so716929366b.0 for ; Mon, 30 Sep 2024 15:12:19 -0700 (PDT) Received: from localhost.localdomain (46.170.88.92.rev.sfr.net. [92.88.170.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2947fbesm593809866b.128.2024.09.30.15.12.14 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Sep 2024 15:12:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727734338; x=1728339138; darn=nongnu.org; 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=zYZS2o413t5NEWqhqyvJRLT8+V/Algd2PuxZZg9wbeU=; b=mG2tj/ValrGJJuWgAGmFoQHkedMOcpOP7WAVKwquaBrqyFgR/WyLXhDZ8tyXOA48cL +SKrjfkHm52lX2x3sJ68FSeg/1urgcgYhWxswbAs341886T6Xg3Mfo87zJOXeHwT4Cac rPbfqPmrrEPViPxoQRfpQulR8tpwzqsX9Z5gdEuCmqHNdVjAwMrS6Nv/laEplSrjjW1R VMeir8cUg7U49euieU0I7BpoTIVXRkYWQcPCFUJelovtuXflKbOUdlAGtMBW1klshzFG pkmFxvxj1/ZdEKgZOAXuDv+yfLlFqEH80zjr8Jzb2JKal5eRvtLNerhLVXB8bUgK87tq 4zYA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727734338; x=1728339138; 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=zYZS2o413t5NEWqhqyvJRLT8+V/Algd2PuxZZg9wbeU=; b=tZR/fW98pnuI5cwQ5G4KA+x/6YgACcdj0q3yaZ5d/lJmuLy1q3D9PGmolIV4c/GA1M wGnI5re/+EzmsYVdVEY4t98mya1cxOXOATV/datjHOtYL0CJUxf37ADD638EmPzwRzyB bjbvv1srtxaj7cd2iHRRduX3vs9+kzlRqkcKih+2SBZADmq+x04khThVLNzQGvSXXlmF QCMxDTpUdy4bFZr7DXiDjGLHCTrdtxYB0x3WzYgK1sumwWfyVhA2cvAgvNL2A7JHep6k cOnisZH1/Rhgbg+yTqMoEvGpG0wy8Mc39jCZsJ3GdistEQDaHLTAjLO8iITlc1YmWqin RGPA== X-Gm-Message-State: AOJu0Yx13SOiHRY1vx32T4iLD0WqFNqhD6NbhUCzH0cHbp8oD9gtdyWr PUWchYsSldHWTQpuafAZ87HW7MdoTynWpwZ1gkhHw3n07wWKVtYRF24xrLhn99EzDyqFl6KWpgi 8d1I= X-Google-Smtp-Source: AGHT+IExdxcYq81zX9FJW1somPfFXnJrlrB3XUOVOuJ5BuFtV0StTj0KDem5UMjns62Iq90Ng7Rz4g== X-Received: by 2002:a17:907:3f25:b0:a8a:926a:d002 with SMTP id a640c23a62f3a-a93c48f5b97mr1500610166b.12.1727734337632; Mon, 30 Sep 2024 15:12:17 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Peter Maydell , Thomas Huth , Hao Wu , Laurent Vivier , Joel Stanley , qemu-arm@nongnu.org, Andrew Jeffery , Steven Lee , Tyrone Ting , "Edgar E. Iglesias" , Igor Mitsyanko , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Jamin Lin , Troy Lee , Anton Johansson Subject: [PATCH 1/3] target/arm: Expose arm_cpu_code_is_big_endian() prototype in 'cpu.h' Date: Tue, 1 Oct 2024 00:12:02 +0200 Message-ID: <20240930221205.59101-2-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240930221205.59101-1-philmd@linaro.org> References: <20240930221205.59101-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62a; envelope-from=philmd@linaro.org; helo=mail-ej1-x62a.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 autolearn=unavailable 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1727734365623116600 Expose arm_cpu_code_is_big_endian() so it can be used by hw/ code. Use it in few places where it was open coded. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- target/arm/cpu.h | 7 +++++++ linux-user/aarch64/cpu_loop.c | 4 ++-- linux-user/arm/cpu_loop.c | 4 ++-- target/arm/cpu.c | 6 ++---- 4 files changed, 13 insertions(+), 8 deletions(-) diff --git a/target/arm/cpu.h b/target/arm/cpu.h index f065756c5c..da8f2b2ec8 100644 --- a/target/arm/cpu.h +++ b/target/arm/cpu.h @@ -3057,6 +3057,13 @@ static inline bool arm_cpu_data_is_big_endian(CPUARM= State *env) } } =20 +static inline bool bswap_code(bool sctlr_b); + +static inline bool arm_cpu_code_is_big_endian(CPUARMState *env) +{ + return bswap_code(arm_sctlr_b(env)); +} + #include "exec/cpu-all.h" =20 /* diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 71cdc8be50..68ff3c14f8 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -29,7 +29,7 @@ =20 #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ + if (!__r && arm_cpu_code_is_big_endian(env)) { \ (x) =3D bswap32(x); \ } \ __r; \ @@ -37,7 +37,7 @@ =20 #define get_user_code_u16(x, gaddr, env) \ ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ + if (!__r && arm_cpu_code_is_big_endian(env)) { \ (x) =3D bswap16(x); \ } \ __r; \ diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index ec665862d9..0cc056be31 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -29,7 +29,7 @@ =20 #define get_user_code_u32(x, gaddr, env) \ ({ abi_long __r =3D get_user_u32((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ + if (!__r && arm_cpu_code_is_big_endian(env)) { \ (x) =3D bswap32(x); \ } \ __r; \ @@ -37,7 +37,7 @@ =20 #define get_user_code_u16(x, gaddr, env) \ ({ abi_long __r =3D get_user_u16((x), (gaddr)); \ - if (!__r && bswap_code(arm_sctlr_b(env))) { \ + if (!__r && arm_cpu_code_is_big_endian(env)) { \ (x) =3D bswap16(x); \ } \ __r; \ diff --git a/target/arm/cpu.c b/target/arm/cpu.c index 19191c2391..f3198ee2f2 100644 --- a/target/arm/cpu.c +++ b/target/arm/cpu.c @@ -1167,7 +1167,6 @@ static void arm_disas_set_info(CPUState *cpu, disasse= mble_info *info) { ARMCPU *ac =3D ARM_CPU(cpu); CPUARMState *env =3D &ac->env; - bool sctlr_b; =20 if (is_a64(env)) { info->cap_arch =3D CS_ARCH_ARM64; @@ -1194,8 +1193,7 @@ static void arm_disas_set_info(CPUState *cpu, disasse= mble_info *info) info->cap_mode =3D cap_mode; } =20 - sctlr_b =3D arm_sctlr_b(env); - if (bswap_code(sctlr_b)) { + if (arm_cpu_code_is_big_endian(env)) { #if TARGET_BIG_ENDIAN info->endian =3D BFD_ENDIAN_LITTLE; #else @@ -1204,7 +1202,7 @@ static void arm_disas_set_info(CPUState *cpu, disasse= mble_info *info) } info->flags &=3D ~INSN_ARM_BE32; #ifndef CONFIG_USER_ONLY - if (sctlr_b) { + if (arm_sctlr_b(env)) { info->flags |=3D INSN_ARM_BE32; } #endif --=20 2.45.2 From nobody Sun Nov 24 01:33:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1727734406; cv=none; d=zohomail.com; s=zohoarc; b=DRrrzsRzwK04a7S66MhG2xiAUA+Put6/9A5SS13bIeiBjjk8LGcJtxFrbPZt47zcPITs0fgkBM/xkHnmJsXgElHuAm3ZQjhFg9aUcT7H9ZxJQlGfCU+HILWcG4x7zIxVQfG734yGP0OSJgtNZ4XxuXyj4H4qhGKy8+BTOZ1iTrg= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727734406; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; b=XcGQKbKgHQ6prRQN5v2ZVaxpHXg9LKjGCVCRHRcQwc5bATXkMQDx+MXQbfKif0w7QCfCvtZAD1GWmB0k0yB3jSB9gn9bplOHCmd4kZL4GQZWnjWn8kLGtgotD8RcYeCs5wmnrIKqTthO5VlKaR9caJqMB2G227xgvXajOCVCofo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1727734406270135.58447391805328; Mon, 30 Sep 2024 15:13:26 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svOd3-0003NE-UA; Mon, 30 Sep 2024 18:12:29 -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 1svOd2-0003MF-Ng for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:28 -0400 Received: from mail-ej1-x62f.google.com ([2a00:1450:4864:20::62f]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svOd1-0002fi-0s for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:28 -0400 Received: by mail-ej1-x62f.google.com with SMTP id a640c23a62f3a-a8d2daa2262so558028366b.1 for ; Mon, 30 Sep 2024 15:12:26 -0700 (PDT) Received: from localhost.localdomain (46.170.88.92.rev.sfr.net. [92.88.170.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c299ac60sm596492866b.221.2024.09.30.15.12.22 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Sep 2024 15:12:24 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727734345; x=1728339145; darn=nongnu.org; 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=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; b=oSF4xcxeKpE9rOxFKXgwYX/rgsKqXmEebX3rX+TPysuaXUbwll4HfpAr9tDt8ugRZ1 QbLlLPuC5APuBkiiEpF71ap/Ry8PeWohncBn0Dw4FekV78+YuDOwkMfyz9fotNg1RGb7 Av2+7KEB9zVA+M/TWs+JLLhQ27RGKjjUxRnem1Bwmqy7oc4vuHoeluQHBXQTLgbcWtP/ yMtfv8an3VCF5hAHWco6y3J2bdXCSsv68umCbCp9+1M0OwrknQxkyMZfsSQbQt49iZmd PBTP8BoXKiojN3ghkZzU1eyfeX2XoXuyVWEkAtaXA3gwt5uNYUlGqSnGh7vpJfgeWNWT 0Z6A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727734345; x=1728339145; 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=grjpT5kTsMGjq3j1/lhkj4QBsxYe83DKBpMh5569Dgk=; b=OKi7Zl/qH9HKov04XGwsy6ohN+34NO/+Bu1YrrHDPcuZjyHzC3UocdSBh8O6HbjeT+ gkltoAiXeuf69ekI0N91TjeICiX4QQ2I8KifVwhXWfucUT+9rvZlw5o7ioDaUVLbhjWD povbnMxt0nGuH69tdmFln32o1kiPyTvjhfx3mSkC1UTBEI8lZVLwPpcNDzBwwkliXQ1x K8hAqtD2cOpgvlfvmxEMxxnoDS841wbgr8J74YJtYfMBh+dhDp4doD8XfFfWo7SaZ99n muTuv5FgYBR2EXiAkDuO8WV+ntDRi5SNxykFvcIUStwxxz0xAr7t0pacj6/wHJMmLimn vZXQ== X-Gm-Message-State: AOJu0YzYAcvJACtVIf3nvTUxS7lPfJbu8ra8Jgp+oLKaKw4DosfDogbG MJjtX7WYgd3hTlZG2o4HGGSLls1qVPcKYNj1qdl9JuJ2mvkLK+jaBlkxxNFutwT3lkf6TLNyi1L DnIE= X-Google-Smtp-Source: AGHT+IEPcXLt1smhJ29KzmCwdkPXbe7bSABmFoFrN9SDqqX5WbSIEsUbxQdEZD9tZa3e3hF5oGDGhA== X-Received: by 2002:a17:907:928b:b0:a89:f5f6:395 with SMTP id a640c23a62f3a-a93c48f0902mr1722277466b.1.1727734344660; Mon, 30 Sep 2024 15:12:24 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Peter Maydell , Thomas Huth , Hao Wu , Laurent Vivier , Joel Stanley , qemu-arm@nongnu.org, Andrew Jeffery , Steven Lee , Tyrone Ting , "Edgar E. Iglesias" , Igor Mitsyanko , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Jamin Lin , Troy Lee , Anton Johansson Subject: [PATCH 2/3] hw/arm: Have arm_write_bootloader() take a ARMCPU argument Date: Tue, 1 Oct 2024 00:12:03 +0200 Message-ID: <20240930221205.59101-3-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240930221205.59101-1-philmd@linaro.org> References: <20240930221205.59101-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::62f; envelope-from=philmd@linaro.org; helo=mail-ej1-x62f.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 autolearn=unavailable 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1727734407445116600 The next commit will replace tswap32() calls by stl_endian_p() ones in bootloader.c. In order to do that, we'll need to know the vCPU endianness. This information is retrievable with arm_cpu_code_is_big_endian(), but we need to access CPUARMState. As a first step, pass ARMCPU as argument to arm_write_bootloader() so it'll be able to access cpu->env. Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- include/hw/arm/boot.h | 9 ++++++--- hw/arm/aspeed.c | 3 +-- hw/arm/boot.c | 9 +++++---- hw/arm/raspi.c | 4 ++-- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/include/hw/arm/boot.h b/include/hw/arm/boot.h index 80c492d742..3d1226ab00 100644 --- a/include/hw/arm/boot.h +++ b/include/hw/arm/boot.h @@ -206,13 +206,15 @@ typedef struct ARMInsnFixup { /** * arm_write_bootloader - write a bootloader to guest memory * @name: name of the bootloader blob - * @as: AddressSpace to write the bootloader + * @cpu: handle to the first CPU object + * @info: handle to the boot info struct * @addr: guest address to write it * @insns: the blob to be loaded * @fixupcontext: context to be used for any fixups in @insns * * Write a bootloader to guest memory at address @addr in the address - * space @as. @name is the name to use for the resulting ROM blob, so + * space returned by @arm_boot_address_space(). + * @name is the name to use for the resulting ROM blob, so * it should be unique in the system and reasonably identifiable for debug= ging. * * @insns must be an array of ARMInsnFixup structs, each of which has @@ -228,7 +230,8 @@ typedef struct ARMInsnFixup { * the entries that @insns refers to. */ void arm_write_bootloader(const char *name, - AddressSpace *as, hwaddr addr, + ARMCPU *cpu, const struct arm_boot_info *info, + hwaddr addr, const ARMInsnFixup *insns, const uint32_t *fixupcontext); =20 diff --git a/hw/arm/aspeed.c b/hw/arm/aspeed.c index cf0c6c580b..cf5fb92238 100644 --- a/hw/arm/aspeed.c +++ b/hw/arm/aspeed.c @@ -217,7 +217,6 @@ struct AspeedMachineState { static void aspeed_write_smpboot(ARMCPU *cpu, const struct arm_boot_info *info) { - AddressSpace *as =3D arm_boot_address_space(cpu, info); static const ARMInsnFixup poll_mailbox_ready[] =3D { /* * r2 =3D per-cpu go sign value @@ -244,7 +243,7 @@ static void aspeed_write_smpboot(ARMCPU *cpu, }; static const uint32_t fixupcontext[FIXUP_MAX] =3D { 0 }; =20 - arm_write_bootloader("aspeed.smpboot", as, info->smp_loader_start, + arm_write_bootloader("aspeed.smpboot", cpu, info, info->smp_loader_sta= rt, poll_mailbox_ready, fixupcontext); } =20 diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 5301d8d318..6efd21f9c2 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -131,10 +131,12 @@ static const ARMInsnFixup smpboot[] =3D { }; =20 void arm_write_bootloader(const char *name, - AddressSpace *as, hwaddr addr, + ARMCPU *cpu, const struct arm_boot_info *info, + hwaddr addr, const ARMInsnFixup *insns, const uint32_t *fixupcontext) { + AddressSpace *as =3D arm_boot_address_space(cpu, info); /* Fix up the specified bootloader fragment and write it into * guest memory using rom_add_blob_fixed(). fixupcontext is * an array giving the values to write in for the fixup types @@ -185,7 +187,6 @@ static void default_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { uint32_t fixupcontext[FIXUP_MAX]; - AddressSpace *as =3D arm_boot_address_space(cpu, info); =20 fixupcontext[FIXUP_GIC_CPU_IF] =3D info->gic_cpu_if_addr; fixupcontext[FIXUP_BOOTREG] =3D info->smp_bootreg_addr; @@ -195,7 +196,7 @@ static void default_write_secondary(ARMCPU *cpu, fixupcontext[FIXUP_DSB] =3D CP15_DSB_INSN; } =20 - arm_write_bootloader("smpboot", as, info->smp_loader_start, + arm_write_bootloader("smpboot", cpu, info, info->smp_loader_start, smpboot, fixupcontext); } =20 @@ -1128,7 +1129,7 @@ static void arm_setup_direct_kernel_boot(ARMCPU *cpu, fixupcontext[FIXUP_ENTRYPOINT_LO] =3D entry; fixupcontext[FIXUP_ENTRYPOINT_HI] =3D entry >> 32; =20 - arm_write_bootloader("bootloader", as, info->loader_start, + arm_write_bootloader("bootloader", cpu, info, info->loader_start, primary_loader, fixupcontext); =20 if (info->write_board_setup) { diff --git a/hw/arm/raspi.c b/hw/arm/raspi.c index a7a662f40d..84fffe2a02 100644 --- a/hw/arm/raspi.c +++ b/hw/arm/raspi.c @@ -137,7 +137,7 @@ static void write_smpboot(ARMCPU *cpu, const struct arm= _boot_info *info) QEMU_BUILD_BUG_ON((BOARDSETUP_ADDR & 0xf) !=3D 0 || (BOARDSETUP_ADDR >> 4) >=3D 0x100); =20 - arm_write_bootloader("raspi_smpboot", arm_boot_address_space(cpu, info= ), + arm_write_bootloader("raspi_smpboot", cpu, info, info->smp_loader_start, smpboot, fixupcontext); } =20 @@ -172,7 +172,7 @@ static void write_smpboot64(ARMCPU *cpu, const struct a= rm_boot_info *info) 0, 0, 0, 0 }; =20 - arm_write_bootloader("raspi_smpboot", as, info->smp_loader_start, + arm_write_bootloader("raspi_smpboot", cpu, info, info->smp_loader_star= t, smpboot, fixupcontext); rom_add_blob_fixed_as("raspi_spintables", spintables, sizeof(spintable= s), SPINTABLE_ADDR, as); --=20 2.45.2 From nobody Sun Nov 24 01:33:51 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1727734377; cv=none; d=zohomail.com; s=zohoarc; b=cumckt6w66x30D9CHmdg420NTW+nDaJBnYYtKJIpKfQ3v9iM33NUPyrmL7tJeZHDiZzIJMxbt54EImGWAfO8dNTfkMt0bmufI5bDwjjL4iwd/8+CiND78TgvH8Wxzm5G+5MlQaL8FH/U0hgeOuZZCu1rlRP4LTzIFoXyevUSwAM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1727734377; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=HzCOrw2J8efbxyRT08lYiOJpbQM+5XRqm9RS7QcrOb4=; b=aYpbLk41qumGTdN9N3MYlOl5KZHZqbqYq7Hu+8tGhdphkqBvqQTF29ZIEa8MA5vYQZAOM208L/OfY5P2pvU8Xyf6/5bBKux74FVRaOvLyegOHYTWFFm4GrfLMEBylgZUwwWffHUPg6IwICjSWhvyggqklwxojN3VA3K8hRtlkfI= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1727734377339493.92068234374824; Mon, 30 Sep 2024 15:12:57 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1svOdF-0004GB-Dd; Mon, 30 Sep 2024 18:12:41 -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 1svOdA-0003rm-I6 for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:38 -0400 Received: from mail-ej1-x629.google.com ([2a00:1450:4864:20::629]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1svOd8-0002gQ-KY for qemu-devel@nongnu.org; Mon, 30 Sep 2024 18:12:36 -0400 Received: by mail-ej1-x629.google.com with SMTP id a640c23a62f3a-a93b2070e0cso588143166b.3 for ; Mon, 30 Sep 2024 15:12:33 -0700 (PDT) Received: from localhost.localdomain (46.170.88.92.rev.sfr.net. [92.88.170.46]) by smtp.gmail.com with ESMTPSA id a640c23a62f3a-a93c2978c18sm604258966b.148.2024.09.30.15.12.29 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Mon, 30 Sep 2024 15:12:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1727734352; x=1728339152; darn=nongnu.org; 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=HzCOrw2J8efbxyRT08lYiOJpbQM+5XRqm9RS7QcrOb4=; b=cOZizfa+SKxWIhQzfChNsB/qWHNY5eY8f+41uwRogK7Ogo3kXzA+uhWQRLgHZZek/B ro3xSMqPXqJcStLdLd1tqcDWUyqG+kJGjaROU/TAKVIwBgABpnhSe/bAOkobb9Z1xhlq TN3vTJZVE8oKaVEUTbmAXbrLwOKtUuuHg+2gNfLHtgnau4I21VWFSuf0OWoq59FUUwJu kiz9L2KmRq8X86Qc2Pb6VLRDnqDbnlkJX+c0gqwyiCo7aVM1/ylGiNm2eJYSGAQSyoz8 AyICWebyCRDvGzrB0snsnIHkJ3QKWyo61T1Tt8Ppjj7H3V4jkhxxSHkJlmqcnZJRZSlU foLg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1727734352; x=1728339152; 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=HzCOrw2J8efbxyRT08lYiOJpbQM+5XRqm9RS7QcrOb4=; b=LCqYalZhJz3U4L8c9wy7nTp8yNvIroc0LWQxZdjcpXKQDC/VtBayxiA9ShW9g2i6vj 0WaB0YVr63XvHKigai93bMDPyxq5hP3IRy8YAjf9D4Q1TY7S4Yg1b6qdIHiiLgm5YFSs 7gYPqv5E5s9g1voSnHCOZ1FNA3hsaa9ZNE13PxRo5Ldo7nYL+gYHwfIwAiARYcM3evR0 mTUzdiB6SdnqVA27Jyp7IzroKl+Y1S3EFm+URMqzTEV/qRWdiYcdYMwDqe67VO/xT3x5 95oqDChV5z9vl4rFI29w785FJ474uT8NiWbPUkw1X7/QP5uo5H80YXYQBxertqheo/iN GBPQ== X-Gm-Message-State: AOJu0YyKiB6u/aFESfN8hJ92tRQyXLjqf7FGBbRbXRNb/hokBFhzq4QB Lyjj1H8ozojIsh33Fg8/iH7JgHtSlsyBizkCEgGLb6p3PoeX8kxiUFnBBlDymVtUVA/D3vkLsZ5 W5t4= X-Google-Smtp-Source: AGHT+IHYen01M9wUzFbyMYNCpGCVFRY4BAhu5eAcrztfOElg9Xk0+IrqBQrjgwjo66yzaFX2I2MMMA== X-Received: by 2002:a17:907:3f0e:b0:a7d:a00a:aa02 with SMTP id a640c23a62f3a-a93c48f1ba0mr1555258766b.1.1727734351755; Mon, 30 Sep 2024 15:12:31 -0700 (PDT) From: =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= To: qemu-devel@nongnu.org Cc: Alistair Francis , Peter Maydell , Thomas Huth , Hao Wu , Laurent Vivier , Joel Stanley , qemu-arm@nongnu.org, Andrew Jeffery , Steven Lee , Tyrone Ting , "Edgar E. Iglesias" , Igor Mitsyanko , =?UTF-8?q?Philippe=20Mathieu-Daud=C3=A9?= , =?UTF-8?q?C=C3=A9dric=20Le=20Goater?= , Jamin Lin , Troy Lee , Anton Johansson Subject: [PATCH 3/3] hw/arm: Replace tswap32() calls by target agnostic stl_endian_p() Date: Tue, 1 Oct 2024 00:12:04 +0200 Message-ID: <20240930221205.59101-4-philmd@linaro.org> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240930221205.59101-1-philmd@linaro.org> References: <20240930221205.59101-1-philmd@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: pass client-ip=2a00:1450:4864:20::629; envelope-from=philmd@linaro.org; helo=mail-ej1-x629.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 autolearn=unavailable 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+importer=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1727734379416116600 Replace the target-specific tswap32() calls by stl_endian_p() which does the same but takes the endianness as argument, thus is target-agnostic. Get the vCPU endianness calling arm_cpu_code_is_big_endian(). Signed-off-by: Philippe Mathieu-Daud=C3=A9 --- hw/arm/boot.c | 8 +++++--- hw/arm/exynos4210.c | 7 +++---- hw/arm/npcm7xx.c | 6 ++++-- hw/arm/xilinx_zynq.c | 5 +++-- 4 files changed, 15 insertions(+), 11 deletions(-) diff --git a/hw/arm/boot.c b/hw/arm/boot.c index 6efd21f9c2..6e8dc00e6d 100644 --- a/hw/arm/boot.c +++ b/hw/arm/boot.c @@ -137,6 +137,7 @@ void arm_write_bootloader(const char *name, const uint32_t *fixupcontext) { AddressSpace *as =3D arm_boot_address_space(cpu, info); + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); /* Fix up the specified bootloader fragment and write it into * guest memory using rom_add_blob_fixed(). fixupcontext is * an array giving the values to write in for the fixup types @@ -173,7 +174,7 @@ void arm_write_bootloader(const char *name, default: abort(); } - code[i] =3D tswap32(insn); + stl_endian_p(be, &code[i], insn); } =20 assert((len * sizeof(uint32_t)) < BOOTLOADER_MAX_SIZE); @@ -205,6 +206,7 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *cpu, hwaddr mvbar_addr) { AddressSpace *as =3D arm_boot_address_space(cpu, info); + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); int n; uint32_t mvbar_blob[] =3D { /* mvbar_addr: secure monitor vectors @@ -243,13 +245,13 @@ void arm_write_secure_board_setup_dummy_smc(ARMCPU *c= pu, || (info->board_setup_addr + sizeof(board_setup_blob) <=3D mvbar= _addr)); =20 for (n =3D 0; n < ARRAY_SIZE(mvbar_blob); n++) { - mvbar_blob[n] =3D tswap32(mvbar_blob[n]); + stl_endian_p(be, &mvbar_blob[n], mvbar_blob[n]); } rom_add_blob_fixed_as("board-setup-mvbar", mvbar_blob, sizeof(mvbar_bl= ob), mvbar_addr, as); =20 for (n =3D 0; n < ARRAY_SIZE(board_setup_blob); n++) { - board_setup_blob[n] =3D tswap32(board_setup_blob[n]); + stl_endian_p(be, &board_setup_blob[n], board_setup_blob[n]); } rom_add_blob_fixed_as("board-setup", board_setup_blob, sizeof(board_setup_blob), info->board_setup_addr= , as); diff --git a/hw/arm/exynos4210.c b/hw/arm/exynos4210.c index e3f1de2631..78e3fae3c1 100644 --- a/hw/arm/exynos4210.c +++ b/hw/arm/exynos4210.c @@ -23,7 +23,6 @@ =20 #include "qemu/osdep.h" #include "qapi/error.h" -#include "exec/tswap.h" #include "cpu.h" #include "hw/cpu/a9mpcore.h" #include "hw/irq.h" @@ -473,7 +472,7 @@ static const MemoryRegionOps exynos4210_chipid_and_omr_= ops =3D { void exynos4210_write_secondary(ARMCPU *cpu, const struct arm_boot_info *info) { - int n; + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); uint32_t smpboot[] =3D { 0xe59f3034, /* ldr r3, External gic_cpu_if */ 0xe59f2034, /* ldr r2, Internal gic_cpu_if */ @@ -496,8 +495,8 @@ void exynos4210_write_secondary(ARMCPU *cpu, }; smpboot[ARRAY_SIZE(smpboot) - 1] =3D info->smp_bootreg_addr; smpboot[ARRAY_SIZE(smpboot) - 2] =3D info->gic_cpu_if_addr; - for (n =3D 0; n < ARRAY_SIZE(smpboot); n++) { - smpboot[n] =3D tswap32(smpboot[n]); + for (int n =3D 0; n < ARRAY_SIZE(smpboot); n++) { + stl_endian_p(be, &smpboot[n], smpboot[n]); } rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), info->smp_loader_start); diff --git a/hw/arm/npcm7xx.c b/hw/arm/npcm7xx.c index cb7791301b..6afdbf1598 100644 --- a/hw/arm/npcm7xx.c +++ b/hw/arm/npcm7xx.c @@ -309,6 +309,7 @@ static const struct { static void npcm7xx_write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) { + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); uint32_t board_setup[] =3D { 0xe59f0010, /* ldr r0, clk_base_addr */ 0xe59f1010, /* ldr r1, pllcon1_value */ @@ -323,7 +324,7 @@ static void npcm7xx_write_board_setup(ARMCPU *cpu, int i; =20 for (i =3D 0; i < ARRAY_SIZE(board_setup); i++) { - board_setup[i] =3D tswap32(board_setup[i]); + stl_endian_p(be, &board_setup[i], board_setup[i]); } rom_add_blob_fixed("board-setup", board_setup, sizeof(board_setup), info->board_setup_addr); @@ -332,6 +333,7 @@ static void npcm7xx_write_board_setup(ARMCPU *cpu, static void npcm7xx_write_secondary_boot(ARMCPU *cpu, const struct arm_boot_info *info) { + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); /* * The default smpboot stub halts the secondary CPU with a 'wfi' * instruction, but the arch/arm/mach-npcm/platsmp.c in the Linux kern= el @@ -353,7 +355,7 @@ static void npcm7xx_write_secondary_boot(ARMCPU *cpu, int i; =20 for (i =3D 0; i < ARRAY_SIZE(smpboot); i++) { - smpboot[i] =3D tswap32(smpboot[i]); + stl_endian_p(be, &smpboot[i], smpboot[i]); } =20 rom_add_blob_fixed("smpboot", smpboot, sizeof(smpboot), diff --git a/hw/arm/xilinx_zynq.c b/hw/arm/xilinx_zynq.c index 37c234f5ab..0d6e246543 100644 --- a/hw/arm/xilinx_zynq.c +++ b/hw/arm/xilinx_zynq.c @@ -36,9 +36,9 @@ #include "hw/qdev-clock.h" #include "sysemu/reset.h" #include "qom/object.h" -#include "exec/tswap.h" #include "target/arm/cpu-qom.h" #include "qapi/visitor.h" +#include "cpu.h" =20 #define TYPE_ZYNQ_MACHINE MACHINE_TYPE_NAME("xilinx-zynq-a9") OBJECT_DECLARE_SIMPLE_TYPE(ZynqMachineState, ZYNQ_MACHINE) @@ -97,6 +97,7 @@ struct ZynqMachineState { static void zynq_write_board_setup(ARMCPU *cpu, const struct arm_boot_info *info) { + bool be =3D arm_cpu_code_is_big_endian(&cpu->env); int n; uint32_t board_setup_blob[] =3D { 0xe3a004f8, /* mov r0, #0xf8000000 */ @@ -106,7 +107,7 @@ static void zynq_write_board_setup(ARMCPU *cpu, 0xe12fff1e, /* bx lr */ }; for (n =3D 0; n < ARRAY_SIZE(board_setup_blob); n++) { - board_setup_blob[n] =3D tswap32(board_setup_blob[n]); + stl_endian_p(be, &board_setup_blob[n], board_setup_blob[n]); } rom_add_blob_fixed("board-setup", board_setup_blob, sizeof(board_setup_blob), BOARD_SETUP_ADDR); --=20 2.45.2