From nobody Mon Feb 9 01:01:44 2026 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) client-ip=192.237.175.120; envelope-from=xen-devel-bounces@lists.xenproject.org; helo=lists.xenproject.org; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass(p=none dis=none) header.from=gmail.com ARC-Seal: i=1; a=rsa-sha256; t=1685362441; cv=none; d=zohomail.com; s=zohoarc; b=RqaOhoBdzHewnqBO0f9kJVHvMj0eg9Uyt8Wv1ZEuRy6pznPo0jqbmnLOov2LQGo0FzjvbQZwdIF9WXH7Vq9Fv/9iJi2zibwAkQ16lbCTcPtwZgbtdnvwiGBBTn+jXCPNyGPV1jWjmBTLoMYmvneBX1LMBiUpHRBOv2qTYYv/73w= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685362441; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=wkQ4zHDkTr4O9GodmGbD3ibtCyQrQEbN6NGk6h/UX0A=; b=LYcm9nXYGZ3bciiZ+aopWUohh8RY3eCdzI+N/1jLMgr9/RsApeFoEilFEH8zGBgDjVcsKypAQ6x0zOwEYsfnwRN+upSTzYU4/JmyO+1DNvrC0VyT4fZSlBHKtHNncZKRYeKD6B7hAAm5cHCG5N4IFmgNZyXVYz+Gcv8FbB41Jfo= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of lists.xenproject.org designates 192.237.175.120 as permitted sender) smtp.mailfrom=xen-devel-bounces@lists.xenproject.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) by mx.zohomail.com with SMTPS id 1685362441736832.4749403888355; Mon, 29 May 2023 05:14:01 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.540603.842450 (Exim 4.92) (envelope-from ) id 1q3bkd-0005DX-Sm; Mon, 29 May 2023 12:13:27 +0000 Received: by outflank-mailman (output) from mailman id 540603.842450; Mon, 29 May 2023 12:13:27 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q3bkd-0005DQ-Pw; Mon, 29 May 2023 12:13:27 +0000 Received: by outflank-mailman (input) for mailman id 540603; Mon, 29 May 2023 12:13:27 +0000 Received: from se1-gles-sth1-in.inumbo.com ([159.253.27.254] helo=se1-gles-sth1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1q3bkd-0005DK-2F for xen-devel@lists.xenproject.org; Mon, 29 May 2023 12:13:27 +0000 Received: from mail-lj1-x234.google.com (mail-lj1-x234.google.com [2a00:1450:4864:20::234]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 36b8513a-fe1a-11ed-b231-6b7b168915f2; Mon, 29 May 2023 14:13:25 +0200 (CEST) Received: by mail-lj1-x234.google.com with SMTP id 38308e7fff4ca-2af7081c9ebso33984231fa.1 for ; Mon, 29 May 2023 05:13:26 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id z14-20020a2e964e000000b002ac87c15fd4sm2427762ljh.95.2023.05.29.05.13.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 05:13:24 -0700 (PDT) X-Outflank-Mailman: Message body and most headers restored to incoming version X-BeenThere: xen-devel@lists.xenproject.org List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Errors-To: xen-devel-bounces@lists.xenproject.org Precedence: list Sender: "Xen-devel" X-Inumbo-ID: 36b8513a-fe1a-11ed-b231-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685362405; x=1687954405; 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=wkQ4zHDkTr4O9GodmGbD3ibtCyQrQEbN6NGk6h/UX0A=; b=d58sQl2RjRtSnDVfLMcJjRKVv1upnmb9HuOWNe/xYJmPy3KUgpdZOWqOGyHyY1UiN1 c1qldE4Id8rQqM/qwM/Y6+tMhWjabRmrOBH/TzzsaYqTZ1FKuB6lBQpJmBCQL5tejuzz uxc6QNunuKRvGTS2RMV3KuXMQAfbkQR9sJpV+Nzly3CskFCeMDq1/ZH1dkEJAI3fUsr2 lvyo8oseMqvIsh0TVDdNBasMESmZzrJOwg4NLM1u8wx7wcwahPcQ35WLShm4+fqQmyDN 5OYTKGZI/CEwikX5y/LyhTX9AsqngumqHBM8ii6vekCz9IMHnKJtkE4afavoiJSrrUnn vfbQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685362405; x=1687954405; 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=wkQ4zHDkTr4O9GodmGbD3ibtCyQrQEbN6NGk6h/UX0A=; b=N3LseP5VmksNXALGPd6BW08UaoPk1MgfGeJEfmE13gc3I0W9wZ870aN8ZQXJQkeIWH tHskXeggc1FCTQXelAXm0C71T1igC5Mk3Ld9ww4sMvoYEVUWgCNxy2QmxjK28bJGK3dm gtYN0QYDCqNxu59Af1lgFsyJKEiNZAFaqnUxgryGwGIt5GBhUpEyHpxiK8P9bCzfaf64 DzHLp9+LceyeiDXvtUEZ4++nT8tbPoP5lWNUivO9Rd+zgvYPQe4lbT5sWwMURVCqM4eR yIW5cC2LxoxcaQCS2rIdg4qm7jYSMfKfhEEa43QzEqZaYMOLs5VFAtcqiDPfoATEHqQy zvRg== X-Gm-Message-State: AC+VfDzIuMWbtG70ZGYW5UOrRCstG1M6+Zwo757PAXHQLujr4fXKBa80 HXISeD7qmUMKHLRa2caIcAlVGgFZnNg= X-Google-Smtp-Source: ACHHUZ4Ha9S4qBbRlL0G/+/O2i7GhUTN8dMSJOG9tXm+dMCi/JovQUoEALmoa6jvQUrT/H5v3za5aw== X-Received: by 2002:a2e:9417:0:b0:2ad:8a4b:6a9e with SMTP id i23-20020a2e9417000000b002ad8a4b6a9emr3593392ljh.26.1685362405214; Mon, 29 May 2023 05:13:25 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Julien Grall , Andrew Cooper , Stefano Stabellini , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH v6 3/6] xen/riscv: introduce decode_cause() stuff Date: Mon, 29 May 2023 15:13:16 +0300 Message-Id: X-Mailer: git-send-email 2.40.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1685362442517100005 Content-Type: text/plain; charset="utf-8" The patch introduces stuff needed to decode a reason of an exception. Signed-off-by: Oleksii Kurochko --- Changes in V6: - Remove usage of LINK_TO_LOAD() due to the MMU being enabled first. - Change early_printk() to printk() --- Changes in V5: - Remove from riscv/traps/c as nothing would require inclusion. - decode_reserved_interrupt_cause(), decode_interrupt_cause(), decode_cau= se, do_unexpected_trap() were made as static they are expected to be used only in traps.c - use LINK_TO_LOAD() for addresses which can be linker time relative. --- Changes in V4: - fix string in decode_reserved_interrupt_cause() --- Changes in V3: - Nothing changed --- Changes in V2: - Make decode_trap_cause() more optimization friendly. - Merge the pathc which introduces do_unexpected_trap() to the current on= e. --- xen/arch/riscv/traps.c | 84 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index ccd3593f5a..ea1012e83e 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -4,10 +4,92 @@ * * RISC-V Trap handlers */ + +#include + +#include +#include #include #include =20 -void do_trap(struct cpu_user_regs *cpu_regs) +static const char *decode_trap_cause(unsigned long cause) +{ + static const char *const trap_causes[] =3D { + [CAUSE_MISALIGNED_FETCH] =3D "Instruction Address Misaligned", + [CAUSE_FETCH_ACCESS] =3D "Instruction Access Fault", + [CAUSE_ILLEGAL_INSTRUCTION] =3D "Illegal Instruction", + [CAUSE_BREAKPOINT] =3D "Breakpoint", + [CAUSE_MISALIGNED_LOAD] =3D "Load Address Misaligned", + [CAUSE_LOAD_ACCESS] =3D "Load Access Fault", + [CAUSE_MISALIGNED_STORE] =3D "Store/AMO Address Misaligned", + [CAUSE_STORE_ACCESS] =3D "Store/AMO Access Fault", + [CAUSE_USER_ECALL] =3D "Environment Call from U-Mode", + [CAUSE_SUPERVISOR_ECALL] =3D "Environment Call from S-Mode", + [CAUSE_MACHINE_ECALL] =3D "Environment Call from M-Mode", + [CAUSE_FETCH_PAGE_FAULT] =3D "Instruction Page Fault", + [CAUSE_LOAD_PAGE_FAULT] =3D "Load Page Fault", + [CAUSE_STORE_PAGE_FAULT] =3D "Store/AMO Page Fault", + [CAUSE_FETCH_GUEST_PAGE_FAULT] =3D "Instruction Guest Page Fault", + [CAUSE_LOAD_GUEST_PAGE_FAULT] =3D "Load Guest Page Fault", + [CAUSE_VIRTUAL_INST_FAULT] =3D "Virtualized Instruction Fault", + [CAUSE_STORE_GUEST_PAGE_FAULT] =3D "Guest Store/AMO Page Fault", + }; + + if ( cause < ARRAY_SIZE(trap_causes) && trap_causes[cause] ) + return trap_causes[cause]; + return "UNKNOWN"; +} + +static const char *decode_reserved_interrupt_cause(unsigned long irq_cause) +{ + switch ( irq_cause ) + { + case IRQ_M_SOFT: + return "M-mode Software Interrupt"; + case IRQ_M_TIMER: + return "M-mode TIMER Interrupt"; + case IRQ_M_EXT: + return "M-mode External Interrupt"; + default: + return "UNKNOWN IRQ type"; + } +} + +static const char *decode_interrupt_cause(unsigned long cause) +{ + unsigned long irq_cause =3D cause & ~CAUSE_IRQ_FLAG; + + switch ( irq_cause ) + { + case IRQ_S_SOFT: + return "Supervisor Software Interrupt"; + case IRQ_S_TIMER: + return "Supervisor Timer Interrupt"; + case IRQ_S_EXT: + return "Supervisor External Interrupt"; + default: + return decode_reserved_interrupt_cause(irq_cause); + } +} + +static const char *decode_cause(unsigned long cause) +{ + if ( cause & CAUSE_IRQ_FLAG ) + return decode_interrupt_cause(cause); + + return decode_trap_cause(cause); +} + +static void do_unexpected_trap(const struct cpu_user_regs *regs) { + unsigned long cause =3D csr_read(CSR_SCAUSE); + + printk("Unhandled exception: %s\n", decode_cause(cause)); + die(); } + +void do_trap(struct cpu_user_regs *cpu_regs) +{ + do_unexpected_trap(cpu_regs); +} --=20 2.40.1