From patchwork Thu Aug 3 12:05:17 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339890 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 13135C41513 for ; Thu, 3 Aug 2023 12:05:41 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576305.902284 (Exim 4.92) (envelope-from ) id 1qRX58-0003Bp-Q1; Thu, 03 Aug 2023 12:05:30 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576305.902284; Thu, 03 Aug 2023 12:05:30 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX58-0003B0-Kb; Thu, 03 Aug 2023 12:05:30 +0000 Received: by outflank-mailman (input) for mailman id 576305; Thu, 03 Aug 2023 12:05:29 +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 1qRX57-0002sc-36 for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:29 +0000 Received: from mail-lf1-x135.google.com (mail-lf1-x135.google.com [2a00:1450:4864:20::135]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 084ba611-31f6-11ee-8613-37d641c3527e; Thu, 03 Aug 2023 14:05:26 +0200 (CEST) Received: by mail-lf1-x135.google.com with SMTP id 2adb3069b0e04-4fe2de785e7so1579671e87.1 for ; Thu, 03 Aug 2023 05:05:26 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:25 -0700 (PDT) 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: 084ba611-31f6-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064326; x=1691669126; 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=xJtJCMw7fy83NnUSxcXJn4fOwoFlzc9n7K+NQt3JNLk=; b=RNWNGd0waEqqsrrlGRF6VMWNTiCqywapKS5vo7BDm/+3b5nQYmkZLLkCFu+QhGUnCI A3mkbvy/dM7C31HgETx5n8dfAM2ieUsPJ75KPDq34gzwYkKpibRifIyqzKh9tbAcC2wb FzLAgrAq0BSwkJAGEgh/krJdAZ53EqRqQfki7kt9+MdkNdyy0jFqbzGJ4PNJPoDCioFV ZWvzf6YQxuqJ+A6s6+uDZFIlrFYSODlraxDAa7vJZGVNttm5r54eJMASsoCKj0uvtbFC 8TxuzXpx7a8n5/aUv94EYHpsxqQDES986incGMJPV9DnoPFDLIwflke/HNChmXsyeM8N know== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064326; x=1691669126; 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=xJtJCMw7fy83NnUSxcXJn4fOwoFlzc9n7K+NQt3JNLk=; b=UXE2H3ruglHdDd2KB9wyZ54dxrHlikIDOBZR4VpyciFgzMaa/Q6cvTQTMJOtSZxiW8 rl0OLkrVGcHRyC05bXf40MWRa299S8/5VekpHIGfQ9Du6QxeFyJ/JKk94W4Dpd6pDagT 68kWtCqygGNRqqmo5m7I1yNHxdemlRjela4Woouy++lOqTfLI23jsHmU3RIAVW929uM5 Z8hBOhrCGwOCZqDxtRHnM/vloCSLDtJaOx9yXZzePNBoP9zAFp2ml/MLWuwHuP7sESGZ lUgfZEioTlmQBWOF4DIXyl02I7NNLjVpXxe0kJ+Oojvvz70Z4llJGXJ0uFi97CSD41gF hAyA== X-Gm-Message-State: ABy/qLa9TdQ2Zh+DrG5UaRgNCdd1+iLzcCbNLdBDctqikXx+15w5wXIT lsCjguoHr/3zVi/Do9f2rGYWZsCvW/I= X-Google-Smtp-Source: APBJJlHetGi4rKmwdsyTXvWMkMyAuaRKX7fJZoGlpHhx8H9/f9PpXxsZXR+gKwxg7MV/tlVe56k1+g== X-Received: by 2002:a05:6512:2009:b0:4f8:6560:6436 with SMTP id a9-20020a056512200900b004f865606436mr6501358lfb.9.1691064325827; Thu, 03 Aug 2023 05:05:25 -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 v7 1/6] xen/riscv: introduce temporary printk stuff Date: Thu, 3 Aug 2023 15:05:17 +0300 Message-ID: <4fbdbbb3bf2bf2ebee2709bbb52be02c89a4a55a.1691063432.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 The patch introdcuces printk related stuff which should be deleted after Xen common code will be available. Signed-off-by: Oleksii Kurochko --- Changes in V7: - only rebase was done. --- Changes in V6: - the patch was introduced in the current patch series (V6) --- xen/arch/riscv/early_printk.c | 168 ++++++++++++++++++++++++++++++++++ 1 file changed, 168 insertions(+) diff --git a/xen/arch/riscv/early_printk.c b/xen/arch/riscv/early_printk.c index 610c814f54..60742a042d 100644 --- a/xen/arch/riscv/early_printk.c +++ b/xen/arch/riscv/early_printk.c @@ -40,3 +40,171 @@ void early_printk(const char *str) str++; } } + +/* + * The following #if 1 ... #endif should be removed after printk + * and related stuff are ready. + */ +#if 1 + +#include +#include + +/** + * strlen - Find the length of a string + * @s: The string to be sized + */ +size_t (strlen)(const char * s) +{ + const char *sc; + + for (sc = s; *sc != '\0'; ++sc) + /* nothing */; + return sc - s; +} + +/** + * memcpy - Copy one area of memory to another + * @dest: Where to copy to + * @src: Where to copy from + * @count: The size of the area. + * + * You should not use this function to access IO space, use memcpy_toio() + * or memcpy_fromio() instead. + */ +void *(memcpy)(void *dest, const void *src, size_t count) +{ + char *tmp = (char *) dest, *s = (char *) src; + + while (count--) + *tmp++ = *s++; + + return dest; +} + +int vsnprintf(char* str, size_t size, const char* format, va_list args) +{ + size_t i = 0; /* Current position in the output string */ + size_t written = 0; /* Total number of characters written */ + char* dest = str; + + while ( format[i] != '\0' && written < size - 1 ) + { + if ( format[i] == '%' ) + { + i++; + + if ( format[i] == '\0' ) + break; + + if ( format[i] == '%' ) + { + if ( written < size - 1 ) + { + dest[written] = '%'; + written++; + } + i++; + continue; + } + + /* + * Handle format specifiers. + * For simplicity, only %s and %d are implemented here. + */ + + if ( format[i] == 's' ) + { + char* arg = va_arg(args, char*); + size_t arglen = strlen(arg); + + size_t remaining = size - written - 1; + + if ( arglen > remaining ) + arglen = remaining; + + memcpy(dest + written, arg, arglen); + + written += arglen; + i++; + } + else if ( format[i] == 'd' ) + { + int arg = va_arg(args, int); + + /* Convert the integer to string representation */ + char numstr[32]; /* Assumes a maximum of 32 digits */ + int numlen = 0; + int num = arg; + size_t remaining; + + if ( arg < 0 ) + { + if ( written < size - 1 ) + { + dest[written] = '-'; + written++; + } + + num = -arg; + } + + do + { + numstr[numlen] = '0' + num % 10; + num = num / 10; + numlen++; + } while ( num > 0 ); + + /* Reverse the string */ + for (int j = 0; j < numlen / 2; j++) + { + char tmp = numstr[j]; + numstr[j] = numstr[numlen - 1 - j]; + numstr[numlen - 1 - j] = tmp; + } + + remaining = size - written - 1; + + if ( numlen > remaining ) + numlen = remaining; + + memcpy(dest + written, numstr, numlen); + + written += numlen; + i++; + } + } + else + { + if ( written < size - 1 ) + { + dest[written] = format[i]; + written++; + } + i++; + } + } + + if ( size > 0 ) + dest[written] = '\0'; + + return written; +} + +void printk(const char *format, ...) +{ + static char buf[1024]; + + va_list args; + va_start(args, format); + + (void)vsnprintf(buf, sizeof(buf), format, args); + + early_printk(buf); + + va_end(args); +} + +#endif + From patchwork Thu Aug 3 12:05:18 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339891 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 74228C04A6A for ; Thu, 3 Aug 2023 12:05:42 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576303.902268 (Exim 4.92) (envelope-from ) id 1qRX57-0002sy-9x; Thu, 03 Aug 2023 12:05:29 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576303.902268; Thu, 03 Aug 2023 12:05:29 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX57-0002sr-5Q; Thu, 03 Aug 2023 12:05:29 +0000 Received: by outflank-mailman (input) for mailman id 576303; Thu, 03 Aug 2023 12:05:28 +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 1qRX56-0002sb-6b for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:28 +0000 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [2a00:1450:4864:20::136]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 08974c9d-31f6-11ee-b268-6b7b168915f2; Thu, 03 Aug 2023 14:05:27 +0200 (CEST) Received: by mail-lf1-x136.google.com with SMTP id 2adb3069b0e04-4fe48d0ab0fso1506314e87.1 for ; Thu, 03 Aug 2023 05:05:27 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:26 -0700 (PDT) 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: 08974c9d-31f6-11ee-b268-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064326; x=1691669126; 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=Y+DU3kYIXVYlczgnjPIgAblT5y0PqecHU2rZnswjn2g=; b=QpM/5DX/BO83ao1VktAURaEd5vCgzt+w0XxW1EJmZXBfkcFVuYv39XZXGen2V/W4T0 tGVUo5RgkpDe4TE2w+dlXerXCXb8ZTG60Rf1Xp4Oep2MG4X5l/PLahyMovcjcZlONjtk BqEQgZBg2fzjkK8GQ1QYllV7nixVPOpRM/MzlfMspE00SQIuskK9asiii0eAkBrluog6 Ohy+t7XsnC/3L0iDYVdEbl5hTNsTkbutZ5WMefoIPETJUFK73EMT9MzfACcvEsXFvv9P fgqhkZ3fYsPp2rwIeYJmEYhPShKTe507oRgPGCj+xKE6cJiQrLgvbsyi9ttpjOSMAT6F tNwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064326; x=1691669126; 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=Y+DU3kYIXVYlczgnjPIgAblT5y0PqecHU2rZnswjn2g=; b=cnFHttdE7hRW8E9z7ofdcgBRw9I5oWfs+rFw9T+CQLoVL9s1IeZxK55EvihLDj69+L tV6ba2vusfsuJb1cmIIsNWUZEYvUBeoieRhVdXWgpn1MCoO7+l681xMBwzqoEk/3Zpm9 JuOTlmErvCFbrkHduP1Dk4U57QL3ZvLXTMVcLErBBqnXvU5Ijd5KCFUASjpNjW+aff7g uGiRIstWQB61k4/q7KjYj5PSzpd4q8HKAesaAMI2DSzzyWlDN0YiEfZxAwlKpFk0bpAK ie/bVpEnjVv5G6AFJxwXLFoBXC5K6lwp8jIjbSc+l+I8M/B791Jkoy8PBhhYqgVEgKkI ZU7Q== X-Gm-Message-State: ABy/qLYwxxTuKDyngEqXIYY1BhA2aZY1cNETapvA3vFlFOzw1PGdwvRj 1XWHwQR0L5BMb9as9M3e/7NvnsJ2Qds= X-Google-Smtp-Source: APBJJlEbonaD9/0BAPXd1RpRxUS7o9+LRSnGh1aH+kdhyaTHliEbakbUGPrbaDGLYJumlFmokTiuTQ== X-Received: by 2002:a05:6512:2253:b0:4fe:711:2931 with SMTP id i19-20020a056512225300b004fe07112931mr7480300lfu.22.1691064326389; Thu, 03 Aug 2023 05:05:26 -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 v7 2/6] xen/riscv: introduce dummy Date: Thu, 3 Aug 2023 15:05:18 +0300 Message-ID: X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 will be used in the patch "xen/riscv: introduce decode_cause() stuff" and requires Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- Changes in V7: - Nothing changed. Only rebase. --- Changes in V6: - Nothing changed. Only rebase. --- Changes in V5: * the patch was introduced in the current patch series (V5) --- xen/arch/riscv/include/asm/bug.h | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 xen/arch/riscv/include/asm/bug.h diff --git a/xen/arch/riscv/include/asm/bug.h b/xen/arch/riscv/include/asm/bug.h new file mode 100644 index 0000000000..e8b1e40823 --- /dev/null +++ b/xen/arch/riscv/include/asm/bug.h @@ -0,0 +1,10 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (C) 2012 Regents of the University of California + * Copyright (C) 2021-2023 Vates + * + */ +#ifndef _ASM_RISCV_BUG_H +#define _ASM_RISCV_BUG_H + +#endif /* _ASM_RISCV_BUG_H */ From patchwork Thu Aug 3 12:05:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339892 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0CBE4C04E69 for ; Thu, 3 Aug 2023 12:05:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576307.902299 (Exim 4.92) (envelope-from ) id 1qRX59-0003Vs-R0; Thu, 03 Aug 2023 12:05:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576307.902299; Thu, 03 Aug 2023 12:05:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX59-0003SP-HE; Thu, 03 Aug 2023 12:05:31 +0000 Received: by outflank-mailman (input) for mailman id 576307; Thu, 03 Aug 2023 12:05:29 +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 1qRX57-0002sb-Qy for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:29 +0000 Received: from mail-lf1-x129.google.com (mail-lf1-x129.google.com [2a00:1450:4864:20::129]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0976e245-31f6-11ee-b268-6b7b168915f2; Thu, 03 Aug 2023 14:05:29 +0200 (CEST) Received: by mail-lf1-x129.google.com with SMTP id 2adb3069b0e04-4fe463420fbso1494136e87.3 for ; Thu, 03 Aug 2023 05:05:29 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.26 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:26 -0700 (PDT) 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: 0976e245-31f6-11ee-b268-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064328; x=1691669128; 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=STtKrHA1Sag04TDET++CsZtqnaGprv3A+LtpFHsKLZ0=; b=Z0jMj2MbtzzeO2TkiK5IxBi2JLOcWaT3c8iXqSjMnwrOGXZUxChrwf3fJ6Njq9NcVg dRPhoo+l+mJa19wEcxQjU64qTTKCIR8LjyxLYOZpuGEcBwcxJzLogBH7tZhR+fBHizdW FmLkSwomBCgO9l7RqQcN9+WlhoMFMj5mHy7ib5Iit0e2JMzv+CF/muG6vYSt5ZE3ibcU 9spL5V5yElrnhTAlTr0VY2VWfPSYWwt4eke7C56tgnVY8AAAZGF7zM2wXeeQyI2JQu+F hOBIUvJQ8pJHT4KgzwFIu7+j7mGfJ99g2UPQXBYwfo2oRIuL53pJDx6g6jQbq/Yup80D Vv7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064328; x=1691669128; 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=STtKrHA1Sag04TDET++CsZtqnaGprv3A+LtpFHsKLZ0=; b=FHhHILzsQ6yrf0ogRkFl8Z9kMFVZziWB08aFbDB6BZH5TXUyyCNiRIU+ChW2K1no6p fEEyT4ZZC2BGejUVujmMfuaS9u3x6rkeTagQ2QTsXP+yLi0WbigKdu+WJzgQ3npB4vgH CPt5NonHCBcZnfjWW9AJY1ZqFmIa7ygSqMX18X5nVxEFDlAyRcBmWMz36NE5tB57j5/L 4/wt6llg3wY9mOPyp+zGKARqCiWR3KWhHVAlAdcbREK7jQyIXOJEQZGw0bTIn4bbDi7L SstIhBHiZgRvfNmXL1WxVgJYyZJBRryH8Nbn7HwLGewA6ugEUNcttFScY83gQxObwY70 3c/g== X-Gm-Message-State: ABy/qLbY8Wz8RklVU0kExmBABzt4ZV5j+VPwZdtpa4tnVTOgzFrpCRL/ 92wbOolBDu6L3oycsO8sfT9Xo1dkfgA= X-Google-Smtp-Source: APBJJlHvs7TfwdJjxWn0f+qWGjUj7YUnxmhAGYG0gOXVrOItVzjirQEsu0ZTFkM/slG5jIGyujl5Gg== X-Received: by 2002:a05:6512:4003:b0:4f8:7055:6f7e with SMTP id br3-20020a056512400300b004f870556f7emr6298170lfb.44.1691064327475; Thu, 03 Aug 2023 05:05:27 -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 v7 3/6] xen/riscv: introduce decode_cause() stuff Date: Thu, 3 Aug 2023 15:05:19 +0300 Message-ID: <25e8e5c5826199ad6f91fb5106472917765d8260.1691063432.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 The patch introduces stuff needed to decode a reason of an exception. Signed-off-by: Oleksii Kurochko 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_cause, 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 one. --- 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 -void do_trap(struct cpu_user_regs *cpu_regs) +static const char *decode_trap_cause(unsigned long cause) +{ + static const char *const trap_causes[] = { + [CAUSE_MISALIGNED_FETCH] = "Instruction Address Misaligned", + [CAUSE_FETCH_ACCESS] = "Instruction Access Fault", + [CAUSE_ILLEGAL_INSTRUCTION] = "Illegal Instruction", + [CAUSE_BREAKPOINT] = "Breakpoint", + [CAUSE_MISALIGNED_LOAD] = "Load Address Misaligned", + [CAUSE_LOAD_ACCESS] = "Load Access Fault", + [CAUSE_MISALIGNED_STORE] = "Store/AMO Address Misaligned", + [CAUSE_STORE_ACCESS] = "Store/AMO Access Fault", + [CAUSE_USER_ECALL] = "Environment Call from U-Mode", + [CAUSE_SUPERVISOR_ECALL] = "Environment Call from S-Mode", + [CAUSE_MACHINE_ECALL] = "Environment Call from M-Mode", + [CAUSE_FETCH_PAGE_FAULT] = "Instruction Page Fault", + [CAUSE_LOAD_PAGE_FAULT] = "Load Page Fault", + [CAUSE_STORE_PAGE_FAULT] = "Store/AMO Page Fault", + [CAUSE_FETCH_GUEST_PAGE_FAULT] = "Instruction Guest Page Fault", + [CAUSE_LOAD_GUEST_PAGE_FAULT] = "Load Guest Page Fault", + [CAUSE_VIRTUAL_INST_FAULT] = "Virtualized Instruction Fault", + [CAUSE_STORE_GUEST_PAGE_FAULT] = "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 = 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 = 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); +} From patchwork Thu Aug 3 12:05:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339893 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 59669C04FDF for ; Thu, 3 Aug 2023 12:05:43 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576306.902290 (Exim 4.92) (envelope-from ) id 1qRX59-0003JY-5I; Thu, 03 Aug 2023 12:05:31 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576306.902290; Thu, 03 Aug 2023 12:05:31 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX58-0003I4-VK; Thu, 03 Aug 2023 12:05:30 +0000 Received: by outflank-mailman (input) for mailman id 576306; Thu, 03 Aug 2023 12:05:29 +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 1qRX57-0002sb-BB for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:29 +0000 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [2a00:1450:4864:20::12e]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0996ed66-31f6-11ee-b268-6b7b168915f2; Thu, 03 Aug 2023 14:05:28 +0200 (CEST) Received: by mail-lf1-x12e.google.com with SMTP id 2adb3069b0e04-4fe28e4671dso1586007e87.0 for ; Thu, 03 Aug 2023 05:05:28 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:27 -0700 (PDT) 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: 0996ed66-31f6-11ee-b268-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064328; x=1691669128; 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=EXuF1AtcaFIuqh3RnuzjKGdWBJliPJb+moN2Ah/LYz8=; b=gRt8bvU/HD2PsiCRodzS3I+Wd6vdyLIiKQ6TVGm0bEIXxGG/YxYsgpadjNhjJFOHZc boEcOY8/NMbjRv9OB3eOWkZKhJqR745V4uG2e1gF/zcas7vS3B7rDMzjFgAxL3ZHte/A 7uquNO9uO4p6HiEwGAoCbd/W/vIPXgNn24ofvgvyIPCUrO1quJwWzv6DnjO5LhL9kJj8 TWN+jPlzEcQJjI/Pt9fDkR3m4By3xjDcD2TOExycv5qSsbU3jS2/UphfWu5Sg+pDaheV Y23fPNM55yuLmMC2PsUSd7Y8DRR/JJ/KLsQU3myo7bjQ6rv5j2EGOgvnxxz/L0VYGj/2 69TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064328; x=1691669128; 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=EXuF1AtcaFIuqh3RnuzjKGdWBJliPJb+moN2Ah/LYz8=; b=XZDJotmPe95E1m7X177znlv36qoCeatTRWekwe4BUNxWpAuMRtv7ql9m0RFfPF03Re 2NmU7pJvVTIKjqZtDzUNvNShugsBUVcjN+gidYVkkyTbdaWtwPp83PE1bcvLTsRp0iVH Hc47DwRtbPPWo0Gys9Agj7KyRgFS4Y76unxmCgzzWkAIftucESg5PAmf1RL+vt+S9MuG XC4Z9KByepRD7KUIXgv0jM20B3MEFovMSIKRtAEoRCZUgpq8maID3WyDWeVt5DrV9Vfe VJ505zxuwxFIY5i6I+2REIPBWef1j77OLU9ZjY8dpRDYUQgWQRDhxTw0Z7JDOiOAym+B e0ZQ== X-Gm-Message-State: ABy/qLZwUEmlKa8t1lTfsv8R1eW2A6HCd6KRKptfDjbtfQnMahwKEjyh 727pqh01mYLI3wJFxepFo/QeMO6fpIk= X-Google-Smtp-Source: APBJJlEYKsvurp295A8fafMIlO/Ww5a4Tb9xWwALkTdp3vT1IkXrzdcwiuV8Q5VT2RegS9LqjAY/fQ== X-Received: by 2002:a19:ab09:0:b0:4fe:1ecf:8ab4 with SMTP id u9-20020a19ab09000000b004fe1ecf8ab4mr6014686lfe.18.1691064328125; Thu, 03 Aug 2023 05:05:28 -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 v7 4/6] xen/riscv: introduce trap_init() Date: Thu, 3 Aug 2023 15:05:20 +0300 Message-ID: <921ea81d2571ce3103336cd2bf6619b8a8a6751c.1691063432.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko Reviewed-by: Alistair Francis --- Changes in V7: - #define cast_to_bug_frame(addr) ((const struct bug_frame *)(addr)). - remove unnecessary comments in trap_init() function. --- Changes in V6: - trap_init() is now called after enabling the MMU. - Add additional explanatory comments. --- Changes in V5: - Nothing changed --- Changes in V4: - Nothing changed --- Changes in V3: - Nothing changed --- Changes in V2: - Rename setup_trap_handler() to trap_init(). - Add Reviewed-by to the commit message. --- xen/arch/riscv/include/asm/traps.h | 1 + xen/arch/riscv/setup.c | 3 +++ xen/arch/riscv/traps.c | 12 ++++++++++++ 3 files changed, 16 insertions(+) diff --git a/xen/arch/riscv/include/asm/traps.h b/xen/arch/riscv/include/asm/traps.h index 3fef318478..c30118e095 100644 --- a/xen/arch/riscv/include/asm/traps.h +++ b/xen/arch/riscv/include/asm/traps.h @@ -9,6 +9,7 @@ void do_trap(struct cpu_user_regs *cpu_regs); void handle_trap(void); +void trap_init(void); #endif /* __ASSEMBLY__ */ diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index 6593f601c1..abdd1669c6 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -5,6 +5,7 @@ #include #include +#include /* Xen stack for bringing up the first CPU. */ unsigned char __initdata cpu0_boot_stack[STACK_SIZE] @@ -15,6 +16,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, { remove_identity_mapping(); + trap_init(); + early_printk("Hello from C env\n"); early_printk("All set up\n"); diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index ea1012e83e..3e08ec44f7 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -12,6 +12,18 @@ #include #include +/* + * Initialize the trap handling. + * + * The function is called after MMU is enabled. + */ +void trap_init(void) +{ + unsigned long addr = (unsigned long)&handle_trap; + + csr_write(CSR_STVEC, addr); +} + static const char *decode_trap_cause(unsigned long cause) { static const char *const trap_causes[] = { From patchwork Thu Aug 3 12:05:21 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339895 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 110D1C001DF for ; Thu, 3 Aug 2023 12:05:45 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576309.902320 (Exim 4.92) (envelope-from ) id 1qRX5B-000461-Cx; Thu, 03 Aug 2023 12:05:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576309.902320; Thu, 03 Aug 2023 12:05:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX5B-000455-63; Thu, 03 Aug 2023 12:05:33 +0000 Received: by outflank-mailman (input) for mailman id 576309; Thu, 03 Aug 2023 12:05:31 +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 1qRX59-0002sc-P8 for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:31 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 0a391522-31f6-11ee-8613-37d641c3527e; Thu, 03 Aug 2023 14:05:29 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fe0e23a4b1so1554116e87.3 for ; Thu, 03 Aug 2023 05:05:29 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:28 -0700 (PDT) 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: 0a391522-31f6-11ee-8613-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064329; x=1691669129; 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=n0T/c4H8PYV8a+tUf8bqa7kNmhfFOIl+4o24A/6F65Y=; b=m802bzewGsdutyqXiwNNiqsYfn3M4z9y5xCanYDSAoA3f8ePVkg/q+T3QSz1krZJbW jjE8Xme9E05+k17DEBsRkiMxZZykmstizUoamdINVEJCYaIYmeHaHYC9ZVoVkasrusoA uf5rdFd9/O+WPvJhaFwBNPQs2EImt+HITbwLhyIKB2WpT/gVrGZpyDy/LQDO4RiHAiPz gov6/EsKwHHrHiJ03r9iFFaks7XPrryTi/ovEt/VWVMnw0jgF22Xz7tTfh9cI5elTtD2 5VfQWJx/V7Y2a1p0RNkqKmTGedc6bUl0Rh/szGEDOmkoLoM9ZDoxeEEKbtVLYPeUx8Ob O8xg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064329; x=1691669129; 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=n0T/c4H8PYV8a+tUf8bqa7kNmhfFOIl+4o24A/6F65Y=; b=iKYl6iSfjwVm7hBvMLRCItxmHJYRF9QbfVImBux0YncG32F06xsVe31eMDWjJ0+vie hXyyXCmiMKFBszlw9D7JtTFL74Gn6Ue2tAKRrX7bcktHsWx0R+FPu0kPMITQ19S+J8YZ 5vks78AEE4lWi+8mD6Y3+vOK2c7JUpddKeVNEpQvltD16Kkwi3IPbqxmk6ySrwVEbxfd IMc/tF4f8KqI+SM0jkAc18/UnVZ4xdAUoEpGX8M8WHWMrQhqXLKiuQzr8pnCDsr4zEkb vZHGjLoYWaFwhKfrP1BAtYLRLBd6R7HRh+fPIvmpAXIG7pN5/7rgtKMG1tWVA0JfeiJ0 EbGg== X-Gm-Message-State: ABy/qLY60VFWowZGvnfR/5SRbw1eD9uO5VITQs4c4IVhsXXyoYxpaUpx KUFFmj77MAhjFD7c+V9N0pZj4SWzuCk= X-Google-Smtp-Source: APBJJlFcG/cnXqx2b/EBsYl3rOroJ1/VDytVVW7Wh4XLH1gBRwg4iEuipD+1UxKgXe6vmMzf+NnUCA== X-Received: by 2002:ac2:5b4e:0:b0:4fe:1f1c:184f with SMTP id i14-20020ac25b4e000000b004fe1f1c184fmr7005761lfp.44.1691064329028; Thu, 03 Aug 2023 05:05:29 -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 v7 5/6] xen/riscv: introduce an implementation of macros from Date: Thu, 3 Aug 2023 15:05:21 +0300 Message-ID: <9fdda7716faf412f1e2cdf9a990c98e64c4b21f3.1691063432.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 The patch introduces macros: BUG(), WARN(), run_in_exception(), assert_failed. To be precise, the macros from generic bug implementation () will be used. The implementation uses "ebreak" instruction in combination with diffrent bug frame tables (for each type) which contains useful information. Signed-off-by: Oleksii Kurochko --- Changes in V7: - move to this patch the definition of cast_to_bug_frame() from the previous patch. - update the comment in bug.h. - update the comment above do_bug_frame(). - fix code style. - add comment to read_instr func. - add space for bug_frames in lds.S. --- Changes in V6: - Avoid LINK_TO_LOAD() as bug.h functionality expected to be used after MMU is enabled. - Change early_printk() to printk() --- Changes in V5: - Remove "#include " from as there is no any need in it anymore - Update macros GET_INSN_LENGTH: remove UL and 'unsigned int len;' from it - Remove " include " from risc/setup.c. it is not needed in the current version of the patch - change an argument type from vaddr_t to uint32_t for is_valid_bugaddr and introduce read_instr() to read instruction properly as the length of qinstruction can be either 32 or 16 bits. - Code style fixes - update the comments before do_bug_frame() in riscv/trap.c - Refactor is_valid_bugaddr() function. - introduce macros cast_to_bug_frame(addr) to hide casts. - use LINK_TO_LOAD() for addresses which are linker time relative. --- Changes in V4: - Updates in RISC-V's : * Add explanatory comment about why there is only defined for 32-bits length instructions and 16/32-bits BUG_INSN_{16,32}. * Change 'unsigned long' to 'unsigned int' inside GET_INSN_LENGTH(). * Update declaration of is_valid_bugaddr(): switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. - Updates in RISC-V's traps.c: * replace /xen and /asm includes * update definition of is_valid_bugaddr():switch return type from int to bool and the argument from 'unsigned int' to 'vaddr'. Code style inside function was updated too. * do_bug_frame() refactoring: * local variables start and bug became 'const struct bug_frame' * bug_frames[] array became 'static const struct bug_frame[] = ...' * remove all casts * remove unneeded comments and add an explanatory comment that the do_bug_frame() will be switched to a generic one. * do_trap() refactoring: * read 16-bits value instead of 32-bits as compressed instruction can be used and it might happen than only 16-bits may be accessible. * code style updates * re-use instr variable instead of re-reading instruction. - Updates in setup.c: * add blank line between xen/ and asm/ includes. --- Changes in V3: - Rebase the patch "xen/riscv: introduce an implementation of macros from " on top of patch series [introduce generic implementation of macros from bug.h] --- Changes in V2: - Remove __ in define namings - Update run_in_exception_handler() with register void *fn_ asm(__stringify(BUG_FN_REG)) = (fn); - Remove bug_instr_t type and change it's usage to uint32_t --- xen/arch/riscv/include/asm/bug.h | 27 +++++++ xen/arch/riscv/traps.c | 128 +++++++++++++++++++++++++++++++ xen/arch/riscv/xen.lds.S | 10 +++ 3 files changed, 165 insertions(+) diff --git a/xen/arch/riscv/include/asm/bug.h b/xen/arch/riscv/include/asm/bug.h index e8b1e40823..f5ff96140f 100644 --- a/xen/arch/riscv/include/asm/bug.h +++ b/xen/arch/riscv/include/asm/bug.h @@ -7,4 +7,31 @@ #ifndef _ASM_RISCV_BUG_H #define _ASM_RISCV_BUG_H +#ifndef __ASSEMBLY__ + +#define BUG_INSTR "ebreak" + +/* + * The base instruction set has a fixed length of 32-bit naturally aligned + * instructions. + * + * There are extensions of variable length ( where each instruction can be + * any number of 16-bit parcels in length ). + * + * Compressed ISA is used now where the instruction length is 16 bit and + * 'ebreak' instruction, in this case, can be either 16 or 32 bit ( + * depending on if compressed ISA is used or not ) + */ +#define INSN_LENGTH_MASK _UL(0x3) +#define INSN_LENGTH_32 _UL(0x3) + +#define BUG_INSN_32 _UL(0x00100073) /* ebreak */ +#define BUG_INSN_16 _UL(0x9002) /* c.ebreak */ +#define COMPRESSED_INSN_MASK _UL(0xffff) + +#define GET_INSN_LENGTH(insn) \ + (((insn) & INSN_LENGTH_MASK) == INSN_LENGTH_32 ? 4 : 2) \ + +#endif /* !__ASSEMBLY__ */ + #endif /* _ASM_RISCV_BUG_H */ diff --git a/xen/arch/riscv/traps.c b/xen/arch/riscv/traps.c index 3e08ec44f7..439c098c22 100644 --- a/xen/arch/riscv/traps.c +++ b/xen/arch/riscv/traps.c @@ -5,6 +5,8 @@ * RISC-V Trap handlers */ +#include +#include #include #include @@ -12,6 +14,8 @@ #include #include +#define cast_to_bug_frame(addr) ((const struct bug_frame *)(addr)) + /* * Initialize the trap handling. * @@ -101,7 +105,131 @@ static void do_unexpected_trap(const struct cpu_user_regs *regs) die(); } +void show_execution_state(const struct cpu_user_regs *regs) +{ + printk("implement show_execution_state(regs)\n"); +} + +/* + * TODO: generic do_bug_frame() should be used instead of current + * implementation panic(), printk() and find_text_region() + * (virtual memory?) will be ready/merged + */ +int do_bug_frame(const struct cpu_user_regs *regs, vaddr_t pc) +{ + const struct bug_frame *start, *end; + const struct bug_frame *bug = NULL; + unsigned int id = 0; + const char *filename, *predicate; + int lineno; + + static const struct bug_frame *bug_frames[] = { + &__start_bug_frames[0], + &__stop_bug_frames_0[0], + &__stop_bug_frames_1[0], + &__stop_bug_frames_2[0], + &__stop_bug_frames_3[0], + }; + + for ( id = 0; id < BUGFRAME_NR; id++ ) + { + start = cast_to_bug_frame(bug_frames[id]); + end = cast_to_bug_frame(bug_frames[id + 1]); + + while ( start != end ) + { + if ( (vaddr_t)bug_loc(start) == pc ) + { + bug = start; + goto found; + } + + start++; + } + } + + found: + if ( bug == NULL ) + return -ENOENT; + + if ( id == BUGFRAME_run_fn ) + { + void (*fn)(const struct cpu_user_regs *) = bug_ptr(bug); + + fn(regs); + + goto end; + } + + /* WARN, BUG or ASSERT: decode the filename pointer and line number. */ + filename = bug_ptr(bug); + lineno = bug_line(bug); + + switch ( id ) + { + case BUGFRAME_warn: + printk("Xen WARN at %s:%d\n", filename, lineno); + + show_execution_state(regs); + + goto end; + + case BUGFRAME_bug: + printk("Xen BUG at %s:%d\n", filename, lineno); + + show_execution_state(regs); + + printk("change wait_for_interrupt to panic() when common is available\n"); + die(); + + case BUGFRAME_assert: + /* ASSERT: decode the predicate string pointer. */ + predicate = bug_msg(bug); + + printk("Assertion %s failed at %s:%d\n", predicate, filename, lineno); + + show_execution_state(regs); + + printk("change wait_for_interrupt to panic() when common is available\n"); + die(); + } + + return -EINVAL; + + end: + return 0; +} + +static bool is_valid_bugaddr(uint32_t insn) +{ + return insn == BUG_INSN_32 || + (insn & COMPRESSED_INSN_MASK) == BUG_INSN_16; +} + +/* Should be used only in Xen code ? */ +static uint32_t read_instr(unsigned long pc) +{ + uint16_t instr16 = *(uint16_t *)pc; + + if ( GET_INSN_LENGTH(instr16) == 2 ) + return (uint32_t)instr16; + else + return *(uint32_t *)pc; +} + void do_trap(struct cpu_user_regs *cpu_regs) { + register_t pc = cpu_regs->sepc; + uint32_t instr = read_instr(pc); + + if ( is_valid_bugaddr(instr) ) + { + if ( !do_bug_frame(cpu_regs, pc) ) + { + cpu_regs->sepc += GET_INSN_LENGTH(instr); + return; + } + } + do_unexpected_trap(cpu_regs); } diff --git a/xen/arch/riscv/xen.lds.S b/xen/arch/riscv/xen.lds.S index 3fa7db3bf9..a10e0ad87c 100644 --- a/xen/arch/riscv/xen.lds.S +++ b/xen/arch/riscv/xen.lds.S @@ -45,6 +45,16 @@ SECTIONS . = ALIGN(PAGE_SIZE); .rodata : { _srodata = .; /* Read-only data */ + /* Bug frames table */ + __start_bug_frames = .; + *(.bug_frames.0) + __stop_bug_frames_0 = .; + *(.bug_frames.1) + __stop_bug_frames_1 = .; + *(.bug_frames.2) + __stop_bug_frames_2 = .; + *(.bug_frames.3) + __stop_bug_frames_3 = .; *(.rodata) *(.rodata.*) *(.data.rel.ro) From patchwork Thu Aug 3 12:05:22 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Oleksii Kurochko X-Patchwork-Id: 13339894 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from lists.xenproject.org (lists.xenproject.org [192.237.175.120]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 0E91DC00528 for ; Thu, 3 Aug 2023 12:05:44 +0000 (UTC) Received: from list by lists.xenproject.org with outflank-mailman.576308.902316 (Exim 4.92) (envelope-from ) id 1qRX5B-00042e-5d; Thu, 03 Aug 2023 12:05:33 +0000 X-Outflank-Mailman: Message body and most headers restored to incoming version Received: by outflank-mailman (output) from mailman id 576308.902316; Thu, 03 Aug 2023 12:05:33 +0000 Received: from localhost ([127.0.0.1] helo=lists.xenproject.org) by lists.xenproject.org with esmtp (Exim 4.92) (envelope-from ) id 1qRX5A-000418-Rf; Thu, 03 Aug 2023 12:05:32 +0000 Received: by outflank-mailman (input) for mailman id 576308; Thu, 03 Aug 2023 12:05:31 +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 1qRX59-0002sb-M7 for xen-devel@lists.xenproject.org; Thu, 03 Aug 2023 12:05:31 +0000 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [2a00:1450:4864:20::12a]) by se1-gles-sth1.inumbo.com (Halon) with ESMTPS id 0af92a90-31f6-11ee-b268-6b7b168915f2; Thu, 03 Aug 2023 14:05:31 +0200 (CEST) Received: by mail-lf1-x12a.google.com with SMTP id 2adb3069b0e04-4fe1c285690so1484750e87.3 for ; Thu, 03 Aug 2023 05:05:31 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id e22-20020ac25476000000b004fdfefdf4acsm3304557lfn.39.2023.08.03.05.05.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 03 Aug 2023 05:05:29 -0700 (PDT) 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: 0af92a90-31f6-11ee-b268-6b7b168915f2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1691064330; x=1691669130; 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=VSibP5eTiQgTk20HjOHTiUPAjHnFr8NTK33Zlp/pEgM=; b=W6CAZlzPU+q9DyJ4PxnDSCSGu2OKImYbHfsVDqpgeVcB03n78aqZo+OJFUKhCPpqvA 3SGs0+aJjno9H1WyopozDLnhJxISIFMSaxf5NLJQGEzb1CHm3DRvfh91cn4q4EnPj/3q 3a8Ty1x2z0FR5T7q7R4eXyMRFrgt1P1V6BAZYkNWfIfMb00+HcdlcLNohfNaY8ftV67s 5f5FqWruN5SCnuRSge+9zxNRYLGgHQYSuE2wFv3eZOP/uzY3NBlO7s9B0QGBVll4u7mP NFqXGNaUDBqtsDocKl8aBME+k7rlfkieewXMxj3i5iq1bVXVPJulwavaLh5wgZhIicWm 0VXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691064330; x=1691669130; 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=VSibP5eTiQgTk20HjOHTiUPAjHnFr8NTK33Zlp/pEgM=; b=EOC2fxJzBMSbmepzTzArxx+7G03PXK0jH5oK5t2wuCoSqiBY/DSO1a+4rf+8zuFFuQ aA4ell+Ff7PmY5c63LVaPXCdhyocZsweivTg5Bud1cXJ4n9RFf5Uz8R/xvKa6tBidS50 roUiDXwt9lTA81oYvIWTB1XojQsRVGkWVV6VF4j6C54ATEQYrslA9eXR2oHOHhla1XJ7 h++MAQK5BwQDBLnO7DAG1RcrgHY/z++XEm34l+/pOSlJC8IFAe5gfwTOkk1HI/AV9dmH 4IBxlbkWCecZLEo+Jw77YAhplxlxBDPZjTC7ZSQHQMNHXb+UHrUZ4T2LEx9zOr96gPNo chHQ== X-Gm-Message-State: ABy/qLbKmrqzKWkCdOeR8AM/isJExFwj4ZqcEPwPo+PN37X6sJxQEMqx VAzKicEwdV2JJ7hehx2audqx4a88GWg= X-Google-Smtp-Source: APBJJlG4UqEUWpc3dVF03OxtTwW2iHbpqYjBVtCRroEIaKyZdZ+eNxE4rlulDSKQ0g3NphinHlIrvA== X-Received: by 2002:a05:6512:2521:b0:4f7:6775:2a66 with SMTP id be33-20020a056512252100b004f767752a66mr8694805lfb.53.1691064330433; Thu, 03 Aug 2023 05:05:30 -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 v7 6/6] xen/riscv: test basic handling stuff Date: Thu, 3 Aug 2023 15:05:22 +0300 Message-ID: <89553c7196a3e01294a17a0ae3946544b1b14e04.1691063432.git.oleksii.kurochko@gmail.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: References: MIME-Version: 1.0 Signed-off-by: Oleksii Kurochko Acked-by: Alistair Francis --- Changes in V6: - Nothing changed. Only rebase. --- Changes in V6: - Nothing changed --- Changes in V5: - Nothing changed --- Changes in V4: - Add Acked-by: Alistair Francis --- Changes in V3: - Nothing changed --- Changes in V2: - Nothing changed --- xen/arch/riscv/setup.c | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/xen/arch/riscv/setup.c b/xen/arch/riscv/setup.c index abdd1669c6..ab83f84e67 100644 --- a/xen/arch/riscv/setup.c +++ b/xen/arch/riscv/setup.c @@ -1,5 +1,6 @@ /* SPDX-License-Identifier: GPL-2.0-only */ +#include #include #include @@ -11,6 +12,20 @@ unsigned char __initdata cpu0_boot_stack[STACK_SIZE] __aligned(STACK_SIZE); +static void test_run_in_exception(struct cpu_user_regs *regs) +{ + early_printk("If you see this message, "); + early_printk("run_in_exception_handler is most likely working\n"); +} + +static void test_macros_from_bug_h(void) +{ + run_in_exception_handler(test_run_in_exception); + WARN(); + early_printk("If you see this message, "); + early_printk("WARN is most likely working\n"); +} + void __init noreturn start_xen(unsigned long bootcpu_id, paddr_t dtb_addr) { @@ -18,6 +33,8 @@ void __init noreturn start_xen(unsigned long bootcpu_id, trap_init(); + test_macros_from_bug_h(); + early_printk("Hello from C env\n"); early_printk("All set up\n");