From nobody Mon May 12 01:38:44 2025
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=flygoat.com
ARC-Seal: i=1; a=rsa-sha256; t=1735050331; cv=none;
	d=zohomail.com; s=zohoarc;
	b=QwrhMmkatJ/r0j3gijLNuZ5ayXsVdsXqpNRbPDwLx79wctp2Xmvi7s7HIxEGwJn6uKZtVUdGjLSoXRNEHvQE8B9D53r9vZFBK5LrxoPs9VgpYXgyS5kjIX97ahWY/WqQYlZuJPFdCU/D8uWaHUjGXHZOcOZHK0e6JjQnEt1otiE=
ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com;
 s=zohoarc;
	t=1735050331;
 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=3qYAndq7s0eBH/drwPl9cVRryaUciC46E2g6bJ91r28=;
	b=hxa42ZI7qpne7CiWeigsSWa8+M5W2JhDALG9HbUJ2wxAuQD4S00EEJuW3QB1V5M3eQOreYTl2gKZ6kmpVir7lS5Uf/DhijvzK72hHQUmEsaWChaKlF802lvS/25+A5LCw1xD++NpZB3f0WfcMdXY0nZQ3ZyBJVfZcussSKC8SqA=
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=<jiaxun.yang@flygoat.com> (p=none dis=none)
Return-Path: <qemu-devel-bounces+importer=patchew.org@nongnu.org>
Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by
 mx.zohomail.com
	with SMTPS id 17350503309475.395833290351447;
 Tue, 24 Dec 2024 06:25:30 -0800 (PST)
Received: from localhost ([::1] helo=lists1p.gnu.org)
	by lists.gnu.org with esmtp (Exim 4.90_1)
	(envelope-from <qemu-devel-bounces@nongnu.org>)
	id 1tQ5pd-0006dT-1Z; Tue, 24 Dec 2024 09:24:21 -0500
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 <jiaxun.yang@flygoat.com>)
 id 1tQ5pT-0006cG-UP
 for qemu-devel@nongnu.org; Tue, 24 Dec 2024 09:24:12 -0500
Received: from fout-b3-smtp.messagingengine.com ([202.12.124.146])
 by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256)
 (Exim 4.90_1) (envelope-from <jiaxun.yang@flygoat.com>)
 id 1tQ5pR-0005LE-K2
 for qemu-devel@nongnu.org; Tue, 24 Dec 2024 09:24:11 -0500
Received: from phl-compute-02.internal (phl-compute-02.phl.internal
 [10.202.2.42])
 by mailfout.stl.internal (Postfix) with ESMTP id D11DF11401A1;
 Tue, 24 Dec 2024 09:24:08 -0500 (EST)
Received: from phl-mailfrontend-02 ([10.202.2.163])
 by phl-compute-02.internal (MEProxy); Tue, 24 Dec 2024 09:24:08 -0500
