From nobody Mon Feb 9 06:05:50 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=1685362439; cv=none; d=zohomail.com; s=zohoarc; b=S0rVbgmCA4scUBoBc8p0sqr50n6nV+78xhaETJE4Q2VIUmSy6d36JycIyFW/RfDYNNJdrPROBGhoknhb5ni9icS6vFOMA7EYTB2aV7vFXbRmZT4P7E/hxAm49SzYof4KqWRrPEJu1faKKZQa6+TYXy1tcCaIv1ptMLkMKF4bJUo= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1685362439; 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=/C052OVgKf2/+kQyjQaALA5nb1G75JwZbX4aVlgaqOA=; b=dtFla0J6fFPAVzsROth12UVu6gfInUd0J2BcUS5NiHz6xTeJXszpaTO3Bf/cxProFN8J4XcBwo9IoTOp0E0Bb0jD9pfGNTg9cp9QArSarVjPmRM0Cv6T04XHhbJXKvynyybuvvScmM31+1N/BLV7AZuQ35R1pfyXTH+ELahUXvk= 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 1685362439369208.48158708559686; Mon, 29 May 2023 05:13:59 -0700 (PDT) Received: from list by lists.xenproject.org with outflank-mailman.540605.842466 (Exim 4.92) (envelope-from ) id 1q3bkf-0005Vz-Fx; Mon, 29 May 2023 12:13:29 +0000 Received: by outflank-mailman (output) from mailman id 540605.842466; Mon, 29 May 2023 12:13: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 1q3bkf-0005VS-9Y; Mon, 29 May 2023 12:13:29 +0000 Received: by outflank-mailman (input) for mailman id 540605; Mon, 29 May 2023 12:13:28 +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 1q3bke-0005DI-5h for xen-devel@lists.xenproject.org; Mon, 29 May 2023 12:13:28 +0000 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [2a00:1450:4864:20::230]) by se1-gles-flk1.inumbo.com (Halon) with ESMTPS id 35be092a-fe1a-11ed-8611-37d641c3527e; Mon, 29 May 2023 14:13:24 +0200 (CEST) Received: by mail-lj1-x230.google.com with SMTP id 38308e7fff4ca-2af189d323fso48962231fa.1 for ; Mon, 29 May 2023 05:13:24 -0700 (PDT) Received: from fedora.. ([94.75.70.14]) by smtp.gmail.com with ESMTPSA id z14-20020a2e964e000000b002ac87c15fd4sm2427762ljh.95.2023.05.29.05.13.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 29 May 2023 05:13:23 -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: 35be092a-fe1a-11ed-8611-37d641c3527e DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1685362403; x=1687954403; 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=/C052OVgKf2/+kQyjQaALA5nb1G75JwZbX4aVlgaqOA=; b=VNtgcoWpnSU3L62BC1zjb8x+g1k92ZREVQ2sFWV0gKoTLZkqrSmvRezX6zNPMdy89n P/KxOIkgrwgdu606XaKgCeDWNNHro4WpxMJsPOH+nw0DLFxOiBSgK4MME7eafqAtubYF LIu4ySxhet2MWQrU8I9DpuRQuDM66qgl4WrYR1w8ajBnYP6dNp1ZZhlkbkL40pGBoIKa oiwIx/dYzIdA/p9rDDAJMvH48rlhZ0wMpqQeVY/cl1HA4dPEc8PAQDtCpxpTZXrfNfYk fS0tYDLDOfD9fCIdl6T2FGhybdO6eVoF4cgHCfkl7NpoqvTMz32KbN5Yi86Sb4wrPOY+ jCPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685362403; x=1687954403; 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=/C052OVgKf2/+kQyjQaALA5nb1G75JwZbX4aVlgaqOA=; b=aHtuGAUjwJWGy95Q7u3juqRWBFfqYz1YNAsIdwysYlXwS69NiccELaTwSxYtc2lWf1 IUzxKsPcOGB2v/rRyU6cC6IfgwEYKC3yj0vjrifoc2x+Hk+XwypwDo2BXuL133rIr3Hn 1CGMEZkKgXMAfyBjwmY3F3L6OOGbsQ9pbvnspx2v3J2nFuLh/MoYvGcLAPV8wGaOamsC EA8c3NJwGXzDW2oqxrcRWQg2b5RBlTeD1f9xvUXcrvxJw3C8w2Ep3M1nObUEZ1FERU3t KSS2AcNUpidtVQB17Xm9flN5iwoDbTTe+xZXUnan8asHUh/lX5YySEZuwx5obY9ITx4C nzWQ== X-Gm-Message-State: AC+VfDzU38Vd0Lg/m9oUfStx2GxDUSFPpAIl8zaRWTlcqLdNn9tBAJf2 g9ybcKbe/lBV5LzfrioInLXZAgU6wJo= X-Google-Smtp-Source: ACHHUZ4KpIiE+T3YC+yLia9p7gQBArv3+/5DXIUwucKoZGsfb2YMWCRkXG+rsinXEzmUEgPso8B6ug== X-Received: by 2002:a05:6512:10cc:b0:4f2:47ea:2f32 with SMTP id k12-20020a05651210cc00b004f247ea2f32mr2439587lfg.23.1685362403464; Mon, 29 May 2023 05:13:23 -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 1/6] xen/riscv: introduce temporary printk stuff Date: Mon, 29 May 2023 15:13:14 +0300 Message-Id: <2a43fd49b34ff2e3e8e3c35e9cf0bdd72ad63f91.1685359848.git.oleksii.kurochko@gmail.com> 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: 1685362440816100002 Content-Type: text/plain; charset="utf-8" The patch introdcuces printk related stuff which should be deleted after Xen common code will be available. Signed-off-by: Oleksii Kurochko --- 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..7d24932a35 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 =3D s; *sc !=3D '\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 =3D (char *) dest, *s =3D (char *) src; + + while (count--) + *tmp++ =3D *s++; + + return dest; +} + +int vsnprintf(char* str, size_t size, const char* format, va_list args) +{ + size_t i =3D 0; /* Current position in the output string */ + size_t written =3D 0; /* Total number of characters written */ + char* dest =3D str; + + while ( format[i] !=3D '\0' && written < size - 1 ) + { + if ( format[i] =3D=3D '%' ) + { + i++; + + if ( format[i] =3D=3D '\0' ) + break; + + if ( format[i] =3D=3D '%' ) + { + if ( written < size - 1 ) + { + dest[written] =3D '%'; + written++; + } + i++; + continue; + } + + /* + * Handle format specifiers. + * For simplicity, only %s and %d are implemented here. + */ + + if ( format[i] =3D=3D 's' ) + { + char* arg =3D va_arg(args, char*); + size_t arglen =3D strlen(arg); + + size_t remaining =3D size - written - 1; + + if ( arglen > remaining ) + arglen =3D remaining; + + memcpy(dest + written, arg, arglen); + + written +=3D arglen; + i++; + } + else if ( format[i] =3D=3D 'd' ) + { + int arg =3D va_arg(args, int); + + /* Convert the integer to string representation */ + char numstr[32]; /* Assumes a maximum of 32 digits */ + int numlen =3D 0; + int num =3D arg; + size_t remaining; + + if ( arg < 0 ) + { + if ( written < size - 1 ) + { + dest[written] =3D '-'; + written++; + } + + num =3D -arg; + } + + do + { + numstr[numlen] =3D '0' + num % 10; + num =3D num / 10; + numlen++; + } while ( num > 0 ); + + /* Reverse the string */ + for (int j =3D 0; j < numlen / 2; j++) + { + char tmp =3D numstr[j]; + numstr[j] =3D numstr[numlen - 1 - j]; + numstr[numlen - 1 - j] =3D tmp; + } + + remaining =3D size - written - 1; + + if ( numlen > remaining ) + numlen =3D remaining; + + memcpy(dest + written, numstr, numlen); + + written +=3D numlen; + i++; + } + } + else + { + if ( written < size - 1 ) + { + dest[written] =3D format[i]; + written++; + } + i++; + } + } + + if ( size > 0 ) + dest[written] =3D '\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 + --=20 2.40.1