From nobody Mon Sep 16 19:10:29 2024 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=1678977599; cv=none; d=zohomail.com; s=zohoarc; b=IWHoNs6FCDIt5lB1uubTrpNkxkltQEA9vF4WKRBt7UAyAlDsf0LKhGmxfDWZkApiSa0VR7XSiDciAm3wP2gpjJW7dreTeOm7xoI/tmM64/8Ie+eC8+vej/7XQVfsk1R+9Ow6lo1S/S5XWLHrW14Fkhv51MlegwJrjo8BWx3aEC4= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1678977599; 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=QwhZUEDbU03FgtZvxsT8dmiRdPOC/MCr+LKArTSUuK0=; b=gIyVXEGVHlggRxSd1MfwSZsB3WgoWcyz/RJbBUUcyPD78KFxQDC/TCf3eNGuvwgRIwJk/grX2Fu2G7kIpQtcyNMhYefhpkZBmmjpyyUkmpTRIO8eK8puo1mtbxNYIOdnAZtjxghTfV4m5noeLVQS7+TcksI3x5zWO8F9StG+JqA= 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 1678977599465918.788925927967; Thu, 16 Mar 2023 07:39:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.510651.788743 (Exim 4.92) (envelope-from ) id 1pcola-0007Ka-9W; Thu, 16 Mar 2023 14:39:42 +0000 Received: by outflank-mailman (output) from mailman id 510651.788743; Thu, 16 Mar 2023 14:39:42 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1pcola-0007JL-4V; Thu, 16 Mar 2023 14:39:42 +0000 Received: by outflank-mailman (input) for mailman id 510651; Thu, 16 Mar 2023 14:39:40 +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 1pcolY-0006WA-H7 for xen-devel@lists.xenproject.org; Thu, 16 Mar 2023 14:39:40 +0000 Received: from mail-ed1-x534.google.com (mail-ed1-x534.google.com [2a00:1450:4864:20::534]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 61e69eac-c408-11ed-87f5-c1b5be75604c; Thu, 16 Mar 2023 15:39:39 +0100 (CET) Received: by mail-ed1-x534.google.com with SMTP id cy23so8471774edb.12 for ; Thu, 16 Mar 2023 07:39:40 -0700 (PDT) Received: from fedora.. (46.204.101.131.nat.umts.dynamic.t-mobile.pl. [46.204.101.131]) by smtp.gmail.com with ESMTPSA id q16-20020a1709060e5000b008b980c3e013sm3970187eji.179.2023.03.16.07.39.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Mar 2023 07:39:39 -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: 61e69eac-c408-11ed-87f5-c1b5be75604c DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; t=1678977579; 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=QwhZUEDbU03FgtZvxsT8dmiRdPOC/MCr+LKArTSUuK0=; b=LfCilxI99YjO1HEPhb9/5Iip+mUoAlN/FaC4RdMQLB1L7MweN8Y0FYUIgEuTj8lQ9D A7LZThJfxU43bPO/EFOOzPXyNC8DpsiB/qIoGH4KmUy5PZE2aHZqyyVCM0suNpEscGq6 XYH1trmXu66/0Zh/dyZJYOUoZ/qEdbYpC/SmNY9yXp2Kj50K2gBSVXmYCFKI9++cOeCA oC+P6xoC/lFSoms266G4CvwNac21sXBfuEn2nyLnhy7ZzCJFt6acWBd87iqteL2ew+e7 dnALpvuSIiKmciecZrGsLb39wf8eZi5aAR7lDUfrmUV+b+DrZ8MTrzh7fRDoHKsjHzkz ApgA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1678977579; 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=QwhZUEDbU03FgtZvxsT8dmiRdPOC/MCr+LKArTSUuK0=; b=3TPWYrcyNRa4g0nME061OxNhAloKw3ZZ3zf75knKrEELncxhXRsl+rHS4omE1loqkn hOrAa0u6l6z2YzpG9UsGqipyxLKrWTuDZTQ3GLYeIf5epDDnmeOTRw6gbAzJscSmfxOy GJXa4vauTh+54rwmIrL0SXvKJa+jwubZVFI+iMvsbGr6845Zxl2V5+cPY7Fri9XbqR3f T3/a1H5VCm8Ql6bZy8kOSeBY8sqihMH5qXLk2P7jNpaWTr8yYp3nSZ+huAnsl/3qU0fH 9sYnP4/40fYfBg5oWOJCljUDcDeLTog0ERCcrJAdpfR+DwR/MlcuB28Kkl1rCsCS7oOK xp1A== X-Gm-Message-State: AO0yUKVr/JqygDLbHDaKCsdwtkwrf/B6NMcPUuZmJiA3Ut7/PoB98vWD ZTswymlpZoGpbXuWu/X9ZawoDGzVQJ5fgA== X-Google-Smtp-Source: AK7set+Vrw/c5buXIsbsEI62JvWFHhRvEkwkzgagKamP974RO2D+8gf004qYvaTQBzeTEN/ggAfbsw== X-Received: by 2002:a17:907:dab:b0:92f:b290:78c with SMTP id go43-20020a1709070dab00b0092fb290078cmr6091041ejc.21.1678977579482; Thu, 16 Mar 2023 07:39:39 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Julien Grall , Jan Beulich , Andrew Cooper , Stefano Stabellini , Gianluca Guida , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH v5 4/7] xen/riscv: introduce decode_cause() stuff Date: Thu, 16 Mar 2023 16:39:26 +0200 Message-Id: <8c7b4a5d328be8b1cd2aa99c8d9a7883e4969600.1678976127.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1678977601507100003 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 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 | 87 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 86 insertions(+), 1 deletion(-) diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index ccd3593f5a..8a1529e0c5 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -4,10 +4,95 @@ * * 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"; +} + +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); + + early_printk("Unhandled exception: "); + early_printk(LINK_TO_LOAD(decode_cause(cause))); + early_printk("\n"); + die(); } + +void do_trap(struct cpu_user_regs *cpu_regs) +{ + do_unexpected_trap(cpu_regs); +} --=20 2.39.2