Received: by mail.messagingengine.com (Postfix) with ESMTPA; Tue,
 24 Dec 2024 09:24:07 -0500 (EST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=flygoat.com; h=
 cc:cc:content-transfer-encoding:content-type:content-type:date
 :date:from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:subject:subject:to:to; s=fm3; t=1735050248;
 x=1735136648; bh=3qYAndq7s0eBH/drwPl9cVRryaUciC46E2g6bJ91r28=; b=
 T7wE2M3vjPOiTEzGj4Yco2ickKsJI14L4dtuE4QFZJM58I/J54/5SCOcIJWuHY5r
 EuxLQzWaykZ/VUsyDOetPcRXUKIv+VkfyirXsdMgqdkwrNU26HdqiYdcJ8y0wDTt
 Hb4/oHmboc+TKlKJ0uP8r5C0b2aO1QWrkPfZ8OR+1E1oZibKK9GVNWZB+eS2fVPy
 sAdFOmzagb2y4hZ1pKIxwl7YQPoP1WIK4BJy8C1k9MoRE4aeIkxL4cuA58/0I6et
 we0H+IEytyjoX55WFAiKSrvNo0fKcrgesGgQqvN683RanGqh6fRsz+LXpmrk3zPH
 OpqLbpzbSSj+qH1wEEarbw==
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=
 messagingengine.com; h=cc:cc:content-transfer-encoding
 :content-type:content-type:date:date:feedback-id:feedback-id
 :from:from:in-reply-to:in-reply-to:message-id:mime-version
 :references:reply-to:subject:subject:to:to:x-me-proxy
 :x-me-sender:x-me-sender:x-sasl-enc; s=fm2; t=1735050248; x=
 1735136648; bh=3qYAndq7s0eBH/drwPl9cVRryaUciC46E2g6bJ91r28=; b=C
 tNIYbcF5LUmJpteeYfkmBcnrf8caImtLSonvTeP8P3a+DZVSN314NgWU06DnHLk1
 l26/6nNhyMldRb/FmszVahv40wM+yBDEsQJwHB7j73MRIl2S1ZubDRBqUGEio2Wo
 sW66j9akMRxzR8UxPJDtWtUQDfJ2KLpT5StNSgrkBbiy5IbmGdsehSM1JGy8vvf1
 +L9EeAnY6VGSm1qeFCt++PlwpAehQaAz1WRXZQjYewgPiGqkyeoDfx6hiXX5ezkR
 SulezZ67d4uCPd52oHxIj/dbJ8nuypf7GKot4jmTErdHdxCZN7LtFKfFJr76+ZNw
 x/4YSIc9q1cd1siUAO4zg==
X-ME-Sender: <xms:CMRqZ7w5yXQ8NTUKcIQ6uh0pI1mYeiQNb726DPwQcaPJAHqy8drUnQ>
 <xme:CMRqZzSZ0gy9YL8ponY6sEN3D7PF-8dVUB7Ax6ry8HK0QkplsI9CzJjg4DRAc0u3t
 RuOvSR-lZ0_dPI2kTU>
X-ME-Received: <xmr:CMRqZ1VLoPbXJoUUtiZP3CWsfmAhkrF6-Z1_cLGpknDr6qmIWZeVQihz>
X-ME-Proxy-Cause: 
 gggruggvucftvghtrhhoucdtuddrgeefuddruddugedgieduucetufdoteggodetrfdotf
 fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdggtfgfnhhsuhgsshgtrhhisggvpdfu
 rfetoffkrfgpnffqhgenuceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnh
 htshculddquddttddmnecujfgurhephfffufggtgfgkfhfjgfvvefosehtjeertdertdej
 necuhfhrohhmpeflihgrgihunhcujggrnhhguceojhhirgiguhhnrdihrghnghesfhhlhi
 hgohgrthdrtghomheqnecuggftrfgrthhtvghrnhepvdekiefhfeevkeeuveetfeelffek
 gedugefhtdduudeghfeuveegffegudekjeelnecuvehluhhsthgvrhfuihiivgeptdenuc
 frrghrrghmpehmrghilhhfrhhomhepjhhirgiguhhnrdihrghnghesfhhlhihgohgrthdr
 tghomhdpnhgspghrtghpthhtohepgedpmhhouggvpehsmhhtphhouhhtpdhrtghpthhtoh
 epghgrohhsohhngheslhhoohhnghhsohhnrdgtnhdprhgtphhtthhopehqvghmuhdquggv
 vhgvlhesnhhonhhgnhhurdhorhhgpdhrtghpthhtohepjhhirgiguhhnrdihrghnghesfh
 hlhihgohgrthdrtghomhdprhgtphhtthhopehmrghosghisghosehlohhonhhgshhonhdr
 tghn
X-ME-Proxy: <xmx:CMRqZ1jdLXPBPn2TZ6JM69o_arayWL2Rs3rfgVjBMzWe7mBeYG4NSw>
 <xmx:CMRqZ9ASyNh6u8fmgGYXQV50W62LHTKLX273c7gzkV1wBYJxsW50vQ>
 <xmx:CMRqZ-J-vUZli-sYSOKIF2NPYnS7wLcQLhp4n0fH4huS8eu9ep9CeQ>
 <xmx:CMRqZ8Cjo8W-4t4iofvpFAT-DXe4OOpqIF7PTMlzgjI8-XO1ecfNxQ>
 <xmx:CMRqZ4_qfVwTxamFPS97B1v7iqqKEP3dpJTsgaNOl98cZDpaSgIcPKLF>
Feedback-ID: ifd894703:Fastmail
From: Jiaxun Yang <jiaxun.yang@flygoat.com>
Date: Tue, 24 Dec 2024 14:24:01 +0000
Subject: [PATCH v3 2/3] hw/loongarch/boot: Take care of host endian for
 boot code
MIME-Version: 1.0
Content-Type: text/plain; charset="utf-8"
Content-Transfer-Encoding: quoted-printable
Message-Id: <20241224-la-booting-v3-2-a15bee060a43@flygoat.com>
References: <20241224-la-booting-v3-0-a15bee060a43@flygoat.com>
In-Reply-To: <20241224-la-booting-v3-0-a15bee060a43@flygoat.com>
To: qemu-devel@nongnu.org
Cc: Song Gao <gaosong@loongson.cn>, Bibo Mao <maobibo@loongson.cn>,
 Jiaxun Yang <jiaxun.yang@flygoat.com>
X-Mailer: b4 0.14.2
X-Developer-Signature: v=1; a=openpgp-sha256; l=6398;
 i=jiaxun.yang@flygoat.com; h=from:subject:message-id;
 bh=qX07bZYD/4hNJTJbuHKhMWse2Akd/h7UJjV6MYQVytQ=;
 b=owGbwMvMwCXmXMhTe71c8zDjabUkhvSsI6yP3tYczpzdF3Zr+qP9v3R9uf5pO+/nPpbX/j9l8
 jyJezImHaUsDGJcDLJiiiwhAkp9GxovLrj+IOsPzBxWJpAhDFycAjCRytOMDP0rZwqV/J5eWzy1
 8eVar0PmGifntGXJXmr8zRI/56+BmS4jQ0fdO68TTrf3b0lSKvjlLbqf//66uy6HSu9PulK1bqv
 5cT4A
X-Developer-Key: i=jiaxun.yang@flygoat.com; a=openpgp;
 fpr=980379BEFEBFBF477EA04EF9C111949073FC0F67
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=202.12.124.146;
 envelope-from=jiaxun.yang@flygoat.com; helo=fout-b3-smtp.messagingengine.com
X-Spam_score_int: -27
X-Spam_score: -2.8
X-Spam_bar: --
X-Spam_report: (-2.8 / 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_LOW=-0.7, RCVD_IN_VALIDITY_RPBL_BLOCKED=0.001,
 RCVD_IN_VALIDITY_SAFE_BLOCKED=0.001, SPF_HELO_PASS=-0.001,
 SPF_PASS=-0.001 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: <qemu-devel.nongnu.org>
List-Unsubscribe: <https://lists.nongnu.org/mailman/options/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=unsubscribe>
List-Archive: <https://lists.nongnu.org/archive/html/qemu-devel>
List-Post: <mailto:qemu-devel@nongnu.org>
List-Help: <mailto:qemu-devel-request@nongnu.org?subject=help>
List-Subscribe: <https://lists.nongnu.org/mailman/listinfo/qemu-devel>,
 <mailto:qemu-devel-request@nongnu.org?subject=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 @flygoat.com)
X-ZM-MESSAGEID: 1735050331601116600

Use stl_p to store instructions so that host endian conversion
will be performed.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 hw/loongarch/boot.c | 99 +++++++++++++++++++++++++++----------------------=
----
 1 file changed, 51 insertions(+), 48 deletions(-)

diff --git a/hw/loongarch/boot.c b/hw/loongarch/boot.c
index 477c40ccb49d45d4d5026d37db0e79f5f2d89d8e..9cb13c1f154cb15373d6fdcbcba=
c883e05472e62 100644
--- a/hw/loongarch/boot.c
+++ b/hw/loongarch/boot.c
@@ -22,53 +22,56 @@ unsigned memmap_entries;
 ram_addr_t initrd_offset;
 uint64_t initrd_size;
=20
-static const unsigned int slave_boot_code[] =3D {
-                  /* Configure reset ebase.                    */
-    0x0400302c,   /* csrwr      $t0, LOONGARCH_CSR_EENTRY      */
-
-                  /* Disable interrupt.                        */
-    0x0380100c,   /* ori        $t0, $zero,0x4                 */
-    0x04000180,   /* csrxchg    $zero, $t0, LOONGARCH_CSR_CRMD */
-
-                  /* Clear mailbox.                            */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x038081ad,   /* ori        $t1, $t1, CORE_BUF_20  */
-    0x06481da0,   /* iocsrwr.d  $zero, $t1                     */
-
-                  /* Enable IPI interrupt.                     */
-    0x1400002c,   /* lu12i.w    $t0, 1(0x1)                    */
-    0x0400118c,   /* csrxchg    $t0, $t0, LOONGARCH_CSR_ECFG   */
-    0x02fffc0c,   /* addi.d     $t0, $r0,-1(0xfff)             */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x038011ad,   /* ori        $t1, $t1, CORE_EN_OFF          */
-    0x064819ac,   /* iocsrwr.w  $t0, $t1                       */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x038081ad,   /* ori        $t1, $t1, CORE_BUF_20          */
-
-                  /* Wait for wakeup  <.L11>:                  */
-    0x06488000,   /* idle       0x0                            */
-    0x03400000,   /* andi       $zero, $zero, 0x0              */
-    0x064809ac,   /* iocsrrd.w  $t0, $t1                       */
-    0x43fff59f,   /* beqz       $t0, -12(0x7ffff4) # 48 <.L11> */
-
-                  /* Read and clear IPI interrupt.             */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x064809ac,   /* iocsrrd.w  $t0, $t1                       */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x038031ad,   /* ori        $t1, $t1, CORE_CLEAR_OFF       */
-    0x064819ac,   /* iocsrwr.w  $t0, $t1                       */
-
-                  /* Disable  IPI interrupt.                   */
-    0x1400002c,   /* lu12i.w    $t0, 1(0x1)                    */
-    0x04001180,   /* csrxchg    $zero, $t0, LOONGARCH_CSR_ECFG */
-
-                  /* Read mail buf and jump to specified entry */
-    0x1400002d,   /* lu12i.w    $t1, 1(0x1)                    */
-    0x038081ad,   /* ori        $t1, $t1, CORE_BUF_20          */
-    0x06480dac,   /* iocsrrd.d  $t0, $t1                       */
-    0x00150181,   /* move       $ra, $t0                       */
-    0x4c000020,   /* jirl       $zero, $ra,0                   */
-};
+static void generate_secondary_boot_code(void *boot_code)
+{
+    uint32_t *p =3D boot_code;
+
+    /* Configure reset ebase. */
+    stl_p(p++, 0x0400302c); /* csrwr      $t0, LOONGARCH_CSR_EENTRY  */
+
+    /* Disable interrupt. */
+    stl_p(p++, 0x0380100c); /* ori        $t0, $zero, 0x4            */
+    stl_p(p++, 0x04000180); /* csrxchg    $zero, $t0, LOONGARCH_CSR_CRMD */
+
+    /* Clear mailbox. */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x038081ad); /* ori        $t1, $t1, CORE_BUF_20      */
+    stl_p(p++, 0x06481da0); /* iocsrwr.d  $zero, $t1                 */
+
+    /* Enable IPI interrupt. */
+    stl_p(p++, 0x1400002c); /* lu12i.w    $t0, 1(0x1)                */
+    stl_p(p++, 0x0400118c); /* csrxchg    $t0, $t0, LOONGARCH_CSR_ECFG */
+    stl_p(p++, 0x02fffc0c); /* addi.d     $t0, $r0, -1(0xfff)        */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x038011ad); /* ori        $t1, $t1, CORE_EN_OFF      */
+    stl_p(p++, 0x064819ac); /* iocsrwr.w  $t0, $t1                   */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x038081ad); /* ori        $t1, $t1, CORE_BUF_20      */
+
+    /* Wait for wakeup <.L11>: */
+    stl_p(p++, 0x06488000); /* idle       0x0                        */
+    stl_p(p++, 0x03400000); /* andi       $zero, $zero, 0x0          */
+    stl_p(p++, 0x064809ac); /* iocsrrd.w  $t0, $t1                   */
+    stl_p(p++, 0x43fff59f); /* beqz       $t0, -12(0x7ffff4) # 48 <.L11> */
+
+    /* Read and clear IPI interrupt. */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x064809ac); /* iocsrrd.w  $t0, $t1                   */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x038031ad); /* ori        $t1, $t1, CORE_CLEAR_OFF   */
+    stl_p(p++, 0x064819ac); /* iocsrwr.w  $t0, $t1                   */
+
+    /* Disable IPI interrupt. */
+    stl_p(p++, 0x1400002c); /* lu12i.w    $t0, 1(0x1)                */
+    stl_p(p++, 0x04001180); /* csrxchg    $zero, $t0, LOONGARCH_CSR_ECFG */
+
+    /* Read mail buf and jump to specified entry. */
+    stl_p(p++, 0x1400002d); /* lu12i.w    $t1, 1(0x1)                */
+    stl_p(p++, 0x038081ad); /* ori        $t1, $t1, CORE_BUF_20      */
+    stl_p(p++, 0x06480dac); /* iocsrrd.d  $t0, $t1                   */
+    stl_p(p++, 0x00150181); /* move       $ra, $t0                   */
+    stl_p(p++, 0x4c000020); /* jirl       $zero, $ra, 0              */
+}
=20
 static inline void *guidcpy(void *dst, const void *src)
 {
@@ -380,7 +383,7 @@ static void loongarch_direct_kernel_boot(struct loongar=
ch_boot_info *info)
=20
     /* Load slave boot code at pflash0 . */
     void *boot_code =3D g_malloc0(VIRT_FLASH0_SIZE);
-    memcpy(boot_code, &slave_boot_code, sizeof(slave_boot_code));
+    generate_secondary_boot_code(boot_code);
     rom_add_blob_fixed("boot_code", boot_code, VIRT_FLASH0_SIZE, VIRT_FLAS=
H0_BASE);
=20
     CPU_FOREACH(cs) {

--=20
2.43.0