From patchwork Thu Feb 28 20:25:32 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: 159441 Delivered-To: patch@linaro.org Received: by 2002:a02:5cc1:0:0:0:0:0 with SMTP id w62csp1093117jad; Thu, 28 Feb 2019 12:34:23 -0800 (PST) X-Google-Smtp-Source: APXvYqx+G/87CiAVWs6BZRJ6COvJbWkuQ9ECCk0AdDUyWyw+h43x5iOsYXJ2/Zo4ILP5CompjjgY X-Received: by 2002:a25:2d44:: with SMTP id s4mr1251871ybe.510.1551386063201; Thu, 28 Feb 2019 12:34:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551386063; cv=none; d=google.com; s=arc-20160816; b=kHJRCvWUON4rH3UyRyAs2Sa1tswz4tbHPwuDCc9d3IYXJmpTMli5SfU2NzMBsvV1PO K+4UFEbDbV5ObOD/ATAViCklVdTOmMCe2MxcnelgAzH0BH7q/xbMwORcMI7GS+JdsVZu w4qBQsqEewjfM/pAL0qC0GRF3kP/qjjEEZm4XnhYyLLwN6riM4rXT7mklJETAta/Pc2O z07DAQQ+cTzNZuPvfsCr6M8qCcSV74ZOnZs06byGjclux9FTpE4crA4MMG+HaZPk6SJ+ ZaMsapyGZlZDDdtzRTpsORnqEtA19hvVmcRcWAoR/yCFO0Y8x+Hztkn8ROSZVsO0HddY 1EFA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:subject :content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:to:from:dkim-signature; bh=IhmDA8Paz4xh5btvDJbvSxpnzxmgwJBv6Kvn01RZQX4=; b=nZabEVo437Do/mixqkyiu2Ltpl9bnqoUO4+gCl7H/DO44kuBcat99K0NnXVJdcnIes OS13PrJWwmD/iTctE2RlUI5xqLWfE3ZX494B7xgcUu63kt2+6Y6nbNXIYHivoNpGRpoL b9zcN+LCfFOmXGaOuVnjRzpIq1NOJJHsPTKu90n+bHlz7ZCfsy8pAULacZajBemEPxf1 pbHdRCyLhZjVn2M6e2GCeRRFvTOmhb34a9P5QzFAPq4aeMcaK/evhV0A+WbMMWCKZdmr faKM3VznusKba0tJS/pdcxtpgREDzaw+vshpbDUa6Jn5MiGNAiefmoZhoz398dgkoNKK KYcQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MjRKO5wQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id q189si10814766ywg.464.2019.02.28.12.34.23 for (version=TLS1 cipher=AES128-SHA bits=128/128); Thu, 28 Feb 2019 12:34:23 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=MjRKO5wQ; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([127.0.0.1]:46087 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzSNq-0006nE-In for patch@linaro.org; Thu, 28 Feb 2019 15:34:22 -0500 Received: from eggs.gnu.org ([209.51.188.92]:42748) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gzSFb-0000VS-CG for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:52 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gzSFa-0007PO-Bj for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:51 -0500 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:44118) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gzSFa-0007Oe-31 for qemu-devel@nongnu.org; Thu, 28 Feb 2019 15:25:50 -0500 Received: by mail-wr1-x443.google.com with SMTP id w2so23414163wrt.11 for ; Thu, 28 Feb 2019 12:25:50 -0800 (PST) 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=IhmDA8Paz4xh5btvDJbvSxpnzxmgwJBv6Kvn01RZQX4=; b=MjRKO5wQFy1j2r9a3RgaJnu11c4bG1dcQi6FDMqTJOIMwaPypVh6UOFBfbRQmC4glI 8DdtC3Eh7P9v+EzNvVDuDgGN0PCPZEfwdeGqUNBYk6B4L5w4Yb6AxYvEjpMhbP/Slq/S dkD0K+P73bn/CSUOCQKZwzPJTdp/120HMqY9+sR+DOgYpmF/764OwELczSLXYZTdY0c0 3aVZrRVZrVs/Z2xKbDRjYjtCWS4CKQPK17KElbCwP84pevQhpx2WlkJruK2Syg4YoDto xMdRmOmPPkg/HCJh29rucka9oMI5hqS94pmf8g674/0dtoKCRtSlvo3EwBSceN9tHH+D P0Zw== 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=IhmDA8Paz4xh5btvDJbvSxpnzxmgwJBv6Kvn01RZQX4=; b=QsofyXcEKfBYrsBrpJ0MY0B8FA6+DJoRPr2GcV/WJJWSlhFMcm214nNWYSuSX3zNF+ BeH7Sd69jPRaEPW8kvH9/WnzRlPSKz0FIixGLjsCW7n0/wQmdtDeV6pIufkibpK/HXtL L7PGD5KOkO+L+e2euBoDGkk0B0NPmak4BlZrUP4o/baC7bwMNMq0mZoPk1x031WYcB6H r6NiapSz2n4hu6E3wkISViQYGdsyf9RF0YHqrX/naFvrmb1uhYch5OU38WxBMidwRBfh l0UpNsAaYdvDUCJUpHsjZnxt8wtvd0V3eBnrsqYgB8LzZyqc099ECocZc5x2dUK7Nel1 NziA== X-Gm-Message-State: APjAAAXN1IVON2jaoMNo+h2lrRKpxTEjCypcL3RPpAEskHEMmUtcLyCH +TWwgULJgXbtqacOQ6PFqJyyew== X-Received: by 2002:a5d:4945:: with SMTP id r5mr779762wrs.295.1551385549123; Thu, 28 Feb 2019 12:25:49 -0800 (PST) Received: from zen.linaroharston ([81.128.185.34]) by smtp.gmail.com with ESMTPSA id a8sm7401392wmh.26.2019.02.28.12.25.41 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 28 Feb 2019 12:25:45 -0800 (PST) Received: from zen.linaroharston. (localhost [127.0.0.1]) by zen.linaroharston (Postfix) with ESMTP id E47681FF8E; Thu, 28 Feb 2019 20:25:37 +0000 (UTC) From: =?utf-8?q?Alex_Benn=C3=A9e?= To: qemu-devel@nongnu.org Date: Thu, 28 Feb 2019 20:25:32 +0000 Message-Id: <20190228202537.4638-12-alex.bennee@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190228202537.4638-1-alex.bennee@linaro.org> References: <20190228202537.4638-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::443 Subject: [Qemu-devel] [PATCH v2 11/16] tests/tcg/cris: cleanup sys.c 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: edgar.iglesias@gmail.com, qemu-arm@nongnu.org, =?utf-8?q?Alex_Benn?= =?utf-8?b?w6ll?= , jcmvbkbc@gmail.com Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This is a mini library which provides helper functions to the tests which are all currently written in assembly. A bunch of minor changes: - removed libc related headers (fedora-cris-cross is a system compiler) - re-organised the functions to avoid forward declarations - cleaned up brace usage - restored exit for _fail case - removed tabs and fixed indentation Signed-off-by: Alex Bennée --- tests/tcg/cris/bare/sys.c | 96 +++++++++++++++++++-------------------- tests/tcg/cris/libc/sys.c | 23 ++++++---- 2 files changed, 62 insertions(+), 57 deletions(-) -- 2.20.1 diff --git a/tests/tcg/cris/bare/sys.c b/tests/tcg/cris/bare/sys.c index 21f08c0747..aa342335d6 100644 --- a/tests/tcg/cris/bare/sys.c +++ b/tests/tcg/cris/bare/sys.c @@ -1,59 +1,59 @@ -#include -#include -#include - -static inline int mystrlen(char *s) { - int i = 0; - while (s[i]) - i++; - return i; +/* + * Helper functions for CRIS system tests + * + * There is no libc and only a limited set of headers. + */ + +#include + +void exit(int status) +{ + register unsigned int callno asm ("r9") = 1; /* NR_exit */ + + asm volatile ("break 13\n" + : /* no outputs */ + : "r" (callno) + : "memory" ); + while(1); } -void pass(void) { - char s[] = "passed.\n"; - write (1, s, sizeof (s) - 1); - exit (0); -} +size_t write(int fd, const void *buf, size_t count) +{ + register unsigned int callno asm ("r9") = 4; /* NR_write */ + register unsigned int r10 asm ("r10") = fd; + register const void *r11 asm ("r11") = buf; + register size_t r12 asm ("r12") = count; + register unsigned int r asm ("r10"); -void _fail(char *reason) { - char s[] = "\nfailed: "; - int len = mystrlen(reason); - write (1, s, sizeof (s) - 1); - write (1, reason, len); - write (1, "\n", 1); -// exit (1); -} + asm volatile ("break 13\n" + : "=r" (r) + : "r" (callno), "0" (r10), "r" (r11), "r" (r12) + : "memory"); -void *memset (void *s, int c, size_t n) { - char *p = s; - int i; - for (i = 0; i < n; i++) - p[i] = c; - return p; + return r; } -void exit (int status) { - register unsigned int callno asm ("r9") = 1; /* NR_exit */ - - asm volatile ("break 13\n" - : - : "r" (callno) - : "memory" ); - while(1) - ; +static inline int mystrlen(char *s) +{ + int i = 0; + while (s[i]) { + i++; + } + return i; } -ssize_t write (int fd, const void *buf, size_t count) { - register unsigned int callno asm ("r9") = 4; /* NR_write */ - register unsigned int r10 asm ("r10") = fd; - register const void *r11 asm ("r11") = buf; - register size_t r12 asm ("r12") = count; - register unsigned int r asm ("r10"); - asm volatile ("break 13\n" - : "=r" (r) - : "r" (callno), "0" (r10), "r" (r11), "r" (r12) - : "memory"); +void pass(void) { + char s[] = "passed.\n"; + write(1, s, sizeof (s) - 1); + exit(0); +} - return r; +void _fail(char *reason) { + char s[] = "\nfailed: "; + int len = mystrlen(reason); + write(1, s, sizeof (s) - 1); + write(1, reason, len); + write(1, "\n", 1); + exit(1); } diff --git a/tests/tcg/cris/libc/sys.c b/tests/tcg/cris/libc/sys.c index b8e759eee3..6ec4e77b22 100644 --- a/tests/tcg/cris/libc/sys.c +++ b/tests/tcg/cris/libc/sys.c @@ -3,16 +3,18 @@ */ -void exit (int status) { +void exit(int status) +{ register unsigned int callno asm ("r9") = 1; /* NR_exit */ asm volatile ("break 13\n" : : "r" (callno) - : "memory" ); + : "memory"); while(1); } -ssize_t write (int fd, const void *buf, size_t count) { +ssize_t write(int fd, const void *buf, size_t count) +{ register unsigned int callno asm ("r9") = 4; /* NR_write */ register unsigned int r10 asm ("r10") = fd; register const void *r11 asm ("r11") = buf; @@ -27,29 +29,32 @@ ssize_t write (int fd, const void *buf, size_t count) { return r; } -static inline int mystrlen(char *s) { +static inline int mystrlen(char *s) +{ int i = 0; while (s[i]) i++; return i; } -void pass(void) { +void pass(void) +{ char s[] = "passed.\n"; - write (1, s, sizeof (s) - 1); + write (1, s, sizeof(s) - 1); exit (0); } -void _fail(char *reason) { +void _fail(char *reason) +{ char s[] = "\nfailed: "; int len = mystrlen(reason); write (1, s, sizeof (s) - 1); write (1, reason, len); write (1, "\n", 1); -// exit (1); } -void *memset (void *s, int c, size_t n) { +void *memset(void *s, int c, size_t n) +{ char *p = s; int i; for (i = 0; i < n; i++)