From nobody Sun Nov 9 23:42:55 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail; spf=pass (zoho.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1552411398097361.58968847397693; Tue, 12 Mar 2019 10:23:18 -0700 (PDT) Received: from localhost ([127.0.0.1]:56322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l7T-0001eP-0a for importer@patchew.org; Tue, 12 Mar 2019 13:23:15 -0400 Received: from eggs.gnu.org ([209.51.188.92]:50688) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l2i-0005OA-J4 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:18:21 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1h3kzn-0003uY-28 for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:15:21 -0400 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]:43645) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1h3kzm-0003pc-Of for qemu-devel@nongnu.org; Tue, 12 Mar 2019 13:15:18 -0400 Received: by mail-wr1-x436.google.com with SMTP id d17so3553369wre.10 for ; Tue, 12 Mar 2019 10:15:13 -0700 (PDT) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id j71sm4584423wmj.44.2019.03.12.10.15.09 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 12 Mar 2019 10:15:09 -0700 (PDT) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id 69D291FFA6; Tue, 12 Mar 2019 17:09:32 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3whuNUzyAJ/yqQTSF6kfELry8GUDCbdrK/J4r3ICj6o=; b=TMvQtfcBAgkdN3qtoj4s72awFniDV1KA9T/jKzWas6FR0K28d75LVdMeT4yJGWG1lt u3cxOjEBpLIdEdLRZKCarhaPtHbOi+iWim3ZiTFq6/8WfwucJOvKZ9jVBwp+KbqYjqtI HvaF56P0/MgDrsUpfm1phflt6VIJGbdtBXl3Oazm1O953cgn8z+9j6D4wyxHrwYn12kD Oyu0z4sHwi3+P+NzRzu+ifXKGneVMkWA8r3wg31Q6TghA7Q9+6pfkZmiITlTBWdqFUHP 7oy/onMaLO382baWnhh5bxK3PAbrWArrHcglOqlwvQSFlce35a3ecXlshG7xfcgm8Xp/ UYug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3whuNUzyAJ/yqQTSF6kfELry8GUDCbdrK/J4r3ICj6o=; b=Z3uAkm/JKaWAsjyutdWo0H2To0rbCdTr/2iBUS54D0ezoCP53hWeeuEdkvEK0J6zLV IIlCE5QKY5hc8ov/jlK91ZZIPn8sN9poPYPDuZ0F8ZaH9qyiLrms7KnC5BFindWTVU9i 3CgFCHjx/erxGXFdmblzsUkvzXnWcW0w8ZTq7lD0Cpl/5mvy666PdUu4RFrhuxeBY34g W/KWwcDWGejdqq2Fd8KCQNlGo+28iJm7SdxVODaC5tkbx3mkGvie+cMI/Sd9yWw+LRgt iP2geKZ7WMKagcwBwU4/hBpfAJGDeM0VBLzAaQbtw3udWomrq+1QF+xFPqcDfZMJ0kP+ glaw== X-Gm-Message-State: APjAAAXNMqzDNS12sXqD5KM9d2Qmced0LFg1a20oqac0OMCgLrp8nxe8 +9IcFX6jdzotS4q8pf5QnlaM6g== X-Google-Smtp-Source: APXvYqw+1hRFlI5ptq6Jz2smYdpYOv+fSBSGZQl+V11dzMXlBJkhFSDJE/nT7NLERIYaY2Ct9xHakg== X-Received: by 2002:adf:ff81:: with SMTP id j1mr25119510wrr.261.1552410912302; Tue, 12 Mar 2019 10:15:12 -0700 (PDT) From: =?UTF-8?q?Alex=20Benn=C3=A9e?= To: peter.maydell@linaro.org Date: Tue, 12 Mar 2019 17:09:26 +0000 Message-Id: <20190312170931.25013-22-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190312170931.25013-1-alex.bennee@linaro.org> References: <20190312170931.25013-1-alex.bennee@linaro.org> MIME-Version: 1.0 Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::436 Subject: [Qemu-devel] [PULL 21/26] tests/tcg: provide a minilib for system tests X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Kevin Wolf , Alexander Spyridakis , =?UTF-8?q?Alex=20Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) We will likely want a few common functions to make up for the fact we don't have a libc and we don't want to feel like we are programming by banging rocks together. I've purloined the printf function from: https://git.virtualopensystems.com/dev/tcg_baremetal_tests Although I have tweaked the names to avoid confusing GCC about clashing with builtins. Cc: Alexander Spyridakis Cc: Kevin Wolf Signed-off-by: Alex Benn=C3=A9e diff --git a/tests/tcg/Makefile b/tests/tcg/Makefile index 8dfd1a76b9..1cdd628e96 100644 --- a/tests/tcg/Makefile +++ b/tests/tcg/Makefile @@ -95,6 +95,7 @@ else # For softmmu targets we include a different Makefile fragement as the # build options for bare programs are usually pretty different. They # are expected to provide their own build recipes. +-include $(SRC_PATH)/tests/tcg/minilib/Makefile.target -include $(SRC_PATH)/tests/tcg/$(TARGET_BASE_ARCH)/Makefile.softmmu-target ifneq ($(TARGET_BASE_ARCH),$(TARGET_NAME)) -include $(SRC_PATH)/tests/tcg/$(TARGET_NAME)/Makefile.softmmu-target diff --git a/tests/tcg/minilib/Makefile.target b/tests/tcg/minilib/Makefile= .target new file mode 100644 index 0000000000..3ed8077d0f --- /dev/null +++ b/tests/tcg/minilib/Makefile.target @@ -0,0 +1,21 @@ +# +# System test minilib objects +# +# The system tests are very constrained in terms of the library they +# support but we are not savages. We provide a few helpful routines +# that can be shared with the tests for basic I/O. +# +# They assume each arch has provided a putc function. +# + +SYSTEM_MINILIB_SRC=3D$(SRC_PATH)/tests/tcg/minilib +MINILIB_SRCS=3D$(wildcard $(SYSTEM_MINILIB_SRC)/*.c) +MINILIB_OBJS=3D$(patsubst $(SYSTEM_MINILIB_SRC)/%.c, %.o, $(MINILIB_SRCS)) + +MINILIB_CFLAGS+=3D-nostdlib -ggdb -O0 +MINILIB_INC=3D-isystem $(SYSTEM_MINILIB_SRC) + +.PRECIOUS: $(MINILIB_OBJS) + +%.o: $(SYSTEM_MINILIB_SRC)/%.c + $(CC) $(CFLAGS) -c $< -o $@ diff --git a/tests/tcg/minilib/minilib.h b/tests/tcg/minilib/minilib.h new file mode 100644 index 0000000000..e23361380a --- /dev/null +++ b/tests/tcg/minilib/minilib.h @@ -0,0 +1,25 @@ +/* + * Copyright (C) 2015 Virtual Open Systems SAS + * Author: Alexander Spyridakis + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#ifndef _MINILIB_H_ +#define _MINILIB_H_ + +/* + * Provided by the individual arch + */ +extern void __sys_outc(char c); + +/* + * Provided by the common minilib + */ +void ml_printf(const char *fmt, ...); + +#endif /* _MINILIB_H_ */ diff --git a/tests/tcg/minilib/printf.c b/tests/tcg/minilib/printf.c new file mode 100644 index 0000000000..121620cb16 --- /dev/null +++ b/tests/tcg/minilib/printf.c @@ -0,0 +1,133 @@ +/* + * Copyright (C) 2015 Virtual Open Systems SAS + * Author: Alexander Spyridakis + * + * printf based on implementation by Kevin Wolf + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * SPDX-License-Identifier: GPL-2.0-only + */ + +#include "minilib.h" + +typedef __builtin_va_list va_list; +#define va_start(ap, X) __builtin_va_start(ap, X) +#define va_arg(ap, type) __builtin_va_arg(ap, type) +#define va_end(ap) __builtin_va_end(ap) + +static void print_str(char *s) +{ + while (*s) { + __sys_outc(*s++); + } +} + +static void print_num(unsigned long long value, int base) +{ + char digits[] =3D "0123456789abcdef"; + char buf[32]; + int i =3D sizeof(buf) - 2, j; + + /* Set the buffer to 0. See problem of before. */ + for (j =3D 0; j < 32; j++) { + buf[j] =3D 0; + } + + do { + buf[i--] =3D digits[value % base]; + value /=3D base; + } while (value); + + print_str(&buf[i + 1]); +} + +void ml_printf(const char *fmt, ...) +{ + va_list ap; + char *str; + int base; + int has_long; + int alt_form; + unsigned long long val; + + va_start(ap, fmt); + + for (; *fmt; fmt++) { + if (*fmt !=3D '%') { + __sys_outc(*fmt); + continue; + } + fmt++; + + if (*fmt =3D=3D '#') { + fmt++; + alt_form =3D 1; + } else { + alt_form =3D 0; + } + + if (*fmt =3D=3D 'l') { + fmt++; + if (*fmt =3D=3D 'l') { + fmt++; + has_long =3D 2; + } else { + has_long =3D 1; + } + } else { + has_long =3D 0; + } + + switch (*fmt) { + case 'x': + case 'p': + base =3D 16; + goto convert_number; + case 'd': + case 'i': + case 'u': + base =3D 10; + goto convert_number; + case 'o': + base =3D 8; + goto convert_number; + + convert_number: + switch (has_long) { + case 0: + val =3D va_arg(ap, unsigned int); + break; + case 1: + val =3D va_arg(ap, unsigned long); + break; + case 2: + val =3D va_arg(ap, unsigned long long); + break; + } + + if (alt_form && base =3D=3D 16) { + print_str("0x"); + } + + print_num(val, base); + break; + + case 's': + str =3D va_arg(ap, char*); + print_str(str); + break; + case '%': + __sys_outc(*fmt); + break; + default: + __sys_outc('%'); + __sys_outc(*fmt); + break; + } + } + + va_end(ap); +} --=20 2.20.1