From patchwork Tue Sep 10 14:44:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173524 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5899929ilq; Tue, 10 Sep 2019 07:46:32 -0700 (PDT) X-Google-Smtp-Source: APXvYqw3TwFfsmqiDj6Pev9SyeuZ5A/NM7jFt/dZ0P95J/b+1xq4hn7HoHS5ZQgHBGhZHbf2xIdc X-Received: by 2002:ac8:1c54:: with SMTP id j20mr29863069qtk.302.1568126792272; Tue, 10 Sep 2019 07:46:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568126792; cv=none; d=google.com; s=arc-20160816; b=IidGAWtiOGy4f2k88sSc/QEIT3Wd/VZijjSQsPjVgUFE84Y1vH3MXeWXQajHXm6yr2 C0zm2ZlbAosGsoYsW/dSsjCv9If7jgRWxRk/z/CbAQGP3kOmOBWVNji16jZwrvTiYuM4 ttD6jJTWK5DpQu+Irnon5Pet4kjspeO8VSL6I6XA7U/4SEAmytx8GW30OxRGI4/tIMUg Xd6moLZvdjionArHiJLKskGQUan4C0z7nonLlbw5U0Qctkce+kmDIsK9uVFHDOnid0YG rewg1zl8+3XmJke0N89EXoMoGi3sujEfufOXizBIFPklUKhj7H7fIK9MhfSbBLsEwK9J 4erg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=enPywXzeQn7ydtPCLlfXnrBKEhQX7hDQH1X+QA8UtcxnjZwWL4lGglqOLxOgcyCQvQ 1w/o7VMQr53A5t4iuIol2myM/WQaSJ9hYEVb67/hUuw9Pok/iH0vXzXdQS3NyoIq26UZ As4ZCiVPS9Aayybip0Lkw2sCia+Exfbk4YjvEei2Hikttuz0GHgK0nqh7P6WA0w3YAee Wpavzj7onnx6M6wiwgUygJlwhjrbrW0EmPHJkYNSY2J8mR9IHhTnpZV6h2985CRxx6wa Z1yAzKSrAFWv3TWH6YdTfTIS7k8UBFJtnS8mqRrCVv/iCg9+pGuW+wyIXOMPCBnXzhAk sRLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=yjlgCfy9; 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 b186si12656046qkf.220.2019.09.10.07.46.32 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:46:32 -0700 (PDT) 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=yjlgCfy9; 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 ([::1]:40642 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hPb-0005Ne-2m for patch@linaro.org; Tue, 10 Sep 2019 10:46:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53877) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNi-0005Kt-Bo for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNh-0004xX-9k for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:34 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:46933) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNh-0004x4-3S for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:33 -0400 Received: by mail-wr1-x441.google.com with SMTP id d17so8066013wrq.13 for ; Tue, 10 Sep 2019 07:44:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=yjlgCfy9He+gTLDKlS4tw4uJ09J7Z4UDlHWsRjtbB+txmHoBkLZCVFMrmmsmTuh2NW rlmUYDsPDLwT6abct4DmFK3w9vnVVOmqK7dNdwZzduuRc7ceYZpHMpN6mYv2VPje1hX8 LUv8zHDO6H0C7IbQZ7lKKSWPisdiX9jbI1gx7JtgLDtDYbepW6gzfg8yifKqH7TlyaQn IDFNKgXt9L4uYdzZT3sBGEgSaoH91SkjAjOkSdzm7hUUnSw3fAQcW3V+xj4SBCvTBeaD uwFB2vzUsONxWrPeppaFOLM9bnBAhkckPPCYVh2W1XHxvqGJkv4It126hXq3BPWXRltt rSnw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+93zhnxV6y7awAg0ASSqV7pmnPcURr2F+yzvl9fZsA4=; b=Um12oqQjEQuMMkNDLp34unzia1b5GtXgntf6MpBuG5KGHTvuiT4zH8IUs+Hj9McvXB Np/c4g+G6yJse547yl+JPL716KkJhixtzHDsUE9FOBGdf7UmG5FOxvYWxF4Be0HxtC3O UbwkYm8rWlxLfYDK8687zTTeoP/0/GuibqoDmUjC/wBrmD0Lu7hjF4mJRZFS0w4OQq5R 4AcBKeuf2lO2mpcBTikKn8X0MyF1lx/9wGWwMBWDDUGNc+ngsaTvuJVgvbJjLYZTndX9 Vabg8Yfjr/kKLoE+U9PisRt+spEnZBLdTRwbJZNSop9OW3Adi7IRGQSOwNaXnXJM1xFx MwtQ== X-Gm-Message-State: APjAAAWPlmpa5ztykVlOH5hCK13fr8daJ9fo3DygD8V1UJNSA60TrI0y nb/CBBoPOKIGheqZDaSHbv/oJQ== X-Received: by 2002:adf:f110:: with SMTP id r16mr4111003wro.152.1568126672093; Tue, 10 Sep 2019 07:44:32 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:31 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:16 +0100 Message-Id: <20190910144428.32597-2-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::441 Subject: [Qemu-devel] [PATCH 01/13] target/arm/arm-semi: Capture errno in softmmu version of set_swi_errno() X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The set_swi_errno() function is called to capture the errno from a host system call, so that we can return -1 from the semihosting function and later allow the guest to get a more specific error code with the SYS_ERRNO function. It comes in two versions, one for user-only and one for softmmu. We forgot to capture the errno in the softmmu version; fix the error. (Semihosting calls directed to gdb are unaffected because they go through a different code path that captures the error return from the gdbstub call in arm_semi_cb() or arm_semi_flen_cb().) Signed-off-by: Peter Maydell --- NB that a later commit will put in some cleanup of TaskState that will let us reduce the duplication between the two implementations of this function. --- target/arm/arm-semi.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) -- 2.20.1 diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 90423a35deb..03e60105c05 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -114,8 +114,13 @@ static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) return code; } #else +static target_ulong syscall_err; + static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) { + if (code == (uint32_t)-1) { + syscall_err = errno; + } return code; } @@ -124,10 +129,6 @@ static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) static target_ulong arm_semi_syscall_len; -#if !defined(CONFIG_USER_ONLY) -static target_ulong syscall_err; -#endif - static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { ARMCPU *cpu = ARM_CPU(cs); From patchwork Tue Sep 10 14:44:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173525 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5900542ilq; Tue, 10 Sep 2019 07:46:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqxPf4dnMfZAzdqMDhaEqKmb8p2j7amPV9JN/EpCIPo3ErsA/6fdzCbzcTkWCoWTppQmxy0F X-Received: by 2002:a37:9804:: with SMTP id a4mr30258672qke.149.1568126817706; Tue, 10 Sep 2019 07:46:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568126817; cv=none; d=google.com; s=arc-20160816; b=u/wp5iCV/qNSe038XQ0+nVl7xjhJlZ0oPdqXzaE1gWDQuLlim+zFRAGsZ+fJB+NgyZ AHMa4TC6SxUnVGpgnpkYNx4kwrKlkZyzBrysApm/qnzzczi5ajWMul5qplhfVkOITz9Q VfNRxNTAosiVy4IJyOdaf1dqAXVZ1JdZnRPfypUu307QeNDepXW0gDnHeVLonssrx4ZO lgEVSoXBCppk4ExL5LnuinXvbr7Ow8+UQYmbGwocjHgb/83TCpN5CGQm/eZoGL0i8Smo 1hBgPKH2UKVMLJaBA/Yi1WWGXIT1jVzXgQzwreQ99LlnO0TClW9NXy7dBKi93Uzm/XiY qGig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=BlCzcnZod8AgP+4BldedCTxgO3zHRl08VhWwYiQFRKNvYOWbphGb1zWGk/p4acry7i tfOkvNhl7ebxu7/Gxjo/blB5EC7s2jTzqeAyo1a4GLl9XjgvdtWNbOVRfuupnHnHCn+s WJjBUKr/fDFqViNn9r4W/zvJqBR3W2Zrlr+cjFUQFzmIDasKtXUoFLOfr8uKPryy/DBN Wf2j1IFGMDOHrmuJrzB0POLZ4MGzitkkBjxd0h7ciZyBlgyN0J7qsWylXYw0TBrZoahu lHvfL9xQe+Exoez6X1dZPfRp9JQ64opYcVGvFpqwGY1CqKXFDnkwxQweYcVMx9PlWlFU gsXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b="WgiYbb/m"; 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 w14si12637594qvf.143.2019.09.10.07.46.57 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:46:57 -0700 (PDT) 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="WgiYbb/m"; 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 ([::1]:40794 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hQ0-0005uy-PG for patch@linaro.org; Tue, 10 Sep 2019 10:46:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53915) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNk-0005Nb-21 for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNi-0004yO-JD for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:45992) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNi-0004xl-CG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:34 -0400 Received: by mail-wr1-x444.google.com with SMTP id l16so20757129wrv.12 for ; Tue, 10 Sep 2019 07:44:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=WgiYbb/m97Pv6ppe2CbKzjKpvS7dFJb+zzJ+DkMmn9q2TdNEUxLAo4aizxIfdunzfr 0hM9q+hAi3EHbk5AP37qhV8rBEDQkM6YA8JTF8wGv6vqDDeJ5d8esuUTbP0zdkx88l81 DvehzHc7ZCldsLYEEUoL5oanNjtjKcJvZatrEjWSa3h+x7/0LsRYm1SD3Zj2+51MI/AP 3pxqFfop6EMdCqsf3OOAjDuyqBgoV8Q+x3CzdML6uhQ0+3FZnP1O+D8rpnA389ezLgpd vWI25Ku1y+Z2Wkrdcwn2ZKBnwonO9MJjzDlOsg0AoGdJcqE5dw4syy4ABW7YJXXDU0u2 XRzg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Z9gxd6ZnA/tu16GX4u76t9CmQTv6s8qenU28wrY9d9Y=; b=oso/Ofr5YeS1J2rZbkDvMaHpUoVf3kmRUsmZE6JX0ywUss2ealOENpyAEC7NiJg34r M4vbb4o+o/n9n6GbFAwBuR3UJQC1Qy/JpDTsiM50UC1QCWaUn2a1r2h50fntju3Eb02Y ch0gFp5vDXD+/f/V4fCKQn8U1RAYWFf37kUP6bCRdZCNhyj0n9H0WvhvLQbdllKNVN+W gD4K9Ra7eHz1DmS3brMWvl17nYeXcd3LxZNDLMNfqthV/3hyrpDJxraROoWiCty9872v lJzS7XTtAbrFjSssv05noq+nUCLqHnOQa2JKKNRAjJrnj9esr0oF7FGVWffx1G0/LlhD 0Egw== X-Gm-Message-State: APjAAAUP5qEsrCKIJSxejlFcBonMQPPymmADX/9KGfI0rI4Fmo6byhhp Dsy5RH6MGIKRJM1ne50Wda82fg== X-Received: by 2002:a5d:6302:: with SMTP id i2mr27913008wru.249.1568126673412; Tue, 10 Sep 2019 07:44:33 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:32 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:17 +0100 Message-Id: <20190910144428.32597-3-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::444 Subject: [Qemu-devel] [PATCH 02/13] target/arm/arm-semi: Always set some kind of errno for failed calls X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" If we fail a semihosting call we should always set the semihosting errno to something; we were failing to do this for some of the "check inputs for sanity" cases. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 45 ++++++++++++++++++++++++++----------------- 1 file changed, 27 insertions(+), 18 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 03e60105c05..51b55816faf 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -232,11 +232,13 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, #define GET_ARG(n) do { \ if (is_a64(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ - return -1; \ + errno = EFAULT; \ + return set_swi_errno(ts, -1); \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - return -1; \ + errno = EFAULT; \ + return set_swi_errno(ts, -1); \ } \ } \ } while (0) @@ -287,12 +289,13 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(2); s = lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno = EFAULT; + return set_swi_errno(ts, -1); } if (arg1 >= 12) { unlock_user(s, arg0, 0); - return (uint32_t)-1; + errno = EINVAL; + return set_swi_errno(ts, -1); } if (strcmp(s, ":tt") == 0) { int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; @@ -413,8 +416,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s = lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno = EFAULT; + return set_swi_errno(ts, -1); } ret = set_swi_errno(ts, remove(s)); unlock_user(s, arg0, 0); @@ -432,11 +435,12 @@ target_ulong do_arm_semihosting(CPUARMState *env) char *s2; s = lock_user_string(arg0); s2 = lock_user_string(arg2); - if (!s || !s2) - /* FIXME - should this error code be -TARGET_EFAULT ? */ - ret = (uint32_t)-1; - else + if (!s || !s2) { + errno = EFAULT; + ret = set_swi_errno(ts, -1); + } else { ret = set_swi_errno(ts, rename(s, s2)); + } if (s2) unlock_user(s2, arg2, 0); if (s) @@ -456,8 +460,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { s = lock_user_string(arg0); if (!s) { - /* FIXME - should this error code be -TARGET_EFAULT ? */ - return (uint32_t)-1; + errno = EFAULT; + return set_swi_errno(ts, -1); } ret = set_swi_errno(ts, system(s)); unlock_user(s, arg0, 0); @@ -517,19 +521,22 @@ target_ulong do_arm_semihosting(CPUARMState *env) if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - return -1; + errno = E2BIG; + return set_swi_errno(ts, -1); } /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - return -1; + errno = EFAULT; + return set_swi_errno(ts, -1); } /* Lock the buffer on the ARM side. */ output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); if (!output_buffer) { - return -1; + errno = EFAULT; + return set_swi_errno(ts, -1); } /* Copy the command-line arguments. */ @@ -544,7 +551,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) if (copy_from_user(output_buffer, ts->info->arg_start, output_size)) { - status = -1; + errno = EFAULT; + status = set_swi_errno(ts, -1); goto out; } @@ -614,7 +622,8 @@ target_ulong do_arm_semihosting(CPUARMState *env) if (fail) { /* Couldn't write back to argument block */ - return -1; + errno = EFAULT; + return set_swi_errno(ts, -1); } } return 0; From patchwork Tue Sep 10 14:44:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173529 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5907178ilq; Tue, 10 Sep 2019 07:52:31 -0700 (PDT) X-Google-Smtp-Source: APXvYqyhPOkzkLsqOtckAIJFvqHZi3LHSDYekuGAQyc2LZjUDMQKiWitFqhBH02JvkvB7KMaKJaB X-Received: by 2002:aa7:cd6f:: with SMTP id ca15mr4477606edb.172.1568127151562; Tue, 10 Sep 2019 07:52:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127151; cv=none; d=google.com; s=arc-20160816; b=slsKAjqpLEcjcDEyA6H5DMkKXl+YNYbssBWgrOIICltOQ9KhqsaJMWXmvjVwG4FkHD B3Hl9VVz04mlnYzvvjiMJlxO/5qH9BjazN/cRAy71LQO7+jHMJ0zyHld1lwL6UKit46U E0PMxxLjhQYUkL4B6Xb2ZzlH+VvQI2QjAADduZ4lc3P1gI109EA/S9uaKt+KEraYmrmW BeA0JevX0ku19g2VL5GjNhRmhFoHEFt+g3Sx7zV0BqyVMtnFAjchwXwekuIET8KD9E/v CjmvwgAPmCTGbbl4MMVP/l1/lCZ8kwLctl6QJv1IXNQSJRCgNucS8+GT0mBHwXhryX6o 9C0A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=r92dHGpoWWxiKFr4mtT9GC8EHi7oaLqR71tkj69EPKHu/tUCgXHywJvHT327JQ8CNM HH4v3wCAdlM/iST2+smEZbMrVii3QliLNJ2TTN096I5NiX++BY3lSypuQt7eyy4zNwmS f/Bt0uFD7sgpUbHRjWt+BdaL2iaANSLZ3KlGDTAlQPFMgN12hFXpaC2/5La3OulKi54O 26VTRx+OyMpN+xiRyzQfURJd3t2pfi2PKdHs6Hm+f06QheaNthozd+rVlFbnTngt1abw ETGum2stVwo42B5km3brK3UNdV3UXcrOYDiPW3U7raix4BJ8jm+sQwuB8HukroKxVMjY 2s8g== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=LuBKYNJ2; 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 z21si10839142edc.4.2019.09.10.07.52.31 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:52:31 -0700 (PDT) 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=LuBKYNJ2; 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 ([::1]:40912 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hVN-00038j-Jt for patch@linaro.org; Tue, 10 Sep 2019 10:52:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54051) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005VA-Lx for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNj-0004zE-RP for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from mail-wr1-x430.google.com ([2a00:1450:4864:20::430]:44607) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNj-0004yn-Ko for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:35 -0400 Received: by mail-wr1-x430.google.com with SMTP id k6so8680231wrn.11 for ; Tue, 10 Sep 2019 07:44:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=LuBKYNJ2o5yuSO/JadJO497TvA6PWxuyGKpPqe4eEc2yMcDuqW4SEbEwTqyEC6nN23 wGxD0GFSQdHUixcTYy1RJ6epcEouLrlp6FiKKjBLy8wuNvWGTpuQANZ7bhHsZaVy2dUl PcK2tX5KGhAHwj0NJqFTpR6XgTdMQPKqstPxa2E0qRHw1lIe7qQI4S5HhqVhe9RzuSXn 0PdEBZAHs5uKAwwn5XBi38fL0Xo7XEy9nOFuQoM8ms+elJ6Jfzvs6fnBOXOOpfV5PfTs jj6OAfnZ8A1tKwcBV/222DiVGULl0oY2uJEVzadV3YgNHXIVwgo+9UpmpIRgO8INSAw2 mLhg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=KUZg/wLKZ46VG6GAy4EjR/UMqLr/ow3tF/QTUuuGP6s=; b=TApzCVbL45P3VNRlCWk7jrAY+8DSNespkrRicy1RPfgXLA6h7tQNRZmpu4+ki1vnN5 t5djhIxubjLFB91GfIBmULRdbScxSWoGzKqRBp5jnhlyJtfXSDMfwuGLdjC1HNuuPPVO 9OaUVU/QqZvtdma1gMuDg1dEIvO6bC/YeK/T5OSK8qSsDY9/B0V6iP9irp4rqzPzSX9t 2Z9Pm75njYaC54I2KBuXKbSIWcIRmnyVR+3A+0/WNXLrVK/cUa2AyYWsH1So1of7+OoY QlgNs3ZZjDDn34n9vqkeQfUPXvca+8GnTd56lP2LN48RebCvjwuf8a9ebig1qFBMFJD0 mXRw== X-Gm-Message-State: APjAAAVL9yybpDQ1sM1mDkbrwlvQYXBXS4sgwSsXjPwm48SEd+ty6QgS Mv6HnwdZ8h4Z1PYra+azB+am1PaOaSy2nQ== X-Received: by 2002:a5d:4907:: with SMTP id x7mr27816658wrq.72.1568126674549; Tue, 10 Sep 2019 07:44:34 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:33 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:18 +0100 Message-Id: <20190910144428.32597-4-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::430 Subject: [Qemu-devel] [PATCH 03/13] target/arm/arm-semi: Make semihosting code hand out its own file descriptors X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently the Arm semihosting code returns the guest file descriptors (handles) which are simply the fd values from the host OS or the remote gdbstub. Part of the semihosting 2.0 specification requires that we implement special handling of opening a ":semihosting-features" filename. Guest fds which result from opening the special file won't correspond to host fds, so to ensure that we don't end up with duplicate fds we need to have QEMU code control the allocation of the fd values we give the guest. Add in an abstraction layer which lets us allocate new guest FD values, and translate from a guest FD value back to the host one. This also fixes an odd hole where a semihosting guest could use the semihosting API to read, write or close file descriptors that it had never allocated but which were being used by QEMU itself. (This isn't a security hole, because enabling semihosting permits the guest to do arbitrary file access to the whole host filesystem, and so should only be done if the guest is completely trusted.) Currently the only kind of guest fd is one which maps to a host fd, but in a following commit we will add one which maps to the :semihosting-features magic data. If the guest is migrated with an open semihosting file descriptor then subsequent attempts to use the fd will all fail; this is not a change from the previous situation (where the host fd being used on the source end would not be re-opened on the destination end). Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 201 ++++++++++++++++++++++++++++++++++++++---- 1 file changed, 186 insertions(+), 15 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 51b55816faf..05491bf5248 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -106,6 +106,113 @@ static int open_modeflags[12] = { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; +typedef enum GuestFDType { + GuestFDUnused = 0, + GuestFDHost = 1, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + int hostfd; +} GuestFD; + +static GArray *guestfd_array; + +/* + * Allocate a new guest file descriptor and return it; if we + * couldn't allocate a new fd then return -1. + * This is a fairly simplistic implementation because we don't + * expect that most semihosting guest programs will make very + * heavy use of opening and closing fds. + */ +static int alloc_guestfd(void) +{ + guint i; + + if (!guestfd_array) { + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + } + + for (i = 0; i < guestfd_array->len; i++) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); + + if (gf->type == GuestFDUnused) { + return i; + } + } + + /* All elements already in use: expand the array */ + g_array_set_size(guestfd_array, i + 1); + return i; +} + +/* + * Look up the guestfd in the data structure; return NULL + * for out of bounds, but don't check whether the slot is unused. + * This is used internally by the other guestfd functions. + */ +static GuestFD *do_get_guestfd(int guestfd) +{ + if (!guestfd_array) { + return NULL; + } + + if (guestfd < 0 || guestfd >= guestfd_array->len) { + return NULL; + } + + return &g_array_index(guestfd_array, GuestFD, guestfd); +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host fd. + */ +static void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDHost; + gf->hostfd = hostfd; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +static void dealloc_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDUnused; +} + +/* + * Given a guest file descriptor, get the associated struct. + * If the fd is not valid, return NULL. This is the function + * used by the various semihosting calls to validate a handle + * from the guest. + * Note: calling alloc_guestfd() or dealloc_guestfd() will + * invalidate any GuestFD* obtained by calling this function. + */ +static GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + if (!gf || gf->type == GuestFDUnused) { + return NULL; + } + return gf; +} + #ifdef CONFIG_USER_ONLY static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) { @@ -272,6 +379,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) #else CPUARMState *ts = env; #endif + GuestFD *gf; if (is_a64(env)) { /* Note that the syscall number is in W0, not X0 */ @@ -284,6 +392,9 @@ target_ulong do_arm_semihosting(CPUARMState *env) switch (nr) { case TARGET_SYS_OPEN: + { + int guestfd; + GET_ARG(0); GET_ARG(1); GET_ARG(2); @@ -297,10 +408,19 @@ target_ulong do_arm_semihosting(CPUARMState *env) errno = EINVAL; return set_swi_errno(ts, -1); } + + guestfd = alloc_guestfd(); + if (guestfd < 0) { + unlock_user(s, arg0, 0); + errno = EMFILE; + return set_swi_errno(ts, -1); + } + if (strcmp(s, ":tt") == 0) { int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; + associate_guestfd(guestfd, result_fileno); unlock_user(s, arg0, 0); - return result_fileno; + return guestfd; } if (use_gdb_syscalls()) { ret = arm_gdb_syscall(cpu, arm_semi_cb, "open,%s,%x,1a4", arg0, @@ -308,15 +428,31 @@ target_ulong do_arm_semihosting(CPUARMState *env) } else { ret = set_swi_errno(ts, open(s, open_modeflags[arg1], 0644)); } + if (ret == (uint32_t)-1) { + dealloc_guestfd(guestfd); + } else { + associate_guestfd(guestfd, ret); + ret = guestfd; + } unlock_user(s, arg0, 0); return ret; + } case TARGET_SYS_CLOSE: GET_ARG(0); - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", arg0); - } else { - return set_swi_errno(ts, close(arg0)); + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); } + + if (use_gdb_syscalls()) { + ret = arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); + } else { + ret = set_swi_errno(ts, close(gf->hostfd)); + } + dealloc_guestfd(arg0); + return ret; case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(env, args); return 0xdeadbeef; @@ -327,17 +463,24 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(1); GET_ARG(2); len = arg2; + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { arm_semi_syscall_len = len; return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", - arg0, arg1, len); + gf->hostfd, arg1, len); } else { s = lock_user(VERIFY_READ, arg1, len, 1); if (!s) { /* Return bytes not written on error */ return len; } - ret = set_swi_errno(ts, write(arg0, s, len)); + ret = set_swi_errno(ts, write(gf->hostfd, s, len)); unlock_user(s, arg1, 0); if (ret == (uint32_t)-1) { ret = 0; @@ -350,10 +493,17 @@ target_ulong do_arm_semihosting(CPUARMState *env) GET_ARG(1); GET_ARG(2); len = arg2; + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { arm_semi_syscall_len = len; return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", - arg0, arg1, len); + gf->hostfd, arg1, len); } else { s = lock_user(VERIFY_WRITE, arg1, len, 0); if (!s) { @@ -361,7 +511,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return len; } do { - ret = set_swi_errno(ts, read(arg0, s, len)); + ret = set_swi_errno(ts, read(gf->hostfd, s, len)); } while (ret == -1 && errno == EINTR); unlock_user(s, arg1, len); if (ret == (uint32_t)-1) { @@ -375,31 +525,52 @@ target_ulong do_arm_semihosting(CPUARMState *env) return 0; case TARGET_SYS_ISTTY: GET_ARG(0); + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", arg0); + return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); } else { - return isatty(arg0); + return isatty(gf->hostfd); } case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - arg0, arg1); + gf->hostfd, arg1); } else { - ret = set_swi_errno(ts, lseek(arg0, arg1, SEEK_SET)); + ret = set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET)); if (ret == (uint32_t)-1) return -1; return 0; } case TARGET_SYS_FLEN: GET_ARG(0); + + gf = get_guestfd(arg0); + if (!gf) { + errno = EBADF; + return set_swi_errno(ts, -1); + } + if (use_gdb_syscalls()) { return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", - arg0, arm_flen_buf(cpu)); + gf->hostfd, arm_flen_buf(cpu)); } else { struct stat buf; - ret = set_swi_errno(ts, fstat(arg0, &buf)); + ret = set_swi_errno(ts, fstat(gf->hostfd, &buf)); if (ret == (uint32_t)-1) return -1; return buf.st_size; From patchwork Tue Sep 10 14:44:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173531 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5908661ilq; Tue, 10 Sep 2019 07:53:47 -0700 (PDT) X-Google-Smtp-Source: APXvYqzL/3jzIY/APGpt8S0jJhTf+ycAAZ5snMVFYbByT5ln6DYWLUUeIYve2ireAF6liNebHsAz X-Received: by 2002:a05:620a:1288:: with SMTP id w8mr16675916qki.80.1568127227544; Tue, 10 Sep 2019 07:53:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127227; cv=none; d=google.com; s=arc-20160816; b=Nuaf3yiTD5SxUNCL9GTonFAzOsLOf5oaGEGGptTZKyWpU737wwUAS8lh79r+EIrQN+ uaZsuDgLiT6KPyrVfIhfkXaLtti/8snS+m2wXfSUd30hxnTssw0RWLZ3J1eUoGJHK/9g Kv2hBiQzkahMxUNj/MSeaut7o44IIqBkQHXQl7qFNO5QyU4lD1aBBXsQxlrudsXy2MEz /2vAIapQwnY4KRO+RmU2CgqcVdu7DcPX1rTqgAIRKu5wzPtU2ZFjAX7HEp9fLz71icpi pGmVtftBYTx/B/g112Mx+t7op+sU9vawmSj2UNaEEjgsf7/n5a4ZwwzRKmftQHxdqQLC P1hA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=tjfRpxhkWYIzDmNlWLSpzTJFtPXNEOH0Yj84/fY51eKtCCI/rxfu/BnaJRRWOLOrGZ kfVSfGZpdbpBw5gdZ1iga0RT6IE3oK3LbrrY/Ovh49jGp8RYVzTLTF9OisHSY+o1QF01 xxD00nQSuBCTnS3oI+Ek8W5fGwdmS0B+uuU3KBoK9mgy1covgPnhndBLTa0g/50B3W5S m9wC740ReqcUz/UPy6ngTViZLjSrFtyhMM13ZMDlhgIFGgSS74apGIEvfBSCATZgLHlM MMjnyBIAuusKwCn+HLAwZB/ri6j6TK4DBISbn40CTSBPw4RlHQ+r5+AeMNZfBDci1oVS oCaA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=IX1Bn+L7; 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 g17si12104789qto.208.2019.09.10.07.53.47 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:53:47 -0700 (PDT) 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=IX1Bn+L7; 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 ([::1]:40949 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hWc-0004zJ-FF for patch@linaro.org; Tue, 10 Sep 2019 10:53:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53956) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNl-0005PV-RP for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNk-0004zj-Gk for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:34246) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNk-0004z7-Am for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:36 -0400 Received: by mail-wr1-x441.google.com with SMTP id a11so11068229wrx.1 for ; Tue, 10 Sep 2019 07:44:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=IX1Bn+L75xsE7wR97ujQGTwx7gERV6QZ/5uUFlJkg4cM3TAIGRuAZ2f8MUOuzmaH/l 7p/3UeB5SACUV7ULkrYPZf4l2JC6jj9Ia/1JBrdu/hhdk1juMbf8qBwLTe92d8CIm2NH WqRilXdkGprmhh3ov14IQ7t9hsiz58myU8OUi1MYToYLLjsE8dU5/PPSjzbfSGiJadSs odf3GudeX81c3LIKoUY4DDPGTQ+v4lqfc74WKRh2/Rk+9uigZLmqKWZKFn9C/RpQPWBT H58yH/v9YQlvo4v5LyWy2MbX0gUfHO+LhyDje0OVd5RAKY69sFsgMk0+YMYgWXUZ/p/I WqTA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=fZA5qZtHref6EES7glsBu8W4zydJFLjuwr0G2I/qEek=; b=ixugX+z0mqG66vfI4OGO/XOLf+l+SJOHKwsJM8jhWeqmsiUXwvOd8c+Zyba9i1NPiv E5BVJyEjKsgsRm1MO3HAZwBpKAtjr4ItgLjYHd6xf4D18QM4yVGEiSB80k/N+91mzicY wjjLjpcq5nbAtfh237hNR1qIToHMskbl9JEmpkUiaeOdf40iFb4z52Ecs9S8CH30mK2Q SG9vJF079+gudjxizzl2dr6/PW4I5TURjWpG2Yjn/uis2GdkmDZZj+HrisuAl2VOk/xC ATfCB0h2Dc/BwS2jygBzWZP5BVesvtBlNlh5/ISP8nImsQHwAUk85Oi3U9hLl7eT4SeC lSdw== X-Gm-Message-State: APjAAAVBNMSEB0jX5944EZh0WBSqN/nEMi1GYPR5ZiSgDqlgPX3SSB5j JXv+F4C+PfCfwmiH5Lk7tSJJEA== X-Received: by 2002:adf:ebd0:: with SMTP id v16mr18411913wrn.352.1568126675477; Tue, 10 Sep 2019 07:44:35 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:34 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:19 +0100 Message-Id: <20190910144428.32597-5-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::441 Subject: [Qemu-devel] [PATCH 04/13] target/arm/arm-semi: clean up TaskState* usage in non-user-only code X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" The semihosting code has to build for both user-only and softmmu; for user-only it needs access to the TaskState struct that holds per-thread information. For softmmu we don't need it. Currently the softmmu set_swi_errno() takes a CPUARMState *, which it doesn't use, and the 'ts' variable in do_arm_semihosting() is set to either be a TaskState* or a CPUARMState* depending on whether CONFIG_USER_ONLY is set, so that the callsite always passes 'ts'. Since we don't actually need the CPUARMState *, we can instead make set_swi_errno() always take a TaskState*, by providing a local-to-this-file dummy typedef for the softmmu case and setting ts to NULL for softmmu. This will make it easier to have other functions which pass through the TaskState*, because now they can have the same prototype regardless of whether they're CONFIG_USER_ONLY or not. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 48 ++++++++++++++++++++++++------------------- 1 file changed, 27 insertions(+), 21 deletions(-) -- 2.20.1 diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 05491bf5248..ce3ba554bef 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -36,6 +36,13 @@ #else #include "exec/gdbstub.h" #include "qemu/cutils.h" + +/* + * Dummy typedef so that we can have functions that take + * a TaskState* even if we're building for softmmu; in that + * case the argument will always be NULL. + */ +typedef void TaskState; #endif #define TARGET_SYS_OPEN 0x01 @@ -213,27 +220,24 @@ static GuestFD *get_guestfd(int guestfd) return gf; } -#ifdef CONFIG_USER_ONLY -static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) -{ - if (code == (uint32_t)-1) - ts->swi_errno = errno; - return code; -} -#else +#ifndef CONFIG_USER_ONLY static target_ulong syscall_err; -static inline uint32_t set_swi_errno(CPUARMState *env, uint32_t code) -{ - if (code == (uint32_t)-1) { - syscall_err = errno; - } - return code; -} - #include "exec/softmmu-semi.h" #endif +static inline uint32_t set_swi_errno(TaskState *ts, uint32_t code) +{ + if (code == (uint32_t)-1) { +#ifdef CONFIG_USER_ONLY + ts->swi_errno = errno; +#else + syscall_err = errno; +#endif + } + return code; +} + static target_ulong arm_semi_syscall_len; static void arm_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) @@ -374,13 +378,15 @@ target_ulong do_arm_semihosting(CPUARMState *env) int nr; uint32_t ret; uint32_t len; -#ifdef CONFIG_USER_ONLY - TaskState *ts = cs->opaque; -#else - CPUARMState *ts = env; -#endif + TaskState *ts; GuestFD *gf; +#ifdef CONFIG_USER_ONLY + ts = cs->opaque; +#else + ts = NULL; +#endif + if (is_a64(env)) { /* Note that the syscall number is in W0, not X0 */ nr = env->xregs[0] & 0xffffffffU; From patchwork Tue Sep 10 14:44:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173533 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5910770ilq; Tue, 10 Sep 2019 07:55:45 -0700 (PDT) X-Google-Smtp-Source: APXvYqxRAhzQjML8u3A3oFWwFhJE0KMBmbbagl3Qo8YCn10Q20SZa0FORZfaUN8snEfGIbxStuST X-Received: by 2002:aa7:c1c5:: with SMTP id d5mr30935899edp.46.1568127345724; Tue, 10 Sep 2019 07:55:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127345; cv=none; d=google.com; s=arc-20160816; b=vc9rtKqurzPTWaa8yX1VqiBDqklGcJtMwpQ3NrpXpCnlv507JDleJB00/OhdauCTUb A+xa+AwqFpubl7dDbmiPJelKfOo10mAYuwaZ+ArWG666sqXgueHs4bIZnEhCqVW3K5Rp oi9Mj9I4CA36KnTI1mioOiVxljPqKdZU+Qpi7aVaXve0bMjEkudXisZdlj1UFxtIKooN 3cgPwmTELnDCY95Sg/R8W9ZoF8grNhMKBa+3HN10LhzCCIj0o1XsbxGnRAO+R16iLAmj Jf+2NHNc0ILL1FkOgHhUGnIOA6xmjvBiiSbCNcOGwSQeIQkzsgRGv1YJEb8wFco8XHbP E4Gw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=icJGQqLN5JwiRgNwYZcYjVHrzF+oYAK3xQScSz/vA4fGWocKZERNXkR9kxq0uinivL rmRZ3AsZ0VNcM2q+fGy1Xaow43WJNMlKm4QC1hLeMm7cxXdh9UaIAXZubU/bDJcmNuQR 3apLiPGOfaxVLxzg2g+CwN/hHvx4YSaK0cCld4HNeH7tU/rp9oMGqbvyhXz8LjuCTznu nSKuJOoCGKOWOaf4SMUitCnZoaR/Z/4dawY+ppLxMB4vH+NR5u0cKnD/9TKovXzn6KQz rdhwNsfCHg5+wH659JCNqyQuXQ0itPih6fo5o2T3QX1IdXomeHh/akIvyau9HVn6vMrN fuiQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=pun+1zY5; 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 e48si11363571edd.239.2019.09.10.07.55.45 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:55:45 -0700 (PDT) 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=pun+1zY5; 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 ([::1]:40996 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hYW-0000Mo-2B for patch@linaro.org; Tue, 10 Sep 2019 10:55:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:53982) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNm-0005RB-Ve for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNl-00050Z-QG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:39185) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNl-000506-Jl for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:37 -0400 Received: by mail-wr1-x444.google.com with SMTP id t16so20832403wra.6 for ; Tue, 10 Sep 2019 07:44:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=pun+1zY5WhN2o0gSnE577xUfjuVDwQhUVEkMW8GsvWdeh82xhKthM9G80PRZ0dZJMB GP3hgPkZvtMQujx48UjpE+VuU1MaxhtDM0V7KqsxgDIe3S4hvscuuRMG82ZI/l2UUnM7 ibzTgjoZtriyYo89qDZ4faNq6B20UfYbFYUH2PdZIv4IHQpRAlMSorG0jxSsqhogCkgy 28gtcUnYN6Apll4DQ8kPb6TqVLwRTC85fMQ8JESNfN7yhJMB9gwDyG+hJ1UKlPRXYPrx qoMxWzBQB2dSAHvbSKTvpbDta9Xt9beJN2pHPI0vEb2cVavqGbQCoo+4Vh00N6Lct+vX cxsg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zlo9vQHXYMdSRYQxbnaGFzeWoJMkmJsq2rf4IJ1ziW4=; b=otDDvNiGuv2mXidwiNuqrsdt6GdXIp9BSbRvNmYXHtq/f6oQJ3ijfJenYCSnv49ln8 qyBJJh+KRA2GdiIbPIiBLKw/bZ8SoxUDJhfdcVMPeMbfhBXq0gkcL8V3jJJPJ/DAn4Xx cVoA1oGDKp7GFjVgqQYN+bqz+a/MHLcNOmjxeLpfdBA+a57vF/THAX8Adp0dLdRaPH1X 4gmVIbjtprQ3fOnElpsHNmmEpiHcdQGwDCIeb4GOVPxhnui073RK/5YeglVMhXfA6IP0 MdhPhGdHUrUo0upduGaKyaN3YwCe1ytCu+GvAbLwFuuj7rB56M576fDtqW3q5X1Dq40a lJ0A== X-Gm-Message-State: APjAAAUGEtn74mtrQXkvb3HFs2ryS7edFWcn0HJXoQuZm/oaDuWWWjuD NYT9CFWMV87dc6I7gEB57HQidanLITRdqw== X-Received: by 2002:a05:6000:142:: with SMTP id r2mr3251793wrx.212.1568126676765; Tue, 10 Sep 2019 07:44:36 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:36 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:20 +0100 Message-Id: <20190910144428.32597-6-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::444 Subject: [Qemu-devel] [PATCH 05/13] target/arm/arm-semi: Factor out implementation of SYS_CLOSE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Currently for the semihosting calls which take a file descriptor (SYS_CLOSE, SYS_WRITE, SYS_READ, SYS_ISTTY, SYS_SEEK, SYS_FLEN) we have effectively two implementations, one for real host files and one for when we indirect via the gdbstub. We want to add a third one to deal with the magic :semihosting-features file. Instead of having a three-way if statement in each of these cases, factor out the implementation of the calls to separate functions which we dispatch to via function pointers selected via the GuestFDType for the guest fd. In this commit, we set up the framework for the dispatch, and convert the SYS_CLOSE call to use it. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 42 +++++++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index ce3ba554bef..f3e0bf77cd3 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -116,6 +116,7 @@ static int open_modeflags[12] = { typedef enum GuestFDType { GuestFDUnused = 0, GuestFDHost = 1, + GuestFDGDB = 2, } GuestFDType; /* @@ -179,14 +180,14 @@ static GuestFD *do_get_guestfd(int guestfd) /* * Associate the specified guest fd (which must have been * allocated via alloc_fd() and not previously used) with - * the specified host fd. + * the specified host/gdb fd. */ static void associate_guestfd(int guestfd, int hostfd) { GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDHost; + gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; gf->hostfd = hostfd; } @@ -337,6 +338,37 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, return is_a64(env) ? env->xregs[0] : env->regs[0]; } +/* + * Types for functions implementing various semihosting calls + * for specific types of guest file descriptor. These must all + * do the work and return the required return value for the guest, + * setting the guest errno if appropriate. + */ +typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); + +static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return set_swi_errno(ts, close(gf->hostfd)); +} + +static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); +} + +typedef struct GuestFDFunctions { + sys_closefn *closefn; +} GuestFDFunctions; + +static const GuestFDFunctions guestfd_fns[] = { + [GuestFDHost] = { + .closefn = host_closefn, + }, + [GuestFDGDB] = { + .closefn = gdb_closefn, + }, +}; + /* Read the input value from the argument block; fail the semihosting * call if the memory read fails. */ @@ -452,11 +484,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - ret = arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); - } else { - ret = set_swi_errno(ts, close(gf->hostfd)); - } + ret = guestfd_fns[gf->type].closefn(ts, cpu, gf); dealloc_guestfd(arg0); return ret; case TARGET_SYS_WRITEC: From patchwork Tue Sep 10 14:44:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173526 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5900620ilq; Tue, 10 Sep 2019 07:47:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqybF9bFrRlwGKvQ0Ni5WhG165ADJBUJTKPIn86J7I1z1YjvLGqy9d+zHKo+5fkav3dqZt7L X-Received: by 2002:a05:6214:582:: with SMTP id bx2mr18043916qvb.60.1568126820804; Tue, 10 Sep 2019 07:47:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568126820; cv=none; d=google.com; s=arc-20160816; b=pWrbKytxsYILyJJfw8DpzvLXqE+uBNbcPJK5hIGqtIcxuLyHwxpMmQvPuVSMynCx0t raT8zFsZubQ2br7DjiUbGruh0UiEX4Loav2BRJHzxiFDePnpelXQ52pOHxwwaG39QNvg yw48/+BUkN8cYqT/3ufO1ezjf69nrNQ19yudEDN1D7hCHm7xKcO4W9fKrvQJDI/VKbCP 5jPiaMy9nA4sBkP0jwNGAAFpqi/IZeST4CQnsrUk5Xf990fdnqsYB0CrzOoQNEd0li9g PSOz1mENYKJXzCijzVhvUaPJ49QJrTEsIAmiFcDZKuO70w8h9e8NufkLK7DUmDTu50Tx CeyA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=p96t5rYUK0t1dw75KiSPERZf4W8kl0rLPFLpIILOVfw4g8/yHdwsNK3BHDRlbIr8JQ IDjozhPSXv3oWpiOJ9T7AKr+dIacfDgsLpvbrf1oVJzY3XQWMJv7e5OssQEl6FNZtf0t 2jECuJ8nBUzwjjQ518su19QZOQmxSGSt6HltDYEC7kQZPSKBYvf/RFLOYxFKk5qnn/c5 V6m2lLAd+spe1ET/ucpJuesm0BG3ZHt2c+xEE6Nx9+eBs28LgmZZ6FXATYhy8oZH48J5 bvuHHPzleq6JwlzIaoGQI3aj2fa/twf1uSfpq3D0o73SqPixJ48LlPz3O+z0MAbp5Zvt w1KQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CPOae9hg; 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 a2si820809qkl.75.2019.09.10.07.47.00 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:47:00 -0700 (PDT) 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=CPOae9hg; 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 ([::1]:40800 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hQ3-00060j-D8 for patch@linaro.org; Tue, 10 Sep 2019 10:46:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54009) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNo-0005Sx-8E for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNm-00051D-Rc for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:39 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:40572) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNm-00050t-Lt for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:38 -0400 Received: by mail-wr1-x444.google.com with SMTP id w13so20818660wru.7 for ; Tue, 10 Sep 2019 07:44:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=CPOae9hgzuSC0OuDGe9BwP3BNIZQOP1fwo3SjCfxBWaL621js/y1AppTZuhJF3YbXx TEQZHopJll6otD2jmKBXQ6+eldWQm2EOTurJXMwBt9IPolSIWRkthFi6Q6m25paKoNfI M+yvPrZXHR8w5y69dXowBN/1N22jRoAM61LgnZClKts3ccSs+x+hpFUJM+7wUiHUzWtN tG56sqp6K7DNFTHkrgKnQhZV/Z848IvOOQZe6ENchdYbKhzLdNeGGQP9NHQacBaeIddc V0XIDgJa7uBgT+7HH1etQGK45TbEws3VGphBaZ63UTv1Wm21qXQ0rcWZFw2nZJsTp1ub M39A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YWOXDYdgItfE8+407vkIvvnaRwn01B+C3RlPpmYpG/U=; b=uOtIsAqxKp/97xw4fttffkhPwZq5lH7EfVgkS5f/vWigjFnqehgqQoI1CmJtzbuQjl bs+3vj3VFvtyCE4+IFAQAU6szpAXCjDg2ui2oz3LmpTlQQTYz6aIvopCiqUlzYaBNYIH qwbj4VuuzYkpIgg6TuZiOczENut7nfZld6MJmaNQ1MZoT4JjMCvguEq4pbl3ElNHSFjQ 7K7c7ZOJCERnlBZJZfFJ7lO5PGQHmN19VaL3v9pEN+6JS/KLlrmxNbU5KDquNIfjjXg7 UiI5BEbLDL6dJLq1rqchtbSoG2MTbuA2j0TzPtIbNoIFEPK5002wSk+Mo6ezSdH1fhtD /JYw== X-Gm-Message-State: APjAAAVVwkO1aQCSyxlvqG5fA9pp6ze9W81cNTgYOpjQ+/+4K4oU8Tb3 mQhPGYSsnse8tX54VUusQpKnUg== X-Received: by 2002:a5d:548d:: with SMTP id h13mr9677544wrv.215.1568126677826; Tue, 10 Sep 2019 07:44:37 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:37 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:21 +0100 Message-Id: <20190910144428.32597-7-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::444 Subject: [Qemu-devel] [PATCH 06/13] target/arm/arm-semi: Factor out implementation of SYS_WRITE X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Factor out the implementation of SYS_WRITE via the new function tables. The #ifdef around the declaration/initialization of the local 'env' variable is unfortunate but necessary, because the softmmu-semi.h version of lock_user implicitly uses 'env', but the user-only version doesn't need it. Without the ifdefs we'd get a warning about the unused variable for the user-only compilation. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 53 ++++++++++++++++++++++++++++--------------- 1 file changed, 35 insertions(+), 18 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index f3e0bf77cd3..0dec4c04e2f 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -345,27 +345,61 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, * setting the guest errno if appropriate. */ typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len); static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return set_swi_errno(ts, close(gf->hostfd)); } +static uint32_t host_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t ret; +#ifndef CONFIG_USER_ONLY + CPUARMState *env = &cpu->env; +#endif + char *s = lock_user(VERIFY_READ, buf, len, 1); + if (!s) { + /* Return bytes not written on error */ + return len; + } + ret = set_swi_errno(ts, write(gf->hostfd, s, len)); + unlock_user(s, buf, 0); + if (ret == (uint32_t)-1) { + ret = 0; + } + /* Return bytes not written */ + return len - ret; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); } +static uint32_t gdb_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + arm_semi_syscall_len = len; + return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", + gf->hostfd, buf, len); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; + sys_writefn *writefn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .closefn = host_closefn, + .writefn = host_writefn, }, [GuestFDGDB] = { .closefn = gdb_closefn, + .writefn = gdb_writefn, }, }; @@ -504,24 +538,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - arm_semi_syscall_len = len; - return arm_gdb_syscall(cpu, arm_semi_cb, "write,%x,%x,%x", - gf->hostfd, arg1, len); - } else { - s = lock_user(VERIFY_READ, arg1, len, 1); - if (!s) { - /* Return bytes not written on error */ - return len; - } - ret = set_swi_errno(ts, write(gf->hostfd, s, len)); - unlock_user(s, arg1, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not written */ - return len - ret; - } + return guestfd_fns[gf->type].writefn(ts, cpu, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); From patchwork Tue Sep 10 14:44:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173535 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5914870ilq; Tue, 10 Sep 2019 07:59:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxBGACqX9rk86WXuFLXp9EjvnKhsFIGtyvSSWSIfNFccIzwaXiWW4TXlxw0AEzG5AuCp3c9 X-Received: by 2002:ac8:1767:: with SMTP id u36mr29660026qtk.152.1568127569547; Tue, 10 Sep 2019 07:59:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127569; cv=none; d=google.com; s=arc-20160816; b=ATV5XWxx7ger0Fn0TgE7U5GzQM2kWXjUJF5A/8xcbu0KsANrOMpJKOMEInR989jWTJ tCASOOkmb4fiC4dYJpwQgLoX5tTR26Ec1Ghf4eRGBTkjirwxPZwVVbJA/noLawziXeQ/ EpN1EHgH+94Ex0V98h5t8Qy0i1DiC3Xcef9tGFA76pf5mdggOLT1duLI5cKxBj5aT8Dr 1q+M2p0lBCn4p2JFaq6GIDwHuQxJtV6YqhDxixpJeBVQUmHf2/B1KbITMizupViqeE1J FBWWoepMisH8Ek1/y86Q2RGcJU6JQCMuT6bB6lpc4+QszENvH3D+IJkSxIgkb57duSHa 5EHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=yhl+uIFd+h155mJnpekNI9cXttutgMD3Ud1iuCaT28JwLf497TSG70YIeECH8gRqYF zC4KuSlUpWBQ9aCSvJCIHkczTcriku0wM1hSm6N6rZqToq8L04rs7FXC76L/OWARrxAP mlLr4gm7IZr16IHi805YglVRiD7PbdqKx/aFz1ahB8hfmn68wB/zYQpZ2iPqsgYu8VKU vyFWJpH6syJz1YScX1EPzHVXVAbkYzwULeWMvIusdSkqQE/aA97jbd88bQDbxxtwsMMG lgtqZdSNtALmgYq9hdSqfo9Zqp3W2ZEV52hmsVY0+qZf6jOIBhSHhBlM17mW6XA2dzpV noFw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=S1W9+GjI; 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 i26si12993962qti.299.2019.09.10.07.59.29 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:59:29 -0700 (PDT) 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=S1W9+GjI; 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 ([::1]:41062 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hc8-00045g-Ho for patch@linaro.org; Tue, 10 Sep 2019 10:59:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54034) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005UH-1a for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNn-00051t-QD for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: from mail-wr1-x442.google.com ([2a00:1450:4864:20::442]:36223) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNn-00051U-Ki for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:39 -0400 Received: by mail-wr1-x442.google.com with SMTP id y19so20839190wrd.3 for ; Tue, 10 Sep 2019 07:44:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=S1W9+GjIQ6Q1+v2erJ8a8p45+tj3PFe1rle3T4TYKuUvrNPQ7Kw88ydslBiCo08oJS AnFATCxYou1iuoeTX7wauXIkGk5wQ1hT0f7vKK0Ft8VVHUjTi9YSMz4yyspTLPhT1kv2 BmVqnCkOpefUdL5WOHjgRVj04HX5GjBuNJPCq23TvsNGBE0+p71t7L37o411Ad0GimlX OFN+SOpA24d92oo5LwlJdKVX0OtQlrbfZb502feAxRpcKkCnJ9ayL8YEslcX+mN1kt2M Lqz21sYS3zCpmNkXLLVB151z2FPn7UZAyTX8O2TgQWgAT0L0/JpYi4hCGakerpNXA/3+ iKrA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7yOOhdKlBIYO8WFMmpn39kOmkjcRHpZcI7p0s8duWdE=; b=CvqypKaItjDyBNFbb7iQfuM05QBGKFdN0LhYQK/RxC90L/T6J6wncaaFGYVmNLqkHp JsAoTA/LLILUJV4+kHzwgz+RXQQDSWN454ji0Zzpx8gULkADQuXpY8ykl4tzU7Jp3ue8 ULFIhDyJw+66UcIkvc7esFyf4I1WEFXg0kSRYTAVkPegs0GDyC6ZXaJkTSN+W5lMilgC UHYa0aTce+rUgkPDqpV23hAPOgtGuH6xkPF61hQ3gdfUOtbLhkQGuEToqkb1eBXC0TAK 8SzR/1A+FgZH1VIiqCNfBkzQS/sMGpAaKA42oivPvdBg5oI5IGD1jAy1VfBLjUgI6IK2 z14w== X-Gm-Message-State: APjAAAWei3qBVeTblUSsfQtffxOaK43VjwEGJRBf6Hfky7xFdGVcJjeD WrffOrPrQKjEKv/prRzLBa6IVCM0L2TvdA== X-Received: by 2002:a5d:49c7:: with SMTP id t7mr276133wrs.229.1568126678753; Tue, 10 Sep 2019 07:44:38 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:38 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:22 +0100 Message-Id: <20190910144428.32597-8-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::442 Subject: [Qemu-devel] [PATCH 07/13] target/arm/arm-semi: Factor out implementation of SYS_READ X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Factor out the implementation of SYS_READ via the new function tables. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 57 ++++++++++++++++++++++++++++--------------- 1 file changed, 37 insertions(+), 20 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 0dec4c04e2f..48a10dd3c3a 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -347,6 +347,8 @@ static target_ulong arm_gdb_syscall(ARMCPU *cpu, gdb_syscall_complete_cb cb, typedef uint32_t sys_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); +typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len); static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -374,6 +376,29 @@ static uint32_t host_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, return len - ret; } +static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t ret; +#ifndef CONFIG_USER_ONLY + CPUARMState *env = &cpu->env; +#endif + char *s = lock_user(VERIFY_WRITE, buf, len, 0); + if (!s) { + /* return bytes not read */ + return len; + } + do { + ret = set_swi_errno(ts, read(gf->hostfd, s, len)); + } while (ret == -1 && errno == EINTR); + unlock_user(s, buf, len); + if (ret == (uint32_t)-1) { + ret = 0; + } + /* Return bytes not read */ + return len - ret; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -387,19 +412,30 @@ static uint32_t gdb_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, gf->hostfd, buf, len); } +static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + arm_semi_syscall_len = len; + return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", + gf->hostfd, buf, len); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; + sys_readfn *readfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .closefn = host_closefn, .writefn = host_writefn, + .readfn = host_readfn, }, [GuestFDGDB] = { .closefn = gdb_closefn, .writefn = gdb_writefn, + .readfn = gdb_readfn, }, }; @@ -551,26 +587,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - arm_semi_syscall_len = len; - return arm_gdb_syscall(cpu, arm_semi_cb, "read,%x,%x,%x", - gf->hostfd, arg1, len); - } else { - s = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!s) { - /* return bytes not read */ - return len; - } - do { - ret = set_swi_errno(ts, read(gf->hostfd, s, len)); - } while (ret == -1 && errno == EINTR); - unlock_user(s, arg1, len); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not read */ - return len - ret; - } + return guestfd_fns[gf->type].readfn(ts, cpu, gf, arg1, len); case TARGET_SYS_READC: qemu_log_mask(LOG_UNIMP, "%s: SYS_READC not implemented", __func__); return 0; From patchwork Tue Sep 10 14:44:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173536 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5923807ilq; Tue, 10 Sep 2019 08:05:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxFWAavCslG9aAuVQ8sTm3E7PQ7B5h0lrn0baJMO9fyLPNiC9ncGt8MDtHEo+pCW4ZI3BXL X-Received: by 2002:ac8:36b0:: with SMTP id a45mr29760954qtc.105.1568127929443; Tue, 10 Sep 2019 08:05:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127929; cv=none; d=google.com; s=arc-20160816; b=Be31ajTis4TSfL6ZmfQxSvwTInYZaR0CCSmOmDEXsjaawUM+mSTwnkkjW/j0/vNMPZ 3w10x5sMd99JgjUULpHviBzKFAFtFGpIExgeh6iG3AWlRquieqwPc3GWMNU3kWyvD69q ECg/vGMOfR7CxOWnOXKn9lcRW0a9lPHWT5CjX/G2squ6EJ5lWZGHml9DFQrFojniUNLt kcRBT5fMiLDPsnbBGzsxmg0NRD26Jq8NmBiTVfri8Xrq1mRpbCvdOk3067kAMqBGMDXx VFlrbsDkf+29ckRzQfKDEal885Dz+tdVbskLZqvdu8kKOg4M4ZkqM6kuu0nwgxGx9Vx6 6ECQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=puVRpqP1TNjFwoEX/1VMsdun2zPJXDkfbuj8bU3o8qTNzkpyubopCsn8cWg+SksBTq sg1abwtU+hGfzbVVm/VrM7lXtkhwVx7JLnBsW3/RiAqm8sMlh7yIKZ+F7bW21pzZ7byo FXlkOYAdJdgSiNM9bg5VIYow+0ga4AC2tBndeZ9GHp5YPNO6H1OvE2qDeXFwXsEia68v BOS5n5kLve8Ip3Jv9PO4PbE7t7LuolCbrET/goYRONIDouFHUuCr64dJOkr1NGX7o2l8 HSXdqeLjw1Pyp6dYdTwFcvkfb5yrU+f90sdLqkd2+3wyCdD+LYYwAPvUryi10dkGNV+s ZdHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=CMo+23GR; 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 o17si13991578qko.7.2019.09.10.08.05.28 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 08:05:29 -0700 (PDT) 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=CMo+23GR; 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 ([::1]:41116 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hhv-0008VN-SY for patch@linaro.org; Tue, 10 Sep 2019 11:05:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54052) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNp-0005VF-Pe for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNo-00052a-MJ for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:41 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:43945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNo-000520-EV for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:40 -0400 Received: by mail-wr1-x443.google.com with SMTP id q17so16120282wrx.10 for ; Tue, 10 Sep 2019 07:44:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=CMo+23GR2ChsncBNW3AD8r9qGAl4f70kTqLT5aG9Jjdja+WFEdwIgiGRU3vUBkHmHK 6g7IHhCCIViRQ7itY+uX+uRkmdTbS6jFCe2GDsFiA+7VDFOPFiQxYrl3BdRIIszrHHQI 8xqKeC4nzfmjr0TuAA0vuez+W9rFcMyhKQLuda3bYuEg3kZ+5c5H0L88rNXiV72liMKa fx4/GDxi3zM6HrfmGQuymVW60BsHXb/JZcHUkYlhonw3vnfSqs/qmJJkUk4FDln6Bghu P/oCKXVqQvg1E+IBmwlHkY5bMUnoQJ4gMXT4SRE28PB1FLi+l7PL7ihgxIe/QOPEkN4F p4tg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LQ3XAKoDLhaOzqFCNhsIdDGJrHIQSVj/rNDcC6T2wTA=; b=B2w7VyLQ16nPCj8Dedmjnwmsa7IczSkKa5GJNaU1Y5XgDy1TdzBJAWm6Z5CU206ogW dJKVdGQBtWKrouCA4krjuJKAtQGCHKiyxMmgdc6bV6i42mZ/trCx6v7jLDhfmn2yQxPS ak8yq/D10VGiVQCOr7A97qD8HsohYmbTfuQYo+dVoHoAWB27bdMumwVxGqRsG/U9PIts oQ8ntCfJs5y4YnKfjYKrfh2GDfDI9Gh11dnCdqbLR4y1QbeTdmq8ip6EsNUrbaKU8X+D af1UukRg87ysF4ZdFxc79zDF3/Ht58Hczi9Hjiv4fOljp5G4Ym0aw7jfe8tZM3vM0bEa DdzA== X-Gm-Message-State: APjAAAVcc6FG1CpeKgLPS1uS/YDZW6PL7w+9MFa3+vZULFO0mJtfT6HX k4/NwhhLurPI89KG3/JK2mtUyk0Pe1rhFg== X-Received: by 2002:a5d:45c3:: with SMTP id b3mr27791244wrs.207.1568126679618; Tue, 10 Sep 2019 07:44:39 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:39 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:23 +0100 Message-Id: <20190910144428.32597-9-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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 08/13] target/arm/arm-semi: Factor out implementation of SYS_ISTTY X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Factor out the implementation of SYS_ISTTY via the new function tables. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 48a10dd3c3a..64ed39fc075 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -349,6 +349,7 @@ typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); +typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -399,6 +400,11 @@ static uint32_t host_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, return len - ret; } +static uint32_t host_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return isatty(gf->hostfd); +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -420,10 +426,16 @@ static uint32_t gdb_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, gf->hostfd, buf, len); } +static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; + sys_isattyfn *isattyfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { @@ -431,11 +443,13 @@ static const GuestFDFunctions guestfd_fns[] = { .closefn = host_closefn, .writefn = host_writefn, .readfn = host_readfn, + .isattyfn = host_isattyfn, }, [GuestFDGDB] = { .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, + .isattyfn = gdb_isattyfn, }, }; @@ -600,11 +614,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); - } else { - return isatty(gf->hostfd); - } + return guestfd_fns[gf->type].isattyfn(ts, cpu, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); From patchwork Tue Sep 10 14:44:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173527 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5901861ilq; Tue, 10 Sep 2019 07:48:00 -0700 (PDT) X-Google-Smtp-Source: APXvYqy/9NpjUnTT652WJ6minihyF8a6QOCbVv5DDCInIHAXh0Lo0s/LW+0N9Y+VbRvsSlA9qFfN X-Received: by 2002:aa7:da8b:: with SMTP id q11mr30962450eds.19.1568126880086; Tue, 10 Sep 2019 07:48:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568126880; cv=none; d=google.com; s=arc-20160816; b=ItO047a8HEYWyAk3bK5WjmRPuCuqqRgzmr508PSe01MrfQh7N/8RNFyz6UH5K2JeP+ oUejkbPBBeLvc4vniuzGK5+uU9zVzoSSDgyVioZ8uM1x299MO/kToELmnkxkPJOQ4HOX ++OBKM0WLUv5rUFM4fsPkPq5IeNnujshvAKBdEaEQcOXaQno5MxRzjX4uQ8RvUKQR3b4 knI9G9zJp0iIbNr7NPqM0zuWVYsmkUejfVzhzZayQqkjBAYL7cqSL1ZxuU58mmGZ7GAU O62SguuB3CjvMaw7aU8cwnBMW5vbkzLgdYVAvWFuqs2ENy5pavBIAOafT6fW+mYJsDny jRHA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=fL3gmmJBBswuNDB/4ZEFRf0iAu43TOZoaC6Y5Amz25oxXflIdgWaToH45837KWmvSd Ox4v0horUdvUP5946czKio0HRWtl3rZDoMMno8cZfoRjvcO8ycxJr5ozGWdokDDkspv6 fVIHDS6HLyYp1NrqV1YEuBCskDxPMi9VFwiZIdgByQMYRmeK6gTWwq8RZHc+3u5omruY fy+yTmuBAHwOKRB+3JEFdKquWX28yYJrsbIP1grUG2Exn8y96Kt7/DjFAiaeuhZ84rJU 6SviHWcSelDQ9jFjFeAzwJMrcJCjO7jOSpaOaTe9K6B+HUfl9busOnlArUziIG0sFbEJ 7NlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=TP4FGPJn; 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 s20si9121186ejq.340.2019.09.10.07.47.59 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:48:00 -0700 (PDT) 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=TP4FGPJn; 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 ([::1]:40828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hR0-00085Y-Qm for patch@linaro.org; Tue, 10 Sep 2019 10:47:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54094) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNr-0005Xi-E4 for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNq-00053l-5I for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:38285) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNp-000533-VG for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:42 -0400 Received: by mail-wr1-x444.google.com with SMTP id l11so20811355wrx.5 for ; Tue, 10 Sep 2019 07:44:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=TP4FGPJnqWDNNaqsdxqiebobluuX7Dowm18Kz3kHyWoTByhD2xEyf5VfrTm/rDvUA8 FupOUbrQw0+PfwZNxK1C5jmqfo4RuUmi1Bl2Rq0vyb+Tg+wnEI/uhOfe9AbEDfF+pkQ+ VdUvNni/d3lHt/jkQYhNUFMbpYl6+LFoZQqROoYTMn0otdcxzIOdErz4i8mTxrjGhpva 3hbEbqy/JtSmIELAJAaMZ/cYuCu19CNmj34mt/4FsLvp+yLlqKz4uAj1XhG+eHiUEdRQ oumvSysknBVXtsNDO9c/QtZbRKbVRmUJv7SEgAai3fyPy0A9E7IZeC3eM48sRZA8FSK0 Gdxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0rlPylnHuLKixhickeuo5/KvckwQXrJ/eGak0x254JU=; b=iQcEazgp3/tPSab6XnjxQBo/37ppYIasxIfnkVZ/xVP5KEruAJg/5lHupWKUjVTms8 dN2wxhIeBiHdHpXc94An1XJydzdmOj4jEWjkJEbQZs673Sdkjkza4mia4NrxwjEWRw5c 2tiy5o+MU5tfteGywwIQMUxBcPOZbkXN0Fx08iovZqIodDgJnP1DZa1NpUcxI4LBV+/g DlMLJE/KHNop046h0L91/bTndvh91Xu1hose7/skeFI6wlRd7dqqpjg4Hge48cdbSfRZ zC2T+0S3nXEXzaDbqkxT5GCM/vc8qfpZnSqQCVxCKdWs76IN1NCy6Rz2buZUC3ttJrLK La+g== X-Gm-Message-State: APjAAAWIRFdGlMP1AGeEXEQA2Qm6ZHO+yLnie9tO3jXuJhiQMDTpxRLx p4AOgzDChGHE0RcPlUA4Ke1yu0fgV05oXQ== X-Received: by 2002:adf:ef44:: with SMTP id c4mr28033411wrp.216.1568126681065; Tue, 10 Sep 2019 07:44:41 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:40 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:24 +0100 Message-Id: <20190910144428.32597-10-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::444 Subject: [Qemu-devel] [PATCH 09/13] target/arm/arm-semi: Factor out implementation of SYS_SEEK X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Factor out the implementation of SYS_SEEK via the new function tables. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 32 +++++++++++++++++++++++--------- 1 file changed, 23 insertions(+), 9 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 64ed39fc075..c548ce849e7 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -350,6 +350,8 @@ typedef uint32_t sys_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset); static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -405,6 +407,16 @@ static uint32_t host_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) return isatty(gf->hostfd); } +static uint32_t host_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + uint32_t ret = set_swi_errno(ts, lseek(gf->hostfd, offset, SEEK_SET)); + if (ret == (uint32_t)-1) { + return -1; + } + return 0; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -431,11 +443,19 @@ static uint32_t gdb_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); } +static uint32_t gdb_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", + gf->hostfd, offset); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; + sys_seekfn *seekfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { @@ -444,12 +464,14 @@ static const GuestFDFunctions guestfd_fns[] = { .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, + .seekfn = host_seekfn, }, [GuestFDGDB] = { .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, + .seekfn = gdb_seekfn, }, }; @@ -625,15 +647,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - gf->hostfd, arg1); - } else { - ret = set_swi_errno(ts, lseek(gf->hostfd, arg1, SEEK_SET)); - if (ret == (uint32_t)-1) - return -1; - return 0; - } + return guestfd_fns[gf->type].seekfn(ts, cpu, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); From patchwork Tue Sep 10 14:44:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173532 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5909254ilq; Tue, 10 Sep 2019 07:54:20 -0700 (PDT) X-Google-Smtp-Source: APXvYqwoXPrdx4JGmKS//x7CR7Pb2iiAQOyvt7BVmQHoDU0tcqz+mePkP7oaAXFV2BleCRtfVdaj X-Received: by 2002:a17:906:2619:: with SMTP id h25mr25202872ejc.283.1568127260557; Tue, 10 Sep 2019 07:54:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127260; cv=none; d=google.com; s=arc-20160816; b=RpO5bF639cUVnwQD+AfMAmDSEgLW/sSD+64/cF+u40q07AaZ2WVS3SVHpiQTI94BgN KLlJnIt+Z4jVpwClJ+bJISge5+fjQfTIQLthFAHRyCG9iTmnud9oFP/0tB2ym9LZVnbA rLrw4uCx8kgm9TE8xbLd1W7tk/XopDlZMADTgbbm6G4W2ZbwhEsKRlO3aWwLcBqhPGFp s+2pcLTzzkkOvrcv8Ll7mOs3Odn8VdDADOJpGSwx2k9hsbHuqezwx7Pw8iHHBbQIAyJA cWeUSlrHpQ5BMnHn3oEIGp7G0kPzpuIB/L7Zt+dF7ZXwbZI1107XrCuP/tAuhKNQO+yH 2XZA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=vx/ZWZroENnFD+reiV+6uSGFq4G7seeNDsGMQLXHT7B3y/7r2rCys/Y2euKVqN4jtB b263Q7XgyUU202dk3Mrpets47V6m7HxxjyUAOJ++EAeRfBtGOsx1PatRkzly0pyA5His kJ0+D+cR6DOcn+acsSoo4pcOtgF/eQqolHpZdyXTZGSvlA3TbOcufRL0xmfB8x3dYj0V 3m+8gwNxG4LRO1GPX+pTQV4SCD6lYY5r2jcYlhdYSzgCyr3jRO/fety7oEaD98Oipeuc GgKWDs/LwY+mU53I5dRUTODeuQqfpEVUt8+4ZwJufRsLzP9c+3VzaQiVob/bbRjzrgRx 4ClQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=vJRR4zhM; 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 qp3si9286432ejb.339.2019.09.10.07.54.20 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:54:20 -0700 (PDT) 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=vJRR4zhM; 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 ([::1]:40972 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hX8-0006t0-Mv for patch@linaro.org; Tue, 10 Sep 2019 10:54:18 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54125) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNs-0005Zb-NJ for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNr-00054d-Gn for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:43945) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNr-000544-9I for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:43 -0400 Received: by mail-wr1-x441.google.com with SMTP id q17so16120609wrx.10 for ; Tue, 10 Sep 2019 07:44:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=vJRR4zhMarIJwOEag+GQp1yXeXT+q/UXt9Xtub70Zzd0iBgHFR+zDca6QkL3KyQrFF d6jtVtMtoVx0jQhhcNC7jmNK1/5GDty5Rk1Lbt04v/3Qg9d7SNU0govHcBdLEL1mawnW /jEdgOl/Fjh/WQ2YyxW8Wvuaus0ak96VghwQvvTVFYD0UUNfdvhFogYqvnXL9ydFz3Dw MHnuvpPut6aHKKU7jvwQEn7vihCg15FIrLr4OVkNUkQcAjgy9uMDn877ZPCHsiyOJ9FA 0U8/NfbaYmKxarb753GB18++ClK8tHper8pHlhsqg8dPa7hCksO/HE/LdgodaFfjNWjB 8Bqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sq8nSzuTSE3z6TeW22Jb/p8ysGSeKIUIld6DHEj34Ck=; b=n229NGgWoTvg7aw28L9CcEycfG/Gk74IoEsHvTfIKnkQeit0TjCYO6uYPKgNsy2tZN ji/dFjJWCknxbeVgyewhOFrtjjOozlDbJ80gbFsCFpoA+yCzzPv0GWPfzRg62XHDFXB/ qEh3LFJq4Ke3oQvoviY3Hjf8Yesk+20su5cUVbB1coMa80HBi3b4YhyIbsL+kqZeHgxW RGOUAAhye/i7fL15EZf8vFRehsT8siDVwfCcEx2yGvw5EIX47My3nyhBUZcUyCQbzDmT hDOFrLl5TOIaEAqBGSqaedUmO7dvnmxH6mbHdhzUSee96fFLaUHjDKKGszL5gakxP2zc oqAw== X-Gm-Message-State: APjAAAVJ/3Jg1abbjJtJvFf+jKLSnQcz1IltV5p0kTN3iATn2Bo8IMud 5437dHau03iGuLQUxppRBhdnRA== X-Received: by 2002:adf:f812:: with SMTP id s18mr28610093wrp.32.1568126682426; Tue, 10 Sep 2019 07:44:42 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:41 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:25 +0100 Message-Id: <20190910144428.32597-11-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::441 Subject: [Qemu-devel] [PATCH 10/13] target/arm/arm-semi: Factor out implementation of SYS_FLEN X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Factor out the implementation of SYS_FLEN via the new function tables. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index c548ce849e7..f9019b00b8d 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -352,6 +352,7 @@ typedef uint32_t sys_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, typedef uint32_t sys_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); typedef uint32_t sys_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, target_ulong offset); +typedef uint32_t sys_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf); static uint32_t host_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { @@ -417,6 +418,16 @@ static uint32_t host_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, return 0; } +static uint32_t host_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + struct stat buf; + uint32_t ret = set_swi_errno(ts, fstat(gf->hostfd, &buf)); + if (ret == (uint32_t)-1) { + return -1; + } + return buf.st_size; +} + static uint32_t gdb_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -450,12 +461,19 @@ static uint32_t gdb_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, gf->hostfd, offset); } +static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, arm_flen_buf(cpu)); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; + sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { @@ -465,6 +483,7 @@ static const GuestFDFunctions guestfd_fns[] = { .readfn = host_readfn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, + .flenfn = host_flenfn, }, [GuestFDGDB] = { .closefn = gdb_closefn, @@ -472,6 +491,7 @@ static const GuestFDFunctions guestfd_fns[] = { .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, + .flenfn = gdb_flenfn, }, }; @@ -657,16 +677,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(ts, -1); } - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, arm_flen_buf(cpu)); - } else { - struct stat buf; - ret = set_swi_errno(ts, fstat(gf->hostfd, &buf)); - if (ret == (uint32_t)-1) - return -1; - return buf.st_size; - } + return guestfd_fns[gf->type].flenfn(ts, cpu, gf); case TARGET_SYS_TMPNAM: qemu_log_mask(LOG_UNIMP, "%s: SYS_TMPNAM not implemented", __func__); return -1; From patchwork Tue Sep 10 14:44:26 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173537 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5925906ilq; Tue, 10 Sep 2019 08:06:54 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvCPMqkxP1QgAc+Sji00mMdNB9L0y/CrV63tKlzzBPk1IdL+VfN9qCkZ5Hzp0L0qlqNdG6 X-Received: by 2002:a17:906:6dd4:: with SMTP id j20mr25358183ejt.173.1568128014622; Tue, 10 Sep 2019 08:06:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568128014; cv=none; d=google.com; s=arc-20160816; b=wMRl59IXCag20tQavUcjd7qOGAI0OZU94qyq3TUpnwL2wMnCLP5IsKYS1UC4meKcAZ AxU2ju+p5daAvDZYxAQn+1Z9HZusrxlL2fIzrqO0G7wh6fkjWf62gBBjaiDl19eMHPzd z6icFtfvnny7cjIEnl45LWN0HSVvbx45UXk+GiQwRXEawArY2lgcgf23lycvCFBOOe2t 96uyrFb7VpxgvIObIqLwhk1iF5WoyEkMTLJaHC/JWIDszVWFQY6NlfH3WVv2ZMp3ReCl EydE5fHnx/xZOdEyvAYJLCoqnvtfDv+SNcyGaynOLdzcRFPlYK69TXRTW2eweDE6CXfk 7YTQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=dv6dEJU0B2xiJlyBZr3gXADuw4AYMsiH+ZbPJXK8ETFrfcWZjmHr4KY62G7N3I+yIj NSdi6k5AmsQ7aeZuOgGOn5Clv4RftiHxYgYzhGfL0MZ0p1jano0Vn9yKNB6P6LT3Wj1q CQsvvJXQ7O4fS1meV1fON4RHJVAxcAOWWI4xhECGOQGGsS9Q4eWYfGuqGJYjrMJ/FixD 10uPFqBuNWxWUVl8YtWlQazLVbZXc4YMvpt67RnzMGH5xUF6faMlhhMypksWkZzDo4Ae FCcvFFauwdDizkyr1EErfhoBtx/aovzW5SjJs8mY8pCsdtHqVuLwzWoLyja7KBhA/xap x3Sg== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=z0OXDxHK; 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 z15si9717493ejb.308.2019.09.10.08.06.54 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 08:06:54 -0700 (PDT) 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=z0OXDxHK; 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 ([::1]:41152 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hjJ-00038Z-1O for patch@linaro.org; Tue, 10 Sep 2019 11:06:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54160) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNu-0005bU-7l for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNs-00055f-ME for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:43947) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNs-000558-FA for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:44 -0400 Received: by mail-wr1-x443.google.com with SMTP id q17so16120736wrx.10 for ; Tue, 10 Sep 2019 07:44:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=z0OXDxHK0OAM37pLD3qWAdkOd2MXOAjoEsXOa6/rmAaP3RxEgFPj+MkEEe2R5xmLyT N6Dmh4rlbm6D6Vet9Hp894dXJC+t8qEmC71ryNd0RW+HVcQDe5iCzPxr5Rqn49TAm3BQ AnCXv1eZ/FxwkMeZZ3G9yrEB+uCz53JO9cRicduZQO+8o3IkG/xVTlzDVLZ73oYpZ/2C yyIn7kMqwf0R0pQ+jLcrTC9Xvh8cokBxF0bN/XtySXYZs1gcf+J/ah3cg1+P6ypD+r9H KYb6pKaqYnMWJMv7iiwLor32Ucz7L46Y+P7Myse0E7ivB/R5AWUPYDJMzRPmgZNFIxWE kdbw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=HFFhnwi1XTh3mteeZB/9qILvDTOSvSbdeT/3s5BHyng=; b=MQf6IAKMOqSPT4xVnmOKEdYQJaviyo/HFtt8MhhGOXWbvzk5Oii4mJJnUfEoIuNjgI Evg4Jz0t5TbWJFv2EF9YDdRRDeTcQeWHMrc4EyPqCyXxnOZEyW85m0uh7B1YVVc373Rp D+X0EUgZ87Invt8PEKg5y/PHe0TGQCMV/VROWm//ktLO1TvGp3aPana7L3jYV8998kub kctEHdG1d+cyqS0eiciVabE8r0s0ItSNuc0yzKGW0HgJaaosbIOzCteVBQNV/JO3Dlr6 UiiE2JGkwAa76cc6jlVInHuaRpcpYHZaYRU/0UJGeu0tW+chvQ0xAtojbYA9jLla4cq5 UjSg== X-Gm-Message-State: APjAAAXnza2FlBCFPistzKbP/pR8YHfLCIxKUZ4xU584+O7dtEYFl/jh XMe+AYo9fHnSwuAmdXVTPok5jQ== X-Received: by 2002:adf:f543:: with SMTP id j3mr8291026wrp.243.1568126683569; Tue, 10 Sep 2019 07:44:43 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:43 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:26 +0100 Message-Id: <20190910144428.32597-12-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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 11/13] target/arm/arm-semi: Implement support for semihosting feature detection X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Version 2.0 of the semihosting specification added support for allowing a guest to detect whether the implementation supported particular features. This works by the guest opening a magic file ":semihosting-features", which contains a fixed set of data with some magic numbers followed by a sequence of bytes with feature flags. The file is expected to behave sensibly for the various semihosting calls which operate on files (SYS_FLEN, SYS_SEEK, etc). Implement this as another kind of guest FD using our function table dispatch mechanism. Initially we report no extended features, so we have just one feature flag byte which is zero. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 107 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 106 insertions(+), 1 deletion(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index f9019b00b8d..531084b7799 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -117,6 +117,7 @@ typedef enum GuestFDType { GuestFDUnused = 0, GuestFDHost = 1, GuestFDGDB = 2, + GuestFDFeatureFile = 3, } GuestFDType; /* @@ -125,7 +126,10 @@ typedef enum GuestFDType { */ typedef struct GuestFD { GuestFDType type; - int hostfd; + union { + int hostfd; + target_ulong featurefile_offset; + }; } GuestFD; static GArray *guestfd_array; @@ -467,6 +471,87 @@ static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) gf->hostfd, arm_flen_buf(cpu)); } +#define SHFB_MAGIC_0 0x53 +#define SHFB_MAGIC_1 0x48 +#define SHFB_MAGIC_2 0x46 +#define SHFB_MAGIC_3 0x42 + +static const uint8_t featurefile_data[] = { + SHFB_MAGIC_0, + SHFB_MAGIC_1, + SHFB_MAGIC_2, + SHFB_MAGIC_3, + 0, /* Feature byte 0 */ +}; + +static void init_featurefile_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDFeatureFile; + gf->featurefile_offset = 0; +} + +static uint32_t featurefile_closefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + /* Nothing to do */ + return 0; +} + +static uint32_t featurefile_writefn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + /* This fd can never be open for writing */ + errno = EBADF; + return set_swi_errno(ts, -1); +} + +static uint32_t featurefile_readfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong buf, uint32_t len) +{ + uint32_t i; +#ifndef CONFIG_USER_ONLY + CPUARMState *env = &cpu->env; +#endif + char *s; + + s = lock_user(VERIFY_WRITE, buf, len, 0); + if (!s) { + return len; + } + + for (i = 0; i < len; i++) { + if (gf->featurefile_offset >= sizeof(featurefile_data)) { + break; + } + s[i] = featurefile_data[gf->featurefile_offset]; + gf->featurefile_offset++; + } + + unlock_user(s, buf, len); + + /* Return number of bytes not read */ + return len - i; +} + +static uint32_t featurefile_isattyfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return 0; +} + +static uint32_t featurefile_seekfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf, + target_ulong offset) +{ + gf->featurefile_offset = offset; + return 0; +} + +static uint32_t featurefile_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) +{ + return sizeof(featurefile_data); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; @@ -493,6 +578,14 @@ static const GuestFDFunctions guestfd_fns[] = { .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, + [GuestFDFeatureFile] = { + .closefn = featurefile_closefn, + .writefn = featurefile_writefn, + .readfn = featurefile_readfn, + .isattyfn = featurefile_isattyfn, + .seekfn = featurefile_seekfn, + .flenfn = featurefile_flenfn, + }, }; /* Read the input value from the argument block; fail the semihosting @@ -586,6 +679,18 @@ target_ulong do_arm_semihosting(CPUARMState *env) unlock_user(s, arg0, 0); return guestfd; } + if (strcmp(s, ":semihosting-features") == 0) { + unlock_user(s, arg0, 0); + /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */ + if (arg1 != 0 && arg1 != 1) { + dealloc_guestfd(guestfd); + errno = EINVAL; + return set_swi_errno(ts, -1); + } + init_featurefile_guestfd(guestfd); + return guestfd; + } + if (use_gdb_syscalls()) { ret = arm_gdb_syscall(cpu, arm_semi_cb, "open,%s,%x,1a4", arg0, (int)arg2+1, gdb_open_modeflags[arg1]); From patchwork Tue Sep 10 14:44:27 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173530 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5908224ilq; Tue, 10 Sep 2019 07:53:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqzPk36eHeMldpcX40hFsVt/XgTqjUtRmyABZ5XLEprYAgw3GFnYfhvdbKPeNkxvqLIofTkK X-Received: by 2002:ae9:df03:: with SMTP id t3mr30121781qkf.165.1568127204706; Tue, 10 Sep 2019 07:53:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127204; cv=none; d=google.com; s=arc-20160816; b=TFl8AxpWpm0Y6yy1Zh2e8pWnVzWq25ppuvygTybNrPkvZk44E5wac39XoaFmiNW/SN 2lDCka8ff+Oe4gzmoufZJWVoOTBPlQtXmjcl5vMdms3frEgxkPy3kI0Czv5qCSZanXj5 OcZZPEWfhMRudYh3pgW/f7/7G2VfwNpitfzN/zYxIT5H6hrzmGR3mI025ITQ3miYFsW4 OVQhsRIAmpioaEUeh/GWM1jva/ifPK8d3SKsUHQp0QmjrUwwzRG8wy4PffR2zu/8A13P RsqTNJ0AkfED5UBdFS5Y1YXxU1ibJOzmU9w2iGVb3zME8nT6ZLI/sO0nNI/XDhNIJuXH xr/A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=mSF28sGGndXRCNElSwJ0qyiILOLlENUJr/Cd+r3rcy/m8/FCNr1R97Ri8QK0neaj5P YHjQ5l+MSSAwcriVbRyUI2qmYjc2Pgjq7d8nLsuEbpHKtkJ5RzA/4mg3RatAolK+k5ny Rj7IvgHgtlJFaX6DT7fiDPW2rUqIbxI5gocIU0vAXd1x+VAMCgs5526HhKEhPDpUiNCv +9+3Ww5z6Suda2WoXkkkqWrdT0tJS3ZyjSwBQks4zP/iICrvewcf9dpdh0zL8UWxVdzg exYJus2IvaPg5qGGX+aO0P9AM+Yr51gcan3SFo2gY+jSgMt8la5VzquSGo0VCzyGA+Br wy1A== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=frJtnUdJ; 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 a132si13290237qkb.209.2019.09.10.07.53.24 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:53:24 -0700 (PDT) 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=frJtnUdJ; 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 ([::1]:40928 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hWF-0004Qa-IS for patch@linaro.org; Tue, 10 Sep 2019 10:53:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54170) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNu-0005cO-NB for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNt-00056U-Id for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:46 -0400 Received: from mail-wr1-x441.google.com ([2a00:1450:4864:20::441]:38283) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNt-00055p-Cc for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:45 -0400 Received: by mail-wr1-x441.google.com with SMTP id l11so20811753wrx.5 for ; Tue, 10 Sep 2019 07:44:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=frJtnUdJmrWMbeMlSI4ZaC0DUyjKF0jSF2ar0QTkVt4vqGH414/fh6f4cec6hioWgF bVubc+ZbCy4Zo3wNxyPpHzUhpokvzCpCmZqwWqCC5mLxtYx/8FULeoW/FY/nU2iQN8Er DuGebK8eZNhACwvJFAoB/FGyYGaeS9Mn3OGNcHR9teG34gNKscxSXh8fHKYz46GrYXVX 6K2vRrSfWYqDa8BBT3sQlxmaAWLzAX8sS8nSRduDQaD4hoU9zMA8yMV6/Zp1tyewgaZx wOUO5rni+XYUAy7LrGmqcDGyquC9yi8NqaQxRq9I3qZPNDbdsqw36Kq1lYIbQmRxFSJD UGEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LA9MpYwh3mZJWgj+jicjrA5Nt9K2oC0TJFXiZTBybLY=; b=CcjyoUPpwu+Ut9fbSnMPaKtHsVQew+r3HUdODN6HbGP5X/znwaOoVYiC+xUMA3twNE 9HDxKNssh9bLjcJ4Lmom/dD6czrYwmj55eEvEfdbfkirEuUZW21nu9uvMgbkqEVGIeGi dVlb0A+iiu6AWFOhpH+O4Co7Gb7KPnw/khN8wXK8G1sJexOmk43GCFJ3Nm54zlyDPjC2 dxcC+NEf/Cnzk4LlEbZRdjo06PAUc56fJhQyxDi0utIHt6061BLT1Oi+7Yf2rUarQxUz NzrqOGwLlWAhPjl0/AZotiGlTumYaS+M8dQ4KBLp23JG16CXc2EO2J780zt3/BtltA9/ 9B5A== X-Gm-Message-State: APjAAAV91vJa1869WdwqGgNt/qpWfiIN5Ntz5gx8BVx+0ISoVCLkdOkZ XsLyCJhwgvy2TsALG1y6pjT1wg== X-Received: by 2002:adf:e392:: with SMTP id e18mr28592507wrm.87.1568126684565; Tue, 10 Sep 2019 07:44:44 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:43 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:27 +0100 Message-Id: <20190910144428.32597-13-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::441 Subject: [Qemu-devel] [PATCH 12/13] target/arm/arm-semi: Implement SH_EXT_STDOUT_STDERR extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" SH_EXT_STDOUT_STDERR is a v2.0 semihosting extension: the guest can open ":tt" with a file mode requesting append access in order to open stderr, in addition to the existing "open for read for stdin or write for stdout". Implement this and report it via the :semihosting-features data. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 531084b7799..0df8d4d69d6 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -476,12 +476,16 @@ static uint32_t gdb_flenfn(TaskState *ts, ARMCPU *cpu, GuestFD *gf) #define SHFB_MAGIC_2 0x46 #define SHFB_MAGIC_3 0x42 +/* Feature bits reportable in feature byte 0 */ +#define SH_EXT_EXIT_EXTENDED (1 << 0) +#define SH_EXT_STDOUT_STDERR (1 << 1) + static const uint8_t featurefile_data[] = { SHFB_MAGIC_0, SHFB_MAGIC_1, SHFB_MAGIC_2, SHFB_MAGIC_3, - 0, /* Feature byte 0 */ + SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; static void init_featurefile_guestfd(int guestfd) @@ -674,7 +678,21 @@ target_ulong do_arm_semihosting(CPUARMState *env) } if (strcmp(s, ":tt") == 0) { - int result_fileno = arg1 < 4 ? STDIN_FILENO : STDOUT_FILENO; + int result_fileno; + + /* + * We implement SH_EXT_STDOUT_STDERR, so: + * open for read == stdin + * open for write == stdout + * open for append == stderr + */ + if (arg1 < 4) { + result_fileno = STDIN_FILENO; + } else if (arg1 < 8) { + result_fileno = STDOUT_FILENO; + } else { + result_fileno = STDERR_FILENO; + } associate_guestfd(guestfd, result_fileno); unlock_user(s, arg0, 0); return guestfd; From patchwork Tue Sep 10 14:44:28 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 173534 Delivered-To: patch@linaro.org Received: by 2002:a05:6e02:ce:0:0:0:0 with SMTP id r14csp5911122ilq; Tue, 10 Sep 2019 07:56:06 -0700 (PDT) X-Google-Smtp-Source: APXvYqxCUn5Od4GrcDaegsIkYdnzwzd1ttgCCEUjkG8XPjIKb81n9HrqSC4ZJnyjsN5Ft6pPMzyV X-Received: by 2002:a17:906:6403:: with SMTP id d3mr15959599ejm.99.1568127366768; Tue, 10 Sep 2019 07:56:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1568127366; cv=none; d=google.com; s=arc-20160816; b=usjejbAx3YGUZUhn5dsYc4qe0uchhuXdYStYXE2ZZ1jqsMbLIu87QCUGivNaev377f J1/ROQhTIkuq9m3CS74zye1AH1zcu6jY+Tlcd1atlCyK8+qOhvnQUzrnjAPvcl5TSsLO E3YR8DdKgubcyAeLxxhDhF075jI0X4RJkjysPwq72jEqAU2szUO1hPk7KFmaDvBhdyja 0EKpUbeLT1UI5saxI5qyZmQ0pkgib/vVC1ltm5pNjmdCR0Mgl7cZ/+PUzo2YBWSQmUiQ 2Soux3abDdyjfoswNPhiVJPL8ok46aAkGkIXhe+D1B57V/jVfP91lbunw27545zeRcJZ Jv3Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to: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=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=o7MA1E/bErl4EK6EBRTsdRu4MWxSX1G7BuUGhVJ+tEAd+/jDM5fPW4kArnV6bip+7A VA7XxCtCvd6Hcxpge/OTtLFYAxtWPGT8PUhsWuwDSWjd3MegJB+lqDWK7egXDb5XVCLx aEVeGwaKVMuYGrTGtKbwS3U4LMLNjEd03ldrrK7ProDaLrtAtrMAHR9KpGW7iabkahOv RzpuBveYh0hpILPWfiuiaMrDbMPdChqCUzaAIl5u7+IT34e5Lj/7v7svBsnlf98x6QDv UjYZmTcy3CEEXPTGlt0MAqQYGbO1V9zmxIm40nJAk4N8g2UWtTCiqsc6ywXPX+CzzJmR AxFA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=FpfoOZur; 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 oj20si9480485ejb.58.2019.09.10.07.56.06 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Tue, 10 Sep 2019 07:56:06 -0700 (PDT) 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=FpfoOZur; 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 ([::1]:40984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hYr-000860-3h for patch@linaro.org; Tue, 10 Sep 2019 10:56:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:54202) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1i7hNv-0005e6-Nf for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:48 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1i7hNu-00057E-Je for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:47 -0400 Received: from mail-wr1-x444.google.com ([2a00:1450:4864:20::444]:33653) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1i7hNu-00056k-EE for qemu-devel@nongnu.org; Tue, 10 Sep 2019 10:44:46 -0400 Received: by mail-wr1-x444.google.com with SMTP id u16so20875157wrr.0 for ; Tue, 10 Sep 2019 07:44:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=FpfoOZur9SeiO5+ovdwDYbHq6hgY6rbpK/dv9x8sQf3BJy2GaAu7MQuZ1a2E3E0XDT YVs0B5uMpkF9uag6dPn7MlYSKCo0zmuLggIJJVhvKllv10u96rc05E5vWgsdlLN4VaHZ sI15QxR7jvaDBR6COKIkQSCcPXZ6QSB2ssG4UvWxNzTLBT5x7GQ+mnRZLv2s0V5YQ3xI hpEvXUl3qo4W5YzjIBteUUC1YjXlUtpNrzrg3lzLyc6htpvPMs4D1YfpiL4sFYc9H4Hz +LUox7B3Sdu084rI+Z7jZqdkeE97Uj6xVJaObKt0+NwX34vUCz+rgQb5NlRVDXbyN38b W2Iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=YNt4rzxDLZvJ3mLelApZg/g3aGU83zBv6U6suQNcbas=; b=D6bEWIWeM1BtUe1giOFQTMZ00geRL16d/GW7jCeA/OdzNtI2E7OS8mRnWYM59RA2wi 5LpyjfxLd6nfLAeR7Dzfq0+NAXei69DSAwPNjGdJBSiVOgDCbIZsXgzGandkge5iUPCk DKadir44vyYqkD4KWX45MY39L8hthH8PFr4romXW3SSphoB7ZqUjogqwpVHu96xbULXZ 9zPjPv1IHHQK1zBdSY829iAe64be0Q4QBiBnfHvfpPqJz6SKnQrNJM3eviA1cdJYFpwO dGWo7UBy8AQ/F8WrvZbsr+E6Ge7LPSciCPKtpH020ZkP8AWBs0uycElPxqc67RjtHCMO M/bg== X-Gm-Message-State: APjAAAUbuAd4RwGYZVdRquUqvqLg0g4AZin9esjP2yYc62P2PAD5D9pJ Ek0PvBPLMVa6gFr4Mr5Uibzw8Q== X-Received: by 2002:a05:6000:1189:: with SMTP id g9mr28272944wrx.117.1568126685607; Tue, 10 Sep 2019 07:44:45 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id a192sm5703814wma.1.2019.09.10.07.44.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 10 Sep 2019 07:44:45 -0700 (PDT) From: Peter Maydell To: qemu-arm@nongnu.org, qemu-devel@nongnu.org Date: Tue, 10 Sep 2019 15:44:28 +0100 Message-Id: <20190910144428.32597-14-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190910144428.32597-1-peter.maydell@linaro.org> References: <20190910144428.32597-1-peter.maydell@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::444 Subject: [Qemu-devel] [PATCH 13/13] target/arm/arm-semi: Implement SH_EXT_EXIT_EXTENDED extension X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" SH_EXT_EXIT_EXTENDED is a v2.0 semihosting extension: it indicates that the implementation supports the SYS_EXIT_EXTENDED function. This function allows both A64 and A32/T32 guests to exit with a specified exit status, unlike the older SYS_EXIT function which only allowed this for A64 guests. Implement this extension. Signed-off-by: Peter Maydell --- target/arm/arm-semi.c | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) -- 2.20.1 Reviewed-by: Alex Bennée diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index 0df8d4d69d6..3900bd4e1e6 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -66,6 +66,7 @@ typedef void TaskState; #define TARGET_SYS_HEAPINFO 0x16 #define TARGET_SYS_EXIT 0x18 #define TARGET_SYS_SYNCCACHE 0x19 +#define TARGET_SYS_EXIT_EXTENDED 0x20 /* ADP_Stopped_ApplicationExit is used for exit(0), * anything else is implemented as exit(1) */ @@ -485,7 +486,7 @@ static const uint8_t featurefile_data[] = { SHFB_MAGIC_1, SHFB_MAGIC_2, SHFB_MAGIC_3, - SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ + SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; static void init_featurefile_guestfd(int guestfd) @@ -1026,11 +1027,14 @@ target_ulong do_arm_semihosting(CPUARMState *env) return 0; } case TARGET_SYS_EXIT: - if (is_a64(env)) { + case TARGET_SYS_EXIT_EXTENDED: + if (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(env)) { /* - * The A64 version of this call takes a parameter block, + * The A64 version of SYS_EXIT takes a parameter block, * so the application-exit type can return a subcode which * is the exit status code from the application. + * SYS_EXIT_EXTENDED is an a new-in-v2.0 optional function + * which allows A32/T32 guests to also provide a status code. */ GET_ARG(0); GET_ARG(1); @@ -1042,8 +1046,10 @@ target_ulong do_arm_semihosting(CPUARMState *env) } } else { /* - * ARM specifies only Stopped_ApplicationExit as normal - * exit, everything else is considered an error + * The A32/T32 version of SYS_EXIT specifies only + * Stopped_ApplicationExit as normal exit, but does not + * allow the guest to specify the exit status code. + * Everything else is considered an error. */ ret = (args == ADP_Stopped_ApplicationExit) ? 0 : 1; }