From patchwork Tue Nov 30 05:52:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anup Patel X-Patchwork-Id: 1561418 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=34kmcIvC; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=wdc.com header.i=@wdc.com header.a=rsa-sha256 header.s=dkim.wdc.com header.b=NO24fjU6; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=sharedspace.onmicrosoft.com header.i=@sharedspace.onmicrosoft.com header.a=rsa-sha256 header.s=selector2-sharedspace-onmicrosoft-com header.b=zbZX1+O/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.infradead.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=opensbi-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4J3BGj0mGqz9sVc for ; Tue, 30 Nov 2021 16:53:33 +1100 (AEDT) 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:Cc :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=JZ1tq/CNCEXnmlPqoLrXsl07IEEJGF86aI/UuQA2RdM=; b=34kmcIvC7PgX/E e38f1p4ahDjz7Hx3ufCR6yrX0FjM6QwX2hvOYfJtdUfA9N1y66wOLa16ITj6yN68FCJTJiR6y3AVb KG5kalkVVq168WdHTB8I/eYwhSoylCWeAhyz7DiavkAzt6ZiMH1wiTquAIT632d5VqElGbTQV0q7P XfneoSJqvejHCPF6wHXN7RouBwTLrbKDxByVipbi1YwKurIfi7O+PrxoZp6m6Nm5WV0RIpDaqU0f/ vPGJPdM4Oho7ETYnfjWcl3iUU9W1pwXdyg/PwiDSHgsqF9uMhJhYdxjwhjxM1WSZQppfHiRxFmHpV Xlxtt2HvY1m7L2NvfrWw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrw4y-003gXA-66; Tue, 30 Nov 2021 05:53:24 +0000 Received: from esa6.hgst.iphmx.com ([216.71.154.45]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mrw4v-003gWS-Vs for opensbi@lists.infradead.org; Tue, 30 Nov 2021 05:53:23 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1638251602; x=1669787602; h=from:to:cc:subject:date:message-id: content-transfer-encoding:mime-version; bh=p3V9Vbc+eAo5YuUaUhf519e3d44LK6tg1hosN99duL0=; b=NO24fjU6Ilc+rXpknpI6M4bfoTzVpjCdfSyh8Mq2UVSZqab5j5B+8X3/ kJFUyIHaPFuL+BTi/cJGCZMWczgO7MqiaP0ERPmIcnP8UTZajMKtuSQ2q eAuF4a8KOE1kCESvRg+n9Pa+M8o62T30ZMBpJNFWA1PQCh88ERAUSd8JB NzEx7RjaG3sIZGUNd8Dw6o+VOYYeVHWGKx0gjjcYI8vIq5QB4N5P+gaXG dwUSHFcOVcLQVomDzLXoE54QY5n/XeqCHXdErnPVAt/bI062Z5qxNslaA 6qAsmb8UYCpdR7SvWDX7x7xsEpdMq/UPml7fBrJqzOAywVkDM3VgvcMVX w==; X-IronPort-AV: E=Sophos;i="5.87,275,1631548800"; d="scan'208";a="188033170" Received: from mail-dm6nam11lp2169.outbound.protection.outlook.com (HELO NAM11-DM6-obe.outbound.protection.outlook.com) ([104.47.57.169]) by ob1.hgst.iphmx.com with ESMTP; 30 Nov 2021 13:53:18 +0800 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gObehquB0lajSko3TkQF4CjW7Nyy/xkmEV1RJgtESN9XuZpPgNWcWjIIl0JKGhRFGwOZsgLj8im5po2E02yMqjfKLvjGlkm762HtjHspQEaYfajmc18vCbqKQZckkqnqwzNuQc+5E6kBQGADqFEgJQDHiguAeubEVLQhJ+Rx0eZtAkxJdzk+P1c1idHDdM8I521xdlc0WFNg++D4J3DqRK3mfg5fGWd3O8bsgUnZVo9tM1EO3SGRY3y/clqqDuwzwFU7utKNfYw+1lnBQKM59My7Nr0QkU+aUVfZuHRNYwGRhlB34Ki0Xw9yL276mO/0V/B/xASB4riZG02KlU7EnQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=Ig2fXJk5dzRTlncLwGFDXlUTCXDPWSuQ7R0Ghq5Tzuk=; b=GUdqhflOtlix68YSbMbslDv59Zazt70xyCzckmxJPSNzwbleTpmkt0RRMpsjse2ImLR8l0Frj/3HwWLkIRHw40MfGbNA1jsFZoIVmmqUSoQYAzBrnz8XqOyhajNFUfyYePdhd2oU0hTzagQW+FNCX/TLedx5UJ4FkNJNTL4hF5GaDfLsmSCxwRsnzAi6IGyTNVTlNoNBEOC+/mfcgpje5sMoqCGqjRlf836+5tIYSCelig2Q3C6GiEgYRI3VnqU1CFt+sl5iW0WEZvc/3Nq+xqoxen5lR8QyBCijIbonYfQhS+ljuBicrsxPE5Xi2YQnTXclwupAajQwSEbCQgnX/w== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=wdc.com; dmarc=pass action=none header.from=wdc.com; dkim=pass header.d=wdc.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sharedspace.onmicrosoft.com; s=selector2-sharedspace-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=Ig2fXJk5dzRTlncLwGFDXlUTCXDPWSuQ7R0Ghq5Tzuk=; b=zbZX1+O/Nrgogy4mgjqIL9KeSOGDxxS+6vE36Ci2ssqIbFkTl3uOgPGysnp9fXubJk45SpnpI4jGgGa3nS+zM3h6HWJiiV06PhHLGjsMtuaJHQOR5OFpB+yYL9TjSLHcd8rPZoGK/W3y/0WINP0gAzIk/0ng4f9ctia5/E0rpHU= Authentication-Results: dkim=none (message not signed) header.d=none;dmarc=none action=none header.from=wdc.com; Received: from CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) by CO6PR04MB7825.namprd04.prod.outlook.com (2603:10b6:303:13b::9) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.22; Tue, 30 Nov 2021 05:53:16 +0000 Received: from CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97]) by CO6PR04MB7812.namprd04.prod.outlook.com ([fe80::8100:4308:5b21:8d97%9]) with mapi id 15.20.4734.024; Tue, 30 Nov 2021 05:53:16 +0000 From: Anup Patel To: Atish Patra , Alistair Francis Cc: Anup Patel , opensbi@lists.infradead.org, Jessica Clarke , Anup Patel , Xiang W Subject: [PATCH v2] lib: sbi: Improve fatal error handling Date: Tue, 30 Nov 2021 11:22:44 +0530 Message-Id: <20211130055244.505091-1-anup.patel@wdc.com> X-Mailer: git-send-email 2.25.1 X-ClientProxiedBy: MAXPR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:c::19) To CO6PR04MB7812.namprd04.prod.outlook.com (2603:10b6:303:138::6) MIME-Version: 1.0 Received: from wdc.com (122.172.180.32) by MAXPR0101CA0009.INDPRD01.PROD.OUTLOOK.COM (2603:1096:a00:c::19) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.4734.23 via Frontend Transport; Tue, 30 Nov 2021 05:53:14 +0000 X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-Correlation-Id: 21796a4d-09bc-437f-9e8b-08d9b3c5b40c X-MS-TrafficTypeDiagnostic: CO6PR04MB7825: X-Microsoft-Antispam-PRVS: WDCIPOUTBOUND: EOP-TRUE X-MS-Oob-TLC-OOBClassifiers: OLM:534; X-MS-Exchange-SenderADCheck: 1 X-MS-Exchange-AntiSpam-Relay: 0 X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: TRHzjnOS1/jDiUhmQpLqaidT8TPimaeLfZPJ6+WxF5UyVC0G73kTSiqpcJyy2s/erowiz6u4ymNGRSTOSnK+aejlLDQdkUiJ6XBe9ctHtuZIrS0lV1Mh/gpQGO5XUfdQC4rMBzy4UjTNtCEv5wPbuXwBVfW0/PWODPb6v7ZiLkd03PKhNCpT7W3ms3lSSKW14l8xRcHBcTg87aZuX3uvbiz3ns+jBsh18USzU54v3oJAcoIZTGO0HLyi4w72+BAmp2Aib5lgxD+pAPZUsRkRRtuxdIxvebWRpX7ZZ+W86SjLmFotNi7W2v14FfquPQe/nXLXOp87N3HrJZqKXo/1rjwHq8rUMaR/ouDatyprlLnEu3iPKpqDYl0UncTSkBllKj6EuSLHwl/z7y6W9ZkNEwv5HlG208/gztb0siNcuxh0jdOnweSINUIlzPw2GFB3A40QpADX7SXYxrEvZdmanGAFsB4r1RyksEvMacV/XPdgs7swp5uUhSZiNHI1oAKKtpx0Q2ukAaB3CdsORGSPQLZyIbDKBMqFK3wpFu3PvWKdw5TeR+ey1VvtCKr1BCpO9opXyRCq/NdHyIjroycqN5khYYPII9Pjn1vaywh1JqN0jD9ill5pB5fxRL0wFnxXH8delRhoLkTxJm+F66gsNnNf7AVqrTsaRaVJVSHujQvoQFPAJl4mbCAPekjsuSjF+d065gm10KnYP1KJV3SnBSxbdi/Lbg+U2+mnWd/63E8= X-Forefront-Antispam-Report: CIP:255.255.255.255; CTRY:; LANG:en; SCL:1; SRV:; IPV:NLI; SFV:NSPM; H:CO6PR04MB7812.namprd04.prod.outlook.com; PTR:; CAT:NONE; SFS:(4636009)(366004)(4326008)(38350700002)(38100700002)(26005)(36756003)(186003)(55016003)(8936002)(508600001)(8676002)(2906002)(82960400001)(86362001)(110136005)(54906003)(83380400001)(52116002)(7696005)(55236004)(2616005)(6666004)(956004)(44832011)(316002)(5660300002)(66946007)(6636002)(66556008)(8886007)(66476007)(1076003)(525324003); DIR:OUT; SFP:1102; X-MS-Exchange-AntiSpam-MessageData-ChunkCount: 1 X-MS-Exchange-AntiSpam-MessageData-0: dm3VBCqZRVabWSXIMMPptjt1MZ9gbLE6b/Ut/Uc0YKLPX0QYg6EpJUTtPkAzISNx+Yrj8rozQ4DS2CbuuC8aWRM9xKbki7VXLMtiFuUgOUhhHPWWN4B17JGzQ6RbGOmwdYTYk+2yU2zrj0jLaZkMcrYAxhLSbfP+lHTK5ecN7uRpdSoCL+wrw5k4B9Kh/jO/nM/eGdSP4q59Tb50TDQmRzjzSUJeJdTamBDrRVj+V2tULXpooPMmQTTpeV9KNVf6wTUM3cyx4crHUJw5rVen9fDg8uxCoP56gYMQH9JFLhScW6iQKEXm23/GotIA7KIkZshxqKPQCDXLf2OPwtjV/JBnE4WtICCMLDlDlQBl1KbuVfXR7JhN9GmDdpU9pTCWhk81RZGP8njvi7aWJRH1pt2MB9y1IUECZ3aZq+NqwFHYuU2HKWqI4P4uAt9aCNhglxwZfnqLOK0DKAKTLnddLBRl5kZvlzQyFedz0amehTVWJeuMmaA0gGC3jv4GHR0uSPLERNCuGzwfHuDkvf/YIgFc82OCV8v56W1z7zoSYPjwy7iN6sSgC+2UkS5gOlN0SeIW1ygjtyuRy+FqSjUVn3XboXVm7LGBQmyIAFNuOW3y/zyhmfpsW8i0bFr7Nkf/9DjB+SiKrvIjXmi2UpxbOWfeTpZ81TmmzfeZ18WHwGajTRQmghcunHwUvygKJYE9YK7r7KpaUZLhG7FETdSn4qfD9UHOZYXeresyg1NQhgPIJSXkHlHNDSZs821HMRMwieGVCHvU76rWESpDDpQz88ZuZRO2awtge7EwDyQItQBg/vL+2z0uBOhS3MphXMgtjs1Lp9CBLXaUbpshMQLD67uiMahdslCyTCcnVE1/5HXCLigVAW9jBLlEaYDn/NJT0dTZvHn+NOkfCF/SlGXooXZAu4aui5A3zhaxeRY3PS3lPNKy/B2j6tftGsgZsCIC5GnqSwpfqFL2eJFDUI3vEay1l1YS+U9XwNLdKOAC84kgF/nFP5SYwFeGVRtmLqRwwKjjHvienFvGAgaoaV7opya7C7SdPmkSk8TQF93y+LSXXMT975SdmC7nEiymS1CZ0lxpAkEFZVFH5MCgCa9WQu52YqQkAHzWoXsA7UAShuvbNM/CNc6mbg8UCT4Ywyq8m0adAD/sNC5JpW3oR4ErntvpBlfV2aN25CcBlL9w48+vkIJFfUrsTcy4WfVSMHRQMzSid/4YYc/4VMo1Z1SsDk030G5dS0fJpLVNdu6gCSWDtYtQi/V2DhNbsRHQjMCBo8Z6iQ9j01tbYvB08o6ktf1SqjuF32Y65eITP4tUw7pJoyTtH1uaan+my9JMbFyrpj4w7Z4MpngnQVgUg8dF6CD9b5tlmpatz8nRzeQ/yVATiCo5IEnzhVHesloSXY8ENd2cNlZbsLfrs9sF3Z5gdwKkY3lY1Fdsz8QoZ07J3EwSkxZFEDrrheD9iogfHF8r8FagofNAauD3CnmDatrFXPsj/TePPe0bOPLLb/VRDlAtqYWPQnSuidCvCb1/zU0HuISNH9aHMXwEjvY9uaK9/PR/wG3dtHU1AnrlGzc6n56kpxfbv2zJ6DkqqwDbxQvGTI1yh99FzG0/Hp3Z/8sp56zwlZ6al6f/T5B3am8CeMs= X-OriginatorOrg: wdc.com X-MS-Exchange-CrossTenant-Network-Message-Id: 21796a4d-09bc-437f-9e8b-08d9b3c5b40c X-MS-Exchange-CrossTenant-AuthSource: CO6PR04MB7812.namprd04.prod.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Internal X-MS-Exchange-CrossTenant-OriginalArrivalTime: 30 Nov 2021 05:53:16.2521 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: b61c8803-16f3-4c35-9b17-6f65f441df86 X-MS-Exchange-CrossTenant-MailboxType: HOSTED X-MS-Exchange-CrossTenant-UserPrincipalName: UUEjsHrAOyPGfJSEMU1QYKS4Me5ICpkHm2IO20NmB9Fta1iF8xAD+FiG/s/40Ig1sQzTe5hjIv8X3ILl7BdG+g== X-MS-Exchange-Transport-CrossTenantHeadersStamped: CO6PR04MB7825 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211129_215322_201558_ED115EC6 X-CRM114-Status: GOOD ( 21.82 ) X-Spam-Score: -2.5 (--) 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: From: Jessica Clarke BUG and BUG_ON are not informative and are rather lazy interfaces, only telling the user that something went wrong in a given function, but not what, requiring the user to find the sources correspondi [...] Content analysis details: (-2.5 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -2.3 RCVD_IN_DNSWL_MED RBL: Sender listed at https://www.dnswl.org/, medium trust [216.71.154.45 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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.0 MSGID_FROM_MTA_HEADER Message-Id was added by a relay 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 From: Jessica Clarke BUG and BUG_ON are not informative and are rather lazy interfaces, only telling the user that something went wrong in a given function, but not what, requiring the user to find the sources corresponding to their firmware (which may not be available) and figure out how that BUG(_ON) was hit. Even SBI_ASSERT in its current form, which does include the condition that triggered it in the output, isn't necessarily very informative. In some cases, the error may be fixable by the user, but they need to know the problem in order to have any hope of fixing it. It's also a nuisance for developers, whose development trees may have changed significantly since the release in question being used, and so line numbers can make it harder for them to understand which error case a user has hit. This patch introduces a new sbi_panic function which is printf-like, allowing detailed error messages to be printed to the console. BUG and BUG_ON are removed, since the former is just a worse form of sbi_panic and the latter is a worse version of SBI_ASSERT. Finally, SBI_ASSERT is augmented to take a set of arguments to pass to sbi_panic on failure, used like so (sbi_boot_print_hart's current error case, which currently manually calls sbi_printf and sbi_hart_hang): SBI_ASSERT(xlen >= 1, ("Error %d getting MISA XLEN\n", xlen)); The existing users of BUG are replaced with calls to sbi_panic along with informative error messages. BUG_ON and SBI_ASSERT were unused (and, in the case of SBI_ASSERT, remain unused). Many existing users of sbi_hart_hang should be converted to use either sbi_panic or SBI_ASSERT after this commit. Signed-off-by: Jessica Clarke Reviewed-by: Anup Patel Reviewed-by: Xiang W Reviewed-by: Atish Patra --- Changes since v1: - Update patch suject - Fixed typo in patch description - Remove "#include " from sbi_console.h --- include/sbi/sbi_console.h | 23 +++++------------------ lib/sbi/riscv_asm.c | 7 ++++--- lib/sbi/sbi_console.c | 14 ++++++++++++++ platform/generic/sifive_fu740.c | 1 + 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/include/sbi/sbi_console.h b/include/sbi/sbi_console.h index 28b4a79..e15b55d 100644 --- a/include/sbi/sbi_console.h +++ b/include/sbi/sbi_console.h @@ -11,7 +11,6 @@ #define __SBI_CONSOLE_H__ #include -#include struct sbi_console_device { /** Name of the console device */ @@ -44,6 +43,8 @@ int __printf(1, 2) sbi_printf(const char *format, ...); int __printf(1, 2) sbi_dprintf(const char *format, ...); +void __printf(1, 2) __attribute__((noreturn)) sbi_panic(const char *format, ...); + const struct sbi_console_device *sbi_console_get_device(void); void sbi_console_set_device(const struct sbi_console_device *dev); @@ -52,23 +53,9 @@ struct sbi_scratch; int sbi_console_init(struct sbi_scratch *scratch); -#define BUG() do { \ - sbi_printf("BUG: failure at %s:%d/%s()!\n", \ - __FILE__, __LINE__, __func__); \ - sbi_hart_hang(); \ -} while (0) - -#define BUG_ON(cond) do { \ - if (cond) \ - BUG(); \ -} while (0) - -#define SBI_ASSERT(cond) do { \ - if (!(cond)) { \ - sbi_printf("ASSERT: %s:%d/%s(): Assertion `%s` failed.\n", \ - __FILE__,__LINE__,__func__, #cond);\ - sbi_hart_hang(); \ - } \ +#define SBI_ASSERT(cond, args) do { \ + if (unlikely(!(cond))) \ + sbi_panic args; \ } while (0) #endif diff --git a/lib/sbi/riscv_asm.c b/lib/sbi/riscv_asm.c index 1642ac6..2e2e148 100644 --- a/lib/sbi/riscv_asm.c +++ b/lib/sbi/riscv_asm.c @@ -76,7 +76,8 @@ void misa_string(int xlen, char *out, unsigned int out_sz) out[pos++] = '8'; break; default: - BUG(); + sbi_panic("%s: Unknown misa.MXL encoding %d", + __func__, xlen); return; } } @@ -145,7 +146,7 @@ unsigned long csr_read_num(int csr_num) #endif default: - BUG(); + sbi_panic("%s: Unknown CSR %#x", __func__, csr_num); break; }; @@ -213,7 +214,7 @@ void csr_write_num(int csr_num, unsigned long val) switchcase_csr_write_16(CSR_MHPMEVENT16, val) default: - BUG(); + sbi_panic("%s: Unknown CSR %#x", __func__, csr_num); break; }; diff --git a/lib/sbi/sbi_console.c b/lib/sbi/sbi_console.c index 29eede3..34c843d 100644 --- a/lib/sbi/sbi_console.c +++ b/lib/sbi/sbi_console.c @@ -9,6 +9,7 @@ #include #include +#include #include #include @@ -397,6 +398,19 @@ int sbi_dprintf(const char *format, ...) return retval; } +void sbi_panic(const char *format, ...) +{ + va_list args; + + spin_lock(&console_out_lock); + va_start(args, format); + print(NULL, NULL, format, args); + va_end(args); + spin_unlock(&console_out_lock); + + sbi_hart_hang(); +} + const struct sbi_console_device *sbi_console_get_device(void) { return console_dev; diff --git a/platform/generic/sifive_fu740.c b/platform/generic/sifive_fu740.c index 3152152..333b3fb 100644 --- a/platform/generic/sifive_fu740.c +++ b/platform/generic/sifive_fu740.c @@ -12,6 +12,7 @@ #include #include #include +#include #include #include #include