From patchwork Tue May 3 19:47: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: 568975 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9784006map; Tue, 3 May 2022 13:11:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxopRaytn6dh+17LC5c0UaFzUcZo4q7YbS4zzczMmHTexoVfpXqhnZlIL1OeFWHiXl6x6z4 X-Received: by 2002:ac8:7d93:0:b0:2f3:99b6:f3d with SMTP id c19-20020ac87d93000000b002f399b60f3dmr16351729qtd.119.1651608713688; Tue, 03 May 2022 13:11:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608713; cv=none; d=google.com; s=arc-20160816; b=DS75s/hly/Bbbug9rbBp/Og9DqoeRRFrWZ11ZKaL46KKKT1BIt0QED8XlrtozM9nsH cbXUlLXieGDvA5jkEDynjqknwj/c7aea1pMBMYCYoR+c50EQQ2yPsrRn/6lRjN2Yu94Z Qko9d8LhLIZjHIaDGQuQae+ni/wvqyQA4eUDitgXw2DdMi3EOKNou0mZc471l9HNIcJW gFYdDkEHj6KP9DvKXi+iQ/ZCw589p2NRW3beASHDs5jnE4yrvDjVd3M8FLi613jTwA7j 91h636uTyfYgs8uyrnCBY30uM6y5uqZHgEX6k4VVs4FCgDKHnbZofiBtIb84Xyp/wraO VrZg== 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:to:from :dkim-signature; bh=aRj/gsSJXACdFyaGcT2laC3B2huL8t1HBP8Z66LM2pw=; b=ttTIo92PlAxNv7pGNnhLSxrrAZyrvyASGm3BGfENKNVly8p/ieExWov/G4ozK63oYX yp4Ic4Bfbv6FCay+bxvx8OE1y9uPxpJACOu4dCH4dlYxofpGwGhby2jjlqMSe8/WZrHr 5fscB8jzXdsCtjQ38QtZExCp9SX+SPfpGCqLIZUli82mJOwpQwzWaD+wHm3TNEshpRwD 4JzgTt1vQ6DQUSHDOn3k/MPnzs/n2KLWEB+400yhGIhOHs8Saro1RE9R1B1b5NyXvttN KLXGIpCYJFzXY9LJyEb+OtQMZgmImGVStNqCNiEpDPgz/O1ulpLdUmDDhgyYtmENbhrm pgxw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=wfVe2b6B; 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 f11-20020ac859cb000000b002f3a0c3955fsi4822779qtf.593.2022.05.03.13.11.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:11:53 -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=wfVe2b6B; 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]:34588 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlysD-0002ey-4b for patch@linaro.org; Tue, 03 May 2022 16:11:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39330) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWN-00023v-H8 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:19 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:44578) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWK-0003bc-Ut for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:18 -0400 Received: by mail-pg1-x533.google.com with SMTP id v10so14780190pgl.11 for ; Tue, 03 May 2022 12:49:13 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=aRj/gsSJXACdFyaGcT2laC3B2huL8t1HBP8Z66LM2pw=; b=wfVe2b6BVPS3lrgWnWwTD5DBclT+fgGrVfvQKWMGJmQCvYQCvamoWa5OBgyqKOo2Jg xXbOsHPdMtkuUSOTKDwyV+h3f/2RByjYY7SfBBmA6Ve0vSN9l6FeE7e/lMZzA6pLWRvJ uAwKgl2GB5NE86kulpDaFwRjBIYsnAmJhTS/wkg1R7OxOWEY3fz90M9mGNBMcGDMQ1Ir y5EubGp1PeHARMk5tzOzgWX7s47SOeGmMHsCtlXDALq8hT+JaveYBSEWBzEOS8WzqK7+ UxycZdavT8CQIsOlk60+/LfdoGv+yIFPbiJzNw7NnMp3R8v3FBpCvwdXU7187vRDPgSy HsBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=aRj/gsSJXACdFyaGcT2laC3B2huL8t1HBP8Z66LM2pw=; b=cYUZEzkNxWFp/sl5Pq65T7bDMjW54nwPBMQgI1Mk5Np/pfoPF3jQ9Mk2cIk0U5Aebx T49F6/0dNXkOrHHYXlH2ssndtTWNByNwN7SF2b8Qgzugc8yEIa9Lb98LGJl+5MXdkSLq 7W+OA6lqYkejEwKO0LF2k5JFIRGs/6jJ4qogP8uFim0dF5TMTd1+0tbgMgVJ35VVn3lU LBFmEj2Lw4FE23hfB2P0qFhxYHSpF8lxgpPbSvu55WgT32RVhtG4HCCdyQCOT/GL9B5/ u+uR8eF2k1kN8ohfdgaY3JP1zBoQ/hN+TESup5SBIC1mBTy16LbrSn3vd1auFLU4Mwl6 IfcQ== X-Gm-Message-State: AOAM531pGI03YGqx9xJTfvgoz4mSn2KfGGfJLFDKowkZoym7gdcQs2rx lpy/nK+dt72RINgWVLt40+s11P5HKeI6cQ== X-Received: by 2002:a65:6e8b:0:b0:3ab:a3fb:e95a with SMTP id bm11-20020a656e8b000000b003aba3fbe95amr14988109pgb.433.1651607352813; Tue, 03 May 2022 12:49:12 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.11 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:12 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 27/74] semihosting: Split out semihost_sys_isatty Date: Tue, 3 May 2022 12:47:56 -0700 Message-Id: <20220503194843.1379101-28-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220503194843.1379101-1-richard.henderson@linaro.org> References: <20220503194843.1379101-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" Split out the non-ARM specific portions of SYS_ISTTY to a reusable function. This handles all GuestFD. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 1 + include/semihosting/syscalls.h | 3 +++ semihosting/arm-compat-semi.c | 27 +------------------------ semihosting/syscalls.c | 36 ++++++++++++++++++++++++++++++++++ 4 files changed, 41 insertions(+), 26 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 056db1a0d0..fd4bc4e937 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -41,6 +41,7 @@ #define GDB_EROFS 30 #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 +#define GDB_ENOTTY GDB_EUNKNOWN /* For gdb file i/o remote protocol lseek whence. */ #define GDB_SEEK_SET 0 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 6f97977edf..8fcef02386 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -291,14 +291,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 +304,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 +327,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, }, }; @@ -488,12 +468,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/syscalls.c b/semihosting/syscalls.c index db8891535b..702541b270 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -151,6 +151,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. */ @@ -276,6 +282,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_for_gdb()); +} + /* * Static file semihosting syscall implementations. */ @@ -467,3 +480,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, GDB_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, GDB_ENOTTY); + break; + default: + g_assert_not_reached(); + } +}