From patchwork Thu Aug 29 20:13:52 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Samuel Holland X-Patchwork-Id: 1978618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=fQslmQXV; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=sifive.com header.i=@sifive.com header.a=rsa-sha256 header.s=google header.b=lnExrHqK; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:3::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=patchwork.ozlabs.org) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:3::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4Wvsw326Dxz1yfn for ; Fri, 30 Aug 2024 06:15:15 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:To :From:Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=D9yKBAIFO/kQhBkVqGA9DLniO0cRo56wc/jUNaATT7g=; b=fQslmQXV3u+KSk Pz2B9IUDC+ZApM4TDvijSrpJOXDN9EP8rze/+tSgI9Q8gf7zrUamwqeYySF9DzNxiyfHxBrI+zKCv 2Lmp4nZYAuTUR84AhVZmw/gyv4wy/pzk08tB6kngIj52W6FHjn373S0tflgTF8kJGdua14SIk2xMe zX5cg3KOeGWkY5++Bv4vr5DCbKggOUi//biFmULFJOpYoHg6J68OPNcySpHP2XWB9JImznaMLdTkw Oc2iqFjCfxcrTLmJrHHzkczzE2+18YXdg8ra0h+9NIe9KclVDQ1lyuOTzVhbZKaO+CtImKfJlTlps MEsP3OAuypsQrLI6pwiw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlXw-00000003VEP-1cNO; Thu, 29 Aug 2024 20:15:08 +0000 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1sjlWw-00000003V5Y-1S6i for opensbi@lists.infradead.org; Thu, 29 Aug 2024 20:14:07 +0000 Received: by mail-pf1-x434.google.com with SMTP id d2e1a72fcca58-70cec4aa1e4so760445b3a.1 for ; Thu, 29 Aug 2024 13:14:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1724962445; x=1725567245; darn=lists.infradead.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=53/IgwWqc++78Gl4dbOyaATtZEhAeMCG2CdNJSAnq64=; b=lnExrHqKkEx4kIdefiaPlsCpP65xp/sdXX08wVGSdaIXLiURLUYYcUNWf3Pg44eZzJ 9QXvkzx4erluhbwoUFOq3pNc24DOrGputCtgnhNaDu+8eoz/7LTEZnXHe4Dfp4tvytYq /aNvTQG7Sscc2WvoEzWEOPRCRtG+rsgnp65iieBDsw+Hu205ueuYkFc/IKFyjZGWuTxj EyTPiS3mT6D6x3MMit88dSQSrr0v4DwdlevE4K18j0GFXmdk9Xi7W9UV1Lt9eqnNEFqz lA5+JtHiphFobuOOYqNp/Cc8Llxg6PRcK2BBt9uMvbhb+CbRcejw/1O9canjy5VkpGR6 tAkA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1724962445; x=1725567245; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=53/IgwWqc++78Gl4dbOyaATtZEhAeMCG2CdNJSAnq64=; b=jamdSrQeemE79UBfBEetDBqproLxTLkIXwbhGDt0HYHvCMRXrRojjqkiIN5w7SPxCt vJAyl0SFSWS0qsgJ5M7qCxeJF4csYVsVGySEugMBXvTex5KDY4OK5XKKE5oKQ/RK1D5Q med61Q2S/Nh/7agHVUnmq+fFB7mZK2v8AJOYJJT6K8uq1A/h2UV52EoFu6G3UPBBh14P i2XlDAfBIZnelzohWPrr5vfqpuXhATSX3B25GnWZnpaDKHpSA7BsGfI7/Iw2kptG9ukn kiPpWguKIwRVi/xPGf06N8wtIswcE2YmJ23gPDpAo4BTk5HEIB8J1oDr8bELXV+nY3Vq GAoQ== X-Gm-Message-State: AOJu0Yz7yk+7N4enb1HejNWsMh51ViNrWzwReGCnYmQmKIAf3FRHvMw6 QjADE4XNrsxTFBaar/QQ4qkz1J7PqvQ/XaOUkiGS0nXuoXfZVzSSn1xy5jmuOWI8D2iZgMSbaoj VqnPqc9gm9dFJjYq0EmPpk/rnqt1IuHRmEB9HCo9b41KQIdAW0we+GYImmeN++O85ONPVgu2DAN CXSBSAZb6+eYGDw+eJ98XY3aeGy3vXEkMun+LLrUGlY2uBdTP9fzc= X-Google-Smtp-Source: AGHT+IEPEd+sV2A+VpBMO1GQSuF/MZycbLmCxvE1f2gpr0p5y80w0uQ9gZioG3nGP3yPpqBQVmODjQ== X-Received: by 2002:a05:6a21:3941:b0:1c0:f5fa:cbe6 with SMTP id adf61e73a8af0-1cce1010186mr3743635637.22.1724962445220; Thu, 29 Aug 2024 13:14:05 -0700 (PDT) Received: from sw06.internal.sifive.com ([4.53.31.132]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-715e56d751asm1513813b3a.169.2024.08.29.13.14.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 29 Aug 2024 13:14:04 -0700 (PDT) From: Samuel Holland To: opensbi@lists.infradead.org Subject: [PATCH] firmware: Simplify FDT header endianness conversion Date: Thu, 29 Aug 2024 13:13:52 -0700 Message-ID: <20240829201403.3658798-1-samuel.holland@sifive.com> X-Mailer: git-send-email 2.45.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240829_131406_417294_13556F9F X-CRM114-Status: UNSURE ( 8.48 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -2.1 (--) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: Reduce the code size by using single-byte loads instead of bit manipulation. This method also does the right thing on (hypothetical) big-endian systems. Signed-off-by: Samuel Holland --- Content analysis details: (-2.1 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:434 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.0 T_SCC_BODY_TEXT_LINE No description available. X-BeenThere: opensbi@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "opensbi" Errors-To: opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Reduce the code size by using single-byte loads instead of bit manipulation. This method also does the right thing on (hypothetical) big-endian systems. Signed-off-by: Samuel Holland --- firmware/fw_base.S | 26 +++++--------------------- 1 file changed, 5 insertions(+), 21 deletions(-) diff --git a/firmware/fw_base.S b/firmware/fw_base.S index b950c0b8..0b58cc42 100644 --- a/firmware/fw_base.S +++ b/firmware/fw_base.S @@ -242,30 +242,14 @@ _scratch_init: beq t1, a1, _fdt_reloc_done /* t0 = source FDT start address */ add t0, a1, zero - /* t2 = source FDT size in big-endian */ -#if __riscv_xlen > 32 - lwu t2, 4(t0) -#else - lw t2, 4(t0) -#endif - /* t3 = bit[15:8] of FDT size */ - add t3, t2, zero - srli t3, t3, 16 - and t3, t3, a4 + /* t2 = source FDT size (convert from big-endian) */ + lbu t2, 7(t0) + lbu t3, 6(t0) + lbu t4, 5(t0) + lbu t5, 4(t0) slli t3, t3, 8 - /* t4 = bit[23:16] of FDT size */ - add t4, t2, zero - srli t4, t4, 8 - and t4, t4, a4 slli t4, t4, 16 - /* t5 = bit[31:24] of FDT size */ - add t5, t2, zero - and t5, t5, a4 slli t5, t5, 24 - /* t2 = bit[7:0] of FDT size */ - srli t2, t2, 24 - and t2, t2, a4 - /* t2 = FDT size in little-endian */ or t2, t2, t3 or t2, t2, t4 or t2, t2, t5