From patchwork Sat Apr 30 13:29:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568118 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp7214019map; Sat, 30 Apr 2022 06:44:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwzTNbFNwKGfLV1HZoVlydU9+RZRGc6TXtPZIM3XaoytHNvdNUArd2dU4sTcSqfHEEGaQKF X-Received: by 2002:a05:620a:2915:b0:69f:1574:ea14 with SMTP id m21-20020a05620a291500b0069f1574ea14mr2876995qkp.200.1651326292696; Sat, 30 Apr 2022 06:44:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651326292; cv=none; d=google.com; s=arc-20160816; b=SdmjZ0ahxR3HZQJ/mZ0d18jfUUQi0tPjZeAOGXiF8x1CInmjmAcO+7oH7tZ1rYD6z5 P5HzwLsdL3U2BPE7pQsTnFP2kEhVUPEQYcKlMtGIGCHt2kebUzsEdn96pDQElG8BX7l2 wNtN3aF2lrk1UWo5EyuiaPHTf7bFPHqMNG358akjiOIN7VFkIjLDD2eOPlFdDCZ7FNJK Pv+6phc/t0nzJcvAqyfE0VAOXL4XDvj5Xz8JQu4XyfS3MAlD/Egh/9rj1HS6SI/XpH0a Xuwhav7yc73V9NgKSS8ZNTiB7a7wHLnzuC1hqx+hWzRx9axJEvl05VMsOr5m6VsI0wCf wlXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:cc:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=lqsGPuaCUPcJSOTUaNA4JwqOyqO5kgM0V/wVLGD2Hkdbx0kZRFQFh6RxQFPtfS1tgG zJjhFt7XwlYr4M/zudnuj7yeoMPacLrFIQi08p5w0toAt+ZhYcxgUVf1lV3vin18GnVq p3V4NXL059rHdZMcqtkjTN2Y/z9YbRtXTmI3P7pUM3ntQlYQIQGWhEceKDR60n5/Bj6s xmywQ8voJoFEoeapJZkMuusH1mK7fv6XdhyoyPo+4dNFxbXI54+EtiCIxlLtnCLtCk96 c/0VOSZQfnaAN/yM+jV97cnTe8RmkU9/yFSHiVpF1u/W/9fEm+xGU3NsnchZGnD2alX8 kWfw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=bZNKDHVX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.gnu.org (lists.gnu.org. [209.51.188.17]) by mx.google.com with ESMTPS id ay12-20020a05620a178c00b0069f0febeb6fsi3891196qkb.434.2022.04.30.06.44.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Sat, 30 Apr 2022 06:44: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=fail header.i=@linaro.org header.s=google header.b=bZNKDHVX; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom="qemu-devel-bounces+patch=linaro.org@nongnu.org"; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from localhost ([::1]:54412 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nknP2-0000Sv-8U for patch@linaro.org; Sat, 30 Apr 2022 09:44:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:55982) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nknAh-0004xT-Bc for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:06 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:33268) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nknAf-0006IR-Ho for qemu-devel@nongnu.org; Sat, 30 Apr 2022 09:30:02 -0400 Received: by mail-pj1-x1031.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so9749554pjb.0 for ; Sat, 30 Apr 2022 06:30:01 -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=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=bZNKDHVXJgAPpJoex5Y0STc+m70+YGhWkLQfC1HTWM0BYt+NCsDWyw8dChT62TEQPk 6N+uhfb8Fl8hD4eF5Bw/YR3N0ADiOjoUETeFn8IWvdPNgB3sF6UyABnnhDUoNcayozez q50Cl0hd5+yGqSuN78N9lkZXrBxTvTcBj6p1KpW/KfhiL5A2I2luiMik/CRpXgzxZZMS EAZlcVvauqjG1p3w+RI+yaoCZCeXyNsNYRLnSqLQa1f2tfkO55nu2IQMHZzI8dICVeGf I+Vynq1UldJkgOv/PtMb1gBoxI7VhIYiSr3VcFcfn1koAdD9lTesMq8SiByDSroggScH 1Gfw== 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=Vn62q4JFTAD/R3vXFdx+pxyclHtNLhvG5t7w0tEUSHE=; b=28NYCuJJNPvk41NqNboOQ2lkM8wZKmGQ3nnsSTta07snuv38NUmgESP+V1LHWF45h0 1N9VG82f315PSvDspA1xf/7vMiFbzFAhaZaczsSSJX7W2/snOiIXBni9Ht+ZhrUUV3g/ 6pqVnI9kijaUl7pzAkACyjDYu3l/kp+FaDtkw1N/M3ODBvv5MgscD/7Bo/ssnKHuP4n+ KNffFKYoiGKSoK4sALaSMNjfGbn7kCFeLuUAR078FapqrlsYxcu+1u3NzsrkpF6HdxLJ OWyPjx/qGmLYr4hGCDqNzEksSFApzF+buFaqxuzWBcfQBaZ1bYx1L/32Aij9y8HZwNEt m7FA== X-Gm-Message-State: AOAM530dilRo4QIGCpzp82iQA5UIB6EacDcAce4ZHvn956mhdOuy0HJQ S246+ONjBgvRA3Zmf512zK1quwM9jp0NNg== X-Received: by 2002:a17:902:82c9:b0:15d:2e43:a0e5 with SMTP id u9-20020a17090282c900b0015d2e43a0e5mr3804083plz.64.1651325400231; Sat, 30 Apr 2022 06:30:00 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id x5-20020aa793a5000000b0050dc7628201sm1522606pff.219.2022.04.30.06.29.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 30 Apr 2022 06:29:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH 26/43] semihosting: Split out semihost_sys_isatty Date: Sat, 30 Apr 2022 06:29:15 -0700 Message-Id: <20220430132932.324018-27-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220430132932.324018-1-richard.henderson@linaro.org> References: <20220430132932.324018-1-richard.henderson@linaro.org> MIME-Version: 1.0 Received-SPF: pass client-ip=2607:f8b0:4864:20::1031; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1031.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: , Cc: crwulff@gmail.com, alex.bennee@linaro.org, f4bug@amsat.org, laurent@vivier.eu 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. Signed-off-by: Richard Henderson --- include/semihosting/guestfd.h | 3 +++ semihosting/arm-compat-semi.c | 27 +----------------------- semihosting/guestfd.c | 39 +++++++++++++++++++++++++++++++++++ 3 files changed, 43 insertions(+), 26 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 9c6967ac53..d3dd081e81 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -65,4 +65,7 @@ void semihost_sys_write(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_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 0cab721a50..3844d0e376 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -290,14 +290,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; @@ -309,11 +303,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", @@ -337,32 +326,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, }, }; @@ -487,12 +467,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_cb, arg0); break; case TARGET_SYS_SEEK: diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c index e33d226534..6ed4a9162d 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -523,3 +523,42 @@ void semihost_sys_lseek(CPUState *cs, gdb_syscall_complete_cb complete, g_assert_not_reached(); } } + +static void gdb_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + gdb_do_syscall(complete, "isatty,%x", (target_ulong)gf->hostfd); +} + +static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, + GuestFD *gf) +{ + if (isatty(gf->hostfd)) { + complete(cs, 1, 0); + } else { + complete(cs, 0, errno); + } +} + +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(); + } +}