From patchwork Sat Mar 11 23:01:53 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Max Filippov X-Patchwork-Id: 9619165 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 17B45604A9 for ; Sat, 11 Mar 2017 23:02:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0A2C02857D for ; Sat, 11 Mar 2017 23:02:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F36B4285A0; Sat, 11 Mar 2017 23:02:34 +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=-5.3 required=2.0 tests=BAYES_00, DKIM_ADSP_CUSTOM_MED, DKIM_SIGNED, FREEMAIL_FROM, FROM_LOCAL_NOVOWEL, HK_RANDOM_FROM, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id A28432857D for ; Sat, 11 Mar 2017 23:02:34 +0000 (UTC) Received: from localhost ([::1]:44955 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmq1x-0000TD-Po for patchwork-qemu-devel@patchwork.kernel.org; Sat, 11 Mar 2017 18:02:33 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:58334) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1cmq1g-0000S5-UQ for qemu-devel@nongnu.org; Sat, 11 Mar 2017 18:02:17 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1cmq1f-0000pJ-5Y for qemu-devel@nongnu.org; Sat, 11 Mar 2017 18:02:17 -0500 Received: from mail-pf0-x244.google.com ([2607:f8b0:400e:c00::244]:35726) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1cmq1f-0000pC-13 for qemu-devel@nongnu.org; Sat, 11 Mar 2017 18:02:15 -0500 Received: by mail-pf0-x244.google.com with SMTP id 67so14859878pfg.2 for ; Sat, 11 Mar 2017 15:02:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oxZ7kMzKm0PzUhxwp6eTNm/5RrCoFwh+XLGErOkwbW4=; b=fE2hO/vHtduPL66huiBCU5Sxp7+R71SiP1owiERH/IVQLVLIPqHUtQx7xP6SIKX7d7 oOhc3Mg1po51lvQtD/Job3W+LLp5JDyMffnfROgWYjhjXycbnrP73Jqs3U/gn6VSpPFh 37LLoUPTS8+CAgSPE2Xq1wa8Ioeyc60aW+leOj+f+eEKTfj1Ejpj3huPgJLGIT4jcmT8 IRQN6hh9t8WEnnNax1Y3ps/AUCSSnyiLV7tWMCcophm9e+pqsHY/rKD7XprSVKpZSYcu 6J1HbqKxlOIYsmspCit8mRHwr1zEMj1SdEhp8Q08aqu/L6tXjdA/z0z0G0Mjgj26LhGr gWWQ== 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; bh=oxZ7kMzKm0PzUhxwp6eTNm/5RrCoFwh+XLGErOkwbW4=; b=Yoz8rRcvrFdzUx6EKZ+KT85ZM7UibH1UaE+OZ5YPX4vzO+qUewXBLDN/ZWV0x1MLsj wlY1izCBsWbHXrntaD+i2iNgajnzee3LPhEZk2JaLePD11/M9c8fjgikTDAoAoEp4u5J xyc7yACMASk+BcaD17f9c11YTE5x6lZ7JCyiFhJHE8r21OEmRF8VwhXtD9/5T6aSBj2x CXmJ5tlYMrtH3p2rFAvVtmTXPcbAiwnvla3X4GsvRzadB65TrhW6Gz7BYqY1xnJWB76N pUTvEyJ8W0ncO7xDvzk1A8pekxhA5NPnVwi7f2qpSn9cxHAwiyeVkPrfHm0vfGmXFH48 1NqA== X-Gm-Message-State: AMke39mUNmMv4f3kXQXHmfW41RKl1Oj7joxrH22DPzcaHOxhQtjDZ7KLK+ZhWb6btfCnAw== X-Received: by 10.98.79.90 with SMTP id d87mr28766773pfb.126.1489273333892; Sat, 11 Mar 2017 15:02:13 -0800 (PST) Received: from octofox.metropolis ([12.47.132.3]) by smtp.gmail.com with ESMTPSA id d68sm25833703pfj.92.2017.03.11.15.02.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Sat, 11 Mar 2017 15:02:13 -0800 (PST) From: Max Filippov To: qemu-devel@nongnu.org Date: Sat, 11 Mar 2017 15:01:53 -0800 Message-Id: <1489273313-22628-1-git-send-email-jcmvbkbc@gmail.com> X-Mailer: git-send-email 2.1.4 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2607:f8b0:400e:c00::244 Subject: [Qemu-devel] [PATCH] target/xtensa: fix semihosting argc/argv implementation 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: Max Filippov Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP So far xtensa provides fixed dummy argc/argv for the corresponding semihosting calls. Now that there are semihosting_get_argc and semihosting_get_arg, use them to pass actual command line arguments to guest. Signed-off-by: Max Filippov --- target/xtensa/xtensa-semi.c | 49 +++++++++++++++++++++++++++++++++------------ 1 file changed, 36 insertions(+), 13 deletions(-) diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 370e365..a888a9d 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -28,6 +28,7 @@ #include "qemu/osdep.h" #include "cpu.h" #include "exec/helper-proto.h" +#include "exec/semihost.h" #include "qemu/log.h" enum { @@ -261,28 +262,50 @@ void HELPER(simcall)(CPUXtensaState *env) break; case TARGET_SYS_argc: - regs[2] = 1; + regs[2] = semihosting_get_argc(); regs[3] = 0; break; case TARGET_SYS_argv_sz: - regs[2] = 128; - regs[3] = 0; + { + int argc = semihosting_get_argc(); + int sz = (argc + 1) * sizeof(uint32_t); + int i; + + for (i = 0; i < argc; ++i) { + sz += 1 + strlen(semihosting_get_arg(i)); + } + regs[2] = sz; + regs[3] = 0; + } break; case TARGET_SYS_argv: { - struct Argv { - uint32_t argptr[2]; - char text[120]; - } argv = { - {0, 0}, - "test" - }; - - argv.argptr[0] = tswap32(regs[3] + offsetof(struct Argv, text)); + int argc = semihosting_get_argc(); + int str_offset = (argc + 1) * sizeof(uint32_t); + int i; + uint32_t argptr; + + for (i = 0; i < argc; ++i) { + const char *str = semihosting_get_arg(i); + int str_size = strlen(str) + 1; + + argptr = tswap32(regs[3] + str_offset); + + cpu_memory_rw_debug(cs, + regs[3] + i * sizeof(uint32_t), + (uint8_t *)&argptr, sizeof(argptr), 1); + cpu_memory_rw_debug(cs, + regs[3] + str_offset, + (uint8_t *)str, str_size, 1); + str_offset += str_size; + } + argptr = 0; cpu_memory_rw_debug(cs, - regs[3], (uint8_t *)&argv, sizeof(argv), 1); + regs[3] + i * sizeof(uint32_t), + (uint8_t *)&argptr, sizeof(argptr), 1); + regs[3] = 0; } break;