From patchwork Tue Jun 28 04:53:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585504 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp452484mab; Mon, 27 Jun 2022 22:54:16 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sN6/r94PvmA5UisHC0yrI0BD0tfWPoPmJXwXU6hrqI1pJ0DyaXmQqvgUWBln5+e7hAFd33 X-Received: by 2002:a05:620a:172b:b0:6a7:61b:9bbb with SMTP id az43-20020a05620a172b00b006a7061b9bbbmr10347620qkb.23.1656395656546; Mon, 27 Jun 2022 22:54:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395656; cv=none; d=google.com; s=arc-20160816; b=AlOUkR1IYpR2GiqzVm49t8WwlF49L8AXeQkQ3BNAdYenW5yb+S9x7H6+xXkLxqYJge KpzQruBZZt36FTZupcX738Xw/Vl3i5dG4hy4AhY2fpHWJi6LBNw013r1QVjQXYC2wKre xww+KSaAzxCg5MBpImRlTU0meiZL1aKQp6/nZJS6jRZ2MXlQ8QKL8OFd3XWxC6kxCRXl i+xjtyUwhsd1eFbIZjfeYLKSe8Pb7CsdEuQhXAZUAVJHZl/6Z86eY1haIpqPsiZxPReU RKswyi8OMjfIj0ag90Os2CVt09m/wE2bUa0wbtQpnYdgX3EUL4+OBGT/zrMGSKsz72Dp EY0g== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hL15phHiFTEeYUryTllbE9QTsXahphlhPjpE5IcwyII=; b=bBy33uLf3vkbM7eBWB32AVW/9MylSXj4RoqDxtcFGLTeXG3z67y9nLQHwScYgvLrCv 2RAqkCQX80nWfIDE0CDnHFnF0Fl/R2lDF7m8hrBs3JAnX+nvmuVrj0HveL7NyZf+Lxqh h4Ehzw+Ah667Oq/J79u/JspfAUaBnJsmObjJu2Ihqw3kK6xkmel7gmm5jFY9zXhKV/aD OuxccYLv5267UbSLrVhuzaT98qDPxjegjOzjGTHvtj3uVxUkala9KW1B/CahQlgI8JAJ 2OvAordwOampS/zyG5G8sBqAMmac1nEhdvKBqUU7P8C/y9NAWOCjBZiQxe+yT1iW2Wq3 lesA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ObaKWAu+; 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=pass (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 3-20020a0562140d4300b004726e3e3f0csi2072647qvr.558.2022.06.27.22.54.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:54:16 -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=pass header.i=@linaro.org header.s=google header.b=ObaKWAu+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35866 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Ay-0003fT-2L for patch@linaro.org; Tue, 28 Jun 2022 01:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:42990) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Es-00028p-Io for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:15 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:41800) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Eq-0008Fs-TZ for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:14 -0400 Received: by mail-pj1-x102b.google.com with SMTP id g10-20020a17090a708a00b001ea8aadd42bso11520430pjk.0 for ; Mon, 27 Jun 2022 21:54:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hL15phHiFTEeYUryTllbE9QTsXahphlhPjpE5IcwyII=; b=ObaKWAu++fvAwBnmA9sCc/E7V3/ILjNLMnBfEWlh+RPBOqz2rLfOpnO7EIs8cb3vta vLd0TE9nqaI9rO1hV4jP7M+a10rPe6tVXWDb0PZpjcpyhMklLrIMBvOiZXZXG3qmV6rj L96jSlab4MHHZbgh10gAS7MfINWKNTjAjiw3uHLR27TZ9t6qAZ37PGfEBusF1ZpCvNJZ ZokBonRn0UqQKA0sw2RtsWdkhkYoC8VgNNvatexjqnOfsbAXIWQXfsS7gveTLPAh3V7x 4gRRLlFyVd2xCux581nHBmfCQMftsE/7fkStliwzWmJpFUjXzQjg7HRwhTIQYkxKT3MS He/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hL15phHiFTEeYUryTllbE9QTsXahphlhPjpE5IcwyII=; b=z7gBXdPw2TFXb3Lqm5HSQhfKnjtHvcJ+00BINw8XuvupBatxg0b1aAI0GjklYwfV5G iwu2ejrRhTm/qpw2kmdVDd2dPj7WXjrHpA1oMLDu076rbWRH/kNddg2fqwpjIH/Jzud7 QV906CydW8xe+z+ptGCYOWQfIFuOGpCMzcy/wHpUVetJUB6kV1tnkepUHYhwKtZ4nACV Vqn31X9L0j4vplUnDGLxUB+AoNKvbUVISei+MfB8WxhdV3Qp8LXQbbgwtsle7aZCd1/E dsiLsMreL+pTSeJtvVEd9tf1aZeBexPtfBb60rRFTRMutvsAho9xUdkzwdYCyMeaPkbi b0vQ== X-Gm-Message-State: AJIora8vsMBk3uCzQJHhKlN+E3xbMf96CY/bfHeZ1ZCXE+PnKron94+w 8dfocODmSpqR1aYbWP3cyN2yziwaqWHwFw== X-Received: by 2002:a17:902:d4c8:b0:16a:480b:b79c with SMTP id o8-20020a170902d4c800b0016a480bb79cmr3065266plg.15.1656392050939; Mon, 27 Jun 2022 21:54:10 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 01/60] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h Date: Tue, 28 Jun 2022 10:23:04 +0530 Message-Id: <20220628045403.508716-2-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We have a subdirectory for semihosting; move this file out of exec. Rename to emphasize the contents are a replacement for the functions in linux-user/bsd-user uaccess.c. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- .../{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} | 6 +++--- semihosting/arm-compat-semi.c | 2 +- target/m68k/m68k-semi.c | 2 +- target/mips/tcg/sysemu/mips-semi.c | 2 +- target/nios2/nios2-semi.c | 2 +- 5 files changed, 7 insertions(+), 7 deletions(-) rename include/{exec/softmmu-semi.h => semihosting/softmmu-uaccess.h} (95%) diff --git a/include/exec/softmmu-semi.h b/include/semihosting/softmmu-uaccess.h similarity index 95% rename from include/exec/softmmu-semi.h rename to include/semihosting/softmmu-uaccess.h index fbcae88f4b..e69e3c8548 100644 --- a/include/exec/softmmu-semi.h +++ b/include/semihosting/softmmu-uaccess.h @@ -7,8 +7,8 @@ * This code is licensed under the GPL */ -#ifndef SOFTMMU_SEMI_H -#define SOFTMMU_SEMI_H +#ifndef SEMIHOSTING_SOFTMMU_UACCESS_H +#define SEMIHOSTING_SOFTMMU_UACCESS_H #include "cpu.h" @@ -98,4 +98,4 @@ static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, } #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) -#endif +#endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index b6ddaf863a..1033e751ef 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -370,7 +370,7 @@ static GuestFD *get_guestfd(int guestfd) #ifndef CONFIG_USER_ONLY static target_ulong syscall_err; -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37343d47e2..a31db38fc3 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -25,7 +25,7 @@ #include "qemu.h" #define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #endif #include "qemu/log.h" diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index b4a383ae90..6d6296e709 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "qemu/log.h" #include "exec/helper-proto.h" -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index ec88474a73..373e6b9436 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -28,7 +28,7 @@ #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else -#include "exec/softmmu-semi.h" +#include "semihosting/softmmu-uaccess.h" #endif #include "qemu/log.h" From patchwork Tue Jun 28 04:53:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585500 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp447381mab; Mon, 27 Jun 2022 22:45:00 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tbQildiqvofK/zZYJaGmr8GhrXUMYdR1HscqWZh/ed/KjtCTgOUk8SnMcgQ/5gWe3s00yX X-Received: by 2002:a05:622a:148c:b0:31b:d8c6:8cbe with SMTP id t12-20020a05622a148c00b0031bd8c68cbemr3216868qtx.678.1656395100463; Mon, 27 Jun 2022 22:45:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395100; cv=none; d=google.com; s=arc-20160816; b=UA+KSjh7nrXmX2r03c+3Y9g4cyWoNdRLkrsX0v7UgLiF4S4XeRoKHqi5HI3LYWWbyK 0VwUB2Zab6BxWRsOup2g3ypq2GWOzJ3f3Xdk09poc8XbRB9KAu4bcX8HLa1m5mcLd5f4 waQiuRal7uJt88LgQU/3ObMTRRsUvboLR9mDYiPa0C/jdr7f0Z2fynRGAC+lUu4Y8CV+ Gi5M6zmOhU/P4sVCarSDoS+KrUIqZ2f1e7xh0XjoRxKA+5zbNGEe2LvUKuRfvv20Xv8w RZ0BZCOqCI8ZwdWNqe+Qo0lg2qOw5hWxYhYYzUja+oCw+QdlYCHsRwyGI//kCrpmn7Nv PfzQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=ACEWsKUyi1geIhoJARDoleed3Aeiv2/DqqaU212kUlEcHI7zSfyxfelgzSthH2OFkW HPjOV+ySCwW02n4obTefn7X7NX77FiMrmVwxfAWfHEzNhTkxqsDQsHMuT7hooRqxpje1 qcHO2oWCHT5Niw3tgw1dxVfnHhJZVjUPWj4po9YkTqmwSYzlkuW5emtEdZ0CKSS6TgIU bcFfJkv3/87Z/H8pz+w2TuoZzCeIi4B9jvhVxJNSqt06F2u8eaWzyEAt2h6yihjfYKZT Xx3RslQ7jNfN3hFGU0CkTVbV0Sm2TMiY0f4hBe+EE2GyYvTHGvr1/hyoKTw+MrwP7P7+ 9Eqg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xjeuGB2B; 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=pass (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 f9-20020ac840c9000000b00304ecce6d99si6984350qtm.173.2022.06.27.22.45.00 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:45: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=pass header.i=@linaro.org header.s=google header.b=xjeuGB2B; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51010 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o641z-00022z-Mq for patch@linaro.org; Tue, 28 Jun 2022 01:45:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43006) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Eu-0002BA-9Z for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:19 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:42660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Es-0008G4-Hw for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:16 -0400 Received: by mail-pf1-x432.google.com with SMTP id d17so10917841pfq.9 for ; Mon, 27 Jun 2022 21:54:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=xjeuGB2Bf7LQdol2RCndLQeLg+HAxOAMtMwAn6KTfZKlCSG1bY13ntZLO2zeMZ67Ce VWEmFmEjVXdIpaPWjn4+I5cb24CUQpfNoF67HlgV/iUEcfFbP5/z41QNq+U0yDsU+OS6 hyt9nYbx+qpctUEnQwllojZYoy3HKPglZRUnbomJMrSF/AGib029zfFyjDHkNDjwxSuH euZNEdJM6g6BknqQ8pnsJbArVRZ93a2ydmyj5mfm56yUC3QbxAXKOHWZFumQnkPlIBZ1 uYkwN9vWlzyVhu9aezh6HAM3fyXefqE1xW+/xgAVTh+0Lh9d3S6WfLQVN/FnTsotQwsE m/kA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XykDNb8AiF5XqooTWDspyQ6eumaI59tyN1vSYpnaRMw=; b=ZdQ8tHAyZg3/Ml7Tw4hgH9WG0HgFrptKHaNSY5BVh9nzwF3BazJQjOM0VAsBx5R0Ce 8CASogPfO/l5ojYGbOHPuRh8Mq2AM/j0zgJ7ZozynUUCnoLvbheyJS5Zvrz7Tk6wfWR5 Iu3B/i5SVWUs2+DxNTPXXtvN8i+6rPo1ZKhBK5qFgqevhUIzMvVYjSikEqn3hguBQzln nf0WW7DdSas06/dgdfd3qArKcHS8ipRVj0e20IVnyzjo9x7Cs5adnIu3wEaAQ/0QBNQ/ iZjeBddd+Mvw9B1v5wudubBQbqCTWipHNkHWKWa1nkkHzDfx3zMfDbYjbJaaQX8c8tx8 sJ+Q== X-Gm-Message-State: AJIora98TXiPudngGfEhB+hVnKYoeB9PMrhrq1gt+Df7tmxNnisD8k3U m7fp5LCEuUDjXtBhjgPB/oWStDgxUU17Bg== X-Received: by 2002:a05:6a00:14c7:b0:525:89c1:35fb with SMTP id w7-20020a056a0014c700b0052589c135fbmr2755157pfu.36.1656392053235; Mon, 27 Jun 2022 21:54:13 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 02/60] semihosting: Return failure from softmmu-uaccess.h functions Date: Tue, 28 Jun 2022 10:23:05 +0530 Message-Id: <20220628045403.508716-3-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We were reporting unconditional success for these functions; pass on any failure from cpu_memory_rw_debug. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 91 ++++++++++++--------------- 1 file changed, 39 insertions(+), 52 deletions(-) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index e69e3c8548..5246a91570 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -12,82 +12,69 @@ #include "cpu.h" -static inline uint64_t softmmu_tget64(CPUArchState *env, target_ulong addr) -{ - uint64_t val; +#define get_user_u64(val, addr) \ + ({ uint64_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap64(val_); ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 0); - return tswap64(val); -} +#define get_user_u32(val, addr) \ + ({ uint32_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = tswap32(val_); ret_; }) -static inline uint32_t softmmu_tget32(CPUArchState *env, target_ulong addr) -{ - uint32_t val; +#define get_user_u8(val, addr) \ + ({ uint8_t val_ = 0; \ + int ret_ = cpu_memory_rw_debug(env_cpu(env), (addr), \ + &val_, sizeof(val_), 0); \ + (val) = val_; ret_; }) - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 0); - return tswap32(val); -} - -static inline uint32_t softmmu_tget8(CPUArchState *env, target_ulong addr) -{ - uint8_t val; - - cpu_memory_rw_debug(env_cpu(env), addr, &val, 1, 0); - return val; -} - -#define get_user_u64(arg, p) ({ arg = softmmu_tget64(env, p); 0; }) -#define get_user_u32(arg, p) ({ arg = softmmu_tget32(env, p) ; 0; }) -#define get_user_u8(arg, p) ({ arg = softmmu_tget8(env, p) ; 0; }) #define get_user_ual(arg, p) get_user_u32(arg, p) -static inline void softmmu_tput64(CPUArchState *env, - target_ulong addr, uint64_t val) -{ - val = tswap64(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 8, 1); -} +#define put_user_u64(val, addr) \ + ({ uint64_t val_ = tswap64(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) + +#define put_user_u32(val, addr) \ + ({ uint32_t val_ = tswap32(val); \ + cpu_memory_rw_debug(env_cpu(env), (addr), &val_, sizeof(val_), 1); }) -static inline void softmmu_tput32(CPUArchState *env, - target_ulong addr, uint32_t val) -{ - val = tswap32(val); - cpu_memory_rw_debug(env_cpu(env), addr, (uint8_t *)&val, 4, 1); -} -#define put_user_u64(arg, p) ({ softmmu_tput64(env, p, arg) ; 0; }) -#define put_user_u32(arg, p) ({ softmmu_tput32(env, p, arg) ; 0; }) #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, - target_ulong addr, target_ulong len, int copy) +static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) { - uint8_t *p; - /* TODO: Make this something that isn't fixed size. */ - p = malloc(len); + void *p = malloc(len); if (p && copy) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0); + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } } return p; } #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) + static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - char *p; - char *s; - uint8_t c; /* TODO: Make this something that isn't fixed size. */ - s = p = malloc(1024); + char *s = malloc(1024); + size_t len = 0; + if (!s) { return NULL; } do { - cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0); - addr++; - *(p++) = c; - } while (c); + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); return s; } #define lock_user_string(p) softmmu_lock_user_string(env, p) + static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len) { From patchwork Tue Jun 28 04:53:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585499 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp444011mab; Mon, 27 Jun 2022 22:39:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vMH69fLIDAFv1OeQVF/imnNZ2k2MFQHO+K9Xu0+kwqC2L7dn4L2BlMVxdxiSsCIKbggncv X-Received: by 2002:a05:620a:2584:b0:6ab:91fd:15dd with SMTP id x4-20020a05620a258400b006ab91fd15ddmr10248573qko.287.1656394741457; Mon, 27 Jun 2022 22:39:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656394741; cv=none; d=google.com; s=arc-20160816; b=c5PK0Tto/y+T3P2Pe4O8dwh7XiH23gKwVOm50xCMP/H+l3mq8wqp8PafSH8gQHPJam 8Ol6b5uuOUvJeA2w/FEcDJ7MLeO0MCEoGl3BMp5hmVZZj1orG5uTEFyoD9YNmvKEdL/F hl0ofbHIaexW/8ILEdWe+TR+310kNseBYXWLzfgnrOpyz8CgotsnuloABbqZ62KO69Kt rV7dqlPxLuYsQ4BFNiRQRvxQTK6O30t2ZgeoH08+JfYDQapMboG0ZenykoODMCe8V5le OI6ID2cDAtDebz5MnLHevajus4TOFYHu6hNMnz2sEHEl9m8Q885mlNkfVnzDfovvShnW uMPQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=hcO6KbcudmR/L1vrL0TiQ0lffJN8P/Isx+5TQQaVoJYPSR1m5VWNLSEYvmIZkbNPYd +auUgjX8gNZaDX6HxvLMDCNrnEAfB5YUc3b2Oop6c7KL2eEUKtTMkNF7aywLTTm0vSZ9 2EuGOHF98ia1pAvK4s6GHFjInpU9F0tJp4mVETC5hmlWT3Ptci0GEjyRVWVrVX9J5x/I Ups5Pw0dqS9GwbPmf3sld2QKKMAg4aF+IDhbWjU/fA69MuE9Y7pkgOgxjKMdE59V5vWp MWKoQhC1a4dldyD9KE3lfo1E3F5mqe7h0iHrSHJXLxmuPpVqoOaJrblPhX8F4tjxqLFe G12Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m2BdSOuD; 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=pass (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 eo6-20020ad45946000000b004702eee87c3si6596039qvb.143.2022.06.27.22.39.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:39:01 -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=pass header.i=@linaro.org header.s=google header.b=m2BdSOuD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:47134 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o63wD-0007aP-1h for patch@linaro.org; Tue, 28 Jun 2022 01:39:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43022) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Ev-0002BJ-Ml for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:19 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:40559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Eu-0008Fk-96 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:17 -0400 Received: by mail-pj1-x1034.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so14628330pjl.5 for ; Mon, 27 Jun 2022 21:54:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=m2BdSOuDP/An0yZke11I+RfufApZBTFYghcf61IYewiSeOUVWISuF/xaDKerW4M2rL hKF6rHsiXmTPwtRcGptOGPt3rj+FHN1GcOs4iuZlH47O3GIEn98gOAgkl0VeZddlLXu1 GHTN9stlJmr5ZW9j1hW5mqd0kF79UryqVmVtncaWi55zJ1CryfSKDGiJE/lMuX8l+4S3 nBjeQ6x7ihUU5vTNFRAluJdMrbqWenKwnWejYBfhA1IZHYXa60J8suine2fcpdsSxEzZ Mc2Ece3nu6hRVWowuczkNBkgpZ49gsq5/zJ1A5m5Gj2aHh3hJU9iVY5pR85WBb23NLEd cE+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+d9/jr06nswWZQd9Uw/cJzKLCMbhQR5Mz1vx++OuQjc=; b=3kE/NwVkAv4+Uhtfl1vyamFui3gPTWnX0ABhSbQoNvgUahXEBN589D2kZzwXmNRprJ LIAFX1nIme3rPszSGXhP9nJsMii9naETWAtL/yKsj/gykNB4qlpO5F50NkM0ken/ezg3 fL/rrPFEGSHtBsiTkuP0qnlygHQLBKJ5bISJoTBeo02csOTXP2LGh12HcsUtRi+oWJxl fvK/NCaHFu5jtF2QEGknlSpIiwcEYXcY5sXXsZ4fYcB8Tg9OGktD8nGfMNtecDLShP57 n/QCsKDN7SUu5sRV81qWz57xFSg/xonzCWPRX6zzMk67lfUM/DW8N9SHZd2cQbCZPlQF xVrA== X-Gm-Message-State: AJIora9WbglV+HZ3r+/4ZNyWX04DMm+CEWmyfZwaodfphdmq6I6g+kXi CcjlvWdxvCELQ6YZ1kZkJmvgfnCQtD9GaA== X-Received: by 2002:a17:90a:404a:b0:1ea:e936:b69 with SMTP id k10-20020a17090a404a00b001eae9360b69mr19594783pjg.133.1656392055506; Mon, 27 Jun 2022 21:54:15 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 03/60] semihosting: Improve condition for config.c and console.c Date: Tue, 28 Jun 2022 10:23:06 +0530 Message-Id: <20220628045403.508716-4-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" While CONFIG_SEMIHOSTING is currently only set for softmmu, this will not continue to be true. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/meson.build b/semihosting/meson.build index ea8090abe3..4344e43fb9 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,4 +1,4 @@ -specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( +specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', )) From patchwork Tue Jun 28 04:53:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585503 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp451132mab; Mon, 27 Jun 2022 22:51:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vO3JnLYyFrlHIliwY3Xqd5nhUpZsKYKdNG9LhXT603cCkIyqfvayEKwfLW4RP83Mpaxpgv X-Received: by 2002:a05:620a:798:b0:6ae:ec93:e6f0 with SMTP id 24-20020a05620a079800b006aeec93e6f0mr10313433qka.413.1656395503441; Mon, 27 Jun 2022 22:51:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395503; cv=none; d=google.com; s=arc-20160816; b=SQF4hGZ34S/yyb5VDwq8A9iqUKPAJLgTKDfuy/WNJtFfMg9itrUidULEKIE0Kigg1W 4R61otPftxiu/Cyiy9nK90KghuSlvYKSuJdnupp/5HxfhJTSVxjf41BDpBqjOeDzBeTs XzW9bShCgNK+fwlDTrvHFsQ1VO8YYcmVMgFUH9LQ+kQtnqOVyBnFTLs+v8H+ZQbpTpMW 0ys1tBxA5Q3efCA7U2N8eEB97s+oqcTBM2NYw4WwntyTR2umSHw5TmabMB3hK1yd20xW sQqxge5fBKu3ovq8+glj1VtGgPZcHwjC2IW5jw/NdmeWVr/toacxJsmm4v7mS6BarSx6 ikbg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=n0e08SowxKTEfylHKNZmg8GOP0bOKzMEP4uQ/G0RKCQPuQDnYvUp+kl4DaqvjVk7yq ommtsMLhm8QdheR7nd0Q6YJabEn02ZFdVkGhPJ1Z+APDNLPJCpqCtXtekvg9Xq9ZgWdY +M/R2RE3RIsXzVA+3M+BJOaNmAzw6pifkSKEjnmOFP/Vxzm0Cc/rGXAqD5jFEQ6T6qVW GteUbwPY3GXtTmh9iV38OM2+g8iXlDZQzgLkTZk0sPSd/LcNC03D+IJYdlteuBN78I/m qysSAnIkRE/D0BMv6RkEwdPGaPSN+PGvcAmyetbbqhsKtPVavLlhVHvxIVsFXIIz3eUR QRFg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qGMtCKFK; 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=pass (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 z3-20020a05622a028300b003052f5b3302si7530754qtw.730.2022.06.27.22.51.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:51:43 -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=pass header.i=@linaro.org header.s=google header.b=qGMtCKFK; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o648U-0000hQ-US for patch@linaro.org; Tue, 28 Jun 2022 01:51:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43038) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Ey-0002Ck-Gk for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:21 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:51860) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Ew-0008H4-U0 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:20 -0400 Received: by mail-pj1-x102d.google.com with SMTP id l2so10248114pjf.1 for ; Mon, 27 Jun 2022 21:54:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=qGMtCKFKQ/U+TbLepNcm1TBMz8/zuUTmR3SAF2lbc1iJTUeLGTXpE2wy4OALtVW6Mx eyhWzWzd1NUH6NpMQ37tPTsQJMXkY2B7nfnNKQoI6P6CZ97Cf3JEX0YxC8c9Mrx2Z0i4 2UvRus1ai+XWCtEl8VDnhgXWundayqjCwWISossbSvscHBKGyyRaMak6osp23xAuLLCG jBOi65PcSeA+u7cptt6PjidNudmzEt04mDvSpJyy6L42dZZJBgebfqHVhSv9jlcwwH7r Hpz5rJAJ/95j7FYqpnLcajOLN3ccAcjJNnfQ2w//wwmDV8I+NoSaA7VM46PNe7S7BoW/ 70aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=UtCh1R/o+jWczZ2gQY+9f4Xav0T6t+bxgoxTR2mENvU=; b=cxo238cMfIOFyUD/M8yl4KmPLEDs4iVWlXnhL61YmL8/jix95FxqPMXBgu9xyEf0j6 3zdRYFVGZjc0fWdrBsSZ6Pgw3Hau9Av51gP2vgqwyx7QUZex45sUwp37gYezUMGwAKES 68QStDInW/uAoCQeTPszrGgST4lrKHn8KjXgrlFXtXZnjnXqHM0QYnfS9UHTuEi4y5Wz VmdlfT7TYxSuYtU+HXe7yPtRpDMEgQHc9DTYAKF3vJZNSrjxGkzOfYMgTAzk9CTw6tc0 CE4Gguvem0nj0DJX9ikWVey/TNs62zHc/U4cb9NFS/VWWrQknjMnAcyuhgaV6EIM9T8A k8jw== X-Gm-Message-State: AJIora/RMNcYx7fwDvdbgMw32/ldSBGi9QOkGxfhxHNojYsk9f4fM78k Db+Pqixo2dRvPSkXgSXwWAdlS4z582CD+w== X-Received: by 2002:a17:90b:2251:b0:1ed:29d2:e013 with SMTP id hk17-20020a17090b225100b001ed29d2e013mr22800287pjb.223.1656392057628; Mon, 27 Jun 2022 21:54:17 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 04/60] semihosting: Move softmmu-uaccess.h functions out of line Date: Tue, 28 Jun 2022 10:23:07 +0530 Message-Id: <20220628045403.508716-5-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Rather that static (and not even inline) functions within a header, move the functions to semihosting/uaccess.c. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 42 +++------------------- semihosting/uaccess.c | 51 +++++++++++++++++++++++++++ semihosting/meson.build | 1 + 3 files changed, 57 insertions(+), 37 deletions(-) create mode 100644 semihosting/uaccess.c diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 5246a91570..03300376d3 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -42,47 +42,15 @@ #define put_user_ual(arg, p) put_user_u32(arg, p) -static void *softmmu_lock_user(CPUArchState *env, target_ulong addr, - target_ulong len, bool copy) -{ - void *p = malloc(len); - if (p && copy) { - if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { - free(p); - p = NULL; - } - } - return p; -} +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy); #define lock_user(type, p, len, copy) softmmu_lock_user(env, p, len, copy) -static char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) -{ - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { - return NULL; - } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; -} +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr); #define lock_user_string(p) softmmu_lock_user_string(env, p) -static void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, - target_ulong len) -{ - if (len) { - cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); - } - free(p); -} +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c new file mode 100644 index 0000000000..0d3b32b75d --- /dev/null +++ b/semihosting/uaccess.c @@ -0,0 +1,51 @@ +/* + * Helper routines to provide target memory access for semihosting + * syscalls in system emulation mode. + * + * Copyright (c) 2007 CodeSourcery. + * + * This code is licensed under the GPL + */ + +#include "qemu/osdep.h" +#include "semihosting/softmmu-uaccess.h" + +void *softmmu_lock_user(CPUArchState *env, target_ulong addr, + target_ulong len, bool copy) +{ + void *p = malloc(len); + if (p && copy) { + if (cpu_memory_rw_debug(env_cpu(env), addr, p, len, 0)) { + free(p); + p = NULL; + } + } + return p; +} + +char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) +{ + /* TODO: Make this something that isn't fixed size. */ + char *s = malloc(1024); + size_t len = 0; + + if (!s) { + return NULL; + } + do { + if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { + free(s); + return NULL; + } + } while (s[len++]); + return s; +} + +void softmmu_unlock_user(CPUArchState *env, void *p, + target_ulong addr, target_ulong len) +{ + if (len) { + cpu_memory_rw_debug(env_cpu(env), addr, p, len, 1); + } + free(p); +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 4344e43fb9..10b3b99921 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,6 +1,7 @@ specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', + 'uaccess.c', )) specific_ss.add(when: ['CONFIG_ARM_COMPATIBLE_SEMIHOSTING'], From patchwork Tue Jun 28 04:53:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585502 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp449721mab; Mon, 27 Jun 2022 22:48:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sx8usFQRygkNxt/qA70iIINSk6CJd+OZl6hmMJE0EVbDhVpuprTScHTN1ZUgJPE8jm1L/t X-Received: by 2002:ac8:5fd2:0:b0:317:c4b5:b5ac with SMTP id k18-20020ac85fd2000000b00317c4b5b5acmr12151918qta.506.1656395339485; Mon, 27 Jun 2022 22:48:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395339; cv=none; d=google.com; s=arc-20160816; b=qpIcKCvBkGirDLwcvAsmDEwDmXBewqU7OpXEaYbZBHye2Qz0rn0Qs1b3KUAW1nQt+e FTZ7vCcUncHLqb18wLWUgsMGUa+zmhv+pTfMIqfYvVAkFYA5YH49P5fAGAQ4rQdXBVfW SV95hgCFfQBgv+/+X/Jev3DEIkDjnsMjWuLyuLRKerpifqGkfFqmZpA6YQTqHpga67t4 95TnToqYXLYw/Mwdc3SgzozBUkFdPoTPsZgB4LsjbKHWwkGfulWUHQm1fqIZEUJEygNQ rQNkFAW8nebD8ICyCfzYmaurrEaumhMKKNLmou3hRi4cEOSGLmVQbJ85qwLy6NESTnzW JU0A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=gmqcmiTjW8Am1AjqY8MfRxNedvHrq6L4BnMrgUFJA4c=; b=oe4dFauIQYSsK2xFsVRaK/kojkX4f1TSDuvbiuKazu0tiWOgtppuRR8qfUeui5XIJL wv5w0GTn0VE2/hYl2hFGjdBB2yT/H1bQK1uYxSZZEW+oz7T817kSttgwJmUREofwRzSR +kD+EqRKp/q0VUxYP82J3O/Eyaub5zGqUS6MBmz7Us0MOWL4TGrcTJbmMiE9Dcvnbi30 DMzp0XrAMN+RqGYsGUW/xYaa6z5M0+o/WXwSOGRFpkBvOs/qcDZzQLL73C6DAmwgyJMd V1TAg16i/kXoO3+7x0Z4GF8jNrekC/KmaWFFYlqQA714vuKkskwiAD19BxWeIUtFtWz/ 8MgQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dazlx0Y1; 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=pass (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 f14-20020ac840ce000000b00317cc208892si5814697qtm.449.2022.06.27.22.48.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:48:59 -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=pass header.i=@linaro.org header.s=google header.b=dazlx0Y1; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:56262 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o645q-0006Y0-VX for patch@linaro.org; Tue, 28 Jun 2022 01:48:59 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43056) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63F0-0002G0-T8 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:22 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:51862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Ez-0008IL-Bm for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:22 -0400 Received: by mail-pj1-x102f.google.com with SMTP id l2so10248182pjf.1 for ; Mon, 27 Jun 2022 21:54:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=gmqcmiTjW8Am1AjqY8MfRxNedvHrq6L4BnMrgUFJA4c=; b=dazlx0Y12li2+0hdT2HllQzLmT3n3PeyvUSGDa7lGEdLPj0DkvnBgHgspwJVdxfgzo YJ1U/klupK5gfjeTILldmrJYQzzzYkwz/k91GO50eMDilSx+3bJnSGjxgEZvvm16thEH 9iwwI8IXWNkrZy6qH7MZsNuJqJxoongNoznKGJ6UvZxdHIbOBvyzLqOoHRMNuLwNx5F8 vi8nSU35pcUbf9cAxc9KmxQObtvBGrIrBdHfnY2kX0X43vXaNgOs4Lh8vGucKp+hK4Tn Fx3w8xrYxnERAh3xFtApW6M9KGSIWTRePwO4QVhgS2nR2ldU5FsW0Lr7YdupgOw+wigT nd8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=gmqcmiTjW8Am1AjqY8MfRxNedvHrq6L4BnMrgUFJA4c=; b=rgqtXhGTWH1206B8V/UEn3qxS/TPGLSWHyHTFMFltNP1+eeh18WMXGZMtBkrk+E3P7 P2kFaQgAgG3VwcBQUE5NpvqZUDlzoKlvDGZxF7qQya7NmLbayLqgDLiDfKEiBdR09k/t TVwrD95vCsYrkLGCH2NPjSuJVIeL7qBSHkI40ETrr1GAoHUFxmp5x0k3YOZNxA5H1sIg 3rcQs5kec0hwrLpGXpn0Ol30WfesX8NxP4+KDEXK03VoK36Lg4w4lCPVu/bAmxca0+jQ EwdRBXocv47n45QSR/WdzzCSsc5LlAUh31AsaJ1vbXQT57jbQk6Jz6saPZRFTUseHdxU kgQw== X-Gm-Message-State: AJIora/l2FsOWAle36EMMr7huWFMuuVBwuOD5SwQTRWMrXtQGb1Gao/o yWoMncpxSL42HqvIuk0ibNklN+dAwHFTBg== X-Received: by 2002:a17:90b:2285:b0:1ec:aa3f:8dc1 with SMTP id kx5-20020a17090b228500b001ecaa3f8dc1mr4542280pjb.145.1656392059912; Mon, 27 Jun 2022 21:54:19 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 05/60] accel/stubs: Add tcg stub for probe_access_flags Date: Tue, 28 Jun 2022 10:23:08 +0530 Message-Id: <20220628045403.508716-6-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102f; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- accel/stubs/tcg-stub.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/accel/stubs/tcg-stub.c b/accel/stubs/tcg-stub.c index ea4a0dd2fb..6ce8a34228 100644 --- a/accel/stubs/tcg-stub.c +++ b/accel/stubs/tcg-stub.c @@ -21,6 +21,13 @@ void tlb_set_dirty(CPUState *cpu, target_ulong vaddr) { } +int probe_access_flags(CPUArchState *env, target_ulong addr, + MMUAccessType access_type, int mmu_idx, + bool nonfault, void **phost, uintptr_t retaddr) +{ + g_assert_not_reached(); +} + void *probe_access(CPUArchState *env, target_ulong addr, int size, MMUAccessType access_type, int mmu_idx, uintptr_t retaddr) { From patchwork Tue Jun 28 04:53:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585508 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp454793mab; Mon, 27 Jun 2022 22:58:55 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sYgx0JcrXT7nWXPZ7eP4FWK9tZfN1Y4ijnBXnYg3okNl7zK6zP2enguwIxiCsXuTXn9UD/ X-Received: by 2002:a05:620a:46a3:b0:6a6:e7a3:2cc7 with SMTP id bq35-20020a05620a46a300b006a6e7a32cc7mr10338710qkb.80.1656395935104; Mon, 27 Jun 2022 22:58:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395935; cv=none; d=google.com; s=arc-20160816; b=a5hLcEU7GEKXq4lo0V37Fxy8rgAun4HU0z5dXtfsMJE8tOwUk3STDlh2kVDZIXBX+y ePowvI5F8rs/GiKbKiKzjS9tbcHnyHW7eUU95BcxgUqF+vXApuNA7+JfIRQiPbZmRvp9 KFz4RjsFp9TxCysFW3IZkwfrvFEuq9ob5sLsp1tpPwdbimU2q76ztaaxQdSy+j85Wk7f OkFsEWte8wB/Mv2yBslzZI9hhGUHFWnkhhWCuB8mJCZVr6jBMEdR6eNTqSHXpPPqk2Mw OEpkr952B0wKwPpHnKfh1bCbqr/NQ/yp8EekFXuCgPdzcdcyhAz+ASkXl6iyCIag5kcS bsVg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=dSN4eb1Twe2zHNIOJc68yIeqf1dnavxtHZlfI889mCAz35l/WXHpJrm+cEA8gipirY U5P0dDopjj/o9XbbCM+G+WdiKQKJ7NFptmUXv7YEkkZ4qJKbc+GSw5woQcpvSnuGH9H+ NkkcAYN/ITNcjz/iu/Q/5gOMEwAKon1mV33iSNm42WYxC2xpYklBOhHtFMYPx0se4a6C 0dy5I5sY1QBUXo7MP50GojY9JNiIe7t6T64scob5J4UqGaNVFm3Dcwc39x9/zp2Bs5Og PHkE5unoyUvqY5H4aWCvntgt8ntT/gJll/Z6BDNSbUzpAdA6rClpwzC24yT5TZZJZzQG POdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=klzn4Mv4; 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=pass (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 az43-20020a05620a172b00b006af46175023si1552504qkb.654.2022.06.27.22.58.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:58:55 -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=pass header.i=@linaro.org header.s=google header.b=klzn4Mv4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44836 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64FS-0001Ya-DN for patch@linaro.org; Tue, 28 Jun 2022 01:58:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43082) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63F3-0002Jb-Gx for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:25 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:41695) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63F1-0008IZ-EF for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:24 -0400 Received: by mail-pg1-x52f.google.com with SMTP id 23so11058486pgc.8 for ; Mon, 27 Jun 2022 21:54:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=klzn4Mv43gJL6TxdLCxg6gbINvGlfcE3+9h1sQ9wuSeZv1JHa80ZIdtqN/2lIyJL3F ZN7k96iXz2rJ9XXGoFgTguWT5G9UPEn3QZc9PjwrMDr/DNjIx5sGt5+Bd9FqTiaDCX0H +bLapgOMzHLaT9Sd9Uq6VKzZSDL4IAY4aHfqtwHyJW52HIpbLfZ1Fedh0XEj4kNLUOJn 9kSgrG/gKEoN0dq8w1569yrkZQBe0C6xqLByICgj8XxwnOa4fRdH5IQxvb2kIikdE9BZ DDC2KSKB+jS5DY6/5Fe51HwZfSciQczakkg7dRbRIQJbNkBO/8uRNvMnvzXoEQEuxTsk deLQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=RK5M0Iz9OI0w9+qLU0kfHIVs85xFEebhwh/ygRwPj/8=; b=pxQIGm4xy5DsOiuHPVppGx2fuLmF1dZpeUMMjNRoCwkPTB9MKOgTqVlbgLCN7hejFx v9VZ6KLuEHsK6NSPQ/nUpdj6kWetftYuCDizQ/vfJ1vOsK3R9NIf9ZrnmZL7/aZFFNev PMsoe+umGMvBoPloH2DVHZJ+RQ13xa51cVf8LeXoN8ZQSSsntocABcztrViEFvM6tPIM xbLEcA/EGfnkHHpMszgiY+wz0xNzpiaqRnK2C5Ih5jk0R2t5/kMruR6e05B2MmmRiQfw rWP37vIZTcslyZPK9rQI+SectrqLR4KLr69VICKr1sgaRFIDI2BiFvWg0VU9Oghqhf3C 1MaA== X-Gm-Message-State: AJIora8bGS53atArUtuaqzdZII+a0xJHyxP+1xdzjgFCJ6aRM13e2b8K +B61wyuBDBNtCen5cav7XZNzm1ZzvVMr8Q== X-Received: by 2002:a05:6a00:893:b0:51e:77ab:8874 with SMTP id q19-20020a056a00089300b0051e77ab8874mr2692434pfj.21.1656392062081; Mon, 27 Jun 2022 21:54:22 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 06/60] semihosting: Add target_strlen for softmmu-uaccess.h Date: Tue, 28 Jun 2022 10:23:09 +0530 Message-Id: <20220628045403.508716-7-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52f; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Mirror the interface of the user-only function of the same name. Use probe_access_flags for the common case of ram, and cpu_memory_rw_debug for the uncommon case of mmio. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- v3: Use probe_access_flags (pmm) --- include/semihosting/softmmu-uaccess.h | 3 ++ semihosting/uaccess.c | 49 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/include/semihosting/softmmu-uaccess.h b/include/semihosting/softmmu-uaccess.h index 03300376d3..4f08dfc098 100644 --- a/include/semihosting/softmmu-uaccess.h +++ b/include/semihosting/softmmu-uaccess.h @@ -53,4 +53,7 @@ void softmmu_unlock_user(CPUArchState *env, void *p, target_ulong addr, target_ulong len); #define unlock_user(s, args, len) softmmu_unlock_user(env, s, args, len) +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr); +#define target_strlen(p) softmmu_strlen_user(env, p) + #endif /* SEMIHOSTING_SOFTMMU_UACCESS_H */ diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 0d3b32b75d..d6997e3c65 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -8,6 +8,7 @@ */ #include "qemu/osdep.h" +#include "exec/exec-all.h" #include "semihosting/softmmu-uaccess.h" void *softmmu_lock_user(CPUArchState *env, target_ulong addr, @@ -23,6 +24,54 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + int mmu_idx = cpu_mmu_index(env, false); + size_t len = 0; + + while (1) { + size_t left_in_page; + int flags; + void *h; + + /* Find the number of bytes remaining in the page. */ + left_in_page = TARGET_PAGE_SIZE - (addr & ~TARGET_PAGE_MASK); + + flags = probe_access_flags(env, addr, MMU_DATA_LOAD, + mmu_idx, true, &h, 0); + if (flags & TLB_INVALID_MASK) { + return -1; + } + if (flags & TLB_MMIO) { + do { + uint8_t c; + if (cpu_memory_rw_debug(env_cpu(env), addr, &c, 1, 0)) { + return -1; + } + if (c == 0) { + return len; + } + addr++; + len++; + if (len > INT32_MAX) { + return -1; + } + } while (--left_in_page != 0); + } else { + char *p = memchr(h, 0, left_in_page); + if (p) { + len += p - (char *)h; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + addr += left_in_page; + len += left_in_page; + if (len > INT32_MAX) { + return -1; + } + } + } +} + char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { /* TODO: Make this something that isn't fixed size. */ From patchwork Tue Jun 28 04:53:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585537 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp497943mab; Tue, 28 Jun 2022 00:09:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vO76GUDJ90JAU1QpEtZ6kSUWo18HcYkcqSR9eToJYPrNIWBfqw+HMPJgD8T5Gk1nh6Gbx8 X-Received: by 2002:a37:446:0:b0:6ae:dab1:c4f6 with SMTP id 67-20020a370446000000b006aedab1c4f6mr10520946qke.753.1656400162960; Tue, 28 Jun 2022 00:09:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400162; cv=none; d=google.com; s=arc-20160816; b=ugTsETaCG3BefQd7BZm0ojtVEki/N38ljiCP99pHjnmn2hw0GUjP8ZGgW8KhAVYu3y k+rIuCkKEsYA/8R3w3046FzH0iEfWHTcLRxdeFke+1JGGObG4r8eYiAC4VQZfP/dV7CP ybMdhx8iR9wYyGWftAfE5318ugFeHcD4Ml5JVdzHr/8y+LvwSSSkv645KIbvF3xfZOBS IXPwCYHavMJli7rV5TQFkkjUQjz/A3WpGPGV2AM2Nn7SQhUBh2GJluljA6HbN+ekRnZR Fg+LomtBfeleRjNOwaQRUraX5UfoWtyxjmn0UiEDRXR7DJMttRilkejhHTwoLiDH8LW6 ihCw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=mnyz4RGMr9davoKlXgtFTdnnm6cHsKuNwuwlINalmn0=; b=v+OlR4XqRrb9SPbknOhQudD8r4tXr+XDYiQ1+PiI2rZaF065MxNQUOIsC+LQYraO/2 +edrlNJINg1yG97xkzQRm/gOsKyhQr3BNMRNb6HD/4aLxRkRx52J3jH+jfCVmavCP2Xx B3yP7AxUj47Tsoc5KD8W8YvY4c/Kx5uvTrd5/wEYvFTKCsMdTJ3W/0X1G6TKOv0d0lPV 4wwRErBi/stumGM6EwCX/wmx+4X6Em0acxudKc6h0cY2Wtf6qkjo5FGLXa1DeBLZZSo4 B+/Lwqaoi07GNKNSBnXBD5ecn3rfrouNXXyvfGQDOidXgqH1jM3RGVR7MKd5ch7ZH4qa 9N9g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=H6JhjGgU; 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=pass (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 w14-20020a05622a190e00b00304c02e45ebsi7195806qtc.356.2022.06.28.00.09.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:09:22 -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=pass header.i=@linaro.org header.s=google header.b=H6JhjGgU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:45294 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Le-0006r4-Dt for patch@linaro.org; Tue, 28 Jun 2022 03:09:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63F5-0002Lm-If for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:27 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:53002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63F3-0008Is-QM for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:27 -0400 Received: by mail-pj1-x102a.google.com with SMTP id g7so6378232pjj.2 for ; Mon, 27 Jun 2022 21:54:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=mnyz4RGMr9davoKlXgtFTdnnm6cHsKuNwuwlINalmn0=; b=H6JhjGgUAEzlI0amOJ4rxtH1w1wZeKsl8HQVy4ZB1r63+EJtEheRrzR17UZCPZ4aSe Ch5OgmsP6xafoc6d480BpDQuW43U13+dbaaeVWRkRjsMFvJ2knbaDXFmdZP9AmcqsKqu HfPagvQHyRpzFRsgIiSFNRWfifWhd+tO87rsn092Vjktj+pzJrQmwV84DfQIaZkJtoOF fiwy8VZWApiKe8pBdjHe4sgp/v4qRdk+UBe+yw2Q0/zeuYN0CCwuz7DPXiGSuC5DNJY4 pCyzfaWr8tnwiJ1Q1VaaiH+z2Ij8632dUTdQmA9e0UVCTA7tk5yQz2iUeAfgFHvfFSPH GEPQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=mnyz4RGMr9davoKlXgtFTdnnm6cHsKuNwuwlINalmn0=; b=d0AX1WlrcL2SHregalCP5UsSE31zUNW5pL/nGm0QBUEBFtoJsC/2W+ShLe2zTYwNG3 2HYeLuZedMndBxCEOgpe/ANA1lWR6Lm4M0D1p6dwzzFduWvle6Gr2c109t7ZsrnAbsJf vWmXkIDQMuP1PEftFN9NJZpGXUZ6JpXyAHiSqzTTTXIPXmbKAmmZlzuU739PrE1hABNO yrXYWReRmnB+H7iNrVX7ypBbR5hvSk1avYWpial650FRVOgHScBsoUb27eo++iS/va5O CgBUAhW5mjJQe08D8blEQOhLscfDWiBV2dlFKavHL7njc8mtaJRVr/nZaB/6c7ELLq80 wBdg== X-Gm-Message-State: AJIora+Mw2boHeOKtR9p4sv+MjGuoDO1M8L/kyhPt4dKuxCrIIppKCJp 8Vp+o6oYpd8mv5Lhsi9Hy5Ot4Qq+hb49EA== X-Received: by 2002:a17:902:860b:b0:16b:7927:b62c with SMTP id f11-20020a170902860b00b0016b7927b62cmr3071500plo.95.1656392064516; Mon, 27 Jun 2022 21:54:24 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 07/60] semihosting: Simplify softmmu_lock_user_string Date: Tue, 28 Jun 2022 10:23:10 +0530 Message-Id: <20220628045403.508716-8-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We are not currently bounding the search to the 1024 bytes that we allocated, possibly overrunning the buffer. Use softmmu_strlen_user to find the length and allocate the correct size from the beginning. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/uaccess.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index d6997e3c65..8018828069 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -74,20 +74,11 @@ ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) char *softmmu_lock_user_string(CPUArchState *env, target_ulong addr) { - /* TODO: Make this something that isn't fixed size. */ - char *s = malloc(1024); - size_t len = 0; - - if (!s) { + ssize_t len = softmmu_strlen_user(env, addr); + if (len < 0) { return NULL; } - do { - if (cpu_memory_rw_debug(env_cpu(env), addr++, s + len, 1, 0)) { - free(s); - return NULL; - } - } while (s[len++]); - return s; + return softmmu_lock_user(env, addr, len + 1, true); } void softmmu_unlock_user(CPUArchState *env, void *p, From patchwork Tue Jun 28 04:53:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585540 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp502819mab; Tue, 28 Jun 2022 00:17:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sOxyxqLuwGRtghoRQxcIuEmbasl/kf1yfs3EF8F1YE2Nt4T2iX2TwHmsx8X1bp9gTkUaYN X-Received: by 2002:ad4:48d4:0:b0:470:4483:4bd5 with SMTP id v20-20020ad448d4000000b0047044834bd5mr2484963qvx.96.1656400663240; Tue, 28 Jun 2022 00:17:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400663; cv=none; d=google.com; s=arc-20160816; b=p8XcAKuzKLXSwFfv7wyiRw396dLY6KYpluIO8TsKHybtZv/bN7oPFiVewXcZ+KPwvd ljLaXgUN28WB46bABBjWTwku7qJavIPlh5iEVECeIK1uSUzbjxwmwJItKQPvgJsJBOSv 3eQD4ObYoiypwUoCL2/ZLe64rjN/K47pQOoYoY7xaXfKAOIVxZo3C801b4QvzVIAHCBa x8QHi+AV/Is6Zvg2Fo1VaVl28VXpHLntS9zy27Pm16+8/aNHpOb9cHW7M06kTLicfTZL v+lIWdSRetDzAK9TGmU0wlC264LIiM7NkZTzP34j3mY5QWxKMVje3J0AkiFysMZKk1pF asqw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=ZpNeXR+riLFDBFgPlcWD2eatfpq6x/LtbRlobcViT8U=; b=tsHdqQUZ0ISsEYJdoDnVnTqOXOOnwlvnhN+HSVEQgSjpb+hmtZ0gEISlRotsbFQ8Wm somqs2U8rVb16VT6v53kdd+mNtyJ8+MlR2/crk7I2dDDTOTgHAvXiUilSmZ+Hy/RkxWI 6of2YlgXxYvc5YryxKi9XxZYepM00jm7FM6x6NRhM15o+cwVrZwzPiSukKm0C24VCI2S 7H8ZDbgFTwbiMFdgqceLEpzgGsqOVa/bfnumgIe6wd+2/XmrRlLRshUMqRI5XVvpBu44 hulvPhnFtaaoUwdGwY3Ft01PwLQPi4UukCOfDzIKifIpsx4LiiQJhfsEmr23TkMtKOO+ TzKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eIyynwEY; 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=pass (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 jf11-20020a0562142a4b00b004703c662ee3si7566388qvb.373.2022.06.28.00.17.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:17:43 -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=pass header.i=@linaro.org header.s=google header.b=eIyynwEY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54704 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Ti-00057q-OL for patch@linaro.org; Tue, 28 Jun 2022 03:17:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63F9-0002Ye-Ul for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:31 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:37550) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63F7-0008JM-29 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:31 -0400 Received: by mail-pl1-x636.google.com with SMTP id k14so10038759plh.4 for ; Mon, 27 Jun 2022 21:54:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZpNeXR+riLFDBFgPlcWD2eatfpq6x/LtbRlobcViT8U=; b=eIyynwEYf+zAYlBqq3YD3ntHYjLFB3MwZtlSnuIXz0oKUT+/Qn+27dpEoQ28yiQGc8 FXh5a4zDXfLw/tsBeBDDfKEdU5Kmx2IRYjzQ9WuZewMB9P7OpKU4Okxkr4Xkxccq8Qy8 +F/tiWdTee5a2bZnKIFE182nd1IRIqRKhdrfmRT3kQ/AIzsE+wbgLn1D1+dpPeSLi0pj K4c83hMaw2z/E7ZoD+jyyUIE1zJ1QYxUtNNFSFcxNjBgOJeUlnABgRqRh1ntagSoO/t2 s2wE6xhBCSv/bbORUOBFfPWQoecsxPphrb/ZXfdL6njNY01nhmTtIhfiRq22F9X1MrwD hKaA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZpNeXR+riLFDBFgPlcWD2eatfpq6x/LtbRlobcViT8U=; b=34XLkyhS78Gw/A6Sk/m4purWRBCMJQZrURKH5cHR3lbLTm7HZzSZRd42BwUQ1ZJpBL SkHkSqS7K75k8o90o2btCSqbSRzeuGqBY8jT53a9SPWHOhul/kYmFmxONqbdJOTija1u O9L9r1vjWHrGwjfvQAkyB07f4rU82UACwPttAsYdEhc9Kz0YVk1jKzhtJHJNjj4vW+pd wJEwbBq3/heVSNy+plcfw9oRoO934wX5Hyv5ljGenvicZXS+mjbVHop0yIWaHdttQosY +FDXemDCxTY9EFPxHW0o7FbD7lwgEgiIbw/a6MhB/WGMSOZrqxlc3oGvEa4o+U1VqVtx HdGw== X-Gm-Message-State: AJIora8AOK8CDv1RG8OLmuJF34aGxx9h64Lz15W5pkD2pYA483VuDm+K 9BMzt9OGAFkODk0xW4s9+czucyz5JooUUA== X-Received: by 2002:a17:903:249:b0:168:ecca:43e with SMTP id j9-20020a170903024900b00168ecca043emr1783181plh.14.1656392067554; Mon, 27 Jun 2022 21:54:27 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 08/60] semihosting: Split out guestfd.c Date: Tue, 28 Jun 2022 10:23:11 +0530 Message-Id: <20220628045403.508716-9-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::636; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x636.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" In arm-compat-semi.c, we have more advanced treatment of guest file descriptors than we do in other implementations. Split out GuestFD and related functions to a new file so that they can be shared. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- configs/targets/aarch64-linux-user.mak | 1 + configs/targets/aarch64_be-linux-user.mak | 1 + configs/targets/arm-linux-user.mak | 1 + configs/targets/armeb-linux-user.mak | 1 + configs/targets/riscv32-linux-user.mak | 1 + configs/targets/riscv64-linux-user.mak | 1 + include/semihosting/guestfd.h | 83 +++++++++++ semihosting/arm-compat-semi.c | 164 +++------------------- semihosting/guestfd.c | 118 ++++++++++++++++ semihosting/meson.build | 4 + 10 files changed, 233 insertions(+), 142 deletions(-) create mode 100644 include/semihosting/guestfd.h create mode 100644 semihosting/guestfd.c diff --git a/configs/targets/aarch64-linux-user.mak b/configs/targets/aarch64-linux-user.mak index d0c603c54e..db552f1839 100644 --- a/configs/targets/aarch64-linux-user.mak +++ b/configs/targets/aarch64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=aarch64 TARGET_BASE_ARCH=arm TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/aarch64_be-linux-user.mak b/configs/targets/aarch64_be-linux-user.mak index 7794424745..dc78044fb1 100644 --- a/configs/targets/aarch64_be-linux-user.mak +++ b/configs/targets/aarch64_be-linux-user.mak @@ -3,4 +3,5 @@ TARGET_BASE_ARCH=arm TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/aarch64-core.xml gdb-xml/aarch64-fpu.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/arm-linux-user.mak b/configs/targets/arm-linux-user.mak index 3e10d6b15d..7f5d65794c 100644 --- a/configs/targets/arm-linux-user.mak +++ b/configs/targets/arm-linux-user.mak @@ -3,4 +3,5 @@ TARGET_SYSTBL_ABI=common,oabi TARGET_SYSTBL=syscall.tbl TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/armeb-linux-user.mak b/configs/targets/armeb-linux-user.mak index a249cc2e29..943d0d87bf 100644 --- a/configs/targets/armeb-linux-user.mak +++ b/configs/targets/armeb-linux-user.mak @@ -4,4 +4,5 @@ TARGET_SYSTBL=syscall.tbl TARGET_BIG_ENDIAN=y TARGET_XML_FILES= gdb-xml/arm-core.xml gdb-xml/arm-vfp.xml gdb-xml/arm-vfp3.xml gdb-xml/arm-vfp-sysregs.xml gdb-xml/arm-neon.xml gdb-xml/arm-m-profile.xml gdb-xml/arm-m-profile-mve.xml TARGET_HAS_BFLT=y +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv32-linux-user.mak b/configs/targets/riscv32-linux-user.mak index bd2f1fd497..9761618e67 100644 --- a/configs/targets/riscv32-linux-user.mak +++ b/configs/targets/riscv32-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv32 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-32bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-32bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/configs/targets/riscv64-linux-user.mak b/configs/targets/riscv64-linux-user.mak index 4aca7662ce..cfd1fd382f 100644 --- a/configs/targets/riscv64-linux-user.mak +++ b/configs/targets/riscv64-linux-user.mak @@ -2,4 +2,5 @@ TARGET_ARCH=riscv64 TARGET_BASE_ARCH=riscv TARGET_ABI_DIR=riscv TARGET_XML_FILES= gdb-xml/riscv-64bit-cpu.xml gdb-xml/riscv-32bit-fpu.xml gdb-xml/riscv-64bit-fpu.xml gdb-xml/riscv-64bit-virtual.xml +CONFIG_SEMIHOSTING=y CONFIG_ARM_COMPATIBLE_SEMIHOSTING=y diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h new file mode 100644 index 0000000000..ef268abe85 --- /dev/null +++ b/include/semihosting/guestfd.h @@ -0,0 +1,83 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_GUESTFD_H +#define SEMIHOSTING_GUESTFD_H + +typedef enum GuestFDType { + GuestFDUnused = 0, + GuestFDHost = 1, + GuestFDGDB = 2, + GuestFDStatic = 3, +} GuestFDType; + +/* + * Guest file descriptors are integer indexes into an array of + * these structures (we will dynamically resize as necessary). + */ +typedef struct GuestFD { + GuestFDType type; + union { + int hostfd; + struct { + const uint8_t *data; + size_t len; + size_t off; + } staticfile; + }; +} GuestFD; + +/** + * alloc_guestfd: + * + * Allocate an unused GuestFD index. The associated guestfd index + * will still be GuestFDUnused until it is initialized. + */ +int alloc_guestfd(void); + +/** + * dealloc_guestfd: + * @guestfd: GuestFD index + * + * Deallocate a GuestFD index. The associated GuestFD structure + * will be recycled for a subsequent allocation. + */ +void dealloc_guestfd(int guestfd); + +/** + * get_guestfd: + * @guestfd: GuestFD index + * + * Return the GuestFD structure associated with an initialized @guestfd, + * or NULL if it has not been allocated, or hasn't been initialized. + */ +GuestFD *get_guestfd(int guestfd); + +/** + * associate_guestfd: + * @guestfd: GuestFD index + * @hostfd: host file descriptor + * + * Initialize the GuestFD for @guestfd to GuestFDHost using @hostfd. + */ +void associate_guestfd(int guestfd, int hostfd); + +/** + * staticfile_guestfd: + * @guestfd: GuestFD index + * @data: data to be read + * @len: length of @data + * + * Initialize the GuestFD for @guestfd to GuestFDStatic. + * The @len bytes at @data will be returned to the guest on reads. + */ +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len); + +#endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 1033e751ef..2fa7f23d8b 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -32,12 +32,13 @@ */ #include "qemu/osdep.h" - #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" +#include "semihosting/guestfd.h" #include "qemu/timer.h" #include "exec/gdbstub.h" + #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -123,27 +124,6 @@ static int open_modeflags[12] = { O_RDWR | O_CREAT | O_APPEND | O_BINARY }; -typedef enum GuestFDType { - GuestFDUnused = 0, - GuestFDHost = 1, - GuestFDGDB = 2, - GuestFDFeatureFile = 3, -} GuestFDType; - -/* - * Guest file descriptors are integer indexes into an array of - * these structures (we will dynamically resize as necessary). - */ -typedef struct GuestFD { - GuestFDType type; - union { - int hostfd; - target_ulong featurefile_offset; - }; -} GuestFD; - -static GArray *guestfd_array; - #ifndef CONFIG_USER_ONLY /** @@ -268,98 +248,6 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) #endif -/* - * 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)); - } - - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ - for (i = 1; 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/gdb fd. - */ -static void associate_guestfd(int guestfd, int hostfd) -{ - GuestFD *gf = do_get_guestfd(guestfd); - - assert(gf); - gf->type = use_gdb_syscalls() ? GuestFDGDB : 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; -} - /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -665,22 +553,13 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* 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(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } -static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ @@ -689,7 +568,7 @@ static uint32_t featurefile_writefn(CPUState *cs, GuestFD *gf, return set_swi_errno(cs, -1); } -static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; @@ -703,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, } for (i = 0; i < len; i++) { - if (gf->featurefile_offset >= sizeof(featurefile_data)) { + if (gf->staticfile.off >= gf->staticfile.len) { break; } - s[i] = featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } unlock_user(s, buf, len); @@ -716,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, GuestFD *gf, return len - i; } -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset = offset; + gf->staticfile.off = offset; return 0; } -static uint32_t featurefile_flenfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return sizeof(featurefile_data); + return gf->staticfile.len; } typedef struct GuestFDFunctions { @@ -759,13 +638,13 @@ 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, + [GuestFDStatic] = { + .closefn = staticfile_closefn, + .writefn = staticfile_writefn, + .readfn = staticfile_readfn, + .isattyfn = staticfile_isattyfn, + .seekfn = staticfile_seekfn, + .flenfn = staticfile_flenfn, }, }; @@ -886,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno = EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c new file mode 100644 index 0000000000..b6405f5663 --- /dev/null +++ b/semihosting/guestfd.c @@ -0,0 +1,118 @@ +/* + * Hosted file support for semihosting syscalls. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" + +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. + */ +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)); + } + + /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ + for (i = 1; 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); +} + +/* + * 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. + */ +GuestFD *get_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + if (!gf || gf->type == GuestFDUnused) { + return NULL; + } + return gf; +} + +/* + * Associate the specified guest fd (which must have been + * allocated via alloc_fd() and not previously used) with + * the specified host/gdb fd. + */ +void associate_guestfd(int guestfd, int hostfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = use_gdb_syscalls() ? GuestFDGDB : GuestFDHost; + gf->hostfd = hostfd; +} + +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDStatic; + gf->staticfile.data = data; + gf->staticfile.len = len; + gf->staticfile.off = 0; +} + +/* + * Deallocate the specified guest file descriptor. This doesn't + * close the host fd, it merely undoes the work of alloc_fd(). + */ +void dealloc_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDUnused; +} diff --git a/semihosting/meson.build b/semihosting/meson.build index 10b3b99921..d2c1c37bfd 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,3 +1,7 @@ +specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( + 'guestfd.c', +)) + specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( 'config.c', 'console.c', From patchwork Tue Jun 28 04:53:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585507 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp453940mab; Mon, 27 Jun 2022 22:57:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vHhkLBBZQ7QkJvp2wuB7mS2FoibVFHakJDdoosXTz4TMfzNCXrkZ0Zp5O3qScdyfr2kHHP X-Received: by 2002:a05:6214:21e5:b0:470:a6cf:b023 with SMTP id p5-20020a05621421e500b00470a6cfb023mr1034077qvj.36.1656395834179; Mon, 27 Jun 2022 22:57:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395834; cv=none; d=google.com; s=arc-20160816; b=hKOcVGMPSzBHilCjJzjO8E4OYc9dUOcSGL/hkxQ8Uji79uo/6UBOd1NlOpa80Y06rg YvB3SC0nheSIY664VlZbf2vvsHTznv8TiVt8hU4OUMzKayFuj1DsW2L8Ie0cePLEMy7O I6ALsUOfGujm8qdunMyhiE/iN+lD61DgnOYb+AODAp/Oj6AbpptA0KZiURs2oAXubIDR /vGtT3RKiqDcDTyHHO/VmVk2KRALXxo243mC4sg57uFePQAmeKH3DGIX0SKs1EM5ochJ UGp9COQ+y2bC1sZuL/QYm/qDUhK+woOoXrJkLeHJvZpiEHo9rvSz7IA3A/RRhDbC85qb Mlug== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=POGsKDtk5VyDw6taq7a+DFAfnB+E161joQzVuaaJQNU=; b=CQCjn1G+EkBokpw1CRudqozs/CoAYd1eSW/j5zoDaL11vfAn9KjLv+HrHNYltZYoko oYcg/yNyzNbQjirV7TO96YDqvGdzZMftjqhHHTKLevbqM3Z8TLtKBmkWSd645NYs5Jw1 T7HkZrns0m54zbWrpIiuf1MkvM8k/sV1zpD+tZghjZKHSoeWDXk8bhfmTxzd6uPYfNcQ maTXzCk0HW+u6GYi4HGsbazJNXxb7eG5XjMUkh5DwBVHatFfna9+cUAI4+xPkC3Yoku7 76nZAx6zqg8IZBvbvrCIKh1LP8WEspkQcKxIuh5weEKDsmznsQv6i7WwV/UxiBSBBnil /Rbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=qr3nZNPV; 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=pass (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 q6-20020a056214194600b0047078edea9esi7193812qvk.561.2022.06.27.22.57.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:57:14 -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=pass header.i=@linaro.org header.s=google header.b=qr3nZNPV; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Dp-0006lx-MF for patch@linaro.org; Tue, 28 Jun 2022 01:57:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43154) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FA-0002bG-S6 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:32 -0400 Received: from mail-pg1-x531.google.com ([2607:f8b0:4864:20::531]:36372) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63F9-0008JT-1P for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:32 -0400 Received: by mail-pg1-x531.google.com with SMTP id s206so2071883pgs.3 for ; Mon, 27 Jun 2022 21:54:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=POGsKDtk5VyDw6taq7a+DFAfnB+E161joQzVuaaJQNU=; b=qr3nZNPV+gT+RDcFuHjFYXlusBpL67vTfmVw0cWvM7lDevygg5+IWRXIYtvVlTeZVP 4oaox/3pj8dfYUGXFq+3Mkc5GaTUIbgmYzCu9tSmoYwSVmOOupjGEwDK5WwcLFB5PxHt ADZeMsdrcKy9H+CNOwhdwmQ9zykrxo8Zrx2+WbLigEvXXgzQh0JYjgiOm5ZmT2QmZAe9 8NAUd26fh/HDQcvyaLnGR5WR2ipDSjphmxFYTk9dkmcujUi210j/W73GhIEqbkIM/5dU yChE/O9WjYRjLTQVLPgc1iPs76Spa7Z+rD2TMtpwYpzUWtsKjPQUnvW6g8kR8VRZhcdf eVxw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=POGsKDtk5VyDw6taq7a+DFAfnB+E161joQzVuaaJQNU=; b=STF+f82h+XUvf03c8exTgvzgNjea0dK+GjfEEgImYTe9G4c9j5kB4mMZzRgmiAZSeE r+KlzdCEZN4foD5gMb+ysJqZNxPd2gRk4JTMssXbtIeJBdJrczCMkt2Y84g9LImnMiG0 Xkx+omoD5rA/HIRzhLTJhy+NjJeX+Yyuj1FmKxfzdyJ5SCkzsTBD+NbtMJl5tel6KBty iF2paFyEplRXxcsaKYiHlM0OqZ+pRa47hBQQve+XlcMZQ5/+L7lw9Wt21QB5W2OfPQrY LFogj9Ir2phI2jPzxcZ69lftVG7jiNYUasylTSZeyWWZgCWFncXw4niKQ/UzHMtvDVi+ UJbw== X-Gm-Message-State: AJIora9KBusHuUmWdmfLSc9+FHBDQuhDa3rxjVoVzy5NYOgLJTgYkOr1 cSQGjwU79SgWnF/jJGFBBSRCKhbjxJdgMA== X-Received: by 2002:a65:4907:0:b0:3fd:bc3e:fb0a with SMTP id p7-20020a654907000000b003fdbc3efb0amr15347689pgs.123.1656392069707; Mon, 27 Jun 2022 21:54:29 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 09/60] semihosting: Inline set_swi_errno into common_semi_cb Date: Tue, 28 Jun 2022 10:23:12 +0530 Message-Id: <20220628045403.508716-10-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::531; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x531.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Do not store 'err' into errno only to read it back immediately. Use 'ret' for the return value, not 'reg0'. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 2fa7f23d8b..9d1f13ea8b 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,28 +290,29 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - target_ulong reg0 = common_semi_arg(cs, 0); - if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); - reg0 = ret; +#ifdef CONFIG_USER_ONLY + TaskState *ts = cs->opaque; + ts->swi_errno = err; +#else + syscall_err = err; +#endif } else { /* Fixup syscalls that use nonstardard return conventions. */ + target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: case TARGET_SYS_READ: - reg0 = common_semi_syscall_len - ret; + ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: - reg0 = 0; + ret = 0; break; default: - reg0 = ret; break; } } - common_semi_set_ret(cs, reg0); + common_semi_set_ret(cs, ret); } static target_ulong common_semi_flen_buf(CPUState *cs) From patchwork Tue Jun 28 04:53:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585506 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp453553mab; Mon, 27 Jun 2022 22:56:22 -0700 (PDT) X-Google-Smtp-Source: AGRyM1s8K/WTEJVfYDNQhlvSl1t0Pf9olDfunNsQkYHbt3BxyJfcVFtpvgxIcgsn1A09r43qU0cy X-Received: by 2002:a05:622a:1486:b0:317:fe76:737d with SMTP id t6-20020a05622a148600b00317fe76737dmr12196064qtx.547.1656395782324; Mon, 27 Jun 2022 22:56:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656395782; cv=none; d=google.com; s=arc-20160816; b=X7MAT3Ylk7TsI28fucRiSZgw9G8G2chh0xkINnQDddX3n0Qd04ZV2Yp/2Ebhz6x2+d 3bJR4gKYDWvXiXKlqqUvvUw/3QYd8lHJqUAD51vVJInI4Z5Yowz/RC05VcpQHWv66CYh Nrpbx7I8AxftjEbAGfsNu8QpDLPaTz4dW6V3GlehogsonNNl05JFHDkjjX2ff/JxgAMz bk9JCcZXrq6I/pG4xDupDS/BsuEJp1q8kUAVSi4gefwtF9Ku8dkRveDl2AXapVU9gyEP sn4ZNeqMz7x8NBxifagMh0H/lOVXWvBPPD0Pu8k2lw7ySwErLNlSUFJqeVbPTFE+rtpI ZB7Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=3TB52VZeYKmQPEU6Mg2AiRo2hCWAnODIZkda7yxBiTA=; b=DReZObBxyXNVur89N1148rchY04byz5k2TGdthsed2Bvcj1BSX6VoDXzRVQbLDTriG Ax90A3bSuzBweU85RDp1ZNHzD1Fa8xcCbqIV81/dDwZ8N328bNUrEh9xe3D+OQcOWYtk i1iophmYfO3iaSPlAyufiL3r+cbvWCGRRUuWD7+bqtkAsJxaKBCJmaAngNbHzdxXL+2j 5CN0UZAHNvqjWu8GnMcUAUfRa9lvYEa3JfB85zSmPGqL1j+NQZwq5V7L+aszgK/pKLII H+C3V60RIlo0XFPuy/QZ4wUIJ/VF2QtoPkd7VLq3J9yhCZTg96fAULJ2lGh3u2HkfeS2 1fZg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=aKzIKpew; 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=pass (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 127-20020a370685000000b006af6285f68esi105893qkg.327.2022.06.27.22.56.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 22:56:22 -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=pass header.i=@linaro.org header.s=google header.b=aKzIKpew; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39638 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Cy-0006MM-BL for patch@linaro.org; Tue, 28 Jun 2022 01:56:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43170) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FE-0002iE-AN for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:36 -0400 Received: from mail-pf1-x42b.google.com ([2607:f8b0:4864:20::42b]:39754) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FB-0008Jf-QJ for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:36 -0400 Received: by mail-pf1-x42b.google.com with SMTP id p14so10944154pfh.6 for ; Mon, 27 Jun 2022 21:54:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3TB52VZeYKmQPEU6Mg2AiRo2hCWAnODIZkda7yxBiTA=; b=aKzIKpewPKPhdX0XxgkVhILt0Q475E7HjSjknS/5lJINuRoaXgTEhxZJjxbx16Vz51 i6Wx27Tz6wqbAlJWsX9F91p/pt4kAMyLmt/7EhWq+/QvDPYa/cU3qIEKT1Qv94sWk1p9 x9CzIk0hTvTcTUWtME4GMECv7enSZtXcZDL8fWRZVxr7oh3fgknBsVvjx6u6BotgQRNs /i725pXT5/sJ1tAgm+LVe2gbHCw5XTXeFKYBpdl4WHaOvKqo24lbE1TpxCVdmyCgdAni Yio+nHaqMplb17XTQDr7ywReNHZU8BGYuoE4YWrq9XyUA8JpirLunvcPZIpteU1B6pr2 7eZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=3TB52VZeYKmQPEU6Mg2AiRo2hCWAnODIZkda7yxBiTA=; b=AeyHxJFV9wxuIbEXDbz0YAk1CLvBoNpqsgCBplCP1J5WZxC10rivud4VeOCVsXFlh2 qSllTbwedQteEOY1hTvgq3knnbT6p3YsxHO1+l09prvpyFeLlP0YGyvBLgiW1B9al8Xh bdoPdXthN3enKgGHKQWEt4DkKczI2H9Jd1AUWvCOjgJoV7w2yFvvOEg/r9hn4JkhUHVZ cKDeB/dvAa5wZrHwB1ihiT8v7hPOFQcIE6lRRLpyAMLy/ww6hZIJo8fSaRTxcnunQmlH UQsgp8Vue6VDAFmj6W+U4lQWGx0jqvFdmMlyvgEWdQ0A6VmecPuh4ZAk2w25vM6z6D9c Dd5w== X-Gm-Message-State: AJIora+yrspxaM8yxtJ6BQRWz/eBYgk0xQoCE/R2rqXJgwuoW6HuV05D sKqMpYHAsL/pvjnuNTzxOWfWpElnwIEuDA== X-Received: by 2002:a63:68c4:0:b0:3fb:984f:6779 with SMTP id d187-20020a6368c4000000b003fb984f6779mr15789994pgc.444.1656392071894; Mon, 27 Jun 2022 21:54:31 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 10/60] semihosting: Adjust error checking in common_semi_cb Date: Tue, 28 Jun 2022 10:23:13 +0530 Message-Id: <20220628045403.508716-11-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42b; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 err parameter is non-zero if and only if an error occured. Use this instead of ret == -1 for determining if we need to update the saved errno. This fixes the errno setting of SYS_ISTTY, which returns 0 on error, not -1. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9d1f13ea8b..88d6bdeaf2 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,7 +290,7 @@ static target_ulong common_semi_syscall_len; static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { - if (ret == (target_ulong)-1) { + if (err) { #ifdef CONFIG_USER_ONLY TaskState *ts = cs->opaque; ts->swi_errno = err; From patchwork Tue Jun 28 04:53:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585543 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp506235mab; Tue, 28 Jun 2022 00:23:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGg6gtqD4+NH9M5SDJ4xoWta/KXAbhdJlXLrOb7M/6TsMXiOIv6w1Qp9nr1McUyDUQgS/+ X-Received: by 2002:a05:6214:16cf:b0:470:5178:ccc3 with SMTP id d15-20020a05621416cf00b004705178ccc3mr1172231qvz.13.1656401003788; Tue, 28 Jun 2022 00:23:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401003; cv=none; d=google.com; s=arc-20160816; b=lTtblRXJMEb1MM0AndZruQXTRK/U5TCxMtZjO0WFVHIjWK0M9Trrmlx/YF6q3xG2EX yUvKEhg4SA3X8hnhp25H6AIMoGOSU/+7yD+tQ+6STCR5ru4nopAGyPHRkRs0wU0/Ud5V RyNnBU+I9//wKXo5s5SH/bysQWMr+nt5LbmYU/yt3n9iELGOAmUrpRxABf5k0xldwU24 +5Bg4Z2Qbu3NttNIx8LfNlYtCOcaW7X/4iJyVjj9BMSS8U/xjl/psKMA5Q3aGQZ1dl5L YJPTXnfg+yuN33xP07v5c7amLPyym9GVrR3yY4L5hnHdcWV+vMV42c0jf7ZuDXtOJpYp KazA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S8Pjs5cOqk+oGTnK7FdV4C/Z/WLlWltx0dBsRwUkzCw=; b=tkiUoGJtFNM8KK0kYIhyWb7oSFwZJscLzTNYMEt1ag87XKz8jLmKG4cSsGOA2joqpO Y0sN3uXehOQ5P/iXMy042nWlCKCpyyEd8DRYW4wYZn9g5sMyS3zxyBgYxGScMc6GQywA bwBaLGSB8C7t9zZA73RkYbLdNka93iRjX+j8mCrVmc+CzD6WuHI7cKaWpf7Ba6dYKMen bvm3YhOKvpWaQjex8pfii7oS/FmgGkXLQz7vYvHm7TryIILVP1HspO0hbDH56dRZG7U8 z028M8G95xVo073+01JA6IbljZmWZHgEPZzg3yE4w93YOaRbBDmWLvbI0Lzo+NSjx1Lo /BTA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Nggt7Fqb; 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=pass (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 h11-20020ac85e0b000000b00317ac568363si7833997qtx.532.2022.06.28.00.23.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:23:23 -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=pass header.i=@linaro.org header.s=google header.b=Nggt7Fqb; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35722 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65ZD-0003AG-9Q for patch@linaro.org; Tue, 28 Jun 2022 03:23:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43194) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FG-0002nT-0x for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:38 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:33883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FE-0008Jt-BZ for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:37 -0400 Received: by mail-pj1-x102e.google.com with SMTP id a11-20020a17090acb8b00b001eca0041455so11321501pju.1 for ; Mon, 27 Jun 2022 21:54:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S8Pjs5cOqk+oGTnK7FdV4C/Z/WLlWltx0dBsRwUkzCw=; b=Nggt7FqbmwGySBd6EoF1AsxLfQWei/HVcjh6YuzAckI99FcmRmM38KF5OUjL/BLuQw 9lIjBp+r3fdx+bC2YLI8IultRc/35/VMBOUlZ5E6EdcE5X4gUbf1elbuWr3HTSitxGZN 4YiEJGU7dUK5PKkVpk5OWpniD0YNaio8lBEVe3tiQVCtqSgnNfwAV03FZr82Gojr/kw6 +YoIzXomFB8yqSi8335TlWIydPUAFLceCjQTAhTC+Bx4FaOTIaTSw2zn5f8ZJ436BKMl +N/AEoTdNiN35ET3B5qYwG/QM0OiLBlWufNmCZyLiABlJkqmx+JuYdYJhDaqPIMA2Lo2 shoA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S8Pjs5cOqk+oGTnK7FdV4C/Z/WLlWltx0dBsRwUkzCw=; b=k7HfBndfH+Tfx0FHggOI5nxEvz1VfrDszrlSuef/Z1F0fO+izrykAcTmrXpWPHDgHg DG11435hSqMHbeF0hI5uYLw0UwYkibSzOYt9wtz9saW1eUDWHgCe18/2YzVuNGUPD0lj GzFmvq1qdgiKeUu4V3S07hqgJztbVT8XFQtqicWm0irQHfJE+/rJD/rRvWfSEB8eeZek z+qy9egJDs3T63+XQpDM9J64aPjk5Dte0EZ0jCTCyKV27j5M1RV8ExtYfN2H8Io9BVYS qsWjwsc6BHH9FtvhYoyVpjJBCsvRcFkFQuTgbwpaQgsGx3dVdJf4QlB1wtNwZZJakfE3 bvOg== X-Gm-Message-State: AJIora97Vjl3kMlcToELA4mA8aYpACYwdOltDb7DJy0r+mCB08gHm0If DPipcIH5OGNrKyKdZlP0Vwpp+IMnOFabeQ== X-Received: by 2002:a17:90a:ac04:b0:1ec:81d2:739 with SMTP id o4-20020a17090aac0400b001ec81d20739mr24846127pjq.171.1656392073904; Mon, 27 Jun 2022 21:54:33 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 11/60] semihosting: Clean up common_semi_flen_cb Date: Tue, 28 Jun 2022 10:23:14 +0530 Message-Id: <20220628045403.508716-12-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102e; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Do not read from the gdb struct stat buffer if the callback is reporting an error. Use common_semi_cb to finish returning results. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 88d6bdeaf2..cc13fcb0ef 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -346,15 +346,17 @@ static target_ulong common_semi_flen_buf(CPUState *cs) static void common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { - /* The size is always stored in big-endian order, extract - the value. We assume the size always fit in 32 bits. */ - uint32_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, - (uint8_t *)&size, 4, 0); - size = be32_to_cpu(size); - common_semi_set_ret(cs, size); - errno = err; - set_swi_errno(cs, -1); + if (!err) { + /* + * The size is always stored in big-endian order, extract + * the value. We assume the size always fit in 32 bits. + */ + uint32_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, + (uint8_t *)&size, 4, 0); + ret = be32_to_cpu(size); + } + common_semi_cb(cs, ret, err); } static int common_semi_open_guestfd; From patchwork Tue Jun 28 04:53:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585512 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp459999mab; Mon, 27 Jun 2022 23:06:15 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvFKJJDSlzJGflZ4wq54kR17+cnn/8wgLrqYN9b2wC5tl7sUZW4AS6lqmL8LAJ/LuPGad6 X-Received: by 2002:ad4:4ea6:0:b0:470:390b:c1e0 with SMTP id ed6-20020ad44ea6000000b00470390bc1e0mr1081123qvb.97.1656396374878; Mon, 27 Jun 2022 23:06:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396374; cv=none; d=google.com; s=arc-20160816; b=QZ4s1e5/lierO2gdFH/1dplfb2fwCRnjjYzmSgGMH5d+1sDze0c1D5jFRktxO2bC2Z ufUSRxeJWSRxMCeI5oS6b1uYWF/J1/hmArNpZgRLNIQshGzXL/lTHcoHNYBDZldrWpWK G8mg2qk6UYGRx802nOz8xAR84+PMejj05l3+DP5z4WvaOkbk/Ah3/4SrJj7vrSKAIazv 4pcsvuGwPyPLuk/AGmo4FCqw7xUXT5hnj2edg9X6s0IkEcHHcVUbLRB6O1W2PcQgzOZX R7OjL/naO4yabSyO7kq9IYiVA4Gkzly0BqsD/TOmYB/SfIms3x4MCsFrxjDi+nSwMRBU cVsw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=C3K2YfSefvABy7M7hq8Nd6JC/pCWOqgHqbPOWNo+9Kc=; b=z4MuHk+WZnpRCjhEcSvasdPAvBQU7Hwm0Bu+idX9kmmGhkVDt9W6lQ4dsJ4D+TjA5s WBRtdIgPCCpBErs4wTxczFi+I15jj0nornrABOcvqe76NnOqdxAhUFiHpq6CBPwJCsnL W4/4NAgOVfRao5gQ0APalRp2BPETbWYIDAHJeOFf4QpsK9eOZf0QPmDPpK10KZYvD6Q2 FyvIpRWPl+8h1TKGQNHNDRj9CpUDyJCMgnjdcBZ7ftGJM0lIwF/8KiZyBjgp3oL3PM5+ GCgYn0zHtH3Y2RUj36zMi8IDXkPIkdiWxTYgcbgGyKqDU1DYXsKv6eL87y/T1jiEq3jj tq3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xGRbtwyw; 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=pass (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 o18-20020ac87c52000000b0031ad4ee2379si2105544qtv.622.2022.06.27.23.06.14 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:06:14 -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=pass header.i=@linaro.org header.s=google header.b=xGRbtwyw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:53572 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64MY-0007hh-0b for patch@linaro.org; Tue, 28 Jun 2022 02:06:14 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43202) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FG-0002pF-V0 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:38 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:33699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FF-0008K5-GG for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:38 -0400 Received: by mail-pf1-x432.google.com with SMTP id n12so11007104pfq.0 for ; Mon, 27 Jun 2022 21:54:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=C3K2YfSefvABy7M7hq8Nd6JC/pCWOqgHqbPOWNo+9Kc=; b=xGRbtwywa3EOF4hpb7h/RnHnYgJcjofWu1Xb68m29btjPVX7grfIe3VrJPEZoBzLRK oRxI/DZ0KOOdneIKU48y10dyJRKlgxz+P8rgi7SL9HRwvu/6iYNfYIyJRqs2pYbEvGy1 2hHz3/6aTv5aPwWlpuoVKCL/w/eZKHRsqGW4XW2k+chlSTtOuABMPb4iPEMk4EX31Z5Z 7+N7K2qJlOOh/DvKtEVSwPLwSfk5sKeQj3VqPW+DgCkd5zR2sqEJ67WaYA+lzfUmPS87 X56qlpCp/R6C7ItjJJjiFG6GyzPwuxo10y+SMWIdDbZ9EExqBCJQqZYwWBnbJmlwBD9s AZnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=C3K2YfSefvABy7M7hq8Nd6JC/pCWOqgHqbPOWNo+9Kc=; b=Vv++kdhfeOERFA07mcMnidDVIjiERWBHTHGQS2O09tkg1nDQzwLOnrOTn1y2OvmOFs dbMdi0a9rIeU+8JOiAEy0rcSEmvQQ9JxlkJahrYQTJr0wCsmbDgagIAUu1CHqbQnvf7q C3fHqxKYd3F6clGOET3FKQXFVEWYLE0Ed2hBY4jbUd0+1jfrnLGR2QfHAUMYXjfy2hgM 5m7g+YAYJDAs6It6OUSaYWdgxEpJEmM5UfRGG/mzWDEzcf7i3NOZQM+AKaFxEB5ofLX5 LlnKyHsYlll5V6YPoJJJpQVVYxjfuz/UnPlLGYY9sJ1p/X/1KFETvxBZbDxiouHCuFyC DkwA== X-Gm-Message-State: AJIora9aUrNYwChpwCsYn8vr1JFRu9mRErgHjV5kib3tKg1KfCSfFlEa rxozpI8sR1oO6kV2Z4QwNGDwmlLeXzoFqg== X-Received: by 2002:a63:3ec6:0:b0:40d:27a:7847 with SMTP id l189-20020a633ec6000000b0040d027a7847mr15763180pga.606.1656392076221; Mon, 27 Jun 2022 21:54:36 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 12/60] semihosting: Clean up common_semi_open_cb Date: Tue, 28 Jun 2022 10:23:15 +0530 Message-Id: <20220628045403.508716-13-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Use common_semi_cb to return results instead of calling set_swi_errno and common_semi_set_ret directly. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index cc13fcb0ef..6414caa749 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -364,15 +364,13 @@ static int common_semi_open_guestfd; static void common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) { - if (ret == (target_ulong)-1) { - errno = err; - set_swi_errno(cs, -1); + if (err) { dealloc_guestfd(common_semi_open_guestfd); } else { associate_guestfd(common_semi_open_guestfd, ret); ret = common_semi_open_guestfd; } - common_semi_set_ret(cs, ret); + common_semi_cb(cs, ret, err); } static target_ulong From patchwork Tue Jun 28 04:53:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585515 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp463644mab; Mon, 27 Jun 2022 23:12:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1taaqkSQRDdvsI/Jj9vXcxjtVfnm/qkzHWXebskr93gYfm5o3QjrxsmLLdiNcVRnuzVk8bH X-Received: by 2002:a05:620a:24c7:b0:6a7:2d03:2de3 with SMTP id m7-20020a05620a24c700b006a72d032de3mr10319801qkn.134.1656396744142; Mon, 27 Jun 2022 23:12:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396744; cv=none; d=google.com; s=arc-20160816; b=lisePtC4EvwLp3wiylw63hkqVvVGjwfHogDwLJeAQnt1xYbjSmKzdNzRIcFJreCGMS 0iHtI7A4bXmO8Ssb3Ylg74ZWZgKQMex4T9Mf2R6zpnNbrivzZtgKeOft51kgwcOTr8s9 1HZntWIcZIb5WAN+dn0AZo6DWZe+wRJR08TChRA1uHKkQxejxtFQMWaxBery7HreFgvR zetDHohL+ClVsz3TLXj69OYM9Aij3vR8ulbHeaKa5P0ABzEM5W6bNRP4HN3EcrR+hcDy 3uJXUpKfRvziPzqN8MZJ7mqrIGRn5Ni2lp8Sk7q6P41bo2xomjMHhKReiOhX6SHLKGyE r/kA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yeVHZxbuaFRRXZUoftJ3W7/CfehcA2RW2b+r1PLF9rw=; b=1Lm3rbA3BC9BtkUUZ8oPUPKPndIJ+P2/VI5ve3ST7xNox1jfovpuO+TzFH3FCmNPsd l/ZINcQe9+n6xoSlM1IfdWZGWDEbFkZlacL1hSVSSEdDoDiWCvy7DA7rGik84OvnDYZd 5aQZeldZPPxDhcSDhSblLuAhPxnrkChUtupMmh6kyHP90aFz3QiN0NNRem+ny1+BddA/ xy2y2TNYqqAFvKM1wVQFHbRPvBK94UHBLjWtGM0hPmwWoyIqPaDN/UkRdO3El1BwjMC8 wSZpEd9Z2qszuuaysX7kXJXLRijfRX5xZa+sbRSY67t1W4O65+EH+pfFcwCMdfMFhLf4 l+Cw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="EMhikwc/"; 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=pass (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 do27-20020a05620a2b1b00b006aeed006d28si7114591qkb.566.2022.06.27.23.12.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:12: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=pass header.i=@linaro.org header.s=google header.b="EMhikwc/"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33992 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64SV-0005iR-Il for patch@linaro.org; Tue, 28 Jun 2022 02:12:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FL-00036R-SY for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:43 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:40559) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FI-0008Fk-IW for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:43 -0400 Received: by mail-pj1-x1034.google.com with SMTP id g16-20020a17090a7d1000b001ea9f820449so14628330pjl.5 for ; Mon, 27 Jun 2022 21:54:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yeVHZxbuaFRRXZUoftJ3W7/CfehcA2RW2b+r1PLF9rw=; b=EMhikwc/NMh73goGEj/9z6F2n2Jz4wIfrIGgULDXRb6XmUWqnhhdW6pG0sOjtuO1Fv HW+qakOXfXy73W43pGwUTxGNHBpawzbaeZThCJRuszO6Iou8z1dilOr4iKtXajAI0+nr 738h0PdzYFOyQ6jeTVxKhKXCwaNEhqMcLuv3OkGut4uMCG9dDQ3G+m1ZptP2wrYu/8qt 5FyQdIkJgt7uBuBejFXxDvBADGSPJK8W+qgr32qwQkit82qo7e8ZZPiIFjtdkmpK7O49 zIpIr1QeAEKM/10GXxJY9873bCDpkzKBYcRNFKGRSdmPeFLXuGru16qlqRSPCMz/TE2g ZO/g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yeVHZxbuaFRRXZUoftJ3W7/CfehcA2RW2b+r1PLF9rw=; b=mrUj4yuXza3bVtcfpvRB3CWiPOZ3v0kicW3P91vpaeFOymkWZo/RjVmA8bZfjZLEPq d18dZQ4fPNvci3hz0d5e9J8pAoOgMN7Q9lig/73Dp7MxfAAL7bBl0OZn9REnZ+gqCLWy NUEaGiXfPIfzjo9vR7A+OUuYRF1S5dm7L7THu9t5QkFxPzLqYbAC/w0ppHI19vrylMF2 0EB2z47sF76gW5L41ZNzBZrldAjMnvxbg0+ubEcY0bDfUp5BSNgh84p8vhUjIbSFHSeC IV5Km4FrP/NPI02jrKSg+Nf2hHMGLCZ3rvixHnZUtQuMQTVo5SeNq7eNLw9kK31FYLvn igXA== X-Gm-Message-State: AJIora+3zrElY6tPmqZxd++zzsIDv/Efa9R21YGg0vXn68IcsbgThDFh oH3N2xazjl/om3IMY/DHO1xsyjcgGyY3kw== X-Received: by 2002:a17:90a:1d0:b0:1ec:7066:49b8 with SMTP id 16-20020a17090a01d000b001ec706649b8mr20355705pjd.163.1656392079535; Mon, 27 Jun 2022 21:54:39 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 13/60] semihosting: Return void from do_common_semihosting Date: Tue, 28 Jun 2022 10:23:16 +0530 Message-Id: <20220628045403.508716-14-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1034; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1034.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Perform the cleanup in the FIXME comment in common_semi_gdb_syscall. Do not modify guest registers until the syscall is complete, which in the gdbstub case is asynchronous. In the synchronous non-gdbstub case, use common_semi_set_ret to set the result. Merge set_swi_errno into common_semi_cb. Rely on the latter for combined return value / errno setting. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- semihosting/common-semi.h | 2 +- linux-user/aarch64/cpu_loop.c | 2 +- linux-user/arm/cpu_loop.c | 2 +- linux-user/riscv/cpu_loop.c | 2 +- semihosting/arm-compat-semi.c | 543 ++++++++++++++++------------------ target/arm/helper.c | 4 +- target/arm/m_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- 8 files changed, 264 insertions(+), 295 deletions(-) diff --git a/semihosting/common-semi.h b/semihosting/common-semi.h index 0bfab1c669..0a91db7c41 100644 --- a/semihosting/common-semi.h +++ b/semihosting/common-semi.h @@ -34,6 +34,6 @@ #ifndef COMMON_SEMI_H #define COMMON_SEMI_H -target_ulong do_common_semihosting(CPUState *cs); +void do_common_semihosting(CPUState *cs); #endif /* COMMON_SEMI_H */ diff --git a/linux-user/aarch64/cpu_loop.c b/linux-user/aarch64/cpu_loop.c index 3b273f6299..f7ef36cd9f 100644 --- a/linux-user/aarch64/cpu_loop.c +++ b/linux-user/aarch64/cpu_loop.c @@ -154,7 +154,7 @@ void cpu_loop(CPUARMState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case EXCP_SEMIHOST: - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; case EXCP_YIELD: diff --git a/linux-user/arm/cpu_loop.c b/linux-user/arm/cpu_loop.c index d950409d5b..c0790f3246 100644 --- a/linux-user/arm/cpu_loop.c +++ b/linux-user/arm/cpu_loop.c @@ -449,7 +449,7 @@ void cpu_loop(CPUARMState *env) } break; case EXCP_SEMIHOST: - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; break; case EXCP_INTERRUPT: diff --git a/linux-user/riscv/cpu_loop.c b/linux-user/riscv/cpu_loop.c index 29084c1421..bffca7db12 100644 --- a/linux-user/riscv/cpu_loop.c +++ b/linux-user/riscv/cpu_loop.c @@ -81,7 +81,7 @@ void cpu_loop(CPURISCVState *env) force_sig_fault(TARGET_SIGTRAP, TARGET_TRAP_BRKPT, env->pc); break; case RISCV_EXCP_SEMIHOST: - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; break; default: diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 6414caa749..cebbad2355 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -261,20 +261,6 @@ static target_ulong syscall_err; #include "semihosting/softmmu-uaccess.h" #endif -static inline uint32_t set_swi_errno(CPUState *cs, uint32_t code) -{ - if (code == (uint32_t)-1) { -#ifdef CONFIG_USER_ONLY - TaskState *ts = cs->opaque; - - ts->swi_errno = errno; -#else - syscall_err = errno; -#endif - } - return code; -} - static inline uint32_t get_swi_errno(CPUState *cs) { #ifdef CONFIG_USER_ONLY @@ -373,54 +359,24 @@ common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_cb(cs, ret, err); } -static target_ulong -common_semi_gdb_syscall(CPUState *cs, gdb_syscall_complete_cb cb, - const char *fmt, ...) -{ - va_list va; - - va_start(va, fmt); - gdb_do_syscallv(cb, fmt, va); - va_end(va); - - /* - * FIXME: in softmmu mode, the gdbstub will schedule our callback - * to occur, but will not actually call it to complete the syscall - * until after this function has returned and we are back in the - * CPU main loop. Therefore callers to this function must not - * do anything with its return value, because it is not necessarily - * the result of the syscall, but could just be the old value of X0. - * The only thing safe to do with this is that the callers of - * do_common_semihosting() will write it straight back into X0. - * (In linux-user mode, the callback will have happened before - * gdb_do_syscallv() returns.) - * - * We should tidy this up so neither this function nor - * do_common_semihosting() return a value, so the mistake of - * doing something with the return value is not possible to make. - */ - - return common_semi_arg(cs, 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. + * do the work and return the required return value to the guest + * via common_semi_cb. */ -typedef uint32_t sys_closefn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); -typedef uint32_t sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef uint32_t sys_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset); -typedef uint32_t sys_flenfn(CPUState *cs, GuestFD *gf); +typedef void sys_closefn(CPUState *cs, GuestFD *gf); +typedef void sys_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len); +typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); +typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); +typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static uint32_t host_closefn(CPUState *cs, GuestFD *gf) +static void host_closefn(CPUState *cs, GuestFD *gf) { + int ret; /* * Only close the underlying host fd if it's one we opened on behalf * of the guest in SYS_OPEN. @@ -428,113 +384,106 @@ static uint32_t host_closefn(CPUState *cs, GuestFD *gf) if (gf->hostfd == STDIN_FILENO || gf->hostfd == STDOUT_FILENO || gf->hostfd == STDERR_FILENO) { - return 0; + ret = 0; + } else { + ret = close(gf->hostfd); } - return set_swi_errno(cs, close(gf->hostfd)); + common_semi_cb(cs, ret, ret ? errno : 0); } -static uint32_t host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_READ, buf, len, 1); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* Return bytes not written on error */ - return len; + if (s) { + ret = write(gf->hostfd, s, len); + unlock_user(s, buf, 0); + if (ret == (uint32_t)-1) { + ret = 0; + } } - ret = set_swi_errno(cs, write(gf->hostfd, s, len)); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - /* Return bytes not written */ - return len - ret; + /* Return bytes not written, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void host_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t ret; + uint32_t ret = 0; char *s = lock_user(VERIFY_WRITE, buf, len, 0); (void) env; /* Used in arm softmmu lock_user implicitly */ - if (!s) { - /* return bytes not read */ - return len; + if (s) { + do { + ret = read(gf->hostfd, s, len); + } while (ret == -1 && errno == EINTR); + unlock_user(s, buf, len); + if (ret == (uint32_t)-1) { + ret = 0; + } } - do { - ret = set_swi_errno(cs, 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; + /* Return bytes not read, on error as well. */ + common_semi_cb(cs, len - ret, 0); } -static uint32_t host_isattyfn(CPUState *cs, GuestFD *gf) +static void host_isattyfn(CPUState *cs, GuestFD *gf) { - return isatty(gf->hostfd); + common_semi_cb(cs, isatty(gf->hostfd), 0); } -static uint32_t host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - uint32_t ret = set_swi_errno(cs, lseek(gf->hostfd, offset, SEEK_SET)); - if (ret == (uint32_t)-1) { - return -1; - } - return 0; + off_t ret = lseek(gf->hostfd, offset, SEEK_SET); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); } -static uint32_t host_flenfn(CPUState *cs, GuestFD *gf) +static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; - uint32_t ret = set_swi_errno(cs, fstat(gf->hostfd, &buf)); - if (ret == (uint32_t)-1) { - return -1; + + if (fstat(gf->hostfd, &buf)) { + common_semi_cb(cs, -1, errno); + } else { + common_semi_cb(cs, buf.st_size, 0); } - return buf.st_size; } -static uint32_t gdb_closefn(CPUState *cs, GuestFD *gf) +static void gdb_closefn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "close,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); } -static uint32_t gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "write,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void gdb_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { common_semi_syscall_len = len; - return common_semi_gdb_syscall(cs, common_semi_cb, "read,%x,%x,%x", - gf->hostfd, buf, len); + gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); } -static uint32_t gdb_isattyfn(CPUState *cs, GuestFD *gf) +static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_cb, "isatty,%x", gf->hostfd); + gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static uint32_t gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) +static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - return common_semi_gdb_syscall(cs, common_semi_cb, "lseek,%x,%x,0", - gf->hostfd, offset); + gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); } -static uint32_t gdb_flenfn(CPUState *cs, GuestFD *gf) +static void gdb_flenfn(CPUState *cs, GuestFD *gf) { - return common_semi_gdb_syscall(cs, common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); + gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", + gf->hostfd, common_semi_flen_buf(cs)); } #define SHFB_MAGIC_0 0x53 @@ -554,63 +503,57 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) +static void staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_writefn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { /* This fd can never be open for writing */ - - errno = EBADF; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EBADF); } -static uint32_t staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) +static void staticfile_readfn(CPUState *cs, GuestFD *gf, + target_ulong buf, uint32_t len) { CPUArchState *env = cs->env_ptr; - uint32_t i; + uint32_t i = 0; char *s; (void) env; /* Used in arm softmmu lock_user implicitly */ s = lock_user(VERIFY_WRITE, buf, len, 0); - if (!s) { - return len; - } - - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; + if (s) { + for (i = 0; i < len; i++) { + if (gf->staticfile.off >= gf->staticfile.len) { + break; + } + s[i] = gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; + unlock_user(s, buf, len); } - unlock_user(s, buf, len); - /* Return number of bytes not read */ - return len - i; + common_semi_cb(cs, len - i, 0); } -static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) +static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, - target_ulong offset) +static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { gf->staticfile.off = offset; - return 0; + common_semi_cb(cs, 0, 0); } -static uint32_t staticfile_flenfn(CPUState *cs, GuestFD *gf) +static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { - return gf->staticfile.len; + common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { @@ -669,13 +612,11 @@ static inline bool is_64bit_semihosting(CPUArchState *env) #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ if (get_user_u64(arg ## n, args + (n) * 8)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + goto do_fault; \ } \ } \ } while (0) @@ -695,7 +636,7 @@ static inline bool is_64bit_semihosting(CPUArchState *env) * leave the register unchanged. We use 0xdeadbeef as the return value * when there isn't a defined return value for the call. */ -target_ulong do_common_semihosting(CPUState *cs) +void do_common_semihosting(CPUState *cs) { CPUArchState *env = cs->env_ptr; target_ulong args; @@ -715,32 +656,23 @@ target_ulong do_common_semihosting(CPUState *cs) switch (nr) { case TARGET_SYS_OPEN: { - int guestfd; + int ret, err = 0; + int hostfd; GET_ARG(0); GET_ARG(1); GET_ARG(2); s = lock_user_string(arg0); if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } if (arg1 >= 12) { unlock_user(s, arg0, 0); - errno = EINVAL; - return set_swi_errno(cs, -1); - } - - guestfd = alloc_guestfd(); - if (guestfd < 0) { - unlock_user(s, arg0, 0); - errno = EMFILE; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, EINVAL); + break; } if (strcmp(s, ":tt") == 0) { - int result_fileno; - /* * We implement SH_EXT_STDOUT_STDERR, so: * open for read == stdin @@ -748,63 +680,67 @@ target_ulong do_common_semihosting(CPUState *cs) * open for append == stderr */ if (arg1 < 4) { - result_fileno = STDIN_FILENO; + hostfd = STDIN_FILENO; } else if (arg1 < 8) { - result_fileno = STDOUT_FILENO; + hostfd = STDOUT_FILENO; } else { - result_fileno = STDERR_FILENO; + hostfd = STDERR_FILENO; } - associate_guestfd(guestfd, result_fileno); - unlock_user(s, arg0, 0); - return guestfd; - } - if (strcmp(s, ":semihosting-features") == 0) { - unlock_user(s, arg0, 0); + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); + } else if (strcmp(s, ":semihosting-features") == 0) { /* We must fail opens for modes other than 0 ('r') or 1 ('rb') */ if (arg1 != 0 && arg1 != 1) { - dealloc_guestfd(guestfd); - errno = EACCES; - return set_swi_errno(cs, -1); - } - staticfile_guestfd(guestfd, featurefile_data, - sizeof(featurefile_data)); - return guestfd; - } - - if (use_gdb_syscalls()) { - common_semi_open_guestfd = guestfd; - ret = common_semi_gdb_syscall(cs, common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - } else { - ret = set_swi_errno(cs, open(s, open_modeflags[arg1], 0644)); - if (ret == (uint32_t)-1) { - dealloc_guestfd(guestfd); + ret = -1; + err = EACCES; } else { - associate_guestfd(guestfd, ret); - ret = guestfd; + ret = alloc_guestfd(); + staticfile_guestfd(ret, featurefile_data, + sizeof(featurefile_data)); + } + } else if (use_gdb_syscalls()) { + unlock_user(s, arg0, 0); + common_semi_open_guestfd = alloc_guestfd(); + gdb_do_syscall(common_semi_open_cb, + "open,%s,%x,1a4", arg0, (int)arg2 + 1, + gdb_open_modeflags[arg1]); + break; + } else { + hostfd = open(s, open_modeflags[arg1], 0644); + if (hostfd < 0) { + ret = -1; + err = errno; + } else { + ret = alloc_guestfd(); + associate_guestfd(ret, hostfd); } } unlock_user(s, arg0, 0); - return ret; + common_semi_cb(cs, ret, err); + break; } + case TARGET_SYS_CLOSE: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } - - ret = guestfd_fns[gf->type].closefn(cs, gf); + guestfd_fns[gf->type].closefn(cs, gf); dealloc_guestfd(arg0); - return ret; + break; + case TARGET_SYS_WRITEC: qemu_semihosting_console_outc(cs->env_ptr, args); - return 0xdeadbeef; + common_semi_set_ret(cs, 0xdeadbeef); + break; + case TARGET_SYS_WRITE0: - return qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(cs->env_ptr, args); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_WRITE: GET_ARG(0); GET_ARG(1); @@ -813,11 +749,11 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].writefn(cs, gf, arg1, len); case TARGET_SYS_READ: GET_ARG(0); GET_ARG(1); @@ -826,129 +762,150 @@ target_ulong do_common_semihosting(CPUState *cs) gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + break; - return guestfd_fns[gf->type].readfn(cs, gf, arg1, len); case TARGET_SYS_READC: - return qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(cs->env_ptr); + common_semi_set_ret(cs, ret); + break; + case TARGET_SYS_ISERROR: GET_ARG(0); - return (target_long) arg0 < 0 ? 1 : 0; + common_semi_set_ret(cs, (target_long)arg0 < 0); + break; + case TARGET_SYS_ISTTY: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].isattyfn(cs, gf); + break; - return guestfd_fns[gf->type].isattyfn(cs, gf); case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].seekfn(cs, gf, arg1); + break; - return guestfd_fns[gf->type].seekfn(cs, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0); gf = get_guestfd(arg0); if (!gf) { - errno = EBADF; - return set_swi_errno(cs, -1); + goto do_badf; } + guestfd_fns[gf->type].flenfn(cs, gf); + break; - return guestfd_fns[gf->type].flenfn(cs, gf); case TARGET_SYS_TMPNAM: + { + int len; + char *p; + GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (asprintf(&s, "/tmp/qemu-%x%02x", getpid(), - (int) (arg1 & 0xff)) < 0) { - return -1; - } - ul_ret = (target_ulong) -1; - + len = asprintf(&s, "/tmp/qemu-%x%02x", getpid(), (int)arg1 & 0xff); /* Make sure there's enough space in the buffer */ - if (strlen(s) < arg2) { - char *output = lock_user(VERIFY_WRITE, arg0, arg2, 0); - strcpy(output, s); - unlock_user(output, arg0, arg2); - ul_ret = 0; + if (len < 0 || len >= arg2) { + common_semi_set_ret(cs, -1); + break; } + p = lock_user(VERIFY_WRITE, arg0, len, 0); + if (!p) { + goto do_fault; + } + memcpy(p, s, len + 1); + unlock_user(p, arg0, len); free(s); - return ul_ret; + common_semi_set_ret(cs, 0); + break; + } + case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - ret = common_semi_gdb_syscall(cs, common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, remove(s)); - unlock_user(s, arg0, 0); + gdb_do_syscall(common_semi_cb, "unlink,%s", + arg0, (int)arg1 + 1); + break; } - return ret; + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = remove(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); + break; + case TARGET_SYS_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, - (int)arg3 + 1); + gdb_do_syscall(common_semi_cb, "rename,%s,%s", + arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); } else { char *s2; + s = lock_user_string(arg0); - s2 = lock_user_string(arg2); - if (!s || !s2) { - errno = EFAULT; - ret = set_swi_errno(cs, -1); - } else { - ret = set_swi_errno(cs, rename(s, s2)); + if (!s) { + goto do_fault; } - if (s2) - unlock_user(s2, arg2, 0); - if (s) + s2 = lock_user_string(arg2); + if (!s2) { unlock_user(s, arg0, 0); - return ret; + goto do_fault; + } + ret = rename(s, s2); + unlock_user(s2, arg2, 0); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret ? errno : 0); } + break; + case TARGET_SYS_CLOCK: - return clock() / (CLOCKS_PER_SEC / 100); + common_semi_set_ret(cs, clock() / (CLOCKS_PER_SEC / 100)); + break; + case TARGET_SYS_TIME: - return set_swi_errno(cs, time(NULL)); + ul_ret = time(NULL); + common_semi_cb(cs, ul_ret, ul_ret == -1 ? errno : 0); + break; + case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - return common_semi_gdb_syscall(cs, common_semi_cb, "system,%s", - arg0, (int)arg1 + 1); - } else { - s = lock_user_string(arg0); - if (!s) { - errno = EFAULT; - return set_swi_errno(cs, -1); - } - ret = set_swi_errno(cs, system(s)); - unlock_user(s, arg0, 0); - return ret; + gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); + break; } + s = lock_user_string(arg0); + if (!s) { + goto do_fault; + } + ret = system(s); + unlock_user(s, arg0, 0); + common_semi_cb(cs, ret, ret == -1 ? errno : 0); + break; + case TARGET_SYS_ERRNO: - return get_swi_errno(cs); + common_semi_set_ret(cs, get_swi_errno(cs)); + break; + case TARGET_SYS_GET_CMDLINE: { /* Build a command-line from the original argv. @@ -999,22 +956,20 @@ target_ulong do_common_semihosting(CPUState *cs) if (output_size > input_size) { /* Not enough space to store command-line arguments. */ - errno = E2BIG; - return set_swi_errno(cs, -1); + common_semi_cb(cs, -1, E2BIG); + break; } /* Adjust the command-line length. */ if (SET_ARG(1, output_size - 1)) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Lock the buffer on the ARM side. */ output_buffer = lock_user(VERIFY_WRITE, arg0, output_size, 0); if (!output_buffer) { - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } /* Copy the command-line arguments. */ @@ -1029,9 +984,8 @@ target_ulong do_common_semihosting(CPUState *cs) if (copy_from_user(output_buffer, ts->info->arg_strings, output_size)) { - errno = EFAULT; - status = set_swi_errno(cs, -1); - goto out; + unlock_user(output_buffer, arg0, 0); + goto do_fault; } /* Separate arguments by white spaces. */ @@ -1044,9 +998,10 @@ target_ulong do_common_semihosting(CPUState *cs) #endif /* Unlock the buffer on the ARM side. */ unlock_user(output_buffer, arg0, output_size); - - return status; + common_semi_cb(cs, status, 0); } + break; + case TARGET_SYS_HEAPINFO: { target_ulong retvals[4]; @@ -1103,12 +1058,13 @@ target_ulong do_common_semihosting(CPUState *cs) if (fail) { /* Couldn't write back to argument block */ - errno = EFAULT; - return set_swi_errno(cs, -1); + goto do_fault; } } - return 0; + common_semi_set_ret(cs, 0); } + break; + case TARGET_SYS_EXIT: case TARGET_SYS_EXIT_EXTENDED: if (common_semi_sys_exit_extended(cs, nr)) { @@ -1138,6 +1094,7 @@ target_ulong do_common_semihosting(CPUState *cs) } gdb_exit(ret); exit(ret); + case TARGET_SYS_ELAPSED: elapsed = get_clock() - clock_start; if (sizeof(target_ulong) == 8) { @@ -1146,10 +1103,14 @@ target_ulong do_common_semihosting(CPUState *cs) SET_ARG(0, (uint32_t) elapsed); SET_ARG(1, (uint32_t) (elapsed >> 32)); } - return 0; + common_semi_set_ret(cs, 0); + break; + case TARGET_SYS_TICKFREQ: /* qemu always uses nsec */ - return 1000000000; + common_semi_set_ret(cs, 1000000000); + break; + case TARGET_SYS_SYNCCACHE: /* * Clean the D-cache and invalidate the I-cache for the specified @@ -1158,16 +1119,24 @@ target_ulong do_common_semihosting(CPUState *cs) */ #ifdef TARGET_ARM if (is_a64(cs->env_ptr)) { - return 0; + common_semi_set_ret(cs, 0); + break; } #endif #ifdef TARGET_RISCV - return 0; + common_semi_set_ret(cs, 0); #endif /* fall through -- invalid for A32/T32 */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, 0); abort(); + + do_badf: + common_semi_cb(cs, -1, EBADF); + break; + do_fault: + common_semi_cb(cs, -1, EFAULT); + break; } } diff --git a/target/arm/helper.c b/target/arm/helper.c index d2886a123a..f6dcb1a115 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10515,13 +10515,13 @@ static void handle_semihosting(CPUState *cs) qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%" PRIx64 "\n", env->xregs[0]); - env->xregs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; } else { qemu_log_mask(CPU_LOG_INT, "...handling as semihosting call 0x%x\n", env->regs[0]); - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->regs[15] += env->thumb ? 2 : 4; } } diff --git a/target/arm/m_helper.c b/target/arm/m_helper.c index a740c3e160..308610f6b4 100644 --- a/target/arm/m_helper.c +++ b/target/arm/m_helper.c @@ -2373,7 +2373,7 @@ void arm_v7m_cpu_do_interrupt(CPUState *cs) "...handling as semihosting call 0x%x\n", env->regs[0]); #ifdef CONFIG_TCG - env->regs[0] = do_common_semihosting(cs); + do_common_semihosting(cs); #else g_assert_not_reached(); #endif diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index 4a6700c890..be28615e23 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1347,7 +1347,7 @@ void riscv_cpu_do_interrupt(CPUState *cs) if (cause == RISCV_EXCP_SEMIHOST) { if (env->priv >= PRV_S) { - env->gpr[xA0] = do_common_semihosting(cs); + do_common_semihosting(cs); env->pc += 4; return; } From patchwork Tue Jun 28 04:53:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585517 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp467223mab; Mon, 27 Jun 2022 23:18:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1v2d3Yg20OB8rlv0u0NBQG4IN+8uSDDDqoxgYdTFm4OFfzH9gOuyNBw4TrL3a6YmSgYLhno X-Received: by 2002:a05:622a:15c1:b0:31b:a2e5:360d with SMTP id d1-20020a05622a15c100b0031ba2e5360dmr3790126qty.516.1656397126785; Mon, 27 Jun 2022 23:18:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397126; cv=none; d=google.com; s=arc-20160816; b=XUJjspCpBNDyR+vw2APB0WroE+zcopUNam9Hp/oXafcPP9+IVVtH99FqvfUHHTE27+ zVJdBIsN/ZIlpKNOgcTunhhq27DfNqApCd+dgTAFuL5B1R9EaKipxWZiQVbVEyevrYE3 HU2s7DkYXg7lXr1If9u+gv5onZhX02xeWXy9TTrDgJiJEwY2FXXVoBcvFOxMyvg51UpK xN8m/M35vImwq8vuIs8+O80bOygbGx2DhoJD6P41XfMMgNKFq/0CMQS34qNaaL7slWkV D88UKD9h9Ti47q/dz05Rq/IwjyqyI9hWKMuFuagsIPk6AxzeHxMYVZQPgp77EEV1tWXJ Vj5Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cx0XUly4xDUnFuxMUIgi+30WH5Nxa4Rsb47NOld+zjg=; b=0Qg7w+QunyzqaVkVHis6kZKNxw3v8s7CHCMxLYhAeQHVxQM4jqest6u/2pIpVU3UGU UH8sOTpNm2RFubMUWJdZ65HHmY+yvl+6mM907xOROj7lAFVNmHtnbR/GuJpBA4SjMUw9 zXH1ceu2HSo1sjt0ROELXHlOlK20OjHkUm7wkZ/bR0LcKXJx2Yo8t4y2ccum1vqVOmjX Rd+xZhQBIMrnLzDptsXPa/njtO4KtBzXpTLMJwd5tuxTkhrxjH8NQmBdUJ3QnfYPykpG /kigH+cwvUW2fmekLoD9XV+4wFqIIut7ANGt3UOfxP9j9a7Sf21Ncry3j9fo9d2ZPyCE mr/w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=l66yS15f; 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=pass (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 kc27-20020a056214411b00b00470425fc0desi5869833qvb.2.2022.06.27.23.18.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:18:46 -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=pass header.i=@linaro.org header.s=google header.b=l66yS15f; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Yg-00049z-7q for patch@linaro.org; Tue, 28 Jun 2022 02:18:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43234) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FM-00038N-R9 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:44 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:46750) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FL-0008KP-BP for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:44 -0400 Received: by mail-pl1-x633.google.com with SMTP id q18so9998071pld.13 for ; Mon, 27 Jun 2022 21:54:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cx0XUly4xDUnFuxMUIgi+30WH5Nxa4Rsb47NOld+zjg=; b=l66yS15f/TsFaCYp2EwBL+NjZGLcdFq3LPpM1JqJCptCKbm7lG4C8vd+H0GP8op17c UOo1m3Ji1MMEwTJgvJTPp7Jjto4M+sVT/vjatCCGngegbd8KT0dTDIh2xBCc9+J8ekoL r3H0N5gr7KtkCORS6u7j5lb5VtH9MTBBSS1MruTdPuu4jWM+aWXs3HAXIBBZ9xJ6Pm6d O7p32poB6cFv8xcINhBzhfClVYQnaTXZSS39LgGQW8qw8Vyk6h6ceev68pxWHpNeP3ve FWGkQSZtSimc9zJm6WagkY9yUr5ShaVPJons4cqUw/22XA0AlCa3ixdXTSlZznWP8mKf TfcA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cx0XUly4xDUnFuxMUIgi+30WH5Nxa4Rsb47NOld+zjg=; b=Ld29HLaU0RT8e+3DO0gYGqHBUK2w4tHkrgzFheDXsTuBLNzB90FDifIeP2gk6v6yGg CGDi0ACyCExNJMybYKEfELXqL1+aB2o/3uzo4MeolkDoKiu32gN2tLKasgh4NGYDBGqj C87wsqh47w+cgXZIrM4Gg134gijHPE66G91onLsUEV8s14Mq3lj/nhAYWSWG532dh3E6 SjFPB+K6SO0FJIS6yx1r3EvdU4xauj/OhXmNVKkHNn3C2mWPeQIXUl/ri4NzFsCgnhWP EumZT2n+zO1TZjMz+n1QAS/1kY4pamJwQ0/diauCHyKgKt4lYvRqrEJXLZGsDf4H8RXF So0g== X-Gm-Message-State: AJIora+drpNYEKbTeGYHneel5Y1g9NJ5hVIkUacxs0VMp1pO0B2512fU QlqtCh7xEfv6SkEksXz52rXDaj6zb8+apg== X-Received: by 2002:a17:90b:1b08:b0:1ec:b29a:4580 with SMTP id nu8-20020a17090b1b0800b001ecb29a4580mr25089976pjb.59.1656392082010; Mon, 27 Jun 2022 21:54:42 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 14/60] semihosting: Move common-semi.h to include/semihosting/ Date: Tue, 28 Jun 2022 10:23:17 +0530 Message-Id: <20220628045403.508716-15-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This header is not private to the top-level semihosting directory, so place it in the public include directory. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- {semihosting => include/semihosting}/common-semi.h | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename {semihosting => include/semihosting}/common-semi.h (100%) diff --git a/semihosting/common-semi.h b/include/semihosting/common-semi.h similarity index 100% rename from semihosting/common-semi.h rename to include/semihosting/common-semi.h From patchwork Tue Jun 28 04:53:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585546 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp508211mab; Tue, 28 Jun 2022 00:26:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLLwTLfGYKVCPpQGEmvhFm/UHxg6tH037IKLiAsUcV5PJBY6rsmWGnkEKS1j7D0hcVY42/ X-Received: by 2002:a05:6214:1ccd:b0:46e:7427:2626 with SMTP id g13-20020a0562141ccd00b0046e74272626mr2520702qvd.101.1656401194372; Tue, 28 Jun 2022 00:26:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401194; cv=none; d=google.com; s=arc-20160816; b=COmtMGplaeepjAXdI0HGSq6jwCwkOB2yJYFq1orRuoxwwsykickshreT5fybGYJQqT k1SsQ+qZpzD+mWssN/kqhUoUlqi07hqnI4EhgtJ8hxpOikgc08fsY2bMcCKy4GT3kNed gn87DDz0wlogu8mswbPrCUP/FGWrxaWUbej/ub22Ln0BOt3D483kU2kGdS38o1vEZdjV MG4WD2vcUgmXVWdlMQtvTy8Z64bpPPlotB2DMzQBS6DCcg9kg7He+Kh55zN+PixVXYHt nb839CDEJhseS6Wl9dNbmyhje76WyqD8oelZuohloIn8O8arxAY6JQdLQCcsk2gwWAAY YzxA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n1ZDBnw0lkX4YrNv7Tv2EuCi+urg5qVqojkVKbH0n5o=; b=RAypYadzJ0ZBB0bPR6YdwHdvLiAzKMEMgGK99KL1jxwj/Cl5kSfX925p8oFruxNfRD 1ZJOvF0AnsIXFX24MoHtcAtDCdOdYU8FZCTs/PpFn04Fh4xyGtRHBXtkPEYfBbtgm1Z7 5x+kD4phPbIKir+IgeXza5JTftS0ebJnj0m1MRQoU8HJFyoe8DeLZgkLFX593nuzfruV t8NDbtTBTekpyxJBcz76bHe9VElOp49EtVlGE+1n6MtmcJQycypLh7JnjbdXaKAidiCj LF/3EC8zyaYsKrjOf9n6bY39uMvmqgUE9784C5zunQSIQXWjrsAvyBjWTLVmkluZ1Syz 0M4g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bW1hkOw0; 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=pass (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 y10-20020a05620a25ca00b006aee941e0f6si8436339qko.428.2022.06.28.00.26.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:26:34 -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=pass header.i=@linaro.org header.s=google header.b=bW1hkOw0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44330 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65cH-0000Up-US for patch@linaro.org; Tue, 28 Jun 2022 03:26:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43250) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FO-0003AO-J1 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:48 -0400 Received: from mail-pf1-x432.google.com ([2607:f8b0:4864:20::432]:42660) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FN-0008G4-1B for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:46 -0400 Received: by mail-pf1-x432.google.com with SMTP id d17so10917841pfq.9 for ; Mon, 27 Jun 2022 21:54:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n1ZDBnw0lkX4YrNv7Tv2EuCi+urg5qVqojkVKbH0n5o=; b=bW1hkOw0g1LQIwRhdUCsQaWncsdyCzDFT7smCy7T3Db3H8UF+545sgjayWESM+yE3b xTYRiIL7ORCFC7PBAXioKTvoDsPkT28o393Xonq+MKH+eZOGad0RVtQJb+K95lxo8k9k k1zm9eO99jNISYqOrfC9fN0GdfX98Qb+hTallkY86zCGUvKlykWNIKjeP7k+5cl7iLR7 Vgabfd8GMxaR82Hc5gWNlt+xjVcl0cCN3g0WZULNQwhEolBjhLTRUwoN04/CDvOXY9m/ pCOkK4fOrqrnpj4OXz4/iguhn5vesO9Mjs3P3PWNKMQWHBwo85I/0GFAU76dETRgWs1l 0q7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n1ZDBnw0lkX4YrNv7Tv2EuCi+urg5qVqojkVKbH0n5o=; b=kLUIycZNPTqlxGt//LRxyWiU3aKjbcVKnGDhwWMpirM7R5/68IJMv5ve45IfXJDPMf 0+KFKsjALTCjQY8vqvkfayriplbZQpEu67dUcVmJW+3uXhnD7A+ZO31a9L67qXf2ZOFm ++K2+kWYlxCH3U5u8O3PUPxOUhNUvlMBosAKOlyhQ0lF04cie2AIEUndL9eNDYXvRvRp StgnwxxNLVCUMa6GitWOw8lFnzSunhMgwuKO2cI8SDuj7EwqENVqeQYABUK0u+a9IUAq DvCY5X0094bn0fgAL7RFQMbtQO+1Zi0JWPJkYvlI6UEw/IQhnBLb35CLAXolLD9JFJDW xL3w== X-Gm-Message-State: AJIora+kOzilW46a4MYoyN9AcROt1X7uCCDJvCq26J++BeSgLec4CSgt sbwVsMZ49Zm1I5HJtDknWfPqchDBU9aDdA== X-Received: by 2002:a63:6d7:0:b0:411:51f2:6de2 with SMTP id 206-20020a6306d7000000b0041151f26de2mr3187221pgg.184.1656392084269; Mon, 27 Jun 2022 21:54:44 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 15/60] semihosting: Remove GDB_O_BINARY Date: Tue, 28 Jun 2022 10:23:18 +0530 Message-Id: <20220628045403.508716-16-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::432; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x432.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01, UPPERCASE_50_75=0.008 autolearn=no autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 value is zero, and gdb always opens files in binary mode. Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index cebbad2355..92c1375b15 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -92,21 +92,20 @@ #define GDB_O_APPEND 0x008 #define GDB_O_CREAT 0x200 #define GDB_O_TRUNC 0x400 -#define GDB_O_BINARY 0 static int gdb_open_modeflags[12] = { GDB_O_RDONLY, - GDB_O_RDONLY | GDB_O_BINARY, + GDB_O_RDONLY, + GDB_O_RDWR, GDB_O_RDWR, - GDB_O_RDWR | GDB_O_BINARY, GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC, - GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, + GDB_O_WRONLY | GDB_O_CREAT | GDB_O_TRUNC, + GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC, GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC, - GDB_O_RDWR | GDB_O_CREAT | GDB_O_TRUNC | GDB_O_BINARY, GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND, - GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY, + GDB_O_WRONLY | GDB_O_CREAT | GDB_O_APPEND, + GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, - GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND | GDB_O_BINARY }; static int open_modeflags[12] = { From patchwork Tue Jun 28 04:53:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585547 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp510137mab; Tue, 28 Jun 2022 00:29:46 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vgieUabtkWVtJ7KAm5nvp93siMJkvNs4wkrel34SS3RSXY6eEMNrkizD1RnGRyabLUanOZ X-Received: by 2002:a05:6214:4003:b0:470:509a:290a with SMTP id kd3-20020a056214400300b00470509a290amr2620397qvb.24.1656401385931; Tue, 28 Jun 2022 00:29:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401385; cv=none; d=google.com; s=arc-20160816; b=MQ8WTA7zNNJEJxdiD51SRDRrQiYGdfx/jbwzG8KkHrAM7JWGOwGhNAlPt9CbmzZkzu gtMZiqCFuNVZIBSz2ESLIxMWo4uyudflTU1L9EOGrExs8ujLbkY4nVuqAB9F3w1X1dBG jh4h3pVWBM+S/OhWmCkfSCL4JZU9b591i9Tm1B9NZ8NmCdXkEgUINbKMHbdN4SK12QRA 8yf8hklsQuAyqqS0MOY2nwCMWThgOVsCkqI1mXP2ATqIGAJdRrfMLBpScGIey/rn1fD0 2xIdvF8oLBwY8Tnc6Si7HOfMuO/fhjGmNWwiJFOvOyPUbC3vZnz0MxwrfhjTKCDe7QmQ PDEw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=0Xz6wzUwopMbPAdNCjdjT86fVDAwIGV9xu3XdWWd8EM=; b=VNa3CTsK23Qs+xCm3j7rnmQzEzMmCPQTmfiHIoO0rBNsE8UdQJgAgFk+qc5ZhHk5uW mMLdP1m1kuB14T2HlSsjufPPd07FXl/pwS6YfTK7r1+/GJ3UjkFh8pWCm8VlkWUcANYe R6cIPhnRBKzwTcmUrIRvJDKkq7yJ1aBwenn8B7mfrr90Vp/eI/VFHoC8A+THSQx9iZkD AsJERyIlPaCAG7IDHBgB+Laibr0KhZ0k6/xXDSKHwFG980O2jheHNLDpqt6s540BMmNz DStZTBnk6WmpPD43C4wIjwwVbqQCJFFID8vCLIEtUwMTilxvpFGo15L2kgd+/9hq4NVA lkdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UL6ebudZ; 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=pass (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 x12-20020ac85f0c000000b00305168db4b9si7236358qta.199.2022.06.28.00.29.45 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:29: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=pass header.i=@linaro.org header.s=google header.b=UL6ebudZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52878 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65fN-0006mS-ED for patch@linaro.org; Tue, 28 Jun 2022 03:29:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43272) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FS-0003BF-6h for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:50 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:43737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FQ-0008Km-Gd for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:49 -0400 Received: by mail-pl1-x634.google.com with SMTP id r1so10016460plo.10 for ; Mon, 27 Jun 2022 21:54:47 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0Xz6wzUwopMbPAdNCjdjT86fVDAwIGV9xu3XdWWd8EM=; b=UL6ebudZa+CwFmlFs6UTQiOWt7qDttWtQkbTBs8kXxSot0mS/5GV1xkSIelsL7Cd+O KIXY/dDzoITqabyRnFknjGLt3TVAzIoKIKblinqCHgevviwh9wlnS1jo2kUSAoCmMtXq x0up7hZT/FrDM8GpteKIOgAlJdb84rwaM6WunADpMbQdN0guGrmWufjVlEfNO3jDZs+k ZF3BygtKqviTfhlFwqAUpd5r3ZMLT25GrxBx5pjhHypm2QcG/G0q7PhKPdUOppksPuZ3 I53YdLjezDwjrP6AnYxBToDLu37uQ9jjy8cOkdwkuK1Sv5fLpNF3mJ1ZKTNtZlldjohc Bi3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=0Xz6wzUwopMbPAdNCjdjT86fVDAwIGV9xu3XdWWd8EM=; b=FuW7Qr6hsb7Czk6SexfLD22SRxp0HUbChbMGS9LgLqViuCWaY4LWzQvT/f0aR73L0/ j+RHYxEsErwrdjew5U/pLzeH1adRv9uNRRSysxhWbyXLyEcmcOB8mqEZYXl4+5AIFY0j mtD/GHZXDFczohjxMN4gEJz+RGkNC0h58a6iMPNsxgsReJPTJQs4oVSGV3WBT1SEtPFL iPVE2+MyTlitEef/vCtfX63Tfpasa3JfcFQs6c+4u6i7sSIp2q7hKrgY54rcrIkMjKi6 Z0qq+nEUlV5Htfy3wSe1COadYfZdCNUCdp46LwNtdEtX3407wu7CFn7u8Dq1l0UD0JNh VJ+g== X-Gm-Message-State: AJIora86F+QZTS42HJ8weboAiAnivPzLOXxWz7XjfF7fS3ki7AmgDdD7 ZdBwrDeABoxgnUKK30FHhcU/WC3VoOKHOw== X-Received: by 2002:a17:902:9004:b0:16a:6808:e602 with SMTP id a4-20020a170902900400b0016a6808e602mr1825205plp.94.1656392086466; Mon, 27 Jun 2022 21:54:46 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 16/60] include/exec: Move gdb open flags to gdbstub.h Date: Tue, 28 Jun 2022 10:23:19 +0530 Message-Id: <20220628045403.508716-17-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" There were 3 copies of these flags. Place them in the file with gdb_do_syscall, with which they belong. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 9 +++++++++ semihosting/arm-compat-semi.c | 7 ------- target/m68k/m68k-semi.c | 8 -------- target/nios2/nios2-semi.c | 8 -------- 4 files changed, 9 insertions(+), 23 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c35d7334b4..603e22ae80 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,15 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 +/* For gdb file i/o remote protocol open flags. */ +#define GDB_O_RDONLY 0 +#define GDB_O_WRONLY 1 +#define GDB_O_RDWR 2 +#define GDB_O_APPEND 8 +#define GDB_O_CREAT 0x200 +#define GDB_O_TRUNC 0x400 +#define GDB_O_EXCL 0x800 + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 92c1375b15..abf543ce91 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -86,13 +86,6 @@ #define O_BINARY 0 #endif -#define GDB_O_RDONLY 0x000 -#define GDB_O_WRONLY 0x001 -#define GDB_O_RDWR 0x002 -#define GDB_O_APPEND 0x008 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 - static int gdb_open_modeflags[12] = { GDB_O_RDONLY, GDB_O_RDONLY, diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index a31db38fc3..475a6b13b7 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -69,14 +69,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 373e6b9436..0eec1f9a1c 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -71,14 +71,6 @@ struct gdb_timeval { uint64_t tv_usec; /* microsecond */ } QEMU_PACKED; -#define GDB_O_RDONLY 0x0 -#define GDB_O_WRONLY 0x1 -#define GDB_O_RDWR 0x2 -#define GDB_O_APPEND 0x8 -#define GDB_O_CREAT 0x200 -#define GDB_O_TRUNC 0x400 -#define GDB_O_EXCL 0x800 - static int translate_openflags(int flags) { int hf; From patchwork Tue Jun 28 04:53:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585520 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp472576mab; Mon, 27 Jun 2022 23:28:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvISjX03sdFpO+DlbU3tbfM3ekfbrftD8phPul+T3Su+FMGSaFKnlZ/LLEkg08BGeSZpWS X-Received: by 2002:a37:4247:0:b0:6ae:e75d:5989 with SMTP id p68-20020a374247000000b006aee75d5989mr10173632qka.470.1656397681563; Mon, 27 Jun 2022 23:28:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397681; cv=none; d=google.com; s=arc-20160816; b=L47AHYv6NbBD9G2czkajolYbp+ELYKdqgaFhT0wEhAMO/bjwabJjnmRxTu2N5vydO2 eiNtBuWh/jkfIbbQEcaJO1RfGcXN6gEOGV/XU09kmcpHCgSQCs4SVxZHOs4ZL5blH0DI h3fkNkF5aUr0puCfZz8hNeknhGdkyVrGLjEf6+Z3OsoVVoGSExGw7IWe6VRh65/TQf3N /3rhkLvlThf7yM2Rm365zQHmHJc5x3Nl797+VkeaS3pS8Y8IX/ZN3mAfK07V6zAijF0+ RAnh5Hkh7cDMB/RU6imJtEeAQqOQtHIg2TYebJSW0jNqN1pWXzDWQyD9owkBIWLv/gm5 Wltw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oxNDqSzg5Hw13giw27gxbf2VZjOoolDUxgjGkiB+OjI=; b=VtNk+WlnZ+83x6XSPEHxC7bddIR8HtENc4FBZvrABrl6D6DiWrcEBlB8wl0wDnvpS8 9bTBvO9orIvQOa8Fd1RQ4QwzjA0gG2D2EE/jYGOCihY7FhNNry91RwVcamdFmI4NxuI2 fRLxRc5aoJwsXj9NTgsCXqTWNZvjv/g1bSMQWtzDbQD/Xa4LfP8xXwPbCxHweHLOrO7u BMtR24zhB4+2lYaD23IrPRsBe1m5ge8fwfJtE0a+4KKg/zUQ6qPdsLN7LP/yj0nMevE8 3BTkpSZwJO2UsdM4K9QaerYFT2rvHgCQZ8WrFdFzj/W6EuPnj7Fdy+X83VLoqeJFuClJ gQ7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ndTeFlB+; 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=pass (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 gm5-20020a056214268500b004702e675f23si7350698qvb.407.2022.06.27.23.28.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:28:01 -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=pass header.i=@linaro.org header.s=google header.b=ndTeFlB+; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51040 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64hc-0002h8-LR for patch@linaro.org; Tue, 28 Jun 2022 02:28:00 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FT-0003DQ-RB for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:52 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:46058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FS-0008Ks-02 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:51 -0400 Received: by mail-pj1-x102b.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so6016270pji.4 for ; Mon, 27 Jun 2022 21:54:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oxNDqSzg5Hw13giw27gxbf2VZjOoolDUxgjGkiB+OjI=; b=ndTeFlB+l0d7nq/d0xZcknu9utwtxMmJ6hW7VdpcxJInFEABVVykGMvYr9ZgaaO11m m6W+HloFIhyquXhQgFx6JtLnrfnNvHFchRl/ng7vwHdTYmto/u1poZQkKGEZ8aSd2c9I 9CiK4pongDLmnKZHuXXsw+RQTs0B39WeVxexiWSxtPz8L1rblcbBYp8LOnGOFPcZB9xy 6Xum74LQ8RmLlhn/qBbYxIWzvnkFwRCo0s8SAZ5g6D+JoEv82NTAlJhiAeDcmajEOs7H GlkGFj+H5Yn22UtFg7tESv9996QpciTseD7ZfQTcUYUuC7NEr7tiVGhB2P8qsa6dtNED Vgsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oxNDqSzg5Hw13giw27gxbf2VZjOoolDUxgjGkiB+OjI=; b=4ZlL/5a39jolFLmbi/9yYCAyvrDEK0H39w/Xilni6geXcpMuGDOUnxXP8BC/U55Zov OYL/qc/+XW4UuQBZ32Pcblf6397XOLXx51Mz7CaiPePxf4Fd8SzsVCKxU8L8cFvxAMlG u9Beaq31nujYZdpSlNok1Pm6x3iyOrElTmOGKofoOWTRpMqSI4e3mn0gq1hcSoAz0Ilm vKeGUbs/TiB2bq/ubzl9XlDf2LZ1oJQ7FqjstWfoEh6AOzBzAleHIL+pDVyDFrRI6aa+ oF07TPYWF8re+o8roDT2BxIs2oo9X5rRIqn7fSfkod9SnmrofojEtpQa5oOGWyZdMNNp jw+g== X-Gm-Message-State: AJIora+MKVqMbRbQAV8nzgkAHey4Q96e/XbalFmH3YjoJb3uBDx7alSX huxk2EM/2NLqqpPHLX7u4cGhSPT1kUIY9Q== X-Received: by 2002:a17:90b:1982:b0:1ec:988f:e133 with SMTP id mv2-20020a17090b198200b001ec988fe133mr25462090pjb.211.1656392088748; Mon, 27 Jun 2022 21:54:48 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.46 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 17/60] include/exec: Move gdb_stat and gdb_timeval to gdbstub.h Date: Tue, 28 Jun 2022 10:23:20 +0530 Message-Id: <20220628045403.508716-18-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We have two copies of these structures, and require them in semihosting/ going forward. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 25 +++++++++++++++++++++++++ target/m68k/m68k-semi.c | 32 +++++--------------------------- target/nios2/nios2-semi.c | 30 +++--------------------------- 3 files changed, 33 insertions(+), 54 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 603e22ae80..7413ffeba2 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -19,6 +19,31 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o stat/fstat. */ +typedef uint32_t gdb_mode_t; +typedef uint32_t gdb_time_t; + +struct gdb_stat { + uint32_t gdb_st_dev; /* device */ + uint32_t gdb_st_ino; /* inode */ + gdb_mode_t gdb_st_mode; /* protection */ + uint32_t gdb_st_nlink; /* number of hard links */ + uint32_t gdb_st_uid; /* user ID of owner */ + uint32_t gdb_st_gid; /* group ID of owner */ + uint32_t gdb_st_rdev; /* device type (if inode device) */ + uint64_t gdb_st_size; /* total size, in bytes */ + uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ + uint64_t gdb_st_blocks; /* number of blocks allocated */ + gdb_time_t gdb_st_atime; /* time of last access */ + gdb_time_t gdb_st_mtime; /* time of last modification */ + gdb_time_t gdb_st_ctime; /* time of last change */ +} QEMU_PACKED; + +struct gdb_timeval { + gdb_time_t tv_sec; /* second */ + uint64_t tv_usec; /* microsecond */ +} QEMU_PACKED; + #ifdef NEED_CPU_H #include "cpu.h" diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 475a6b13b7..b886ebf714 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -45,30 +45,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct m68k_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -90,11 +66,13 @@ static int translate_openflags(int flags) static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) { - struct m68k_gdb_stat *p; + struct gdb_stat *p; - if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct m68k_gdb_stat), 0))) + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { /* FIXME - should this return an error code? */ return; + } p->gdb_st_dev = cpu_to_be32(s->st_dev); p->gdb_st_ino = cpu_to_be32(s->st_ino); p->gdb_st_mode = cpu_to_be32(s->st_mode); @@ -114,7 +92,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct m68k_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); } static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 0eec1f9a1c..3e504a6c5f 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -47,30 +47,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -typedef uint32_t gdb_mode_t; -typedef uint32_t gdb_time_t; - -struct nios2_gdb_stat { - uint32_t gdb_st_dev; /* device */ - uint32_t gdb_st_ino; /* inode */ - gdb_mode_t gdb_st_mode; /* protection */ - uint32_t gdb_st_nlink; /* number of hard links */ - uint32_t gdb_st_uid; /* user ID of owner */ - uint32_t gdb_st_gid; /* group ID of owner */ - uint32_t gdb_st_rdev; /* device type (if inode device) */ - uint64_t gdb_st_size; /* total size, in bytes */ - uint64_t gdb_st_blksize; /* blocksize for filesystem I/O */ - uint64_t gdb_st_blocks; /* number of blocks allocated */ - gdb_time_t gdb_st_atime; /* time of last access */ - gdb_time_t gdb_st_mtime; /* time of last modification */ - gdb_time_t gdb_st_ctime; /* time of last change */ -} QEMU_PACKED; - -struct gdb_timeval { - gdb_time_t tv_sec; /* second */ - uint64_t tv_usec; /* microsecond */ -} QEMU_PACKED; - static int translate_openflags(int flags) { int hf; @@ -102,9 +78,9 @@ static int translate_openflags(int flags) static bool translate_stat(CPUNios2State *env, target_ulong addr, struct stat *s) { - struct nios2_gdb_stat *p; + struct gdb_stat *p; - p = lock_user(VERIFY_WRITE, addr, sizeof(struct nios2_gdb_stat), 0); + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); if (!p) { return false; @@ -128,7 +104,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, p->gdb_st_atime = cpu_to_be32(s->st_atime); p->gdb_st_mtime = cpu_to_be32(s->st_mtime); p->gdb_st_ctime = cpu_to_be32(s->st_ctime); - unlock_user(p, addr, sizeof(struct nios2_gdb_stat)); + unlock_user(p, addr, sizeof(struct gdb_stat)); return true; } From patchwork Tue Jun 28 04:53:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585509 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp457663mab; Mon, 27 Jun 2022 23:02:49 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tungxRpbLzDwc+tuKO1iwkIaA0q+s0tJM3cNzZsMPxvAvUEYFFO6g8ByYQdaxtc7Leui6q X-Received: by 2002:ac8:570e:0:b0:31b:a5d7:1dd0 with SMTP id 14-20020ac8570e000000b0031ba5d71dd0mr3776661qtw.416.1656396169092; Mon, 27 Jun 2022 23:02:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396169; cv=none; d=google.com; s=arc-20160816; b=FfmyIDHzi3vOFNzeMFPSSfPIo0u9H+pCEoBSqMLcdGPPHxRqFIYGx1AlbsOOPXksIR 74Ur7jQKOE8cGyFgqzCFLbjYC5mKFkNUZxsFW0TUjOWLdVEB5C+/NBeOCcbDgVsnhh+I 2fr2QKO33AATgYLIsxcNTtfw+GsoyUz1SDU6UstUpUto8cVq+7wrsYkicxeY/ODMGd8W W5z9Wbr3lyzRoFy/7fS42a9WfrUhMr0FI4RV7S16upDVdOKJRXRl+N9vr/VhPu3VcjUI a8A6KKuNFvmpiI/YbW+t/oKN2d5mx8ZuCJVOmSSEDMkK+E38y9P/c9KKvb+YVzBDv2+9 NO9w== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NjQBlXjjbHpBXE089hJEGJBlz6b/dSudHA99LN0l1yc=; b=n/elJJ/TAtyyymlYuyaZLfTGGXOT6d2oZa1dIS3Wc5d+uIRAcFNVSeeIrcVcWQCItk ZHZ/m4dnuXm1kYMuRjXMYpeA5AwxpHH9kJRNn5yiR6+rqbJfqPTYSElz+sOfmWFPYLoK 8kMTe8m5dw6ML3rCiN8nOfSG4xqmc+Xqp8jLCufYrWG2RtejfXs6RDUYbuqRMMFMy+45 5l0Vuoy4FRIXBxqMx3Ru+PgMAKvJYVsEk2Q0DjR5c5Jfut3m653pxnWjowaH+y5nb1Jp pUGk5w1k1ZKxfwnJkUdrpKgrWdnsGGbMvBr4Pn+2qOmIpeWcjFfx8rW7QEC8AZrAZjoG LRlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xCXeg5zh; 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=pass (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 g20-20020ac85814000000b00304f4d49bd1si7410864qtg.574.2022.06.27.23.02.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:02:49 -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=pass header.i=@linaro.org header.s=google header.b=xCXeg5zh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48984 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64JC-0004MV-PI for patch@linaro.org; Tue, 28 Jun 2022 02:02:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43304) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FW-0003Ev-BC for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:55 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:42964) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FU-0008L7-Jc for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:53 -0400 Received: by mail-pl1-x634.google.com with SMTP id jb13so10016754plb.9 for ; Mon, 27 Jun 2022 21:54:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=NjQBlXjjbHpBXE089hJEGJBlz6b/dSudHA99LN0l1yc=; b=xCXeg5zhkteR4z5nAJ/sR0LDfQDaEIGXNiE3Erxf2tRLB/VS2xNNvLgTUFUSRjq9Fu 7u1/AuE+zeiZuUtCe8zBU7ARUKonHFJI/u5dBPcVI+2jeLWcS6A5ibQsiTpP0jStogqo xp03JLYUuRcQ7TD9S4dQS4XJRmiwF17U149m239vPjkqVc9b6OBQpc9ONcauLPRUshOA fhRT1TgJdAHNkk6ZDN1hE6K391g8zHWPDUHiqOhvqm7iMXFWzsotbAi3oGDYSEuCLPJ7 u9rPfD5XynkkbA0UXBuSY0QYIBWgmz0eEaI1MyzefgwQ52WiZ3AO1Q1abD+zfSXxY6SZ X8Vw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=NjQBlXjjbHpBXE089hJEGJBlz6b/dSudHA99LN0l1yc=; b=30BJrKJE0Pcm13AP7ZLfIJ+lIjmaYpwgzijM9Zs6oo1O7VSbAUAiEmY3pppYt0Sc+p tENONaY2uHnHQ/a/7553geQ/OKCtf29fy8pJFgiQFlMkxbJzFSKl1TIq1ua2k/oDxIqZ 0Wfuhi+MVK6PTajtXxw/PI+/iZWsJ3FIbx9l94aH1Gfc4cTbS5JTa1e5tkLVrxGdAxtX +horATm1Fy9FYuAau2eIOEbJfzhjkK82SjpmJ0ZBZwqZYnDDphgINLoR36O+8eM6rbWw 3oEusKRVN6bUy7Yo3JqUuDfcubi4ctTkhfibT7CeATDaywa4grsH+9vDr72ivXZr/wSS T4bA== X-Gm-Message-State: AJIora+1/Zqy1GOFZd+DkozHIOuDyJiOZlTDMNqob5Y0hmgVQVZkmXk0 Cu+fufBCNJfz49Qh8M6DWSC5bEGEHOLPlA== X-Received: by 2002:a17:902:e849:b0:16a:32d9:7226 with SMTP id t9-20020a170902e84900b0016a32d97226mr1778008plg.81.1656392091241; Mon, 27 Jun 2022 21:54:51 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 18/60] include/exec: Define errno values in gdbstub.h Date: Tue, 28 Jun 2022 10:23:21 +0530 Message-Id: <20220628045403.508716-19-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Define constants for the errno values defined by the gdb remote fileio protocol. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 7413ffeba2..95a8b7b056 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -19,6 +19,28 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o remote protocol errno values */ +#define GDB_EPERM 1 +#define GDB_ENOENT 2 +#define GDB_EINTR 4 +#define GDB_EBADF 9 +#define GDB_EACCES 13 +#define GDB_EFAULT 14 +#define GDB_EBUSY 16 +#define GDB_EEXIST 17 +#define GDB_ENODEV 19 +#define GDB_ENOTDIR 20 +#define GDB_EISDIR 21 +#define GDB_EINVAL 22 +#define GDB_ENFILE 23 +#define GDB_EMFILE 24 +#define GDB_EFBIG 27 +#define GDB_ENOSPC 28 +#define GDB_ESPIPE 29 +#define GDB_EROFS 30 +#define GDB_ENAMETOOLONG 91 +#define GDB_EUNKNOWN 9999 + /* For gdb file i/o stat/fstat. */ typedef uint32_t gdb_mode_t; typedef uint32_t gdb_time_t; From patchwork Tue Jun 28 04:53:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585513 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp461905mab; Mon, 27 Jun 2022 23:09:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uj18a72zAnrOKW1zWCAAnCFY+5l/n0v4WnwcUw4KCooDRcy360xQ4A5mcfsmLu5ZHleFmP X-Received: by 2002:a05:6214:3002:b0:470:7273:bee5 with SMTP id ke2-20020a056214300200b004707273bee5mr2348957qvb.98.1656396583591; Mon, 27 Jun 2022 23:09:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396583; cv=none; d=google.com; s=arc-20160816; b=hwTVbOXEAzVa0H/+LkzRAza+XhwFXUIz78vMZGonnLnk1fcZyuIBebRM8tHyJD0K08 /8foxAkSHZ2oxzTZF+UCS6H/7UDmGWdo/qEpz4cTZ/RcLvRJQmjV0dbSvItCxTxyGzmh +Kx9q4lsffH3LNOwSf7t53hIAHerJivVuNM8I9BpRyf60ZiRDZyHZ4JwaC6U7DZ/ILYJ xHABjoUcIgt74yjnyC8kkESAOBju/D4RXgXeUlO78PSSzITXPrCFxEL3rIqiDwqVOMqO nQa4+fHPFs6HOYsJ5WYwspZJ99/AEqIYoInNNwnVjtZcTwieZixZiR+MF+29Jk5pfw08 lqxQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=h8LQotJB86tKW7baXHd45kRYb/tuL0ssQ0shlDYqkXc=; b=e9u98conTMOYGRZK/szmxUz5jt0OaKlm2uaeW1H1s4pDkkMiTmnW+tiGOWAXWOjYyj ckKHK7raJwXxTeKKyfvaCcXvCtxcJtOZOEHqtyNFJebNgM9bsCbwt449AaHXSAbukUBM cEbJMxrh64nXOrBpyIJJp9TxF8nhMdEQHWRRW6edGrV+rF0gjg3q/Fqz7GXFaUtbblIM HCq6OgyYSSu9gRfHT9ByNoFbb35PYve0cNbZ6vzw2WSCAeZO/nOnzdL8m++vo2z+cz9F gb1APMK9Gkl5ovFQhNeZ/DwotpzGqHl6JBVAMVEjlJaTj3lRCxFJOsyUYpx0LEan2BC+ FRgw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Yb0ZDcXD; 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=pass (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 m19-20020a05620a291300b006a72f26bb07si5149727qkp.429.2022.06.27.23.09.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:09:43 -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=pass header.i=@linaro.org header.s=google header.b=Yb0ZDcXD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Pv-0001xv-4z for patch@linaro.org; Tue, 28 Jun 2022 02:09:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63FY-0003FC-Jc for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:58 -0400 Received: from mail-pl1-x634.google.com ([2607:f8b0:4864:20::634]:43737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FW-0008Km-4J for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:55 -0400 Received: by mail-pl1-x634.google.com with SMTP id r1so10016460plo.10 for ; Mon, 27 Jun 2022 21:54:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=h8LQotJB86tKW7baXHd45kRYb/tuL0ssQ0shlDYqkXc=; b=Yb0ZDcXD0G11W8UTrUonyloyWUOMF66yZUfWAK4MBwt6rY0klsKxImqCKi1TdLDK7R Ht2AuDaMrCFXb0XFQNh0Gumawx4beJRx5+C8gVAUkBGIIlEtVcitZ9bfMNYQ8vNVguQI 9VMZuVDOXwralfeXE4Ehp3oVzxt2K80Lk9FQJcoUHIEm67BGm24oCoYXrxGVlJKMCBnb ZIcpypFEI7z0F7/FznaCvALM9DslKuev+qXPP6AGGCQ0XUnXnfizrpOdOXhQqmraVEdB te+IiKYgg+6eH+aMRrcVtyZQWdRR6RNNDSEZDSzCpjV6eQ5ZU5k+66bNEFWB62zCPs5v thIA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=h8LQotJB86tKW7baXHd45kRYb/tuL0ssQ0shlDYqkXc=; b=oT0t1pQxSKVnFkUmhBH9DPpzgjymoA9RT4KTpidmvDkOZNPORqzqRokDv3RwCZhbHU EwrMLYzOOwN9ysPKHtfMr4qU2qZ8f3phDCeTCXjeYEPM1fggQJjR7ISLaoGEV6CkKkvF v20LEX3DxKRrvkV/KZZDJN6OAYQnqLgykdNzwrJcZ1emtrpjjyvt4mxgLGYigI5H0Xrw ISTTSVdGciL+3Hm7i9KjXncqZcJCVHuahW6xH3VsJDHfCp+Gwf7mntm86DTaBVJiT5hN P2sNv1dkOuLKMpwf5rMAgZg9UisVKYsWzwt4dWWm7Lw5e+6zyJfDDUsk1sJWjzf93qYW PWYg== X-Gm-Message-State: AJIora9qnHZeE+ne8nDRz+gx/RnYS0UoSME/dAx5q7KExkqET1qbaaVx AKlyoeX0o1AphtJ9sju6IuMIIIRYvUSuvA== X-Received: by 2002:a17:90a:dc81:b0:1ec:afea:3b17 with SMTP id j1-20020a17090adc8100b001ecafea3b17mr20353877pjv.203.1656392093386; Mon, 27 Jun 2022 21:54:53 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 19/60] gdbstub: Convert GDB error numbers to host error numbers Date: Tue, 28 Jun 2022 10:23:22 +0530 Message-Id: <20220628045403.508716-20-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::634; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x634.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Provide the callback with consistent state -- always use host error numbers. The individual callback can then decide if the errno requires conversion for the guest. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- gdbstub.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/gdbstub.c b/gdbstub.c index 88a34c8f52..f3a4664453 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1886,6 +1886,37 @@ static void handle_file_io(GArray *params, void *user_ctx) } else { err = 0; } + + /* Convert GDB error numbers back to host error numbers. */ +#define E(X) case GDB_E##X: err = E##X; break + switch (err) { + case 0: + break; + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(ACCES); + E(FAULT); + E(BUSY); + E(EXIST); + E(NODEV); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + default: + err = EINVAL; + break; + } +#undef E + gdbserver_state.current_syscall_cb(gdbserver_state.c_cpu, ret, err); gdbserver_state.current_syscall_cb = NULL; } From patchwork Tue Jun 28 04:53:23 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585548 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp513512mab; Tue, 28 Jun 2022 00:34:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uvpDSxZLDpDLoQXq11MQ8DkaSIsW9IARNuuc8Pv4AHqD/eJgJpHy2dgn1zL+unvMUsaW1+ X-Received: by 2002:a05:6214:ca7:b0:470:47dd:f449 with SMTP id s7-20020a0562140ca700b0047047ddf449mr2471324qvs.112.1656401692179; Tue, 28 Jun 2022 00:34:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401692; cv=none; d=google.com; s=arc-20160816; b=sQwJs7X2r/Bd68jKcyt9nUJOlLiEyB4fOPu9ZtwZDAK3tZpNgKiXWscwCM4a0zUmO6 zdvLibzk/oDb4VRI2Biz3yiXgzpWGhNc+LNoJL4QzKKWz7jUNwwA960m1BQUFnnX9nd6 Dkj1CEs/QluD8uQ2dmOmEJC1niaM/N4m5qfBrx0bEunaN14lhdcrcg2H0TFS9lm5r1do BrOET7N6YCHnmPFklwq2fgfAdx8Wl29tOCw0T1GflU/D0v4lmvuOIcgOwa+WWp+0GdDt Od6tOkCr8ESSTm7goT1tiTtTf0I9hvpYzrJTZUoNGNZ9nPJbNlbg2V537nP52snEQ6bj 6g1g== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+SUmfyQ28nnP+FCpGEWeUk9jn7QL0Ax1+bQ0aHyUN6Q=; b=x6KBFvKh3HgFDO4c0mvW92iMc5oz2lMbtxn632WBEqlBpE8zD5VQiC7jVnH3/T8FPX 1FCnEF7T+1j1tAbTZjU4za0O6WeFMX0AWiJZxVV3At5RoHRGI81AvSdpqvcpowfNCFyv 7CN2xRK/H3cyodyoUjksReRYi8KFNZaMwEcoB4w4DM2DHHLC3tedcTS3DcsF9xRrnOh0 j88kaBBL20QeuNEPPdF1Wq6pFnFlwfYirG3M6ZShgfX6yEHb3AW/ro4Ge5hc/Dcyr5cI nTdsTkl1sM6LTlT3XGPwMCJIBaN/SGhXlvq+3VU3qcUE0yrF576Z2+PhFIEuofaJuOFf rSSw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="zpGw/8zC"; 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=pass (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 i8-20020ac85e48000000b003052dd970ddsi7405726qtx.187.2022.06.28.00.34.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:34:52 -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=pass header.i=@linaro.org header.s=google header.b="zpGw/8zC"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33500 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65kJ-0005An-OZ for patch@linaro.org; Tue, 28 Jun 2022 03:34:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fd-0003G8-4r for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:03 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:53002) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63FZ-0008Is-SX for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:54:59 -0400 Received: by mail-pj1-x102a.google.com with SMTP id g7so6378232pjj.2 for ; Mon, 27 Jun 2022 21:54:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+SUmfyQ28nnP+FCpGEWeUk9jn7QL0Ax1+bQ0aHyUN6Q=; b=zpGw/8zCcCCsYwIGhp8OeQD6dM2dXFiG1oNAMKh/bMmyAp7tfZvezrs+eaRHfvV/c4 m/m6JrQdpawQnGZe9/zM+kAOwqh8Bq4RL6PTuOpvw9xzYRhBIaBX9+7kfNIQoHKTiwm/ /zHVtUQUX+cuBp1ooh1XEs6BTbPtg53YW4UsIkQaPPKaYysF33cqVdwNKna/7yyGNIWM dM4GUSFFrlCt9Ioi27df3MPimbj/pKJf82Z478Vpd8CXBn569mpRgSza3kAQWVpalmD7 VG9+bq5ovnUwEY9RoFcxkBUtKc2q90/3Fs5BO9E02tlTLGg5de8Wp2ie5p17Td2P5nRw LM0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+SUmfyQ28nnP+FCpGEWeUk9jn7QL0Ax1+bQ0aHyUN6Q=; b=5RjA/qlJMbQaHNAWovf3uUnLdFvjaA6ZflAC5dZvAsxJQRL4nmVgqDUNwI5jjWv37N t9RTkgI57Lu67HyMGtTGm6nh4w7TooNi5RButRPvhaTdintkZz16R2n9yiwGa/9kwT7v IwEav1g2KvMkRh9gRBbuJfMvhOFVW+2aTeB+l8pRItn36lpj0O+8U8o58oWEEiK5TPnX BTQ89oXw6sy0s/qIETu04OIXrjC+uoOMtBtwpCIlO1wThsQz4XNc1AzENZ4MbUAsvvQL 6TIdlJONwTYyPiND+GylMWsg8sx2vEwNUwx5mlEqjTTRdEJ1hB5UklqGqRGgfZoe/e9M w6tQ== X-Gm-Message-State: AJIora+u7XWWuiYfRkJmJ5P4WIdfspfhQMCSaP5ork/RXBrxd/qIxVZI KYqiUTn4Xsr2VnF8DQMarAilrxNB7OIQ2A== X-Received: by 2002:a17:90a:8413:b0:1ea:ebf4:7079 with SMTP id j19-20020a17090a841300b001eaebf47079mr20506313pjn.48.1656392095753; Mon, 27 Jun 2022 21:54:55 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell Subject: [PULL 20/60] semihosting: Use struct gdb_stat in common_semi_flen_cb Date: Tue, 28 Jun 2022 10:23:23 +0530 Message-Id: <20220628045403.508716-21-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102a; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Load the entire 64-bit size value. While we're at it, use offsetof instead of an integer constant. Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index abf543ce91..a9e488886a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -325,14 +325,12 @@ static void common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (!err) { - /* - * The size is always stored in big-endian order, extract - * the value. We assume the size always fit in 32 bits. - */ - uint32_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, - (uint8_t *)&size, 4, 0); - ret = be32_to_cpu(size); + /* The size is always stored in big-endian order, extract the value. */ + uint64_t size; + cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0); + ret = be64_to_cpu(size); } common_semi_cb(cs, ret, err); } From patchwork Tue Jun 28 04:53:24 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585523 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp477564mab; Mon, 27 Jun 2022 23:36:08 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u11ipOKGppBYpdO218wtUEKgElBXcRAZUUdLqcLFMwiMb2xfPg6/tvMwxKRt3WmXV8JW+j X-Received: by 2002:a37:a215:0:b0:6af:cf8:dda7 with SMTP id l21-20020a37a215000000b006af0cf8dda7mr9689312qke.180.1656398168081; Mon, 27 Jun 2022 23:36:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398168; cv=none; d=google.com; s=arc-20160816; b=i8yNVhJaa5zkgQMNO/XA8plXqAKk/UxjW0IJDBMHm9Y9uoNAgMPFDheletczfCfGtR 1vwEWHsykgRxAcInCTgfNQK7HpV0i3gNtVWEgv3Sr3tj4LwR2EsPH8p9my8JUx4D7zFY u7P6APFz8cpaP1QLwiV24WTChrvCcG2T4MJgLXyUjyo6BhJjr6+uSVaD6PDZeHT9Xm00 f6b2DCRtisBBB9tWxPQ3BqfCC5g0+TkQmMVNCXLQ8eR+qPMqsXpJejQs/7msowQ7z/KW G1UFO8JlC0S/HlmBeVQJLY6RYP49ezdewjrPPARPY3VM67VCCSWpoaxsypXwpXcZJNiE UvBA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=97oCc36lcB1BPvxIKIrtIrCafpxgp+n+HDsHM7STsDo=; b=h6wEeuZTUj5nW2jZ4hdHuHMqRCbKYYGVjuOJD/jmiis0WlcGZbkK4Vw4zbmAsEi+cx c30/CWXl+w+HJqSNP1VcdSU2ntdKe1Uc16zC4a0cop4JpIEPagaEruztH0JBSejTqSHV 37VOobfLA1RB1RJ4Pxl1YZHnm4m2pRyn5c8TDRjwE+yolU031FT3JvEfCCMv+Ng1vDys zEoSWtJnp5vMf4PcQ+PhXhruf8azy5ROQVm4VM25H0YAb/DKsZ9tPhgLlwkAqKAvxzYK X7VrCmtN5SvqYPTQgxWvs1m938Oc7Xlrv2reGY7edNjZaKzX7zxYDri7S2dW/Hv8m/gc RyNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W4New5dC; 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=pass (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 t8-20020a0562140c6800b004703c6466a4si6516742qvj.271.2022.06.27.23.36.08 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:36:08 -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=pass header.i=@linaro.org header.s=google header.b=W4New5dC; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60002 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64pT-0000hG-IR for patch@linaro.org; Tue, 28 Jun 2022 02:36:07 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fe-0003GH-F6 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:03 -0400 Received: from mail-pf1-x435.google.com ([2607:f8b0:4864:20::435]:37444) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fc-0008Lk-TT for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:02 -0400 Received: by mail-pf1-x435.google.com with SMTP id bo5so10957168pfb.4 for ; Mon, 27 Jun 2022 21:54:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=97oCc36lcB1BPvxIKIrtIrCafpxgp+n+HDsHM7STsDo=; b=W4New5dCkHRHgaHOrYGtDqAhzNjhDlaLyP3CITzTlSwcPfTlyAAdwSdr6nr6XxjAtq I2wNfTJPeufqD2OhC7n/H55w2sevvhsTEctC1y5xbi8G5McgWjfxJ5y0mUTpZMvJelaw vV67swn4zGzmMGsmjDP5lFHyPGDt52lIn9gNo6OzfH7P+OXzXqFpGxfwz+C1lfoy9Z3u RXBMsuzseSNGHBeknl86LGwjxRifKO63gnDyD6qInaMhIAVQy1IbNHBipCTVHUcd71Ey qF0bmmOcTHEJYIf6fKU0uSMBg0l1fj7ahA1ITxU1/i3zCilxVcy/wjVRQiT0wk0GwB0+ mstA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=97oCc36lcB1BPvxIKIrtIrCafpxgp+n+HDsHM7STsDo=; b=yOnfq/PnvPowkwLynTs5FAY+zcLJg6CFHtVDJV9BwIryTsTRSkGEKcdj42OvPMVqpR htOSWbZ8QKwHPuEIBevs9qdyLghEOvDyrLXNadljaTeARdceX4AFgHMO8aY2NFee9p4V BSLSZ5RbyZJ4Kgd1WlCRpxqdZZhP7+B1YudHPaxPPfKpGT8fanR8OkYKiW1l3aLFANah 0qP+4CLAKXOPcfrMOUmG2riOCaBtveYPS0rvcsEj1TzU+Pq+LBdqM5A7DdnNoQNYX5wM QnpmtBlLUNxfv7O9tWaIEKq4uq0IdoHdVvNgCr63jKQKzb95LKFIQ09o27N0u8AUZl8L 2wyQ== X-Gm-Message-State: AJIora/wG1JrqJCBgine+JgFx/WFz8SxNDhoDN64xZKDcnZs6PmWCRUu omZCKxpw2Gbhr/OixltfORUzlEhQOetkXw== X-Received: by 2002:a63:a749:0:b0:40c:57e0:86c0 with SMTP id w9-20020a63a749000000b0040c57e086c0mr15924234pgo.265.1656392098640; Mon, 27 Jun 2022 21:54:58 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:54:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Alistair Francis Subject: [PULL 21/60] semihosting: Split is_64bit_semihosting per target Date: Tue, 28 Jun 2022 10:23:24 +0530 Message-Id: <20220628045403.508716-22-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::435; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x435.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We already have some larger ifdef blocks for ARM and RISCV; split the function into multiple implementations per arch. Reviewed-by: Peter Maydell Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index a9e488886a..d2ce214078 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -213,6 +213,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -238,6 +242,10 @@ common_semi_sys_exit_extended(CPUState *cs, int nr) return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); } +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} #endif /* @@ -587,17 +595,6 @@ static const GuestFDFunctions guestfd_fns[] = { * call if the memory read fails. Eventually we could use a generic * CPUState helper function here. */ -static inline bool is_64bit_semihosting(CPUArchState *env) -{ -#if defined(TARGET_ARM) - return is_a64(env); -#elif defined(TARGET_RISCV) - return riscv_cpu_mxl(env) != MXL_RV32; -#else -#error un-handled architecture -#endif -} - #define GET_ARG(n) do { \ if (is_64bit_semihosting(env)) { \ From patchwork Tue Jun 28 04:53:25 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585549 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp515903mab; Tue, 28 Jun 2022 00:39:02 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tuGxdJ1/x5w5PnBJuULxzRzdSLXkmLR7YoMXqp42+0wSXRCOD3ytp5I1rg/Bo5zob4mTTx X-Received: by 2002:ae9:f718:0:b0:6af:5c0:6cdf with SMTP id s24-20020ae9f718000000b006af05c06cdfmr10559200qkg.426.1656401942484; Tue, 28 Jun 2022 00:39:02 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401942; cv=none; d=google.com; s=arc-20160816; b=c5F+0B6k98QYoAt8cDi7g6QYjw1G7P+PFzAZziP/0dmffXBHYeGop92JByXI5zabfA 76Lx/Gc/BQ2RYVDs1SVINaDBMH2YC6kGm5cm1Qssje0R8+WiOYifVeZNbBuKntn2o3nQ XtMHg4KzpRcHkgu7O05uz8GwI25T5nCApalRDFT56I4ufL7erEpSkJCuTJ7y0ry1rIPD kAdtYyN3iuPvq5sjaipZ8Lol/Kby+Dcoca9xi/CcEwcwRcieWgDpoOwFxsJHuwDZiNY1 EbxiwwdrgclD5ULu3kmRHChfu6OuCWzp3fSe5AxvR/7e5KQxx0/vfekdjW+9kC4T+20l u0SA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zVpqLWTsPExWd6f8jF1EY/VDSSozWoVLxOFKhLPqh5c=; b=BMuSFjRkCsQhRbNJHzvLMQo2DLoXWWuxsbim4ILLdZx8bLaToZci6zVORAe2WX7g4t oQVYvTgATbk3841q35gzIMz2QMhai9Ab1iw6tT+xViEhhMM+iDm24F8vs+OCzDuec5AJ TzXg+m9ESo7P9mT3tNr16ZgiGmnlx1U+cyfQ7cqvURvrc5iT/fa2oostW1XYEciWlanY 0gAPFoL1JRSVtvWgsDOKsH8izqGxsgE3NteARg3jcsPrw2nl7udaVTXr+aEKEvuFz4cH H2axsXazxyFBnAKfLFUcVu3z+uxhqoYT2hsItfntEIoD+IoOKjzMUZVlEKF7LjWWf1i/ 7tYQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=UhoFZJZJ; 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=pass (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 o18-20020a05622a139200b00306fd63b901si5838261qtk.105.2022.06.28.00.39.02 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:39:02 -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=pass header.i=@linaro.org header.s=google header.b=UhoFZJZJ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:42000 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65oL-0002YU-Vd for patch@linaro.org; Tue, 28 Jun 2022 03:39:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43390) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fh-0003H7-Eh for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:06 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:42606) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fe-0008M2-PU for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:04 -0400 Received: by mail-pg1-x536.google.com with SMTP id d129so11056785pgc.9 for ; Mon, 27 Jun 2022 21:55:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zVpqLWTsPExWd6f8jF1EY/VDSSozWoVLxOFKhLPqh5c=; b=UhoFZJZJ7sf6X6sDYSJ8kTUIHJnjrJP35kzXRhk1u5KJpN92OMg6fqNgAcj7Iz9h9B Af0kPXlAAmiOOghBCSYt6A7+LWnT1ihWPwkqXFEXJnwPURNLaJ8pX28Zul3Wq096sO85 nIX5TPGgjO4Kwq8GlREq8jMjG4+Xpzt2wm70Tn2oMbjoXh8suf4pmfz4ZijmFCjda3DN 83FoTide3wolQjJAeCTnLDVxZx9m8dg4U6KU2RKISdO46BdCHCHMFTMKK4d6tHb9gpC3 aK804d607hTjEbVZxhe2192SbMoHWVfLjRxVA/HWDatfYqkYshqRTDx1ZFnysslOZd1u xhVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zVpqLWTsPExWd6f8jF1EY/VDSSozWoVLxOFKhLPqh5c=; b=ZB2cQ3gGeMP1DSOiXrGoWxNOMRFwJOtyYLRZiFy4l+7g3iLnijudV1X2vIkJ0bTNRI 6Qi7XDdJ1WWDgcIZoGfi06DNJOfuQ/Ggy9LhYKNvnUaFkwjHdk4tXIyBjRzWIppDW0j8 E5Mnd7U8f/22WIvZbCQFhvLbUee/ki7dTCNsiqYe/Lq2F44UCB/XtUhcUeqdw3xnUBJX 3uI83afAaYQy9jlFazlZJNjvuQXEP4Oqc9zNpp/35L9y+ltAhFKe2Iy325ARQ/OatRDf iY4cvR955FDt/PfnCprLwtecPTmoHEC7u0q0WF08rUuY2ZgLXleiWNwDF+ixwmBMig+R /kcg== X-Gm-Message-State: AJIora+0sCyiZavLBsISkFDB5Ey8Tc6BO5Ifu75dB5wtrIsYSVOVSbgr wH65FrdLhcd6wIYxEq9YkMlfVFT50tv2DQ== X-Received: by 2002:a63:81c1:0:b0:411:6433:b4ba with SMTP id t184-20020a6381c1000000b004116433b4bamr19251pgd.585.1656392101383; Mon, 27 Jun 2022 21:55:01 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.54.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , Alistair Francis Subject: [PULL 22/60] semihosting: Split common_semi_flen_buf per target Date: Tue, 28 Jun 2022 10:23:25 +0530 Message-Id: <20220628045403.508716-23-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We already have some larger ifdef blocks for ARM and RISCV; split out common_semi_stack_bottom per target. Reviewed-by: Peter Maydell Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 44 +++++++++++++++++------------------ 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index d2ce214078..7550dce622 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -217,6 +217,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return is_a64(env); } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -246,6 +253,13 @@ static inline bool is_64bit_semihosting(CPUArchState *env) { return riscv_cpu_mxl(env) != MXL_RV32; } + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} #endif /* @@ -301,31 +315,15 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * Return an address in target memory of 64 bytes where the remote + * gdb should write its stat struct. (The format of this structure + * is defined by GDB's remote protocol and is not target-specific.) + * We put this on the guest's stack just below SP. + */ static target_ulong common_semi_flen_buf(CPUState *cs) { - target_ulong sp; -#ifdef TARGET_ARM - /* Return an address in target memory of 64 bytes where the remote - * gdb should write its stat struct. (The format of this structure - * is defined by GDB's remote protocol and is not target-specific.) - * We put this on the guest's stack just below SP. - */ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - - if (is_a64(env)) { - sp = env->xregs[31]; - } else { - sp = env->regs[13]; - } -#endif -#ifdef TARGET_RISCV - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - - sp = env->gpr[xSP]; -#endif - + target_ulong sp = common_semi_stack_bottom(cs); return sp - 64; } From patchwork Tue Jun 28 04:53:26 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585516 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp464855mab; Mon, 27 Jun 2022 23:14:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vT+9vUEC4jLEtFcslMC0kT1X17JYx7jcEDV3UnT66eMDACisGFrZceVVeOYF7+22FFymKo X-Received: by 2002:ad4:594f:0:b0:470:5b16:808 with SMTP id eo15-20020ad4594f000000b004705b160808mr2365394qvb.51.1656396878006; Mon, 27 Jun 2022 23:14:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396878; cv=none; d=google.com; s=arc-20160816; b=UYB/iHNDeBZZtV4Pp1sBzn7kNeStZ6CB+XELyzdOfxhgprlOoaI2eHFfwzoTvkD6LY +Ukzq4tGFSHvZw77c1loP00in19xbk3z0lfKvOQNUHZ69U96NTrjGGM1xTL9/3Nk4tv0 Hpo5pASIwMsmb0GqkJ7cWuYsTDJgLaZXdTZoZ2mdxo63KcIPLJGopr3G0+gXxvSbMCG6 HaXqtIDnjPiEDQKFmWeeprncYLBbHN9in+eyAYmEx4hvxUYQevZ1E3BxuDPCtUudbZhW CTNg1rtLy2p9Ci0Th91dAy91vNml2iLaXOXaYrbQAEYrN5O4WV3iFLelvw5js6jh7cgM xLJQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=Lkal5KDK4537KjIiM5DwOIkXPoQZ/flNccQ9lkg/eXQ=; b=u/Fe6azSe461S8d5AVyIvMXu+yB5uLCrkP1mBZ0wXBurU/s/o6TMt5OfWqgPVPDgPR L8w9Vt7kmVmhwp94hHb86YVw1wNIxsxl9nxBA7wt5trZex8Zh+kUizGd3byeEb+M+0FB LpVVj4FJHS3OS7Gv3rB6W7k3k/fdGDB67BEDEChY0kyum0TCSHbD5CcW3UzTsIUChFMT HX/FCSp1P3UQS5jI/d9bz2u2jR4P60piS7FSXwFytLMZd/nxDl4fXX9FZ+GSOx9wtJfn 1MjM8Sf6jA2z5maYNnr5dmJwVOvr1d1KW8tbCY5R9kE0QIapxsxOk/iR9a4ajh2fA26q 9Hew== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=N9DoaUCi; 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=pass (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 l11-20020a05622a050b00b003050a104479si7856540qtx.268.2022.06.27.23.14.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:14:38 -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=pass header.i=@linaro.org header.s=google header.b=N9DoaUCi; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:37874 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Uf-0000IQ-HO for patch@linaro.org; Tue, 28 Jun 2022 02:14:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43438) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fk-0003IS-7e for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:08 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:41844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fh-0008MN-7B for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:07 -0400 Received: by mail-pf1-x433.google.com with SMTP id i64so10930283pfc.8 for ; Mon, 27 Jun 2022 21:55:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Lkal5KDK4537KjIiM5DwOIkXPoQZ/flNccQ9lkg/eXQ=; b=N9DoaUCiXErs7MF3E7SpMzgtl2eyhVKm5dFsrkV+kACpDJ+lXFXFWs1dX0wlF3/kKu mYY+bJDGyVeGhpy5APu/J7iHPPyO2ply8VWqu7PI+al/kTEbnrJMLlK7KOeyAJiZY1aG c2Izsxj+OxnLt56m+EiJllTAzmfWBoP4j3YhyodELyW227C7g1p0EqI07VPMExKxBeOl VMEMSy0oTyA6O5qRAdcV//+eSPyOv16h4xVaV5iqUD9VAGUW4tIGdOTDIwFEFbdXqjgs mXu2bgBeuZkAy5009qPw/emWTU3AfdpuBGbWrnSzBFC0xelU0zT31xdyA6Tscd0Hsi7y e8wQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Lkal5KDK4537KjIiM5DwOIkXPoQZ/flNccQ9lkg/eXQ=; b=fGwGJ2W4qOOV5YPwY5QBfAZkgPO9DgbsarQGWryWy/3q5jcxk71Dsn/kXD3TTujRk1 uU4IXV5v9j3D2PQqgezgzJly30Sxq5wXSln06EihHM1zyXMJ/4dycCZqeeZ6f0Ymxwm6 Z7K2zhZqKxr4y5SMIkBzY8xbelYkGPkupwKVFdCojGSRmfP0iRZ5APSxT5Iustt/kqvG M9Tz0rbYtKqVYtf8RX2slfZkRovKY/r81Usa77WazmYzF7bxBIoYTgkBuwHKP6CDvsVu PAWr+i75J+uJFps2gNblsNWRjFzt/ir7rjkmL+89tXqrLmZv8DUmFxPZxSvLvwyOOfju TvoA== X-Gm-Message-State: AJIora/rm8eRg4QkP0be2haIN1mEF6APv+utdARb/rIrFKpkvufQv9cV EPI52N2Y7Ot/utuTKqxJmAL5IfNakMPWBA== X-Received: by 2002:a63:1613:0:b0:411:51f0:eaf8 with SMTP id w19-20020a631613000000b0041151f0eaf8mr3186813pgl.62.1656392103637; Mon, 27 Jun 2022 21:55:03 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Alistair Francis Subject: [PULL 23/60] semihosting: Split out common_semi_has_synccache Date: Tue, 28 Jun 2022 10:23:26 +0530 Message-Id: <20220628045403.508716-24-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::433; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x433.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We already have some larger ifdef blocks for ARM and RISCV; split out a boolean test for SYS_SYNCCACHE. Reviewed-by: Alistair Francis Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7550dce622..50f40a2a1a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -224,6 +224,12 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPUARMState *env = &cpu->env; return is_a64(env) ? env->xregs[31] : env->regs[13]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Ok for A64, invalid for A32/T32. */ + return is_a64(env); +} #endif /* TARGET_ARM */ #ifdef TARGET_RISCV @@ -260,6 +266,11 @@ static inline target_ulong common_semi_stack_bottom(CPUState *cs) CPURISCVState *env = &cpu->env; return env->gpr[xSP]; } + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} #endif /* @@ -1102,16 +1113,11 @@ void do_common_semihosting(CPUState *cs) * virtual address range. This is a nop for us since we don't * implement caches. This is only present on A64. */ -#ifdef TARGET_ARM - if (is_a64(cs->env_ptr)) { + if (common_semi_has_synccache(env)) { common_semi_set_ret(cs, 0); break; } -#endif -#ifdef TARGET_RISCV - common_semi_set_ret(cs, 0); -#endif - /* fall through -- invalid for A32/T32 */ + /* fall through */ default: fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr); cpu_dump_state(cs, stderr, 0); From patchwork Tue Jun 28 04:53:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585518 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp469359mab; Mon, 27 Jun 2022 23:22:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tUmM8XO2GeDhhtT11BHKM7MnXdIKaDgoHXniGQ+aJMTgb9mjdpzXEvuXmIUIvkdtx+Ryp7 X-Received: by 2002:ac8:5c96:0:b0:31a:c19a:7da1 with SMTP id r22-20020ac85c96000000b0031ac19a7da1mr5599318qta.62.1656397344581; Mon, 27 Jun 2022 23:22:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397344; cv=none; d=google.com; s=arc-20160816; b=reEmz9jg+18iAjFKc4tJLfuOf6oIEGrsOdIXrh8yWSP+LuR1GHdkkHLLpr0Lcbwv16 JA2YABEuD2dhCLH+f/PihTZrK989S1h73KnzrAY8/6GpZnV2fS3fR+cwZtP8aIKmAkQg RcBb9qfnxYyMCbazFmn/yTjRRlNSEm21vOaWVzFAdQlAWQUAvKt9RvaH9LLc8tzd/feX ypfnqiqMxljKULFBjEkkKZjZPZkrtW9eGsdtcx0YtdG3gzDHiO3gDrMAUnE2URufOedA z5tEeIn0egkhjNUuCHWEJ7aDiAMvx1gjY5C6HX0asmkjuunXouR7+boZ6NFZy79Mptis UsAw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=yLewmFCQYfYKQ8zF22ZeW0whi874jiIombKuJNnln/U=; b=zkO4sqt0HjOGq2UJV2NTH4aq9zTBtRuhFpffrBztE+KEpfO638yN/5bj4ooBoRHIGW OTs+uygiu6RZjGnRmkglJ5ydKyALTGziSW7yh8Fu+FDU2MKsUuD+IsY0loE27KlG8kWa ME3OnaWeXxgFyuSj+PSgHnADrY+7SOeKBVzf6tUhWZ5t9TYuuEtnqqaOBgBrfR1sPNmj 6LozMiDbZqpZ3L1xfQd09wqa1ek60Q0aJOaa+c8D3mIF4Pv6fi6weL1HkC3pDoWwT1tl 2ILaH39cUss/HLo4NeoSlzceAPACQzOs/7AMDBNDwB4WGz/IrOiuRRHiwybNlSXZcpmp wT7Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dllIxhJq; 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=pass (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 o5-20020a05622a008500b0031777b47163si7982576qtw.421.2022.06.27.23.22.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:22: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=pass header.i=@linaro.org header.s=google header.b=dllIxhJq; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64cC-0007Sk-3b for patch@linaro.org; Tue, 28 Jun 2022 02:22:24 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43480) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fm-0003Jy-JN for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:10 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:41699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fj-0008Mm-VX for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:09 -0400 Received: by mail-pg1-x530.google.com with SMTP id 23so11059700pgc.8 for ; Mon, 27 Jun 2022 21:55:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=yLewmFCQYfYKQ8zF22ZeW0whi874jiIombKuJNnln/U=; b=dllIxhJqlHD9P6Hlp7OHxtF3aLxNW+05S00uU3IKw1tZ5tMBupdeSA5DeVTJZZxWW0 XHXDIhDSrTARzKro6OIUUzcrAQ5i8/N/oHXIxTf81NVjHbgJZCVDDV9ZekfgpAecHDTq hcpbTGlKK5j7YS8SI5XPNMzNVvE6X0gzzjCxLStV2itSUaohBE5f/a+ExTbN28cO+gpC e8mjfHTa5to+Ke5eLbBRJpAoCk2lyocM0yrps8bP3JaeV7FhYdu8ejsgTWOd1DMxGE8c WNpcPAV2Fd/SAXFZOOneNyfBu3FQOslW0dqhoRk65YdIyum2iWVEDS1QjtJ5JLv4ajxl lBZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=yLewmFCQYfYKQ8zF22ZeW0whi874jiIombKuJNnln/U=; b=VKEuad/F0nU+Mlqnl4RPwVUIZT1E70Gv4ujfhhOZSP4FWofWTbUeFYjpBWs1c0YBnY tZwEB+EeO6rllCNbYL+DkgSyiPdU+FnghVb40l6UbF+i2wSnvKL09leFsEwYpQ4pdrLx SUO3ZMmXHfJA5G/Vmn3nRafyaqBQ9wMKnkAPZ+C1YautNsbc2TpJfV0eCV2s3gGp/P49 F1u94IKrVflapzN3co6KvcsVpfljzy8J3MDb1Xh9TkWEwzalyAKoI4uHpy0D5pGeuAjq p0kW2cvFinijrrXyHBTYQGmY7eozACE7wwts32Cd2OWFRt4xkLt4LUH5F2gVLusI5qSU MDZw== X-Gm-Message-State: AJIora/GPuu8heQ2GjtoouSzKYAZtF0MSXYTWLpgwcTkby+N8K3AzFgi UlO/cfEfxB/YJRVQzixXhqWRTOqsZfIB/g== X-Received: by 2002:a63:9c01:0:b0:40c:e842:ff5e with SMTP id f1-20020a639c01000000b0040ce842ff5emr15832681pge.145.1656392106335; Mon, 27 Jun 2022 21:55:06 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Luc Michel Subject: [PULL 24/60] semihosting: Split out common-semi-target.h Date: Tue, 28 Jun 2022 10:23:27 +0530 Message-Id: <20220628045403.508716-25-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Move the ARM and RISCV specific helpers into their own header file. Reviewed-by: Alex Bennée Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- target/arm/common-semi-target.h | 62 ++++++++++++++++++++ target/riscv/common-semi-target.h | 50 ++++++++++++++++ semihosting/arm-compat-semi.c | 94 +------------------------------ 3 files changed, 113 insertions(+), 93 deletions(-) create mode 100644 target/arm/common-semi-target.h create mode 100644 target/riscv/common-semi-target.h diff --git a/target/arm/common-semi-target.h b/target/arm/common-semi-target.h new file mode 100644 index 0000000000..629d75ca5a --- /dev/null +++ b/target/arm/common-semi-target.h @@ -0,0 +1,62 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_ARM_COMMON_SEMI_TARGET_H +#define TARGET_ARM_COMMON_SEMI_TARGET_H + +#ifndef CONFIG_USER_ONLY +#include "hw/arm/boot.h" +#endif + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + return env->xregs[argno]; + } else { + return env->regs[argno]; + } +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + if (is_a64(env)) { + env->xregs[0] = ret; + } else { + env->regs[0] = ret; + } +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return is_a64(env); +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + ARMCPU *cpu = ARM_CPU(cs); + CPUARMState *env = &cpu->env; + return is_a64(env) ? env->xregs[31] : env->regs[13]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + /* Ok for A64, invalid for A32/T32 */ + return is_a64(env); +} + +#endif diff --git a/target/riscv/common-semi-target.h b/target/riscv/common-semi-target.h new file mode 100644 index 0000000000..7c8a59e0cc --- /dev/null +++ b/target/riscv/common-semi-target.h @@ -0,0 +1,50 @@ +/* + * Target-specific parts of semihosting/arm-compat-semi.c. + * + * Copyright (c) 2005, 2007 CodeSourcery. + * Copyright (c) 2019, 2022 Linaro + * Copyright © 2020 by Keith Packard + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef TARGET_RISCV_COMMON_SEMI_TARGET_H +#define TARGET_RISCV_COMMON_SEMI_TARGET_H + +static inline target_ulong common_semi_arg(CPUState *cs, int argno) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xA0 + argno]; +} + +static inline void common_semi_set_ret(CPUState *cs, target_ulong ret) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + env->gpr[xA0] = ret; +} + +static inline bool common_semi_sys_exit_extended(CPUState *cs, int nr) +{ + return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); +} + +static inline bool is_64bit_semihosting(CPUArchState *env) +{ + return riscv_cpu_mxl(env) != MXL_RV32; +} + +static inline target_ulong common_semi_stack_bottom(CPUState *cs) +{ + RISCVCPU *cpu = RISCV_CPU(cs); + CPURISCVState *env = &cpu->env; + return env->gpr[xSP]; +} + +static inline bool common_semi_has_synccache(CPUArchState *env) +{ + return true; +} + +#endif diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 50f40a2a1a..5e442e549d 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -46,9 +46,6 @@ #else #include "qemu/cutils.h" #include "hw/loader.h" -#ifdef TARGET_ARM -#include "hw/arm/boot.h" -#endif #include "hw/boards.h" #endif @@ -182,96 +179,7 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #endif -#ifdef TARGET_ARM -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - return env->xregs[argno]; - } else { - return env->regs[argno]; - } -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - if (is_a64(env)) { - env->xregs[0] = ret; - } else { - env->regs[0] = ret; - } -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || is_a64(cs->env_ptr)); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return is_a64(env); -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - ARMCPU *cpu = ARM_CPU(cs); - CPUARMState *env = &cpu->env; - return is_a64(env) ? env->xregs[31] : env->regs[13]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - /* Ok for A64, invalid for A32/T32. */ - return is_a64(env); -} -#endif /* TARGET_ARM */ - -#ifdef TARGET_RISCV -static inline target_ulong -common_semi_arg(CPUState *cs, int argno) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xA0 + argno]; -} - -static inline void -common_semi_set_ret(CPUState *cs, target_ulong ret) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - env->gpr[xA0] = ret; -} - -static inline bool -common_semi_sys_exit_extended(CPUState *cs, int nr) -{ - return (nr == TARGET_SYS_EXIT_EXTENDED || sizeof(target_ulong) == 8); -} - -static inline bool is_64bit_semihosting(CPUArchState *env) -{ - return riscv_cpu_mxl(env) != MXL_RV32; -} - -static inline target_ulong common_semi_stack_bottom(CPUState *cs) -{ - RISCVCPU *cpu = RISCV_CPU(cs); - CPURISCVState *env = &cpu->env; - return env->gpr[xSP]; -} - -static inline bool common_semi_has_synccache(CPUArchState *env) -{ - return true; -} -#endif +#include "common-semi-target.h" /* * The semihosting API has no concept of its errno being thread-safe, From patchwork Tue Jun 28 04:53:28 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585550 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp518048mab; Tue, 28 Jun 2022 00:42:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tP3OhqoS6NaEoKnIK5K+zezzeVF+deXC6uWQwLUdw1uDibIOZL4LbT/kjg6hqMlk6/TiuM X-Received: by 2002:a05:622a:4c9:b0:306:6959:e1d3 with SMTP id q9-20020a05622a04c900b003066959e1d3mr12248802qtx.680.1656402163768; Tue, 28 Jun 2022 00:42:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656402163; cv=none; d=google.com; s=arc-20160816; b=f63daY9B3pSnMjrsjeoXkT9no79/qxhMDqyTzhP19R/k3JLqi9yun3Ic3t4ynM0zzz gG08vp1a4UETrqq9H80ipbbvDhrr39RTB7pF0WyuwfIWrHkzVLfA2y7sLiUB5lkCnrVv BLbFJLnXLrVWdYeUGE63YV4u4EPRA69d+0EDbdPSyP+3NLarPgg9AmGPk+JIv3xaQOLm zszZ/c5AKvFiEOQWfKVOmj/n9NZW5Tw0fb+v/eSHFh4FWhEIwjZYn+3BhjJG7wL4JsDa l4KnL2Jpot70hK0nxtE0ngUwW65genabTaPb6lhMbpUPppkXaMA9Xygwpbw79gx5c7tk nk2A== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=DuF5Y9ugc2vh1YcdXplN2TQNBs2y+b/t7ZKHYCfY2p4=; b=u82Ye1EVLm2yjpPDjaQMIvnac+zWrK3hL/g4Xytrj0V62Ob+V7+wH+b7xHOU0a9iTf DDWBJRPuy9xGCIrm7eascxAdJhPmhIIBWP+y9MUmFveU9C3jW4WKXv2tksjIBuPKLRPU 8WKPTB6s6rv31ky2CEXW4Rfx6JmoawwzeeKLQaWg1Dx5gAfV4fjvEbxYmdlNTySNBKxY W4wFkBjO3VqZFtSjmlmQs54caI1N6g+hp4vubbimg4IjZlsP4Smv0ztlwsdnH+DOyPMH 7TydMkxHpZ/ymkk+xr8MEGWusE//zBZr83IbJv0syQ7UsMGIquep7nMiqHgnYZawgPTP 0k2A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ixA+V6iD; 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=pass (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 f16-20020a37ad10000000b006aefcb1721bsi6335080qkm.576.2022.06.28.00.42.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:42:43 -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=pass header.i=@linaro.org header.s=google header.b=ixA+V6iD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65rv-0000Ko-Ad for patch@linaro.org; Tue, 28 Jun 2022 03:42:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43502) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fo-0003Kv-1R for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:12 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:36723) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fl-0008NA-VI for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:11 -0400 Received: by mail-pj1-x102b.google.com with SMTP id c6-20020a17090abf0600b001eee794a478so3965904pjs.1 for ; Mon, 27 Jun 2022 21:55:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=DuF5Y9ugc2vh1YcdXplN2TQNBs2y+b/t7ZKHYCfY2p4=; b=ixA+V6iDPANT2bm5QfVw2aDvOn7ebl2sJInzmb1uUbOO+8hzf0YRyU/rHgWURKAbKr z2IbeaBy0exuZ9pwbUXZkW9QH3xsVoIWoDFCSCn4R/XwQpbkNLxlekIMRTdAp5BB9ggs S7Vzm4IC+F3TJgcsAKpQib3XuLDiC6CMQ9NuuVJGJ9JfbkvX47PvJRXd+Y7uXhVI+LW7 8bCunHGkUYo50lEuNjgLy31x5rK2N2llH6r519FkGFqkt6+2jnkBtDDNPNcaDgEvnz78 EeBfiBeMHoyRiWoYi4y3nP4r7yO3zQvMA2CbDdichY23Yss5Pt1qLKcOYS8XxrgzyoUx gnxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DuF5Y9ugc2vh1YcdXplN2TQNBs2y+b/t7ZKHYCfY2p4=; b=nRaLXNHa2nqOLsiAtOvLJJ/ES82OtLwrReIhaccojoY20aZ4t1tiseitSbcmQiOaA2 lfVqVuwrr3jdSXqZ8fKQ1XyNd0qD804ormnSU5i9bZlXm0p/5w7OUibqauE36IbuAur4 UnAenEi4CiFUbV4xKEyCIwp2mM8FNYJ7oDtirqirRRLRtyqXCWdLV0AmCIG3V/dBaJ5g LHGo9x3537FaUBxjYG9UXIahDCunXqpVzGLfohDI5cdJiMQM9jyUhf2eO1Z1WsuTRux8 M7ttBqngRZ1iay0uEIPGguuLS8Ur5cL9KVmeuRkY7Ttu6Bz/O+Zzzb0FfmnQFolQVYrk OejQ== X-Gm-Message-State: AJIora8wHee2RwMQerkpyKIcm/BeNqXc0Q5789sHjpHWYPpqcYT/w/k0 coV3m7hXCMGuL8gmD5R37Nggz621EKVZbQ== X-Received: by 2002:a17:90a:31c1:b0:1ec:729f:36b7 with SMTP id j1-20020a17090a31c100b001ec729f36b7mr24534959pjf.123.1656392108549; Mon, 27 Jun 2022 21:55:08 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 25/60] semihosting: Use env more often in do_common_semihosting Date: Tue, 28 Jun 2022 10:23:28 +0530 Message-Id: <20220628045403.508716-26-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We've already loaded cs->env_ptr into a local variable; use it. Since env is unconditionally used, we don't need a dummy use. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 5e442e549d..adb4e5b581 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -553,7 +553,6 @@ void do_common_semihosting(CPUState *cs) GuestFD *gf; int64_t elapsed; - (void) env; /* Used implicitly by arm lock_user macro */ nr = common_semi_arg(cs, 0) & 0xffffffffU; args = common_semi_arg(cs, 1); @@ -636,12 +635,12 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(cs->env_ptr, args); + qemu_semihosting_console_outc(env, args); common_semi_set_ret(cs, 0xdeadbeef); break; case TARGET_SYS_WRITE0: - ret = qemu_semihosting_console_outs(cs->env_ptr, args); + ret = qemu_semihosting_console_outs(env, args); common_semi_set_ret(cs, ret); break; @@ -672,7 +671,7 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(cs->env_ptr); + ret = qemu_semihosting_console_inc(env); common_semi_set_ret(cs, ret); break; From patchwork Tue Jun 28 04:53:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585551 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp522059mab; Tue, 28 Jun 2022 00:48:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tfUHgOiu18vbboIbqXWTFgwx34og7gR6naDO/ZLC3PFNi1/r6+KsFsSaMsKus8SXA5G829 X-Received: by 2002:a0c:fa8c:0:b0:470:3ec6:5ca3 with SMTP id o12-20020a0cfa8c000000b004703ec65ca3mr2514867qvn.8.1656402499839; Tue, 28 Jun 2022 00:48:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656402499; cv=none; d=google.com; s=arc-20160816; b=Mv7bl/+KRmhTMHqnz3g2kmru/LCW167vk+bNhTbNIpcQgBxa0IQuyoselKi9MMtOjG gA7V0eoUNB3hHxfCNdkGwCalb2Qni8WOMN12rC4hqXvccuLT7QFqV0l3UKIFy0+oV6Le cbxtWQjuGM2GqHWex2/VgOWdZMO1XzU6ZzA+favwNur/zqbGuMz4gTUc199BrOgMi8RB 9/doAMKe/qppImyDVMvtOLhQ06mCgfe9PKgWHmFmC56ydwF0dYUTs9QLsei3SjyTGPPA AIfFBCIl3po8NNyTtU/ntpukm0SoHwBQXOBrUpLA57oE7gpGYsnzHr8DE5uGqdSY3E3u KBQA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lqFv93ItJHKCx8rfb3Csr21RF/dQfiqOGTpOdE1PXrY=; b=fLSDfpjcNFcR5mmypJQNL2MZi+mYseagJHUa7B7bwjfpR8lGadUWjbGpOFvY0PuDUY Vg21XsivbZvaWY0nvKxRZscqheglm4IjHIqV/ftO3JWCxXkAktsTM6dMQLaYrM043o+l MTFqEANwMKrcCy83uZBrK0u1sQWbcRuDGM8tcgPH44di2VlLJyIaNpIF6ovihit8s+rL K5Etapm5TovICHZZHGHUj6OiQz5DuDBRPEhOfsa066vO531k3venK4p+Koi3fT1voU2f cgTem06EIrl7NM7Gb9aBciCW/lGkk2YlZiqyATzxYVNbHU+UnwUorcB9EdPJWglsGKi/ 9ZJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=brQzbWzc; 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=pass (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 dx12-20020a05620a608c00b006af18494b34si3726794qkb.272.2022.06.28.00.48.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:48:19 -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=pass header.i=@linaro.org header.s=google header.b=brQzbWzc; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59100 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65xL-0006Gx-D6 for patch@linaro.org; Tue, 28 Jun 2022 03:48:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43552) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fr-0003O1-E4 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:15 -0400 Received: from mail-pg1-x52e.google.com ([2607:f8b0:4864:20::52e]:44961) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fp-00004s-N1 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:15 -0400 Received: by mail-pg1-x52e.google.com with SMTP id v126so6903695pgv.11 for ; Mon, 27 Jun 2022 21:55:11 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lqFv93ItJHKCx8rfb3Csr21RF/dQfiqOGTpOdE1PXrY=; b=brQzbWzcKgPiQuN9jQo/y0wegbplxcfDNNwyXKTNLg8m9iMcGOgffYDWVk640fq0no CNPWz0Y7FEHFag2Wf3l2wzcaJLURapML1PyGJn7KavX/KdQvcpRP62uDsuC4hYx/WkHY M2VIeCUJuo79A/vzvScEf3GAetUlA0ZTIAodCary1j4me+ZWzhxTn6+dsDRaAVCnbI4h 2a5H8u0Q9jKtTZ8IGsHOIfo3LjHquBk1j4i/LoL4wrjLCiRSXZWbT0C3s8xpfccOX9HU Z4KW040l09D3/mEKg+ZqAfJSGT7UlKKWGXVfa2OVio+CotYuCW9AK8wCyAlO06p9oJfW +PiA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lqFv93ItJHKCx8rfb3Csr21RF/dQfiqOGTpOdE1PXrY=; b=uMFtw1JXPHB7Ub/NlHKaKq2p5B/TeGc/KVE23THk52KLQvT9NTAGvinNiMxh7LSWLD PnCEyaSlwvYbjclxiymnXrq5eBUgSZIevBFSGKiZ4zTiAjjp8equdfbWPezzagRq9WaQ OqKyie8l2HTQR6UjolnP+0IwegxecLxtk7EDltnh9h5SbuhMQNxN1e5spbAN3zeCcyIC 2rXUBVRs0S2k/xwLXMJ6IR1BsNr4/SPsvMUmODe4sq1AjCZBzZ/3cV3lzAAL7v+Q7Mqq MhMLgPt38E0ILeGzp+F5O12aKkKUrvKMsTeCB5sfh95FWVlAXtMi+12dyWy/7M2+wWMS 4FMw== X-Gm-Message-State: AJIora9DQGA1rnP4pSesRUzHn6g+XwtkCWyCyyDImNcMT8HmvGr98wrY f0aLcfMqOUGGNqnToL9y0r+8WSImj7YZog== X-Received: by 2002:a05:6a00:2185:b0:520:7276:6570 with SMTP id h5-20020a056a00218500b0052072766570mr2801950pfi.84.1656392111018; Mon, 27 Jun 2022 21:55:11 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Alex_Benn=C3=A9e?= , Peter Maydell Subject: [PULL 26/60] semihosting: Move GET_ARG/SET_ARG earlier in the file Date: Tue, 28 Jun 2022 10:23:29 +0530 Message-Id: <20220628045403.508716-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52e; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Moving this to be useful for another function besides do_common_semihosting. Reviewed-by: Alex Bennée Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 48 +++++++++++++++++------------------ 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index adb4e5b581..72a1350512 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -181,6 +181,30 @@ static LayoutInfo common_semi_find_bases(CPUState *cs) #include "common-semi-target.h" +/* + * Read the input value from the argument block; fail the semihosting + * call if the memory read fails. Eventually we could use a generic + * CPUState helper function here. + */ + +#define GET_ARG(n) do { \ + if (is_64bit_semihosting(env)) { \ + if (get_user_u64(arg ## n, args + (n) * 8)) { \ + goto do_fault; \ + } \ + } else { \ + if (get_user_u32(arg ## n, args + (n) * 4)) { \ + goto do_fault; \ + } \ + } \ +} while (0) + +#define SET_ARG(n, val) \ + (is_64bit_semihosting(env) ? \ + put_user_u64(val, args + (n) * 8) : \ + put_user_u32(val, args + (n) * 4)) + + /* * The semihosting API has no concept of its errno being thread-safe, * as the API design predates SMP CPUs and was intended as a simple @@ -507,30 +531,6 @@ static const GuestFDFunctions guestfd_fns[] = { }, }; -/* - * Read the input value from the argument block; fail the semihosting - * call if the memory read fails. Eventually we could use a generic - * CPUState helper function here. - */ - -#define GET_ARG(n) do { \ - if (is_64bit_semihosting(env)) { \ - if (get_user_u64(arg ## n, args + (n) * 8)) { \ - goto do_fault; \ - } \ - } else { \ - if (get_user_u32(arg ## n, args + (n) * 4)) { \ - goto do_fault; \ - } \ - } \ -} while (0) - -#define SET_ARG(n, val) \ - (is_64bit_semihosting(env) ? \ - put_user_u64(val, args + (n) * 8) : \ - put_user_u32(val, args + (n) * 4)) - - /* * Do a semihosting call. * From patchwork Tue Jun 28 04:53:30 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585552 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp524176mab; Tue, 28 Jun 2022 00:51:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tE+eEtKWkT6OgKYWzpeWmjLloPviuWzIjSg5CEwslA5T5Py1y/h5n8ZNfQ62nJl63WXUqr X-Received: by 2002:ac8:57d2:0:b0:305:2db3:47fa with SMTP id w18-20020ac857d2000000b003052db347famr12251471qta.29.1656402708062; Tue, 28 Jun 2022 00:51:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656402708; cv=none; d=google.com; s=arc-20160816; b=X8Wa+6pGZq3q3CVzNitQzBWiwmdD2m2sGBIMHfcezGaXWxObEFnSjKlIaGZjBdfQ9V 53sFlLAjMYXFbt34auJx2x7u2W2vlleqKXmqWFJHrC6F/93t2mTdm+zYC0l+ruOcaghu WmqVlseIcyiwht+MU9a+b3lEH/TMCk/N47YhpoWdJ5koJGRed9Eg1UQUWBr58FG7rjfO MYLnj8tE6KRB1JDv4+RWOmV9zxBG4zfa0mN3ZwQWev7/lbfxbF+XElKq7eTHIIHiZf7f QAtGDwCYclARerzUZWSLkyieNuUI6ZUyCsiTly2mNYXnVg+SHjoLJsggcWiYXNP0tzB+ R5Sg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=SB0SPUk72cCTkCcvpipl11hti/rXHdZHTqbefwlQDxE=; b=HDkeSSJF0pCHmw+ITAcNk2fLA9ZIB83K3ToLcYN1m4SxLCPeEuzot+Pm0W0hnelrYx DgFNsoHicmau0bPzc/BkYPG8WgEE5qrNbkpSo2oRY58HF0zCd/kzy8/g4QAej/kyuc9I Ccmx78Y20xAXOy2JFNTaoIDmJ7SVQx1BBQs6xo01+dFSkiYxrynmS3LfoXcf0y+7d52A ROxxUOpm1dZ0stDK2kI/ceiRJzMUP5i64MxYZnjuhRh+1ZA4ztMiF8G36dmnpzxZktSl 7bJs1VBqyzD3YrHr//zSIpYHckVfw+7tHv+Yhk0YxhfRfzV7wPXLb6ceCmaJeVIOfXoC +TVw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="csh/rdij"; 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=pass (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 d20-20020a05622a101400b00304ec8e48a9si2081686qte.719.2022.06.28.00.51.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:51:48 -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=pass header.i=@linaro.org header.s=google header.b="csh/rdij"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:39458 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o660h-00043G-JV for patch@linaro.org; Tue, 28 Jun 2022 03:51:47 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43644) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63G4-0003Xy-Iw for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:29 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:46058) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fq-0008Ks-DO for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:28 -0400 Received: by mail-pj1-x102b.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so6016270pji.4 for ; Mon, 27 Jun 2022 21:55:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SB0SPUk72cCTkCcvpipl11hti/rXHdZHTqbefwlQDxE=; b=csh/rdijizk9mK6S2gozHoKd2YdBbZ1kOqvVopSrXGwyiaPgQc9uzNMIpTSZiz/1sQ TtE01wuqTtr6QG8QdIi3JqqUFsLjGbgKy6EB3iTk5ePch/wqLmFBuj4gF/VhFbLd6iHL UMX6cUI7E5V3cZLWqCkgmYp0cJoJtM+foowbSbuSCgCSb/Dw4s7P3OcOHfSMNx0VjtqN jwwUY5kKJi8Don3GTmRxWmY4kgn6QOegKn1M9qKVXWRJga7tB9zjPHbo7otp4aRQWSQf iROpzzv4L/aucdwrk/z/K53h3yhUFOfR5cePAFA/aYyeHbKRbmHgx0H21Od/vhno3PsC 2GlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=SB0SPUk72cCTkCcvpipl11hti/rXHdZHTqbefwlQDxE=; b=Bbxbb7pi098P2YoINedIdmuFdmizHv4F6LJxwuACW3ciNE9z/F5l4XAU6i31Ec6rD7 AripR+LmK8lKaWoyGLFxiPHxWykq7Br4Hq9k72rrIVu+wrfRqaCbcF/tpM4KhNVKaZ/P eTteWT2d8qgz/uc0VgYCCfP51IGi/PHUFyWtohvOgxxen6SC2/meuXcRMPdlTY64UtSC tyLaq5nzNR6ZbytckkK18k76VHqXMOY6cPMQ6gKkaSxzHjDxkvCjSl+Ko96uJ3je4Ti0 kbhNyvbJDIDX6s1Utm4cjSOEd0ot/W+zGC62wiySTUpgnKGnyR7rgen5V5qjnC+YWje0 WSww== X-Gm-Message-State: AJIora/wtJRsDoBKfAtD0Of7Q/jc+ywor0X9X+hQnih4Ut++Xlzp104R oHBiWv0AVM+Z4Hl5g5aFahFmXNOt9miwxw== X-Received: by 2002:a17:902:db0d:b0:16b:9057:8042 with SMTP id m13-20020a170902db0d00b0016b90578042mr698580plx.165.1656392113426; Mon, 27 Jun 2022 21:55:13 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 27/60] semihosting: Split out semihost_sys_open Date: Tue, 28 Jun 2022 10:23:30 +0530 Message-Id: <20220628045403.508716-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_OPEN to a reusable function. This handles gdb and host file i/o. Add helpers to validate the length of the filename string. Prepare for usage by other semihosting by allowing the filename length parameter to be 0, and calling strlen. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 25 ++++++ semihosting/arm-compat-semi.c | 53 ++--------- semihosting/guestfd.c | 5 ++ semihosting/syscalls.c | 156 +++++++++++++++++++++++++++++++++ semihosting/meson.build | 1 + 5 files changed, 194 insertions(+), 46 deletions(-) create mode 100644 include/semihosting/syscalls.h create mode 100644 semihosting/syscalls.c diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h new file mode 100644 index 0000000000..991658bf79 --- /dev/null +++ b/include/semihosting/syscalls.h @@ -0,0 +1,25 @@ +/* + * Syscall implementations for semihosting. + * + * Copyright (c) 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#ifndef SEMIHOSTING_SYSCALLS_H +#define SEMIHOSTING_SYSCALLS_H + +/* + * Argument loading from the guest is performed by the caller; + * results are returned via the 'complete' callback. + * + * String operands are in address/len pairs. The len argument may be 0 + * (when the semihosting abi does not already provide the length), + * or non-zero (where it should include the terminating zero). + */ + +void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode); + +#endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 72a1350512..07960658d8 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -32,12 +32,13 @@ */ #include "qemu/osdep.h" +#include "qemu/timer.h" +#include "exec/gdbstub.h" #include "semihosting/semihost.h" #include "semihosting/console.h" #include "semihosting/common-semi.h" #include "semihosting/guestfd.h" -#include "qemu/timer.h" -#include "exec/gdbstub.h" +#include "semihosting/syscalls.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" @@ -98,21 +99,6 @@ static int gdb_open_modeflags[12] = { GDB_O_RDWR | GDB_O_CREAT | GDB_O_APPEND, }; -static int open_modeflags[12] = { - O_RDONLY, - O_RDONLY | O_BINARY, - O_RDWR, - O_RDWR | O_BINARY, - O_WRONLY | O_CREAT | O_TRUNC, - O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, - O_RDWR | O_CREAT | O_TRUNC, - O_RDWR | O_CREAT | O_TRUNC | O_BINARY, - O_WRONLY | O_CREAT | O_APPEND, - O_WRONLY | O_CREAT | O_APPEND | O_BINARY, - O_RDWR | O_CREAT | O_APPEND, - O_RDWR | O_CREAT | O_APPEND | O_BINARY -}; - #ifndef CONFIG_USER_ONLY /** @@ -284,20 +270,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_cb(cs, ret, err); } -static int common_semi_open_guestfd; - -static void -common_semi_open_cb(CPUState *cs, target_ulong ret, target_ulong err) -{ - if (err) { - dealloc_guestfd(common_semi_open_guestfd); - } else { - associate_guestfd(common_semi_open_guestfd, ret); - ret = common_semi_open_guestfd; - } - common_semi_cb(cs, ret, err); -} - /* * Types for functions implementing various semihosting calls * for specific types of guest file descriptor. These must all @@ -601,22 +573,11 @@ void do_common_semihosting(CPUState *cs) staticfile_guestfd(ret, featurefile_data, sizeof(featurefile_data)); } - } else if (use_gdb_syscalls()) { - unlock_user(s, arg0, 0); - common_semi_open_guestfd = alloc_guestfd(); - gdb_do_syscall(common_semi_open_cb, - "open,%s,%x,1a4", arg0, (int)arg2 + 1, - gdb_open_modeflags[arg1]); - break; } else { - hostfd = open(s, open_modeflags[arg1], 0644); - if (hostfd < 0) { - ret = -1; - err = errno; - } else { - ret = alloc_guestfd(); - associate_guestfd(ret, hostfd); - } + unlock_user(s, arg0, 0); + semihost_sys_open(cs, common_semi_cb, arg0, arg2 + 1, + gdb_open_modeflags[arg1], 0644); + break; } unlock_user(s, arg0, 0); common_semi_cb(cs, ret, err); diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index b6405f5663..7ac2e147a8 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -11,6 +11,11 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" #include "semihosting/guestfd.h" +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +#else +#include "semihosting/softmmu-uaccess.h" +#endif static GArray *guestfd_array; diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c new file mode 100644 index 0000000000..9f9d19a59a --- /dev/null +++ b/semihosting/syscalls.c @@ -0,0 +1,156 @@ +/* + * Syscall implementations for semihosting. + * + * Copyright (c) 2022 Linaro + * + * SPDX-License-Identifier: GPL-2.0-or-later + */ + +#include "qemu/osdep.h" +#include "exec/gdbstub.h" +#include "semihosting/guestfd.h" +#include "semihosting/syscalls.h" +#ifdef CONFIG_USER_ONLY +#include "qemu.h" +#else +#include "semihosting/softmmu-uaccess.h" +#endif + + +/* + * Validate or compute the length of the string (including terminator). + */ +static int validate_strlen(CPUState *cs, target_ulong str, target_ulong tlen) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char c; + + if (tlen == 0) { + ssize_t slen = target_strlen(str); + + if (slen < 0) { + return -EFAULT; + } + if (slen >= INT32_MAX) { + return -ENAMETOOLONG; + } + return slen + 1; + } + if (tlen > INT32_MAX) { + return -ENAMETOOLONG; + } + if (get_user_u8(c, str + tlen - 1)) { + return -EFAULT; + } + if (c != 0) { + return -EINVAL; + } + return tlen; +} + +static int validate_lock_user_string(char **pstr, CPUState *cs, + target_ulong tstr, target_ulong tlen) +{ + int ret = validate_strlen(cs, tstr, tlen); + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *str = NULL; + + if (ret > 0) { + str = lock_user(VERIFY_READ, tstr, ret, true); + ret = str ? 0 : -EFAULT; + } + *pstr = str; + return ret; +} + +/* + * GDB semihosting syscall implementations. + */ + +static gdb_syscall_complete_cb gdb_open_complete; + +static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + if (!err) { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + ret = guestfd; + } + gdb_open_complete(cs, ret, err); +} + +static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_open_complete = complete; + gdb_do_syscall(gdb_open_cb, "open,%s,%x,%x", + fname, len, (target_ulong)gdb_flags, (target_ulong)mode); +} + +/* + * Host semihosting syscall implementations. + */ + +static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret, host_flags; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + if (gdb_flags & GDB_O_WRONLY) { + host_flags = O_WRONLY; + } else if (gdb_flags & GDB_O_RDWR) { + host_flags = O_RDWR; + } else { + host_flags = O_RDONLY; + } + if (gdb_flags & GDB_O_CREAT) { + host_flags |= O_CREAT; + } + if (gdb_flags & GDB_O_TRUNC) { + host_flags |= O_TRUNC; + } + if (gdb_flags & GDB_O_EXCL) { + host_flags |= O_EXCL; + } + + ret = open(p, host_flags, mode); + if (ret < 0) { + complete(cs, -1, errno); + } else { + int guestfd = alloc_guestfd(); + associate_guestfd(guestfd, ret); + complete(cs, guestfd, 0); + } + unlock_user(p, fname, 0); +} + +/* + * Syscall entry points. + */ + +void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + int gdb_flags, int mode) +{ + if (use_gdb_syscalls()) { + gdb_open(cs, complete, fname, fname_len, gdb_flags, mode); + } else { + host_open(cs, complete, fname, fname_len, gdb_flags, mode); + } +} diff --git a/semihosting/meson.build b/semihosting/meson.build index d2c1c37bfd..8057db5494 100644 --- a/semihosting/meson.build +++ b/semihosting/meson.build @@ -1,5 +1,6 @@ specific_ss.add(when: 'CONFIG_SEMIHOSTING', if_true: files( 'guestfd.c', + 'syscalls.c', )) specific_ss.add(when: ['CONFIG_SEMIHOSTING', 'CONFIG_SOFTMMU'], if_true: files( From patchwork Tue Jun 28 04:53:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585521 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp473643mab; Mon, 27 Jun 2022 23:29:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vMQ3kuYWXZNhy58xxawwYKe3VdbLYH6ps60WrSZGeRUseLuzYHgfnMmm9tJZkMGpzFUCUn X-Received: by 2002:a05:6214:2621:b0:470:5b13:4647 with SMTP id gv1-20020a056214262100b004705b134647mr1362462qvb.20.1656397778024; Mon, 27 Jun 2022 23:29:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397778; cv=none; d=google.com; s=arc-20160816; b=z1TnJt7oKeQij76pjlO8KAvU+cd0/bsYlx+w/F+lbWLIK0diZnsVwqdHUSmegf718t 08Ka98y2zInb5bn5unlhsp6GoSHwqVYaQ6sMeycud+JHFMiPdIcM+re3g6Om3PCbADIn yewoWszTVoQRnphcmNEKYBDW5+L7n1qAVdw38h3WAs8NdPXTTLkulXxCR2hyDv9rhEvs cjhoX/ZqK7XgOkbfYA8+vQ9KT8Zh+1qizTw5KDUZslh6b+3FkAalf+RmMzN+BqBSsWL8 m1e4sPDR9cqrhlTwPbjveRFSArh5bJSTiaJGPOvqe6HWXM9XKl2ASlBji4/KU82gEsf0 QbHQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=n33T5xELKuAGnE/iYC5J4cnvv6uYJy7huCb2qTzez6s=; b=LWVW+K6saabl4SU4MAiNzGXXjpy6RVnkytyX+Av7EZ67DZldwk722V/eomgJowzeq1 YFV3CYRRnf/kpgsRoQr3Dt0yfhf2dGy+yNBv44LV6hMicwKheIoKlJf5TAFkjMlXoqoW 9NyWWdRgUX8+YQAwc+k5mTCmFmPf83GTHMDRcMTLcD05yJKCB2MJBB8XZrwL+Wv4fABj tRu5HGQuBbW+b7ebHudJy0I/rEHkmBoSUDaPr2fuzs4dkIlkK+UPTTRmjVmX6NEMcsay fqcjddWGyagA72OuzCfSKN5a4v6pU6C1VJGGeVLxiZlDgW7Ibh7M76so4HF+pfWxEXI1 124g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=BApJ7H1e; 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=pass (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 g21-20020a05620a40d500b006a6c1692e72si8834068qko.658.2022.06.27.23.29.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:29:38 -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=pass header.i=@linaro.org header.s=google header.b=BApJ7H1e; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54790 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64jB-0005VU-C7 for patch@linaro.org; Tue, 28 Jun 2022 02:29:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43604) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fw-0003Su-Kq for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:22 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:38779) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Ft-00007r-3g for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:19 -0400 Received: by mail-pf1-x42c.google.com with SMTP id k9so1725230pfg.5 for ; Mon, 27 Jun 2022 21:55:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=n33T5xELKuAGnE/iYC5J4cnvv6uYJy7huCb2qTzez6s=; b=BApJ7H1eSP6cdgBR9Pxkgtq0fqfsFXaBoyF28LtYDm7l5nsA5gUwDgIUBMkDliwhSp 7ZitEQDemIjuuorOA46GKCNO+u38gULrHVg/WTLKfBGHkiEaV34VYuoa0y+zI3VgttzJ IMnFy4IeY3ZzgOKLVaGvYrAel5SejGlr+NSYVc8xBJLubWtSODsjeetJeyKclscE5IOo cyIgE7yBL0/l9yWsmL227Jb3gypZ8k9tRagHa4pTHMTls1xKga6vR0jpXBmm1SZetGQP vQvPHfJC7JZOTrWlVFgEArbVtOaz01YEEtRDyyFH44u6ogsImF/+8p/2iub8Cj6eU5/h 9X7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=n33T5xELKuAGnE/iYC5J4cnvv6uYJy7huCb2qTzez6s=; b=757NoX2QXDKQVsQOHSBoyIFO80OfOyPXbzlfdxa7gxk8hocBaGc5aVy4Q9X43Ux67e CTObBc9zpErB/zq3JVYI9ccm/UaUvhO2lU1yrf6L74ygp/dm1IlEWJdsd9w3ezGLT9uI dKqCtvFzpBJ8EK8VZaBuQ+9oIRtkB9KIVqHBmM4cto1WfXci/qHqHm04/CS3MG1BDn5m RS9e8hi4HhXUU4d6EjLX0+1H1IlY7ylDacIsnu0QkGgjf+vY+eCptjeLBHnK7CKETD6c 5uopAoeBUFW7+OPUCMGCdC5EQGozN6kqda4V0dkSO+Piayzw0390VnoxG/svNSaPirPc XnNg== X-Gm-Message-State: AJIora83sMUByq5ziNL2rNu0LrGdTONR+OAA0VzP4GJizQ+zG/0aHnCu cMtzpho6MgM7AFkeY76rNoietlY8pXvVrg== X-Received: by 2002:a65:490d:0:b0:40d:9867:2df with SMTP id p13-20020a65490d000000b0040d986702dfmr16132499pgs.171.1656392115739; Mon, 27 Jun 2022 21:55:15 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 28/60] semihosting: Split out semihost_sys_close Date: Tue, 28 Jun 2022 10:23:31 +0530 Message-Id: <20220628045403.508716-29-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42c; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_CLOSE to a reusable function. This handles all GuestFD. Note that gdb_do_syscall %x reads target_ulong, not int. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 41 +---------------------------- semihosting/guestfd.c | 7 ++++- semihosting/syscalls.c | 47 ++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 41 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 991658bf79..00e718f11d 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -22,4 +22,7 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, int gdb_flags, int mode); +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 07960658d8..0cb3db2a1a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -276,7 +276,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_closefn(CPUState *cs, GuestFD *gf); typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); typedef void sys_readfn(CPUState *cs, GuestFD *gf, @@ -285,23 +284,6 @@ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_closefn(CPUState *cs, GuestFD *gf) -{ - int ret; - /* - * Only close the underlying host fd if it's one we opened on behalf - * of the guest in SYS_OPEN. - */ - if (gf->hostfd == STDIN_FILENO || - gf->hostfd == STDOUT_FILENO || - gf->hostfd == STDERR_FILENO) { - ret = 0; - } else { - ret = close(gf->hostfd); - } - common_semi_cb(cs, ret, ret ? errno : 0); -} - static void host_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -362,11 +344,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_closefn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "close,%x", gf->hostfd); -} - static void gdb_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -414,12 +391,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_closefn(CPUState *cs, GuestFD *gf) -{ - /* Nothing to do */ - common_semi_cb(cs, 0, 0); -} - static void staticfile_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len) { @@ -468,7 +439,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -478,7 +448,6 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .closefn = host_closefn, .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, @@ -486,7 +455,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = host_flenfn, }, [GuestFDGDB] = { - .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, @@ -494,7 +462,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .closefn = staticfile_closefn, .writefn = staticfile_writefn, .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, @@ -586,13 +553,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_CLOSE: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].closefn(cs, gf); - dealloc_guestfd(arg0); + semihost_sys_close(cs, common_semi_cb, arg0); break; case TARGET_SYS_WRITEC: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index 7ac2e147a8..e3122ebba9 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -49,6 +49,11 @@ int alloc_guestfd(void) return i; } +static void do_dealloc_guestfd(GuestFD *gf) +{ + gf->type = GuestFDUnused; +} + /* * Look up the guestfd in the data structure; return NULL * for out of bounds, but don't check whether the slot is unused. @@ -119,5 +124,5 @@ void dealloc_guestfd(int guestfd) GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDUnused; + do_dealloc_guestfd(gf); } diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 9f9d19a59a..3648b9dd49 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -94,6 +94,12 @@ static void gdb_open(CPUState *cs, gdb_syscall_complete_cb complete, fname, len, (target_ulong)gdb_flags, (target_ulong)mode); } +static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); +} + /* * Host semihosting syscall implementations. */ @@ -140,6 +146,23 @@ static void host_open(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, fname, 0); } +static void host_close(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + /* + * Only close the underlying host fd if it's one we opened on behalf + * of the guest in SYS_OPEN. + */ + if (gf->hostfd != STDIN_FILENO && + gf->hostfd != STDOUT_FILENO && + gf->hostfd != STDERR_FILENO && + close(gf->hostfd) < 0) { + complete(cs, -1, errno); + } else { + complete(cs, 0, 0); + } +} + /* * Syscall entry points. */ @@ -154,3 +177,27 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, host_open(cs, complete, fname, fname_len, gdb_flags, mode); } } + +void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_close(cs, complete, gf); + break; + case GuestFDHost: + host_close(cs, complete, gf); + break; + case GuestFDStatic: + complete(cs, 0, 0); + break; + default: + g_assert_not_reached(); + } + dealloc_guestfd(fd); +} From patchwork Tue Jun 28 04:53:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585514 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp462944mab; Mon, 27 Jun 2022 23:11:18 -0700 (PDT) X-Google-Smtp-Source: AGRyM1taerdFtD8sKzwZd911NLeA7a6chFGPcGIwhNDCAuGPTU7qGR0tTNJZiMzAWI6hixpaT9rh X-Received: by 2002:a37:2c45:0:b0:6ae:fd6d:5af with SMTP id s66-20020a372c45000000b006aefd6d05afmr10097178qkh.591.1656396678080; Mon, 27 Jun 2022 23:11:18 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396678; cv=none; d=google.com; s=arc-20160816; b=t4oy+hiAKjuC4NZGyeY4mCNfVaA2kj1A6UqvG42DKezfND9zxc5uMWp0htI7u1Wquh MFqAdIdjtVS9lhNDsLZ1k/1//Kux+4IU7IhL3iq9IwLVKqgWiYxhGaeSzWuWnW+E4NiO giQL6CVLrrfPA4zQ98UGFzPgeexlBbPTfaU0341TRux5fF6vt8FEQrukkhkk5JC5oo3I EFlqxfPWgcQ84lz7GTweDy+Tl5mO9Ov2aykLVksPHdi22gUmQwxLNS0hrG2caFpGCEKy WTwXRiiV9HifBWa9fgy2Ulh25Ch7TC2F2sPLMlJTZYMT15Oylsu2PmdQSKlf+wuhBcUR PgRg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=+2WX/o0EdaKzZJdZ1q668Ivtbna4dh4XHWGyBlz4SiE=; b=tcoUwr5oARUvH5WhDEZtEx2L12Bvt7PyT2VCMYDBav6jfKrVqQ3YiMak2EyNPnIuCb qE4GTTktmwwgEXLYuDavWVxncG5h2NjXbj2xeXswt9+f7Dm8lGSBDyR2gP5CxhURrM44 UufDL/B9u6BX4f0o9Cb9WzGpD+/oorBVHzwzz2V0OH+Xayw+fWJ1htD0aspmAdCBXqaF UBHvmB92Pj3Y5OZLvlcgqkJ2v7Tz3VMqQ2/ZUPaj/F4VxQXlls9hLjD85tKPiAvDbT/u hDB7/MTvaU+AsIaJWQ6p6S1yiDBXuEt/eI55oQJ52vYTfhibfqYrigHZAQhtCFiVFjGf 6NTw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=R4VOSEXs; 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=pass (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 c19-20020ac87dd3000000b0030520ccb80fsi7249140qte.615.2022.06.27.23.11.18 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:11:18 -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=pass header.i=@linaro.org header.s=google header.b=R4VOSEXs; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60020 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64RR-0003z1-Ii for patch@linaro.org; Tue, 28 Jun 2022 02:11:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43624) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fy-0003Tp-ST for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:24 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:46067) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fv-000082-I8 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:22 -0400 Received: by mail-pj1-x1032.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so6017061pji.4 for ; Mon, 27 Jun 2022 21:55:19 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+2WX/o0EdaKzZJdZ1q668Ivtbna4dh4XHWGyBlz4SiE=; b=R4VOSEXsRytvPDkr8rGQlS6TbQZeec6gJiQIL2OQwxR8d1n7Qd5HFkjVXPE3SFoiev tAshcjbm/swqhLPPqjQ8vyeEXPyXN6y+IJ9CoWN+pio83idTG372yI6w8ZYxJbesplvV VaRAtq5fMeBNhZCwVFvW8xigwzEmHFpufn1qUcwaj/l04IBgQcQ3NUX33zh73zT2wUMI TWJoye+LsGzR5Yt+yqQyI7NDwpYjliOuALpZ/HBmyIFiyO92XCw+CoCU1Yxs/T/RK1WK w2M5KM3d5/hDFyaXE8wGAXu7ZDwmeOq7d71s8GpZ+G4/Stw6Mf8EnvPRApk+s5pPrg3P r2AQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=+2WX/o0EdaKzZJdZ1q668Ivtbna4dh4XHWGyBlz4SiE=; b=289vFWzh2kgoPNsQX5v9TGXVLLMmgkIkf0XS36XzuRQBb/6Smf63zpKVql82IiEBPG T/NYCq4y7c3if9EvtH0AHIWYn+yrXVNVbTPP/EG16Eo1hvjTX9SaqUTfcp+uoKEKlcHC UfoRWj7wRVTS3XlnWDQ72f3pDC8SdxLvWT3oOhXpUi/OeREz16f4Z8k7Flk0zu/7A2kQ bhl/8EksXcCHC+4bnqhxWAjm73D0g1rv2uPB//CVfcF7GNFeRz+KejxKbUnDbNLj9q+8 CaVq5wmijo/7duqT+zYUO2OPKHteaONCpA0Wj1NbVFZgge6UTuNe6KMts0HfULS5Hkne nPQg== X-Gm-Message-State: AJIora/jLwJc/08kw1/ENvey9x0RIYpGOo496h0Ommkb3NjePB9jK1sw ioeN9UDWPRQFAoqWWcP+5bdJ02MzAlP/5g== X-Received: by 2002:a17:902:da87:b0:16a:54e1:3426 with SMTP id j7-20020a170902da8700b0016a54e13426mr1747769plx.157.1656392118020; Mon, 27 Jun 2022 21:55:18 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 29/60] semihosting: Split out semihost_sys_read Date: Tue, 28 Jun 2022 10:23:32 +0530 Message-Id: <20220628045403.508716-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_READ to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_rw_cb. Note that gdb_do_syscall %x reads target_ulong, not int. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 8 ++++ semihosting/arm-compat-semi.c | 85 ++++++++-------------------------- semihosting/syscalls.c | 85 ++++++++++++++++++++++++++++++++++ 3 files changed, 113 insertions(+), 65 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 00e718f11d..20da8138b0 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -18,6 +18,8 @@ * or non-zero (where it should include the terminating zero). */ +typedef struct GuestFD GuestFD; + void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len, int gdb_flags, int mode); @@ -25,4 +27,10 @@ void semihost_sys_open(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + +void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 0cb3db2a1a..8da31d8507 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -231,7 +231,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { case TARGET_SYS_WRITE: - case TARGET_SYS_READ: ret = common_semi_syscall_len - ret; break; case TARGET_SYS_SEEK: @@ -244,6 +243,25 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, ret); } +/* + * SYS_READ and SYS_WRITE always return the number of bytes not read/written. + * There is no error condition, other than returning the original length. + */ +static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +{ + /* Recover the original length from the third argument. */ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong args = common_semi_arg(cs, 1); + target_ulong arg2; + GET_ARG(2); + + if (err) { + do_fault: + ret = 0; /* error: no bytes transmitted */ + } + common_semi_set_ret(cs, arg2 - ret); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -278,8 +296,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) */ typedef void sys_writefn(CPUState *cs, GuestFD *gf, target_ulong buf, uint32_t len); -typedef void sys_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); @@ -302,26 +318,6 @@ static void host_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, len - ret, 0); } -static void host_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_WRITE, buf, len, 0); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - do { - ret = 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, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -351,13 +347,6 @@ static void gdb_writefn(CPUState *cs, GuestFD *gf, gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); } -static void gdb_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "read,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -398,30 +387,6 @@ static void staticfile_writefn(CPUState *cs, GuestFD *gf, common_semi_cb(cs, -1, EBADF); } -static void staticfile_readfn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t i = 0; - char *s; - - (void) env; /* Used in arm softmmu lock_user implicitly */ - s = lock_user(VERIFY_WRITE, buf, len, 0); - if (s) { - for (i = 0; i < len; i++) { - if (gf->staticfile.off >= gf->staticfile.len) { - break; - } - s[i] = gf->staticfile.data[gf->staticfile.off]; - gf->staticfile.off++; - } - unlock_user(s, buf, len); - } - - /* Return number of bytes not read */ - common_semi_cb(cs, len - i, 0); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -440,7 +405,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_writefn *writefn; - sys_readfn *readfn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -449,21 +413,18 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .writefn = host_writefn, - .readfn = host_readfn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .writefn = gdb_writefn, - .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .writefn = staticfile_writefn, - .readfn = staticfile_readfn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -583,13 +544,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].readfn(cs, gf, arg1, len); + semihost_sys_read(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READC: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 3648b9dd49..d42a190746 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -100,6 +100,13 @@ static void gdb_close(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "close,%x", (target_ulong)gf->hostfd); } +static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + gdb_do_syscall(complete, "read,%x,%x,%x", + (target_ulong)gf->hostfd, buf, len); +} + /* * Host semihosting syscall implementations. */ @@ -163,6 +170,54 @@ static void host_close(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_WRITE, buf, len, 0); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + do { + ret = read(gf->hostfd, ptr, len); + } while (ret == -1 && errno == EINTR); + if (ret == -1) { + complete(cs, -1, errno); + unlock_user(ptr, buf, 0); + } else { + complete(cs, ret, 0); + unlock_user(ptr, buf, ret); + } +} + +/* + * Static file semihosting syscall implementations. + */ + +static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + target_ulong rest = gf->staticfile.len - gf->staticfile.off; + void *ptr; + + if (len > rest) { + len = rest; + } + ptr = lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + memcpy(ptr, gf->staticfile.data + gf->staticfile.off, len); + gf->staticfile.off += len; + complete(cs, len, 0); + unlock_user(ptr, buf, len); +} + /* * Syscall entry points. */ @@ -201,3 +256,33 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) } dealloc_guestfd(fd); } + +void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + switch (gf->type) { + case GuestFDGDB: + gdb_read(cs, complete, gf, buf, len); + break; + case GuestFDHost: + host_read(cs, complete, gf, buf, len); + break; + case GuestFDStatic: + staticfile_read(cs, complete, gf, buf, len); + break; + default: + g_assert_not_reached(); + } +} + +void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (gf) { + semihost_sys_read_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, EBADF); + } +} From patchwork Tue Jun 28 04:53:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585511 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp459412mab; Mon, 27 Jun 2022 23:05:19 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tEEARkfR5cU8FibfDRammFveBda0ynpEnIKgrHwIIO6xDbNrnVKzyECh1SQndPZAXHUvjK X-Received: by 2002:ae9:ea09:0:b0:6a7:7ea1:395e with SMTP id f9-20020ae9ea09000000b006a77ea1395emr10426312qkg.543.1656396319598; Mon, 27 Jun 2022 23:05:19 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656396319; cv=none; d=google.com; s=arc-20160816; b=ednHFImwNJvxyrWA1nMActjpd+YTTBNHslL6D1zhSezQpAx6FYVqHCZpDtB1bLfvSH HpN5vqaGtuIkpaD1pmoTNG8lVMGUo+Ij3TqAP7u+8A/AupjQRmaHiSA2l920jtm+6v8X 3x2Bj9BnaQVSLs7Es4pYjx1QQm9BSzejwHQOeTsiuRf5ynVmh0iR6iu2V8vh13StfeGK yzK07jYtu5QVvHd7acU+kRl+mMaSmfKOb7WnIRPdEsVIPWONzQ6/w+WtO3lUT+RCBQBZ msVRBIaUC/IDiaxONk7r35LGt+kiu8dp3Ej0dYpEm2MJTmMpHocqFF2PQ1VZNwPCnRpp w2Xw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zxu6KINxLNHNyp6D+HUlx2eL0Z4pY5AXAf49O5rqj6A=; b=THEqc6+CvdBhtkOE7cJBbqJGg7XDqX6PouUQhbU04XUX+6cc25TFiywwRHlTU/rn/3 xKvU+gCMX1nO15uYCzROVhLoafDjrb6VOuEEdjjw5cz+bwP2n/xYO5XKNU20G4I+9TyB jNz0qhKh2zmRbMx3FH9YgLK6Nz6ro8h7ZuAq/OT6LLJT83CkmOapqFF8/QZTAI1P7tEl uTKh0ZXq+Z8Ke4YbH0UVZBut83KM0QaN/FZlwmCeJ7yZKngk412hKFURzYPgrrJL//19 IEh9OqwnVGQBIT1Iu595tC2miSA3CROJzM6MMnbHpYPW4RgAO8/bte91ixDXXqcI3Z4F f4aQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cBCUYNHP; 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=pass (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 i4-20020ad45c64000000b0046eee6ce56fsi6967923qvh.399.2022.06.27.23.05.19 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:05:19 -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=pass header.i=@linaro.org header.s=google header.b=cBCUYNHP; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51462 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64Lf-0006ES-0E for patch@linaro.org; Tue, 28 Jun 2022 02:05:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43626) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Fz-0003Tr-Jf for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:24 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:41699) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Fx-0008Mm-5N for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:23 -0400 Received: by mail-pg1-x530.google.com with SMTP id 23so11059700pgc.8 for ; Mon, 27 Jun 2022 21:55:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zxu6KINxLNHNyp6D+HUlx2eL0Z4pY5AXAf49O5rqj6A=; b=cBCUYNHPK+CnqgoDTUgj6Xdpe68GwVrVwfHhgZDNNM5qAGI1VjPSu8xl+KvR5P73ci +oNK4+oE4LdCN4ds7ftO6wlb+cCrNO8KPsd3Ft16r4ntdx6Bklvg3QVJTpzL1iwmQX2x Rs7wbz/q5v9yLPgwCWqdd8nKU/pNV+nZiuGeV/DEucmBbLeI7LMIQvd4RnppRKW20xX8 Qwq45WsYSZecuO4PZ215wXRKsFjod4xf5neYzU4RfvCRW60lBg2ZvA9+DTr/j5+LE0TH ZeN8EtySP8sX3RbCkrmzsZM7hGOPDcWP4O/mteUrW3EwSu8opeFhkdFcotH2JhKnOQQk 20Jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zxu6KINxLNHNyp6D+HUlx2eL0Z4pY5AXAf49O5rqj6A=; b=hC4cOJ6Vm9PlN3D9XFnzMW/tpOrkmFhptLMH3MSbCIqRBCGGf+nhj3jdqocMMZM1Sa RfV8fgfxgezqq0jQ6H2lQ2O0cwuElMgzlgrpZzzHhASEvs6DJ/nyEOUpyh2TYXa+6K5X lBc+Gl3Yuqwh1LOxKokXwo5hrCuHklO1XUxvYMvEhyJjfppaP2gNvPNkZMKNYJ/aPYk5 2LvI/Tg1MZaqYFABZ0nUqGVwy4EnLBoXIfFUKmHy4ZAZZqtzIwLfIxKb0jYUtfUdoI05 VYwLhuz9Gfhi6KWRsdZ9d2sjcxDZnP7Z8fQIHcSl3EuNFuTO0ukwoxMYTlDfnZvZKA9Q jAiw== X-Gm-Message-State: AJIora9OeYlGeHFDBpV/KEyEbTWW2oVr4BcJ2a75UTaPHN3ayCeaHUQa AEY5qIelem2C7/lfShEXDezas8Geb07MiA== X-Received: by 2002:a63:4a4e:0:b0:401:baa6:d695 with SMTP id j14-20020a634a4e000000b00401baa6d695mr16690155pgl.259.1656392120327; Mon, 27 Jun 2022 21:55:20 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 30/60] semihosting: Split out semihost_sys_write Date: Tue, 28 Jun 2022 10:23:33 +0530 Message-Id: <20220628045403.508716-31-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_WRITE to a reusable function. This handles all GuestFD. This removes the last use of common_semi_syscall_len. Note that gdb_do_syscall %x reads target_ulong, not int. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 6 ++++ semihosting/arm-compat-semi.c | 52 +------------------------------- semihosting/syscalls.c | 54 ++++++++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+), 51 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 20da8138b0..2464467579 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -33,4 +33,10 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len); +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len); + +void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 8da31d8507..d591fcd7c2 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -215,8 +215,6 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static target_ulong common_semi_syscall_len; - static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (err) { @@ -230,9 +228,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) /* Fixup syscalls that use nonstardard return conventions. */ target_ulong reg0 = common_semi_arg(cs, 0); switch (reg0) { - case TARGET_SYS_WRITE: - ret = common_semi_syscall_len - ret; - break; case TARGET_SYS_SEEK: ret = 0; break; @@ -294,30 +289,10 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len); typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - CPUArchState *env = cs->env_ptr; - uint32_t ret = 0; - char *s = lock_user(VERIFY_READ, buf, len, 1); - (void) env; /* Used in arm softmmu lock_user implicitly */ - if (s) { - ret = write(gf->hostfd, s, len); - unlock_user(s, buf, 0); - if (ret == (uint32_t)-1) { - ret = 0; - } - } - /* Return bytes not written, on error as well. */ - common_semi_cb(cs, len - ret, 0); -} - static void host_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, isatty(gf->hostfd), 0); @@ -340,13 +315,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - common_semi_syscall_len = len; - gdb_do_syscall(common_semi_cb, "write,%x,%x,%x", gf->hostfd, buf, len); -} - static void gdb_isattyfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); @@ -380,13 +348,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_writefn(CPUState *cs, GuestFD *gf, - target_ulong buf, uint32_t len) -{ - /* This fd can never be open for writing */ - common_semi_cb(cs, -1, EBADF); -} - static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, 0, 0); @@ -404,7 +365,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_writefn *writefn; sys_isattyfn *isattyfn; sys_seekfn *seekfn; sys_flenfn *flenfn; @@ -412,19 +372,16 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .writefn = host_writefn, .isattyfn = host_isattyfn, .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .writefn = gdb_writefn, .isattyfn = gdb_isattyfn, .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .writefn = staticfile_writefn, .isattyfn = staticfile_isattyfn, .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, @@ -449,7 +406,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - uint32_t len; GuestFD *gf; int64_t elapsed; @@ -531,13 +487,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].writefn(cs, gf, arg1, len); + semihost_sys_write(cs, common_semi_rw_cb, arg0, arg1, arg2); break; case TARGET_SYS_READ: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index d42a190746..5cb12d6adc 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -107,6 +107,13 @@ static void gdb_read(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, buf, len); } +static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + gdb_do_syscall(complete, "write,%x,%x,%x", + (target_ulong)gf->hostfd, buf, len); +} + /* * Host semihosting syscall implementations. */ @@ -193,6 +200,22 @@ static void host_read(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + void *ptr = lock_user(VERIFY_READ, buf, len, 1); + ssize_t ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = write(gf->hostfd, ptr, len); + complete(cs, ret, ret == -1 ? errno : 0); + unlock_user(ptr, buf, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -286,3 +309,34 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, EBADF); } } + +void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + switch (gf->type) { + case GuestFDGDB: + gdb_write(cs, complete, gf, buf, len); + break; + case GuestFDHost: + host_write(cs, complete, gf, buf, len); + break; + case GuestFDStatic: + /* Static files are never open for writing: EBADF. */ + complete(cs, -1, EBADF); + break; + default: + g_assert_not_reached(); + } +} + +void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong buf, target_ulong len) +{ + GuestFD *gf = get_guestfd(fd); + + if (gf) { + semihost_sys_write_gf(cs, complete, gf, buf, len); + } else { + complete(cs, -1, EBADF); + } +} From patchwork Tue Jun 28 04:53:34 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585524 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp478939mab; Mon, 27 Jun 2022 23:38:24 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uuQpl02cSbsmc2vZz6TeY8arL9Am6bI6cEB+9dPirmBk78hD8yt/x4wRnrRlX3H9zE+jhi X-Received: by 2002:a05:622a:1a93:b0:31b:efe5:8b6 with SMTP id s19-20020a05622a1a9300b0031befe508b6mr1422259qtc.347.1656398304638; Mon, 27 Jun 2022 23:38:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398304; cv=none; d=google.com; s=arc-20160816; b=WmizpnAQqROKpswAMS/NjLl8NMfema5KlXR3TZSfvw3Vn+r5fMswnoorJX1PzmMTog QE2dmeIC2qwJvwLSpL5aF8IYigvTviPIPTlBEt76RfEZjZGHb5PxSq/GA/ahd6Z2Il+I iLIp8sB4SVHcUK1gyFKOrtiZFMyYsZuaC1NsH6PNu3eSUXShT+pLrNucQhAAN4lPVown aidFIMCu3K0vr02C+UcfunGpEhtQ7lCOKqR3dMMtMvKx3/Hy5FqVVbqAecceTj6zDbwG p24FKbAHu0ue8stng0Cq0pF3mVwbOx+MgiWQK1RmdhC5GrZaRPoB8BjYUc7EOybaoO9t l7bA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=BeS68NN3ViIVt950y4ivDmAvcVcb3oQ70+IeLQ73SLs=; b=S7z1Tpuhnk+2T8aw6RTgIO2oRE2ClbF44chPcer953jvLCEsnFJsGhFjgkvyIlL9uX YKoeWQps17W/hl3V8wrM72NYEw/j5GIWBowA569jncrp/eTq59yc5Y63I6mNyPSVxeqB d28E7Zhzeq0sZhcX4cAtpHHckrv3RxgEGK4XRokCWl4xwbMmz3O+hiyyCMFwemNdoirc mqbQzFVwyCfAJHDaq5R+dmUv/90C1eiXzcXLn/3Yi5ApzMp9T3K45UhLssubIe2yJfKn 7Kq0uI7tI07HAfP4yWohqTaCFAx3xN81F6XejRwgEFJ0erkBur3A+7pXkZoX/oy7tXNX 10nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jwGBVqhw; 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=pass (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 c9-20020a05620a11a900b0069c7ad4331bsi236796qkk.571.2022.06.27.23.38.24 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:38: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=pass header.i=@linaro.org header.s=google header.b=jwGBVqhw; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35320 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64rf-0003BJ-SU for patch@linaro.org; Tue, 28 Jun 2022 02:38:23 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43642) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63G2-0003WG-BQ for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:26 -0400 Received: from mail-pf1-x42e.google.com ([2607:f8b0:4864:20::42e]:46714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63G0-00009v-2G for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:25 -0400 Received: by mail-pf1-x42e.google.com with SMTP id a15so10914775pfv.13 for ; Mon, 27 Jun 2022 21:55:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=BeS68NN3ViIVt950y4ivDmAvcVcb3oQ70+IeLQ73SLs=; b=jwGBVqhwFq3YqIFYlA19VFZ78Yp0mFy6lQ6e+XCYwsX1PsDtwfbOXDJRFKVWVLITZb oTPR4PG4WTFCisEr6CpNzQS9WUC1zxuz9/pDOdt9IU7BQ0ED/G4qcr+VIJtwtTPlcDZm TUMBwFYkT0T+Plcd6ib438HF2ABJ5hEarlAz/YuAQdbMWOiE6ILsaWtuUh9X9EP5+JRc 1ODQ2WuzcqW7jLJQuWqpkz7I2QB+RaNremaXTwEzU2UksmTcZLsIpPf+J7lVg0463ZKL XAoBhJhwX/JnsmLxSYKZAbEFbKxp0p4JxkbxwBz7YsZwSCn7N+e44jBXSaHNF8fWkE7v ADUQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=BeS68NN3ViIVt950y4ivDmAvcVcb3oQ70+IeLQ73SLs=; b=lsTmC8aL7UEOwAdhPEvf9nqnb1jEtJXwmgQ13Asg53dpIXyLzCYmaUW9B4Qy0KqUrz QK0uGv7FRrc5zRVD5IsHdpF/dLwpFOHgc/zvqD33+SZnM5v/uF+VOV5qS5hdhZEx6lNq HdxyqNmiylRc6PYivmtZ9ke+E+XetwzCoTia0cwtrpxcMwaBO1BzL27AKmr/TuGVc6yY HSg5adtVZIYyziMb3s0fpTYgeEnf2i/0O/B3RS+kkmeSWW1hBrRA7nTk2glA9Ts8qwQ9 paXDG3i1C2yf9QVWhGoFpfppN1OM8k7zqQ40mnuPXeOBIugTIwLUIxZ4bihzWSCSty6p ASig== X-Gm-Message-State: AJIora+cYxqRslRu7oOMU44z+IelsR9aYSHdH5xvk5A0lkAoYaIybNDI KyrW2sFiqW6Kr1AVJNnR2dd7VkETi0Ss9Q== X-Received: by 2002:a63:7d45:0:b0:40b:e6ad:8e80 with SMTP id m5-20020a637d45000000b0040be6ad8e80mr16354704pgn.59.1656392122573; Mon, 27 Jun 2022 21:55:22 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 31/60] semihosting: Bound length for semihost_sys_{read,write} Date: Tue, 28 Jun 2022 10:23:34 +0530 Message-Id: <20220628045403.508716-32-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42e; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42e.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Fixes a minor bug in which a 64-bit guest on a 32-bit host could truncate the length. This would only ever cause a problem if there were no bits set in the low 32, so that it truncates to 0. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- semihosting/syscalls.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 5cb12d6adc..eefbae74f1 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -283,6 +283,14 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len) { + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_read(cs, complete, gf, buf, len); @@ -313,6 +321,14 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len) { + /* + * Bound length for 64-bit guests on 32-bit hosts, not overlowing ssize_t. + * Note the Linux kernel does this with MAX_RW_COUNT, so it's not a bad + * idea to do this unconditionally. + */ + if (len > INT32_MAX) { + len = INT32_MAX; + } switch (gf->type) { case GuestFDGDB: gdb_write(cs, complete, gf, buf, len); From patchwork Tue Jun 28 04:53:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585526 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp480995mab; Mon, 27 Jun 2022 23:42:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uV6P7m/vRB/+shuA/CKXvjr5JtwTGcSZU48YUbYhMzNZquCFG4iTVKlzXyyHdvvR3maI7y X-Received: by 2002:ac8:58d2:0:b0:305:116c:de96 with SMTP id u18-20020ac858d2000000b00305116cde96mr12153562qta.14.1656398532327; Mon, 27 Jun 2022 23:42:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398532; cv=none; d=google.com; s=arc-20160816; b=TtXa0zJSQHSdReqmQym5doi2wMMMsqgGuN5kn4P+bQmhiIKDZVkzCFpbvYcJBIxSYE HAyB2QDAkPx1opUwuWfTBzx7/X8+ueWILzN40o5ZrBX54aqfi/BBQD68vvbvnosbDfCt tUeB/RuI+GdYFpuw/1X8p65LXefeadO3zb93jGNMdcc/2mvMUA/kAHD2zbRn/42vo66J oYwn3B+ufG67x+2HSoAjVawLZoPRWNjIYrsLgpmCLc14xdlEMtej8LNVsOlyHjzDhcQL eTUSrMMisbjYkwGwc7kcZEcSKs01o7gBgaCTsbxxYGP+CNsQY4FsjqIZE4z9q1d+rWbN lX2Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=10Sm3AeWIBieyWVHcZYCqLqccWMHZXhdScLSkrcOWBg=; b=aTfuwgGcIK3ZOAQXW31by9U+NEdr6Gye5dPH5p+5cZFRPa+5HZ4o+yqoxv7pAkwVRC TJdst++Gq91B0E0EUaO1gHsdN3WU9F6qiG44lHunrKbjRjK1o15kTfIbyKrjJgTNhL8u Z14SyxemseNm2X6hY9Sj60TDl+VNycGldssl8NVhILkMLH4tsX3udeDp7NI4sMrVKp4G RTvx7JYOM+O+2DR6fcVyEULr6NFEsdr3GD3FNIzvEiKRDD2m/neGqVZ6bgQEMd8lZ+vL rJBBh4t9clx6GIV/c/sAk8GNhbIF1MpfK0idyRL4FWDTUjU8lqMTUkXw+acMw5Cfk38N Lgsw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="fFt/E0Z0"; 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=pass (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 c8-20020ac80088000000b00304fec7114asi6043602qtg.180.2022.06.27.23.42.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:42:12 -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=pass header.i=@linaro.org header.s=google header.b="fFt/E0Z0"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40492 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64vL-00077f-QC for patch@linaro.org; Tue, 28 Jun 2022 02:42:11 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43680) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63G7-0003bG-Nn for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:33 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:51862) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63G5-0000Dc-Po for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:31 -0400 Received: by mail-pj1-x1029.google.com with SMTP id l2so10250429pjf.1 for ; Mon, 27 Jun 2022 21:55:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=10Sm3AeWIBieyWVHcZYCqLqccWMHZXhdScLSkrcOWBg=; b=fFt/E0Z0g283YMBON7DbCxqJ8v1rcOW8l+QOvGs7Chp6cQeJe9f8wOS5d9Y2Ssv7/0 dTIVbfUAe+pFxJhJuIJCyyzPUQwDC/zxJQNlq0VYJAk4lnWRni+uYQZdLHU7VtpPZl3i Y/C4YtMCpEHrByBzTWeYgjcsBUPvqCnSdPtoCfYogy8zObWPkHP+cTJ742dcxgA78L1h fjiKV1ym7UfZHsS67PWs2PScjEmwTjb/frWeQvI8sialWURR5Ta1sJzoea+BcYJUALmX 2bHJhPk15iqHORP0TpOwynxgvos3M5qjbCbcJg2ca6av3FogQEUP/UDlVoZ2l96ZHe17 DHYg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=10Sm3AeWIBieyWVHcZYCqLqccWMHZXhdScLSkrcOWBg=; b=BTW5cCzEoDurhYGLmZ7R2o8l5MizezraWJ0fBc73HwBCnJ+gXIWzx+5ol1FY+GJ3TC wjcHjxOQu2FYodgeb6/ZcLJzoFAZ98sgCOfoMQ10gm6XU1TyzsrZVEEhZF/XNQA1iEra faGDu+iW7bX9+2EqtPIkt/0+hITMfJPVrH0iYe2+1A1szm7sTTGqRszK0KkxoZj4yEWg nKSUloKT70KQMeianxByhGTzpj12ilTZe25gmugHUd0R4G++tCk7h3f6tdb6P91Ic42t sCdVQPYQpQio1O65IIwgYb+BmwX4Aa9r9VgUbuoBQ2aDIyFb9DTCSwYEeD1zXiX/7+mT N67w== X-Gm-Message-State: AJIora+1Hu99RWeWJ7EManeALy3rB1QvGAm6Z5KRLpant3kzX5gveKOd py6C82rEZJWULCFo+krqc3B/1VhaxWkn5w== X-Received: by 2002:a17:903:11c9:b0:16b:8293:c5a1 with SMTP id q9-20020a17090311c900b0016b8293c5a1mr1808341plh.72.1656392125013; Mon, 27 Jun 2022 21:55:25 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 32/60] semihosting: Split out semihost_sys_lseek Date: Tue, 28 Jun 2022 10:23:35 +0530 Message-Id: <20220628045403.508716-33-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1029; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1029.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_SEEK to a reusable function. This handles all GuestFD. Isolate the curious ARM-specific return value processing to a new callback, common_semi_seek_cb. Expand the internal type of the offset to int64_t, and provide the whence argument, which will be required by m68k and nios2 semihosting. Note that gdb_do_syscall %x reads target_ulong, not int. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 5 +++ include/semihosting/syscalls.h | 3 ++ semihosting/arm-compat-semi.c | 51 ++++++--------------- semihosting/syscalls.c | 81 ++++++++++++++++++++++++++++++++++ 4 files changed, 102 insertions(+), 38 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 95a8b7b056..b588c306cc 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -41,6 +41,11 @@ #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 +/* For gdb file i/o remote protocol lseek whence. */ +#define GDB_SEEK_SET 0 +#define GDB_SEEK_CUR 1 +#define GDB_SEEK_END 2 + /* For gdb file i/o stat/fstat. */ typedef uint32_t gdb_mode_t; typedef uint32_t gdb_time_t; diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 2464467579..841a93d25b 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -39,4 +39,7 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, GuestFD *gf, target_ulong buf, target_ulong len); +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index d591fcd7c2..a117d180bc 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -224,16 +224,6 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) #else syscall_err = err; #endif - } else { - /* Fixup syscalls that use nonstardard return conventions. */ - target_ulong reg0 = common_semi_arg(cs, 0); - switch (reg0) { - case TARGET_SYS_SEEK: - ret = 0; - break; - default: - break; - } } common_semi_set_ret(cs, ret); } @@ -257,6 +247,18 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } +/* + * SYS_SEEK returns 0 on success, not the resulting offset. + */ +static void common_semi_seek_cb(CPUState *cs, target_ulong ret, + target_ulong err) +{ + if (!err) { + ret = 0; + } + common_semi_cb(cs, ret, err); +} + /* * Return an address in target memory of 64 bytes where the remote * gdb should write its stat struct. (The format of this structure @@ -290,7 +292,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * via common_semi_cb. */ typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); -typedef void sys_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); static void host_isattyfn(CPUState *cs, GuestFD *gf) @@ -298,12 +299,6 @@ static void host_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, isatty(gf->hostfd), 0); } -static void host_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - off_t ret = lseek(gf->hostfd, offset, SEEK_SET); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -320,11 +315,6 @@ static void gdb_isattyfn(CPUState *cs, GuestFD *gf) gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); } -static void gdb_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gdb_do_syscall(common_semi_cb, "lseek,%x,%x,0", gf->hostfd, offset); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -353,12 +343,6 @@ static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) common_semi_cb(cs, 0, 0); } -static void staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) -{ - gf->staticfile.off = offset; - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); @@ -366,24 +350,20 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) typedef struct GuestFDFunctions { sys_isattyfn *isattyfn; - sys_seekfn *seekfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { .isattyfn = host_isattyfn, - .seekfn = host_seekfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { .isattyfn = gdb_isattyfn, - .seekfn = gdb_seekfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { .isattyfn = staticfile_isattyfn, - .seekfn = staticfile_seekfn, .flenfn = staticfile_flenfn, }, }; @@ -520,12 +500,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SEEK: GET_ARG(0); GET_ARG(1); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].seekfn(cs, gf, arg1); + semihost_sys_lseek(cs, common_semi_seek_cb, arg0, arg1, GDB_SEEK_SET); break; case TARGET_SYS_FLEN: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index eefbae74f1..9e3eb464b5 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -114,6 +114,13 @@ static void gdb_write(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, buf, len); } +static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int gdb_whence) +{ + gdb_do_syscall(complete, "lseek,%x,%lx,%x", + (target_ulong)gf->hostfd, off, (target_ulong)gdb_whence); +} + /* * Host semihosting syscall implementations. */ @@ -216,6 +223,29 @@ static void host_write(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(ptr, buf, 0); } +static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int whence) +{ + /* So far, all hosts use the same values. */ + QEMU_BUILD_BUG_ON(GDB_SEEK_SET != SEEK_SET); + QEMU_BUILD_BUG_ON(GDB_SEEK_CUR != SEEK_CUR); + QEMU_BUILD_BUG_ON(GDB_SEEK_END != SEEK_END); + + off_t ret = off; + int err = 0; + + if (ret == off) { + ret = lseek(gf->hostfd, ret, whence); + if (ret == -1) { + err = errno; + } + } else { + ret = -1; + err = EINVAL; + } + complete(cs, ret, err); +} + /* * Static file semihosting syscall implementations. */ @@ -241,6 +271,33 @@ static void staticfile_read(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(ptr, buf, len); } +static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, int64_t off, int gdb_whence) +{ + int64_t ret; + + switch (gdb_whence) { + case GDB_SEEK_SET: + ret = off; + break; + case GDB_SEEK_CUR: + ret = gf->staticfile.off + off; + break; + case GDB_SEEK_END: + ret = gf->staticfile.len + off; + break; + default: + ret = -1; + break; + } + if (ret >= 0 && ret <= gf->staticfile.len) { + gf->staticfile.off = ret; + complete(cs, ret, 0); + } else { + complete(cs, -1, EINVAL); + } +} + /* * Syscall entry points. */ @@ -356,3 +413,27 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, EBADF); } } + +void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, int64_t off, int gdb_whence) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_lseek(cs, complete, gf, off, gdb_whence); + return; + case GuestFDHost: + host_lseek(cs, complete, gf, off, gdb_whence); + break; + case GuestFDStatic: + staticfile_lseek(cs, complete, gf, off, gdb_whence); + break; + default: + g_assert_not_reached(); + } +} From patchwork Tue Jun 28 04:53:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585553 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp527050mab; Tue, 28 Jun 2022 00:56:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vtq9k4t8XW4TFl82GS6oKUK9YPrn4So+bgTm1gLjRQAdbSna28+KrX2FMSutPTGXXmp5Y1 X-Received: by 2002:a0c:e888:0:b0:470:4b73:fbb with SMTP id b8-20020a0ce888000000b004704b730fbbmr1244680qvo.128.1656403012367; Tue, 28 Jun 2022 00:56:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656403012; cv=none; d=google.com; s=arc-20160816; b=e9pU5FY/DwG+h+XcuzlbhP+glyQtYiIbYVKUbO3MpVZoFz8Po57VmNHd0YxiWelATF Yq0M9PcxbRvaeulRH20tcHEyO5/RRJ3MmUQxwh47ZD9PEKwc9J+RO1oGvAAxP84CupU6 nG/9sGqyfSQnZI7K2+ALGzglnohxdb3JXu1vRoUxpEwUd7CxlRD1kOhxknjznH/SvcBD TtXPeXdgRueq4D6oVtEkEa0p87D5SVzIvjZQQ5RL7G5SsQmoIPaejrqj4CDt0EXHXw7W dB7vVywdNG2Ou9RAHfFVibBlHLodomWrfxdQZCrQtASIuxFDfyWrN5PTOwaWs8+6Ok1+ GXUA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=N4HA6P3LhSfjOwoWfaJXDw0oNNYju2wXfDZ+QMa3+ug=; b=rfkYX3ns20wgDkklpVCwzciUgE+7iskd18qX5za26T6aG+QL/M1ORzGFXy27fMG8Tp R6cGkiUdQceLWrrtlhjg60EOQ3WkuDGvrUPfVsUYcgCpUD2iCezX7IgR+lI+X6ABWvt3 At9pedkEd89EOHyUnKcTCCY9jcFE8pdqEbFH88cCwbYr1AHTXTBDc54ZhcxYEbotobkx vgIHE96uS33GndUrvqG6IFRN4Ff2DQ13Oz0U+t7ctKfn6mH6SQl52OfxRosNxujK/tA2 MszSPCtYiiX+M4SAQvQIEMpx5uGEIh+FfLqBxvKnKVxBGkGUVNLP1TN5DNWgY1Y253mA fA3Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRuIinTN; 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=pass (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 a17-20020a05620a439100b006a7794a2fe8si7654081qkp.499.2022.06.28.00.56.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:56:52 -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=pass header.i=@linaro.org header.s=google header.b=cRuIinTN; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o665Y-0002B3-Pk for patch@linaro.org; Tue, 28 Jun 2022 03:56:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43694) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63G9-0003bi-Jk for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:33 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:45990) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63G7-0000FM-Ct for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:32 -0400 Received: by mail-pf1-x42a.google.com with SMTP id 128so10916483pfv.12 for ; Mon, 27 Jun 2022 21:55:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=N4HA6P3LhSfjOwoWfaJXDw0oNNYju2wXfDZ+QMa3+ug=; b=cRuIinTNBgorQM6jGfSD1MdnylEjYdekm+RlbjoCDJWnLRCadZmrPC8xSOiVgS8g5Z ysnFeHLDxhsxqTNVVShvRvfVNb2nTIUTUikN03d07CsJ4W3BMXHSThNiDjzfqd4bBRuB mh+ZAAynGORRIHyF8lTcDtBIsrv9XLA+yChlMWlZlwpb673j+mIttMH1lA/Dl0I0Cmpz tLes+ExYT/Y7r875aKUoAFSx6XFSwwXxBAUVvwR5eB5UAzj81WVM2S9UrPaqtIb9T5kt pq4f8UVvzhB3TKuuV+VbP/Hl7o+GJMHvCxFwODi1u2TBJOPkzJqW9T8JEhb1twB5+qHD 5uwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=N4HA6P3LhSfjOwoWfaJXDw0oNNYju2wXfDZ+QMa3+ug=; b=Z5a40b+hIzzbJVwtR7K9w9xEIFvCZqBRhTdX9O7CN2BlJAqj/P6D3c78rWjCDALbVI ixYxdAApVPCliXt6evnuvOJ2YTUTAVBUIQvE80I9sbDYJbAqEtxeYOUn0Gid71wRAkx6 jm8MQAwxswGxzLpUvWyLaySQwfyXpNq234qSlRlwtinBjpqts9QzTfSswvhursfufJBQ lRB9zv9DQPrXsfs5DqX6ZfChNVaCWrVxAb93xZNZCk2mhgqHb5hpVIKF1AnQOD5gFzpl 9AmNBFmvxABx4pOD9BPcXM79zsgDoR/QboqcuNuABBV0+p82Bop2yopYsFXZbLp9fBYr IHtA== X-Gm-Message-State: AJIora9HqSkjrQSh/mtdn37stMGjz5S935U6qBh4lM30T5dd+ae9vqxH qnd4bRwkvhsX/2DqsNQISATvOd/wOmAbmQ== X-Received: by 2002:a63:7c3:0:b0:40d:5dc5:f9f0 with SMTP id 186-20020a6307c3000000b0040d5dc5f9f0mr15529137pgh.524.1656392129985; Mon, 27 Jun 2022 21:55:29 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 33/60] semihosting: Split out semihost_sys_isatty Date: Tue, 28 Jun 2022 10:23:36 +0530 Message-Id: <20220628045403.508716-34-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_ISTTY to a reusable function. This handles all GuestFD. Add a common_semi_istty_cb helper to translate the Posix error return, 0+ENOTTY, to the Arm semihosting not-a-file success result. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 40 ++++++++++++---------------------- semihosting/syscalls.c | 36 ++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 26 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 841a93d25b..c60ebafb85 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -42,4 +42,7 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, int fd, int64_t off, int gdb_whence); +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + int fd); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index a117d180bc..3cdc2b6efc 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -247,6 +247,19 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, arg2 - ret); } +/* + * Convert from Posix ret+errno to Arm SYS_ISTTY return values. + * With gdbstub, err is only ever set for protocol errors to EIO. + */ +static void common_semi_istty_cb(CPUState *cs, target_ulong ret, + target_ulong err) +{ + if (err) { + ret = (err == ENOTTY ? 0 : -1); + } + common_semi_cb(cs, ret, err); +} + /* * SYS_SEEK returns 0 on success, not the resulting offset. */ @@ -291,14 +304,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) * do the work and return the required return value to the guest * via common_semi_cb. */ -typedef void sys_isattyfn(CPUState *cs, GuestFD *gf); typedef void sys_flenfn(CPUState *cs, GuestFD *gf); -static void host_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, isatty(gf->hostfd), 0); -} - static void host_flenfn(CPUState *cs, GuestFD *gf) { struct stat buf; @@ -310,11 +317,6 @@ static void host_flenfn(CPUState *cs, GuestFD *gf) } } -static void gdb_isattyfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_cb, "isatty,%x", gf->hostfd); -} - static void gdb_flenfn(CPUState *cs, GuestFD *gf) { gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", @@ -338,32 +340,23 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_isattyfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, 0, 0); -} - static void staticfile_flenfn(CPUState *cs, GuestFD *gf) { common_semi_cb(cs, gf->staticfile.len, 0); } typedef struct GuestFDFunctions { - sys_isattyfn *isattyfn; sys_flenfn *flenfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .isattyfn = host_isattyfn, .flenfn = host_flenfn, }, [GuestFDGDB] = { - .isattyfn = gdb_isattyfn, .flenfn = gdb_flenfn, }, [GuestFDStatic] = { - .isattyfn = staticfile_isattyfn, .flenfn = staticfile_flenfn, }, }; @@ -489,12 +482,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_ISTTY: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].isattyfn(cs, gf); + semihost_sys_isatty(cs, common_semi_istty_cb, arg0); break; case TARGET_SYS_SEEK: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 9e3eb464b5..1f1baf7e2d 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -121,6 +121,12 @@ static void gdb_lseek(CPUState *cs, gdb_syscall_complete_cb complete, (target_ulong)gf->hostfd, off, (target_ulong)gdb_whence); } +static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); +} + /* * Host semihosting syscall implementations. */ @@ -246,6 +252,13 @@ static void host_lseek(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret, err); } +static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + int ret = isatty(gf->hostfd); + complete(cs, ret, ret ? 0 : errno); +} + /* * Static file semihosting syscall implementations. */ @@ -437,3 +450,26 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, 0, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_isatty(cs, complete, gf); + break; + case GuestFDHost: + host_isatty(cs, complete, gf); + break; + case GuestFDStatic: + complete(cs, 0, ENOTTY); + break; + default: + g_assert_not_reached(); + } +} From patchwork Tue Jun 28 04:53:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585529 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp484539mab; Mon, 27 Jun 2022 23:48:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sWGhpmg/4GTvbM7kfjpsVhwQr5AkJ6LP3Y09Rse1kcue+gw272Vjk29xfu/EDUkc8BDnS2 X-Received: by 2002:a05:6214:238a:b0:441:76a5:2331 with SMTP id fw10-20020a056214238a00b0044176a52331mr1339356qvb.96.1656398907235; Mon, 27 Jun 2022 23:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398907; cv=none; d=google.com; s=arc-20160816; b=FvvoYy7Zok31RprGGoyg+NJ+fpRJy0Jh154RMEKERi9EfCkUsGAgxGt8W7fvK/20if Kr2M7newVW4CaU+fyqJ9y/cZzKnOO3eczPtVzOifPQiKFC+KWV/e96bsQru/wsqoOkrc avazR4yv0oIMAl9SzJNejVkn2yDTgucP6bVT14uqyFOburexWEbZ517cNA8QB7JuZTjb WpDD1RGbmTcb3mKHpcvw9pnbaCb7DqS2mqpHnwAoFUxs6kOjsYe6lhW2NBu5evGYY0V0 0QRuCDhCGnxjUAIET28iQsRTFZ5HKnM6SlrCsL7wHo+M63OnDMFFe4hLKejxzPz+D3MB vvHQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=e0dAQ/YOvhpKY6EYJN7zTJpG6M7hET9zvzuE2OXVj4w=; b=yvSdBanJ48L0Mz85A3ZwihGl6QBl9BFEnUzfYH8iTkq2XAwKg7vuqtkNzuL6El58H3 n5/Bt7IqtJBFhDX7LK8PZAG88LhXxzCYxfOFMdt1cVBqVVCFQQnfNx+p7rmnfZoTHq7V UIUXKx5WVc/2kXhJdmegKEEJwKrJSccA7AZ4QLzzC/rsM27Jd4AQluirKe1oyBduJu6L CPuaSfrWvWs/Ll7FVHnAA1gVjsK7Dz//DCFZxRCpZ/9Zzwf6rJXsXYxfjvoQuU6KlkzU rG6oC6xHWLhLsdDTvMHhVev5TbOHBji4mI0LER7B5aMlb6rxyGs1EokzRsO7o+Z6YNWt Mp8w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kR6vAJgv; 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=pass (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 eo13-20020ad4594d000000b0046e7dbde39fsi6039955qvb.352.2022.06.27.23.48.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:48:27 -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=pass header.i=@linaro.org header.s=google header.b=kR6vAJgv; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:48862 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o651O-0004iQ-Bq for patch@linaro.org; Tue, 28 Jun 2022 02:48:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43710) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GB-0003dR-Dq for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:35 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:33711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63G9-0000G4-JG for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:35 -0400 Received: by mail-pg1-x536.google.com with SMTP id z14so11119047pgh.0 for ; Mon, 27 Jun 2022 21:55:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=e0dAQ/YOvhpKY6EYJN7zTJpG6M7hET9zvzuE2OXVj4w=; b=kR6vAJgvPy9rX0YSGbP9GJZ+JljizWuAmR/XtmMbR7NVC0+ss8+a1Fthg/hUYOMXUX TNUHvcplcW17YttQl+pgF6j0rxV983cIVuRs+EPI9lctuKUeMKFmrW8ueWW3jrzRXIzq RoR6SC4nHralehXTr4o41hWKUs9WrOT3Cjc8FgNcV7hei1ascMT4j/OmU8HT+pNGTx0m Hq5S9GMb71/ygnLRQXl/BWgMRJJMBEERQJ0urMh+WlERpdS4h3Go+DYoY0wrw+O/ouRf DzXfgaaMNY2BtL9ox4OXvp0kwFrIb8Fn7WovuPIdyS9XFuCFHK2pcsimnyP5LPJ+Y7Eh AZxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=e0dAQ/YOvhpKY6EYJN7zTJpG6M7hET9zvzuE2OXVj4w=; b=4CL1qr/4fNGACf3jRR5Rfe5vUZxilVCSk/Hh9KH4y7JyOeFZsXyDHrUyoD+VPlkbu/ ZovOECKw/G7ZmreNG0GI5se9SJl3q0FFrvZlAHJND0tPQFaEMWK7qQqR0pZquuixy9r9 Ho4sFfCol5VUrdlyqxTvLmYxtF3M/dKqTyoryaWOOTg8k9g4MpUaFymVi1piwexoWtaH MBTQCx9dxMoyZE6+XthXDG5Pic4ayKwYmGJ7M6i0CNuIuTeWA68f169jf6YVPhDEySg+ DCgXCa35eJsBWqlUoxF2hz8Nx0Np7zVj/vLNZfKoJKhrHcI6MPVTRzqC1acrXILOvczw Kd1w== X-Gm-Message-State: AJIora/8xLMXmLZInhwDs7fZu9V6BdAPeGAapBQ4tM6JaFPdBNBDTM4F KaAw7wrPeLOVhGn62M2vkC0mgr9bUleVkA== X-Received: by 2002:a65:4907:0:b0:3fd:bc3e:fb0a with SMTP id p7-20020a654907000000b003fdbc3efb0amr15350938pgs.123.1656392132293; Mon, 27 Jun 2022 21:55:32 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 34/60] semihosting: Split out semihost_sys_flen Date: Tue, 28 Jun 2022 10:23:37 +0530 Message-Id: <20220628045403.508716-35-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 ARM-specific SYS_FLEN isn't really something that can be reused by other semihosting apis, but there are parts that can reused for the implementation of semihost_sys_fstat. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 4 ++ semihosting/arm-compat-semi.c | 74 ++++++---------------------------- semihosting/syscalls.c | 49 ++++++++++++++++++++++ 3 files changed, 66 insertions(+), 61 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index c60ebafb85..1ae5ba6716 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -45,4 +45,8 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd); +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, + int fd, target_ulong fstat_addr); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3cdc2b6efc..68e13d9077 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -285,44 +285,25 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) { if (!err) { /* The size is always stored in big-endian order, extract the value. */ uint64_t size; - cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + - offsetof(struct gdb_stat, gdb_st_size), - &size, 8, 0); - ret = be64_to_cpu(size); + if (cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size), + &size, 8, 0)) { + ret = -1, err = EFAULT; + } else { + size = be64_to_cpu(size); + if (ret != size) { + ret = -1, err = EOVERFLOW; + } + } } common_semi_cb(cs, ret, err); } -/* - * 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 to the guest - * via common_semi_cb. - */ -typedef void sys_flenfn(CPUState *cs, GuestFD *gf); - -static void host_flenfn(CPUState *cs, GuestFD *gf) -{ - struct stat buf; - - if (fstat(gf->hostfd, &buf)) { - common_semi_cb(cs, -1, errno); - } else { - common_semi_cb(cs, buf.st_size, 0); - } -} - -static void gdb_flenfn(CPUState *cs, GuestFD *gf) -{ - gdb_do_syscall(common_semi_flen_cb, "fstat,%x,%x", - gf->hostfd, common_semi_flen_buf(cs)); -} - #define SHFB_MAGIC_0 0x53 #define SHFB_MAGIC_1 0x48 #define SHFB_MAGIC_2 0x46 @@ -340,27 +321,6 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; -static void staticfile_flenfn(CPUState *cs, GuestFD *gf) -{ - common_semi_cb(cs, gf->staticfile.len, 0); -} - -typedef struct GuestFDFunctions { - sys_flenfn *flenfn; -} GuestFDFunctions; - -static const GuestFDFunctions guestfd_fns[] = { - [GuestFDHost] = { - .flenfn = host_flenfn, - }, - [GuestFDGDB] = { - .flenfn = gdb_flenfn, - }, - [GuestFDStatic] = { - .flenfn = staticfile_flenfn, - }, -}; - /* * Do a semihosting call. * @@ -379,7 +339,6 @@ void do_common_semihosting(CPUState *cs) char * s; int nr; uint32_t ret; - GuestFD *gf; int64_t elapsed; nr = common_semi_arg(cs, 0) & 0xffffffffU; @@ -493,12 +452,8 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_FLEN: GET_ARG(0); - - gf = get_guestfd(arg0); - if (!gf) { - goto do_badf; - } - guestfd_fns[gf->type].flenfn(cs, gf); + semihost_sys_flen(cs, common_semi_flen_fstat_cb, common_semi_cb, + arg0, common_semi_flen_buf(cs)); break; case TARGET_SYS_TMPNAM: @@ -820,9 +775,6 @@ void do_common_semihosting(CPUState *cs) cpu_dump_state(cs, stderr, 0); abort(); - do_badf: - common_semi_cb(cs, -1, EBADF); - break; do_fault: common_semi_cb(cs, -1, EFAULT); break; diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 1f1baf7e2d..fff9550c89 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -127,6 +127,12 @@ static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); } +static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); +} + /* * Host semihosting syscall implementations. */ @@ -259,6 +265,18 @@ static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret, ret ? 0 : errno); } +static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + struct stat buf; + + if (fstat(gf->hostfd, &buf) < 0) { + complete(cs, -1, errno); + } else { + complete(cs, buf.st_size, 0); + } +} + /* * Static file semihosting syscall implementations. */ @@ -311,6 +329,12 @@ static void staticfile_lseek(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + complete(cs, gf->staticfile.len, 0); +} + /* * Syscall entry points. */ @@ -473,3 +497,28 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) g_assert_not_reached(); } } + +void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, + gdb_syscall_complete_cb flen_cb, int fd, + target_ulong fstat_addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + flen_cb(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_fstat(cs, fstat_cb, gf, fstat_addr); + break; + case GuestFDHost: + host_flen(cs, flen_cb, gf); + break; + case GuestFDStatic: + staticfile_flen(cs, flen_cb, gf); + break; + default: + g_assert_not_reached(); + } +} From patchwork Tue Jun 28 04:53:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585532 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp489128mab; Mon, 27 Jun 2022 23:56:27 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uA7aiHNjXvuRVmIit7s++PSDMtx9LpJtUYJCzsszP540dD32J4v87OVrzMlVnaQ/2UL3+r X-Received: by 2002:ac8:57cc:0:b0:305:1fc6:b0cb with SMTP id w12-20020ac857cc000000b003051fc6b0cbmr11994408qta.427.1656399387720; Mon, 27 Jun 2022 23:56:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399387; cv=none; d=google.com; s=arc-20160816; b=J5wmob6hbMJ8tpGGiqK38u9VJwgCwolXzsPbTNZSj5NWMy0L1/eNbahK/2qOKPVFjs XMo9FoxBhImgyuTI78goE6K3YLs3iTcFxuHPzvxnergp8SwjSIuwLaWMpFXA8IZ20D/i liB/ctg5Ldq95yhpTztnO17A/dExGsP/WSq7e77q0wj2/LmjYSCW79C6WewHC8uEWgOK 6K6tdzBj7Q5NvSirMP5wtg5MAhzW4/nwNiM263Hd4VrWTEWgP8fUk6zlhOM2N29OzdYH Tzh19ECgirWL868u/SOADWuUxjOJit8Sfz1ZH/P0i0a+si78fj3lPoNTJv+MdUi2Yiap 2TNQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=75MpsrFXvyEUWpCESuFADgwToaEzRn7+pYxzAo7cwTQ=; b=qiKJ5pKe5iNn3FqMPUqm297rf/DJYd+v9oAfTJoGRUvh74HGcuGOk0asIQou+ZzbnW JLTgQaPmJjL3sGRAh6EUVtCdyenK/R+JmrFgP80eU4MBfH2of/Lox9BvM+lszBH/cIjv c7NWDBicEChoI31oKQ0KPnAKbcXv24dh2Vk9Ji/pMRP8Xp6mhlhWXS+NiuhcNxkLPu35 FosadkJeQ4YIjmckZL2m17PkbSO+65OaxvjiFdcXLqmwv+6OlpFg7MiFeboEO55II4IQ SzGJcwjQEWMN16yE8SWr3TgjyFIobsAKZVFqQDQagjYsutRlns2NJXI6FvclRJPztp1r 5K4A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bsWBNFHh; 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=pass (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 64-20020a370b43000000b006a768c699acsi6243593qkl.325.2022.06.27.23.56.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:56:27 -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=pass header.i=@linaro.org header.s=google header.b=bsWBNFHh; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57324 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6599-0002Zi-7x for patch@linaro.org; Tue, 28 Jun 2022 02:56:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43726) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GD-0003j8-HN for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:37 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:56210) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GB-0000GM-Sk for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:37 -0400 Received: by mail-pj1-x102d.google.com with SMTP id w24so11407914pjg.5 for ; Mon, 27 Jun 2022 21:55:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=75MpsrFXvyEUWpCESuFADgwToaEzRn7+pYxzAo7cwTQ=; b=bsWBNFHhXhhcuJ/17hvviMdtaF/6DrfFR8dw+0nL4WieqMjJBkzXotPEWSHBJj7tBi qS4CllRk9MXE64fW+n7ZkHd0gmhfopvPRcxqY1D2eM3vaISYIsNHj7ia/tvNG88eKJ2J UgrEq2zm6HCUmhBI5QRJCSV2FNjs6jBizmuoCFyArvUQGheHsuqLvoB7V40GqQZoF8A6 pp5cuQHq5C7NMK4GTfdr5qr+FpXrMoR9lZNgelZGeXCW8WmxF99D8RIGndVBecVf/7dR gePE0CjmWvwf+nADF++aBNguw/NRbf91aWmb4sbHCCw/ZHz3NY5u+bm63apyh0whd7OR CSBw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=75MpsrFXvyEUWpCESuFADgwToaEzRn7+pYxzAo7cwTQ=; b=jhCZtP8aJeR8uz33yD+UkcLIOIhi4krT4J5AKw5fr63Wiqc9ksbeGGRdbtlxB5xd66 8zT/f6ai7uCZg7pEZa9D+iu3uyYvg7aGJvNqZUxmh11kqJBBzFVK19pZJUY7hs6N3sc4 JQX9Jh7xhbmgiMJ6HLqX7jGtTwC1Xq3cFkOA6ABujOdD1JTMIl13z0v0hww/pgdDzlRI AGcglK73jGVsqgJZZ2Ztsb9QDp2NpJyG6SF37AOJ5tI3BSoePcEVF0NCwlsrN9mvY5go YrZxGr08I2CtdV7DdKtrJfJg3DcZpnZHcr9D54ZR+j79bF9v3q/TyIN7+vag9RpoTcLH 0zgA== X-Gm-Message-State: AJIora+wvBcnkKedDKyf8CGmvAPP1TygDewe9uWM+w/fTRoIGxBxVxvP lcKw21Xkk9MtHwuIv4MIPtNlkp4yjX644w== X-Received: by 2002:a17:903:32c4:b0:16a:6b37:7cbe with SMTP id i4-20020a17090332c400b0016a6b377cbemr1822703plr.30.1656392134542; Mon, 27 Jun 2022 21:55:34 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 35/60] semihosting: Split out semihost_sys_remove Date: Tue, 28 Jun 2022 10:23:38 +0530 Message-Id: <20220628045403.508716-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_REMOVE to a reusable function. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 13 +---------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 12 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 1ae5ba6716..748a4b5e47 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -49,4 +49,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 68e13d9077..f4ce3851a4 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -484,18 +484,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_REMOVE: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "unlink,%s", - arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = remove(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); + semihost_sys_remove(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_RENAME: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index fff9550c89..5ec4e8f827 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -133,6 +133,18 @@ static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); } +static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "unlink,%s", fname, len); +} + /* * Host semihosting syscall implementations. */ @@ -277,6 +289,24 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = remove(p); + complete(cs, ret, ret ? errno : 0); + unlock_user(p, fname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -522,3 +552,13 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, g_assert_not_reached(); } } + +void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len) +{ + if (use_gdb_syscalls()) { + gdb_remove(cs, complete, fname, fname_len); + } else { + host_remove(cs, complete, fname, fname_len); + } +} From patchwork Tue Jun 28 04:53:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585527 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp482178mab; Mon, 27 Jun 2022 23:44:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uRaC+dkTgkIWhpFfXORu2lsj00Y3nYUnIcEHRXaPWEPSZQ0bE8WBLKE2TiCgh4KbDG2ojh X-Received: by 2002:ac8:5e4a:0:b0:305:aeb:2efe with SMTP id i10-20020ac85e4a000000b003050aeb2efemr12103800qtx.664.1656398669500; Mon, 27 Jun 2022 23:44:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398669; cv=none; d=google.com; s=arc-20160816; b=e3HuDm40LkKTkNqjjnoy8+YEs7I//bjJDY0wMclrDfYu0JrLOg716E5aSEMCbvkq9G 1szcRwERybd1K0MlCOR6KZMCjPvMXidztrTF9zuw0vfZjjay7zlux+ZZfAdUV+j5J25N cWE8Aabzzzsu8ZMlCoNIwPKk7QTGGKcH7cDAwF4LIOPgcsvFbgI43+iatpLBv1tpc4/g 2mUZkn5Da89bpYOvN8ioUW95JoSaZ+3b0A8OyBA7NLBByH64DcJxab+RkzWpL6ZkjCFS NdH7mWyhShSWMBJ9YRwU7NAYJmxhvx41TEiDFsL6P+6Q0+tN7gNRu0UnO5AnVPgPwbcL NQnQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=fUqwyrISXbZwt1ZuLZ7Xz7ZC8Kr8XD801TBJXsnU197hcClSmGegsrnnpN87jkgwOf Dwwpw0t6FYki3ZzOviOfhgYBSop+DbUL2+EDtn2TfbQNyKFcDbFVx0G+IJDvYyrXa0ch QdodEe4GWOzLfxWSklcvP10PCQjJA0+Es0qCmrJi8v6QajNK0FlnKDhzzVV905dYFiBu fZ2S3tTmn1txtdG8OPWPA54Ugly//uPmw0JsrBElZanPyk94nYzL9uiZeXgh8jjxL1gH ns4I/euKqk7vjJJ853onog3KGU7slypyd+X3t6OznWgp+NxbPBhvdqOpZIlD1nT//65u di5Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=SRhbol8Q; 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=pass (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 n186-20020a37a4c3000000b006ab8e886693si6163701qke.578.2022.06.27.23.44.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:44: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=pass header.i=@linaro.org header.s=google header.b=SRhbol8Q; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:43848 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64xY-0001G7-R3 for patch@linaro.org; Tue, 28 Jun 2022 02:44:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43742) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GG-0003qe-6u for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:40 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:35784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GE-0000Gd-A8 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:39 -0400 Received: by mail-pl1-x629.google.com with SMTP id o18so10051393plg.2 for ; Mon, 27 Jun 2022 21:55:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=SRhbol8Qd+JYSMjw8eSHKdrb+4gmhXVC0W6OZHlQHE8FJuCyU8FeXcCQ8/GG9VL/FC q77zL1O0wGAu3ObFrZsLK45uGJvmY/Iab1YERORRcHmq7P7cwidBeA3pIdEFBxlT6HmV HRAQOUWYjDosADvQ+7wDfrHaZX0lsD9nA3ilRjSxYYGwVxNW97w+BBZPUdhgf2V/XScI I0WRbuGY8Jeo23WSK0WyqoVGfRxDQ9EzndjYPAecR/FKlsJY6fAuFM6IXxhCOBwz8vnp Cyd4QJIjPVjfwt/k9Nzxcl4RtfLNcEwXQTWa2cvllzjSkDgUk8X4o1pTccGhq0UR2g7D xl6w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=qJ6ZZZSlz1PZaI3jEWDbIt6ncn6Ih8ucdkzmvg+FD4w=; b=Avws7zcWBZerPKPTQpV3BDBZV8fuxwTT86W1uhvilJSZEk5oSqbyHFep8iHbyCLT96 ASGpp1rZ9gXz5xKLyAdiWUANelnFqCz41+OdaTGULVuU3EeanY3Vgwr9NnSkfv4KlfgC sQpfzheb4wNow8z+4A5Et5jPgYxKnelZpQcK2T8t4eonZeAJRaOrewx0Ns+naZaR5aMP kI08Uln/jif4XvHhLgIIj3HVmPWIHt0FZcaN31Aa3Wt8+3g2fghaisQtXqQcsF0sQTl1 t0ctF2YV0iGFHZsmSysdVfv0h4kCizmW8eMSRm7AhCcdO3S7E74Q16MfRUxrSqLD80nn ntpA== X-Gm-Message-State: AJIora+QEwtklo2JfRq73N8gXHapweG4XvKCZHoVriXY5XPKIwsy9Scr LfvpZyNgvWcDPtz9f9arBN8K0xvfHDsRSw== X-Received: by 2002:a17:902:e749:b0:16a:2839:9e5 with SMTP id p9-20020a170902e74900b0016a283909e5mr3104269plf.48.1656392136939; Mon, 27 Jun 2022 21:55:36 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 36/60] semihosting: Split out semihost_sys_rename Date: Tue, 28 Jun 2022 10:23:39 +0530 Message-Id: <20220628045403.508716-37-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 4 +++ semihosting/arm-compat-semi.c | 21 +------------ semihosting/syscalls.c | 57 ++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 20 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 748a4b5e47..21430aa0ef 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -52,4 +52,8 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index f4ce3851a4..14d37ac9da 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -492,26 +492,7 @@ void do_common_semihosting(CPUState *cs) GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "rename,%s,%s", - arg0, (int)arg1 + 1, arg2, (int)arg3 + 1); - } else { - char *s2; - - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - s2 = lock_user_string(arg2); - if (!s2) { - unlock_user(s, arg0, 0); - goto do_fault; - } - ret = rename(s, s2); - unlock_user(s2, arg2, 0); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret ? errno : 0); - } + semihost_sys_rename(cs, common_semi_cb, arg0, arg1 + 1, arg2, arg3 + 1); break; case TARGET_SYS_CLOCK: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 5ec4e8f827..223916b110 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -145,6 +145,26 @@ static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "unlink,%s", fname, len); } +static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + int olen, nlen; + + olen = validate_strlen(cs, oname, oname_len); + if (olen < 0) { + complete(cs, -1, -olen); + return; + } + nlen = validate_strlen(cs, nname, nname_len); + if (nlen < 0) { + complete(cs, -1, -nlen); + return; + } + + gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); +} + /* * Host semihosting syscall implementations. */ @@ -307,6 +327,32 @@ static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, fname, 0); } +static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ostr, *nstr; + int ret; + + ret = validate_lock_user_string(&ostr, cs, oname, oname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + ret = validate_lock_user_string(&nstr, cs, nname, nname_len); + if (ret < 0) { + unlock_user(ostr, oname, 0); + complete(cs, -1, -ret); + return; + } + + ret = rename(ostr, nstr); + complete(cs, ret, ret ? errno : 0); + unlock_user(ostr, oname, 0); + unlock_user(nstr, nname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -562,3 +608,14 @@ void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, host_remove(cs, complete, fname, fname_len); } } + +void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong oname, target_ulong oname_len, + target_ulong nname, target_ulong nname_len) +{ + if (use_gdb_syscalls()) { + gdb_rename(cs, complete, oname, oname_len, nname, nname_len); + } else { + host_rename(cs, complete, oname, oname_len, nname, nname_len); + } +} From patchwork Tue Jun 28 04:53:40 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585554 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp530028mab; Tue, 28 Jun 2022 01:01:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sbKq8nhvkhP6GZbudV3qHvHTPQ1AeaVBi/1L/auSLv7o1yxaGwkyShmGcWRg7hJvr+fHwi X-Received: by 2002:a05:622a:1a14:b0:319:c590:cdd9 with SMTP id f20-20020a05622a1a1400b00319c590cdd9mr7710206qtb.23.1656403289915; Tue, 28 Jun 2022 01:01:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656403289; cv=none; d=google.com; s=arc-20160816; b=u1gdhvYis0fEJgEL8RFuu5+W1g+WMD5QivRFBgNyOzdqUn9bs3x43KId1LVoyEMEb3 0wkKVrRm09xCVZ+KADvlh3xRcTo+30uYizAc+4wuwc4wGIgCXPkWokSTawfdfIPtaCcT Kvgs55CcFk92J3AXrVezLi++GBMtqCPSL5DJx/noKN/vS7HQPe/289QXF8bpRKXT13Rs wR8YqYxwT13mihrXpYkzIUSp6OFhlr0f+6Oj1/QHYvTZXsco2DFGBDRtB/tmEMnWCWpr NYB9Hz7j5aO7jzBYg8KuMyLsYqAQbv7q6srqPKsyLWQXqTfKs5IFNN8fcxSrQs2LIOjO D15w== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=sqp9IIiWGMnLBTOaRTxTj2Z4mZVXWV8I9X5qMlWtiQO0NC6/eV9TthvfVmZFHswup4 nb4xwd4rDp//lRWSwCVO78zS3TA1wZhhMpjDWrJCTAF+qI43jAIydIlgIXUCIhfP5W0n Ylj4l5Q8sHslu/r5//V4qoGaV9rKsY5hULwhUdSpR+aYXApSoLXqWK2fBDIPrljyFfOd jJA8ZuC8xYkoezE+QuGPRuMzBFHuk+YsAMu4k6hkZBC+0uEQ4g0MC1USjMpPRbLeHqYQ a30e/6wI2WRZCtBATfYqgq+ZItrlqf9q3iQqCFfLnyusAwMDW3MeXxdSiU2fru6gotMX nR9A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="VIw/+1no"; 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=pass (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 q10-20020a05621419ea00b004644918d50bsi6842004qvc.148.2022.06.28.01.01.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:01: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=pass header.i=@linaro.org header.s=google header.b="VIw/+1no"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66A5-0001as-D6 for patch@linaro.org; Tue, 28 Jun 2022 04:01:29 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43758) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GH-0003vs-TT for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:42 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:39504) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GG-0000Gk-9b for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:41 -0400 Received: by mail-pj1-x102d.google.com with SMTP id b12-20020a17090a6acc00b001ec2b181c98so14638271pjm.4 for ; Mon, 27 Jun 2022 21:55:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=VIw/+1noFjzd2DXm5WGJmLaqSAX8Nuv8x+Ze4SLQgbA5tG3LPUG2j0qF6/SRFB/N/l o9UPqFOGovgfukdQOJUeFmGSik6UfrH7SVqpCazMn80VSGbPz7E5eTiwRxB+puvaArWP ZAA614ADrxhGvfI4bS8dPOlNUKcZD+grqLSdp1W+TZjznz6StHACyriQIYp7cZSozKKS QZOet/XLyNqVIwsdkX7iPkYw8gpmpjRHA4yao4ZUB1JKxdUcTrRCjZeEbqnsBsXUYgnq lbdpfskyajW8DKCZfhOxJB6k7yFRMhFJcAQTeS9AIXC1UJ/QLUNxOtp/XqjfxtdLZkE6 90TQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XnFWwBa1I9VJoksIMHyZzDE5/cUcTWTNeSlLEr2nKGs=; b=aUeRuUM8vsZp/EBKp0W3F3oBihpu/6nln5LPCuy7LLoV7V4b5pKHHsfFg+ICWJwX/a QeN8SGdQ9K9YNsv5pxhp0fZ4Sk30B3m/AVniPfYF7eJCi4cV7d8vY4mQJjvT1Z9QeuoY 7l2brl/bNNZGBICrojMv2wilDOXvBGYbUXqfcPSDLsq7XAE8b7D2jrrd982Pz56YfDtY GUxQpZpsYUHipol/QVocIATKJKoYPJw6iGckbjOqnvTZaVJvRgPBTXa2Ky5JRmR0k8Np gRY1ndTl7+YVDdOZp6sarwQnbAnx2JRP2GoNHH/5KfEs1WK4MmdZBzBiL8z7XKhw1cbM eCDw== X-Gm-Message-State: AJIora+2KMHmkYHyvfmZuf3ra7aMtsyYb/3lnccaSUQNFr86+HwXsx8z 0qfyPMOVdRvmBo9+eHBymWfJH+F470rZBg== X-Received: by 2002:a17:90a:b703:b0:1dd:1e2f:97d7 with SMTP id l3-20020a17090ab70300b001dd1e2f97d7mr24902310pjr.62.1656392139103; Mon, 27 Jun 2022 21:55:39 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 37/60] semihosting: Split out semihost_sys_system Date: Tue, 28 Jun 2022 10:23:40 +0530 Message-Id: <20220628045403.508716-38-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102d; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Split out the non-ARM specific portions of SYS_SYSTEM to a reusable function. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 12 +--------- semihosting/syscalls.c | 40 ++++++++++++++++++++++++++++++++++ 3 files changed, 44 insertions(+), 11 deletions(-) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 21430aa0ef..c9f9e66be1 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -56,4 +56,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong oname, target_ulong oname_len, target_ulong nname, target_ulong nname_len); +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 14d37ac9da..7ab6afd7fc 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -507,17 +507,7 @@ void do_common_semihosting(CPUState *cs) case TARGET_SYS_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(common_semi_cb, "system,%s", arg0, (int)arg1 + 1); - break; - } - s = lock_user_string(arg0); - if (!s) { - goto do_fault; - } - ret = system(s); - unlock_user(s, arg0, 0); - common_semi_cb(cs, ret, ret == -1 ? errno : 0); + semihost_sys_system(cs, common_semi_cb, arg0, arg1 + 1); break; case TARGET_SYS_ERRNO: diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 223916b110..de846ced32 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -165,6 +165,18 @@ static void gdb_rename(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "rename,%s,%s", oname, olen, nname, nlen); } +static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + int len = validate_strlen(cs, cmd, cmd_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "system,%s", cmd, len); +} + /* * Host semihosting syscall implementations. */ @@ -353,6 +365,24 @@ static void host_rename(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(nstr, nname, 0); } +static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *p; + int ret; + + ret = validate_lock_user_string(&p, cs, cmd, cmd_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = system(p); + complete(cs, ret, ret == -1 ? errno : 0); + unlock_user(p, cmd, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -619,3 +649,13 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, host_rename(cs, complete, oname, oname_len, nname, nname_len); } } + +void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong cmd, target_ulong cmd_len) +{ + if (use_gdb_syscalls()) { + gdb_system(cs, complete, cmd, cmd_len); + } else { + host_system(cs, complete, cmd, cmd_len); + } +} From patchwork Tue Jun 28 04:53:41 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585530 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp486691mab; Mon, 27 Jun 2022 23:52:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLD+OUcTAUbQDTSJ2PdvtJDv5t7PTJOrVVYFJZMyyfMwYzbhvvXrIO3qqknWSgCcS6ULRN X-Received: by 2002:a05:6214:2308:b0:432:e69f:5d71 with SMTP id gc8-20020a056214230800b00432e69f5d71mr1149852qvb.19.1656399140214; Mon, 27 Jun 2022 23:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399140; cv=none; d=google.com; s=arc-20160816; b=D1n5OJlms5M7Y0bR5Dm3jREEIkKlzPgibtdewT0cpjcQczDm9y7SOj7GZdWlBfhI9S GqzpEHIwa2X0ZMKDZ+ZcjgYuBBjwFocJmrMjr9aamK8VM4QxpDZgJpF+DmZGttZst0Vb P5Z+Kh1A+fyop1IPXl4L/PPSGZcpHv8t5k3el4ZcYXR41YV+RVXijO0NT+U1LVtAYfpC 1EOP2hhSyzdYqba7T8zX2h0tdob58M8qA7d0RMnJ+aILfQiqNcJrIX1LlYVD3vFyDB/R /gX0xM0t53yqbweQkyL1B154Kk91r96kUD5zenCjYUTHOt63xCaH1E8Th8Lcb7mjI2Xt MQlQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=xz1GJ2vpyUefp+d9+tObRooQRvZARHWKCaa2fidKEx8=; b=jLbEWu2bKn/8UoLjpYzBUvTFBFFiGaCJx9EMwVKOU4LKL/NrEZrSh9IV9uZGsxeBC1 4UBnTsmnbcrMluOYRet/xVkcFDWBcPLY3jM9bFFfouwJ3KqTcHm0+rYWUaWdUrS6jJcv Y0+qrPUz5VRUTd/Suq4h6NskHgT3PNaMXu93dAMT7B2ngeaZ9aMu9tlmvdjMsC6HfUcf I5VqIsRsPRsSmViegeusxbo5t2Oa6Qz3JUc5Wv5xlnngk1n2yGao3ARSp086jF/wHxO7 0DL1fNk9MPKdK7ZtwiMuLQDIM3s7nouEL28wx1SMBAlgaQTwGULeDWUdMt/k+wN00/3V 3IYg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YDO3MAWr; 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=pass (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 i4-20020ae9ee04000000b006af09bc3a68si5394779qkg.581.2022.06.27.23.52.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:52: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=pass header.i=@linaro.org header.s=google header.b=YDO3MAWr; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:52140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o6559-00076Y-Nf for patch@linaro.org; Tue, 28 Jun 2022 02:52:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43780) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GK-00041C-Ou for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:44 -0400 Received: from mail-pf1-x436.google.com ([2607:f8b0:4864:20::436]:44667) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GI-0000Gx-LC for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:44 -0400 Received: by mail-pf1-x436.google.com with SMTP id 65so10913129pfw.11 for ; Mon, 27 Jun 2022 21:55:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xz1GJ2vpyUefp+d9+tObRooQRvZARHWKCaa2fidKEx8=; b=YDO3MAWruLzbZK7abyxVaacC0k/lCnj7r3IJU0rGn1C/jb7glnu5+k0C5Mjt5wCC+e EaHcneY7uAMgi/7d2K6cb7yikrTvxJRoae/t3ibsUB9RYuaL6IfmHSHElP1vjtqemlvO rVEtD0LKMM7TkM1DNl/rdkCAPZFT9mdxhh4JJb5VBht/yZqR7Rk8D9GFqlv29blxti2s piRvdiX8Y/PjEyDx/lsqHJ6aRxsNMfXfjjokYrLqN4inOkam03Sn1OFH0ydqYuj43gXR W1QC4X6eEc03aAEX3oZqk06O5Lk5FRGhNrX+ReocERztOCoznXK0NCa3JEkoqd9E3cdD fOEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xz1GJ2vpyUefp+d9+tObRooQRvZARHWKCaa2fidKEx8=; b=kFQ1PAyACRogH+ruCSlwcLf9oJwWAU5bDi3Z0/hZ+zVk8QnOhIf7Vzk3wtetcrScaa zHtZYLK66xVAqXfxaXvgDdHKQoorirTKrE+FAhRh3xY/mKOmE67FJaiI/c7cc77Y+Kqh O4o+pwr+B8b40oF8zl8rUqeo9LF8rL/EnvoY4EhDCPPfyvqBTba3HdZYJCQpzI8treXC FM1ds1LmamnuOBAmRvR1nwCL80LqQ73vNGKUDtqRxqt4g29m5VRk70ngMaw8Nfjl0KK8 6Z+srEXL90RR6vk4aA0aCxcLqCbrO7QC4lT8iBfgf2/TZ7Ee55qWs3n5bxEdF0a789F0 8YDA== X-Gm-Message-State: AJIora+dk6XP+cph67OcKKpIDXm39hT1w3GDnxxZt0UmvjY1ehmWwkOr +v5WvGMbkMMt5Sh/6KzV1fcfBr0EezOgTw== X-Received: by 2002:a62:1652:0:b0:525:4253:6f5a with SMTP id 79-20020a621652000000b0052542536f5amr2747195pfw.59.1656392141343; Mon, 27 Jun 2022 21:55:41 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 38/60] semihosting: Create semihost_sys_{stat,fstat} Date: Tue, 28 Jun 2022 10:23:41 +0530 Message-Id: <20220628045403.508716-39-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::436; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x436.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" These syscalls will be used by m68k and nios2 semihosting. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 7 ++ semihosting/syscalls.c | 137 +++++++++++++++++++++++++++++++++ 2 files changed, 144 insertions(+) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index c9f9e66be1..ecc97751a9 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -49,6 +49,13 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, gdb_syscall_complete_cb flen_cb, int fd, target_ulong fstat_addr); +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr); + +void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr); + void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len); diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index de846ced32..d21064716d 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -63,6 +63,52 @@ static int validate_lock_user_string(char **pstr, CPUState *cs, return ret; } +/* + * TODO: Note that gdb always stores the stat structure big-endian. + * So far, that's ok, as the only two targets using this are also + * big-endian. Until we do something with gdb, also produce the + * same big-endian result from the host. + */ +static int copy_stat_to_user(CPUState *cs, target_ulong addr, + const struct stat *s) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_stat *p; + + if (s->st_dev != (uint32_t)s->st_dev || + s->st_ino != (uint32_t)s->st_ino) { + return -EOVERFLOW; + } + + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -EFAULT; + } + + p->gdb_st_dev = cpu_to_be32(s->st_dev); + p->gdb_st_ino = cpu_to_be32(s->st_ino); + p->gdb_st_mode = cpu_to_be32(s->st_mode); + p->gdb_st_nlink = cpu_to_be32(s->st_nlink); + p->gdb_st_uid = cpu_to_be32(s->st_uid); + p->gdb_st_gid = cpu_to_be32(s->st_gid); + p->gdb_st_rdev = cpu_to_be32(s->st_rdev); + p->gdb_st_size = cpu_to_be64(s->st_size); +#ifdef _WIN32 + /* Windows stat is missing some fields. */ + p->gdb_st_blksize = 0; + p->gdb_st_blocks = 0; +#else + p->gdb_st_blksize = cpu_to_be64(s->st_blksize); + p->gdb_st_blocks = cpu_to_be64(s->st_blocks); +#endif + p->gdb_st_atime = cpu_to_be32(s->st_atime); + p->gdb_st_mtime = cpu_to_be32(s->st_mtime); + p->gdb_st_ctime = cpu_to_be32(s->st_ctime); + + unlock_user(p, addr, sizeof(struct gdb_stat)); + return 0; +} + /* * GDB semihosting syscall implementations. */ @@ -133,6 +179,19 @@ static void gdb_fstat(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "fstat,%x,%x", (target_ulong)gf->hostfd, addr); } +static void gdb_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + int len = validate_strlen(cs, fname, fname_len); + if (len < 0) { + complete(cs, -1, -len); + return; + } + + gdb_do_syscall(complete, "stat,%s,%x", fname, len, addr); +} + static void gdb_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { @@ -321,6 +380,51 @@ static void host_flen(CPUState *cs, gdb_syscall_complete_cb complete, } } +static void host_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + struct stat buf; + int ret; + + ret = fstat(gf->hostfd, &buf); + if (ret) { + complete(cs, -1, errno); + return; + } + ret = copy_stat_to_user(cs, addr, &buf); + complete(cs, ret ? -1 : 0, ret ? -ret : 0); +} + +static void host_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct stat buf; + char *name; + int ret, err; + + ret = validate_lock_user_string(&name, cs, fname, fname_len); + if (ret < 0) { + complete(cs, -1, -ret); + return; + } + + ret = stat(name, &buf); + if (ret) { + err = errno; + } else { + ret = copy_stat_to_user(cs, addr, &buf); + err = 0; + if (ret < 0) { + err = -ret; + ret = -1; + } + } + complete(cs, ret, err); + unlock_user(name, fname, 0); +} + static void host_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { @@ -629,6 +733,39 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, } } +void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, target_ulong addr) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, -1, EBADF); + return; + } + switch (gf->type) { + case GuestFDGDB: + gdb_fstat(cs, complete, gf, addr); + break; + case GuestFDHost: + host_fstat(cs, complete, gf, addr); + break; + case GuestFDStatic: + default: + g_assert_not_reached(); + } +} + +void semihost_sys_stat(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong fname, target_ulong fname_len, + target_ulong addr) +{ + if (use_gdb_syscalls()) { + gdb_stat(cs, complete, fname, fname_len, addr); + } else { + host_stat(cs, complete, fname, fname_len, addr); + } +} + void semihost_sys_remove(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong fname, target_ulong fname_len) { From patchwork Tue Jun 28 04:53:42 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585555 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp534066mab; Tue, 28 Jun 2022 01:06:52 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tFzH0NvvfKprcfzjGotjCzp8X0klolr0IRyjTU86PKjGDMZ5JHNoFa1uPW74EorMmgd6Dm X-Received: by 2002:ac8:7dc4:0:b0:31a:df41:9f11 with SMTP id c4-20020ac87dc4000000b0031adf419f11mr5371470qte.31.1656403612272; Tue, 28 Jun 2022 01:06:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656403612; cv=none; d=google.com; s=arc-20160816; b=Va8/4olZZIl/XtLphJhFTp0uKypColjUaDZNhUbqu28aBPXYMzEBsP7ThTXlsILLpJ LVHLpWYyou2CTR1fgpaR0WBgcL2GhpLJbsLvcShyArNIA7N9lW5mwRCobo53zQ0cjS6v wOvkwoPZtq9Da2Ipc0dfKppJF3l5KJKlKG1cOZremYAQejADLKXjQ1EkJDY2GbrmpONi Btu6Sa7MAu9W4EPRZbBeUq1XVbvXYAnqbCBlqteG8eb/ixl6sZvqo09tCDk3ptkzRDK1 XNrsfbTCPl7zJGCrGR4ZZZSNkQ2tRrIhFeAD6PQVVeNnQBA9UzuLwsgSYsjTIU5M1JYH duvQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=M4lQss5y82kxG4apGz3RTK5qy0uFL1fGo6xWNcOCvdA=; b=r0xaKnnqD1WCHnF2aFjRfUul1YnXbXmeZ620ODruUn5QKNGWwt9VVTeLG3SpZ7mprs xO58z7shMuoK8+hJ3sdhTnLBqa/5h1beJ2s8ofv8Vqwj8Aaz+ST/1mjctp+IYwUlANe7 FUWevyVOO68CdkUhSx2HBsudv4ciY+r4mHc7zqmX6yvxUtn4FYeJikpImgNII7C4LVW3 bj85SR0uCRunHfHiEXioV3WnqzObTm7vye9UdzbePpeUPQhwgmGcezdI+GCDfr6Gbsof XQHeXA2lwrPxzIbgCgJKbtJn302aqhFiLYDmgJJKDsMU1LXheM9ZOmlA9oGQ2m0lugM+ k6Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=NpwZbdKA; 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=pass (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 d11-20020a05621421cb00b004704fc573e6si6920406qvh.89.2022.06.28.01.06.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:06:52 -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=pass header.i=@linaro.org header.s=google header.b=NpwZbdKA; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40074 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66FH-0007N0-RJ for patch@linaro.org; Tue, 28 Jun 2022 04:06:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:43790) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63GM-00044C-AC for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:46 -0400 Received: from mail-pl1-x629.google.com ([2607:f8b0:4864:20::629]:35784) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63GK-0000Gd-GU for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:55:45 -0400 Received: by mail-pl1-x629.google.com with SMTP id o18so10051393plg.2 for ; Mon, 27 Jun 2022 21:55:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M4lQss5y82kxG4apGz3RTK5qy0uFL1fGo6xWNcOCvdA=; b=NpwZbdKAbrfdvxQa8vRd1u8VBP7l9+5lwmnI1U5RR0yEkq9OG4x804nI5dXro9cQqm W+LAZ90IIDMl75rYLEoE1KwuhyWG1Bfsbu2n2M4v9i4N8hTsxi+V500LXDjFpdUGtfLK mnnSj7nKsmTphd48ifZ3PgsHgW2RYdl7dAkx7kpmC7VyhHxGpypDXC1O3QTVT3Fm0QVP Mkvej/eCQ4en65u2u84lpVlCFAlFniAzymQz6/ijDew82V0KUeXff26UXuDltQe+aSRV HCORIIj6MkFyKovyNkmwf2xQ6JzLosTcgEhtzFm9oekFOU9JDovDvDAY9cLoNkQJfu1g TIPg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M4lQss5y82kxG4apGz3RTK5qy0uFL1fGo6xWNcOCvdA=; b=nVhRvrekodqBFRHHp3VIRPe+BCpyhRkxKIrlv7/oWvf/ygf/np+8Y4B0FZUErcHvNR HgfeJZ+9f/YWzl9q+cM/Ea3wT9ejn/Ei78XKqNP6XYnOmIJpLsVrjVFUkVXLhjiaJpb3 s4R0A35tW1KV1WlPOCppnp92Y4MpPvI+8hnZZ5GugnvxwN8q3WKAU0qPfr7tyTN8knfQ YVQe4I6+Jewtvnfw14N85TarSJ7a3L3qpN6FnWIYqCyEHhpNw6yZXcI7W/kGY2rt7Blt aZdbxdTVAqPCucZuy/iA1wqtl29vMRGHbBLCy8W3/fdc/2xJAnKrLnjue4lnuICRRPxD ucxA== X-Gm-Message-State: AJIora8AZb/i8yZF8khnwdsCu22oISVjpmTJmYostFXOtuQ9B46uuHMr U1klkcm6/jA8nBheFu4JoSrEVQPnCaJbVw== X-Received: by 2002:a17:902:e809:b0:16a:22dc:d23a with SMTP id u9-20020a170902e80900b0016a22dcd23amr1833255plg.119.1656392143560; Mon, 27 Jun 2022 21:55:43 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id w8-20020a1709026f0800b00168c523032fsm8073735plk.269.2022.06.27.21.55.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:55:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 39/60] semihosting: Create semihost_sys_gettimeofday Date: Tue, 28 Jun 2022 10:23:42 +0530 Message-Id: <20220628045403.508716-40-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::629; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x629.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This syscall will be used by m68k and nios2 semihosting. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 3 +++ semihosting/syscalls.c | 42 ++++++++++++++++++++++++++++++++++ 2 files changed, 45 insertions(+) diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index ecc97751a9..347200cb9f 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -66,4 +66,7 @@ void semihost_sys_rename(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong cmd, target_ulong cmd_len); +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index d21064716d..db1e9f6cc9 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -236,6 +236,12 @@ static void gdb_system(CPUState *cs, gdb_syscall_complete_cb complete, gdb_do_syscall(complete, "system,%s", cmd, len); } +static void gdb_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + gdb_do_syscall(complete, "gettimeofday,%x,%x", tv_addr, tz_addr); +} + /* * Host semihosting syscall implementations. */ @@ -487,6 +493,32 @@ static void host_system(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, cmd, 0); } +static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + struct gdb_timeval *p; + int64_t rt; + + /* GDB fails on non-null TZ, so be consistent. */ + if (tz_addr != 0) { + complete(cs, -1, EINVAL); + return; + } + + p = lock_user(VERIFY_WRITE, tv_addr, sizeof(struct gdb_timeval), 0); + if (!p) { + complete(cs, -1, EFAULT); + return; + } + + /* TODO: Like stat, gdb always produces big-endian results; match it. */ + rt = g_get_real_time(); + p->tv_sec = cpu_to_be32(rt / G_USEC_PER_SEC); + p->tv_usec = cpu_to_be64(rt % G_USEC_PER_SEC); + unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); +} + /* * Static file semihosting syscall implementations. */ @@ -796,3 +828,13 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, host_system(cs, complete, cmd, cmd_len); } } + +void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, + target_ulong tv_addr, target_ulong tz_addr) +{ + if (use_gdb_syscalls()) { + gdb_gettimeofday(cs, complete, tv_addr, tz_addr); + } else { + host_gettimeofday(cs, complete, tv_addr, tz_addr); + } +} From patchwork Tue Jun 28 04:53:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585519 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp471022mab; Mon, 27 Jun 2022 23:25:26 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tsni47jm8qa9Wr3Qk7iVKix9OMeC63zLi61/7p8QktEgMbQN8CmcllwMH9v7rh/m3EVcoz X-Received: by 2002:a05:622a:1903:b0:305:a19:78b7 with SMTP id w3-20020a05622a190300b003050a1978b7mr12176790qtc.342.1656397526156; Mon, 27 Jun 2022 23:25:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656397526; cv=none; d=google.com; s=arc-20160816; b=aiukSt9HhXT9pxsfA8OkpLw8R63rNRslsHqYraPB+L6dsfRuhOL0HJ5e95A5MFJ1+F sp7UzU2fSdaVb8JOo/aAfZ2fPXrm9GygcClr2M9QFlGRux+u6o0qBu8dt1xoilAZkd3R 0V9MvPOHyuNfJmKj2mWcD/WLm7oXYoQ7+CJQiYPapzDk+FeMAVubR+ZVkUK3ZDzhqcJs bEI2k/2K7nNTC4DioFEyWQOuDmT9c49HJdpG+udmL5eBpyuV9YhQmkStWYl12a6OGcRn LQK1EtHexDOcP3fbGGrgLnidkW4TDPbDZtA41j13S2EhDhcWjOa2B1UBJebmz8NamaqL l7og== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=cXIVhOFx1yMV+bG8yPyaI+livennK38GrI/+kr+nCDk=; b=OQgxdaFP/DQoD4rGmLDwZFVeZQOLnN967swXSQFww5bOcwpNuKS1PN69CZSwniYLns zDCPI8U+B7G8x+ju7bjSC01X5S8FUxEz3xdttcpNXbZ+Q22KNNFbb5GP35gM0CKKQx9f MmL8VpQicoDr0H1+piiyyOUrHA071EtxUmexecv8RB3RrLvw9xGMBoGfA3Up7s1AVDNl TbAYZZLOFUPnck+mkBQC8MxkIVKAe+JGWeis8qB0foIWk88/P4XyMkhPn1B9jrpbHjqm nsO2TjJ1SybBfwE/sR7cc8BPm0rQStAPPgjwV4qrAeqjhUuISQ0y8yKARrg9gp77c1m3 By6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EKxs+YcU; 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=pass (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 iu10-20020ad45cca000000b004722d690b77si2388395qvb.211.2022.06.27.23.25.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:25:26 -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=pass header.i=@linaro.org header.s=google header.b=EKxs+YcU; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49070 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64f7-0001Lo-JY for patch@linaro.org; Tue, 28 Jun 2022 02:25:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44094) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JN-0001ti-Fr for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:55 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:36398) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JL-0000Vf-LD for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:53 -0400 Received: by mail-pg1-x536.google.com with SMTP id s206so2079554pgs.3 for ; Mon, 27 Jun 2022 21:58:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=cXIVhOFx1yMV+bG8yPyaI+livennK38GrI/+kr+nCDk=; b=EKxs+YcU21PxxjEw2ajYqdvUpW+TcMrqjfmU/UYPKoX1dlrp/jmtiLmonfbZM9CTTE 4ovcjkE+z5YZwBSbwkLJtsoZbOCOyHBEANBQrZQZR+K7N2yKFmZNzFJQZBNsV0/IYv/4 Z+/tPgAJpAwLF8lCWyk69/z3/QHk3u1uWjH8QPzSkppmCwrDHg52iNp5WLTaNnMWiLRt VoOSm3+mCDG22Efh2yTf9zvCJ1mz9036bdO/aXn2jydmowDjA61AtuZyzxiU5qkQPNca 0kQjoLbHVVfdN6P+2YpFEyTug7moZQJDZCOVrzuRD/Dgo590YgSPOczXHgwb4birqFbX bWyA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=cXIVhOFx1yMV+bG8yPyaI+livennK38GrI/+kr+nCDk=; b=qTGLhf/9fD6ENyimYtfAZatzSdZ42FIJ+2KuuJo7qm5XqAh6AiaIcg/bAuwg7Txl09 yRXGFQgKORIHLlB2sxdgo1v47Jnu0ttoS1uU7v91SyCKuA68Qbp4R31v8Sfrj6dh3XNJ XlnG3k0m1mmaVP+nDLvFvbkSAISVyxDhhZPawovj2Ipk5T24ofA4B3A/HCyfxj+JKndq I5cEYs274+ywx8jzxfbVyyr4DkNdPtZ0DQ9LzV+3dphWrk4wK07b6fuFvsiLIEKfcYIs jTmDc9PqfoiOxriquNMLQBJ4LrCQ2SISpiDBX1Z1tg5I2JTbgB9nISqnHh7uTZPiJ0nU FUGw== X-Gm-Message-State: AJIora/kf15NDuvS9Uu1cmhgKi6VLG5yMAMPSsgPML2MZ+m8J5Bke2xD nZaY87dEWx+P1hSpNjV7uVk07CCKHep39g== X-Received: by 2002:a65:6045:0:b0:399:3a5e:e25a with SMTP id a5-20020a656045000000b003993a5ee25amr16325911pgp.139.1656392330295; Mon, 27 Jun 2022 21:58:50 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.58.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:58:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 40/60] gdbstub: Adjust gdb_syscall_complete_cb declaration Date: Tue, 28 Jun 2022 10:23:43 +0530 Message-Id: <20220628045403.508716-41-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::536; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x536.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Change 'ret' to uint64_t. This resolves a FIXME in the m68k and nios2 semihosting that we've lost data. Change 'err' to int. There is nothing target-specific about the width of the errno value. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 3 +-- gdbstub.c | 7 ++++--- semihosting/arm-compat-semi.c | 12 +++++------- semihosting/console.c | 7 +++---- semihosting/syscalls.c | 2 +- target/m68k/m68k-semi.c | 10 +++------- target/nios2/nios2-semi.c | 8 +++----- 7 files changed, 20 insertions(+), 29 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index b588c306cc..f667014888 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -74,8 +74,7 @@ struct gdb_timeval { #ifdef NEED_CPU_H #include "cpu.h" -typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, - target_ulong ret, target_ulong err); +typedef void (*gdb_syscall_complete_cb)(CPUState *cpu, uint64_t ret, int err); /** * gdb_do_syscall: diff --git a/gdbstub.c b/gdbstub.c index f3a4664453..cf869b10e3 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1878,11 +1878,12 @@ static void handle_read_all_regs(GArray *params, void *user_ctx) static void handle_file_io(GArray *params, void *user_ctx) { if (params->len >= 1 && gdbserver_state.current_syscall_cb) { - target_ulong ret, err; + uint64_t ret; + int err; - ret = (target_ulong)get_param(params, 0)->val_ull; + ret = get_param(params, 0)->val_ull; if (params->len >= 2) { - err = (target_ulong)get_param(params, 1)->val_ull; + err = get_param(params, 1)->val_ull; } else { err = 0; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 7ab6afd7fc..1b0505987a 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -215,7 +215,7 @@ static inline uint32_t get_swi_errno(CPUState *cs) #endif } -static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_cb(CPUState *cs, uint64_t ret, int err) { if (err) { #ifdef CONFIG_USER_ONLY @@ -232,7 +232,7 @@ static void common_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) * SYS_READ and SYS_WRITE always return the number of bytes not read/written. * There is no error condition, other than returning the original length. */ -static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void common_semi_rw_cb(CPUState *cs, uint64_t ret, int err) { /* Recover the original length from the third argument. */ CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; @@ -251,8 +251,7 @@ static void common_semi_rw_cb(CPUState *cs, target_ulong ret, target_ulong err) * Convert from Posix ret+errno to Arm SYS_ISTTY return values. * With gdbstub, err is only ever set for protocol errors to EIO. */ -static void common_semi_istty_cb(CPUState *cs, target_ulong ret, - target_ulong err) +static void common_semi_istty_cb(CPUState *cs, uint64_t ret, int err) { if (err) { ret = (err == ENOTTY ? 0 : -1); @@ -263,8 +262,7 @@ static void common_semi_istty_cb(CPUState *cs, target_ulong ret, /* * SYS_SEEK returns 0 on success, not the resulting offset. */ -static void common_semi_seek_cb(CPUState *cs, target_ulong ret, - target_ulong err) +static void common_semi_seek_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { ret = 0; @@ -285,7 +283,7 @@ static target_ulong common_semi_flen_buf(CPUState *cs) } static void -common_semi_flen_fstat_cb(CPUState *cs, target_ulong ret, target_ulong err) +common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { /* The size is always stored in big-endian order, extract the value. */ diff --git a/semihosting/console.c b/semihosting/console.c index ef6958d844..4e49202b2a 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -64,11 +64,10 @@ static GString *copy_user_string(CPUArchState *env, target_ulong addr) return s; } -static void semihosting_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void semihosting_cb(CPUState *cs, uint64_t ret, int err) { - if (ret == (target_ulong) -1) { - qemu_log("%s: gdb console output failed ("TARGET_FMT_ld")", - __func__, err); + if (err) { + qemu_log("%s: gdb console output failed (%d)\n", __func__, err); } } diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index db1e9f6cc9..13a9bdeda6 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -115,7 +115,7 @@ static int copy_stat_to_user(CPUState *cs, target_ulong addr, static gdb_syscall_complete_cb gdb_open_complete; -static void gdb_open_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void gdb_open_cb(CPUState *cs, uint64_t ret, int err) { if (!err) { int guestfd = alloc_guestfd(); diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index b886ebf714..8c186c0e9f 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -95,7 +95,7 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) +static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || @@ -110,7 +110,7 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, uint32_t err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) +static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) { target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || @@ -124,16 +124,12 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, uint32_t err) static int m68k_semi_is_fseek; -static void m68k_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); CPUM68KState *env = &cpu->env; if (m68k_semi_is_fseek) { - /* - * FIXME: We've already lost the high bits of the fseek - * return value. - */ m68k_semi_return_u64(env, ret, err); m68k_semi_is_fseek = 0; } else { diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 3e504a6c5f..4d02789d26 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,8 +108,7 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, return true; } -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, - uint32_t err) +static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret, args) || @@ -124,8 +123,7 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, } } -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, - uint32_t err) +static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) { target_ulong args = env->regs[R_ARG1]; if (put_user_u32(ret >> 32, args) || @@ -139,7 +137,7 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, static int nios2_semi_is_lseek; -static void nios2_semi_cb(CPUState *cs, target_ulong ret, target_ulong err) +static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); CPUNios2State *env = &cpu->env; From patchwork Tue Jun 28 04:53:44 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585533 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp490689mab; Mon, 27 Jun 2022 23:59:14 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uR3yfy9OSpulhu1Wr3OHjKqDCO83weVUONCq+drZN/vtZ37EwQHNsdOxqHT6dALUuwEzVG X-Received: by 2002:a05:620a:370f:b0:6a6:d7c3:a7f2 with SMTP id de15-20020a05620a370f00b006a6d7c3a7f2mr10260964qkb.644.1656399553899; Mon, 27 Jun 2022 23:59:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399553; cv=none; d=google.com; s=arc-20160816; b=r7hv+JDsBC/DnlgyaeVR9s9nIcuQeunLppoj9fNVyWNgaEjv3G4Z1BYbZqPn5pwnSA BsYRYDluMuSLewoV4ZITMItxc6zEUPei/pnZZyXjYvE/TJgK2soPdDzhX0v7AtSh/pfq Qh34awx5hvGOi+ik/8odlbgWu39+Bl6dza3i/ozdqOrdEPJOp7/bRsZwl6nYK6GQrkRW 9W/WsBbD76jbyM8nInGmzwZphqIfCbBAg7sdv6V5GDnA/q9dnaaQbqwq/xkUTa6nBscs oSl6OU8UJVnlo/1eh7NvRm98lhXgPHXrZQy4MzMQ06n6gdfe/uEHOeRYkLgQzO1lf8aV vwEA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WukvkIkeVaM1+jg6SBYcwpvOTXb/8GOiZ0LXRT6uF1w=; b=BnyHSf5GEpNxC64plK9sp5CHG+4qM/RqT8hbrJgV8nubeaziK0nR0IYWGzJPpFr1so hCR1b6hQDE1D6/rPOnShoR6rhyu13GXyPsAfWu6t1q0kpJi50wyG72r01/Shgtu5OOHy DWENEoRMoIAxwzajmZXyzGPk8HjBsiCkQh0YXJXV0ojuUjnuAOtPk+PL20qY6NrJSg3v aGLhK6sA/D1LHfKYNRgY4j1EL9QjEMGdl8v9NmKSa7aA+vmJ6QgPWV+qPuior2UhvpL/ Dp7dVMBdD/ewoXdqApEDiTfzZh/XQBjWwNPdJk0mFE8uhpbQyTot7Sa/2iQPmOf8ARir ZFxA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=hm0eyMeY; 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=pass (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 z11-20020a05622a060b00b003179eec232bsi1056431qta.119.2022.06.27.23.59.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:59:13 -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=pass header.i=@linaro.org header.s=google header.b=hm0eyMeY; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:33004 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Bp-0005PJ-Bc for patch@linaro.org; Tue, 28 Jun 2022 02:59:13 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44110) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JP-0001ud-R4 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:56 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:41819) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JO-0000Vk-6t for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:55 -0400 Received: by mail-pj1-x102b.google.com with SMTP id g10-20020a17090a708a00b001ea8aadd42bso11528192pjk.0 for ; Mon, 27 Jun 2022 21:58:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WukvkIkeVaM1+jg6SBYcwpvOTXb/8GOiZ0LXRT6uF1w=; b=hm0eyMeYJzygr5X7Snrs3lgwu67nH1l9onFPThhLK078vWR0R+MNcK3m3hhlaCEjmO SH/gkTOj6ivZtu+J8ICqBxBx1BHKpDTgPyHGDPiXB9ughOajXLLpfJo3rXxfJdZv/x90 /CqyqJcumkvFVhTFWHK0iU013V4bF0D9JklNZbhhS9zzxNfIksb/ELCBQNwYY+WMDi3L /rMV5wUICtS/ja36WRqbLtS9C9Hf6o5FIrhvbz/RErbV8cjR9XAo0bFHb/hYy91jmXTe qE8+3usKB/QVgBmcK9hfDcErQ0GgewUCjn5sZ8lbPrI8pxxVtVe8PLJpigQ0YRagsB8O PBTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WukvkIkeVaM1+jg6SBYcwpvOTXb/8GOiZ0LXRT6uF1w=; b=cgADjuQFSe2oQhcPJkKijd2tsrgHMO9W85yHTVN3GRtcuNc0tgq8JguK/pnASvFIj8 WTnui4B9E5TJus5YUEqxrK1KBLZAAlL6gFGEVS7jBRLPdOodmTkB37fJiYG13tIlSB8J qhyMFwwuP+WLiRxYn+taaeYaaVP0h3lk0DVe815KHsIKQ5PkX8EcKEnU2dpOi01YnTDj gmshs3QWfXckyrOl+EYOh98Mij38hqqbaC7JRd9jXF7YEVIe6VXxQZN4wyuSPOvbsUtM TMjnVWKHCkxS3JoZxMJB8x8ScoqF+IMwTA3xAKRzJxQtG6r9TONHq0egmDaSOPS6gw4B Bsxw== X-Gm-Message-State: AJIora9B91xxfsn3CCAFwo08hMsvOPmOT7wd6v4TopDNWLFSV23527iE mTZdP5A3JG+Y3rMLHEsXKrUai8Tq2VET+g== X-Received: by 2002:a17:902:8d98:b0:168:a310:3ea6 with SMTP id v24-20020a1709028d9800b00168a3103ea6mr1780874plo.9.1656392332735; Mon, 27 Jun 2022 21:58:52 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.58.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:58:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 41/60] semihosting: Fix docs comment for qemu_semihosting_console_inc Date: Tue, 28 Jun 2022 10:23:44 +0530 Message-Id: <20220628045403.508716-42-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102b; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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 implementation of qemu_semihosting_console_inc does not defer to gdbstub, but only reads from the fifo in console.c. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/console.h | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 0238f540f4..4f6217bf10 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -41,11 +41,10 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); * qemu_semihosting_console_inc: * @env: CPUArchState * - * Receive single character from debug console. This may be the remote - * gdb session if a softmmu guest is currently being debugged. As this - * call may block if no data is available we suspend the CPU and will - * re-execute the instruction when data is there. Therefore two - * conditions must be met: + * Receive single character from debug console. As this call may block + * if no data is available we suspend the CPU and will re-execute the + * instruction when data is there. Therefore two conditions must be met: + * * - CPUState is synchronized before calling this function * - pc is only updated once the character is successfully returned * From patchwork Tue Jun 28 04:53:45 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585522 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp476115mab; Mon, 27 Jun 2022 23:33:40 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vwpvFH5XnvFDIJmBEzrt6bnmuvhD2UAT86HH1YozRSxhMgP2vH4qaY2Ur3KpN6o4AAt4mv X-Received: by 2002:a05:6214:3003:b0:462:1c15:772c with SMTP id ke3-20020a056214300300b004621c15772cmr1320327qvb.71.1656398020365; Mon, 27 Jun 2022 23:33:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398020; cv=none; d=google.com; s=arc-20160816; b=gLq4OKRTIbEvxro2T+L0UdO7+M5rAsg9pJ7JYhdu1YPa9PUtGdW6lHB8Bw4XpSjnQH ITBEUj7cUHt5z//a7evHneBfCyIEb/t9d/pW/vxKqtBg3WmzM0waZEv7GOzDeAPa1k1R hWGIua19xEz34HW62uiBaN0LBbOIAMcaDVyRovEQJHDEZ/XfgsSTtpchAs4Czs2KZ+M/ u0feDtjnZ3+VnMRwFjELut3ReFWvns7FXYRtari2GXYDr5DLoEyyxAsVcCAFgMKZoMed MUw/zimod8P2N1+scwYl6v/4fFmzbU1IDfpl8erN+5IaTaLjuduKG3tMWCifxCEezy6n xOzw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=s5yvC5+jgu+oomjjgt/lH/bjvfcHjmqplnFnsHD+6cE=; b=h1P6xTam+rYHaEbtN3/I3/5NamKa8ualOTvVstEt6ZLyzZj4Guy4HF2gw2Do8wfhG4 UwS8Op6Rgmsq2qi+C/wcAa46WMx+NR+oEvZekj6E9P1pIzwfdrqDxy3MZctTeUepw2d3 nxOI5yH5fAS1roA8o9EZg/2c6ySewn8xywnsY4IzEInZifq1xdLpMhj6J5gKZfoK+jl0 egT7lIIedHoico1+CktxcRIP7ASG5NXXwlerlniLihRxds+9k/dycWUMIffiQz+JmGn0 wBqH0rqP5HhGjoDScgXA5Z1jCrbYhILirZEFaxXIiNQbG4h1WjnAUi7QNGozKeWUvMce Z2IA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gEYpunoX; 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=pass (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 v7-20020a05622a144700b00319586f870csi3522372qtx.380.2022.06.27.23.33.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:33:40 -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=pass header.i=@linaro.org header.s=google header.b=gEYpunoX; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:57802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64n5-0007Wv-Pr for patch@linaro.org; Tue, 28 Jun 2022 02:33:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JS-0001yX-Ep for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:58 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:41887) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JQ-0000Vy-Ps for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:58:58 -0400 Received: by mail-pl1-x62b.google.com with SMTP id c4so10024091plc.8 for ; Mon, 27 Jun 2022 21:58:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=s5yvC5+jgu+oomjjgt/lH/bjvfcHjmqplnFnsHD+6cE=; b=gEYpunoXsdElb/xsiVOf7ZhcIikAKdM//IguWcqio4khuTT9GqJ/NINnGl+1eb0BSP KKwJWZg0loTExrH0XUnpZ/QEl7V0MPH4FkPcfNEUBWpLCaVzXTykLkyp+mljoacRTLgm TKR02ugJKWVvbi8RwglFrTzjTk+bhqRZZz31gYPiQDL6j8RJG3bx+XY64acR1SoVf77t 8qesmlazB34WlcYD7ub0hIEiAhwl09Pxcaudl/pJ6A04j3pxNVXusLgDfZXR46hKxbJj iimx2Yq7/YnEH8Hl2M1+P2NiG2TpET56doooEtosqxa8GBwc3xYHHXXt3tp/fG2YwDE+ WLZA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=s5yvC5+jgu+oomjjgt/lH/bjvfcHjmqplnFnsHD+6cE=; b=Ju5Snip4/pfcr+265IvJu40fcvcLP4Yqxl6MwLePbfpPa2z3xvOSXGp/Lzaqp2kP7q 4VF4rLF+gz3ISHEnVBNSu3EVAEWLWW8EKhTE40vyZhgRdL6Zao77qIYMtaUZhfUTWerm d0jjDzMiEELT0vCbTAR4EK7/REQJZrZ0etsgfJv1FhSaFkK4U17p2NogSK/Blyy2O0k1 bhzuUsGNPB4l7YbrPR8l/N1cR+Rf0qelVbjMsdecJJdRJLNyll8d974lnaRa5Ovj9yRi 71z79mnDnr/SWL/7cHXYIt3cE5K+qNmIeBCBO4z1bmECgsp66H9aFzvm3TzFC8XnF3IX CWCg== X-Gm-Message-State: AJIora+Rpnz1fuAc77RRbkLbFY5EE6ihDDre32DL36sS0vsAa7FLig7R DoXlLVEN5rYYNaiF6GcKBmDkqXdERR4FLA== X-Received: by 2002:a17:902:d488:b0:16a:158e:dd0b with SMTP id c8-20020a170902d48800b0016a158edd0bmr1795761plg.162.1656392335259; Mon, 27 Jun 2022 21:58:55 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.58.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:58:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel , Peter Maydell Subject: [PULL 42/60] semihosting: Pass CPUState to qemu_semihosting_console_inc Date: Tue, 28 Jun 2022 10:23:45 +0530 Message-Id: <20220628045403.508716-43-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62b; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62b.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We don't need CPUArchState, and we do want the CPUState of the thread performing the operation -- use this instead of current_cpu. Reviewed-by: Luc Michel Reviewed-by: Peter Maydell Signed-off-by: Richard Henderson --- include/semihosting/console.h | 4 ++-- linux-user/semihost.c | 2 +- semihosting/arm-compat-semi.c | 2 +- semihosting/console.c | 12 ++++++------ 4 files changed, 10 insertions(+), 10 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 4f6217bf10..27f8e9ae2e 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -39,7 +39,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); /** * qemu_semihosting_console_inc: - * @env: CPUArchState + * @cs: CPUState * * Receive single character from debug console. As this call may block * if no data is available we suspend the CPU and will re-execute the @@ -50,7 +50,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); * * Returns: character read OR cpu_loop_exit! */ -target_ulong qemu_semihosting_console_inc(CPUArchState *env); +target_ulong qemu_semihosting_console_inc(CPUState *cs); /** * qemu_semihosting_log_out: diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 17f074ac56..f14c6ae21d 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -56,7 +56,7 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) * program is expecting more normal behaviour. This is slow but * nothing using semihosting console reading is expecting to be fast. */ -target_ulong qemu_semihosting_console_inc(CPUArchState *env) +target_ulong qemu_semihosting_console_inc(CPUState *cs) { uint8_t c; struct termios old_tio, new_tio; diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 1b0505987a..40f3730778 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -428,7 +428,7 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(env); + ret = qemu_semihosting_console_inc(cs); common_semi_set_ret(cs, ret); break; diff --git a/semihosting/console.c b/semihosting/console.c index 4e49202b2a..17ece6bdca 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -144,17 +144,17 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -target_ulong qemu_semihosting_console_inc(CPUArchState *env) +target_ulong qemu_semihosting_console_inc(CPUState *cs) { uint8_t ch; SemihostingConsole *c = &console; + g_assert(qemu_mutex_iothread_locked()); - g_assert(current_cpu); if (fifo8_is_empty(&c->fifo)) { - c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, current_cpu); - current_cpu->halted = 1; - current_cpu->exception_index = EXCP_HALTED; - cpu_loop_exit(current_cpu); + c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, cs); + cs->halted = 1; + cs->exception_index = EXCP_HALTED; + cpu_loop_exit(cs); /* never returns */ } ch = fifo8_pop(&c->fifo); From patchwork Tue Jun 28 04:53:46 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585556 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp537873mab; Tue, 28 Jun 2022 01:12:43 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vSwW7e5aFp1IBvmnE5y8b1b9r48RRuWRLYYtiPCI9l5O/49hL3H3rzlYzRTO7Wf7inT2aT X-Received: by 2002:ac8:7d8a:0:b0:31b:7da9:d513 with SMTP id c10-20020ac87d8a000000b0031b7da9d513mr4312507qtd.500.1656403963484; Tue, 28 Jun 2022 01:12:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656403963; cv=none; d=google.com; s=arc-20160816; b=FubBX6ZoUwOAAkQGqkEKSOrqCvS1Cib1VvOfbudoucnJv/CY/e5GHRfPzI3MM15OND NTEiiIS5n5epXgNQgB12J6D3eTkazpsQHSM6redY6GytPYxsdJNYXZ8JzXAybwtIP3Fb 7Sugttcg0LFGvJOLJX7drvc8+0dqGOPxgjFwBWHWueqpajfuZhwAuU/U5M19kxDniSB1 flVFRIw3q4W9v8oUuRBnkWz5rsF3wJUTsvsshqBBD5rNUGK1c/q6R7FKVWnRonDpZnTx +S18vUbd6Qqa4YZNzOH6da4OpiK/8ENiUIr4KX/7f6bo9Cx5iROVEv9wAcjiShdQVF+u 9ioQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=WmyDAD2u3RMCBNdl3aDHlvaK8YHnvUt0O1mqd+xCUGE=; b=qTS3hUbGGLGqal4iGIfigREPUAmNLfIvMyHKiCuVC+vzJtKHZxx3Ju/wpKouAcybH/ i6vgnsa1TXzZdOesgnRGKsTUw37FlocIj1kI+49uDCBwBSbGzUFenEtln0RbHpPh593v ju70Cm0sn51q0528vfG/qOs/9sK/c2uWYtTooIp/59mX2acbJWf4SvKgiLV4wyaD6rEn U24NuC7IEa3o8BsgAuPlZqjg7w+nVBeFYqferg5qsdey7vcUlCS9WWT4wJ4OX+yYYcXx pQ/TBoS7qSgqTbWNeLBrFfFDbVY8+Gm072XkTvzZSm38jrvQ7Hg15WlrJxzjguQFjoRp 0Qug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=yPzNIlLR; 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=pass (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 jm10-20020ad45eca000000b00470463cbee7si7167818qvb.429.2022.06.28.01.12.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:12:43 -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=pass header.i=@linaro.org header.s=google header.b=yPzNIlLR; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:49432 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66Kx-0005io-2I for patch@linaro.org; Tue, 28 Jun 2022 04:12:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44148) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JW-00020U-1p for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:05 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:53956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JS-0000W5-NE for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:00 -0400 Received: by mail-pj1-x1032.google.com with SMTP id d14so11436914pjs.3 for ; Mon, 27 Jun 2022 21:58:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WmyDAD2u3RMCBNdl3aDHlvaK8YHnvUt0O1mqd+xCUGE=; b=yPzNIlLRl02tY5GNzHcbg5Ftr7Gjp5ATtWtnUDHZPiKklVbnNPhT7rJxV+gHfo3Xrz f1ZcnpJNXy4fwBm8RE77G4i2NscTtm0TpHKOI76D2wseGoKuF3Ly7PXKst+2euCL15wv oCIWyzHMwQXxporJ3VB+xzV6Fr2ETRFQxjOEqKX67PmRdLkXOdWrw9AXpo2YLVmhlIrk XtEbKfAvGnt2OvAbNYJRJ0zCiGXgphc/p3hgr12G907WdCYhzdib/ry5HxpSBBj6rxLo 26YHihH0+32s9iG+VM08Y3MdafQwZuiXDU25yYvWDM1xehITMk7rLvSmwjxHpN1m8xTm LK1A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=WmyDAD2u3RMCBNdl3aDHlvaK8YHnvUt0O1mqd+xCUGE=; b=BeIydrsXLtk1WYmX+/BjbdjpJBE2NL9IYhm7S2+D5XazBmq1AyDLWYaJ+5s2KMe1oz BCUhwKDwjVesKopPNHgsF+udcYJyajdpGMx8wVt78ONVAaHBaOY2lNF7k52nT8zQDzcf 49CBGhF3WakDNujzmcU/2LSbGEOe35+UI2gVvl1FMrJl77ms06Of1dimCcFLL/yvVoOW VjaC9rab6WAz7pzonb7EBDNl+ZAHXYa0Bm3akbkOcI4v7vC/lilWcZnzV9/NVXacies2 k2l4aWJgzdLO5d2oV9PcszR6C4hNvLEar/mWivw3l8PqysWOIhOz67gWChpbHFLiwvkT dzvw== X-Gm-Message-State: AJIora+mKedVK5rY7URXi3RqwGpJqiH+BtGbBxfyH/4233LrSNgWUqnm Gz5FW83g0UrMfUSrsqh1izMM6fh+TBrk4Q== X-Received: by 2002:a17:90b:3584:b0:1ee:fa46:3986 with SMTP id mm4-20020a17090b358400b001eefa463986mr3367219pjb.227.1656392337342; Mon, 27 Jun 2022 21:58:57 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.58.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:58:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 43/60] semihosting: Expand qemu_semihosting_console_inc to read Date: Tue, 28 Jun 2022 10:23:46 +0530 Message-Id: <20220628045403.508716-44-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Allow more than one character to be read at one time. Will be used by m68k and nios2 semihosting for stdio. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/console.h | 12 +++++++----- linux-user/semihost.c | 10 ++++++---- semihosting/arm-compat-semi.c | 11 +++++++++-- semihosting/console.c | 16 ++++++++++++---- 4 files changed, 34 insertions(+), 15 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 27f8e9ae2e..39dbf1b062 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -38,19 +38,21 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); /** - * qemu_semihosting_console_inc: + * qemu_semihosting_console_read: * @cs: CPUState + * @buf: host buffer + * @len: buffer size * - * Receive single character from debug console. As this call may block - * if no data is available we suspend the CPU and will re-execute the + * Receive at least one character from debug console. As this call may + * block if no data is available we suspend the CPU and will re-execute the * instruction when data is there. Therefore two conditions must be met: * * - CPUState is synchronized before calling this function * - pc is only updated once the character is successfully returned * - * Returns: character read OR cpu_loop_exit! + * Returns: number of characters read, OR cpu_loop_exit! */ -target_ulong qemu_semihosting_console_inc(CPUState *cs); +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); /** * qemu_semihosting_log_out: diff --git a/linux-user/semihost.c b/linux-user/semihost.c index f14c6ae21d..2029fb674c 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -56,21 +56,23 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) * program is expecting more normal behaviour. This is slow but * nothing using semihosting console reading is expecting to be fast. */ -target_ulong qemu_semihosting_console_inc(CPUState *cs) +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) { - uint8_t c; + int ret; struct termios old_tio, new_tio; /* Disable line-buffering and echo */ tcgetattr(STDIN_FILENO, &old_tio); new_tio = old_tio; new_tio.c_lflag &= (~ICANON & ~ECHO); + new_tio.c_cc[VMIN] = 1; + new_tio.c_cc[VTIME] = 0; tcsetattr(STDIN_FILENO, TCSANOW, &new_tio); - c = getchar(); + ret = fread(buf, 1, len, stdin); /* restore config */ tcsetattr(STDIN_FILENO, TCSANOW, &old_tio); - return (target_ulong) c; + return ret; } diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 40f3730778..fdb143ace8 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -428,8 +428,15 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - ret = qemu_semihosting_console_inc(cs); - common_semi_set_ret(cs, ret); + { + uint8_t ch; + int ret = qemu_semihosting_console_read(cs, &ch, 1); + if (ret == 1) { + common_semi_cb(cs, ch, 0); + } else { + common_semi_cb(cs, -1, EIO); + } + } break; case TARGET_SYS_ISERROR: diff --git a/semihosting/console.c b/semihosting/console.c index 17ece6bdca..e5ac3f20ba 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -144,12 +144,14 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -target_ulong qemu_semihosting_console_inc(CPUState *cs) +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) { - uint8_t ch; SemihostingConsole *c = &console; + int ret = 0; g_assert(qemu_mutex_iothread_locked()); + + /* Block if the fifo is completely empty. */ if (fifo8_is_empty(&c->fifo)) { c->sleeping_cpus = g_slist_prepend(c->sleeping_cpus, cs); cs->halted = 1; @@ -157,8 +159,14 @@ target_ulong qemu_semihosting_console_inc(CPUState *cs) cpu_loop_exit(cs); /* never returns */ } - ch = fifo8_pop(&c->fifo); - return (target_ulong) ch; + + /* Read until buffer full or fifo exhausted. */ + do { + *(char *)(buf + ret) = fifo8_pop(&c->fifo); + ret++; + } while (ret < len && !fifo8_is_empty(&c->fifo)); + + return ret; } void qemu_semihosting_console_init(void) From patchwork Tue Jun 28 04:53:47 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585557 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp539707mab; Tue, 28 Jun 2022 01:15:30 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vGLvD3SVOABP0npM5Ct9UWcDIbd2EXnCAG3RzOhmJIKim8bmod+t+Q3ojFfS9P/f72WSuq X-Received: by 2002:a05:620a:6008:b0:6af:5d81:870b with SMTP id dw8-20020a05620a600800b006af5d81870bmr464176qkb.763.1656404130548; Tue, 28 Jun 2022 01:15:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404130; cv=none; d=google.com; s=arc-20160816; b=ioPzFOalCgW0eGyQzhaJ1YHawv/YPm51+QnP09y8FYFf6RDkWrh6tANFSNnXtf5I+x UeWU4kMswG98biDq80pNtNxqRQWzbgpwpINr/aZ6QWUGO0/A+Xp8Z+fnbnM6Uj8+vspg 3iA1DexCPeyB5mtkHNEwVjdHMhaXEY7EGwPmoCjCzBgQZFab7DmBh7Gje1RzV3z+EpF5 sUNPEgFjc+vt5llxl4EO5bkCAw0pgb/LMydBUaWfMq95KBpOgi0CSIr0TTFLu3hxYyB0 Pgr06+FmqdmJBC+AhwBGU1aSPeo/iclzvD+I4mz+okWH+7gHpahGZBaDfvnCV6lIcTEl 71bg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4xXXCwDW7BZ3fRj3JS6tTL98Qk1OFP4MXs/nw6KdL3U=; b=C8aCth/Yjde2+8qNW2bOB3CQRb5+Fs5rb1z2iPWGGc7miWlsgtWUcptO3UPI7aanSI lMOdNz+mY9SHmKyV4gdT6ihRgX4OuJzs1Itl4PaC6OAUf62E2f6teUjCJqM/W4WoahZ4 AV45BKrFmZB+Q3xo4LjnsR4y7JHwSebmFPj1IaONWO4yNLb1tXDy78oosegg4HDZi1HI oMFbgUGHfAjsoMKg0pjioVKurOFAATqr5DxOWRdgZnst9d3xQ1aI2VL7vB714ryrMvbT ZInqNb58DZTeoeUg276cQEFcACHqKJ5dirVqluZHG7mGS6Kji1FX96WKwn4ev87Osryy 6Pmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ynHheS0Y; 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=pass (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 o12-20020ac87c4c000000b00304e5298d21si7256913qtv.169.2022.06.28.01.15.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:15:30 -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=pass header.i=@linaro.org header.s=google header.b=ynHheS0Y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:58110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66Ne-00037I-3Q for patch@linaro.org; Tue, 28 Jun 2022 04:15:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JX-00020i-Mc for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:07 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:46597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JV-0000WI-SR for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:03 -0400 Received: by mail-pj1-x1033.google.com with SMTP id h9-20020a17090a648900b001ecb8596e43so11458083pjj.5 for ; Mon, 27 Jun 2022 21:59:00 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4xXXCwDW7BZ3fRj3JS6tTL98Qk1OFP4MXs/nw6KdL3U=; b=ynHheS0Y3IppPELmhzsxCYif+ufZJPn62i3aR8N2lQ3rbTBOk/ee1+inUvPPDaP5Cg miMfQReeaqC2Bz2np625pAhCkJodExCgw522zblq4wT8Dyv72By5lmu+6Grhd06V5e0H EZI//KB7ek01gzY7cYyxYygOa34lLTh3VkbvevKSh5UkZw6JGurgvWx6zxNOsbYIWShS y1Gb938CkFldRoxPAOuAMtNG7cu0AhV4FSnxJKfkL7NM8GwHSU1MMqsBkL5eAgp4Zd/q qh+KqSNTC2D5Hyyyi6Fvoh6D2aww6Jsp5aDYOKilkOdQy8/ecz8MN4DaoCggLhMyiVsC iacQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4xXXCwDW7BZ3fRj3JS6tTL98Qk1OFP4MXs/nw6KdL3U=; b=Z8IYTms1P+mQ+DxlCS4Slb/Yx+6/GZcgd8MUu/8+UV7Xwms7jbtQcy9XqW0EgQqH2A P/++Fh+Hh0UP8WBUf7KJWdd5vSOjdvXjly9FxKLZg0K4byY6tjpw7S4LYvBw3YqohRY3 2jXV6UO2GsnRVqvThSJ2EccKZH+ztct+5fs9M47ifCujG9QbjZd5Wg2wNYmNyinx/WhU z7LL6BhGXFuVUb+ISGWVCI8zy//4GtdTvydyK9i+bw53smaHNpr4xmAHuUCDCaxnA+1/ OelUDFaUI3gdi+sbHXFmPMf+X6wgjJKpLotYuwFotbn7MWXq8MEbvI4LfXaqjQ4eGyq0 Sr7w== X-Gm-Message-State: AJIora9q3bqclyTJgEue8OsyeD3Osf6bxFET6J0H7z2iVsIfdEnsiIYp SsWco6wOGOtJL2XWVEUwi+ZqwcHN0IXxzA== X-Received: by 2002:a17:903:2410:b0:16a:81d2:f5e8 with SMTP id e16-20020a170903241000b0016a81d2f5e8mr1789101plo.81.1656392339527; Mon, 27 Jun 2022 21:58:59 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.58.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:58:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 44/60] semihosting: Cleanup chardev init Date: Tue, 28 Jun 2022 10:23:47 +0530 Message-Id: <20220628045403.508716-45-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Rename qemu_semihosting_connect_chardevs to qemu_semihosting_chardev_init; pass the result directly to qemu_semihosting_console_init. Store the chardev in SemihostingConsole instead of SemihostingConfig, which lets us drop semihosting_get_chardev. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/semihost.h | 13 ++----------- semihosting/config.c | 17 +++++++---------- semihosting/console.c | 31 +++++++++++++++---------------- softmmu/vl.c | 3 +-- stubs/semihost.c | 6 +----- 5 files changed, 26 insertions(+), 44 deletions(-) diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 0c55ade3ac..5b36a76f08 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -51,14 +51,6 @@ static inline const char *semihosting_get_cmdline(void) { return NULL; } - -static inline Chardev *semihosting_get_chardev(void) -{ - return NULL; -} -static inline void qemu_semihosting_console_init(void) -{ -} #else /* !CONFIG_USER_ONLY */ bool semihosting_enabled(void); SemihostingTarget semihosting_get_target(void); @@ -66,12 +58,11 @@ const char *semihosting_get_arg(int i); int semihosting_get_argc(void); const char *semihosting_get_cmdline(void); void semihosting_arg_fallback(const char *file, const char *cmd); -Chardev *semihosting_get_chardev(void); /* for vl.c hooks */ void qemu_semihosting_enable(void); int qemu_semihosting_config_options(const char *opt); -void qemu_semihosting_connect_chardevs(void); -void qemu_semihosting_console_init(void); +void qemu_semihosting_chardev_init(void); +void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ #endif /* SEMIHOST_H */ diff --git a/semihosting/config.c b/semihosting/config.c index 3afacf54ab..e171d4d6bc 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -51,7 +51,6 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; - Chardev *chardev; char **argv; int argc; const char *cmdline; /* concatenated argv */ @@ -122,11 +121,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) } } -Chardev *semihosting_get_chardev(void) -{ - return semihosting.chardev; -} - void qemu_semihosting_enable(void) { semihosting.enabled = true; @@ -172,16 +166,19 @@ int qemu_semihosting_config_options(const char *optarg) return 0; } -void qemu_semihosting_connect_chardevs(void) +/* We had to defer this until chardevs were created */ +void qemu_semihosting_chardev_init(void) { - /* We had to defer this until chardevs were created */ + Chardev *chr = NULL; + if (semihost_chardev) { - Chardev *chr = qemu_chr_find(semihost_chardev); + chr = qemu_chr_find(semihost_chardev); if (chr == NULL) { error_report("semihosting chardev '%s' not found", semihost_chardev); exit(1); } - semihosting.chardev = chr; } + + qemu_semihosting_console_init(chr); } diff --git a/semihosting/console.c b/semihosting/console.c index e5ac3f20ba..1d16a290c4 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -27,11 +27,21 @@ #include "qapi/error.h" #include "qemu/fifo8.h" +/* Access to this structure is protected by the BQL */ +typedef struct SemihostingConsole { + CharBackend backend; + Chardev *chr; + GSList *sleeping_cpus; + bool got; + Fifo8 fifo; +} SemihostingConsole; + +static SemihostingConsole console; + int qemu_semihosting_log_out(const char *s, int len) { - Chardev *chardev = semihosting_get_chardev(); - if (chardev) { - return qemu_chr_write_all(chardev, (uint8_t *) s, len); + if (console.chr) { + return qemu_chr_write_all(console.chr, (uint8_t *) s, len); } else { return write(STDERR_FILENO, s, len); } @@ -106,16 +116,6 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) #define FIFO_SIZE 1024 -/* Access to this structure is protected by the BQL */ -typedef struct SemihostingConsole { - CharBackend backend; - GSList *sleeping_cpus; - bool got; - Fifo8 fifo; -} SemihostingConsole; - -static SemihostingConsole console; - static int console_can_read(void *opaque) { SemihostingConsole *c = opaque; @@ -169,10 +169,9 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } -void qemu_semihosting_console_init(void) +void qemu_semihosting_console_init(Chardev *chr) { - Chardev *chr = semihosting_get_chardev(); - + console.chr = chr; if (chr) { fifo8_create(&console.fifo, FIFO_SIZE); qemu_chr_fe_init(&console.backend, chr, &error_abort); diff --git a/softmmu/vl.c b/softmmu/vl.c index 3dca5936c7..b24772841d 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -1917,8 +1917,7 @@ static void qemu_create_late_backends(void) exit(1); /* now chardevs have been created we may have semihosting to connect */ - qemu_semihosting_connect_chardevs(); - qemu_semihosting_console_init(); + qemu_semihosting_chardev_init(); } static void qemu_resolve_machine_memdev(void) diff --git a/stubs/semihost.c b/stubs/semihost.c index 4bf2cf71b9..f486651afb 100644 --- a/stubs/semihost.c +++ b/stubs/semihost.c @@ -65,10 +65,6 @@ void semihosting_arg_fallback(const char *file, const char *cmd) { } -void qemu_semihosting_connect_chardevs(void) -{ -} - -void qemu_semihosting_console_init(void) +void qemu_semihosting_chardev_init(void) { } From patchwork Tue Jun 28 04:53:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585536 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp495891mab; Tue, 28 Jun 2022 00:06:23 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vLzlEi0RLEuDosxQEbKsxdiB6KO/rFVbZhQnO/TMgiDlBlxMGMWO3HN2ZLmZMxnKWY0Hnp X-Received: by 2002:a05:622a:118a:b0:315:b54c:a9b7 with SMTP id m10-20020a05622a118a00b00315b54ca9b7mr11789782qtk.647.1656399983254; Tue, 28 Jun 2022 00:06:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399983; cv=none; d=google.com; s=arc-20160816; b=k2IBABlb7GRiuWj0E4HTwNT0GiGuVheg0xB7IPdaWgCdH390Nj2hJz0mkb7AAtGaH/ NVfhWZMGDWXTV1bpfFm8y6idvN9dEi9LW/poMdmO/zzwU7edx5QfBpkmN5ETHjaWyyfJ 9GGZ8mFFIMDJFoi/xMfPD2g28izvq4xPnw7C1JEJ/eilBbOAOB6WtC803PhaePoya5I2 n0/U5ZJKHt1gSWg/0Je7UzNSC++QheOZQMveDvOqxuRhwmzAt5/dbPZKX69b+KjpNwW/ 8Wsrr8S1fm2tT8CtnJlJDN8oTR4wGa24n0jU8Xq4U+SNibbmm2OHByp1tBzw8Sr5OO0b +DsA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=K8zCLnXZDBM5u3PUfLQVmMkwLgGIxJ2JdOpBGrHPDBM=; b=q+v8vUqbph8qlJGRSCRg9I9SL0LTTx+w5nn+PWVeH4AlIXNgGqTw4SsqGsWjtOSuv4 Y/BU/zSyEFuaAIogzKMaR/9qwt+lbAaw1weG8kOjAXl5cye1UGMx2acFLThyfHzsLkL2 YEYuV2dTNc1rswV29nfcUcxgqdYJCBjQhe/WnLvB7vwXDniYo/B6Ssw6AhVwPn/XXTz4 RY72g3ECIUpIN0nbdf8l2tLFjseoS0VK3cKEidODUO6bTRWvCXvts6EjYakAe8JbHc9J 0LHTcI2bRcGtGdRCe4tJe4Iqnle4nbbudc6vVzYx038A3sb1mPL8HFIf+aRITeiH4vpJ Cosw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gBtaAg4I; 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=pass (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 o16-20020a05622a009000b00304e8592510si6670005qtw.159.2022.06.28.00.06.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:06:23 -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=pass header.i=@linaro.org header.s=google header.b=gBtaAg4I; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:41886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Ik-0004Ex-Oc for patch@linaro.org; Tue, 28 Jun 2022 03:06:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44182) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63JZ-00020r-T1 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:07 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:35767) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JX-0000WW-FF for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:04 -0400 Received: by mail-pj1-x1035.google.com with SMTP id x1-20020a17090abc8100b001ec7f8a51f5so14692524pjr.0 for ; Mon, 27 Jun 2022 21:59:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K8zCLnXZDBM5u3PUfLQVmMkwLgGIxJ2JdOpBGrHPDBM=; b=gBtaAg4InhTyedzc7vVXTU0QokhJc3tFnjZNrofUuePwZysa0t3Bzr7nEDqE7lw7TK eKxDRRg0GzX8vbHRgotFQUMinGaUI0lt+oi5X7Hjo0VUvOW+GkbNh05+aRLy+W0LYY0u 8RKY8wmoqY7HeJ4mPwd2le4OVwP1kN+OmNLTLlqpn+jJzGtk2Jn13M+hheisgUpsgGIv +LlTDrfrHIkmM0NZ0AxqKI9Lt5rQqz/86Gqz/pFaT8wmutb1ypCFoYkH5pckUu8PHW4d u8rTA9IQg3piHTh6YQap5SI0/IdNm1xfFDlWMF+mCin0HjVfT/g0wKGKfz+7sg5FLcud ZHrw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K8zCLnXZDBM5u3PUfLQVmMkwLgGIxJ2JdOpBGrHPDBM=; b=3w2h0uGjWKNP9oeBtNui7+IXUvlfTLG3dh1pRkJAnvcJAxlv1zfes0mTNHwfxqe+7P LJt28+Yn/8CeE8wxnWv5RgAVZ9Cw1EH14ndyLFpFkKOGuKjSZ39dH+HWMBEnEbIYGwZH o5wi7TPwWHnvxr+tMKGZkn6k1Wq/SkAeNAVJzrQ0L5V1yVYp2rYXjdkwKwFNbnI0HX/k z6GwXHW0jRLyYZuF7eBaLyyPj3YfY3PegpHqUsjVbhV1Bs9rK3h5hG7Qn2TJy1Ds3Lwi TcM5hzphdQmDXihUlG13HTh2ve+ePiCd7CnHdXBiVG4/pvbpmEoiw70tR1jdl39UXA7p C1Zw== X-Gm-Message-State: AJIora9m7npam5LYPwx78/zweZYfuhhNts0BPDKW1IbIl0q83plN3a3x OCOaJf2lMY6SXho5JXdWQgOCUzfKYDrhrA== X-Received: by 2002:a17:902:d4ce:b0:16a:7696:9700 with SMTP id o14-20020a170902d4ce00b0016a76969700mr1820322plg.66.1656392341812; Mon, 27 Jun 2022 21:59:01 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.00 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 45/60] semihosting: Create qemu_semihosting_console_write Date: Tue, 28 Jun 2022 10:23:48 +0530 Message-Id: <20220628045403.508716-46-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Will replace qemu_semihosting_console_{outs,outc}, but we need more plumbing first. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/console.h | 12 ++++++++++++ linux-user/semihost.c | 5 +++++ semihosting/console.c | 9 +++++++++ 3 files changed, 26 insertions(+) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 39dbf1b062..6994f23c82 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -54,6 +54,18 @@ void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); */ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); +/** + * qemu_semihosting_console_write: + * @buf: host buffer + * @len: buffer size + * + * Write len bytes from buf to the debug console. + * + * Returns: number of bytes written -- this should only ever be short + * on some sort of i/o error. + */ +int qemu_semihosting_console_write(void *buf, int len); + /** * qemu_semihosting_log_out: * @s: pointer to string diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 2029fb674c..871edf993a 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -76,3 +76,8 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } + +int qemu_semihosting_console_write(void *buf, int len) +{ + return fwrite(buf, 1, len, stderr); +} diff --git a/semihosting/console.c b/semihosting/console.c index 1d16a290c4..540aa0cd4b 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -169,6 +169,15 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) return ret; } +int qemu_semihosting_console_write(void *buf, int len) +{ + if (console.chr) { + return qemu_chr_write_all(console.chr, (uint8_t *)buf, len); + } else { + return fwrite(buf, 1, len, stderr); + } +} + void qemu_semihosting_console_init(Chardev *chr) { console.chr = chr; From patchwork Tue Jun 28 04:53:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585539 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp500912mab; Tue, 28 Jun 2022 00:14:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ukesL/vWPppMemVDDVorw20DjuobhA88HGjfkPlYK60tmtS43r4SkLNVfsZ7Wlw6RarfOr X-Received: by 2002:ae9:f106:0:b0:6ae:dca2:73f7 with SMTP id k6-20020ae9f106000000b006aedca273f7mr10450772qkg.266.1656400476507; Tue, 28 Jun 2022 00:14:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400476; cv=none; d=google.com; s=arc-20160816; b=xjMPymO+OV6Ojvc1WI0yYFi0msSLltTVMN84iKNvVoQ5pAxbJgx5r13jVXNBubumth awPC5snSoYJeCLOKr+SDK6IOvQoOk35a0T5we6RU6lyZ9fR/i75/La/dCx6ZYkd+u8DG /zo4dzmQgypt27y8E6d+KReXfPkdAm+WtMNC/D4BpGMAQXg3YN7edkn9FTuNBYGYADdP 0pXu6mfJ8EMsze/dcfeCEWeLy/yn3QNQndDXCZE8ekCQt/mcjSZ3LRdSBxovA5mPpB1E l+7pMOJ4SXIaYpCsvFPZ0EGLtp4JTuE/D0Km8ljkMbd+xxfW+gSJGGoAdeG/ZGELWNEq ZcuQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=hlSrerE/ONSg0LVKjyJGeSkE9veMTHprjHDwYw72eK4=; b=VgBwrJB089F+L9ne5Fq8PhXEuDAEz8sLGjJcy2R/iGN3NyH5ZODbdV5cM93I09DU6+ JRv6zBHva/Y1y49n/d2O4oBiXJYkuSt9THvTAnOige0Zc4SyG+I17rn8tGtnxCg2k4eb N85wXGSUwuKp1TXTWDyq1lwmeGzrGiNvEyYIoedgv7aI8p0eOWOzdWbM3aGRVnvZqAkg +NO4eZF9a7D9miA281uG1djc15jjHThTrSh3L6tmI7V/ZrPj/O8+UF/ZygPBaiAI/Xi/ qHaunorDLUypPIPsHaDPNSu24kQxJACurydS06vzYuPOdg+oW+L4N1flzU9jmX9DPn3R 0fqw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WBu+wYa4; 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=pass (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 j11-20020a05621419cb00b0046e46e4326dsi7153299qvc.78.2022.06.28.00.14.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:14:36 -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=pass header.i=@linaro.org header.s=google header.b=WBu+wYa4; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:51144 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Qh-0002db-Sh for patch@linaro.org; Tue, 28 Jun 2022 03:14:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jc-00021q-Hs for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:09 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:53956) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63JZ-0000W5-IW for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:07 -0400 Received: by mail-pj1-x1032.google.com with SMTP id d14so11436914pjs.3 for ; Mon, 27 Jun 2022 21:59:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hlSrerE/ONSg0LVKjyJGeSkE9veMTHprjHDwYw72eK4=; b=WBu+wYa4ZYQQg+UltowXTuhS+SlEhkRbLgY+DJZmcvY0DcvkkdVlPjvYuPadJvFyCi s/aDbc9eBX71n2NF37BOPyzD7OomMpwOkZNhQzQCkIg8pvTpnc96fUVmWPIOTEmk8E6A xRyBaElITNA4NItBnMfFU6/cVraqLR1h1ATK8Yap0WLTI0lkB/H2WNzIO8pGs826HJPQ /TtDjUFTZaUOHNTDazuGYtWCliOL3GahwgovCEZzRiikTCSfgnDkBHhk/Nuhd0fYHf5C emWT9knXu1TTTj2pDmyaYWdHWQfYz/WoDOfYpSqbdHej7wteKKVbfRw+teE20m23o+St 6qNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=hlSrerE/ONSg0LVKjyJGeSkE9veMTHprjHDwYw72eK4=; b=o88K5Y2QSHu7serpZVyK+8mJORTtULIeEhvoS/nbUIxpN+AZMxyWkhBioW/jMAoocf Q+gOjhKvAjeU5qSBjVVYBDbNfUzGs8bqUMXsx3xVwBoiuUgm9FYdI4toGbAPTd0e5gqU 6m4nACyhnQCoq1gfFO0a2lskU0rQId9DroddHTZvzRZyG+MHNCRNhghrt6Hk6aQ4m+DW vSTqAvAjj/qFLBo0nOSnLXVZ61107Rob2v6CXebpnsDMZ8J/Mpb/LoQyCFWyEm3YgCPM lLLYhuqTUNWy9a/BrQ0b0Riu0JsvfMBTmyqqjLNOKW3+bFlIinFIgRv/EUOS0y2AQJ5e L+hw== X-Gm-Message-State: AJIora9BBidCj4nMBY9SOxIQ3rz9CzRi9fzwC9hSGYt1lBOnUMQuUGza 0h9eI+UPTPedsCxptj0hTs8r+G6AIFG9dQ== X-Received: by 2002:a17:903:328e:b0:16b:8745:bb77 with SMTP id jh14-20020a170903328e00b0016b8745bb77mr3030872plb.70.1656392344208; Mon, 27 Jun 2022 21:59:04 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 46/60] semihosting: Add GuestFDConsole Date: Tue, 28 Jun 2022 10:23:49 +0530 Message-Id: <20220628045403.508716-47-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Add a GuestFDType for connecting to the semihosting console. Hook up to read, write, isatty, and fstat syscalls. Note that the arm-specific syscall flen cannot be applied to the console, because the console is not a descriptor exposed to the guest. Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 ++-- semihosting/syscalls.c | 68 +++++++++++++++++++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index ef268abe85..a7ea1041ea 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -13,9 +13,10 @@ typedef enum GuestFDType { GuestFDUnused = 0, - GuestFDHost = 1, - GuestFDGDB = 2, - GuestFDStatic = 3, + GuestFDHost, + GuestFDGDB, + GuestFDStatic, + GuestFDConsole, } GuestFDType; /* diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 13a9bdeda6..9e499b1751 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -10,6 +10,7 @@ #include "exec/gdbstub.h" #include "semihosting/guestfd.h" #include "semihosting/syscalls.h" +#include "semihosting/console.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" #else @@ -577,6 +578,56 @@ static void staticfile_flen(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, gf->staticfile.len, 0); } +/* + * Console semihosting syscall implementations. + */ + +static void console_read(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ptr; + int ret; + + ptr = lock_user(VERIFY_WRITE, buf, len, 0); + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = qemu_semihosting_console_read(cs, ptr, len); + complete(cs, ret, 0); + unlock_user(ptr, buf, ret); +} + +static void console_write(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong buf, target_ulong len) +{ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + char *ptr = lock_user(VERIFY_READ, buf, len, 1); + int ret; + + if (!ptr) { + complete(cs, -1, EFAULT); + return; + } + ret = qemu_semihosting_console_write(ptr, len); + complete(cs, ret ? ret : -1, ret ? 0 : EIO); + unlock_user(ptr, buf, ret); +} + +static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, target_ulong addr) +{ + static const struct stat tty_buf = { + .st_mode = 020666, /* S_IFCHR, ugo+rw */ + .st_rdev = 5, /* makedev(5, 0) -- linux /dev/tty */ + }; + int ret; + + ret = copy_stat_to_user(cs, addr, &tty_buf); + complete(cs, ret ? -1 : 0, ret ? -ret : 0); +} + /* * Syscall entry points. */ @@ -608,6 +659,7 @@ void semihost_sys_close(CPUState *cs, gdb_syscall_complete_cb complete, int fd) host_close(cs, complete, gf); break; case GuestFDStatic: + case GuestFDConsole: complete(cs, 0, 0); break; default: @@ -637,6 +689,9 @@ void semihost_sys_read_gf(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDStatic: staticfile_read(cs, complete, gf, buf, len); break; + case GuestFDConsole: + console_read(cs, complete, gf, buf, len); + break; default: g_assert_not_reached(); } @@ -672,6 +727,9 @@ void semihost_sys_write_gf(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDHost: host_write(cs, complete, gf, buf, len); break; + case GuestFDConsole: + console_write(cs, complete, gf, buf, len); + break; case GuestFDStatic: /* Static files are never open for writing: EBADF. */ complete(cs, -1, EBADF); @@ -712,6 +770,9 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDStatic: staticfile_lseek(cs, complete, gf, off, gdb_whence); break; + case GuestFDConsole: + complete(cs, -1, ESPIPE); + break; default: g_assert_not_reached(); } @@ -735,6 +796,9 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) case GuestFDStatic: complete(cs, 0, ENOTTY); break; + case GuestFDConsole: + complete(cs, 1, 0); + break; default: g_assert_not_reached(); } @@ -760,6 +824,7 @@ void semihost_sys_flen(CPUState *cs, gdb_syscall_complete_cb fstat_cb, case GuestFDStatic: staticfile_flen(cs, flen_cb, gf); break; + case GuestFDConsole: default: g_assert_not_reached(); } @@ -781,6 +846,9 @@ void semihost_sys_fstat(CPUState *cs, gdb_syscall_complete_cb complete, case GuestFDHost: host_fstat(cs, complete, gf, addr); break; + case GuestFDConsole: + console_fstat(cs, complete, gf, addr); + break; case GuestFDStatic: default: g_assert_not_reached(); From patchwork Tue Jun 28 04:53:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585558 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp542670mab; Tue, 28 Jun 2022 01:20:17 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sfHRjsr35H8s+CQdnxu9ki3SOAnNJcXo01ybXoydZr+WEv0w0cNzM7iq9ZKBmlFzFzYvnp X-Received: by 2002:a05:620a:790:b0:6af:6859:ff9f with SMTP id 16-20020a05620a079000b006af6859ff9fmr130489qka.252.1656404417066; Tue, 28 Jun 2022 01:20:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404417; cv=none; d=google.com; s=arc-20160816; b=stzhPNNrVq/3frcQEmizvY5nDJ5eQXg4KNT6/7+snuXx9vQXSlLLP4LUe33C4XHeu1 N3C/jZoJTQYoPw5zA7VSXzqfV2GuoA9Gv6LKy22s8JMKggFuBNxhDBORWdKSy+Tl4Pna KVfyxFPhivs6gv4Yqpi4cB6UBeW6PWHenyh0jhR0k5vFEl7NpdR0PL+IFMmAWU3VShVG /PuMIJP85wRwza7wbVfUbmJpBpE9at/BI2tTExMQVurgpGTiNFKdwI7SVxJhqLSKrga2 fKuJrF63XInrbVzvDKhpnABoVbYeVGslwOV1LGBdV6/rSOZLMXQaJjZf98GiDYpJ8NlS gjIw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=dvGEwia2LqXULvjK9x7SGCFtetADqVhqrMHOvvd+KrlFN9yY46SPCBXZHSe2a2iJl+ /IB7b3CWWLrxZR02fRY7dB9d+PvZp3gFN5iVI81yWIqZadDAw0rm9l72Jshafw3Pr8iN otgiEW8J5Sr4i1isW4m4YbRml+4Ay37lgMaYnCeUEWOeew73Hv5XdxdYYhzu1XC2dNe/ zgFQZMMn/r3Io6wLD2RWB47GVKuF06nQFKWOBlOy2scL0x4Ugc7ehRCZTJYYnTZxHPz4 ZVdXXm2Q0ZdVV/rVcqn+unaOnyK7m0tK1tuYcO1lkfW7JlSQ2U7rugxRWwfcu48I3h1M kizA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=y+8Dn+aa; 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=pass (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 u21-20020a05620a0c5500b006a6c8a03307si8191913qki.88.2022.06.28.01.20.16 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:20:17 -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=pass header.i=@linaro.org header.s=google header.b=y+8Dn+aa; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38266 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66SG-0000SH-K2 for patch@linaro.org; Tue, 28 Jun 2022 04:20:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44214) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Je-000225-4Z for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:11 -0400 Received: from mail-pl1-x633.google.com ([2607:f8b0:4864:20::633]:38562) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jc-0000Wu-AF for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:09 -0400 Received: by mail-pl1-x633.google.com with SMTP id m14so10041998plg.5 for ; Mon, 27 Jun 2022 21:59:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=y+8Dn+aa7QQPwv08UEhLc2w3gkwzn1ur98cRK5MdLtldEaEEcNjZoVcC66T6moET+/ aavLWDihOjqHv1CfnvHwrmBNvY5ARq8mXVE/wjiBuxHAeskJ4mQipFxRWfQHiC8YIJRp 01v0HbM1VuDmaOoFVS2nv648CgEqan+YoAJzbcp0spi8JO9Eq25mBWWnZ6nWup07LzDf FLbSZtgk6agW3B7mcl6gS9kYCo9vPWyaWtnthhRtLomJ3c3HXakvs5YAzEg6Gon6KP/0 xMShIa/iu53RBYTGNRumacp4tsjf2vcTxgHOYk4AhtXwpwLGm0QDJHIK105QapgxJw7c Q1Mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lB5ybBGRmrAOm3Wx4wV/l5RlYf9l1nrqsAeZO2RipkU=; b=n1NoqHvNGbOAy0USXDUS6W2rCwM4P/w6fTNsLub7wXJyf0/KwkQj0EWcn9McM3V7BI +4kY/WhWy1NNfj0IAq8Xc8Qh/UP+qj5XgvI0AyUbyLWeANcxSaYf4QoWDlmNEIIj6Euh enpYuiqjRThfBsXJYmWpKSifJAW/KRamD4Sz0cxixthHHtPy4kJpRqHjgmLxfiLrkmOZ Xh7JQ5JUuZeD94MVJozWDry2zgym5hc8y7htucV4iSon4tAA0aO8c/UuwsV7zTndqDBe PvrFL5XNgZF444cgaZSniqNV0/aVp0Q1GZCP2ULJlASjtVjSYUZzDjrakL6x1iC232Jt pEgg== X-Gm-Message-State: AJIora8PzefVjzU36SrdFOlVsAJOoPzQy93rnOQF5g2cQ1elb37JAKuo ++HwrIiHGg7G1F+fLMcGaUuyUH7FXSe1kA== X-Received: by 2002:a17:903:1cc:b0:16a:73fd:3c87 with SMTP id e12-20020a17090301cc00b0016a73fd3c87mr1783853plh.41.1656392346832; Mon, 27 Jun 2022 21:59:06 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 47/60] semihosting: Create qemu_semihosting_guestfd_init Date: Tue, 28 Jun 2022 10:23:50 +0530 Message-Id: <20220628045403.508716-48-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::633; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x633.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" For arm-compat, initialize console_{in,out}_gf; otherwise, initialize stdio file descriptors. This will go some way to cleaning up arm-compat, and will allow other semihosting to use normal stdio. Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 7 +++++ include/semihosting/semihost.h | 1 + linux-user/main.c | 9 ++++++ semihosting/console.c | 2 ++ semihosting/guestfd.c | 52 +++++++++++++++++++++++++++------- 5 files changed, 61 insertions(+), 10 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index a7ea1041ea..3d426fedab 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -35,6 +35,13 @@ typedef struct GuestFD { }; } GuestFD; +/* + * For ARM semihosting, we have a separate structure for routing + * data for the console which is outside the guest fd address space. + */ +extern GuestFD console_in_gf; +extern GuestFD console_out_gf; + /** * alloc_guestfd: * diff --git a/include/semihosting/semihost.h b/include/semihosting/semihost.h index 5b36a76f08..93a3c21b44 100644 --- a/include/semihosting/semihost.h +++ b/include/semihosting/semihost.h @@ -64,5 +64,6 @@ int qemu_semihosting_config_options(const char *opt); void qemu_semihosting_chardev_init(void); void qemu_semihosting_console_init(Chardev *); #endif /* CONFIG_USER_ONLY */ +void qemu_semihosting_guestfd_init(void); #endif /* SEMIHOST_H */ diff --git a/linux-user/main.c b/linux-user/main.c index 651e32f5f2..e44bdb17b8 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -54,6 +54,10 @@ #include "loader.h" #include "user-mmap.h" +#ifdef CONFIG_SEMIHOSTING +#include "semihosting/semihost.h" +#endif + #ifndef AT_FLAGS_PRESERVE_ARGV0 #define AT_FLAGS_PRESERVE_ARGV0_BIT 0 #define AT_FLAGS_PRESERVE_ARGV0 (1 << AT_FLAGS_PRESERVE_ARGV0_BIT) @@ -906,6 +910,11 @@ int main(int argc, char **argv, char **envp) } gdb_handlesig(cpu, 0); } + +#ifdef CONFIG_SEMIHOSTING + qemu_semihosting_guestfd_init(); +#endif + cpu_loop(env); /* never exits */ return 0; diff --git a/semihosting/console.c b/semihosting/console.c index 540aa0cd4b..955880514e 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -190,4 +190,6 @@ void qemu_semihosting_console_init(Chardev *chr) NULL, NULL, &console, NULL, true); } + + qemu_semihosting_guestfd_init(); } diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e3122ebba9..b05c52f26f 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -10,15 +10,56 @@ #include "qemu/osdep.h" #include "exec/gdbstub.h" +#include "semihosting/semihost.h" #include "semihosting/guestfd.h" #ifdef CONFIG_USER_ONLY #include "qemu.h" #else #include "semihosting/softmmu-uaccess.h" +#include CONFIG_DEVICES #endif static GArray *guestfd_array; +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING +GuestFD console_in_gf; +GuestFD console_out_gf; +#endif + +void qemu_semihosting_guestfd_init(void) +{ + /* New entries zero-initialized, i.e. type GuestFDUnused */ + guestfd_array = g_array_new(FALSE, TRUE, sizeof(GuestFD)); + +#ifdef CONFIG_ARM_COMPATIBLE_SEMIHOSTING + /* For ARM-compat, the console is in a separate namespace. */ + if (use_gdb_syscalls()) { + console_in_gf.type = GuestFDGDB; + console_in_gf.hostfd = 0; + console_out_gf.type = GuestFDGDB; + console_out_gf.hostfd = 2; + } else { + console_in_gf.type = GuestFDConsole; + console_out_gf.type = GuestFDConsole; + } +#else + /* Otherwise, the stdio file descriptors apply. */ + guestfd_array = g_array_set_size(guestfd_array, 3); +#ifndef CONFIG_USER_ONLY + if (!use_gdb_syscalls()) { + GuestFD *gf = &g_array_index(guestfd_array, GuestFD, 0); + gf[0].type = GuestFDConsole; + gf[1].type = GuestFDConsole; + gf[2].type = GuestFDConsole; + return; + } +#endif + associate_guestfd(0, 0); + associate_guestfd(1, 1); + associate_guestfd(2, 2); +#endif +} + /* * Allocate a new guest file descriptor and return it; if we * couldn't allocate a new fd then return -1. @@ -30,11 +71,6 @@ 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)); - } - /* SYS_OPEN should return nonzero handle on success. Start guestfd from 1 */ for (i = 1; i < guestfd_array->len; i++) { GuestFD *gf = &g_array_index(guestfd_array, GuestFD, i); @@ -61,11 +97,7 @@ static void do_dealloc_guestfd(GuestFD *gf) */ static GuestFD *do_get_guestfd(int guestfd) { - if (!guestfd_array) { - return NULL; - } - - if (guestfd <= 0 || guestfd >= guestfd_array->len) { + if (guestfd < 0 || guestfd >= guestfd_array->len) { return NULL; } From patchwork Tue Jun 28 04:53:51 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585542 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp505341mab; Tue, 28 Jun 2022 00:22:01 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tKFv/2rg4xAWkKPZYU3ivhpXPqgLyNgp+tYfxasT20wKuV8ORWSFOYhZe6XMy7aJIBImt0 X-Received: by 2002:a05:6214:300d:b0:470:4530:79f1 with SMTP id ke13-20020a056214300d00b00470453079f1mr2358488qvb.121.1656400921680; Tue, 28 Jun 2022 00:22:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400921; cv=none; d=google.com; s=arc-20160816; b=pFT+9QxjkJe4C64aXfM9N57CMJ/QkyF1FgMTZnJyWTrxoBU8jyRbpPS6FTOOotWXN3 bUnS8blFQ9u0X7J6b4DU1Bc65rKEGgeWLFfS6ZIWefdsOgvA2wsxk1/f/U3i5Gv9x1kf 4nSYf3nfxLcBqVoVrC2T00qiCCxCoFl6Lolm/v1YvHOIvNjXAcT2p7wEVOBSMsNrX+A9 sud60M9aCIdAq5gks6RggvAU5174ouCyxwiJGb5adpgAV7tY1hW+Ls9kY5o4ICENhlyL dI3kE/r1xEe6ja/RvBxJMj4JLkMFkypL5apWoDpx/cs57lolMHyOb4zjpqI1R49eglET Zp9Q== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=4guIB9WBX/ay757xxYogFh0D5rQcKO1Qw1OmBzJA6xE=; b=fLo5dam2iQDOlryqlWq/2frFR/Y3WSC4zjAjXxUslD2ZTKT8qH+XfUiZPlu0GldpMt WgKJ5fWdO5KuHqTpeNGnJIZIOLseKMpwdfE6yyy3mg3AOyeYFdKpwaEvJ3bNOI4SRraO Xm7OOQtcsZ863Vcd9t3IYJn8aCBHYChdsrNq//SrVDGXqCe68GDEXu7fSr5y9vkCWqr2 IAyshkK4Jib7PMlJM0WVzY0L4S71RpsswHPUZgqTLnD+By/qhWy+nNwJL67osSJpueM/ gn9Qx8+HvltVHvvuVBCPMqVzmW+Mq5T4wymOL5MBeuYIIZQ6GiZLU8HxUev6YWM8tpPJ 8XQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="yfKjKX/S"; 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=pass (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 jl7-20020ad45e87000000b004707a5335c1si7078608qvb.200.2022.06.28.00.22.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:22:01 -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=pass header.i=@linaro.org header.s=google header.b="yfKjKX/S"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:60190 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Xt-0000Wb-7w for patch@linaro.org; Tue, 28 Jun 2022 03:22:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44240) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jf-00022v-Te for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:14 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:35588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Je-0000XJ-Cd for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:11 -0400 Received: by mail-pf1-x42a.google.com with SMTP id x4so10975509pfq.2 for ; Mon, 27 Jun 2022 21:59:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4guIB9WBX/ay757xxYogFh0D5rQcKO1Qw1OmBzJA6xE=; b=yfKjKX/S2DdUpfHmMrARtImCXV/D7LCsXznW7ul5S6y1Gt4eO1MKURfhw4Gi7O/lu7 t/4Tv6qDMameV3Yc5mc8kUkaGHfMlalR0SnmFAirq9oz/kC2bCZxwa2WDSihyy/uCNDL U/pisHTm62ckyTM11VdRwocXUa7xYbGhOiKj+UPLeWm1cTteSoV4He+DmlUKbJumP6jw ydEMwYfY9u45LjYqv8ZwiX0ZbhiApbJKatVwevv+0e1luvKAKXKEwRluLeTh4/6pQtEy oOaB9ZJ866ZsCsDpJN7L75v3HOwE6KQhzq4FuP5NKkThrpdqiiNdydTRFGdRTV9LbSLn VOxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=4guIB9WBX/ay757xxYogFh0D5rQcKO1Qw1OmBzJA6xE=; b=Pt0yPb95pOq/cp/xq1kwe3illHrxRyXClASfVkSbD/l1nlg20O/446mtKHHEPq3Agc V40lVrRNZ773pevR68peS4YQhOEBH5sYujKeMZFptzXFqUab+KXClNcdolsAgAWQhe8N 3CsMgOv7SYLLHUdeBBpCHcDNeAsYCVAl0xPoH4S+5aH4zmg8FLLh4WZDDjHxPQkyFoGU AyXwn6MSGdMi/5usQfST+FKMo2frGPS9V2FgDbCzZb26o7CHrAtnxz/rk+cZchUh1vKa xCJyvmlZmDudNphPr2iGehxmiILJWfWCIdHBCwuF/4PM9twXdQP/ecVUa1CpUcSuCPA5 o3aA== X-Gm-Message-State: AJIora8x0rgRLpw4cOVyxZe4cyMtHiL4ff+afPykVxDbUmfqxnyf2jFE v7XCB2ZR7dYTJfZNvCoSAiAQYdzEGzPQaQ== X-Received: by 2002:a05:6a00:2402:b0:4e1:46ca:68bd with SMTP id z2-20020a056a00240200b004e146ca68bdmr2767516pfh.70.1656392349181; Mon, 27 Jun 2022 21:59:09 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 48/60] semihosting: Use console_in_gf for SYS_READC Date: Tue, 28 Jun 2022 10:23:51 +0530 Message-Id: <20220628045403.508716-49-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 27 ++++++++++++++++++--------- 1 file changed, 18 insertions(+), 9 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index fdb143ace8..9d4d6d2812 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -302,6 +302,22 @@ common_semi_flen_fstat_cb(CPUState *cs, uint64_t ret, int err) common_semi_cb(cs, ret, err); } +static void +common_semi_readc_cb(CPUState *cs, uint64_t ret, int err) +{ + if (!err) { + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + uint8_t ch; + + if (get_user_u8(ch, common_semi_stack_bottom(cs) - 1)) { + ret = -1, err = EFAULT; + } else { + ret = ch; + } + } + common_semi_cb(cs, ret, err); +} + #define SHFB_MAGIC_0 0x53 #define SHFB_MAGIC_1 0x48 #define SHFB_MAGIC_2 0x46 @@ -428,15 +444,8 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_READC: - { - uint8_t ch; - int ret = qemu_semihosting_console_read(cs, &ch, 1); - if (ret == 1) { - common_semi_cb(cs, ch, 0); - } else { - common_semi_cb(cs, -1, EIO); - } - } + semihost_sys_read_gf(cs, common_semi_readc_cb, &console_in_gf, + common_semi_stack_bottom(cs) - 1, 1); break; case TARGET_SYS_ISERROR: From patchwork Tue Jun 28 04:53:52 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585559 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp544399mab; Tue, 28 Jun 2022 01:23:35 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tAOksgOtcftD0U88JtkFr/Pl1M8LqjHX8x6SbfBmoru/Z4/RTzUx8HgJnomXVRphTClfbF X-Received: by 2002:a05:6214:5085:b0:470:5bed:5bfc with SMTP id kk5-20020a056214508500b004705bed5bfcmr2628267qvb.54.1656404615174; Tue, 28 Jun 2022 01:23:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404615; cv=none; d=google.com; s=arc-20160816; b=G0lsDXmwbMOe1jiSv3BXSqs4MHhn6FXNzXDiiyHvk8DssOdHLIHlJdNiFexEIiAOYS E8w1RXebwFDkz6+wqFz6vhZSP9F52ae2YXOCjbsFc93wkxz5K/8q0WAFX0Z4YAT5vCqw DiL1/nv75gb5K1XemPQtuRLoG1UZ9THt5vATMZbZB9QpsrAr7xjG7etgCh6q09Ge9zAN 0HeERzfi/QArjwmISTfC9fZma16qm1NcKV6Fb7WjZ+PubYH/NodnyMzmOYJZzrcuH90G 13I3XhBv2WTyZEL+tmB9WmREhL6mIMqpJ6PhT94FajwNbLvficRC3AT6b+5JeJNqfSeE UKww== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=wM0GjsxkSw3jZSEeWPTbzsq2rsJJyzwSV/fI9isMOSA=; b=Iqzj9wObgHSS0bNKCvoUk4PaGbwebIm391Hz8yaYSwgsbHM5TmyHrV7RXImMfFlGwI /4CrMV4V+CQWy0FnARev1W9+oi4oC9G7RFG48S5Y5TGJOtwSl/1RSZhOh58EIZ84yhYF Kc4ho2tk1l01tXbL1ScksjdDdko6ghQ3yTM3ompdi+FIXFoduoz+D6rdangINagnrxTT z8Ztkw+KypgznIBp7qkT8rPTLVe7uAEeMlKjNR3odDBfKlCRrhT29/3EN9ay0KPCuJLr LLtUDLbROxXQTyfhMlbobCSN4KUM8no/LYDswpMt0oqgjoQZ+kcD6498VHLPaJfsjeV8 DBuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Q6X4+tVD; 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=pass (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 b14-20020ac85bce000000b00319fe79f832si2584836qtb.573.2022.06.28.01.23.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:23:35 -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=pass header.i=@linaro.org header.s=google header.b=Q6X4+tVD; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46824 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66VS-0006Vr-P9 for patch@linaro.org; Tue, 28 Jun 2022 04:23:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jj-000240-7G for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:16 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:35591) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jh-0000Xd-OS for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:14 -0400 Received: by mail-pf1-x42d.google.com with SMTP id x4so10975568pfq.2 for ; Mon, 27 Jun 2022 21:59:12 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=wM0GjsxkSw3jZSEeWPTbzsq2rsJJyzwSV/fI9isMOSA=; b=Q6X4+tVDZu542rRxiyXP/DmQEVgL3f8z2r9ZH6MiYFpjWSekZlA2qceoD9aO5bnvHw hmuXuvuQXFmOKnKZG7ExJt8SRLaqZcafVVvUmo/KHHoTZ4OEpSVuHTI5Z0wEh00hDe4b bybj/S158j3hKzIrrbjbt6TvEvoDXxJoe1j8cDTueJL2z1TsygxNglbJE19DH5zjL29R LFotj4Pa9DSvck+YheZWBh0BZLFDek+sLKebpN+1BHwv0pF5AZbqe2fWPYMpxFR0BdhC CjGJaWS+5sWxCiMx/awPAk4eiGGEqGe6QVqlRtq7MpUp2XTI0sPKc++9NZT89PBCy1IB gXQg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=wM0GjsxkSw3jZSEeWPTbzsq2rsJJyzwSV/fI9isMOSA=; b=SRaB7s7BBLebzZV31cfsMJY2kUZvBUlX57DEaZFC0AG5NXcshR2zPb/mgSXdVY4J+J 0a6HUyMtzitE/9slgUTgaWEJIXHlt/DeK1PuNWKr0UM3VIWCFciZvHhbZL5DSkkWNiCO pZt/h1PFy4/c8PhB7JHtcyen0P5bq2eTmrsq7y5qsKtlGHh44xiX6RbKCnoYpBSukqnL bUZbJ5SNFOgBWKbg+ONH4qTq4drouK/IRoW/7E80V6yEbYyebIubIfY/Wnk2/jKQlpBQ zWrysqlorua738/O+aT7GtnadXFzHbvO82NnOKZZP9r3lFP3PK7dtYCmws2KbdSIsh2e 4PDw== X-Gm-Message-State: AJIora+DAbEhOo5NWH63JmbEay0tXpJ9XPjfAexarnkdBYQmsXwaaXlw Piy6fyjxV0xPvvhnoLpk606KP3t+JPtiXA== X-Received: by 2002:a05:6a00:889:b0:510:91e6:6463 with SMTP id q9-20020a056a00088900b0051091e66463mr1708175pfj.58.1656392351360; Mon, 27 Jun 2022 21:59:11 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 49/60] semihosting: Use console_out_gf for SYS_WRITEC Date: Tue, 28 Jun 2022 10:23:52 +0530 Message-Id: <20220628045403.508716-50-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42d; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 9d4d6d2812..d61b773f98 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -228,6 +228,15 @@ static void common_semi_cb(CPUState *cs, uint64_t ret, int err) common_semi_set_ret(cs, ret); } +/* + * Use 0xdeadbeef as the return value when there isn't a defined + * return value for the call. + */ +static void common_semi_dead_cb(CPUState *cs, uint64_t ret, int err) +{ + common_semi_set_ret(cs, 0xdeadbeef); +} + /* * SYS_READ and SYS_WRITE always return the number of bytes not read/written. * There is no error condition, other than returning the original length. @@ -341,8 +350,7 @@ static const uint8_t featurefile_data[] = { * The specification always says that the "return register" either * returns a specific value or is corrupted, so we don't need to * report to our caller whether we are returning a value or trying to - * leave the register unchanged. We use 0xdeadbeef as the return value - * when there isn't a defined return value for the call. + * leave the register unchanged. */ void do_common_semihosting(CPUState *cs) { @@ -420,8 +428,12 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITEC: - qemu_semihosting_console_outc(env, args); - common_semi_set_ret(cs, 0xdeadbeef); + /* + * FIXME: the byte to be written is in a target_ulong slot, + * which means this is wrong for a big-endian guest. + */ + semihost_sys_write_gf(cs, common_semi_dead_cb, + &console_out_gf, args, 1); break; case TARGET_SYS_WRITE0: From patchwork Tue Jun 28 04:53:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585560 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp546189mab; Tue, 28 Jun 2022 01:26:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vt1UsrA27Xj8JvMXemp9SM0ZH299w5f9hkBXuLTaFKYbHuM0SEAA+VJgRAE6Rd7PrivO0B X-Received: by 2002:a05:6214:cab:b0:470:2e0e:476c with SMTP id s11-20020a0562140cab00b004702e0e476cmr2591394qvs.92.1656404817586; Tue, 28 Jun 2022 01:26:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656404817; cv=none; d=google.com; s=arc-20160816; b=MFeuRoq7hiaiYeWeAd1g+LaGm3zP6wpYEEiK5PrvDXJ9PJiwRONdpF5Tm2Ho+0QAQW ECwlxzaSTbZhl/hDvmm1MBU3gTOMLKTn+fQB+BL2mqIG0GZDagsJxzs5uGl8wV6oVVwg k2m0Oqhb80ZwZZA7ltQo6KIrlW2KRarmfhKqA3joUyG9mdFicyPvFqZ3Dueh/7o1XCEF T1yDjXLuCNArSj5nq1lhNoMeecfE2AgvWi3j5+JEer6T+K9fdIshEU7KGzXJ6SD2fmCy CyRiyNRdX1v1Ti8LJNbB2pJkHNOXW0UJHKgv/wBIGM3TNcSLBaXVp2aGoAdUfZwOUzFB XYfw== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=S34t29VeZyFZjhq+3Izzb9WFwxolWUsOd1jqso6L3og=; b=vp4g9Ous+x7iKICELEpF+0h8g2bvvh8+5vQRuYdhyo6XNdslKgiU5v+ZEblEJZ3MDu q1+Iai4WKS6RyUk2vS4jIgngEPULZRwEmk4AyeJlk9Yr3nXUFIv+g0NkexOEndF/JTkt Wr7Gj7YymRHzp0pMw2Saqlo56uU6twMT8Mu8GuJMMVJ0dsC5yuwjGbeBgddgeTG6Az76 uZG+wccSIdk3PEX8S496Yis5FbhEuEd/Bt0GrVlR1METBRVaMaWRq4nUnUqJqovcr766 OZGbqcmBWvMVkTwwGL576awKOC3LcBtw2x4oa0ARHdHpSnyRn5m1GegziCgHx4Cgw0v/ DDnA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=uGh6j6f3; 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=pass (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 b76-20020ae9eb4f000000b006a02c12bfb0si6894499qkg.588.2022.06.28.01.26.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:26: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=pass header.i=@linaro.org header.s=google header.b=uGh6j6f3; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:55054 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66Yj-0003iL-3W for patch@linaro.org; Tue, 28 Jun 2022 04:26:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jk-000247-HG for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:16 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:41712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Ji-0000Xh-UM for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:16 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 23so11066822pgc.8 for ; Mon, 27 Jun 2022 21:59:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=S34t29VeZyFZjhq+3Izzb9WFwxolWUsOd1jqso6L3og=; b=uGh6j6f3BuXBXVpVaLU/i3ugslAm00P6tGr4mj2JI33hh+YZXUIcyA0wnSmfWUgbHT 9xeLjd53PjDNJOAcevnWJpHjozNDsnJ+o/IHYwGqK4SHjr3tlr04FlsitnKdqjuWAFOw lI/SfFEp861V3t4nJHSuZyKSwrH0pAExwFZV/mins8brBcxH9ngkvgnKTuRgHKzCtVa6 vjh0obrrlyUKwfATUodl9J/3ZcdzI72k6thgOOwpVrF0VTpvtfz8r5Sw4LVL/Nb7wHOo zcpYtx4tM/m8kVsJTpT8CTGTDwz2Ljc7WOMEP4VBuhP1fVDRMob1brDNZKU6a5WktRE7 ZYFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=S34t29VeZyFZjhq+3Izzb9WFwxolWUsOd1jqso6L3og=; b=IFmuFK/s7eaqOYU+Wl0mFy8T9W1ulPuNFQXXMMGDZ0S9MrqBUTWZZOZo1xZErr4/10 NAR8TXJnmGi1q2kVEuaxbYgh1AgKRKvQAmZmw+EExRq/0oBQiVWijRR7pzjt+ioaZi4g 06AyVqRojw3LsVk74z9OkfDiRsy6/uY464cM24L8Acn0mG/yTO0XW69bUl49eHxmnaUv nV84rMuFTHcN1Xisd3cNbW9x0wCefm25y8haYvfervwJbOdzdBupwvUh6XqqYFdYuPIQ KKGhWSJ1NoKUjPan4kmRqM6hUCaldjd/nK7sSg6dqXivgA884NY+hUHeVptl/JRHC/Ox MWeg== X-Gm-Message-State: AJIora8DHFilUvJNXOphPx+zf7cUhRaltF+kDyhsHZK/4ibqjtlqxwPR YgeKmEAZ0bhO0F5CkQOt7W1ZIG1tFncTtw== X-Received: by 2002:a63:7a5e:0:b0:40c:f760:2f18 with SMTP id j30-20020a637a5e000000b0040cf7602f18mr16094000pgn.456.1656392353530; Mon, 27 Jun 2022 21:59:13 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 50/60] semihosting: Remove qemu_semihosting_console_outc Date: Tue, 28 Jun 2022 10:23:53 +0530 Message-Id: <20220628045403.508716-51-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::52a; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This function has been replaced by *_write. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/console.h | 13 ------------- linux-user/semihost.c | 16 ---------------- semihosting/console.c | 18 ------------------ 3 files changed, 47 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 6994f23c82..d6c1cc58ab 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -24,19 +24,6 @@ */ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); -/** - * qemu_semihosting_console_outc: - * @env: CPUArchState - * @s: host address of null terminated guest string - * - * Send single character from guest memory to the debug console. This - * may be the remote gdb session if a softmmu guest is currently being - * debugged. - * - * Returns: nothing - */ -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong c); - /** * qemu_semihosting_console_read: * @cs: CPUState diff --git a/linux-user/semihost.c b/linux-user/semihost.c index 871edf993a..f8bc8889f3 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -33,22 +33,6 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) return len; } -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) -{ - char c; - - if (get_user_u8(c, addr)) { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - } else { - if (write(STDERR_FILENO, &c, 1) != 1) { - qemu_log_mask(LOG_UNIMP, "%s: unexpected write to stdout failure", - __func__); - } - } -} - /* * For linux-user we can safely block. However as we want to return as * soon as a character is read we need to tweak the termio to disable diff --git a/semihosting/console.c b/semihosting/console.c index 955880514e..fe7ee85137 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -96,24 +96,6 @@ int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) return out; } -void qemu_semihosting_console_outc(CPUArchState *env, target_ulong addr) -{ - CPUState *cpu = env_cpu(env); - uint8_t c; - - if (cpu_memory_rw_debug(cpu, addr, &c, 1, 0) == 0) { - if (use_gdb_syscalls()) { - gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, 1); - } else { - qemu_semihosting_log_out((const char *) &c, 1); - } - } else { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - } -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Tue Jun 28 04:53:54 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585525 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp480410mab; Mon, 27 Jun 2022 23:40:57 -0700 (PDT) X-Google-Smtp-Source: AGRyM1sZAuNGMyC/Y0zlrGwQLx9/7OoOcGOEDdPCXfCsWGQzM8VfcvnKU4iQbW7SrkjRdSidqqg1 X-Received: by 2002:a05:6214:811:b0:470:3b84:ea47 with SMTP id df17-20020a056214081100b004703b84ea47mr1319755qvb.59.1656398457106; Mon, 27 Jun 2022 23:40:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398457; cv=none; d=google.com; s=arc-20160816; b=atfK14vZMecvm20aubEDerjE074priuIy4y+X9U4DvD2jcPTkONqRky+83/VMZO0XI qcd3Y7CoINjoKnOe5m5KCLz8ZOpdXZvOMUdC5HcIMgoZtTFZAX1lo/FW/adz82oK33DI LEq4M8X+O5k1GBxRc3Fpk91dWERmwk+8bVqdmcIRwcIVC3//jJ9EHPFhwr9KO5KWNCPC Z4UURzQNmYxy0MP1tcHhl4xY4TecDydLh2NI/iHjCVo5CFI5rsurWePRf0g63aN94AIq m2Ye+2WCwoJZbp1/4/zUgknpeP1cWx1Bhh+86gd8vKVEP4K37qKrhmdJvK91THmeIzpq UaQQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=JTrVkXiF8A1/K/SnVM2m98TUbaMDWvrW5Gsdia3GE5w=; b=vekAJQk+3Hu4OHyXzwDcNjaN+HyQBIlkLeJAfSuSm5lFfk944gnkawNnrBsnxgnH/6 nKzWMGtKER81udMaHdHoIrhoQVFo83tDHfL5EZWEL98aAN65X5kM5vmsr9l0UuzJtb1D 8eT7KWut4qWgQpsB5EDxReKKkfkLxslTEtkKzEdgWJC8+rF7EsPiTChTbUvkU1MYXg5s UIuPGuABEv0aNbYtc5GZrWC6Prl0nQPzL8dBbqpP6qXozl2xUi++b4hQYf0L2fBJfguW UrJbNC+0igKSRQEbIx34xUjNVHN/don4XnzCkyaEPvwj/0IzpVB9iGi546TMj/mC00x2 xv5w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=zpL9D2ZT; 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=pass (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 13-20020a0562140dcd00b0044643570037si6764806qvt.502.2022.06.27.23.40.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:40: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=pass header.i=@linaro.org header.s=google header.b=zpL9D2ZT; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38340 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64u8-0005Wc-BJ for patch@linaro.org; Tue, 28 Jun 2022 02:40:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44294) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jm-00026G-Ca for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:21 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:34542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jk-0000Y5-VU for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:18 -0400 Received: by mail-pg1-x532.google.com with SMTP id g4so4176140pgc.1 for ; Mon, 27 Jun 2022 21:59:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=JTrVkXiF8A1/K/SnVM2m98TUbaMDWvrW5Gsdia3GE5w=; b=zpL9D2ZTPgE6bxTr0m803jXyixiJXkm7MyexsxIyPg1oD9xA9xAbVyYX4AqKxQxk/3 idWo21HUrtLESE9WrxfB3thd2x+5+9NERN76/EZ34SiMEz1mZt+I3UE7btDsq49ROUpO RH6FLMl2B672GQWZDnU0J8RtWcqFmO1YaBwpMa9Bcis9UNxIhurCxBw3fh8ZANGL5hXg VPE312FwYw0t2uIpp/Z5a8oXAXWw0wXeLP+SEbkouuTIhUf9064DBOK8sPXwx3OQJdFC LII37v5cdmkC+IJ1UBiut/QldA3h26Qbhz1QserfhSJ7qups8w+y4Cu1LH2HwgbDjnTo roIw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=JTrVkXiF8A1/K/SnVM2m98TUbaMDWvrW5Gsdia3GE5w=; b=svSYDLbFOI6MfCyJThf7XnM/O00DLO+mg7+qgHZPcZdhku02FC/Wm8TnnJ5rYnV3Ih EA6dFqE2GjIporTJvoerfdENTNQytgp5dlEhcGojrsq3Odfmr2UzJMdiZ5NxouxWnlWq yOe5WYEuWgtIvIVRZSQNl8l60LkNhfk2q7lI+Dr8EPm8SSKLiE8kzbBskAb9IGs6Y/b7 Ko/X3ldPDzLHnEFAK9T9SXenay9/Og92T+MhNt/LCArqLFxvTWn0i3pxq3G4JCY6UIh7 XmSfhzP0RdBjP38DF4KaYAMByqaIxRFICA2LkzpEuGwp3zj6yfJtoRAtwMvFIrOeTYVl W68A== X-Gm-Message-State: AJIora8R/oETL3JA7XK1VZ9sAOJPLCUTzdbXmqFY661dwRHqADbpeZCu IXRZzep534oqvIKSpKLUkFsUa+7xg9Z8Jw== X-Received: by 2002:a05:6a00:c91:b0:525:8c3f:269 with SMTP id a17-20020a056a000c9100b005258c3f0269mr2830253pfv.66.1656392355521; Mon, 27 Jun 2022 21:59:15 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 51/60] semihosting: Use console_out_gf for SYS_WRITE0 Date: Tue, 28 Jun 2022 10:23:54 +0530 Message-Id: <20220628045403.508716-52-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::532; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x532.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index d61b773f98..1a1e2a6960 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -437,8 +437,15 @@ void do_common_semihosting(CPUState *cs) break; case TARGET_SYS_WRITE0: - ret = qemu_semihosting_console_outs(env, args); - common_semi_set_ret(cs, ret); + { + ssize_t len = target_strlen(args); + if (len < 0) { + common_semi_dead_cb(cs, -1, EFAULT); + } else { + semihost_sys_write_gf(cs, common_semi_dead_cb, + &console_out_gf, args, len); + } + } break; case TARGET_SYS_WRITE: From patchwork Tue Jun 28 04:53:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585535 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp493328mab; Tue, 28 Jun 2022 00:02:38 -0700 (PDT) X-Google-Smtp-Source: AGRyM1syZIL4yQmN9o7UYvraMMj/Rl5Mng1lSN5h9AN/neDG5nZv3Wq0FcUVsP4gBb6Iek5+5rnI X-Received: by 2002:ad4:5ceb:0:b0:470:54e3:92a4 with SMTP id iv11-20020ad45ceb000000b0047054e392a4mr2509458qvb.22.1656399758754; Tue, 28 Jun 2022 00:02:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399758; cv=none; d=google.com; s=arc-20160816; b=luUB6oAnDCfLlv79Tx+/PvJMA8MaijTxAVLgFRMGd2AW0h1v2IaOZyYm8mQYlOQEuz JBdNTFVOWxOoEApw3jJLULwxxdx9SRfg+IDh0PiZr5b1nFgRrrUF9XK1E0ts91xHQls+ USO0gvnLnWqBs+ziRuqlrugd1JZ+rwTXCt7t1Ts7kTvO4DMP+NoKuekTFV7xzcAWQKoe xefu8Xu7RKjvPCqkvXrXFr3ZCAeLg3aNrmnFyLI/QNzM6IwHxWEEDMm+o1rIIAiPP2p0 BrXzdO7p6eNTdpd/I+L+ItG1gdbzS2TttUVVYLDXDxnMDbxNGqdz8QOgOXOXTFzIF7Ml 99KQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=VcbXRuc9p7xnMmio/gUl33BwOOt/KNGf1EdU6Sq8hhs=; b=CywPuhqpqfmZIeItSi5ttkR1v8RVjG8L/ignS27F7uekStce9pzs2A30TkeVziPqo2 8DLXXgmTyATcEpDruDByA3QzMKicmzE18BjU3E6u6tDqwheVmbEf52erRiVpBAH8P162 LyJnHuBZDd0jPf90z2UwnFD1DVKXY5GQmARCwN20PwtVFI2H4l8il1BJGoFtak/e4jub nyhRnd8ZpyqUfjxNJzoTaddiWf8x8x64NWCKBR4znbwnySx2LRZZ5Z/JzgHTMJB2HOuy IqWGSuF4am98oB0pQ2FY1CFSm8vbb4yX11bowj/kvWZw3whwge0Np5kFOSp8jXn6dHfE P82g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tu2q1Hku; 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=pass (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 iy4-20020a0562140f6400b004704d654be1si7106118qvb.168.2022.06.28.00.02.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:02:38 -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=pass header.i=@linaro.org header.s=google header.b=tu2q1Hku; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:38048 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65F8-00012j-AJ for patch@linaro.org; Tue, 28 Jun 2022 03:02:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44310) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jo-00026L-K0 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:21 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:43974) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jn-0000YT-4r for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:20 -0400 Received: by mail-pj1-x1032.google.com with SMTP id dw10-20020a17090b094a00b001ed00a16eb4so11495395pjb.2 for ; Mon, 27 Jun 2022 21:59:18 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VcbXRuc9p7xnMmio/gUl33BwOOt/KNGf1EdU6Sq8hhs=; b=tu2q1HkuuHDYgTQOZcvytJU41cHMM57GoxsK69uZnVRqC0gSeUqkFa7QyWOvgSahjW aF0sgBoY/fzOnspifTdR4JrcJ3BF0hISXVk4qlg3Vr1E51iviWVBc6IGRmOBDqdQhXC0 wNc7FSDWgn324lDlazRqF+2/r67hrE6rp3y5+l1WJ6j25EeXykLmQRmPmKuCo3ttYNDK 3BuPw3hWsuaVmTdt1MYNXyLJ51IVfqf6xLZSJkFuEPCqDsvzdCOhU32KrYdo7CrhbfpO 2sxSlvsXUqTXj5IxFLnZVw2d6Wvb2BUJc3s6JwV0wq9qjwvxzuObYcd4u3YosjDp9nxM FYvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VcbXRuc9p7xnMmio/gUl33BwOOt/KNGf1EdU6Sq8hhs=; b=hVw9gMBewVMcfVWmbTm7EqqoQyQTA2plqlN3y0WkzWf7LdhrmisyIDrR+kiUjbUQcy 26oUSg7cDUGpQlRggpi5UTAjOGa4ILn1shCpr3v4cWJo8eLlaAqWMu1VANNrS6Yw13Q2 iU5QGkkgug5PvlosAaemPQ9FOLxYj1iKubrR54TXQAHSSVFs5sIZGfdWokY8KBstzd2k ku1wlcbaRpkcy+HsBT8klAckHvFKWcrV6ZsYidpZ7nPnqMeZ+ooR3XkxfiiOpl44ldhE zv3cIt539SC5v8Cnt8xkJUDKVE82EZ7dw8LbU16cd/YOji++SZNn5dnJtStnR54bGicA APrg== X-Gm-Message-State: AJIora8mw38naDFw3nUWArRBRgWkZn6O4E7+khLbm+8OTxsefEeuBHoy J+XZKTyknlhS3PGGK45Mnd6kQrsPKH9xFw== X-Received: by 2002:a17:90a:5b0d:b0:1ea:d1ed:186e with SMTP id o13-20020a17090a5b0d00b001ead1ed186emr19525459pji.240.1656392357910; Mon, 27 Jun 2022 21:59:17 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel , =?utf-8?q?Alex_Benn=C3=A9e?= Subject: [PULL 52/60] semihosting: Remove qemu_semihosting_console_outs Date: Tue, 28 Jun 2022 10:23:55 +0530 Message-Id: <20220628045403.508716-53-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1032; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1032.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This function has been replaced by *_write. Reviewed-by: Luc Michel Reviewed-by: Alex Bennée Signed-off-by: Richard Henderson --- include/semihosting/console.h | 13 ---------- linux-user/semihost.c | 17 ------------ semihosting/console.c | 49 ----------------------------------- 3 files changed, 79 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index d6c1cc58ab..20c31d89d4 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -11,19 +11,6 @@ #include "cpu.h" -/** - * qemu_semihosting_console_outs: - * @env: CPUArchState - * @s: host address of null terminated guest string - * - * Send a null terminated guest string to the debug console. This may - * be the remote gdb session if a softmmu guest is currently being - * debugged. - * - * Returns: number of bytes written. - */ -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong s); - /** * qemu_semihosting_console_read: * @cs: CPUState diff --git a/linux-user/semihost.c b/linux-user/semihost.c index f8bc8889f3..cee62a365c 100644 --- a/linux-user/semihost.c +++ b/linux-user/semihost.c @@ -16,23 +16,6 @@ #include "user-internals.h" #include -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) -{ - int len = target_strlen(addr); - void *s; - if (len < 0){ - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - return 0; - } - s = lock_user(VERIFY_READ, addr, (long)(len + 1), 1); - g_assert(s); /* target_strlen has already verified this will work */ - len = write(STDERR_FILENO, s, len); - unlock_user(s, addr, 0); - return len; -} - /* * For linux-user we can safely block. However as we want to return as * soon as a character is read we need to tweak the termio to disable diff --git a/semihosting/console.c b/semihosting/console.c index fe7ee85137..c84ab97ab6 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -47,55 +47,6 @@ int qemu_semihosting_log_out(const char *s, int len) } } -/* - * A re-implementation of lock_user_string that we can use locally - * instead of relying on softmmu-semi. Hopefully we can deprecate that - * in time. Copy string until we find a 0 or address error. - */ -static GString *copy_user_string(CPUArchState *env, target_ulong addr) -{ - CPUState *cpu = env_cpu(env); - GString *s = g_string_sized_new(128); - uint8_t c; - - do { - if (cpu_memory_rw_debug(cpu, addr++, &c, 1, 0) == 0) { - if (c) { - s = g_string_append_c(s, c); - } - } else { - qemu_log_mask(LOG_GUEST_ERROR, - "%s: passed inaccessible address " TARGET_FMT_lx, - __func__, addr); - break; - } - } while (c!=0); - - return s; -} - -static void semihosting_cb(CPUState *cs, uint64_t ret, int err) -{ - if (err) { - qemu_log("%s: gdb console output failed (%d)\n", __func__, err); - } -} - -int qemu_semihosting_console_outs(CPUArchState *env, target_ulong addr) -{ - GString *s = copy_user_string(env, addr); - int out = s->len; - - if (use_gdb_syscalls()) { - gdb_do_syscall(semihosting_cb, "write,2,%x,%x", addr, s->len); - } else { - out = qemu_semihosting_log_out(s->str, s->len); - } - - g_string_free(s, true); - return out; -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Tue Jun 28 04:53:56 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585528 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp483344mab; Mon, 27 Jun 2022 23:46:34 -0700 (PDT) X-Google-Smtp-Source: AGRyM1u5DTwavbudMyVz9848GyLQZ8bjqDcVQQdccJiVAqWnvme4yA2vSWPuCOd7DI80qkUrIYJy X-Received: by 2002:ad4:5c65:0:b0:470:b1fc:4f3f with SMTP id i5-20020ad45c65000000b00470b1fc4f3fmr1168471qvh.102.1656398794116; Mon, 27 Jun 2022 23:46:34 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656398794; cv=none; d=google.com; s=arc-20160816; b=PQiGGSnWPfRsj9lM/7OxyejWqYDwoaQhSIHO3vjTWD/B5ijGDxR9ZyYl6UEUJVyK9m bqTOhoDIjKvnfZt2Zz1IW3cYlYxdERTzJDiEk2EN9uJtE+zSUuM0mBas2c1zuKzlK/00 TQeWl/SQL4slZwnNfnVjLdOjF0BRTQvzqPGnhcz1tnu0nrp4imm5dG3+ugYwJse5b2EP IxRZzzAjSu5Mv8HSsAmV4vTk8WQLGWZDLDNfNZCJRQTnCLvXWdc4Nqx3bgJGs38STBRR xceiOGHNPv8l9NFdXN/PAy+9XUNFwWmUXKELNFZW7BHRV1zWqXFsJv/NmXSDUiw7Y+Gv WQSg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=7STZk4xzNs8UP6IZ1WVHwgF6+pwm+siOFOx+ShINrpY=; b=gqcPJ55oI2pENzaBoJ8n/jPz2ke668J6BmqBuNmwh6h0OberOTalZ7OxWCp6RvqhRG 60WFecUjCibbUUSRxDfsHz3p/pwgsaIGnWjgFfiVCgpZOOXDTdRtU3fIpGCzuUorCU9C Ru+vmCYgQbmUqU2guFRh7tDw7DAkhAOfXlS2rotOY4ak/9sdxXWHTX3aLdQTwYChQVmT 7vxSWi5MttN7fZqxY4ehiRYr7OZeagLl+PxjQ9/yrs3n+4GWDOY+Am9E+nHAyC3YkQ/D z79g27OkmFqJcF7WZLlFG4boW6Lx8SiKjriZ3OTl2iyCrYi069/KVvJn00oxVofgxlfI VCNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="fRy/CuQa"; 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=pass (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 h20-20020ac87d54000000b0030506ff8312si6760928qtb.81.2022.06.27.23.46.34 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:46:34 -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=pass header.i=@linaro.org header.s=google header.b="fRy/CuQa"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:46630 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o64zZ-0003B7-HX for patch@linaro.org; Tue, 28 Jun 2022 02:46:33 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44326) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jr-0002Ac-3Q for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:23 -0400 Received: from mail-pl1-x62d.google.com ([2607:f8b0:4864:20::62d]:40844) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jp-0000Zg-C5 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:22 -0400 Received: by mail-pl1-x62d.google.com with SMTP id b2so3033998plx.7 for ; Mon, 27 Jun 2022 21:59:20 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7STZk4xzNs8UP6IZ1WVHwgF6+pwm+siOFOx+ShINrpY=; b=fRy/CuQaHoVykurF9UlrI81YDlzfjJLyDIAP0NpqUTujTOPbl5ThJywsAqT6+OoTWQ RpNjIGVZ2bVkr2pZ5rWJKrTl+VdVA3qQyvHmB6Ws1dn46caaYjR3bjVfKFFlcoedakKM UBkO6GQIP6YpznfCdTN8sybJCSAvJMozrcharRNXOynEJac3mQhxYC2CUh9UquVO2OfX nYz63udT9ZX1LQtcEQBkmQCoLeiZIY/LWk71vls4jpMRBfwJJ0PSGUJV1LlaJ+B80lnY X+pGE60lSqIuc6Lp3dQfwJbOuRnp0FAQs4LPg91m2BiGPe5/q+TsQabtGlwiTTCW+8Ty T7jQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7STZk4xzNs8UP6IZ1WVHwgF6+pwm+siOFOx+ShINrpY=; b=yix4p+TDWqFVVUNmvXXp1xFbJM2uQBevKeRx3sOccRkDTuO03VWc50m4nETmmibObp 0vFSxYcadlzVDbN3bo7ZfTuJGaonOI8MTvWnds+kH128w1njaBf6JlP7P+DWnNKl38y2 iD0XZDtLmdSoU87zsnCDAlGY5Gr6228z2aPniGAcnBpmHecwx9ECSNQtiOSqSwbjqLGY vDOXfODq0Dtmn7/FN0xAPACXTJBd6EupqX9rD5jtlZAzKAeeWKRV0af3gbsG7nBJJP7o uhHSLzDT82WGXZjo+uqlOn79e83CuJc/6N+HPL1PQSwHgWjS1n4zrKDTAP7l66UJZ2Kj p0Jg== X-Gm-Message-State: AJIora/KMwXg2++aBXx8AkpCcjw2QK4tH2XH1rVKW+x/x+nAR+Sd6Isc gdYfJtjOKOTpbJrFFsQrN9NFzfj+l1ezcA== X-Received: by 2002:a17:90a:f314:b0:1ec:91a9:3256 with SMTP id ca20-20020a17090af31400b001ec91a93256mr20025348pjb.155.1656392360018; Mon, 27 Jun 2022 21:59:20 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Luc Michel Subject: [PULL 53/60] semihosting: Create semihost_sys_poll_one Date: Tue, 28 Jun 2022 10:23:56 +0530 Message-Id: <20220628045403.508716-54-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::62d; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62d.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" This will be used for implementing the xtensa select_one system call. Choose "poll" over "select" so that we can reuse Glib's g_poll constants and to avoid struct timeval. Reviewed-by: Luc Michel Signed-off-by: Richard Henderson --- include/semihosting/console.h | 16 ++++++++ include/semihosting/syscalls.h | 3 ++ semihosting/console.c | 19 ++++++++- semihosting/syscalls.c | 70 ++++++++++++++++++++++++++++++++++ 4 files changed, 106 insertions(+), 2 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 20c31d89d4..61b0cb3a94 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -53,4 +53,20 @@ int qemu_semihosting_console_write(void *buf, int len); */ int qemu_semihosting_log_out(const char *s, int len); +/* + * qemu_semihosting_console_block_until_ready: + * @cs: CPUState + * + * If no data is available we suspend the CPU and will re-execute the + * instruction when data is available. + */ +void qemu_semihosting_console_block_until_ready(CPUState *cs); + +/** + * qemu_semihosting_console_ready: + * + * Return true if characters are available for read; does not block. + */ +bool qemu_semihosting_console_ready(void); + #endif /* SEMIHOST_CONSOLE_H */ diff --git a/include/semihosting/syscalls.h b/include/semihosting/syscalls.h index 347200cb9f..3a5ec229eb 100644 --- a/include/semihosting/syscalls.h +++ b/include/semihosting/syscalls.h @@ -69,4 +69,7 @@ void semihost_sys_system(CPUState *cs, gdb_syscall_complete_cb complete, void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, target_ulong tv_addr, target_ulong tz_addr); +void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, GIOCondition cond, int timeout); + #endif /* SEMIHOSTING_SYSCALLS_H */ diff --git a/semihosting/console.c b/semihosting/console.c index c84ab97ab6..cda7cf1905 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -77,10 +77,17 @@ static void console_read(void *opaque, const uint8_t *buf, int size) c->sleeping_cpus = NULL; } -int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +bool qemu_semihosting_console_ready(void) +{ + SemihostingConsole *c = &console; + + g_assert(qemu_mutex_iothread_locked()); + return !fifo8_is_empty(&c->fifo); +} + +void qemu_semihosting_console_block_until_ready(CPUState *cs) { SemihostingConsole *c = &console; - int ret = 0; g_assert(qemu_mutex_iothread_locked()); @@ -92,6 +99,14 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) cpu_loop_exit(cs); /* never returns */ } +} + +int qemu_semihosting_console_read(CPUState *cs, void *buf, int len) +{ + SemihostingConsole *c = &console; + int ret = 0; + + qemu_semihosting_console_block_until_ready(cs); /* Read until buffer full or fifo exhausted. */ do { diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 9e499b1751..4847f66c02 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -520,6 +520,21 @@ static void host_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, unlock_user(p, tv_addr, sizeof(struct gdb_timeval)); } +#ifndef CONFIG_USER_ONLY +static void host_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, GIOCondition cond, int timeout) +{ + /* + * Since this is only used by xtensa in system mode, and stdio is + * handled through GuestFDConsole, and there are no semihosting + * system calls for sockets and the like, that means this descriptor + * must be a normal file. Normal files never block and are thus + * always ready. + */ + complete(cs, cond & (G_IO_IN | G_IO_OUT), 0); +} +#endif + /* * Static file semihosting syscall implementations. */ @@ -628,6 +643,34 @@ static void console_fstat(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret ? -1 : 0, ret ? -ret : 0); } +#ifndef CONFIG_USER_ONLY +static void console_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf, GIOCondition cond, int timeout) +{ + /* The semihosting console does not support urgent data or errors. */ + cond &= G_IO_IN | G_IO_OUT; + + /* + * Since qemu_semihosting_console_write never blocks, we can + * consider output always ready -- leave G_IO_OUT alone. + * All that remains is to conditionally signal input ready. + * Since output ready causes an immediate return, only block + * for G_IO_IN alone. + * + * TODO: Implement proper timeout. For now, only support + * indefinite wait or immediate poll. + */ + if (cond == G_IO_IN && timeout < 0) { + qemu_semihosting_console_block_until_ready(cs); + /* We returned -- input must be ready. */ + } else if ((cond & G_IO_IN) && !qemu_semihosting_console_ready()) { + cond &= ~G_IO_IN; + } + + complete(cs, cond, 0); +} +#endif + /* * Syscall entry points. */ @@ -906,3 +949,30 @@ void semihost_sys_gettimeofday(CPUState *cs, gdb_syscall_complete_cb complete, host_gettimeofday(cs, complete, tv_addr, tz_addr); } } + +#ifndef CONFIG_USER_ONLY +void semihost_sys_poll_one(CPUState *cs, gdb_syscall_complete_cb complete, + int fd, GIOCondition cond, int timeout) +{ + GuestFD *gf = get_guestfd(fd); + + if (!gf) { + complete(cs, G_IO_NVAL, 1); + return; + } + switch (gf->type) { + case GuestFDGDB: + complete(cs, G_IO_NVAL, 1); + break; + case GuestFDHost: + host_poll_one(cs, complete, gf, cond, timeout); + break; + case GuestFDConsole: + console_poll_one(cs, complete, gf, cond, timeout); + break; + case GuestFDStatic: + default: + g_assert_not_reached(); + } +} +#endif From patchwork Tue Jun 28 04:53:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585538 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp500668mab; Tue, 28 Jun 2022 00:14:12 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ttCcffPCxaTpZXTZ+PhcZfWWBpTcEqswOsRoDB8jZZGSSgDktCTkMSuqXHAYA0Fp7iSbqD X-Received: by 2002:ac8:5cd3:0:b0:316:f772:f0b8 with SMTP id s19-20020ac85cd3000000b00316f772f0b8mr12235561qta.162.1656400452693; Tue, 28 Jun 2022 00:14:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400452; cv=none; d=google.com; s=arc-20160816; b=eHcdSJQFLJXCtbn5AlsjoM2DulniwxvF0gJXDER6OGbZScCfqBsit8qNomOqFeNaMJ pOZubE6LPeaEQ0sEmAQiuexg2XXAtnYwhiXHXs2VyGJvN6QbkKH/v/03Cbkc47tABOVQ Qey572KFNU50FFIDVxzYUEYJXPgmocqw4Mka4OQ1Ou5O9iPjpo5FnCFOyftVqlDcsnjw 9Y7u1jDHXi95wU+Ky6QCfqMEk4I02+JjKutv9IJdccGPEjWwDeDLQP/a/ueJjdu2pu5r DE/bpTQ9gVx89AXUcd8JqPkCS3vLTFVnT5AXANcacoKx5HE/J4FT0BPHVWd6sCUY1g/E dyuA== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=p6Vm/V/7AHyeMphYYuV64Tllnf1xC7wkvKIiUvWLsiU=; b=gfQxFKCdPIxSIjIRK2pUgfewTYvlq/l4vtKxjVahceAUUg/qySAPr7GJ74fs8TXvbO pbn0mrTrwHeQE3fEgCoaN66OsF/zgyzZv4MeMppgWSpOrTXtYN4+G1gxhLiTTJ9+swNr LEFCaa+T4TUaKIluZMsp1QBPHgxntbu51n+QuO/dAF83hGkzLGYvUGNH6MuPgt8A0T6B EjsO2yyV/w60QYTvippMIAwG4ZdbvzInykHsyDTk6w361HKT6j2OZCC1h308gSFKKbNZ LpD6FFa9amwDM2rsYTXCeJ/86HdjSlIEfcDY+sulSPBwPrx7Uhcs789SxozG/Fgvqanh /JlA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=r9g+7DyZ; 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=pass (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 q14-20020a05621419ee00b00467d56ac2a7si6535961qvc.401.2022.06.28.00.14.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:14:12 -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=pass header.i=@linaro.org header.s=google header.b=r9g+7DyZ; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:50332 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65QH-00023C-1Z for patch@linaro.org; Tue, 28 Jun 2022 03:14:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44342) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jt-0002G1-AJ for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:25 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:46597) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jq-0000WI-V4 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:24 -0400 Received: by mail-pj1-x1033.google.com with SMTP id h9-20020a17090a648900b001ecb8596e43so11458083pjj.5 for ; Mon, 27 Jun 2022 21:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=p6Vm/V/7AHyeMphYYuV64Tllnf1xC7wkvKIiUvWLsiU=; b=r9g+7DyZlEnM489xOngVbdtCwnoggcctAVv/J8jg+bYXWMyd1X9wRO0Bsrxgm/kDBM eiELSPvosQv3Gl9b+hbdQCp89x0TIUkt2/GFyDp19Xd2Alq1yYCp5G+MBWTTt+khp3vM wULGllDb15zsnsoAIzKhtyOeBJs9KWo0YJNnf4Wpp9fDK/dSCaMw+z4wn6oJPmGDsfPE V4wVFHBQizcFikAz11iV5IGxz65m5RfOAsn8ajVjtuUg0BggDl1+trmcnHxECm5GlMN/ dWBDpHPGOqSIuh1wwqWhwA8uB6ncw/lzhw3TdU7Hv8FdgLyd0Q0wsQsShu6FtYMfsQhm P4Sg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=p6Vm/V/7AHyeMphYYuV64Tllnf1xC7wkvKIiUvWLsiU=; b=XnRjkD/lbj4J7BSz9ic9d3leZd7I/JL7KoX2Oltdux1vk9PKvmAb+mnXwun2Xjsfw7 3aw7m899R8mKX2gGshA+h4JcH6tZEpJaWOLo/V7mUndJM0J+alb+q6/+R31h4Ju0XO0Q ars7wEWokLqcd0vEf7t2nWET9ubUQd8CcRFpStJEnOsRubR6LpXUzZEJfYssX3asvUmg xsJT/6bP5tbICZZnjon3R8GZX4SH6M6LPsoNqlcgmWjp/1iV5Ep7SBXvWElIyBOXJWYT xh6wMF4kyNyUnhPRXbMYNwOOocZzY+r9Rgj9I1kKbfvdCKHzRAH0O2Z7Kllh8u9y5Rno PSDA== X-Gm-Message-State: AJIora86lbJ07dKjq+BS60FGbfI2SrZUjnVq5qxZbsQIHLu650aoLm7b n68iVDnatUBdJuJ8yGLTU+Xf38GoYf4AMA== X-Received: by 2002:a17:902:7282:b0:16b:7a53:3b41 with SMTP id d2-20020a170902728200b0016b7a533b41mr3028896pll.1.1656392362117; Mon, 27 Jun 2022 21:59:22 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 54/60] target/m68k: Eliminate m68k_semi_is_fseek Date: Tue, 28 Jun 2022 10:23:57 +0530 Message-Id: <20220628045403.508716-55-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1033; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1033.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reorg m68k_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 55 +++++++++++++++++------------------------ 1 file changed, 23 insertions(+), 32 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 8c186c0e9f..37b409b0b9 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -95,8 +95,11 @@ static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) unlock_user(p, addr, sizeof(struct gdb_stat)); } -static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) +static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret, args) || put_user_u32(err, args + 4)) { @@ -110,8 +113,11 @@ static void m68k_semi_return_u32(CPUM68KState *env, uint32_t ret, int err) } } -static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) +static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + M68kCPU *cpu = M68K_CPU(cs); + CPUM68KState *env = &cpu->env; + target_ulong args = env->dregs[1]; if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || @@ -122,21 +128,6 @@ static void m68k_semi_return_u64(CPUM68KState *env, uint64_t ret, int err) } } -static int m68k_semi_is_fseek; - -static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - M68kCPU *cpu = M68K_CPU(cs); - CPUM68KState *env = &cpu->env; - - if (m68k_semi_is_fseek) { - m68k_semi_return_u64(env, ret, err); - m68k_semi_is_fseek = 0; - } else { - m68k_semi_return_u32(env, ret, err); - } -} - /* * Read the input value from the argument block; fail the semihosting * call if the memory read fails. @@ -151,6 +142,7 @@ static void m68k_semi_cb(CPUState *cs, uint64_t ret, int err) void do_m68k_semihosting(CPUM68KState *env, int nr) { + CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; void *p; @@ -169,7 +161,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, + gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, arg2, arg3); return; } else { @@ -190,7 +182,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) int fd = arg0; if (fd > 2) { if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "close,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); return; } else { result = close(fd); @@ -206,7 +198,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "read,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", arg0, arg1, len); return; } else { @@ -226,7 +218,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "write,%x,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", arg0, arg1, len); return; } else { @@ -249,12 +241,11 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(3); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - m68k_semi_is_fseek = 1; - gdb_do_syscall(m68k_semi_cb, "fseek,%x,%lx,%x", + gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - m68k_semi_return_u64(env, off, errno); + m68k_semi_u64_cb(cs, off, errno); } return; } @@ -264,7 +255,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "rename,%s,%s", + gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", arg0, (int)arg1, arg2, (int)arg3); return; } else { @@ -284,7 +275,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "unlink,%s", + gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", arg0, (int)arg1); return; } else { @@ -303,7 +294,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(1); GET_ARG(2); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "stat,%s,%x", + gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", arg0, (int)arg1, arg2); return; } else { @@ -325,7 +316,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "fstat,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", arg0, arg1); return; } else { @@ -340,7 +331,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "gettimeofday,%x,%x", + gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", arg0, arg1); return; } else { @@ -361,7 +352,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) case HOSTED_ISATTY: GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "isatty,%x", arg0); + gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); return; } else { result = isatty(arg0); @@ -371,7 +362,7 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_cb, "system,%s", + gdb_do_syscall(m68k_semi_u32_cb, "system,%s", arg0, (int)arg1); return; } else { @@ -429,5 +420,5 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) result = 0; } failed: - m68k_semi_return_u32(env, result, errno); + m68k_semi_u32_cb(cs, result, errno); } From patchwork Tue Jun 28 04:53:58 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585561 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp549809mab; Tue, 28 Jun 2022 01:32:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vScSQgkefN/S5z8511gLs0I/hh28lug5BvZRbiYJiSb+92ptMFNv+rHVkLaUdCexylgO6P X-Received: by 2002:ae9:e114:0:b0:6af:244:8de3 with SMTP id g20-20020ae9e114000000b006af02448de3mr10647020qkm.236.1656405163876; Tue, 28 Jun 2022 01:32:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656405163; cv=none; d=google.com; s=arc-20160816; b=mGOBy1iTVgcz6TF4RGw4CdCdOJKWmg7AWIS3zCBetx1/LUx2/BuIez5c7sssCVxtkT iVOREfojfDBdV0MGDBDarN9+xju9uupQyfaINmoTu3tdGmRW3eEBrPtQUJPXt8oXql5w MVYaxar8UXjFXV/50giNii2h4hFwYVElRlARw2GCAdvl3tIU7DK/KXtlKjX6mVoZCdpH UDHPaH0Rd8R7q2WNNQO16Uou3dFJ4l9F6VkIHz0AAdCz/Rb/ENKuI5h2Onggafno5jfO I2H2LxwcV9Ou3Qhwf9+lVWliKFwQIGMpTxgRcSFaooJiNuRnVm7G4JXATNQeF6xC+ZWA j4GQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oOSJj8VCPFHmlYdoQtcKShj3B4Hf2mnMJRAlgJxNn5k=; b=i9/U36UM9UXEd8XwMfpJW1k5cBWWRBGkDKFmjTlw87Jtz64uJtdMRzLACD7ifUfN4a e+GbylukBAhqLcDx7yCqv4KGrw4qGeWRnDJ/saaCrCE7xGiop3B0dPuMYs5tdqviELdy KmdDxen6R8/IIUdZYR4itFaRFkLnyepFT4p0ioK9x5kh+FWgUeznc6Uw0qvdfGVplDgC KxPqpdVEWpG/PnfXdJLVfAeoiBaO0a+f920XMoMWivBsuXMWpv/wTZWQSSQtWS58fYna NnjdYUK0dyTAmhOxt1iPZkl23Oyql1VnHJZpL1J3XtFH+q51BF1Lp4O/Z4/l6Y5IkFDl KNMQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ZQSdHDs0; 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=pass (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 22-20020ac85756000000b00317cb8ec640si5956279qtx.91.2022.06.28.01.32.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:32:43 -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=pass header.i=@linaro.org header.s=google header.b=ZQSdHDs0; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:35364 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66eJ-0001LV-BG for patch@linaro.org; Tue, 28 Jun 2022 04:32:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44358) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jv-0002MP-9t for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:27 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:40485) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jt-0000a6-Kp for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:27 -0400 Received: by mail-pg1-x530.google.com with SMTP id 9so11074535pgd.7 for ; Mon, 27 Jun 2022 21:59:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=oOSJj8VCPFHmlYdoQtcKShj3B4Hf2mnMJRAlgJxNn5k=; b=ZQSdHDs0EGAoR01+DKW88oOMGPaOaHHE3JuU78ENscPXUV+vv2F6Nzq4Sg/sloQZu5 1AVS1FG+GKvjE+8I125cvBGoa/g0ew34CcqP6JvEcNEdrjx5ROGyPkPxGRStP/Ww9py9 bT9CrXdd6wQwMlGvFM28O+xX203i4p63gOhHpUoTrr/GtORgFY74RyVeflrdxCih5ywF /Z91m/7/4FRGGJTBg8/R8At3RSs/H/oJnk1pbg6maO7yeTURgcrDSedz6+bpAOsqFzHT agkGHEsIWDArtHFGNlAUk3ILnCgTQ64T4x3oKMSBewLgXn+2wWjnqmdoxuOnOOVjflEj RXXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=oOSJj8VCPFHmlYdoQtcKShj3B4Hf2mnMJRAlgJxNn5k=; b=zNqM5ZosNHv7xccuC+f17YpALYUEUTymoQBtEQHGt7b1CiOsTAb+VQVgtcDYXe96hl cIQ+7r9mv2+vTBSc3jLjmDPXsinqVYAUppJeX35INdUYW1ouJThEVlXP7Wryb18itlI8 gIBuZ86pdwH7v1SNdw6/uLz8z/CX6omnmcJi8cyLh5C3VoQGNFIuzCMLM9XibgNsLqV2 JnolC47IbAYoZjFKlvavbhFnyJweHPaeBTD67C4T3KWQqU7WbzRVGOQ2ahDCSLTDmcfh 8SD26DXDo9MPKIIDkveXDpaV4fKf66024RlhStHa7qU3MNqHVLngSLRgBUjEkCUeIHdx 28/g== X-Gm-Message-State: AJIora8UIYQWnCVHPhVZ6EpfMAPRBaf5AY3j/Lrvnjc4Mi8BwoRr0v9o NySJj9B8V0UTeWtGpOpPdFTdNME6f2GRbQ== X-Received: by 2002:a63:f34a:0:b0:405:dd6:5278 with SMTP id t10-20020a63f34a000000b004050dd65278mr15826596pgj.359.1656392364238; Mon, 27 Jun 2022 21:59:24 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Laurent Vivier Subject: [PULL 55/60] target/m68k: Make semihosting system only Date: Tue, 28 Jun 2022 10:23:58 +0530 Message-Id: <20220628045403.508716-56-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::530; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x530.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" While we had a call to do_m68k_semihosting in linux-user, it wasn't actually reachable. We don't include DISAS_INSN(halt) as an instruction unless system mode. Reviewed-by: Laurent Vivier Signed-off-by: Richard Henderson --- linux-user/m68k/cpu_loop.c | 5 ----- target/m68k/m68k-semi.c | 36 ------------------------------------ target/m68k/meson.build | 6 ++++-- 3 files changed, 4 insertions(+), 43 deletions(-) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index 3d3033155f..caead1cb74 100644 --- a/linux-user/m68k/cpu_loop.c +++ b/linux-user/m68k/cpu_loop.c @@ -36,11 +36,6 @@ void cpu_loop(CPUM68KState *env) process_queued_cpu_work(cs); switch(trapnr) { - case EXCP_HALT_INSN: - /* Semihosing syscall. */ - env->pc += 4; - do_m68k_semihosting(env, env->dregs[0]); - break; case EXCP_ILLEGAL: case EXCP_LINEA: case EXCP_LINEF: diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 37b409b0b9..d0697ddbd1 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,13 +21,8 @@ #include "cpu.h" #include "exec/gdbstub.h" -#if defined(CONFIG_USER_ONLY) -#include "qemu.h" -#define SEMIHOSTING_HEAP_SIZE (128 * 1024 * 1024) -#else #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" -#endif #include "qemu/log.h" #define HOSTED_EXIT 0 @@ -377,43 +372,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) } break; case HOSTED_INIT_SIM: -#if defined(CONFIG_USER_ONLY) - { - CPUState *cs = env_cpu(env); - TaskState *ts = cs->opaque; - /* Allocate the heap using sbrk. */ - if (!ts->heap_limit) { - abi_ulong ret; - uint32_t size; - uint32_t base; - - base = do_brk(0); - size = SEMIHOSTING_HEAP_SIZE; - /* Try a big heap, and reduce the size if that fails. */ - for (;;) { - ret = do_brk(base + size); - if (ret >= (base + size)) { - break; - } - size >>= 1; - } - ts->heap_limit = base + size; - } - /* - * This call may happen before we have writable memory, so return - * values directly in registers. - */ - env->dregs[1] = ts->heap_limit; - env->aregs[7] = ts->stack_base; - } -#else /* * FIXME: This is wrong for boards where RAM does not start at * address zero. */ env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; -#endif return; default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); diff --git a/target/m68k/meson.build b/target/m68k/meson.build index 05cd9fbd1e..27d2d7ba87 100644 --- a/target/m68k/meson.build +++ b/target/m68k/meson.build @@ -4,14 +4,16 @@ m68k_ss.add(files( 'fpu_helper.c', 'gdbstub.c', 'helper.c', - 'm68k-semi.c', 'op_helper.c', 'softfloat.c', 'translate.c', )) m68k_softmmu_ss = ss.source_set() -m68k_softmmu_ss.add(files('monitor.c')) +m68k_softmmu_ss.add(files( + 'm68k-semi.c', + 'monitor.c' +)) target_arch += {'m68k': m68k_ss} target_softmmu_arch += {'m68k': m68k_softmmu_ss} From patchwork Tue Jun 28 04:53:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585531 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp488356mab; Mon, 27 Jun 2022 23:55:09 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vJVTSW/jnhxNMaLYNlP3fAmDNL8++GOOfY7x/LwBNXH2lWmkPRYjz6w+NMTIOfFOjbt1w7 X-Received: by 2002:ad4:5ceb:0:b0:470:54e3:92a4 with SMTP id iv11-20020ad45ceb000000b0047054e392a4mr2495425qvb.22.1656399309200; Mon, 27 Jun 2022 23:55:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656399309; cv=none; d=google.com; s=arc-20160816; b=yVRuXHaH74tXlNX86DgIBmBfrV0kQIwHKCCG5lJoxxTmJKeVp5BdFo/AnbyLzhqd2+ ghKd6BfjcnMv1RuE+1cgImXKL4/Q/KvB5uViWkSmjHATnC7k/ze0HSUUFgo91l8zFdFX S7tfINUohtkHb/D+JDEsvFsMv4rmt2byfVUsZCUeY7q+1TESz2QLcV7dXfAozJ/L9Jvv JhV85hz7VWQmJyXyjZ3lkPAA+NUCIzKhrYos12JURTcEK0iJG1WGwAb9Mv+dh+q0Ibfs UFeu1f72KsKE2KHKBj11Cpn7niws1L/qjRc20knlzeKI42xoxw2XoSCwKi+Ao23Oz84m ObQg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=zI9/tIpkmxJGD6rfujxQ9XUlmWHuHJ+RJ3gAxf5iixM=; b=mXQgHQRa1QAYJlhdCmIDHe+KI5tWP1vDD3XmYVCsINw25N6+Mm8ZLQ9CQPobmZDoO+ lWNomgIAyY7GnMFAQm53UFgXkgLcTOydK0T03Q6qLKRmKCD1QFqxtUUYsyj89tAoQ9r2 0fR7tT56rZ+CWCu6rI0ScP73ithXGGC/wlQUg9myHxczf20T8RAbVM+rd3jb08faQcI/ XtloLafH4EfXuFH5nN5UscB1rKlBebfbiRrPnCLTMLTloy0q+xnk66v3CYr5UBgoA4M0 i0GWDENmS8CH3FlBgyG2wRuHEYwkxwxOv2PraXqd9xYB4ivOtD+HRlzeKpHFivGQfLxh Ju3g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vanwxbLF; 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=pass (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 m7-20020a05620a214700b006a6d57659acsi6522811qkm.589.2022.06.27.23.55.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 27 Jun 2022 23:55:09 -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=pass header.i=@linaro.org header.s=google header.b=vanwxbLF; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54980 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o657s-0000ei-NC for patch@linaro.org; Tue, 28 Jun 2022 02:55:08 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63Jy-0002Wt-66 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:30 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:33729) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jw-0000aS-7i for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:29 -0400 Received: by mail-pg1-x533.google.com with SMTP id z14so11125743pgh.0 for ; Mon, 27 Jun 2022 21:59:27 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zI9/tIpkmxJGD6rfujxQ9XUlmWHuHJ+RJ3gAxf5iixM=; b=vanwxbLFKRpsdet/imh7WUq/fQYzriL9H8R3L0p0K0SIx5uUWZ4rarptLnT7yYLNFS 7hK6sZBfbLtKvUoVQ3FC/d62MERN32l0HDurJtb+jjAb9ad148yuPYIacTquM7X6L3Wh yCPRcMYDlf1x1qtkwzu3P3HITIDGQffe0nwU+3JnIJenhtUyYjNoMSwCF3S0qsBoariW 5OSgUtfy3j7IxB+NNSzKKNEi35jei4J7GRzFJjOTHrKp22Lva9Hy6zfMpc6roeN4cZPI 0vK5SQxR4NrzP7ovGsb8HMsjLG3qOORN+cVs7cnvYs3xHWIIMA9k6A0HunAvLS+VYJ7T BKEw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zI9/tIpkmxJGD6rfujxQ9XUlmWHuHJ+RJ3gAxf5iixM=; b=CRJhKaCkJEfBUJ0CYrU4HHstB8B8oXJHeTYEuogzNY5PqQ/71J5b0kfhju5kvkMsnR D28e+t86tMfkSQZ+FLQmpYUqZvoPdTnX3A6vAGyGUbw3kpvmlsOtlnfGiPZ3xvaA6CbX +/D+nvzrxT9t2BKOLTJCaZPqX68dN2w0SgZQOhu+SmHvjhjp8NisQyKqx+8O1ckOr4TO hBtnyi84ovaqDu15N7Ev/P+2XH33SKzYl2rnm+cu+09xPvRfJS6GFle/roOVhklv6gKZ fAE5QcnxDjdFPqXbAktCWPJTslqBeal4mFJNuskTZuUuAbz1J6Mn4upL8hRcj1CA2Vrw L/9Q== X-Gm-Message-State: AJIora/9lSGtNfOrMX1JwDxwtXscmfjda1w78OY/KK4dDFTrbsvWIQYH z1t0n4WT3LpWUEOKUBzKLWSQnLUGHuaaCw== X-Received: by 2002:a62:1444:0:b0:525:254d:14ce with SMTP id 65-20020a621444000000b00525254d14cemr1613861pfu.58.1656392366915; Mon, 27 Jun 2022 21:59:26 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.24 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 56/60] target/mips: Use an exception for semihosting Date: Tue, 28 Jun 2022 10:23:59 +0530 Message-Id: <20220628045403.508716-57-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::533; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x533.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Within do_interrupt, we hold the iothread lock, which is required for Chardev access for the console, and for the round trip for use_gdb_syscalls(). Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/mips/cpu.h | 3 ++- target/mips/tcg/tcg-internal.h | 2 ++ target/mips/tcg/sysemu_helper.h.inc | 2 -- target/mips/tcg/exception.c | 1 + target/mips/tcg/sysemu/mips-semi.c | 4 ++-- target/mips/tcg/sysemu/tlb_helper.c | 4 ++++ target/mips/tcg/translate.c | 12 ++---------- target/mips/tcg/micromips_translate.c.inc | 6 +++--- target/mips/tcg/mips16e_translate.c.inc | 2 +- target/mips/tcg/nanomips_translate.c.inc | 4 ++-- 10 files changed, 19 insertions(+), 21 deletions(-) diff --git a/target/mips/cpu.h b/target/mips/cpu.h index 42efa989e4..0a085643a3 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -1252,8 +1252,9 @@ enum { EXCP_MSAFPE, EXCP_TLBXI, EXCP_TLBRI, + EXCP_SEMIHOST, - EXCP_LAST = EXCP_TLBRI, + EXCP_LAST = EXCP_SEMIHOST, }; /* diff --git a/target/mips/tcg/tcg-internal.h b/target/mips/tcg/tcg-internal.h index 993720b00c..1d27fa2ff9 100644 --- a/target/mips/tcg/tcg-internal.h +++ b/target/mips/tcg/tcg-internal.h @@ -62,6 +62,8 @@ bool mips_cpu_tlb_fill(CPUState *cs, vaddr address, int size, MMUAccessType access_type, int mmu_idx, bool probe, uintptr_t retaddr); +void mips_semihosting(CPUMIPSState *env); + #endif /* !CONFIG_USER_ONLY */ #endif diff --git a/target/mips/tcg/sysemu_helper.h.inc b/target/mips/tcg/sysemu_helper.h.inc index 4353a966f9..af585b5d9c 100644 --- a/target/mips/tcg/sysemu_helper.h.inc +++ b/target/mips/tcg/sysemu_helper.h.inc @@ -9,8 +9,6 @@ * SPDX-License-Identifier: LGPL-2.1-or-later */ -DEF_HELPER_1(do_semihosting, void, env) - /* CP0 helpers */ DEF_HELPER_1(mfc0_mvpcontrol, tl, env) DEF_HELPER_1(mfc0_mvpconf0, tl, env) diff --git a/target/mips/tcg/exception.c b/target/mips/tcg/exception.c index 0b21e0872b..2bd77a61de 100644 --- a/target/mips/tcg/exception.c +++ b/target/mips/tcg/exception.c @@ -125,6 +125,7 @@ static const char * const excp_names[EXCP_LAST + 1] = { [EXCP_TLBRI] = "TLB read-inhibit", [EXCP_MSADIS] = "MSA disabled", [EXCP_MSAFPE] = "MSA floating point", + [EXCP_SEMIHOST] = "Semihosting", }; const char *mips_exception_name(int32_t exception) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 6d6296e709..ac12c802a3 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -20,10 +20,10 @@ #include "qemu/osdep.h" #include "cpu.h" #include "qemu/log.h" -#include "exec/helper-proto.h" #include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" +#include "internal.h" typedef enum UHIOp { UHI_exit = 1, @@ -238,7 +238,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, unlock_user(p, gpr, 0); \ } while (0) -void helper_do_semihosting(CPUMIPSState *env) +void mips_semihosting(CPUMIPSState *env) { target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; diff --git a/target/mips/tcg/sysemu/tlb_helper.c b/target/mips/tcg/sysemu/tlb_helper.c index 73254d1929..57ffad2902 100644 --- a/target/mips/tcg/sysemu/tlb_helper.c +++ b/target/mips/tcg/sysemu/tlb_helper.c @@ -1053,6 +1053,10 @@ void mips_cpu_do_interrupt(CPUState *cs) } offset = 0x180; switch (cs->exception_index) { + case EXCP_SEMIHOST: + cs->exception_index = EXCP_NONE; + mips_semihosting(env); + return; case EXCP_DSS: env->CP0_Debug |= 1 << CP0DB_DSS; /* diff --git a/target/mips/tcg/translate.c b/target/mips/tcg/translate.c index 5f460fb687..d9d7692765 100644 --- a/target/mips/tcg/translate.c +++ b/target/mips/tcg/translate.c @@ -12094,14 +12094,6 @@ static inline bool is_uhi(int sdbbp_code) #endif } -#ifdef CONFIG_USER_ONLY -/* The above should dead-code away any calls to this..*/ -static inline void gen_helper_do_semihosting(void *env) -{ - g_assert_not_reached(); -} -#endif - void gen_ldxs(DisasContext *ctx, int base, int index, int rd) { TCGv t0 = tcg_temp_new(); @@ -13910,7 +13902,7 @@ static void decode_opc_special_r6(CPUMIPSState *env, DisasContext *ctx) break; case R6_OPC_SDBBP: if (is_uhi(extract32(ctx->opcode, 6, 20))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { gen_reserved_instruction(ctx); @@ -14322,7 +14314,7 @@ static void decode_opc_special2_legacy(CPUMIPSState *env, DisasContext *ctx) break; case OPC_SDBBP: if (is_uhi(extract32(ctx->opcode, 6, 20))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { /* * XXX: not clear which exception should be raised diff --git a/target/mips/tcg/micromips_translate.c.inc b/target/mips/tcg/micromips_translate.c.inc index fc6ede75b8..274caf2c3c 100644 --- a/target/mips/tcg/micromips_translate.c.inc +++ b/target/mips/tcg/micromips_translate.c.inc @@ -826,7 +826,7 @@ static void gen_pool16c_insn(DisasContext *ctx) break; case SDBBP16: if (is_uhi(extract32(ctx->opcode, 0, 4))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { /* * XXX: not clear which exception should be raised @@ -942,7 +942,7 @@ static void gen_pool16c_r6_insn(DisasContext *ctx) case R6_SDBBP16: /* SDBBP16 */ if (is_uhi(extract32(ctx->opcode, 6, 4))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { generate_exception(ctx, EXCP_RI); @@ -1311,7 +1311,7 @@ static void gen_pool32axf(CPUMIPSState *env, DisasContext *ctx, int rt, int rs) break; case SDBBP: if (is_uhi(extract32(ctx->opcode, 16, 10))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { check_insn(ctx, ISA_MIPS_R1); if (ctx->hflags & MIPS_HFLAG_SBRI) { diff --git a/target/mips/tcg/mips16e_translate.c.inc b/target/mips/tcg/mips16e_translate.c.inc index f57e0a5f2a..0a3ba252e4 100644 --- a/target/mips/tcg/mips16e_translate.c.inc +++ b/target/mips/tcg/mips16e_translate.c.inc @@ -952,7 +952,7 @@ static int decode_ase_mips16e(CPUMIPSState *env, DisasContext *ctx) break; case RR_SDBBP: if (is_uhi(extract32(ctx->opcode, 5, 6))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { /* * XXX: not clear which exception should be raised diff --git a/target/mips/tcg/nanomips_translate.c.inc b/target/mips/tcg/nanomips_translate.c.inc index c0ba2bf1b1..ecb0ebed57 100644 --- a/target/mips/tcg/nanomips_translate.c.inc +++ b/target/mips/tcg/nanomips_translate.c.inc @@ -3695,7 +3695,7 @@ static int decode_nanomips_32_48_opc(CPUMIPSState *env, DisasContext *ctx) break; case NM_SDBBP: if (is_uhi(extract32(ctx->opcode, 0, 19))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { gen_reserved_instruction(ctx); @@ -4634,7 +4634,7 @@ static int decode_isa_nanomips(CPUMIPSState *env, DisasContext *ctx) break; case NM_SDBBP16: if (is_uhi(extract32(ctx->opcode, 0, 3))) { - gen_helper_do_semihosting(cpu_env); + generate_exception_end(ctx, EXCP_SEMIHOST); } else { if (ctx->hflags & MIPS_HFLAG_SBRI) { gen_reserved_instruction(ctx); From patchwork Tue Jun 28 04:54:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585545 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp507535mab; Tue, 28 Jun 2022 00:25:29 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vkApKOqz2BRzTdWWtYqZX/VuGP4l1Kz9KqL2qI7wG5Q8rshd3f9DFf4sYTui9rVBt2+uWP X-Received: by 2002:a05:6214:598b:b0:470:45a3:7983 with SMTP id ll11-20020a056214598b00b0047045a37983mr1393867qvb.78.1656401129217; Tue, 28 Jun 2022 00:25:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401129; cv=none; d=google.com; s=arc-20160816; b=sT19fhh66dmfNLf6I0H2ncrY/bhCcmt+WmfWEV0VB8k+6g9nT97fj4lp4haoNhxCYk /vTWYe+V/cVnE3BGUnakyXs/RBGcSQmRasuL3X0PQ4SpXSS5effkojf8SQb85PoHUt4k qjPWeLnXgM/lAXT4gNzGhlIq+PF+4SZZmEK8UcsAz71m6GDyeW2FJ4iZND2aLYoTr9kt vhKB8nMNXcWSV6TFWGg7qTuixVvzv2R7tr/TQoa83JeEJqTiHcsMelTmbY054R6XM/FI L1AdW3y7tS8iss4o6ULykvGbWFTstlur9D7A4Ei4n97O8Tykqc3mohRd9N82bMmTf1qe AxdQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=TXyEX5EGojRk37xSHJRE+V8ZZ/aXpEnXqpHF/pSGdMc=; b=QoBcNKvFuSg16wEdK0HG79eXIPeWLvI6tUqhqnNJlgGtAuRvOV8UqDlXE/9fSAwACU JF7D5wzzZKRVidnFzgVJ5WPaoK8HIZ7JLLdf313qlBYPC/Ba77WYL5GNmxm3pNdQwR2z aqF2I/WzWiKwkT7u87o+Qq9vTi+gfbnoUGWjwbfKt14jZIsqRDRFQeDhLwBNCTvROU7/ 15IsikMDn7+ppv3F7T4xlASi7wnJrzMItLk6k4UpY9Tw0e4A864uFqvbn5SnlQ0puBuZ z/F8+lB+DUKlBI/8RRt0im0+PQrjMrwwwYVo61JTybghUdb4ogPzHqFTMFABzt/a1vh/ 9hAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gdLADNrL; 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=pass (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 jx11-20020a0562142b0b00b004705f6a80e6si6930335qvb.233.2022.06.28.00.25.29 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:25: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=pass header.i=@linaro.org header.s=google header.b=gdLADNrL; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40818 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65bE-0006ZW-Pm for patch@linaro.org; Tue, 28 Jun 2022 03:25:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44396) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63K1-0002d8-DA for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:34 -0400 Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]:41861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63Jy-0000aZ-Ao for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:31 -0400 Received: by mail-pf1-x42f.google.com with SMTP id i64so10937492pfc.8 for ; Mon, 27 Jun 2022 21:59:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=TXyEX5EGojRk37xSHJRE+V8ZZ/aXpEnXqpHF/pSGdMc=; b=gdLADNrLoo7dmxZmlwTxA45p/kmRYTM55HrZ0SCH8WeRTaXMpaQbAuFlLqF++8N3EL cB5uu5IIlTXEg/WvsD91KrKd9hRR/FJaEVgz/lbnw6UF1wCV98QDKgrufnZPjM36vzyU PSLOf1HgGIlnaYIz4B1RBHA50DGofcl0QSO8mOspcQECdXVOKekwS1Ipq+gAwPRGQUI1 QpunC8GclRBXPn4SBTUr+pw7IZ4biLBDaFRjc6LTRLEkWhCuI72c0fW6p/evNR2wb4Q5 9DecmN2AucdQzSEwohvUSBub3rpcr/s8KrgttzBhg/2IUgF/QEHSV587oVbTTGD5z+dd fSsQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=TXyEX5EGojRk37xSHJRE+V8ZZ/aXpEnXqpHF/pSGdMc=; b=1+wK7G4IGJc7FNKWAy3IQxEYvKj0p7ovqHx3JrRdxzn2ryXJDNvD9tZFdgXIx6cApP uNoM0zSZAgSU1Lx+t/FQgsocnozLJzt0Kbnp0DD0VF4aSrlgXHd+sMHSRpoPFejhSa7I BcjKKvd+MXdPiRpf3ZMX47qkvPWyu2oTC6XqK+g9dkDm2B8P7zo7XishBV1c/be6z2uA gVbf0VB1BheQFJ+NaOKeUtpRpb3yjQPFyC+I5uuiYrkAzjP1ywxIjKwrXgINm4nhmhO2 BlIdRzooAkYpEG4z46pXGvw9trb3hoM6eRjIgk9juHSeSZcRizMxD+4x/CfLn0oXEpZK Kscw== X-Gm-Message-State: AJIora+nFWAVNW0VAmTYIOeO1vxfWdFgrOblBoRtg7t0jb729MGZPaqe R5RrTEJ3iRJhHVqXpj0BS31qEF/0BYXiqg== X-Received: by 2002:a63:1824:0:b0:408:a22b:df0c with SMTP id y36-20020a631824000000b00408a22bdf0cmr16318367pgl.119.1656392369048; Mon, 27 Jun 2022 21:59:29 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 57/60] target/mips: Add UHI errno values Date: Tue, 28 Jun 2022 10:24:00 +0530 Message-Id: <20220628045403.508716-58-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42f; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42f.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" >From the Unified Hosting Interface, MD01069 Reference Manual, version 1.1.6, 06 July 2015. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index ac12c802a3..2a039baf4c 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -74,6 +74,46 @@ enum UHIOpenFlags { UHIOpen_EXCL = 0x800 }; +enum UHIErrno { + UHI_EACCESS = 13, + UHI_EAGAIN = 11, + UHI_EBADF = 9, + UHI_EBADMSG = 77, + UHI_EBUSY = 16, + UHI_ECONNRESET = 104, + UHI_EEXIST = 17, + UHI_EFBIG = 27, + UHI_EINTR = 4, + UHI_EINVAL = 22, + UHI_EIO = 5, + UHI_EISDIR = 21, + UHI_ELOOP = 92, + UHI_EMFILE = 24, + UHI_EMLINK = 31, + UHI_ENAMETOOLONG = 91, + UHI_ENETDOWN = 115, + UHI_ENETUNREACH = 114, + UHI_ENFILE = 23, + UHI_ENOBUFS = 105, + UHI_ENOENT = 2, + UHI_ENOMEM = 12, + UHI_ENOSPC = 28, + UHI_ENOSR = 63, + UHI_ENOTCONN = 128, + UHI_ENOTDIR = 20, + UHI_ENXIO = 6, + UHI_EOVERFLOW = 139, + UHI_EPERM = 1, + UHI_EPIPE = 32, + UHI_ERANGE = 34, + UHI_EROFS = 30, + UHI_ESPIPE = 29, + UHI_ETIMEDOUT = 116, + UHI_ETXTBSY = 26, + UHI_EWOULDBLOCK = 11, + UHI_EXDEV = 18, +}; + static int errno_mips(int host_errno) { /* Errno values taken from asm-mips/errno.h */ From patchwork Tue Jun 28 04:54:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585541 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp505222mab; Tue, 28 Jun 2022 00:21:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1ukikIA9FyN/Tvq5Hd4W6JGfsEQomamoBzoIlJGL4mycNa2Bxhv50m1j1Y4r2OGMJ7kSBAb X-Received: by 2002:a05:620a:2809:b0:6a9:9088:f251 with SMTP id f9-20020a05620a280900b006a99088f251mr10474488qkp.653.1656400908627; Tue, 28 Jun 2022 00:21:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656400908; cv=none; d=google.com; s=arc-20160816; b=sHdj2+R2E2YWBZmPqIOLYxz7dPByYOtvn3/0rEH4p4uYq0jPDFhCXU+iOzPKcmIX08 FF+H+I7BaEi68UOD+GE5Pzza7ljCEE3t9cFk9K9jBehOyVapOsMQTCdN1Z7JMRIWWSG/ PGhWgPxVrM1hJp4rJVTxbqTC2AOCwZZGpXHx/QsjYG/NSfU2djNVRpd2yrzf967X63Yw 0lbnTmw8dzo6TvUbLXxfN3jDNWKiGQoWjVExq50xPXVtmK6Fvf8xe3sWeKJGFO6ihNnJ huLtui8tDqE+s/hvSZztHPmn2xreVpHJw8fheumx8BsXZDNFooYGnKyNikYa29R4gncB s4Eg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=QTidsW/sRsHGcxNCrK3b1asXzS4RAQoz54ikW3J5w+g=; b=GHmUKhgyBuRBJQh7RP/8i+e4K4XewFU7gs5C8HhOj5WeRErRNl+sakYvtcurMDmoku I+37dgS+yrNsaZJKzBaoZGS7ZHyW1gUuKmpZmvv4i55zhMFocfc/TXqTVTGJ7FgBI+l7 wOUBJJOZkOqW4uTDQZiya+M43TCcahUlGoScS+gvfRP2Be4l2i/4T0FIrzBYqYTsp9Hf Xqv9zcd5pUNQs5JbWicisEY0k1YRpI+PQU0J8SRDr4meXkjo9tkdP2+6n+qet55+k01R FB296S+r3unjQz+qrcylShztp2idHRJbUdVp9iR3IGwn2FKS0iJK9Ye0YLfeg44O26zs KjrA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PdP3BM1y; 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=pass (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 x3-20020a05620a448300b006af3802e929si1926056qkp.200.2022.06.28.00.21.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:21:48 -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=pass header.i=@linaro.org header.s=google header.b=PdP3BM1y; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:59520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65Xg-0008Rt-72 for patch@linaro.org; Tue, 28 Jun 2022 03:21:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44414) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63K3-0002e1-2P for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:36 -0400 Received: from mail-pj1-x1035.google.com ([2607:f8b0:4864:20::1035]:45574) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63K1-0000an-5t for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:34 -0400 Received: by mail-pj1-x1035.google.com with SMTP id g20-20020a17090a579400b001ed52939d72so6024074pji.4 for ; Mon, 27 Jun 2022 21:59:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QTidsW/sRsHGcxNCrK3b1asXzS4RAQoz54ikW3J5w+g=; b=PdP3BM1y/ajBZm0VBpLOGB93nY0LP6UWQeDY/EsgTvncT3NpKEEgADJLio+Qsj0VTu n5L0Iqrl/3vmM/X6i4scTGY+fn9rCHmUzDsc4ouw1FBaCXyryxfVoGoebh4xAIiGFVq+ 4gMmm9M3YYLfjk9S8xV9RqiO8Avvkp2keWeD5X3NOCxVui4fTh/LWBj07KmSJ65tWqJ6 xmEUfFPxdvd/F9BX9tSRpqMCBDTPiMIp/KVTcOeJt21odExscFQ21+gh/7KG/KVbV30V Nc0WSmgvIaEb2///sNYisysnlYLyx7X+0x2XKFziROQk+dVLfpUqsfDGzYdYkEwldMoC 2qbg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=QTidsW/sRsHGcxNCrK3b1asXzS4RAQoz54ikW3J5w+g=; b=ofK+dTlZlfMTeijA2bXX9K/hSEEjIJUARtspWehJhNTNc8PF++pqWgBU43P722Q2Xe MTToUoSnx2pIHt1GLoPZy659k3Tx4g/0thRnLYtggui1IgoHOs6NNvLx4ipGA9lYTtCb Xz1fJvetzqhidnS7DrnuqjahwhEIAasdLeuJKu2bLcdUFmGaf9VBtkGVp9SSHuMaz0tT jL+L1JwvQZduK+9MRPYl2t9UXgZKQ5mZbf7mieh0fCzMxcWxH+Y4qnDdq+BXlvCfxkFb 2fSChH8PbeiYIpSbfErdBLjPyzbCk2QEhivtCOP88iz3I4zpV7dzKdB3AWt9NWWlkf7+ 7tgA== X-Gm-Message-State: AJIora9Oy4U2KjwWKKnJqqHLcT2heSHCJWPqxyuqn8tBGFAbImKKSB3W 8fuw2julfRDnPmW9aX8E2NDyZDW9Z0JJEg== X-Received: by 2002:a17:90b:4a0b:b0:1ed:4a56:d805 with SMTP id kk11-20020a17090b4a0b00b001ed4a56d805mr16629093pjb.246.1656392371419; Mon, 27 Jun 2022 21:59:31 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =?utf-8?q?Philippe_Mathieu-Daud=C3=A9?= Subject: [PULL 58/60] target/mips: Drop pread and pwrite syscalls from semihosting Date: Tue, 28 Jun 2022 10:24:01 +0530 Message-Id: <20220628045403.508716-59-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1035; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1035.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" We don't implement it with _WIN32 hosts, and the syscalls are missing from the gdb remote file i/o interface. Since we can't implement them universally, drop them. Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 39 ++++++------------------------ 1 file changed, 7 insertions(+), 32 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 2a039baf4c..67c35fe7f9 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -182,8 +182,8 @@ static int get_open_flags(target_ulong target_flags) return open_flags; } -static int write_to_file(CPUMIPSState *env, target_ulong fd, target_ulong vaddr, - target_ulong len, target_ulong offset) +static int write_to_file(CPUMIPSState *env, target_ulong fd, + target_ulong vaddr, target_ulong len) { int num_of_bytes; void *dst = lock_user(VERIFY_READ, vaddr, len, 1); @@ -192,23 +192,14 @@ static int write_to_file(CPUMIPSState *env, target_ulong fd, target_ulong vaddr, return -1; } - if (offset) { -#ifdef _WIN32 - num_of_bytes = 0; -#else - num_of_bytes = pwrite(fd, dst, len, offset); -#endif - } else { - num_of_bytes = write(fd, dst, len); - } + num_of_bytes = write(fd, dst, len); unlock_user(dst, vaddr, 0); return num_of_bytes; } static int read_from_file(CPUMIPSState *env, target_ulong fd, - target_ulong vaddr, target_ulong len, - target_ulong offset) + target_ulong vaddr, target_ulong len) { int num_of_bytes; void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); @@ -217,15 +208,7 @@ static int read_from_file(CPUMIPSState *env, target_ulong fd, return -1; } - if (offset) { -#ifdef _WIN32 - num_of_bytes = 0; -#else - num_of_bytes = pread(fd, dst, len, offset); -#endif - } else { - num_of_bytes = read(fd, dst, len); - } + num_of_bytes = read(fd, dst, len); unlock_user(dst, vaddr, len); return num_of_bytes; @@ -312,11 +295,11 @@ void mips_semihosting(CPUMIPSState *env) gpr[3] = errno_mips(errno); break; case UHI_read: - gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], 0); + gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6]); gpr[3] = errno_mips(errno); break; case UHI_write: - gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], 0); + gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6]); gpr[3] = errno_mips(errno); break; case UHI_lseek: @@ -382,14 +365,6 @@ void mips_semihosting(CPUMIPSState *env) FREE_TARGET_STRING(p, gpr[4]); abort(); break; - case UHI_pread: - gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6], gpr[7]); - gpr[3] = errno_mips(errno); - break; - case UHI_pwrite: - gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6], gpr[7]); - gpr[3] = errno_mips(errno); - break; #ifndef _WIN32 case UHI_link: GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); From patchwork Tue Jun 28 04:54:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585562 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp552874mab; Tue, 28 Jun 2022 01:37:47 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uQY/4/eh/0+ObLUN2vX1UQ3QzhsDrTTZBoUYKEcmjl7grsKzV3k3gnJk2DkQIF9plrC1KI X-Received: by 2002:ac8:5c08:0:b0:317:e856:bcff with SMTP id i8-20020ac85c08000000b00317e856bcffmr12126705qti.615.1656405467277; Tue, 28 Jun 2022 01:37:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656405467; cv=none; d=google.com; s=arc-20160816; b=i7JingG+pJbKa72Nzcpxog/l6GgjznI2kdEoUXIQl7zMfNinHBST2NIGuNU54nPI0x iCFJMZYF87LgEV/a3sVE3Q7q4/umda4yotP9LgdVBa8f0WVKkDMaHPh60+AJQ3kzFu+p IVz2XFoxTE7d1I/+d5aSHRfP0toaUg4EqVrlsET8P4329chP6+BvrJYe6FiZcZRQHZfA srPBBpE/ExTrA/3U64LIvyz1lpjPpEYXfZqqC2zDy1O43dRld8QMR7iJ6Cqh2JGaHFuT Hl9g2Oq4kU3/Hyf7Xj/CO5k4/LmNYHRitj1IV6hnGRRpnuZULrIQa7fftbO65oJek0cN 2dLg== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=10UhMZtSJjpdAac+q1u2FCqNKjafnovkh9qR1nshVX4=; b=E+8lslx4To4scD24RcrCBGqlGaMkzJJXudyp8J5eNrgBQJMcLz8H5ncpAzTz7plunh bcbvZchWgNeKh3uM7bnEtcI2Qicl/w6M7p9aoM0/WBDGoZuTU6iKvQ7H4dmA13nUpRuw iS5rAYNg/zk644AAEyMBZpS3LTEgA3Y4Up/sMSz1KbmjZwzfTfa9VnK0cUIKqpDyI4gd sSckF8aOx2bS6xS3QsH9rLfOsjzVwtIEozpCpzfLwL0nwT9lJHkt8bCydu7e8Dmbvyme eixAa/vQgH6VCjwpE40XAXEQ3m4ZAT0ZdRkkt7saiUZf+caKrCU+0jv0m0TEZaR9/h0a 81kQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Lo/9Jmnm"; 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=pass (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 12-20020ac856ec000000b00304f080a0fcsi6958486qtu.51.2022.06.28.01.37.47 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 01:37: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=pass header.i=@linaro.org header.s=google header.b="Lo/9Jmnm"; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:44026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o66jC-0007bc-Ri for patch@linaro.org; Tue, 28 Jun 2022 04:37:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44426) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63K6-0002eu-DO for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:39 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:35588) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63K2-0000XJ-CM for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:36 -0400 Received: by mail-pf1-x42a.google.com with SMTP id x4so10975509pfq.2 for ; Mon, 27 Jun 2022 21:59:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=10UhMZtSJjpdAac+q1u2FCqNKjafnovkh9qR1nshVX4=; b=Lo/9JmnmMBmpr5i6MHz8gd6z+sojHbcUWqLVRihYdwwWIBn9u4ctLDhpd5Dgo1iQ34 i1Y8YzcIigyE4nT6gqJY4w9P5ETwqCxh7TQU6LUTNvlN7GAiNbc5RucH7QDpF0NzPO8T j6LieHpMZeAIpYNV+yoXSuHGewi+X2xNhRiraA1IGia1yoH31aTaueBhBmKwQ3oQrITF ETNQCD6x7X5Vt0CqK0FUeemYVGzhxErrQ/Syw60tUWsbtc8Gs9Aw3NBPbIX3Bxt6WjYf 1uOQkI2RpTLwetMJu+VHkJe0rxS6Rl5BHAb4k8b3nzlcBzhf3C3x3D6K74kf4POxRxZ7 HthQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=10UhMZtSJjpdAac+q1u2FCqNKjafnovkh9qR1nshVX4=; b=4VPs4GKHxLATCsbS1lcarELDQpGPy6FZel8Sm1AG2yVPkkq7Nk2B9Hl2GJUVULs2kd uXZ1Oa8bM0yZvB4jPShfv5D1tF6VtAeGqYfbktX+XQXmdooo1ZSfqionsnbQO7ppZy8r r/9/a5lmfUiDOv9qqzu5GvbpE++KXvmI1flYaLGIqZlk2RFDjQNXYMdUQ+5ER5HwQsEc vJutevWsH0Z8kpc570sN2ybtVf82x+59Z3gG2AjF0vOqJfHVuDHbAGCCKWVjUX1yqmu3 urYJvZpdIkSWY7cbL0eWD9Q/p/y0ByGK9lVSNDP4L+cUJWuwZQM5Za7VmcBDw1AiNOms Pb2A== X-Gm-Message-State: AJIora/OtwO48dEy+6koSf2LltnAQl/CgicE7XyiGB226YU3biPQ4NeY 1UgGHD7XUqf+x33C4rMXvY26HA4rrgwfLg== X-Received: by 2002:a05:6a00:1da5:b0:522:cb12:549b with SMTP id z37-20020a056a001da500b00522cb12549bmr2767958pfw.81.1656392373618; Mon, 27 Jun 2022 21:59:33 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PULL 59/60] target/nios2: Eliminate nios2_semi_is_lseek Date: Tue, 28 Jun 2022 10:24:02 +0530 Message-Id: <20220628045403.508716-60-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::42a; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x42a.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Reorg nios2_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 59 +++++++++++++++------------------------ 1 file changed, 23 insertions(+), 36 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index 4d02789d26..bdf8849689 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -108,9 +108,12 @@ static bool translate_stat(CPUNios2State *env, target_ulong addr, return true; } -static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) +static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu = NIOS2_CPU(cs); + CPUNios2State *env = &cpu->env; target_ulong args = env->regs[R_ARG1]; + if (put_user_u32(ret, args) || put_user_u32(err, args + 4)) { /* @@ -123,9 +126,12 @@ static void nios2_semi_return_u32(CPUNios2State *env, uint32_t ret, int err) } } -static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) +static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) { + Nios2CPU *cpu = NIOS2_CPU(cs); + CPUNios2State *env = &cpu->env; target_ulong args = env->regs[R_ARG1]; + if (put_user_u32(ret >> 32, args) || put_user_u32(ret, args + 4) || put_user_u32(err, args + 8)) { @@ -135,25 +141,6 @@ static void nios2_semi_return_u64(CPUNios2State *env, uint64_t ret, int err) } } -static int nios2_semi_is_lseek; - -static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) -{ - Nios2CPU *cpu = NIOS2_CPU(cs); - CPUNios2State *env = &cpu->env; - - if (nios2_semi_is_lseek) { - /* - * FIXME: We've already lost the high bits of the lseek - * return value. - */ - nios2_semi_return_u64(env, ret, err); - nios2_semi_is_lseek = 0; - } else { - nios2_semi_return_u32(env, ret, err); - } -} - /* * Read the input value from the argument block; fail the semihosting * call if the memory read fails. @@ -168,6 +155,7 @@ static void nios2_semi_cb(CPUState *cs, uint64_t ret, int err) void do_nios2_semihosting(CPUNios2State *env) { + CPUState *cs = env_cpu(env); int nr; uint32_t args; target_ulong arg0, arg1, arg2, arg3; @@ -188,7 +176,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "open,%s,%x,%x", arg0, (int)arg1, + gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, arg2, arg3); return; } else { @@ -209,7 +197,7 @@ void do_nios2_semihosting(CPUNios2State *env) int fd = arg0; if (fd > 2) { if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "close,%x", arg0); + gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); return; } else { result = close(fd); @@ -225,7 +213,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "read,%x,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", arg0, arg1, len); return; } else { @@ -245,7 +233,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); len = arg2; if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "write,%x,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", arg0, arg1, len); return; } else { @@ -268,12 +256,11 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(3); off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); if (use_gdb_syscalls()) { - nios2_semi_is_lseek = 1; - gdb_do_syscall(nios2_semi_cb, "lseek,%x,%lx,%x", + gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x", arg0, off, arg3); } else { off = lseek(arg0, off, arg3); - nios2_semi_return_u64(env, off, errno); + nios2_semi_u64_cb(cs, off, errno); } return; } @@ -283,7 +270,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(2); GET_ARG(3); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "rename,%s,%s", + gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s", arg0, (int)arg1, arg2, (int)arg3); return; } else { @@ -303,7 +290,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "unlink,%s", + gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s", arg0, (int)arg1); return; } else { @@ -322,7 +309,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(1); GET_ARG(2); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "stat,%s,%x", + gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x", arg0, (int)arg1, arg2); return; } else { @@ -345,7 +332,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "fstat,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x", arg0, arg1); return; } else { @@ -361,7 +348,7 @@ void do_nios2_semihosting(CPUNios2State *env) /* Only the tv parameter is used. tz is assumed NULL. */ GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "gettimeofday,%x,%x", + gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x", arg0, 0); return; } else { @@ -382,7 +369,7 @@ void do_nios2_semihosting(CPUNios2State *env) case HOSTED_ISATTY: GET_ARG(0); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "isatty,%x", arg0); + gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0); return; } else { result = isatty(arg0); @@ -392,7 +379,7 @@ void do_nios2_semihosting(CPUNios2State *env) GET_ARG(0); GET_ARG(1); if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_cb, "system,%s", + gdb_do_syscall(nios2_semi_u32_cb, "system,%s", arg0, (int)arg1); return; } else { @@ -412,5 +399,5 @@ void do_nios2_semihosting(CPUNios2State *env) result = 0; } failed: - nios2_semi_return_u32(env, result, errno); + nios2_semi_u32_cb(cs, result, errno); } From patchwork Tue Jun 28 04:54:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 585544 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:5036:0:0:0:0 with SMTP id e22csp507249mab; Tue, 28 Jun 2022 00:25:03 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uj/G+fnd+udphash4IbMU3jAa+F3Xr2pGC9OZj0tbpblUg9zw+9epVZTfMlX+KfyDRR0Wf X-Received: by 2002:a05:620a:248b:b0:6af:4f9b:b0b3 with SMTP id i11-20020a05620a248b00b006af4f9bb0b3mr1718402qkn.408.1656401103060; Tue, 28 Jun 2022 00:25:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1656401103; cv=none; d=google.com; s=arc-20160816; b=HZZpcLXF61wDq1E8/pqZSa0bUzsgYOMHJHqE8QdNwyWrXeAFhvMLNMtt7gZonxSrpp +6njIOtgXpWiM7n6tSqnetUKPOnDa76OOpJpmPEuGoXrVi897pGO1zdU6Fo0FmHS45jR Xw+G0FADJ88THPnHLN9UlvGByyQOl3hYRHZDnjQESeCVe4pO8Ks+J5AdBWGal59UX88j 6RjJ/khaWXMdwt4P72h8N1GELcpGBpW4GtSV2D7iecO4uKOiWy7UwITN8JFIHA6gPzPp D6/qn9CHODLlgoDl34IxgpqMceMhWpYOKF/QCX8s7MWbh5M4GBZ+kPmIfkHBYMfpYg2x /IHQ== 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:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=lp6xOv80VDFzS9xxN19WiasmRSXfzVX2i/YL5INbRnk=; b=jViHjRLboMOWd2kFM1+0Vs9vNt1YPir/OIwC6zdPJ5n8HOpsP55AqKO8+Yj4t2ZHLX pQWVA3ic28VimU7TmBjkmYDptUtQ0o5tfElkY4Y6mDilTTW5WxgypVqbqUdhOfXuuVzy TzC80zWYdQ2qOh5+WmCTQh1dxudwuy1SzQmKnEyB9C8M915EzY/Kv5+bOiFdvSYHnh7m SSqWaWlb7jwIfJcl7LcIV7sPn784FZTdAj5fiKhI/nSdd+dYmctYQgbQVkVQ3RYa2qN0 sD1Ml6BrGTOqWtAsL9r8nxOXmQmaXlrdgspbMnAs/tz++yNG9isckaZRCvGY9SpL2Ygp aOKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=a5GrIpal; 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=pass (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 21-20020ac85755000000b00304da33ef29si7110897qtx.314.2022.06.28.00.25.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 28 Jun 2022 00:25:03 -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=pass header.i=@linaro.org header.s=google header.b=a5GrIpal; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:40258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1o65ao-0006CT-B6 for patch@linaro.org; Tue, 28 Jun 2022 03:25:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:44442) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1o63K8-0002g1-L7 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:40 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:37685) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1o63K6-0000b7-65 for qemu-devel@nongnu.org; Tue, 28 Jun 2022 00:59:39 -0400 Received: by mail-pj1-x102c.google.com with SMTP id w19-20020a17090a8a1300b001ec79064d8dso14659316pjn.2 for ; Mon, 27 Jun 2022 21:59:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=lp6xOv80VDFzS9xxN19WiasmRSXfzVX2i/YL5INbRnk=; b=a5GrIpalYDaQk+Uok6mZnjYvJJsgtxHZKiE3IC3ZgPXHNW1mgXguWDo05VL3k4su1x 0BilF4u1GY6N2ILosi/+PTaA7Lzy2nGLHxjEnKubGlyzxZcQEuGaYjFuZQNK5MNC3Y7J g8KMomRhLPl1iHiXTyMNIF23tu0Fc3Hn918jVLisOFyFc34IGUB7UmfXL2aE25d9Jc9w mKiKykP9rv70B6rfO3z7732nz051dBxXGHZdTuDrAOgDjHJ5qFOcx3MtnkoQsO61FM+5 JTJNha3J+0iHM1EbJBPNng1/hdI1kVJVTFtVgf4bZiTd0In4i2uSDw/xLk5PGHldCqa8 Ebig== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=lp6xOv80VDFzS9xxN19WiasmRSXfzVX2i/YL5INbRnk=; b=fkavQf0QTADY7L1xjw2a6dtiWjS5tBoQysooPToK6wn761AlTfGeEtOpbgj0JcHivH fZOBUlhS3qSjaV6P3i36gtG5oYFjo0wRD/a91DzweI4r56BWdSmvjVawfhTkcvXZsxDH 8IjLKvcLjp1376yyZ0NeKyf2oKfBn5G60HeIfOWaKpi6VZXK5O6sU35z/wBXlanDzMKY 822z1PVdiBuZQ9ultKcTC3by+9IFORW0/Ta7E9Ig+DfrnuQcm20RPq2JrJBfFSm1l/Of ZaYmCgegX5if1VOvJ76Z2iNp4njP+4QiEqxSriV6akMBkCgcEt8XmwDE8xJ8eZArslVF hyjg== X-Gm-Message-State: AJIora9msDFuBXr7qSvj0z0NJDIjKu9XXFyAC1enxGocPBJImEGg/ZXy 51WXsxtLYyOrWqiVzSoT0zOvyR3d8i6Zzw== X-Received: by 2002:a17:90b:3ec6:b0:1ec:ac25:ce6f with SMTP id rm6-20020a17090b3ec600b001ecac25ce6fmr24619521pjb.203.1656392376219; Mon, 27 Jun 2022 21:59:36 -0700 (PDT) Received: from stoup.. ([122.255.60.245]) by smtp.gmail.com with ESMTPSA id y7-20020aa78f27000000b00522c0a75c39sm8259686pfr.196.2022.06.27.21.59.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 27 Jun 2022 21:59:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: Peter Maydell , =?utf-8?q?Philippe_Mathieu-Dau?= =?utf-8?q?d=C3=A9?= Subject: [PULL 60/60] target/nios2: Move nios2-semi.c to nios2_softmmu_ss Date: Tue, 28 Jun 2022 10:24:03 +0530 Message-Id: <20220628045403.508716-61-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220628045403.508716-1-richard.henderson@linaro.org> References: <20220628045403.508716-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::102c; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x102c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 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" Semihosting is not enabled for nios2-linux-user. Reviewed-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 5 ----- target/nios2/meson.build | 4 ++-- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index bdf8849689..55061bb2dc 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -22,14 +22,9 @@ */ #include "qemu/osdep.h" - #include "cpu.h" #include "exec/gdbstub.h" -#if defined(CONFIG_USER_ONLY) -#include "qemu.h" -#else #include "semihosting/softmmu-uaccess.h" -#endif #include "qemu/log.h" #define HOSTED_EXIT 0 diff --git a/target/nios2/meson.build b/target/nios2/meson.build index 2bd60ba306..c6e2243cc3 100644 --- a/target/nios2/meson.build +++ b/target/nios2/meson.build @@ -1,7 +1,6 @@ nios2_ss = ss.source_set() nios2_ss.add(files( 'cpu.c', - 'nios2-semi.c', 'op_helper.c', 'translate.c', )) @@ -10,7 +9,8 @@ nios2_softmmu_ss = ss.source_set() nios2_softmmu_ss.add(files( 'helper.c', 'monitor.c', - 'mmu.c' + 'mmu.c', + 'nios2-semi.c', )) target_arch += {'nios2': nios2_ss}