From nobody Mon Feb 9 16:53:08 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=1674828018; cv=none; d=zohomail.com; s=zohoarc; b=R/zFGp5GccZA5OsBCCrexymr3Aags65rwglaSyxDvmGUkUlOJWygGjSOwG9DJIIjHz0mfvipPCw2J9ASYd5I+QBUtsp3U37oKkySaojwcgoGT0Hoz197FR2doaTQF8WpsJiWygLpKVRBG0nobljQEVrLfIx8I0+CajLw73apwqM= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1674828018; 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=iFyYyPwBn9OgtucWxezUDT/W93gze1yZbOtcpEyG5FI=; b=d7tthLKtUXbcwSKQd8uftQbtW3UGq4PquNyx1fNhIqvTFhI34y8nQRVE4KN8G7qX8/ReOuFFeIUWEQcmUo6rbRL8UgZD9FWlYvf7rbGju3c8V9z4s17miSd88XS1SrnndPYcYOBHotr+oXNLPZvTuOiRNNHgd/GX9S60bKcrBEc= 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 1674828018628781.4264023570989; Fri, 27 Jan 2023 06:00:18 -0800 (PST) Received: from list by lists.xenproject.org with outflank-mailman.485597.752989 (Exim 4.92) (envelope-from ) id 1pLPGl-0002tc-OY; Fri, 27 Jan 2023 13:59:55 +0000 Received: by outflank-mailman (output) from mailman id 485597.752989; Fri, 27 Jan 2023 13:59:55 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pLPGl-0002pZ-Fw; Fri, 27 Jan 2023 13:59:55 +0000 Received: by outflank-mailman (input) for mailman id 485597; Fri, 27 Jan 2023 13:59:53 +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 1pLPGj-0000nM-Nc for xen-devel@lists.xenproject.org; Fri, 27 Jan 2023 13:59:53 +0000 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [2a00:1450:4864:20::42f]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id df587b6a-9e4a-11ed-a5d9-ddcf98b90cbd; Fri, 27 Jan 2023 14:59:53 +0100 (CET) Received: by mail-wr1-x42f.google.com with SMTP id h16so5020282wrz.12 for ; Fri, 27 Jan 2023 05:59:53 -0800 (PST) Received: from localhost.localdomain (lfbn-gre-1-240-53.w90-112.abo.wanadoo.fr. [90.112.199.53]) by smtp.gmail.com with ESMTPSA id d3-20020adfe2c3000000b002bc7fcf08ddsm3971131wrj.103.2023.01.27.05.59.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 27 Jan 2023 05:59:52 -0800 (PST) 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: df587b6a-9e4a-11ed-a5d9-ddcf98b90cbd DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; 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=iFyYyPwBn9OgtucWxezUDT/W93gze1yZbOtcpEyG5FI=; b=nEzGY4RrpxaVb3ZuCObP2TewcA8p1mMJ8Te3uzA2J2GNVDnNgSG729cegKOCYy2hCI jG2w9WFh5suUgQxLGGixYNQfFFgte3H9QT/T2Wsu3r8bzLXK4rmP0jm65MgnMWP2QpgW 1uvlHG6NjR0v70WT8unlJe9g7E5t8VzDJL7K6C7sW7vu+Dl/SeTElfioXB4PT48siwwi EFIPj1P5tl9Xm+BHD0A5PsS2GvCWoDAQyS9mfDrAs1uI75gkck1EL+Sd/GkJEO4scvHL IFsnasEz8djaJdWlFNj7W2kDj2DraF+pcB5BFschBSrgKpoic9NBNDKZYv1iwkoEQ/9j 2Quw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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=iFyYyPwBn9OgtucWxezUDT/W93gze1yZbOtcpEyG5FI=; b=6xcu4uMbdKU0uLQ3w29KFyOk78qfnCmV/wv/RII5TVoNvD4kELZbx11hlZkE9s7SJE pqUvWBbap4Ru6WocEt+f+u+slUW2w+TgeeCBrCZui859zoXyGG5triT6usaCbPwQi7ua VBnF5uDXL0EAYhHi7rpmOq56hbOWkG5IgSEPEFLCu9eMuasP3cFNMzuseCLJ/7ribAWE HJeko6AaCZEyimTp06vxRdkZ1Pdle89/ukdmDpfL5J9whlooogO/bEctdB1uSGAo08LZ s9s7LUj9kw6xvItCY1jJUoGg4fsZuVEuhpCVkQAo+mt2dqXRttTX96d6i3nQZ+0e8uJg QzhA== X-Gm-Message-State: AFqh2krBvu3vKLWuuHmvGIdTeL5M4ZNZXDfTyAba5OQtLtKWzddaki6N gu/envEDfhl6ghnmzwueulFo+NuJkV8= X-Google-Smtp-Source: AMrXdXv4349AKuNWUMaghthp68QWPvH7Xes8fNq4qne42EPmK/TeGCJXxAtyuuS5aqMs+d4CEEC6IA== X-Received: by 2002:a5d:6548:0:b0:2bd:f645:19dc with SMTP id z8-20020a5d6548000000b002bdf64519dcmr32348410wrv.68.1674827992465; Fri, 27 Jan 2023 05:59:52 -0800 (PST) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Julien Grall , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH v2 09/14] xen/riscv: introduce decode_cause() stuff Date: Fri, 27 Jan 2023 15:59:14 +0200 Message-Id: <5deb64dcb85d5ddef33c9a1adc9c50ddaadc5d5a.1674818705.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1674828020660100005 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 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 | 85 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 84 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index ccd3593f5a..f2a1e1ffcf 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -4,10 +4,93 @@ * * RISC-V Trap handlers */ +#include +#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"; +} + +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 TIMER Interrupt"; + default: + return "UNKNOWN IRQ type"; + } +} + +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); + } +} + +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); + + early_printk("Unhandled exception: "); + early_printk(decode_cause(cause)); + early_printk("\n"); + die(); } + +void do_trap(struct cpu_user_regs *cpu_regs) +{ + do_unexpected_trap(cpu_regs); +} --=20 2.39.0