From patchwork Tue Mar 12 17:09:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Alex_Benn=C3=A9e?= X-Patchwork-Id: 10849589 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 065F81515 for ; Tue, 12 Mar 2019 17:22:47 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D82D0296DB for ; Tue, 12 Mar 2019 17:22:46 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CAF40296EB; Tue, 12 Mar 2019 17:22:46 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-2.7 required=2.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 3559C296DB for ; Tue, 12 Mar 2019 17:22:46 +0000 (UTC) Received: from localhost ([127.0.0.1]:56322 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1h3l6z-0001eP-Ft for patchwork-qemu-devel@patchwork.kernel.org; Tue, 12 Mar 2019 13:22:45 -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) 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) 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) From: =?utf-8?q?Alex_Benn=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 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_?= =?utf-8?q?Benn=C3=A9e?= , qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP 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ée 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=$(SRC_PATH)/tests/tcg/minilib +MINILIB_SRCS=$(wildcard $(SYSTEM_MINILIB_SRC)/*.c) +MINILIB_OBJS=$(patsubst $(SYSTEM_MINILIB_SRC)/%.c, %.o, $(MINILIB_SRCS)) + +MINILIB_CFLAGS+=-nostdlib -ggdb -O0 +MINILIB_INC=-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[] = "0123456789abcdef"; + char buf[32]; + int i = sizeof(buf) - 2, j; + + /* Set the buffer to 0. See problem of before. */ + for (j = 0; j < 32; j++) { + buf[j] = 0; + } + + do { + buf[i--] = digits[value % base]; + value /= 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 != '%') { + __sys_outc(*fmt); + continue; + } + fmt++; + + if (*fmt == '#') { + fmt++; + alt_form = 1; + } else { + alt_form = 0; + } + + if (*fmt == 'l') { + fmt++; + if (*fmt == 'l') { + fmt++; + has_long = 2; + } else { + has_long = 1; + } + } else { + has_long = 0; + } + + switch (*fmt) { + case 'x': + case 'p': + base = 16; + goto convert_number; + case 'd': + case 'i': + case 'u': + base = 10; + goto convert_number; + case 'o': + base = 8; + goto convert_number; + + convert_number: + switch (has_long) { + case 0: + val = va_arg(ap, unsigned int); + break; + case 1: + val = va_arg(ap, unsigned long); + break; + case 2: + val = va_arg(ap, unsigned long long); + break; + } + + if (alt_form && base == 16) { + print_str("0x"); + } + + print_num(val, base); + break; + + case 's': + str = va_arg(ap, char*); + print_str(str); + break; + case '%': + __sys_outc(*fmt); + break; + default: + __sys_outc('%'); + __sys_outc(*fmt); + break; + } + } + + va_end(ap); +}