From nobody Sat Dec 21 12:40:10 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=1691764404; cv=none; d=zohomail.com; s=zohoarc; b=lLTYJjCkK51YCKi2YvDipQ/8KtWZwK7JLjDsXd6wNzaDR+y8dt4c2lx/c0wBSJcnFaJzLDDWDi77lpcmBQkHMq246OifyHkHe9/AJcPY+JHJ3aGJdxFDAKqHJ05UTlmC4EsBMA59VW/xqqPv6uil8Q5rXUUHR9tkoPJDNog3aFA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1691764404; 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=yUcu2qxnQUPl60o9J+2YFJhCdL460tY2JEgoa99A+hs=; b=F/lxh5wamx0KpZp6wI0TkKCNVJOwoZ53k5EodtaqrQXTM/01cjy4awNlDBVs12FhWrTjz6sMG9Zm0LkBV22gmhkliRQJwQE/Bfhm/C6qzOSgWM4/tvRLOsAvya+4lWtk/5hDFbXusAUi2OO4M9/cuNgWCrsyt8BqQPZ7nRQDniY= 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 1691764404842141.04934199240904; Fri, 11 Aug 2023 07:33:24 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.582506.912325 (Exim 4.92) (envelope-from ) id 1qUTCJ-0005WI-CQ; Fri, 11 Aug 2023 14:33:03 +0000 Received: by outflank-mailman (output) from mailman id 582506.912325; Fri, 11 Aug 2023 14:33:03 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qUTCJ-0005Sz-5f; Fri, 11 Aug 2023 14:33:03 +0000 Received: by outflank-mailman (input) for mailman id 582506; Fri, 11 Aug 2023 14:33:02 +0000 Received: from se1-gles-flk1-in.inumbo.com ([94.247.172.50] helo=se1-gles-flk1.inumbo.com) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qUTCI-0004v5-5k for xen-devel@lists.xenproject.org; Fri, 11 Aug 2023 14:33:02 +0000 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [2a00:1450:4864:20::12d]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id f88d3af2-3853-11ee-8613-37d641c3527e; Fri, 11 Aug 2023 16:32:59 +0200 (CEST) Received: by mail-lf1-x12d.google.com with SMTP id 2adb3069b0e04-4fe27849e6aso3261494e87.1 for ; Fri, 11 Aug 2023 07:33:00 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id q2-20020ac25a02000000b004fe07f06337sm753453lfn.53.2023.08.11.07.32.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 11 Aug 2023 07:32:59 -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: f88d3af2-3853-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691764380; x=1692369180; 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=yUcu2qxnQUPl60o9J+2YFJhCdL460tY2JEgoa99A+hs=; b=kpmGNC0rGdvqjEnckQmthWRufVqIFbkXrlV1X8NxCthx0hq5FHxZabpthDdNBYljYB BE2b4op30+CS9s6+msN5L4Qs85H43tMFlRvdX5UQLrX3ABo9B8bKQJczO1phoEw+gH1G yupgxEROaEzYvhy84SMLfwOT9EBlu84M11LSFqq3c6sUDMqUOv+faXSXcHhrAcxMpftL CVdPVTdvKjIflbyCY2LRVGueomS7UjvHGpZdY+IS7k36s1fwqEY0h3XL1QKkkwkJ0b7Z YzMI8FBjed9DITZiNZ1wzFJI9dKDC20mlpAYoY9GenR0TzTuOymF+DF/vMRd9QJ0MdbU 9D0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691764380; x=1692369180; 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=yUcu2qxnQUPl60o9J+2YFJhCdL460tY2JEgoa99A+hs=; b=P24XaqRIDpVqe70esv2MgjtJQjkvl8joO3NUpVJQ/ihXF/CFWpQmDNCYiH/BBvjWXC KEAc4DPdoadtKHgPEjOBzRKhhLjLNFfFZjPd6/yxJ8BtnlIiIUSnVgMfNE87FVI3aZvz XoGdhU8Ml+2irn6IHcpz8qa2X7VUqvjSYx0qcdUNPvBT1bDbSn5bY5JyCuYVEYfce0mD BlDroRY6eI/FXrI/kbMTWS8hb493bp7M/Zq3w/FqAhlYr19XJQ5uHMSe9fO22xwdgYwu wOJSKuZC9bNQpJbk2jQTUQ4cTMJdJe0DLQ0a5swew5BWsCechGI/1jQo7MLIUpglneA8 chDw== X-Gm-Message-State: AOJu0YyV7qUVluFU13ezcSQCXWdL1UfDuLBu8JpP/w+eFjU2IL/LMgrb 7RiISImK2Ffte92fUNaQ/ZVJOnY6Q+o= X-Google-Smtp-Source: AGHT+IG3DDqQ/ltjvGgtw/Whl2OwvjMojKAXkZMmzPqYsbf0lTo9FGVz+/HNzm7xePWRhZRr93Tuig== X-Received: by 2002:ac2:5205:0:b0:4fe:e8f:e216 with SMTP id a5-20020ac25205000000b004fe0e8fe216mr1486152lfl.39.1691764379572; Fri, 11 Aug 2023 07:32:59 -0700 (PDT) From: Oleksii Kurochko To: xen-devel@lists.xenproject.org Cc: Jan Beulich , Andrew Cooper , Oleksii Kurochko , Bob Eshleman , Alistair Francis , Connor Davis Subject: [PATCH v8 3/6] xen/riscv: introduce decode_cause() stuff Date: Fri, 11 Aug 2023 17:32:52 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @gmail.com) X-ZM-MESSAGEID: 1691764407031100007 Content-Type: text/plain; charset="utf-8" The patch introduces stuff needed to decode a reason of an exception. Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- Changes in V8: - fix typo in return string from decode_reserved_interrupt_cause - add Acked-by: Alistair Francis --- Changes in V7: - Nothing changed. Only rebase. --- 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..a2b63d579b 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.41.0