From patchwork Tue May 3 19:47: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: 568955 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9770693map; Tue, 3 May 2022 12:50:54 -0700 (PDT) X-Google-Smtp-Source: ABdhPJySV561gYIw6IxJj86x6frRllExyq2tUsRB1MtqW0BJ+7oyJr8ASjkzpgu7aZdsGLeDH9qw X-Received: by 2002:a25:378a:0:b0:645:7945:c1b6 with SMTP id e132-20020a25378a000000b006457945c1b6mr15186985yba.436.1651607454056; Tue, 03 May 2022 12:50:54 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607454; cv=none; d=google.com; s=arc-20160816; b=b1+QlrW+Cx6jJ3hcWp/kmBmsG9H9lOOtlejPXTMA8ZpXbVXQ1lcW2VNWYVyAe5VIXh Qw2aLNqxi0o+RY/oPpcYD8qvPBZVmREc0HLQ8m3IVkfJzX6LLVPGh8SBxJxWyNXTDZ49 Kwte+AvQ8P7FfrD6EGizp6xU8F3xEUWAIaizc8ET+NpklLuCRnIxj9KpeLq+XNtq+O9B MMB0XNsjOxOVBHnukQgotwXTJBA3XQkYq+o7c0mX+C8sGJcB6rsCGGgO0qKA4VNNHAwt VRQq97mCvmzVIXgP/EfoKM9vThMXCVUXrItCDqBaOGtwpSk416co3fgdjy48krEJuBtn l1Lg== 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=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=kZMzibBE27LDNiwrVidrvVsxxREIFZDjT0tF7fru8cRRA6s85/X90jEsqn8xX8dZW7 0bBd7J8/v3LLxCkLsqDy+5HiduQEroA95mKzOtk7eN/M5MFI/QTF426ayfPY9qdIh6tk mWxgmDprHueU58EFNi7wzAB26SxAccvNksp+DlX+9c4mgJB957+oqgBg86Uo/jud6mRp j84ezI788yN23rY78aTD4WkC03a4SNZRC+At8VwU0qwIwthL5dKpHgSodnEALC3SLqCU Qvg0GrgTUUoX3R45hRKloSKYgoQ7VN+m7x3biFsKFaNBI6W6ONUsoIq/l1QJpHQTeSML GxqQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FxosJmDe; 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 d136-20020a81368e000000b002f907750411si4301127ywa.301.2022.05.03.12.50.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:50:54 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FxosJmDe; 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]:49110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyXt-0000uQ-11 for patch@linaro.org; Tue, 03 May 2022 15:50:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38808) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVu-0000sc-2Q for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:50 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:35711) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVs-0003Vd-Ad for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:49 -0400 Received: by mail-pj1-x102b.google.com with SMTP id w5-20020a17090aaf8500b001d74c754128so3245656pjq.0 for ; Tue, 03 May 2022 12:48:47 -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=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=FxosJmDeLkZQSNaEv1jIraPAwjHrnUm3Lm9a+ZR5TTHrAOfHMe6LbKQU2AyCxlGHiW gNxuZVqONK0TCZIzeNP6jOyiOhkeUggVPU7HCV/rBbLl/pNybzEZvg3Tgltjqvf8r7/X EB0LTob5lcR3ndVV190FNwSC7kZ/qrszqlk9Y8LNzFAXyuXFpXLtMMK+/K3c0CmYq07A yxcLiAw56sAvm8nHL8BtmBJX9l3qW/VP4r0yxFxzEoCoSCDtnPRcLpH9hdH6zKpM2JqY oY5SW9OCD02SPPL5/0sNyqFZG56YvEbyhhh6AA+lffO43c3mHShFp7oSy3S/wp1MQmnt MtcA== 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=96XCoIxFXWNe7OzxTXGAkWBiSUjrkUaQNrXa5Y9vDmM=; b=1UWryq+gYrVRg7tWwbumzILiElLf1s2iM+kulHDd2u3JZVM+lEriaUimqDi7c06RLi 2gxpbzy5jxbB7nfjULuywleUQnNLwiF3c9Nm6tvynuBlvLzW2QhH+dTgBEyE6VwGa6q2 wtPIdFRnK9n2Npy1XcVnJAkqu27Zbj9+B5T9C1JsoJsO7ZQDz1yCQmOpxrPdw4WDnwoq bYOl3Bqxfkb3cuwYZk/XFiHHNCEhwadn3TSXMDHi55BAw9cYS82Vc5ht5Ymxk87hcIBY hspdLjr+YExFS9K4AJn/Latlcxn5ke5MmUtvF96yt5jaHLIMYiK4P3svZJ95lmWa427V O+rg== X-Gm-Message-State: AOAM530E2z0IUdWxdAyDYbQ4XVrWHCn/eFZsa9zJ5PrC3Et9V6M0O4sm bL5fczsBT8k9hJLV5yYYiKpZsK2qwfH8kA== X-Received: by 2002:a17:902:7e0d:b0:156:47a4:a7c4 with SMTP id b13-20020a1709027e0d00b0015647a4a7c4mr18662653plm.141.1651607326238; Tue, 03 May 2022 12:48:46 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:45 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 01/74] semihosting: Move exec/softmmu-semi.h to semihosting/softmmu-uaccess.h Date: Tue, 3 May 2022 12:47:30 -0700 Message-Id: <20220503194843.1379101-2-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::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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- .../{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 7a51fd0737..dbef280b87 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 May 3 19:47: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: 568956 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9770705map; Tue, 3 May 2022 12:50:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsIXN2omN4rxxBGnQVJBTxzg4tZKUFZdvEWJ6DX+0oRzZC5we+XtSCq3dISvPJ4VMhNUs/ X-Received: by 2002:a05:6214:27eb:b0:45a:b022:c97d with SMTP id jt11-20020a05621427eb00b0045ab022c97dmr1019016qvb.24.1651607455619; Tue, 03 May 2022 12:50:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607455; cv=none; d=google.com; s=arc-20160816; b=fPbhyfGvPkjZluQylecgcei2xIFz5o1npsF/N+mupCJZwAkOkDOVrWpUE6DV1aMGxp g+Cg5fTPZs8ViqOXjQq1/C1sHMOZQh8oe84a73IH19OS9Xt0x5B8HyX6ycXoL25ZGDtG ws4aF/0y7pTNXPDAtCEtCG0d5iYY58R5bkCpueozjh79qfQeUowTxgpqQl3d3IGeivyT ndjWrDAwNr7q+1cY8cMSo2/5JiVXeokud4/gmXNYvxyRARzVx5WOdlf6AcVSoX6bnlha WPVHzjkchbnVVFVT1+LOsozbYuwxOeh8iAUKYH2cyYgw8QNoe4rvKiNWQ3F7qKq76r5k 6KJA== 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=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=qVYCJKQXu+8joZJtOzUWANGM865j7sigxCWNytqY27xjjUa7Nsb9AUmUb0OyT2jfc2 LQbfCJyMW3iKxSDPNlGedvUK8Fsw1jLv50MaLmaAFovseh2lucJ5UWRTS3iLJJyMe0Fi dGQiwg3TlW48FOR6cQiEi1Uj/8NO7tImqfYliHctKh/f8vZVLPUdjsoz7FHwFV6maZrV +Iezy1aXZ+jSaNtmF3jcHTI4/rU6k+u5GDYSZymDJBuz6HS0/D004AYVsq/Morrf526H AxJ42nxJofiYxRxIL7EgYa2eqaA0pvz/Ee6ynJ5g1SrqQobJ893veiAMNUE5V0MXhR8l jfgA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=sX78squj; 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 e8-20020ac84e48000000b002f398bd4d42si6697827qtw.413.2022.05.03.12.50.55 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:50: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=sX78squj; 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]:49220 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyXv-0000zL-5K for patch@linaro.org; Tue, 03 May 2022 15:50:55 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38846) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVv-0000v3-MM for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:51 -0400 Received: from mail-pj1-x102c.google.com ([2607:f8b0:4864:20::102c]:36721) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVs-0003Vk-Pi for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:51 -0400 Received: by mail-pj1-x102c.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso3228084pjb.1 for ; Tue, 03 May 2022 12:48:48 -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=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=sX78squjtmzGOpUIRbp50M4d2uh99P40qHeG2CdHVN4D2rk6435KnvgQ4l45KzyF7M uD/gM+P55XCSCd4DPQEpGLzJp5EKGeQPOxXKmd9i1MDnveSUvZW0VsW1V9tdV8EqEgU1 mlXEw8+YJ6f6e7wajO/V8CfH82Or1ornKYWFB+vZysiGyDcWb67egen/JJfr7u2dVhX/ xwKB7m0RhF7dniC6qu86kKnrQZJ7Zb0V5XaVIuIj8Nn10976qRAkQLmKk5y5aw2S43u1 S9AO7jMJP2ZjGhsCHiumbtQQoIGw1Ay7fSeVD5eCXHW04u/KiU9SFOqs96PslxOUlZ3m c0xA== 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=3JX05tYCGijKFYZwundP0SWA2fF8+V1jI3B1WPSLqJI=; b=wIDRNjCKdaWRUVz0CRfEWmeoEH8ZODZpD4JIZLZcWbSDcoXBn2gEmiSKBuBCggnNe0 6hXR0y9Osbf348FL7Sqh8vBY+xSdDX3wFpeyUtYG5uEfMAq5IiMmEOTdXyFXbNRQGOAC znPkxEKsI0pOBufrbz/IeEBLvfszB2+vc3+laKcZbuIJvCJ3Wqg1VVLnWGtTh7I7Avlg ogW6kV9jce+rTRM2amit90s6zbwnKelS8vVij+byWaBqHW+dwPkF+PDMqCdroqtB+IWA 1vuXlEr/no/tV8cBWaJyDXflzW+r3GLsbsICCVV5ZSIgW/XElAhpgkD+C4rjn9CQbv/k KHeQ== X-Gm-Message-State: AOAM532JYpQVyowSwjH0nQTGaoPHwfMxDqz18ePWygdHJ8RDdgJRpTQF 0NZkEXx+gqEbpCtiZ4s3q7fpTyCHv4HIig== X-Received: by 2002:a17:902:6b87:b0:158:a0d9:9bd with SMTP id p7-20020a1709026b8700b00158a0d909bdmr18081458plk.156.1651607327363; Tue, 03 May 2022 12:48:47 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.46 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 02/74] semihosting: Return failure from softmmu-uaccess.h functions Date: Tue, 3 May 2022 12:47:31 -0700 Message-Id: <20220503194843.1379101-3-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::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" We were reporting unconditional success for these functions; pass on any failure from cpu_memory_rw_debug. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 May 3 19:47: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: 568958 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9773056map; Tue, 3 May 2022 12:55:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxJSxYNVb+Nn1rnO5XkeOYMuh80CcgUOBkReQ+yUkfPLqQjHhW/9qaeA5yJeWawTWbg/rF1 X-Received: by 2002:a05:6214:761:b0:441:196:795e with SMTP id f1-20020a056214076100b004410196795emr14839558qvz.67.1651607728396; Tue, 03 May 2022 12:55:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607728; cv=none; d=google.com; s=arc-20160816; b=IpNSKZAd0Rf6gEG5WO0D3ufhmxAt57UYaCtp9jbJxcTzEkZ7JVFmlPSubOnDFLzphQ yHy2dI25jPxriYY5WzG3XVl6fX5Wgvfj9X3Yz67ABIevQ9vzFtebDHuPsPzrkK6xjznv O69sTCGXSi6CdoEwpWZVQhq+vFrIckH8m7eiqqnDo/iI9Tm0mFVX/82UBd3slppCAFPG UdX/wjXQzofZOuWcOqgfUulMpv3re1Wwf8IZcxzoPyjSdxk0SNpy/nwXMOJK5Y3DDOGJ F7Y5uKBc/RVUEhYI//TuXjn4lJgyC1rKhnLkFVtI/Gy2OsYujIG0SnATRPJ7Fq2PBPIS jIMw== 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=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=Z54/QUtzHCIr2WmokttU5d1Tk/iBkzbDMsaRMQ1i5qMXTuZSTEyM5H/DUjosZEJrW5 9xXYK+MNY3NCblG8BkUjKqUSqZdHVfGWNQ9uz5RD+X7EH81g3vHFJ0Be1QQqrmKJx3fM TtoAzg6jCq7gnGOT4/OI8jmEj9oLoo/X9gcAywKz8cVHGmoC0/WLDFF35Es0+MTgzmxn qITEJ6WwEbWfNOptQS4HsSOPLeBLxHBTv4ePz27YEhjd1WQEMmM8hI+f9vL/hcA6lf+J m7fT9fMoTB01BudI9bwmh0hnOBD2yfC4Z20xTbES+X9EpbdNprHYq3+Bn+6VPjsqZgOh w/Kg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=nOGB2d2y; 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 d21-20020a05620a241500b0069fc32c2b3esi5384263qkn.667.2022.05.03.12.55.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:55:28 -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=nOGB2d2y; 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]:57044 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlycJ-0002Ke-5I for patch@linaro.org; Tue, 03 May 2022 15:55:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38844) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVv-0000uk-Cx for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:51 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:33898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVt-0003Vy-H5 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:51 -0400 Received: by mail-pj1-x102e.google.com with SMTP id qe3-20020a17090b4f8300b001dc24e4da73so2280378pjb.1 for ; Tue, 03 May 2022 12:48:49 -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=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=nOGB2d2ykFcR7cORq1EVOOEjV3dgItwgPDgfetyovX8KuiIbkwXQpw4RzxPEvxa6OT ktOPzuz3Y5oqOMmFzzr4YXM2GB9PJ6LpAbNLNWgzxIexDKprzXPndboV4ryEdSQoGZgx 9Mc9yxRuhpU4lP9nTDzWW8jBuMC1jo8bzscMZMheStuIHySnX3uJQJCnVpmGlQD2SnXk WJop/Y6U7m/110xv561q8gamtcvum4h/mGfBY+HqCgFQfWhVwLhZRbCuyqXYZa058Pb+ eOMgjUDvKqMB2VC6DuDj0DTJ2zGyFqi3ZEjugSNV3rBu9SsHT279MU7Vwanj4zUoSwDy d+nQ== 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=Tl4F0M/gOxqcmd1Ho0EBp9s9GppksaThNyFvq/k0E0E=; b=hT1pMnU7QXJ9MVFLrNtlE6Ob+4j434xqlVgz08j6KtQi0m60kzEAFdajmGw0earCXi 4eY5h0yt0+bZ33ipxw5OfVKGwb6GPAt4Lkfm2ALV1wWFPqJuFys5RKZTmYmC+7js3Oic qljWfGIwBcwAKC+xd+ME7CGCKzFZ+87WUWw3mO3MtvgMIN+A6Q1V9aZe8IZhvqmOAjrg kCTvr/TM3dh/Mojn+Ff0FZbuWeEVm2hIX2imtjLvxVNGyEv6HPh0aVBc6Znc993IotlD XzXAuNguWzKCiisdiFjl9FBhi+jXzArCZiTtggttrCqV9LlTDt/XJx75LWQTohXtD7IB RyzQ== X-Gm-Message-State: AOAM531du4O1yjT3Rf1xKR+c6cjeGeb8tr1cAZbFu1ZssI6z0PLGIz1o NbPNsiAr+GTMr9gwpvquarz74hFz9UG1Xw== X-Received: by 2002:a17:902:e5c1:b0:15e:b847:2958 with SMTP id u1-20020a170902e5c100b0015eb8472958mr3876172plf.101.1651607328239; Tue, 03 May 2022 12:48:48 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 03/74] semihosting: Improve condition for config.c and console.c Date: Tue, 3 May 2022 12:47:32 -0700 Message-Id: <20220503194843.1379101-4-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::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" While CONFIG_SEMIHOSTING is currently only set for softmmu, this will not continue to be true. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 May 3 19:47: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: 568962 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9774919map; Tue, 3 May 2022 12:58:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzmS6WhYGByESRUE6KMn2YRqCyvptBzpTg1zWQfylh93cRMmEMaTVpsA+jovgx9nQ1M+l8h X-Received: by 2002:a05:620a:24c9:b0:69f:400f:f59c with SMTP id m9-20020a05620a24c900b0069f400ff59cmr13379842qkn.466.1651607919281; Tue, 03 May 2022 12:58:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607919; cv=none; d=google.com; s=arc-20160816; b=JjRyDXFV3iR7wIvoEQXPXFyD050S7zzJTWpgIOnXzaTkICvjctyt4t0afpI8LoPAdV xBE2dQiq0Ap0GByfDwLUEsaFmh6ptv/1klTvVjDFlcPDTEGHNn0Xhua+XtKjvtRMy1oB L0cy+KPWrjUqWQuP0UcsYTo+9MgiQ5ThicJ1NSXPs1WfgwSprr+axH5FZuf3o8ou5b9v 1imooQm2HceVIcH9JP+hpPhc1HxlyYCvVBCJPdShIprvrL9oWC7PVcsgCd2pfjAWlMmU 49UZSbAue+Pczuu1Z/4RYGDTJJH49zZQAaPe/PVvf4t417/okQonz6YmP1Dv17u/2NeO 5ELg== 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=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=iy7Iz+g5HGAF2W2mVohbJY6yNnNrGJfCGSzz/1YHJQv1Sf0xT9Ov5PFdNg3wyu+NDK gkigyISY1aHPCH+uUApNA9SCqepeoYHM7m8DXIlrm6kuHeBXjS1Isu4LQBox3kb8CARX MLF5w/4m2I0lOvuuBX5F0bd9g4hP4CloVv3JWeep5De4AHwNK+m3DMtCXOrYSY1qVWXM G4SQV2jo7ZO54LlC65x0Id+9uG0auX6dXyzcR53WxCuFh0420SaVP6TfARNj5WhsnH2I 4fFtG9+NGntwCTogYIoTLWBTC09fGlWG0BE0Pph1cft+5Ptp+UK5ycZ6yza9pVKQPH5V /t/Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Ap8tlY1/"; 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 dt15-20020a056214098f00b004564ec055edsi8031426qvb.237.2022.05.03.12.58.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:58:39 -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="Ap8tlY1/"; 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]:36282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyfO-00031e-Nv for patch@linaro.org; Tue, 03 May 2022 15:58:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38854) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVw-0000wK-4A for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:52 -0400 Received: from mail-pl1-x62a.google.com ([2607:f8b0:4864:20::62a]:44583) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVu-0003WE-D1 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:51 -0400 Received: by mail-pl1-x62a.google.com with SMTP id j8so15854448pll.11 for ; Tue, 03 May 2022 12:48:50 -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=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=Ap8tlY1/zvmj1NdsBqP7L3lr7TWoj7dETfMi8P6lmSeifw+nXAEx7F18kBuibwXh4A /YFgtTuvk1q792G/pTJQyvlDj/HdUEyeGVIXR5Oaua10WZHmEvCtrCBeQuJSS0ASZfQQ PLkw+hzRvDqEcAt+tw7dSgfRpZCDZY15nndRk+ZFoW8KOYP8Jr6I3aRkyM6op698SWvT w+kWhwKfy950+ULD3aAT11RCpI2jJluDX9e0ezUHD+rg/kPEzJFylDKquYsFDdxZzWbG 1rLRiortOzOWkCDFj5E4lmpeF35g9sUvplOcsi8ap1Z5zJnJjoA8+TQE+tuJ3wqTARsa zWAQ== 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=x8BxBi+dxwcNinwm6heDyciERoofO1ytsNZ6JDtu0RE=; b=4AMQsKaROxFo6hDGu9nu4o6oWsvOYpA7RZebOZOOdHFnMZBxZDlzu32jxjuPSeKD2U XCUNwnh12b9JHJ+FRXaabqfMnzBbbTZr2NgBo60LgqHvZPrn564y/O6rkSWjGqWMm6S5 DACwyqUck2tgiQZtFY6ElIyof6WWNMhUHDCjeDijlUhgcVRMbreR5ojbD24xQ0tbfVsA hB1w5430Q4CtxpDtWjF58/bwOrJHjZjWQSTeXHl74bOllltsWAtwbfKIgmvc4LTKqLoZ HJM2PuHhTkHZxkasa6n0E+ZNMduOOvYuT/oWxEh2zS2ETi9iw+/wCnHYdqF5CgKrZPwD qq+g== X-Gm-Message-State: AOAM531f+Xux1ikuGRFpNCptx24RkSzVTPaHtIafrc0UWPKh3q8Qh1Nq IYXwdbNWR1iVYCo/gv+pEeOQaeuvIMb7ew== X-Received: by 2002:a17:902:9b92:b0:158:9b65:a78 with SMTP id y18-20020a1709029b9200b001589b650a78mr18564198plp.53.1651607329039; Tue, 03 May 2022 12:48:49 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 04/74] semihosting: Move softmmu-uaccess.h functions out of line Date: Tue, 3 May 2022 12:47:33 -0700 Message-Id: <20220503194843.1379101-5-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::62a; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62a.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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- 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 May 3 19:47: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: 568959 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9773273map; Tue, 3 May 2022 12:55:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx9ujWkNLQsCnXx1QrOOK6F80Fh2wRKovApxy+FhAquLXrnW+rAJKg5MlRvFQsGA722fW13 X-Received: by 2002:a05:622a:5d0:b0:2e1:d430:a5c9 with SMTP id d16-20020a05622a05d000b002e1d430a5c9mr16468376qtb.639.1651607752331; Tue, 03 May 2022 12:55:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607752; cv=none; d=google.com; s=arc-20160816; b=SoRtCxszsCX4ikCqd7Wy/FyHT21lGEBrO8DD8UMOqmgKWgmBbncLBa0qrAb7rq78F3 bDdTRduP/DoIE4AIZRADK5UDYDJ2l8RNiqtwU2OHNZZXutcSYpsaDOgrpjGegIuZ/jdH VaJrDjHv2hUQd7I0uhK96eNBj31m0voivGB5GcLeTQpQfnLxOHZf1dKTMyNmnw9M9B4j QVoT1pFDY0VsgO+2fXCxx1quERYfoqVXIsQFCm3nCt4VJzWT5OM+yf01W6gvhGIxyFGn 8RzCuXskmFCIFxRmvlLNpy9wWVD9dvXYTA3bTjC9/49/Jms3gwSTV3L6geAYcSrmpuDC CK4Q== 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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=rcLYNFFBIMPyJgzu/UquODk9ebR2bYWPDjPaBR/eXM2vHlGFlJu/Ej1ZbOTFUhp2I8 zKHiQl3agS1oUesMlu67KrV4zu3XzNtqx56qm0fRIdEQ2NW3pI+b3J36Fh+IKC72RRcN ak7SvagBmOh0RTAvy08NUEpt36Fg3MsF7w9ozUDAcA1Hhn5pOQTj2bhES0h162cDRSgJ cE4Ty2uym/uF92jXUW8CBdokiEe9C2VjFafhHCOaisx/qHSkM7FmsFcdPJUhxyeu5Q/w ApTVVvx+nkHp3zbqeXs/jFYYZdlt6faw82NA0lSNOESy7Jo1SnDvT6ojATf9SnDIUXkM igTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=DQQOZkS4; 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-20020a05622a104b00b002f367a700desi8190359qte.238.2022.05.03.12.55.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:55: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=DQQOZkS4; 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]:57268 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlych-0002Wv-L3 for patch@linaro.org; Tue, 03 May 2022 15:55:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38876) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVx-0000zk-DN for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:53 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:42873) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVv-0003WZ-Op for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:53 -0400 Received: by mail-pg1-x536.google.com with SMTP id 202so4542546pgc.9 for ; Tue, 03 May 2022 12:48:51 -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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=DQQOZkS4g5w1HAIASzVcGpUOvgy81o897RsNehNQ8S2/PsQMU7DRIfglJ/vPwK9SAe tDQM0CPLyfXBXnaRdPcAuQri3hZ+e/kiPhYsE/hdhz1NnYMv+K8M6JSGJkPdGPF9oHVR /OWs7YhNSyUFTm5neasruoE9RJDlN3Gan6ROcZQMwiHMKw/99ixxxWF/xWDLf/+Expj+ 0GdFSX6N6VahEF1h3NyyLYfpNJdcCeqK2Yndytr7Z8nmtwY4NX1D5cZlX5ybyMzuA3J4 x3Q8hGgZEi1hNHjOKqKmetkmeMYzYgNWKAi0A3F1RvDCP/8zhqR3SuZf2iRvolWUi16s ANLw== 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=B0IjewfhPoB21mUL+ukAhhgR2+vOUEMvAP9pcUk/okk=; b=6d7LutO5nNzoniDSmUlIiILi9p+xIQ0USDMXBwOFwV3PMJROFyGRGuqPulZMkzEtzS pHAlsGi9w5p0Y4RNU74WoE1nEwOCzGsTIg7uaxd//Rkn1moGcZwNp04IzCa+KF6cLo3E qSijyJyF4xJ2zpf6ejNH7lhKO+m7wGXquk3EqbEpu1xGTfFD3dk6MSNiRYId++f5a6aK LWuJZd0TvXV7XhrHLnwEp1xHKEZV4NnZ100LDsC5UkxCtzc0MyriffDNiE/c84FpsCY4 Zcx0cGa9NZq6Qin3D0tmR/HTxSs2hPmCLHAIsQG7Riv+muwTfBq8FSXQeT8eGzv4DZSo u1+w== X-Gm-Message-State: AOAM531tf0RmvnwdVVsvqlpqPp0+yA4wj8XQsl66KWy5sSDSaTaWHuF3 QpZdYOK6QhqAZs9ugbFH4htp1suVEutzkA== X-Received: by 2002:a05:6a00:1824:b0:50c:e939:118a with SMTP id y36-20020a056a00182400b0050ce939118amr17776383pfa.15.1651607330440; Tue, 03 May 2022 12:48:50 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 05/74] semihosting: Add target_strlen for softmmu-uaccess.h Date: Tue, 3 May 2022 12:47:34 -0700 Message-Id: <20220503194843.1379101-6-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::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" Mirror the user-only function of the same name. Signed-off-by: Richard Henderson --- include/semihosting/softmmu-uaccess.h | 3 +++ semihosting/uaccess.c | 29 +++++++++++++++++++++++++++ 2 files changed, 32 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..3cd809122c 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -23,6 +23,35 @@ void *softmmu_lock_user(CPUArchState *env, target_ulong addr, return p; } +ssize_t softmmu_strlen_user(CPUArchState *env, target_ulong addr) +{ + char buf[256]; + size_t len = 0; + + while (1) { + size_t chunk; + char *p; + + chunk = -(addr | TARGET_PAGE_MASK); + chunk = MIN(chunk, sizeof(buf)); + + if (cpu_memory_rw_debug(env_cpu(env), addr, buf, chunk, 0)) { + return -1; + } + p = memchr(buf, 0, chunk); + if (p) { + len += p - buf; + return len <= INT32_MAX ? (ssize_t)len : -1; + } + + len += chunk; + addr += chunk; + 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 May 3 19:47: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: 568966 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9777656map; Tue, 3 May 2022 13:02:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwA6fHi3DzquIod+7Y1OfyOxM1d+wX0U550oSCKN+Ohg0ZpfG53G4H8dNKtffRa6yHX6WZk X-Received: by 2002:a05:622a:1352:b0:2f3:9afb:5ab8 with SMTP id w18-20020a05622a135200b002f39afb5ab8mr16486567qtk.451.1651608151032; Tue, 03 May 2022 13:02:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608151; cv=none; d=google.com; s=arc-20160816; b=CcC3yDEwIFOBDVdJ4MkFdDkmkxGhXPnWCzLroje+yxAG6ti8C2F4AU3NV0FnqjIzDv umjoz4+OYixga1wIFoxzF2X8mEPCmG2tfdvXDil2h3586iLxTJEoTBJLqnAuXafn9avr ikjOAAv+QUgMeYl7CJqisMKD9EdQSC9NO7IBFgRGwVkA0KzhAdwBdUCt5jBEly/ywd8Q hneRkAnyaqCjH4TFmT9jEEOy3yJUzrGPBU875Im4x+SJy9UIZGiLtITlJ/EbmQmE0U8d d+ZMVq5xyMmIEXBDsO30HEEJ+INEh8iI7xZzz6W0TfkxI78bUHcpYEEH1B4wChQHJhY1 jafA== 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=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=KhZOis7ZIm9G/UnuZG23ZK6eQkTPFckPRFcbbjWhWUpKI7sHIFv3IlUGboweLjIlwF uWadsYqddU2IkBZ3NyKXDQub6cvhz8MfW0m2Y5TXIrDKzJqEtU6KquYbKUFrmZGRbdU1 jgjWDkvVB4/Pdli2HD6XMCJIfeLM3p5p0ecQgPLyw5GuUBqnHkJMv0IrGPDUPDEaBkWY bFG4uObEVAXNFXZq1fzttKweeDe/g7YCDvXaHxvoiIMNMERDZfZKTaHBzdMWQx2wFJvd Rxi7ypL8L4Dz+2ITUMSih/zjCccI6IJcIhL4nQqBbxSR9SJn4J5jZju9mmKTVDDXomF5 0WkA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CQu8NFjI; 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-20020ac858d5000000b002f39acf77d5si5875244qta.340.2022.05.03.13.02.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:02:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CQu8NFjI; 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]:44046 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyj8-0002Cw-G1 for patch@linaro.org; Tue, 03 May 2022 16:02:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38882) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyVy-00012N-Az for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:54 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:39542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVw-0003Wq-Ow for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:54 -0400 Received: by mail-pj1-x102a.google.com with SMTP id a15-20020a17090ad80f00b001dc2e23ad84so3204444pjv.4 for ; Tue, 03 May 2022 12:48:52 -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=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=CQu8NFjI5KIdFmNP/grBRFku9EHiYne5J99g7KsDQ51F7cdNQy1FgMjKXaO4s6Ibmj iJtzQHeUaYCH6SaKP4Jc+oenaMHto58Oo++eZiOanUDowgZTS9CdHu2AZPX4VqznmVZC OLcUc2ig+xGJ1jZ2fA/jsgcTrxDZylPtYHOJnSswOH5J9TLLLHJhclF7is7rSj6gLl4v QEXoKE2RBKTdIPRmNmJRILOVH64j0m1itiDt+MUDtPk5y/f5/ruNavNmLW01KTqWImHO OIWgc0v8eez6DyP8pi1fCxRxgDBI4l/NV2GDudSWznhAfL0Y+yqQ0r/0eZTdpckSkugg EEnw== 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=yYl4ubh19IwlWlMYqHs938Y3A5pmp6ChkIekWgSMVhY=; b=onmYkiPfuVmpjVgYs2AZDSvzbgGHSrTRyAfI3rXTusvxwwpxKWBE+ALQhWRNS8ctS9 lMIBmviRCFcCdJYVyLMM/gyg3raGvePR704ifgcCfiCErGOYK0M2Td/hcQ7s52P5XS6D o4Ewi+AUzMRnYcgnpdCjignAOzoWqYU5JzlYRDYeetr/+J/ErtLaA60quasWbUdH1g6P v2sqE2xuqfx0FoGPT9xm6BaAZG5xFAo93iTiKIOyDqSSNDR4/3Sals5Vkkf7CU1Z4eAf mta9tthoY8Kj5SDvJNFvezlCKxZACV/goQ8c8abhpUEQYG59zWUZLV4UOi3wkwcD3v28 tU0g== X-Gm-Message-State: AOAM530qVPxMyKUAvq5Aj3vqOABKh4N7XKYQWkld9+BoQvcdGogX2Riu RXj3PcW6z4YvRJaE1JMYYZtOEo8eOUM9XA== X-Received: by 2002:a17:902:ecc8:b0:15e:9e46:cb7e with SMTP id a8-20020a170902ecc800b0015e9e46cb7emr13056067plh.111.1651607331472; Tue, 03 May 2022 12:48:51 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 06/74] semihosting: Simplify softmmu_lock_user_string Date: Tue, 3 May 2022 12:47:35 -0700 Message-Id: <20220503194843.1379101-7-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::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. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- semihosting/uaccess.c | 15 +++------------ 1 file changed, 3 insertions(+), 12 deletions(-) diff --git a/semihosting/uaccess.c b/semihosting/uaccess.c index 3cd809122c..f5fc94c401 100644 --- a/semihosting/uaccess.c +++ b/semihosting/uaccess.c @@ -54,20 +54,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 May 3 19:47:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568965 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9775539map; Tue, 3 May 2022 12:59:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwU+3B4czdo/MP14iJGxbbuZRW4v4Iv1Im5djuZKCRJwjblK56KBZELu9zZoGiv9TQgMWkM X-Received: by 2002:a05:622a:248:b0:2f3:b478:d5de with SMTP id c8-20020a05622a024800b002f3b478d5demr1645165qtx.519.1651607982327; Tue, 03 May 2022 12:59:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607982; cv=none; d=google.com; s=arc-20160816; b=UqqyRCSHt6OsGsz+BtzhVmWZThqQBJPlAWJjeF1JLo0mwzguEMGipBZ+kwcT8mSRYg YQBWkQJNIb2XTESVCQ68z+Gmv6ce0HeOI9FKCeCBbd0OqShj+Yx4wHg86MManKnXQ7SH 9XnhnaIhk407yasrimq8u95apQ1S7REoiVBTrOGHd3Qccvh3ZkxbqIGz8e0CbTCABJ/p imr09oYyKzIzDdnUCua2h8nKZlM0y99Pv2awtf6I0WmVRIDc1O5B729pSoI1LFh50LBb 7T4Nf8MgN54SAXa6sArBzJEl1Jr08PVBYbzlGyFi1c+2rKkb/Rnkg3RIEnZFxkiE3CBF MQQg== 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=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=XhbZenvGnfwwnT79Dcxx1mvucXbVHGieOJ0nmLoHo2+DHytwEA/3DOtSHB53rkVM/H c53DaY13YFgTRA8+oz7QMsL4FigP1sC7dzQTeRXH9pDQ8H7nHox8EcS93S6aM4Ac2Dqe NUJdG9myh9INaU3X9F0Up1bWlLwUR1A82UmjGRw3WS+h+8VryoVRSZIBuNphpp02Ka1E uXvHXf98CxTOeqHgFCNcMLxCPwIFkz0J3FnMpjMAzZ7Yg/YVFpqAeKJ0GCMA/q7DBT1s 3cJJpslmAJbncufCxEiVVCIz/ruz6AIpKOCupN1P+vh9iC/AKQ18QhXXoFRMduiYVw5p JvWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=M2iTS49j; 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 s8-20020a05620a254800b0069eabe44597si9084006qko.310.2022.05.03.12.59.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:59:42 -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=M2iTS49j; 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]:39778 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlygP-0007TW-Ox for patch@linaro.org; Tue, 03 May 2022 15:59:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38956) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0001AG-MX for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:00 -0400 Received: from mail-pg1-x535.google.com ([2607:f8b0:4864:20::535]:34410) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVy-0003XF-9b for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:56 -0400 Received: by mail-pg1-x535.google.com with SMTP id j70so3886172pge.1 for ; Tue, 03 May 2022 12:48:53 -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=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=M2iTS49jC5fPxkJzVEGryyLmyh9nIOlKpXwWFAdAkuWlBDFzAEkBzv2gDbTi7KArbX ZKB1PP41NHkGFJP3EwIL0eR3YjHongXSrJkNtyhI83oEM4Hitmg7HJX+dYD5zUbs2hTM rQ54fYpVbaaplmzwbizEAUKBBUpTE6HpFG/qf4ZBRRmZdFL/AzG7FX7Y9fFnYPsnC3s9 h/nRDM+1KOveTN9zbmctMXG/S6jjZuCPD4OZNNXPrCoTGF0atC/I4amjS0nFnPbdsXje nGJRgEEUlqnfJ5nxynID5KhjrsvdoRGkA4WxecfzwH4vjORr6zQhvCZjb8D06BmDnONL lRjQ== 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=Rdp8FUFv0ef0StprWjSCHgZq98w5M9LAMIgcdDdNZUM=; b=1liSjbNRty7H0lA3EX9GHXB9wdL5xR5h2xSDGBclQixCHIAa/1Eq+S77+HLOBFGMcU +cDmlVeG+Kth87Ub0puEYlwGPCQwvVdrxDEbZs3czTwu+3U91GKVoGPDvZyk1KJPUZyx 6FVDjkrcpcaQDQ5lU43UFYaJxJX2k4Niwo/F80k2w0nChbS8/3xe/Pzc9Mx4bj9cUY68 3/u+N5Ugeqc4nH8EWCfUMQpSwsi7Ox9r+JIYNPBAQ+pKVITHJmzdlMM8hmM5bBJuwvO8 OYiXq418iSe6mCwEEmK6BnYfwiOMfyOBDSuu2XMZygUJGkyZ3Vtk4C5tW+qfjawCQAyo CtGw== X-Gm-Message-State: AOAM530iwXQ5vrDn2fVrEb/E3CCOq0YVax/JOKCry4OdACfRMxGZqsAw 4yLGUNbxWLOmWaRm2rCVGJTbdtugc7EZvA== X-Received: by 2002:aa7:88d3:0:b0:50d:a2d7:7f12 with SMTP id k19-20020aa788d3000000b0050da2d77f12mr12322991pff.27.1651607332880; Tue, 03 May 2022 12:48:52 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 07/74] semihosting: Split out guestfd.c Date: Tue, 3 May 2022 12:47:36 -0700 Message-Id: <20220503194843.1379101-8-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::535; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x535.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. 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 | 40 +++++++ semihosting/arm-compat-semi.c | 125 +--------------------- semihosting/guestfd.c | 116 ++++++++++++++++++++ semihosting/meson.build | 4 + 10 files changed, 168 insertions(+), 123 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..5d6e744305 --- /dev/null +++ b/include/semihosting/guestfd.h @@ -0,0 +1,40 @@ +/* + * 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, + 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; + unsigned featurefile_offset; + }; +} GuestFD; + +int alloc_guestfd(void); +void dealloc_guestfd(int guestfd); +GuestFD *get_guestfd(int guestfd); + +void associate_guestfd(int guestfd, int hostfd); +void init_featurefile_guestfd(int guestfd); + +#endif /* SEMIHOSTING_GUESTFD_H */ diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index dbef280b87..c092138031 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,15 +553,6 @@ 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) { /* Nothing to do */ diff --git a/semihosting/guestfd.c b/semihosting/guestfd.c new file mode 100644 index 0000000000..e77265db0f --- /dev/null +++ b/semihosting/guestfd.c @@ -0,0 +1,116 @@ +/* + * 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 init_featurefile_guestfd(int guestfd) +{ + GuestFD *gf = do_get_guestfd(guestfd); + + assert(gf); + gf->type = GuestFDFeatureFile; + gf->featurefile_offset = 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 May 3 19:47: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: 568970 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9781215map; Tue, 3 May 2022 13:07:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw8HWt5RrleT5p1vIr4jNMU5Oci7Y9uCmMYcboH/eWZANZe2qJizq9wOHpLq0DE6uWn5GyI X-Received: by 2002:a05:6214:c87:b0:45a:b06d:d8cf with SMTP id r7-20020a0562140c8700b0045ab06dd8cfmr891299qvr.3.1651608460496; Tue, 03 May 2022 13:07:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608460; cv=none; d=google.com; s=arc-20160816; b=RC1otuQfdFt+rsTeXZBkpP2dLzdECV2JB3zPI0pU6T5ukOQiiKSTyQowjEbVOLOH92 WE2VT1m/kFajEQFe/l9aUOjano77Mc+JdGSZ33uZ0P9tXPurE7Xo6ZPerrR4kvGs5Bna HOezb3dCrt5ZYvNOQ/Q2TXIShb1CRQchSjsdEUJCeckOd2/WxmbtaeDSnb0KCHbFMsbr ktDdbb/4VlFBk3RkN35trdKalny2sUHNrwGHpVUx2wnze8/nAGcQE/Lj3GyLkH104X5u JyxXD98mqO5JJs9HEGwcCYmcdmkh2ZyhKZR0L869kywnAPFRQi9/JFXMOUJfic0XpMEV v7Xw== 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=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=ucEKH/5qARGuLgt8vCfxXT76FD7Pc+EfO98SuWM5el/GQsR+gyQzRoW98YHx/mNpe/ ygaTFX6+pU/vVt61agSmlbnF6eyD/8MtvG0ZAYMJIn/eVGAApfLC5ovBAxJOQ2mI44Ek BbpWFUU8SEt0tBM6gAgx+KZcbPnRctfcimj4E+mRu56H7tiqyQYiexE3AQUirgmacDGI 6O+vSct8X4TKGf04qF7wVQz1m1doNnJBYZL5Ie/sXDlUxs/oGh7cjt8Zfxhx880KO5Fh aIdVj5HaoQc8BhFbZG6vIIrqDR4tmGSIHsG+JEUnEZfXG4iwFH3KuWixhthkSvfiM+KR b64A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S3QQ8TbT; 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 m17-20020a05620a291100b006a002b516c6si1625284qkp.440.2022.05.03.13.07.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:07: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=S3QQ8TbT; 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]:52058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyo8-0000bC-19 for patch@linaro.org; Tue, 03 May 2022 16:07:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:38958) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0001AY-NN for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:00 -0400 Received: from mail-pj1-x102b.google.com ([2607:f8b0:4864:20::102b]:56238) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyVz-0003XQ-8y for qemu-devel@nongnu.org; Tue, 03 May 2022 15:48:56 -0400 Received: by mail-pj1-x102b.google.com with SMTP id r9so16218584pjo.5 for ; Tue, 03 May 2022 12:48:54 -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=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=S3QQ8TbTC+eFCTQcugP9X3NsliEZmOYxOwCxD5YBKQgjo2tKfr3o4Txt8Cs4zgTNoy qfKQqmoAhT8TYaQSC6xVYxEHb3RbK2q+rc83OObLnERLXLDD6wyQFmcPMVZ90Smvd43E AFTGhJIcn75i5U+PoLeVYB2Y+CFgXQ6CnA2HNIeBW3rjWoFOQpBtOntECfhJyfwbsT7w M7vjIY7Gag7KaLYYy55MNl3c9ltySc+ohzzMGjM9CGulT9OtLy0TWZfwZzVjEgHEIZdl QifNFUTUfHE5k1T+2EHdBofBpoLzL8Lu27IK7lyDafFRi/iIqDiWVq5l9/qRAYLvC7ZQ Qixw== 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=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=LetmW0ciKF/ARjbMKJaDYjxr0FMSshUl4EatgPPOR0C+Qmwxcn9vHhlOxrE5pnF289 REn3IN3v+cLY85SkyUGYSdKwGNyaZdpxsVdh6WXjqpRPQZpowQWhwFXysttMSEgS7SzT feVoyAKLAShm2Z1nnhK770XF99HQZX/jIzfW+QfjccaNh6dU7/O+LrC57knhCkNjLkmF 4f51IiHVmsLR3j1T8iGJXLzYJ7a0R43+ZKuPo2wRZOZC8tinNwsMCVhgOr5WNHmRjBYV c2G3uW9sm+BbuPxFhIHorw0zDLjYKzRzRasJLUkjFZDaSmyHWkmWu6ezQGbE6X7M0oCb 6Z2Q== X-Gm-Message-State: AOAM533OEm/5l88mAV9LZB/7J+/KX93Li0tWdXo7Odt/a6a4tU5Aauyy ffQoLNZqEfKZ3u1QNnonV53U/j6O3DMx4A== X-Received: by 2002:a17:902:b106:b0:159:5c6:cb53 with SMTP id q6-20020a170902b10600b0015905c6cb53mr18373702plr.99.1651607333962; Tue, 03 May 2022 12:48:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 08/74] semihosting: Generalize GuestFDFeatureFile Date: Tue, 3 May 2022 12:47:37 -0700 Message-Id: <20220503194843.1379101-9-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::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" Rather than hard-coding the buffer from which we deliver data, pass it in on initialization. This decouples the feature from ARM semihosting. Signed-off-by: Richard Henderson Reviewed-by: Peter Maydell --- include/semihosting/guestfd.h | 10 ++++++--- semihosting/arm-compat-semi.c | 39 ++++++++++++++++++----------------- semihosting/guestfd.c | 8 ++++--- 3 files changed, 32 insertions(+), 25 deletions(-) diff --git a/include/semihosting/guestfd.h b/include/semihosting/guestfd.h index 5d6e744305..5aa2722cb2 100644 --- a/include/semihosting/guestfd.h +++ b/include/semihosting/guestfd.h @@ -15,7 +15,7 @@ typedef enum GuestFDType { GuestFDUnused = 0, GuestFDHost = 1, GuestFDGDB = 2, - GuestFDFeatureFile = 3, + GuestFDStatic = 3, } GuestFDType; /* @@ -26,7 +26,11 @@ typedef struct GuestFD { GuestFDType type; union { int hostfd; - unsigned featurefile_offset; + struct { + const uint8_t *data; + size_t len; + size_t off; + } staticfile; }; } GuestFD; @@ -35,6 +39,6 @@ void dealloc_guestfd(int guestfd); GuestFD *get_guestfd(int guestfd); void associate_guestfd(int guestfd, int hostfd); -void init_featurefile_guestfd(int guestfd); +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 c092138031..c6bfd4d1ba 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -553,13 +553,13 @@ static const uint8_t featurefile_data[] = { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 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 */ @@ -568,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; @@ -582,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); @@ -595,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 { @@ -638,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, }, }; @@ -765,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 index e77265db0f..b6405f5663 100644 --- a/semihosting/guestfd.c +++ b/semihosting/guestfd.c @@ -94,13 +94,15 @@ void associate_guestfd(int guestfd, int hostfd) gf->hostfd = hostfd; } -void init_featurefile_guestfd(int guestfd) +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) { GuestFD *gf = do_get_guestfd(guestfd); assert(gf); - gf->type = GuestFDFeatureFile; - gf->featurefile_offset = 0; + gf->type = GuestFDStatic; + gf->staticfile.data = data; + gf->staticfile.len = len; + gf->staticfile.off = 0; } /* From patchwork Tue May 3 19:47: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: 568960 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9773885map; Tue, 3 May 2022 12:56:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxYPR0O34WjD1vAF4KCFjkkcuOcQxiToXCA+5MDUr/fobBUeX+kg8PLyKzc/uhwNpuUn7DX X-Received: by 2002:a05:6214:c44:b0:44d:adfa:612e with SMTP id r4-20020a0562140c4400b0044dadfa612emr15007525qvj.3.1651607811990; Tue, 03 May 2022 12:56:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607811; cv=none; d=google.com; s=arc-20160816; b=GC/y7tkxQv9NAyIgzdirA1G3P63OgAf64W0EEne54LCrCV4An408A2ZTF6NO8oNiTm PFbHq1jwz8i6vF3GvyhkFpVFkHazLesbLkOudgqFWoH6UVs9lV5LDDju08jn51eQoCGu BgFF63SmQ1ekuq8e9UAimGQAh/46vnEJhke8qO0HVR+GPz0vDAP3Kix3rInp/lWB2fVj GndgfzZbfOuC+RhgfjbE80kw1543wu2XuCa9lzUyIur5IzRLCeB8efsoacYLlxRUYsmZ 6QFD5K/OleLg+SfGRzY3CxRex5sMIDc3r3bBndA4uWu7mCoQ9t1aPaU5rfOiPETJgtFb olDA== 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=RfNrr2MMNRj+8Yx94MQAihFWVTbLoFVuTh/kk6HikyE=; b=ZD9JBYcX/nGiXB+0DSV9n61/Y5mDm3RhHhS6qmJa1SeTs2+GbB3suBn8cd21OcYsIS OvFaB1aPmubC9bT995vimeX0mm6VqKdXh3a0jkh20K7XKw2/idMvn2CLetQ+RWLvZpqv Nehg6khfQkr/y31c5McDGJoksaJ3HdRUZ2sDDWJ6bcfEv+ktGFTl9kWRe86USJCrlGVH 3+lZvUsUSxOLKSELTcIg+8yBuUGbidC0fGrihvfRTb3cIT5TfZz/ufwoqkU9aorJk8Xs yVwXynDr2vkmUSF9dcaklndsqZbdHdrnnAs9vHt6FIhZrG390tSpuXnQ9NW7OAdiSfRE 1puA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=PQKUmgPt; 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 o22-20020a05622a009600b002f382f4e391si3312394qtw.437.2022.05.03.12.56.51 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:56:51 -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=PQKUmgPt; 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]:59998 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlydf-0005Lu-Fs for patch@linaro.org; Tue, 03 May 2022 15:56:51 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39106) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW9-0001WZ-6M for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:35763) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003XX-Cp for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:04 -0400 Received: by mail-pf1-x42d.google.com with SMTP id c14so6715689pfn.2 for ; Tue, 03 May 2022 12:48:56 -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=RfNrr2MMNRj+8Yx94MQAihFWVTbLoFVuTh/kk6HikyE=; b=PQKUmgPt8zOo2pAcL7bd7ErREtht+3gCXdwp13vCpg2huLEsunAFVBrpbSiXbsvih/ 3+uUXIjpSayAZCE4HeYl3FjOmEyQiJNm2G+/TU6d1KHDeKsbDyDFkSkyJBXWtRyezyJq oK4tJMDMDLDAeP4N0cEbY0ltLcaV+yAatH0oXkxY+ffzu1XnGlWLqSzOePrrjygiwL+I Rr0ptWMq2oCqBlcYvueshrPL1FrxkP3vJjjB+1Zvw+99+f3hr5LPzPSlXRRlNZo5Z8ww 3p7IakFCqgJRktyW1bYwXXFUBNirZJ8HFaovZMwOxokB4lXWV+eb73kEMMQhrzhqeN7E IIaw== 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=RfNrr2MMNRj+8Yx94MQAihFWVTbLoFVuTh/kk6HikyE=; b=DWNJQLn9fBwDLV6pwn6tGsfPNsm4z2fl+hgden3T9pG8pugCmkpSPVnE3uj3VPcjLZ H2N6b0wPWnVxefoVFRh6ZyP+31S8e/PrTFY2Qc5Gto2YfDrW8wX8Spq8wqiieA5M9nDN /U5T/Sdqeicl+ac5o8lW3EQmrQBQkflzo2ZEuBYV6bli1Js4S0PcMWofB5EI+mdXWbn5 qQywGNnqpt1kgKVmh8lQOXU/XbXnrpw2flsX6CdHaOvUo3gfX9yW3vchpInZhFvFLerL Y/tNVY/E9OaWn17recXmSG1U/4EBDur8g00YwGhr0xOntkNc09ATfJuoSouBnhvFrW5q JkLw== X-Gm-Message-State: AOAM531/69TU4yZxaPl5LC5MMWsWiWBZ9DZols1IAaz8dx2xIpog0SGC cjhU4ze20vMecvKhpT0MoTeotLzuSQKdSg== X-Received: by 2002:a05:6a00:2484:b0:50e:68e:d5a5 with SMTP id c4-20020a056a00248400b0050e068ed5a5mr6432354pfv.47.1651607334974; Tue, 03 May 2022 12:48:54 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 09/74] semihosting: Return void from do_common_semihosting Date: Tue, 3 May 2022 12:47:38 -0700 Message-Id: <20220503194843.1379101-10-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::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" 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. 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 | 571 ++++++++++++++++------------------ target/arm/helper.c | 4 +- target/arm/m_helper.c | 2 +- target/riscv/cpu_helper.c | 2 +- 8 files changed, 278 insertions(+), 309 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 c6bfd4d1ba..7030dfd587 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 @@ -290,28 +276,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) @@ -351,9 +338,8 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) cpu_memory_rw_debug(cs, common_semi_flen_buf(cs) + 32, (uint8_t *)&size, 4, 0); size = be32_to_cpu(size); + common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); - errno = err; - set_swi_errno(cs, -1); } static int common_semi_open_guestfd; @@ -362,64 +348,32 @@ 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); 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); -} - -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); + 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 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. @@ -427,113 +381,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 @@ -553,63 +500,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 { @@ -668,13 +609,13 @@ 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); \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ } \ } else { \ if (get_user_u32(arg ## n, args + (n) * 4)) { \ - errno = EFAULT; \ - return set_swi_errno(cs, -1); \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ } \ } \ } while (0) @@ -694,7 +635,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; @@ -714,32 +655,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 @@ -747,63 +679,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); @@ -812,11 +748,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); @@ -825,129 +761,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. @@ -998,22 +955,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. */ @@ -1028,9 +983,8 @@ target_ulong do_common_semihosting(CPUState *cs) if (copy_from_user(output_buffer, ts->info->arg_start, 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. */ @@ -1043,9 +997,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]; @@ -1102,12 +1057,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)) { @@ -1137,6 +1093,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) { @@ -1145,10 +1102,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 @@ -1157,16 +1118,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 5a244c3ed9..4981a22821 100644 --- a/target/arm/helper.c +++ b/target/arm/helper.c @@ -10195,13 +10195,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 e1aa4f2097..55105cb0cc 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1345,7 +1345,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 May 3 19:47: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: 568969 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9779431map; Tue, 3 May 2022 13:04:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxKGgwCE+MPFbUnFrpUXLqNVZOOOMFLJBL4tbXEX4C+uhHY53Dx3u9ObFQRIvjSZeHB3ONn X-Received: by 2002:ac8:5b51:0:b0:2f3:8654:53b2 with SMTP id n17-20020ac85b51000000b002f3865453b2mr16430305qtw.300.1651608299401; Tue, 03 May 2022 13:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608299; cv=none; d=google.com; s=arc-20160816; b=Mq+aFylrxeUoihCJc58kHtx1AWuyDukUEEqEGJlVcWrDmBYxYRbbI7TE8uQok5H/k+ 6/qp0ib7pF206EouKH2cK6npkzqTQ/CYLn65X0DnYZJF9/A8LrEnkHYHj2iy5ICKnwBB HT70sHogr83wXzwjwmULGwwVPrATcUY9ImUTggEf4ehV+zv/SNzPbKnvLGYzZD6cQc4a F8ssSSvLILq64gesoQUsOs9FQvQIwXSz/0WSTQ0pdtAIvMCkPu4wNMZ2nReYHwlx3g4W gJ3/QEUkTozkQsGuj84LF6nX6uuJUZTCnQecN5AXXqedO+PHsd8++szalTLGv3Pj+6EB tWLg== 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=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=y+VwtVD4IukizXKgcBoqGEK4F/YLqNw+jGd14SBDsZkCBSZkCr/WgKAGIQ57V3pJL/ 0mT7pRkDObshozhCF4zQTZf+qCwkYz8QND7e/eOiCYmwVrNkcsEe1/I+VXE8IRY9YD8Z zmnPM+0k+jYw7wLJwReatMxNjzrmFNSs9Ecv1k0/ywRZJaXuCPn8gnuw6FMj51Fin0MP qLkyARIj89OFFxKJqZhQaCKZwIqr00Ha52G47xHS4u4CrNjaPilJkE6/uAGzD2dRKiHI OPUNGZ7R2rBWfk6TfhQ/PwHQmbC8KhugNLfLqyaTiShxAEp60Tn+p359cRsVQFSEhQ1L UWkQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+M7sOnW; 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 m126-20020a378a84000000b0067e4be2384asi7956241qkd.143.2022.05.03.13.04.59 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:04: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=W+M7sOnW; 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]:48034 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlylW-00053H-Ts for patch@linaro.org; Tue, 03 May 2022 16:04:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39040) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW7-0001Nl-G3 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:03 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:39542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003Wq-7p for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:03 -0400 Received: by mail-pj1-x102a.google.com with SMTP id a15-20020a17090ad80f00b001dc2e23ad84so3204444pjv.4 for ; Tue, 03 May 2022 12:48:56 -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=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=W+M7sOnWKH4+sz4oIHDL1NUrIdYlxisX00NL5wkyu1dO0mGxe2R3gBQRXA7T/n4yEl mtdZ9gvLlurO0axgbzgE8MayT6SITdDzKoa7XoZfDJBw4qQBTUrEoC/XpBZ7HKUeW7kN C7/k1tOzJDDE/nXo2aL+hOzfxc0YggsvQscNaYlpifl9C9+8dnrCOM7dw/UO3XZtU+i5 OJZF2rvyA9wHNccWgVOazhau1i1OmZsw4xlMkpHJEuRGj0vKLhtON4tF7o4zR5YBgEpv hxJTEvi8JQdZmAzmvkDqX9RMKwHC1mp02hp1cTylinevt3GpeM0kVY/fQriZqM7YvcOF OASw== 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=D4UV//9Dx1fKTWaO/CeFVHK/oLn3ZgWAg/jUv9V5umM=; b=CPiGVyYAMnfxYqoV2GQ84sTWZmBmtFBl+HFOW4yxQmoLqTFxseEo7p1UNSravDAnZD hE4r1R9Z8KEw9se3E3PpHYybzSVqtB++gum4AwC9/WkmHOX/XljBby54JTLu1pLm9SpX Jh9sUlW+jMDJMRp6lPE6+Lx9I4a0FuTs8NU1qFegj3aEYFMgfYNq1NFU7e6KOkQgtB9H PS4BE4x4KaLbZ7/mObVyiZCHYFxJTnL8Te4rqZL27enI4Db/8NJOoogESmjRsmx3ngw9 X5cPuv7xCNmUbOEO03pLBjW9vzLtkOTA4SO1jBhIQlp8jmjwiC5J4V4/izB2jaNrehsT 0l9w== X-Gm-Message-State: AOAM530/HQ5EECmukAWem8i6N2ebdnXkBfFzJaJZtYFXDJAGrbvROJkg l7awsyyrR/AoetR8TYGcfFpqJ99kZGl71g== X-Received: by 2002:a17:902:eb85:b0:15e:bf29:bd9f with SMTP id q5-20020a170902eb8500b0015ebf29bd9fmr2104357plg.135.1651607335759; Tue, 03 May 2022 12:48:55 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 10/74] semihosting: Adjust error checking in common_semi_cb Date: Tue, 3 May 2022 12:47:39 -0700 Message-Id: <20220503194843.1379101-11-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::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" 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. 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 7030dfd587..18664b1c47 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -276,7 +276,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 May 3 19:47: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: 568978 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9785315map; Tue, 3 May 2022 13:13:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz/hcxe1J6J65CZ+L7rDJDsUgU8bvTxOJHibri8lk2rtucEzov4HS84ML3lfiLULrIKw6SZ X-Received: by 2002:a05:622a:6098:b0:2f0:f0d2:b5f0 with SMTP id hf24-20020a05622a609800b002f0f0d2b5f0mr16175972qtb.583.1651608829808; Tue, 03 May 2022 13:13:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608829; cv=none; d=google.com; s=arc-20160816; b=dqau9TbhemRMsgHWsAoe9syTDZ0mCTW6GBfjAHmfatzHJBuQasulWFhc17k827heiL oXqEhT2ozC8ljEn5NzrkIWN+xqBFsjlgk+t/8v1Ks4Py48vheM2WNiFxS5znScwUfh9C OEZJxCFU+zwyGbE72hBmym5hR+yBCkhK4lVUuWvppUUc+/788rnAE8jJIs56cPit+lbP EAiy9+InjnVKDCkXFzS26EQ3euGiKxGNyjBOrpyXAe0uTBmhH1W9PjNnOUMX2eGQN3oE QfkMjPohDiSYeLgsi4zJKem0jnZywDsddPBgol6ZX364gNsZkWzowq4ulaw4ELvB8wBb qSFA== 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=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=dt9+Qbo8MKflhXyCsn9DusvVWSpX1alHqUgy3USyNbidA2+eq2yQdWRIoZ+qoQdkZ9 S5stMpNl5dDXG10dPz2wx/VeN6xegvzXCXfA3ptlnYWPkcPUEVONED3dGUGmbFcW3SuV QpHlkWXjRSFmXnQ6BSpQuynYlyydamTbY3SqVve0hwcLgRqxjWM6PCg2B7vcIM4j2VqW w0D0qzxrfitmcQnTQD4U6WgBbi7AsI7E9TVEEOEYkiccWr97fAnZ2Bj3fOWkzCfP9Xow 0YanDrljy5iLOEAGqEL2bdcds2o92+NFJckLPIPNHWZzc3yi8iOVZY83a8hf32dHZO2f IpzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=v5oHlKFl; 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 i19-20020a05620a249300b0069f567d37fdsi9742131qkn.588.2022.05.03.13.13.49 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:13: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=v5oHlKFl; 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]:39282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyu5-0006EZ-9p for patch@linaro.org; Tue, 03 May 2022 16:13:49 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39158) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWB-0001da-0n for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:07 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:44589) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003Xn-FD for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:06 -0400 Received: by mail-pl1-x630.google.com with SMTP id j8so15854661pll.11 for ; Tue, 03 May 2022 12:48:57 -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=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=v5oHlKFln1ctjaDmtcYOPVFlnNJ2AY1VCefdxEpPrhr6iqI8GV32zMwL1mi3eY1m9o Fp09PfeZKeO4jqjKl+L/l3lDw6lakjLyaiPitjEOaF9EvpICuSQLuhY2daLoUAf2Lu2j w0P2z6ENYQ6RJTNnS4+Xzp7hqUk2Hzs6ZCdrlC9T/uOR+TuABNkYlyIsnxerbkZRXvlK dZL1xWV0mGa/A8/04rQopr1QvtTAoFKiAJiPpC+TdpLltmShzXSsf8YH38Xwd1RJJPvV ErbN7ntxy2kU1qAjhULMRAEdRbCWd1+SZHhozL6tW61bp6i25rLkuVrATeGoYdbzWv85 QWGg== 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=uw4gme9KuFW+TrMXShBM/0VdYE8dR14VXRbCtedKveY=; b=6IRP+ptwWf8TA4c5csna1Uc30Ym9bAysGM5TPqKbMf4T9jsan+ssV2IPMkKStC3I7W 6jmHzxhwU/Cqnoz6RqXe4b8V+6wIQAnkeQRwrwhLv6dRwOwJDBqxI3lLo3+AtLE5IIFa rj74hOibwHd01N4xOU8ph1rVENs+Q2Le7qhK/dLXVcGlt4frRTi5tT+n3wDnd0nMzuQY OhdUq+MgNPP0iTWT2gZcp5/GnzfBO44o0/rpKH4Gj15CMnn6Hl6ckTMxnVXIaGYWJTUr DQtSlTH/OmCHafyMFkwa2GOHqDgV1k/L3mRS0Pxa+6dTGL1nGb6EtEIloa7XzMwHU8PD BPSA== X-Gm-Message-State: AOAM533RqnwHtjDZF5KD043SVZqDYrCwM7O1/3nG/1mQsaSsVPv7j6T8 jdGnUowukD12xzeUqM0R0zV+/c4oRTj9Jw== X-Received: by 2002:a17:902:e393:b0:15c:f1c1:c527 with SMTP id g19-20020a170902e39300b0015cf1c1c527mr18214358ple.22.1651607336683; Tue, 03 May 2022 12:48:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 11/74] semihosting: Move common-semi.h to include/semihosting/ Date: Tue, 3 May 2022 12:47:40 -0700 Message-Id: <20220503194843.1379101-12-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::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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. 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 May 3 19:47: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: 568973 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9781897map; Tue, 3 May 2022 13:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyf/0gi+aZgIa+tlG+mfWwJdAR318Nfw808xAzkWNXyjJsZOFTZbrwu4Wrwc4R2JIRr+uBz X-Received: by 2002:ac8:5907:0:b0:2f3:7cd7:e554 with SMTP id 7-20020ac85907000000b002f37cd7e554mr16502494qty.348.1651608511824; Tue, 03 May 2022 13:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608511; cv=none; d=google.com; s=arc-20160816; b=nfyvW3IcuZUuY5GC/7cxct+AmD4qJfAae4vraa+dvgWoml3kFFRc7Ep6mcmk6fNWw6 aAoKbz4JXaBqE17U8rmSgJ/T13qcD2l4F6a6jzm1siBFlXrHlT6+GXCD9LPOHXVg4Vxp 1kme9uaZnT6Uyc3hqCB75L1JTExV5NJazAWqaUQsBfp+6yBuHijpDp6NIVpMfheZOrut H4Fp13uGt2pTwtH5jnf2fcBVwTSz0IDV5n85LTr1c89BZ8qSNEjenjl1g8wvcbBfF/f0 fcNYkNFpDD5H+xddeFiI2Yk6EG62pJLX4Dd4BuquOZHlv3aA2F8h0oXHqtpJ+BM4FKGn BDOA== 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=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=GQrc17JjS/a6TBAX1UBX4mj5bz2FANXGHC8iHTAjUAXhjZwyA/691CLgSAeiRm7jiE 6MvWILxCRyhDJdhz9aODKokBpJzpUZYpKtrFptqs2BMAjQQlLSE4eRwvL2WB7bme+xqH /GQGiX2sh5rT4V9HOySq0gfdMxCpunztT+DGDHgkWLw7hi5HB6Mce8tyGIFwKTaPp9ic IWpbDi61ldy3l7Gqdf9+fdzOTOYPGU8P1XbGBhsADLBCG+pXXOCPLGT4fFisaK0c4Oep SJbSCf5T5wSE6/0QiHR0dzDmEmN/yvVkML39Dpm8HoMZlaSySVPpF2plMyZQZcD7Iiw7 e/0Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fECEga2V; 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-20020a05622a009200b002f3650bf452si8103841qtw.115.2022.05.03.13.08.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fECEga2V; 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]:55802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyox-0004gy-D5 for patch@linaro.org; Tue, 03 May 2022 16:08:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39068) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW7-0001QW-Vk for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:04 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:55185) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003Xw-G8 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:03 -0400 Received: by mail-pj1-x102a.google.com with SMTP id fv2so16237021pjb.4 for ; Tue, 03 May 2022 12:48:58 -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=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=fECEga2VAgTlWdGXRWCSw7ZJomvFAD+c/TlMFmWimvRjhPGcxFomTF5Zz+iTSRrhNC Ug/Lo5d2Uqx1na8FQjvQjWOgfZFuH6adBfWP196GukXo1p2hHLpQHVd8p7wy+PPzIcWt zBqq/fMXbgifKBHQGIAEHHnM+2S6DQiP7xpcGcgqRjo1Qp3X0u9A+JuNjCDv4L3UZ39a 7bh9m2rri9IzS5c3JGE2/W4E/kGxB7FQ16xE4MgWFM8Ie+zwatrqlb0dOK8CLcMSrwl7 nI/8tbyAG3kHXwoeq1dO9DTzEI0RVwXm601IIFEutdlI7LMWJOg4eOoDptr7gjeH3i6Q 5xlw== 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=sRa3I/Ez0AmhRV5BtAXtTCzSb0MQ7Gt+C1fZfKVXMvs=; b=qy7M9t7fqkmakEkPWveHJ2dViVnntBsiYhbxeiK6AryOlN2W9L9PaXJLZ2uM6BbjCT bMPqVf7CxGup+6UDpHaJwKScnCYagE+2Mwz585PXhow1OI+8gMZJe3/aIj7CPZWqtrml TB/XcekF3U/fTvwHo3lyCwAx2OG6GWTjahUfRSPtYwqgQWzl0AwyCwlC3AXaMcth1m31 hWw/hNQiAFG9YBwkQ7Z/0N42R3rMzYNHlSAO8nB8wKznGx04BjafxFM93owet+bqrwC8 HJ6X/26CEqGq/UokzYktjP6qayUGbn64fyYPlM8CniUDkvu/Cv6wFnomAI1Oa1YoJefy V2gQ== X-Gm-Message-State: AOAM531t3bwchK6p/eJ5+/TUoaGX77Z/yFp7Xq1I4Yv/pQ/hELuGhtt/ SNOJcaDJvV5aKlOatyBqw7J7dCVFHYnSDg== X-Received: by 2002:a17:902:b416:b0:15d:7f2:b19b with SMTP id x22-20020a170902b41600b0015d07f2b19bmr17988514plr.93.1651607337758; Tue, 03 May 2022 12:48:57 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 12/74] include/exec: Move gdb open flags to gdbstub.h Date: Tue, 3 May 2022 12:47:41 -0700 Message-Id: <20220503194843.1379101-13-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::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" There were 3 copies of these flags. Place them in the file with gdb_do_syscall, with which they belong. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 10 ++++++++++ semihosting/arm-compat-semi.c | 8 -------- target/m68k/m68k-semi.c | 8 -------- target/nios2/nios2-semi.c | 8 -------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index c35d7334b4..2aaba9c723 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -10,6 +10,16 @@ #define GDB_WATCHPOINT_READ 3 #define GDB_WATCHPOINT_ACCESS 4 +/* For gdb file i/o remote protocol open flags. */ +#define GDB_O_BINARY 0 +#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 18664b1c47..a1fc4ea039 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -86,14 +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 -#define GDB_O_BINARY 0 - static int gdb_open_modeflags[12] = { GDB_O_RDONLY, GDB_O_RDONLY | GDB_O_BINARY, 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 May 3 19:47: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: 568957 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9771672map; Tue, 3 May 2022 12:52:46 -0700 (PDT) X-Google-Smtp-Source: ABdhPJywffar9N1WoInoAuV7uCTCuaHAJ9yEsa2xb1f+2lqqy40K3mX/afJT/EgQFw1m2lTLvAFZ X-Received: by 2002:a0c:f703:0:b0:456:3799:b153 with SMTP id w3-20020a0cf703000000b004563799b153mr14861634qvn.97.1651607566839; Tue, 03 May 2022 12:52:46 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607566; cv=none; d=google.com; s=arc-20160816; b=jqDwX+esDCv4y18TDLLXw/pJgu19xmLKrnFDYufhB45jLxTpoGEwKAUHliTvHV/DOr gI2eKOt/8xcFslf1SkTSr8qohKtZiNdJLeAWC42JYWf3kLkFv9uxaOtlNHi8qe/Au9PC Z0d/YYWoB2eTgQ7/sL++0Ba+ZWwKZmmPcflDeceXwzy6NIOFrhAVpFk3xjwL8+1wkUg9 gLPbDpUwTSWNTB6vUDMwJjsuqGJSc0HjOpO5Rh89tWcm8KWBF9qwbe2TuzixWJsqN1Y8 mXo5Ruc2viqPHx0gVia7YGGGz4DF90ZFsMwEaJbo8amKNPN4T8a2tVKtWoJkhHBbzYRp 6/2Q== 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=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=UHxXB/okML438AD/QH9I0UqrNW4Oc55Kqh6Mn37+50QSDVlzeNlaRUiRB4o4+1VJUf FyZZSt//rMNzLgIRWL+2pdEA7nphVTQEWN+0P82DiGOJmZQZLN5pNADbB4teaw3RPtKH bXFwjRDxdqx5/WT4qsiVWUGM3sdtrjZaoUHPSjg/t2ELCvy+Tbk9ZyHzWLMCvmZjcYsK ROGQX90Se+c3r5NQ8gMUp3TX7ZutR6Cyh0DLY0bJ7E+34xw+n2+nc4S5B2/uAXYPyKze jSW8IKZWhQ8h1d8rfXjHjeVnbastWXNS/ul1XzhKDQpny8YerXHFZVIgSvZeE8cRuEyI Lfyg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=n1p+YBgD; 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 w20-20020a05622a135400b002f38bf9e02dsi6952766qtk.578.2022.05.03.12.52.46 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:52: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=n1p+YBgD; 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]:52180 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyZi-0004eQ-Cl for patch@linaro.org; Tue, 03 May 2022 15:52:46 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39052) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW7-0001Ob-LA for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:03 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:38499) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003Y2-Ew for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:03 -0400 Received: by mail-pj1-x1036.google.com with SMTP id cx11-20020a17090afd8b00b001d9fe5965b3so3213750pjb.3 for ; Tue, 03 May 2022 12:48:59 -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=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=n1p+YBgD6XI2JwnHgOijz7KfPR9n1UnNU4QtocC+XqF46pcmizC9w/iNgEmjKw4HBg esfQwnRa55pdJMQIQpLufB8B6PydWJAiaU8GfUM6Wn6RAWrhEE580ZinfF4lOUXm13ZA HEm/oWIiofnCqIIyJ7nX7cgthsIFAIAOW7cC/YtvzYrsPs2CpmNPpQaRYJEw5LqyfqeU NG3uC98XZt7oXxSBqOwog5PBETFsr9lcjIC9ep6HjunTPTxh9zS96GEfXKTbtypDdViF 9TG31i94jkGGP9FyCL0EG1lApL3bFvbO/uAlsmJC4Z5euxd8hPhinj73GENV1+BuSyhh vyEw== 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=o7WLR0F1itSeL1D48lB12rI6iLH/uoOr7m0MR0rWKoM=; b=0XSSAInd9yPkfEk8eHqPmfF9aQIhQwz/Ldso+/objxtpMTDSj4wLaztA/Sn5myWxho 1Igbrm6HvrQlRiZvl2ER8npBJ9PYD7C5XLtvoc94MZCkctV+WOUfBNC+swpPz8EsihN8 bR0pUZ/PPeRYMW904+7LEmEsPTUoVJMbCr5m47hgWLUqshLokE5WJj9wGE4Vi5ttcdaY j95obn6id5LkVmc3i3CIIXbHU1p+Klmomq9A/7NYFBuTRsZ/rEIOqp4TcAPh1g5gcIqF fhJV5kNWKCQTVRy3t+IfF1iXGo4/ASnly3L3lWe8cTd005khh240ZOBvNV40mQYXImNj +X6A== X-Gm-Message-State: AOAM531FjjSo4wIOAXisFZKY/t0gRy6LbPxWd3Ws4oi/e/CP8IVAesIQ oq9CEdvJB7gChoX/59GtlcAX9mdHuXtfUg== X-Received: by 2002:a17:903:2344:b0:15e:bc62:bda7 with SMTP id c4-20020a170903234400b0015ebc62bda7mr3159739plh.120.1651607338655; Tue, 03 May 2022 12:48:58 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 13/74] include/exec: Move gdb_stat and gdb_timeval to gdbstub.h Date: Tue, 3 May 2022 12:47:42 -0700 Message-Id: <20220503194843.1379101-14-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::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 25 +++++++++++++++++++++++++ target/m68k/m68k-semi.c | 30 +++--------------------------- target/nios2/nios2-semi.c | 30 +++--------------------------- 3 files changed, 31 insertions(+), 54 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 2aaba9c723..33a262a5a3 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,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..da0186f3ef 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,9 +66,9 @@ 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))) + if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) /* FIXME - should this return an error code? */ return; p->gdb_st_dev = cpu_to_be32(s->st_dev); @@ -114,7 +90,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 May 3 19:47: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: 568963 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9775030map; Tue, 3 May 2022 12:58:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz8ux3UjXCUvANE7gNYMc+LdKAPySzXjkA4XJVqJEdr6BwREvgaXTAyBYnlzPdS7h0kwDHL X-Received: by 2002:a05:620a:4f3:b0:69f:d693:b5de with SMTP id b19-20020a05620a04f300b0069fd693b5demr9223696qkh.1.1651607928950; Tue, 03 May 2022 12:58:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607928; cv=none; d=google.com; s=arc-20160816; b=ma82SmC3oWNT3qZckamAzNMc4A2FUfPsVtAIj/YEkwFEWOLtNa6f0rKTLQlSj6ftUY KCS3FA9nPVt+k1P+c/6BwXIcRK0hAE3wpyJgNAkx6oQp9Ke1loIMSFeulJmmcp+IFUqh noXBqrmK5+iaJL8ahOwVYGktmXshpPxvSE3w2pCmufb32fqqAd/JPaSRbctXvgQm5WR7 0fv8ymrk4wGJ4hHRdF+au9718o31HcjRJM/BSKM/g4gcp4S38hEpV7ceDcoox2viWudE 9YzveU3/DSsv1TtAF4TK948dh5W5lIHagZg5zLoU4dPFZsrI62E6MNxI2HDo9KgUER10 gWzA== 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=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=o/xnuYJWBxo7n7K4+6XsaxxSdjYllL9ejjsY9uh508w3YNd7MnT5sm/KhczzSadHnB 8B12xMmSgO0dp3EQSzsJeNAYoW5FzUIyzw7dDC8pm99ZiPlzVcmaTYwkn/pQ/bwRQFlA GQ5iT/xBrO0kZMT8Qz2tqedatZ+cs5SYdwszzWqIOdnlup9IVX2TiQjsNPshwXd4rOP8 3QkPLAz7f+vHVYOQscfTSst/thAAqsFFIL045BMWAv3V3BncqbSr2mssNS+hY7xWL+Vc kfZk/pP61xRBHN/BusQDVdvSchL5SvyP9pNUZHP0SKgrQeJeebWSt+lroVldZK2ZA7v5 xahQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=z5qul+tK; 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 l7-20020a05622a050700b002f200ea785asi8684731qtx.648.2022.05.03.12.58.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:58: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=z5qul+tK; 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]:36576 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyfY-0003Pm-G7 for patch@linaro.org; Tue, 03 May 2022 15:58:48 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39100) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW9-0001Vd-02 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: from mail-pf1-x42c.google.com ([2607:f8b0:4864:20::42c]:39608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW4-0003YB-Tk for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:04 -0400 Received: by mail-pf1-x42c.google.com with SMTP id v11so6093062pff.6 for ; Tue, 03 May 2022 12:49:00 -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=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=z5qul+tKrMWBjIMyxDqBAHSxaIjC8t0vuywF+XiC0leeeoVVy1yxxMD229Xbdu9Eh8 2O7IP+5ewmqq5TqYog3fxI1h74kJuShtqVRh+kxYF/0/iSvuDGkO2rgkO60hcwR6NDYu Bhv4/MuByOjl5x+2TLj/Q2x+M7wpDmzeLvQ3+J8CjlJ4EoNHFH1v1RaOtFtJ48eHKvNa erTwncCB6hgL09RlH8IFBUWe4oF7lFRm8ixKMBh/jCmj/G2LQSkm5ZAo+MbzwuEwi9j9 ed/7l5+B/TvVDIOfaBmI9ovExrgRxIkWihyiwPWmRPmc2SOIVWv7juVXZEbHgmUaZ9Ni xnhA== 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=WN+exJ1hbQPzvMVT+L6AO18pYzO8jIYQwhbqxtMuNbU=; b=smItWueoY9MIO6pHUJynHJnKa/YjG8A5S2J/3Fve9jezIB/RhRwRRXAKREEqe9XA09 oOh/5h08ZMxmEKiCtkIb0whSTWv/jrqTDsAf41X8DkZgGBuf8Dh4MtVZOX9PyUaRXboR 94sLGWpeSHQ4O3qFr46uLEhOJ55bbzBNi1n+MqVzg6EfszhRSAuEsMCKYO25e9d0/hQJ Zx4/yFsnia58DZXq6BKebDrIhgsyGrgJM0em8VXgYQ1l6MwK2qVuTRm+IFD5NmUFb1pO Ty6O328S6VmcD1vNiczIInEmbm6LVJPjiLOdwCe66Iru4NwwoxhHJEy6F3+LqQExZP65 YmpA== X-Gm-Message-State: AOAM533orzOLbMmdN/nVlXEH1dAiPWx6vU3ORcXiDy9xUXJhiQ8wABHC zskEWoBBOLGPWcG7EYwQFDoL3WtUHkBbbA== X-Received: by 2002:a62:15d1:0:b0:50d:3db1:babd with SMTP id 200-20020a6215d1000000b0050d3db1babdmr17760279pfv.19.1651607339604; Tue, 03 May 2022 12:48:59 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:48:59 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 14/74] include/exec: Define errno values in gdbstub.h Date: Tue, 3 May 2022 12:47:43 -0700 Message-Id: <20220503194843.1379101-15-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::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" Define constants for the errno values defined by the gdb remote fileio protocol. 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 33a262a5a3..0a6e0d6eeb 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -20,6 +20,28 @@ #define GDB_O_TRUNC 0x400 #define GDB_O_EXCL 0x800 +/* For gdb file i/o remove 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 May 3 19:47: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: 568974 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9783231map; Tue, 3 May 2022 13:10:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy0e7ffFxC+FZhK+e6QtQ4Un7Xqvy9tArwLcnxQ43yf5mcPXemEIRyjekaL0yWRcv82Jbr6 X-Received: by 2002:ac8:5c8e:0:b0:2f3:81ee:d6b8 with SMTP id r14-20020ac85c8e000000b002f381eed6b8mr16516581qta.561.1651608642499; Tue, 03 May 2022 13:10:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608642; cv=none; d=google.com; s=arc-20160816; b=VxjyWvMuENQ+Fm5t8G2+nkhG5Gz4wxdAIXyx8blk1XZk0p8pGsdofZ1Y+3IeYQISGc VLrmsP7AqP5cusQUJ00O9u0FdChr7xiAvU7ATvNamrsYXwx6HAfCazFAIPdyum56S5jL Qkc1rWLUvDeT37tIVTS9G48UpExUUo7Vvs6smuwg7uIeaM9RO+kTlVLxFloETVB9dTKX ver7zuAWxHRk+kz7W+NjCbHc7AECsuooBIOJEkCLiQXMdWykc+wNMlvhwIAr7jRE7lPc 6rEAE9uw63ylKgAJTwZsaM4jBTvc4usKTTPi28A+R1Mke7dnGGncbmg2lEAOKs7eXpGu CU2Q== 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=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=qLR9VIrdTcQLRrCyWg1qko/DswRSmtmu1HMZdiKycepWiKX70dUq/Syzs5XoBj4bFl WxERBX878lcgIMMeMAUKh9BnHIUpt9vt0zWGZwiCpO5uUfVIpe+xr0zeB4he5W98UMNV hKGqecyuEzCF5ygXfPG1iFOSrh9Kw2UJSiAzbetU/hm5D6c/ju4uHmxvhPGnNahNClTC HDQX5acuzLu5S3xsSS+ZP2D63f6gG4GoizgcxjexdAkekCgH1N3j4bS3wjFmZt0LF2Bp iPIy37EfxhlliaihmeprKj6ZMfHfiQ0ktcRT6EoTc/ZZgZCZl05okW6BUUthpnPNvxzu jR8Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=noZ8esmc; 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 n136-20020a37278e000000b0069fb3328f31si6098311qkn.488.2022.05.03.13.10.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:10:42 -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=noZ8esmc; 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]:59828 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyr3-0008Kx-VY for patch@linaro.org; Tue, 03 May 2022 16:10:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39114) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyW9-0001XX-CQ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:33898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW6-0003Vy-0i for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: by mail-pj1-x102e.google.com with SMTP id qe3-20020a17090b4f8300b001dc24e4da73so2280378pjb.1 for ; Tue, 03 May 2022 12:49:01 -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=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=noZ8esmczgDpg05wd663WFFXffzdEMFM03mebaYYoO2B8ohfDLWdle9XrHCNzxNF60 ZZtbyP/3hJ9BeskBpt5SvfmuguviJyXbwJOUfDftSNbKoA3Ewt/EL2RBoAjire9N9Zvq BbtCnBLeHIPOwYz4LvCF4nNlvV/cazD4xSb0WbSCldZn8k4iHkz9i4TktRnl+iG/+7Dc N6AwKogbVNIcbj5fO/oZCbe1PDcneRLliwyPjncE+vsNx0TDxFyvAqVcEfzVDhH5oWtc aFOH+SG82ArnghrIoF6Nqcsh7XB/rCgG4m2oJGEZZIKFJ7Gup00P/9dmODP27cnUKciK 61kQ== 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=mB9/XCqnXEyOKhpBk6W2/uLe4X0aD05IrrxcgIYWBfg=; b=SMawwPQFgGtYA6EYEeGBmc+4F8MTVnNcB6T+FV36Swv5NrzNVl8iQvqVqjPZ5IyhOG WNkyoQc3Bu3Ez9qNjA2zDagQpXS+RPwgXOnXaLFeCW+FHMTv8W2BoMcZIREYgHrNGQAe giqiouSb5yFjXtLzlwRuvqn5xhTJtAAV8HHgA1XP7Cwyf8IafsGgZnT6EdNjLf6eLqCl PAUSBtsoBx4i0TmZQDoxrClkri/yQ2dQ4wslA1f+nhqz0YYhBpjikvaP/3VSZr/lPQ9a +nbbMoGRMmgLOOwSy/LJt+m0ZP+I9nQtxlQlTIW+OYRrxQdXyuQ0H+d7QEDQ+y4kSY9y drbA== X-Gm-Message-State: AOAM530T9tx6yNid3YHzFbLp+Y3YXh/rA5aO6D2rmd4PriU7oDNxVC8n a9OL8teIBnexiMC14X0uOPoSspERVsc6PQ== X-Received: by 2002:a17:902:f24c:b0:15c:b564:e4cc with SMTP id j12-20020a170902f24c00b0015cb564e4ccmr17935919plc.137.1651607341128; Tue, 03 May 2022 12:49:01 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.48.59 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 15/74] semihosting: Use struct gdb_stat in common_semi_flen_cb Date: Tue, 3 May 2022 12:47:44 -0700 Message-Id: <20220503194843.1379101-16-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::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" Use offsetof instead of an integer constant. Load the entire 64-bit size while we're at it. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index a1fc4ea039..a6c6e5baf6 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -324,12 +324,12 @@ 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); + /* 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); + size = be64_to_cpu(size); common_semi_cb(cs, -1, err); common_semi_set_ret(cs, size); } From patchwork Tue May 3 19:47: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: 568977 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9784058map; Tue, 3 May 2022 13:11:59 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwh0ZxbWDA1XCCrA1LM/RY75Cb2mNF8CF+aKVJj5z4h/lPaVAuleN4x4EB4DH97XmDlW3W/ X-Received: by 2002:ac8:5f46:0:b0:2f3:371f:7cd with SMTP id y6-20020ac85f46000000b002f3371f07cdmr16690233qta.94.1651608719008; Tue, 03 May 2022 13:11:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608719; cv=none; d=google.com; s=arc-20160816; b=hl4VQo+VJhpvNmiJ4/UVLvk37Wkw13jGniY6dsG2GUuFGQcRcbSG4ass7y9xo5fh24 3K5ulqqPx3dfc7PfZAgNlDqfJq2ObnxQHaD3QlSstdDM5qO/NOg3kRtffPVAzh5zueT6 VlUNH01pjYe5XWoVztnX73ZejeNyJ3dL57+NHiNSA0HLoLMVvlqgHWhC8yVO4kJxy1uB t0mCW/fL4gfHo2bOUxS22F2qjbb+NBCvjcyWkm4ZV4NiGJ+SAXFYS+SXwSMsiY2waFtY Mmgitn05xVMYodTvlNjYErYsy28zlN28wYL/ugpOsRmjD099yoBe/TBTWazxR9Ds2ab+ oZ4A== 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=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=WCZiv8tH21Nff2PX/KlYR4BzooFpVuZJmxEzKZqhDObLIOk9VurFhw5fyCIdy/U1Tv L2X62eJ0W4mfDEkQKSdnTlDuLGAlqEQzytk9KySYnd9eWguEgD6vGUVN7UUFif60yT/Y n05WJ1WLFD00npb3xB13LIMTb+ncB86LmqHOyYpooSkWr92ak15bnkifxMJil8G+ZlTl UWmGF4kddngsZKB2uXOiEtI0kf1RaZ2YNOjQxaMzuXYzTKznhi98gQuCXe/e3Lr7T/ld Rjl93y/1/zrY67RWbwSocMtg0GVTXGZ6f/zsAU+vEFjOjAlcKC2xppB1eIBL70PBmz5w kqWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ABLpqbmL; 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 f18-20020ad455b2000000b004561657079esi7762349qvx.224.2022.05.03.13.11.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:11:58 -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=ABLpqbmL; 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]:35258 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlysI-0003CC-Ip for patch@linaro.org; Tue, 03 May 2022 16:11:58 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39138) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWA-0001ad-9V for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:06 -0400 Received: from mail-pl1-x62b.google.com ([2607:f8b0:4864:20::62b]:42985) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW7-0003Yr-98 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: by mail-pl1-x62b.google.com with SMTP id d22so5697110plr.9 for ; Tue, 03 May 2022 12:49:02 -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=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=ABLpqbmLIoquJFUWi+oSPoFUFfiF7nk7imQAanAZPuu1+Vxsy7Hf4rSQSeayvWro0U HShbzROH+ZuHaxWTV+FVC287e81nDwtXaPjcnXsMph7pvWwZCRSz88QAlr7MAv9Dvx/z AHAIXnvlRsdErNhdHCOJanZZVIs6OfLoXPZORGUnyDwbH93FaKiYnzG5NHYQPHodSBS5 Gs2GoANWopj/KAOCXAZg1q5OpM12/+hVsEuQHCPpl2/52eN8vm12toIjXwsEh/jTCKfW toTjpNQy6WhkbDCnFWrV7mARI8Uh/oXwP6ZZCPetvb5GS2In8ATFRhcP8KZ7Un0dRfJ5 tBzw== 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=coOzTtMwr9rrGl+3cyhDbkXBtamsk22lDxbutCmvHoo=; b=P+TFdeK6QdBNSpihgsaeh/27bqEsrXKFOUqaHNqQeSdW6vVvvPciewTpTMviCzqn+o JT08A9W/8OpQBHeHsljfLXX/t98rhgoOUueLxY2Sjkh6bH9W9/kjDsGbTlANPcgM9xZH vW+2Na7nssHUBJgHh0S69Vm9sb+w4wU9cYYqcmsc7WKh3ZXaWiyzvoIB+ljBLpKuijsA bQX2pwWtC3s6V+rBMON8VQA9vsAlZsMsKusbn3+JqO0BnJktv6zkl9EFzLmWB9gp1cfV 1tnB5ka4LSfIV88pwARNVM166AUdFVpMJtNmCkx+d/U912A2IVZJrxdbjoCFT1/vjTJ9 feRw== X-Gm-Message-State: AOAM531u0Uhq7qVQBr1SCEH0Rp8nQSDuU2qlCe0t7ZS/vvcoDfg1K8BX uPmi+g00jf9L7SgW/qaefZFutJdXwQASQg== X-Received: by 2002:a17:903:32c9:b0:15e:a1b8:c1ef with SMTP id i9-20020a17090332c900b0015ea1b8c1efmr12299316plr.173.1651607341940; Tue, 03 May 2022 12:49:01 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:01 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 16/74] semihosting: Split is_64bit_semihosting per target Date: Tue, 3 May 2022 12:47:45 -0700 Message-Id: <20220503194843.1379101-17-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::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 already have some larger ifdef blocks for ARM and RISCV; split the function into multiple implementations per arch. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- 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 a6c6e5baf6..7fc60e223a 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 /* @@ -586,17 +594,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 May 3 19:47: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: 568964 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9775517map; Tue, 3 May 2022 12:59:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzJeMFQn96fXzGI9036UAJAG2ZlsqunVjw7KEMKjZ61R+IXNYpV14wrzCE3cWiWr9tW4wCQ X-Received: by 2002:a0c:eac2:0:b0:456:339e:4d46 with SMTP id y2-20020a0ceac2000000b00456339e4d46mr14806742qvp.129.1651607979180; Tue, 03 May 2022 12:59:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651607979; cv=none; d=google.com; s=arc-20160816; b=JwHlxE5t4yLJqrxRjUR9jomOhLLYsYpZknQgw4zBck9ah7MBp0yOoGuheWGWYYA97z LkZih3qC6NPRLrPuu7h3LCFiHaNRc8bHJ9MgQwMEynRQZEP44cDCuQWo8LDevWIoJEhT QVXYkgcJY9UMAbwYFehYTJsmbwQ8zOTP9tjWR+TwIvDVnEyAgyKZYhEQ71M4VRbxFI45 K99tcBCMLNe4Lpy5+FF8/2g12jzcCqhYB/m7BCmJdNbqk47Dir/AyfIeYbXwtHI7vN7k UsKxciK/pTHuqX+zJjB2r9FGWKNawm/o4kBJQfXUZKx1evz4Uy+1bYaZ6gAk4GkTyFpc gPpA== 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=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=paTaqiMKqwOmhMOeJv7fWF1T7j/G7PIeoIeIRMw03dwmpGcejXsRgTbfFmTvR/ecKH TISNZJwS6GVfvrElfwBvmq45yrf0YWy7DBADkGhKnFKzpgdryW67EiZU/PeHuxziG9N9 DXuG8o8I5zDhMskmlS6mZwL+5DsvTV75bhjclpZIGckKiDjq5ov3JClV9Pdor+VLy820 5kNzC5X4Cd2EWVgMxnI0R7fv1e1JyIE9qSeOorLAkiGyNmmuRiOVYhN/lRWV5aFJZH+Z eqlEPk+DjgYBH3iXGgyKuCaBRiSGFHYm68YarwWZ4agCU3816yaj2cDdrm4536nVVb1K RPsg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gPs9i22c; 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 j4-20020ac85c44000000b002f1e9e717ccsi6180947qtj.156.2022.05.03.12.59.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 12:59:39 -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=gPs9i22c; 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]:39682 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlygM-0007LQ-O7 for patch@linaro.org; Tue, 03 May 2022 15:59:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39136) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWA-0001aR-8g for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:06 -0400 Received: from mail-pg1-x533.google.com ([2607:f8b0:4864:20::533]:38894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW8-0003ZC-5f for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:05 -0400 Received: by mail-pg1-x533.google.com with SMTP id e5so3713381pgc.5 for ; Tue, 03 May 2022 12:49:03 -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=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=gPs9i22cIau2c/IJ+nxe8oLHO+RT1WPWq2zugch/0nTQTEQaCTpFkbg0OpCxMAK13P 4YGqVESrxpuD1xyAdeupLRePpOolFZKxQ95EN2ZvSkV96THNb0zNKIE8WhSBbR3cla9X 7nI/HFzO+eMqJWSdeZmvW1J03s0Gxe1bOgRZrSmLrbStNxu9acc70KT6x8wd1Vmdmc+j 6DdPyEDgxCeJ/RmGQPRvdtNv0USLXVEkQU6QflTpLwFwOWlecXKsoOaEVKSz3bBwS14l EP4QOdwWZvppCzPlsPeNz9rKqpJhAZxi/Aw3n250zWCbJgdRAvf74Jh0+KS4FJu4OjCy 6DcQ== 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=IzZtboHFK51ahqSRhw7zz5hbdZTb6VGng4tHM8rPvXQ=; b=4r5DBnsGp6keCUiup+BJjBZFTRXlSbRX32NZrxlmgll8cLti4GN5n7l3KwEJUPCqey T63GOR09qnBgJPvh4q6QaapBrp6GmpcbvLJnuOjDMt1EyiCCTT9eODH4M+8/lFp/kWrO CZ3HH19bAFArKt8MclL77M0FPk1+PgfQuGYIXi82m0QeUDtuQgffizBZAd0doxfeDywK iwEOaJM85gIE1f7x78Mgp8rXgJW2s9+jbt/h0aitOST8LWQ0rOFYSLTzC7uE/8APmEZn HRyvSjyyMN8yXSZY686kV4A1aU/ndhGlrm2N+toxO7y9+LLmo26OpkIHRBt6WjiMXEE2 G/qg== X-Gm-Message-State: AOAM531eUM0mot8Jxq3X7X/OgBZ4gIlCQblEc9NXJI+3KFcYEvpea+Yd C44ZKOjK4XE0Yu3djlGOyJJg3UvfwKlRUg== X-Received: by 2002:a63:610a:0:b0:3c5:a1f9:c556 with SMTP id v10-20020a63610a000000b003c5a1f9c556mr446863pgb.366.1651607342856; Tue, 03 May 2022 12:49:02 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.02 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:02 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 17/74] semihosting: Split common_semi_flen_buf per target Date: Tue, 3 May 2022 12:47:46 -0700 Message-Id: <20220503194843.1379101-18-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" We already have some larger ifdef blocks for ARM and RISCV; split out common_semi_stack_bottom per target. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- 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 7fc60e223a..b2816e9f66 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 May 3 19:47: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: 568967 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9779013map; Tue, 3 May 2022 13:04:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy5UBcmlFEjsXM2rZITfh+RuHcWF1t9RfJ4E6bexmD0lkbll1lYJiuANEtRCJf5qY2v4uSg X-Received: by 2002:ac8:5a8b:0:b0:2f3:93fd:2317 with SMTP id c11-20020ac85a8b000000b002f393fd2317mr16504147qtc.372.1651608260982; Tue, 03 May 2022 13:04:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608260; cv=none; d=google.com; s=arc-20160816; b=zd120hDzgZw1l6voSTdqHO9wHE+wTDH1O9jU3isA++DVpns2l/QalT88GgE4khDt8U ykhq3A+EWaCsDlmrJV8vMV3yCOxYFHNcY2Zy6CI59S2//I9FeTKta9hOX4kwvx1b44NR JfTxFsX6vqtqcQYMGoGSwcX4wY5YUFjXMUfCb0O8mf5q7H2+J7CKcDBNkybKVw4bEdsE jeRVQ0PTCMwjXtJEiqgpodiqAzos2rsBvklPhC33PCWKxIVZSwHhCbKStUD9ceVWen1o 0lpw6vT8Hv+rQ6DKQ+ZRSfAwnLKIjzs0isdGA98CVRQUzNlvGZyAG4ovIEe3THpMlWTa kLbw== 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=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=j0jeNE/SFDdwGqJUie9LDfjJn3N8XvJ7Zi6+s/TckMTqbxKNvASi11y+Q+RSE14Uwr zRgyRftyqKFGQ+XRkMqT1zasuyRuJmJdfWZ6V24ezrECzs+5zRik+Kt023zCdm/dR7nt e7F3rs8n6B5FzOaVg5uIRyILDrgT5lg+nnEmMpxvsjP51XmtD5rjQ3RV4bAZceIycWtL cXAOBJUml5/I4ZJ/OKpAENWLOE8rQMPQ+Auy+wurut1sqU2+tsS6uIFvn7hTn1NvFfXr xanK+4lTo9J5umppuHO+xbZ+VKqq84DvFOuYvcmyQamn649bA7urdPaIFaAHDPbEM5Oq /xyA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=j+An7W31; 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 u14-20020a05620a430e00b0069f8c0bc3d1si9326496qko.300.2022.05.03.13.04.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:04: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=j+An7W31; 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]:47184 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyku-0004Sp-IN for patch@linaro.org; Tue, 03 May 2022 16:04:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39156) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWA-0001dV-Vy for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:07 -0400 Received: from mail-pf1-x434.google.com ([2607:f8b0:4864:20::434]:37572) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyW9-0003Zj-Bu for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:06 -0400 Received: by mail-pf1-x434.google.com with SMTP id bo5so15577626pfb.4 for ; Tue, 03 May 2022 12:49:04 -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=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=j+An7W31FxhL8mLTNcnB4u/q60PmhwVB8D9LrThK+Bf+ZIcpe6tCSB5JgIhtbsTr8a mNXm2OzzNZU+FFAwTHcLD8RbBVxhuXuIKupap8f6PqfDGe2eE4T7/4rr3wbuF+fXlnqd EU2nzl1DWGY9Z7jPn/h+hqw0n4hmkNDDasYjvp9kmb0Qjdgy23TqOQJ1VU29qScE4rAJ VBNJ0QpaL8ifwo85+hEBZMhLYiYVSnwm2eCeaAKSoggH1V1bXMb8lHgi2AIN4XfWnqdO QuipIkFwAIftnGt0aanVuqgg9ZD8u2uwFvrG17zebqhe8Nn7JK+CNOTDzN1ZXavqVfI3 CPkg== 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=bMzSVxcdvq+IuYW0Vc/jOyPOv06xtgKXvctJnUGtedE=; b=zJ6EnuLwh7z3qfD532/Si/pbhBLgUestHQrL52N73ggHyiL0Go+tJmhgGlotsJGzrP r1XZgHlVlVp/uDiFKw/jZFBKnhAZabONnF//itduA6i17biZn0isoi4y0aP7R4+wtbrQ MLEsrD+KWLDmYg5r8dkyHl8je09A57ED/QMiM06cR7L1RfZ40c5ikip2ysowzxXIgMv6 aZQPW0vRIAEC5b8NFd4JeIIOepiENauFcNGxZRErxHZVMAEGtvLBjU/Picc7wbPD2zgS 1p2CNhnKKYZKQmCu1FSFCqJ6JWhrlmJf6hCX5XFaA78x11APx6ZO1Hbhz1v3/IlF/jHS NgZA== X-Gm-Message-State: AOAM530WG6bLUFpDLk0XIPJVjfrNZVFNnPYqtgShwhrf/vfmNiwIgnVU jtx+cfjOnkUo+u74EglzU99OJurr08zg+g== X-Received: by 2002:a63:8548:0:b0:3aa:fc6b:a36c with SMTP id u69-20020a638548000000b003aafc6ba36cmr14974925pgd.267.1651607343868; Tue, 03 May 2022 12:49:03 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.03 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:03 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 18/74] semihosting: Split out common_semi_has_synccache Date: Tue, 3 May 2022 12:47:47 -0700 Message-Id: <20220503194843.1379101-19-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::434; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x434.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. Signed-off-by: Richard Henderson Reviewed-by: Alistair Francis --- 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 b2816e9f66..6149be404f 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) +{ + /* 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 /* @@ -1103,16 +1114,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 May 3 19:47:48 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568980 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9787059map; Tue, 3 May 2022 13:16:21 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxE08pv7C21Eu2WcJ62APTHf9SjhkfsQndPGu2WoDlpNLF6CPTf+Hcb0XEkMYqYdMuSsse6 X-Received: by 2002:ac8:580e:0:b0:2f3:7ff9:39c6 with SMTP id g14-20020ac8580e000000b002f37ff939c6mr16476513qtg.434.1651608981131; Tue, 03 May 2022 13:16:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608981; cv=none; d=google.com; s=arc-20160816; b=ncrms3O12ocuUCS6C7CTtdlpi5ISi8+wvMYaiIIYFT9Aq98rf2+b0fhZbzKLXqWSE+ DGiRsMRgIf37Dp7TIA8aoo7p4JG/Syk5GFZ0p7ebWoXaOWev1jjq8KPIXBD2dxuyRo1z GEGbbszT8indmv+aKDZzbYuhPTDZp0TBdgaxrrqxKEW2fXeTaYWHjVU+YLfJCSEPAZWU KkYpkXS9jWfZHvNoxsrIUpibKlMt56tNNB45hqSlWOv3yc+TbsYNDpzskKLxjL7dbcf9 Lz/9L/s4Z7scEjVjFKA8+YMSmML4lKgCTW14wtd0AuOCX8DWAYjkcn2WWYZMPN7uYDwG xiZw== 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=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=Ekq9CXRtK0U5FRs7gxLsvcESAaIRrVMmF20Y3KDFZ3vdnc8Den3wGz8Vc1mFr1eK6I nCHERydbh7FkZbOv/5e28LJLa/12gNWs3DLDt3FucvUccPC26NkryNxZtsM3dWCzBRxy rplbPgkPxguULMA49fYS11fDNcJdUOvx2vCFqQdjIhM5Kb97o50tRJ0jveju/CO7hrW3 /3hQX7nvGsZcv5W+O7RwenDYDbYQrgLErvw676qoQojIu4+3dAAmLny+u7euow6nWq3d oE5gLiNjV5BB6ZnFa6IEkxu/Xv3U7LlLylNnUl8mTGpSo4LwGxu7qcpP5j7ILW3JqWHi uV1w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=EbDksDGU; 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 o14-20020a05622a008e00b002f39228d583si6859148qtw.490.2022.05.03.13.16.21 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:16:21 -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=EbDksDGU; 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]:43150 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlywW-0000YS-GK for patch@linaro.org; Tue, 03 May 2022 16:16:20 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39184) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWC-0001hK-81 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:08 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:37741) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWA-0003a7-6S for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:07 -0400 Received: by mail-pj1-x1036.google.com with SMTP id t11-20020a17090ad50b00b001d95bf21996so3227295pju.2 for ; Tue, 03 May 2022 12:49:05 -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=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=EbDksDGUqveYixSOgkkhKb/ClBKSD//cJlxStKWxIIxQamq5MocJObRKZNLrFgMUEC vjO9n8d54Ac3S06mrYq1EgquxWdGeJIhWg9hAnXJM1ArPRxJv14ASsmIBcws03oKdKMM aPg6SJ1k3PVi6/L1bEbjY1iBTQcZFO7L3JoIymswCW3XE1QVPHc90bqX7mS1b5oMSnrm kAopSHHzHIEsl6ugbpXx/bFR6Twh9DhNBI67Zc/tI1l3LerbZmn+2HAMUGu7Bw5Q6GoG H2Bms4Du4DnDtk9BYtfBa8L+jPlbR02LTk7Oz2hBOdkG19nqSmNWpyO+QCj/lon7vK6N MzUg== 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=wXLSxy1WX79eMXmNdpTVz+8RqAC6B/BBjkCPMRdeubQ=; b=NP/as7MhfCQBx/Y6m7LCZGhaWnxzCsjOVLwU2ZW49s8Me7D+anW90fZlS3yXgiHmU5 vvWqzNd7zCQNNlxThtaafg41/HiCIjdyHhHGxKEFYKnjPC4j7f/TjxXtx39BEPjgHxcf a99TwzP54UbYq5wg592BcnqwFHPqxLqBpcmYdhcGiiivYkN2OUoxbGmz5/Igwkg2BVZi xprV7yohvHY8cxgjLGxKHxTcprYsbbR/PTrQrzb8lpTCCPaSJS3pUc6CUaYVe5vp8TuS P0l0q5taXn/8HgzIWlKCLRM8AfL3hGObFlX8mpYIc6Zl/8RrZyQz/C67pNiF5naGpq/k jueQ== X-Gm-Message-State: AOAM533xS7Zi/540MTpJ1UKP6qoAtKYu6sKsF0FKJnhOW5ohdZS77Oav odnNRiYV6rLinktzsqCASn0ELRdXk1VcQA== X-Received: by 2002:a17:90a:de87:b0:1d9:8264:baef with SMTP id n7-20020a17090ade8700b001d98264baefmr6492685pjv.227.1651607344875; Tue, 03 May 2022 12:49:04 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:04 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 19/74] semihosting: Use env more often in do_common_semihosting Date: Tue, 3 May 2022 12:47:48 -0700 Message-Id: <20220503194843.1379101-20-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::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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. Signed-off-by: Richard Henderson --- target/arm/common-semi-target.h | 62 ++++++++++++++++++ target/riscv/common-semi-target.h | 50 +++++++++++++++ semihosting/arm-compat-semi.c | 101 ++---------------------------- 3 files changed, 116 insertions(+), 97 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..c20e1cca76 --- /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) +{ + /* 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 6149be404f..3a740482f9 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) -{ - /* 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, @@ -646,7 +554,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); @@ -729,12 +636,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; @@ -765,7 +672,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 May 3 19:47:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568968 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9779392map; Tue, 3 May 2022 13:04:56 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwMLfUBjvbjyTWsN9h5vXX+M00AptOU6wgrFkLtuERqQn34warQ7wXWuAyeC6Ax9sXCTf3g X-Received: by 2002:a05:6214:23c8:b0:450:863a:fa1e with SMTP id hr8-20020a05621423c800b00450863afa1emr14750124qvb.54.1651608296667; Tue, 03 May 2022 13:04:56 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608296; cv=none; d=google.com; s=arc-20160816; b=KyMDUwIWccOAK03xSjY4xzQj9xO7Re6PxY59FPqrWI32IWtZ7j2bWaXCOevVCBhtU5 ZJqyVfUi/cbmHhY1LkyYoeNzqRSWypfFhM4k/AFCOMfiMrCrxo5/TaprOZsviJM4m4Sa hZTFcK4XbL4Irkz+ZwC03oaDV+U1tq5OySzPqIZROZ9Q2+v678khCXTC+75Sb7D0ZvE8 1zdCKYKPONRHrvzolfpEOdiT8WFblbGtxl0Zg/gkWFVwHQuBDes88Hfl61zIianhiMhg x8hKIMdGEv91U8n9gtJZURRQwFcouRMf2HVx50v3yaXx2E0//n3QPOfU43oQu8nG7297 4Ysw== 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=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=kJTVijwoZs9VNSqKrW5So7ZAySGOs9QZ+kWS/5wcyBrB/m49udKwV+kxPKbT9tqqdK cOuWSj+/4I0wjW0SXjk9RrmkV6NGsBi0+ONhAK63EFrXt6HNJVAOCAgCEypI/SN+RcN5 vgnwM1+7sASWBJBbgvpqXCmVCU+EGiMQ/rLwzCp4N1ja97SJpXk6/YyX2sooFDHbOqPd RFDLX41unXJrio3mE1fOGwc0rKsqO7ODj8+wG7yhfLSlzwrK8Reukc52eHpZP/mTTJsv LcMy9J1KcMSNzd0b28G84Ufy/RU6EbUeguvnoqj1YUSA80FpkRYcUXsF90rTRd2W00m+ rauA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=odW9mdNF; 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 gw5-20020a0562140f0500b0044644eb42e0si9180912qvb.314.2022.05.03.13.04.56 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:04:56 -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=odW9mdNF; 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]:47946 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlylU-0004zX-45 for patch@linaro.org; Tue, 03 May 2022 16:04:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWC-0001jR-Um for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:09 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:46894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWB-0003aL-4r for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:08 -0400 Received: by mail-pl1-x62f.google.com with SMTP id c11so5631053plg.13 for ; Tue, 03 May 2022 12:49:06 -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=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=odW9mdNF/Ot9avhe8ntqbHxp+eu0osB+bvU1Co8fY6ibEH5dDUmkmzIXdRqLylxpGG EWSRmZWY3VdsN/CZ39jX66HOlVKzDdHQV9I52BsfjBJ5nnAHEfDtUBiX1aIyx4lfLowz CUMxT3WmF/Qn0LPDc87Q6HMcgekLsnL7eQnI22VnrG5kUBmAd4NNVLvejdH6tyKOJEBV l/FCRU9hr1sqF14k4YG8hV1wRyIcAD6KtYm7RvqkeDR681CwmBpMTqAVJaqAe9nA22u7 BPNSOe/mij4Y6hr7KitrgezFXFJY4cd+eFdGOesJ7/4hXDjG/mylzsy6sdysHcZbHZIG ze5g== 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=KTqJr1ojr+Avm6OwJN9PAVJEmcUCfXozWTlyiMGyM9k=; b=NDUAoF8XlNTq3BGoTIBEuPeXgNe7WUQ3C8wVNvR2U2LomWUIAWov3FlUjsJuVaDVjV VZGHYNFVQgVin8fdjfcz5yTl9g82Hq1Ws/7ny4fb05MjrVpk8IxC8LWpy5o0Yi18MmMF duzUr9ZkrusKAxXudMOYzvlx5uogRZ93av8NGEOb/RH+9cWVJmbGXpqv5pxRIKlilefU 0L4D/S+L8Xm3OQjFvhwywJint2ooUSRLKupc/tta/yFUcsq+9mUe5fuTRce0ySCbiOqT CZpq5FEEZf+QzATBaZ1wNkxPncPGr/q4XuOJI4ZCSSRLmJ7ZD2VYCJKBRS8V2t8kvQX9 DT0Q== X-Gm-Message-State: AOAM5325j9RK6HGrg0g1uU5tITfo273lYZQU+nvuZaFwTMvUNPAYnYJh YxGU0bve2V81tMFRSx70LLcWdK+dIBJ0tQ== X-Received: by 2002:a17:902:8c8f:b0:15e:ab1c:591b with SMTP id t15-20020a1709028c8f00b0015eab1c591bmr9453232plo.171.1651607345699; Tue, 03 May 2022 12:49:05 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.04 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:05 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 20/74] semihosting: Move GET_ARG/SET_ARG earlier in the file Date: Tue, 3 May 2022 12:47:49 -0700 Message-Id: <20220503194843.1379101-21-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::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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. Signed-off-by: Richard Henderson --- semihosting/arm-compat-semi.c | 52 +++++++++++++++++------------------ 1 file changed, 26 insertions(+), 26 deletions(-) diff --git a/semihosting/arm-compat-semi.c b/semihosting/arm-compat-semi.c index 3a740482f9..49f976cbc5 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -181,6 +181,32 @@ 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)) { \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ + } \ + } else { \ + if (get_user_u32(arg ## n, args + (n) * 4)) { \ + common_semi_cb(cs, -1, EFAULT); \ + return; \ + } \ + } \ +} 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 @@ -506,32 +532,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)) { \ - common_semi_cb(cs, -1, EFAULT); \ - return; \ - } \ - } else { \ - if (get_user_u32(arg ## n, args + (n) * 4)) { \ - common_semi_cb(cs, -1, EFAULT); \ - return; \ - } \ - } \ -} 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 May 3 19:47:50 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568983 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9789462map; Tue, 3 May 2022 13:19:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVkf0N9gC5+XwoqQZ4iEty1u5BbLI92aP2UaQyh0r8g/BudOR4B2KeFCm/5jsg3exf2coV X-Received: by 2002:ac8:5a83:0:b0:2f3:b2b2:b92c with SMTP id c3-20020ac85a83000000b002f3b2b2b92cmr2622637qtc.557.1651609179584; Tue, 03 May 2022 13:19:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609179; cv=none; d=google.com; s=arc-20160816; b=hGfF3ejsbSrfCBptdLdx1s3O+HYs338CLAI/jIpnvfnLKTewJjUEwV7K+WSZ5ZN+dK pCviSszpK4LslOPk8Mu8vYbE1397lBxu8YhDuLvNbDMTuzJnn40vvf0NWV13SgW9FgR0 tVkSH5YPMkWvn2RCkAsALySc9tbHrZlL9mhed5MJ48mdgBqDR3ui9MKf7h+EVgLQkPWr FgUEqHzqDFGXso2AuwA8IYJbR+ge4QB9Tazrf+t8ogxBz2H8MXWcpL3PeZ1RgcAKSm1i MepH1TgNuXP1o7YFi0Aq6NleN0hnff5iBuq+XOKPD2lbkRVRrLkwXulE4yKniJfZHEST dnvw== 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=PbM+bhS7D2Mao4BFHDU0zIPvu+k4lfhRPdlGiKOdrM8=; b=RaUREfkAU1CAaBjv0zW2ts+8XyiyWZviXwyHYRJcOnSnPYAjJeIMVCzIl6N7rBiAhz 6L8fAp2NsJP8ZTPl8KgwdIcz3Lb4TBg29gbwfbfhAbU7PvJEV/mO+5uxFHKGDMrjOzuM uuRsV4pe4tWtkD7/m8C0TBHGV1YlNuN+OOXds6GS2z6jKA8l+G7WmrQkI7v7+qREGVEv fO+Xg4WjSwUTSSlA7CfN8TENJxAuDf9sSG1sMxPtUh1b/KP1xXP95eyM7/jPTVDdi8B4 154rcYS3p/nWpJmXkxIGsCv5FOyDlI+UKMxkK5MBYf76+vvHmbK/y7iRVmCVl9HUb+pS VcIQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Qf47cunu; 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 e1-20020ac85981000000b002f204a6872esi8526933qte.75.2022.05.03.13.19.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:19:39 -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=Qf47cunu; 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]:51598 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyzj-0006WP-66 for patch@linaro.org; Tue, 03 May 2022 16:19:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39246) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWH-0001u4-UJ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:14 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:41884) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWC-0003am-6i for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:10 -0400 Received: by mail-pj1-x102f.google.com with SMTP id z5-20020a17090a468500b001d2bc2743c4so2909974pjf.0 for ; Tue, 03 May 2022 12:49:07 -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=PbM+bhS7D2Mao4BFHDU0zIPvu+k4lfhRPdlGiKOdrM8=; b=Qf47cunupHAEWp/7LUiYMwfF4R6cksvKk4aWPu3+CohQi8zC2gYXxXemi9qO/TZVVo DHojSYT4VJ+zJUKlwask2dxnH9aFtiYRspMX52sSruFRDMNqPCRDrf1f0XSXBP/dQ62+ 24g8wYv10f8tcSp/kO45RFydlGSDVLn/H/WJIM1ehysX0YKq2pk0tSXcjer9UNyqsyoM fvBnbdJn1sc/U/Xy4Yn3kDGqtiWFCaRE2F6SBqWkD89ubOxNxT5IbWdZMOH8WKgW9Rwf ziVh/lmIZNm1s6QP2SLFI06IbiU7N3Jvv1mXx0claXUyaJI+OEKZseZ7H7PzkaGJiOgD FBjQ== 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=PbM+bhS7D2Mao4BFHDU0zIPvu+k4lfhRPdlGiKOdrM8=; b=NLqw59mUwyW+T4VjZTEUeqNTq/BWUV1Jkwa9+U36vOJuvliOJsdLYHTE7rTGbo2KNg GdExWDa7UJRnZbO6xF6H82WXDGjSze6lfMlJRAM10Wo+Rm10ijgvZVBgsqlAVdGlz8st A3+qycNHn/nBApFO7eZCA5XdWzastiiV4QFCkh0s8HK0IncGVDf6gNrmV4GP8CElj3zD WPSzzuY9mz4dDHAgxdChBQTS12+K06rczAz2thOwK2aY0zV32AaYUxseRS95mkD3CVAK n/93c462kdG8Js1LjhJ2ne+fABxLhigm0x2xi3NWypcGEJJ8nR1UEXYabEGbRp0CMwr/ MP+w== X-Gm-Message-State: AOAM531OO4YZHZDfCnzCfLo8mI+VsPqk3++RWD7WMPyHLqPTL4oeEUob gVS2ld2lec2jaN5YvNisMpu7D/FkvEXyjA== X-Received: by 2002:a17:90a:c504:b0:1bf:6d9f:65a6 with SMTP id k4-20020a17090ac50400b001bf6d9f65a6mr6392146pjt.204.1651607346756; Tue, 03 May 2022 12:49:06 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:06 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 21/74] semihosting: Split out semihost_sys_open Date: Tue, 3 May 2022 12:47:50 -0700 Message-Id: <20220503194843.1379101-22-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::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" 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. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 25 +++++ semihosting/arm-compat-semi.c | 50 +-------- semihosting/guestfd.c | 5 + semihosting/syscalls.c | 186 +++++++++++++++++++++++++++++++++ semihosting/meson.build | 1 + 5 files changed, 222 insertions(+), 45 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 49f976cbc5..4a2f0c9202 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -35,9 +35,10 @@ #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/guestfd.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 | GDB_O_BINARY }; -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 /** @@ -285,20 +271,6 @@ common_semi_flen_cb(CPUState *cs, target_ulong ret, target_ulong err) common_semi_set_ret(cs, size); } -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) { - 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 @@ -602,22 +574,10 @@ 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); - } + 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..a44d5cbae2 --- /dev/null +++ b/semihosting/syscalls.c @@ -0,0 +1,186 @@ +/* + * 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 -GDB_EFAULT; + } + if (slen >= INT32_MAX) { + return -GDB_ENAMETOOLONG; + } + return slen + 1; + } + if (tlen > INT32_MAX) { + return -GDB_ENAMETOOLONG; + } + if (get_user_u8(c, str + tlen - 1)) { + return -GDB_EFAULT; + } + if (c != 0) { + return -GDB_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 : -GDB_EFAULT; + } + *pstr = str; + return ret; +} + +static int errno_for_gdb(void) +{ +#define E(N) case E##N: return GDB_E##N + + switch (errno) { + 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); + } + return GDB_EUNKNOWN; + +#undef E +} + +/* + * 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_for_gdb()); + } 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 May 3 19:47: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: 568981 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9788170map; Tue, 3 May 2022 13:17:53 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwQGUNxZqd+vefN7AIERlwpjmpQvElx4ZWkS058pACvBqNffGVEFSLru2EWPPBZMKgD1AIa X-Received: by 2002:ad4:5ba8:0:b0:456:3c2a:dcd9 with SMTP id 8-20020ad45ba8000000b004563c2adcd9mr15561484qvq.14.1651609073526; Tue, 03 May 2022 13:17:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609073; cv=none; d=google.com; s=arc-20160816; b=GyaInvhJcCe9+lgSiPTzV0SXAdA6RbQ5m4d1+Z76M8D2j5FJ7Mp7bgSqlvuwRT0VeF n1AFkSP7Pvdm/3qoYxpAWhBLlYdMemWqSB4WkfAbkDrebzc1FvDYRTUeIaVr3y1v2f/z /Zzw/P5mDk5n7DrquuncO5gkXQ1r5NZLSwm55cB6xPx9EeZFRV/GlQqA+UOdMnvyHMxH XQxaat9arJCgME2PB7t+LwyK8foJHezSX8wRLM0PNb6z6YZmFMQIZDj+YT2uK1320ya6 zCpXytQwzH5MRSEBd3zjYUCmV1mTSiyNRiZIydzafzTARtOUIg+C78VaGm8vzmoNOTuk 3H9A== 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=1rMTJEowh+1/F2+H1eC/4OFTUMesMIGu/YPb8vPE9Cc=; b=LXy/Ei9ZheYqCGXRDs+OmPKWHL45+WyAzM+Fpw5zHxwsPUA2GUrRDja/lVukNudbee /bh6GuqMotOdgTh2SxSwKdkNUKgTf9xEnWYf78Bze02Fbtwl+YDtfxZe2r9KR0GpDy9h pn56WhNuooe73Rc9ZSCvMCZLzVqhgLE27CLjee2KV9s/HcKy2X22RMJKGzoEc8jTJa6z 8fo9KLMokFctWSyVKp3h8m/btKQ22Y4PiuXcaVRqtQEW7Ce+7GTm7scttgV+OHSo1yjn RA3xCZQuk0CVBgVPRE81gm7krFXb/1EIl53+vU1zC8SlZFv45rwKK8/zD/jEUzZu/x01 LLmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=JQMPilqd; 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-20020ac87dc9000000b002f381076b1fsi8799395qte.760.2022.05.03.13.17.53 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:17: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=JQMPilqd; 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]:47564 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyy1-0003fk-3L for patch@linaro.org; Tue, 03 May 2022 16:17:53 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39262) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWI-0001w2-Vu for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:15 -0400 Received: from mail-pl1-x62c.google.com ([2607:f8b0:4864:20::62c]:40927) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWD-0003ay-3f for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:10 -0400 Received: by mail-pl1-x62c.google.com with SMTP id i1so9737491plg.7 for ; Tue, 03 May 2022 12:49:08 -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=1rMTJEowh+1/F2+H1eC/4OFTUMesMIGu/YPb8vPE9Cc=; b=JQMPilqdU5XA1CU+12ojhec7Jo6T9RO11bYratSyk5/pWdTZpV56CGOODmdgLQI+ri Ns5eZ81FxKmKwOedMFOIEHyvZAALPqJ+zjTEccMgTB7vYECx30OryHy5nXzzq9x/RPV7 f73Uwx/Uy7oDKhRsR4JHvNvbeVheYxlUvpaI6LAkuQhd7diI1f1NBeXg4gkgrsLDgo1Z qwSreSmgyBB3ep8oUC9HGmDKhxw7FcF+JKdsUX9FiCTe2sLPYHtwAgADasVjMvnRJSwY FOuWLzCY91uKHGBvcrjl3MFBFDRbpGg0sHQgg7jLMZ++DUHqGTyaK+L6aburPslmKDSy x/Dw== 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=1rMTJEowh+1/F2+H1eC/4OFTUMesMIGu/YPb8vPE9Cc=; b=jWfPXHwQXWWT2UO99v0u2WzSGTPb2CsmmNLc+buRAgixI+hObjpiPWKd6+o4icgn4k aLk89UEJDPx5Z7pWTLDMkDG3AC+2lxbuX7OVRhXpHTOnvXxnC/MdXP52r0HkrihIOSua wrrH6vtNAZitbwfAekkrehLbtuhImGzE06rHSdlmkvbQ8jmOwAceiDNsP2wtuwO7t+4E X3D3r9LcELKyAU2jxiVYHqa7y3rAMFyZn67ysUkKao6Rpl4VfTG1ZY5IuQBzQRGf1hpz rV+W0muocJ4wBm76lCfxnHc0rb4W4otrOUxG7s5T4A5dS1X92oir4q5UB6vpR/hvb343 fl5A== X-Gm-Message-State: AOAM531ZhqzPYVc91ArjRHN4/I/Rj8cQG/zBOhXzi8v6Uj0HMcDQ9m1r 25Psm2NpzG40LPtqsrvPzQKEmrccbM8Usw== X-Received: by 2002:a17:90b:1c04:b0:1dc:4dfd:5a43 with SMTP id oc4-20020a17090b1c0400b001dc4dfd5a43mr6614696pjb.160.1651607347745; Tue, 03 May 2022 12:49:07 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.07 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:07 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 22/74] semihosting: Split out semihost_sys_close Date: Tue, 3 May 2022 12:47:51 -0700 Message-Id: <20220503194843.1379101-23-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::62c; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62c.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. 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 4a2f0c9202..8ebe3aad55 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -277,7 +277,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, @@ -286,23 +285,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) { @@ -363,11 +345,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) { @@ -415,12 +392,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) { @@ -469,7 +440,6 @@ static void staticfile_flenfn(CPUState *cs, GuestFD *gf) } typedef struct GuestFDFunctions { - sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; @@ -479,7 +449,6 @@ typedef struct GuestFDFunctions { static const GuestFDFunctions guestfd_fns[] = { [GuestFDHost] = { - .closefn = host_closefn, .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, @@ -487,7 +456,6 @@ static const GuestFDFunctions guestfd_fns[] = { .flenfn = host_flenfn, }, [GuestFDGDB] = { - .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, @@ -495,7 +463,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 a44d5cbae2..9c4b635317 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -124,6 +124,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. */ @@ -170,6 +176,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_for_gdb()); + } else { + complete(cs, 0, 0); + } +} + /* * Syscall entry points. */ @@ -184,3 +207,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, GDB_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 May 3 19:47: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: 568971 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9781796map; Tue, 3 May 2022 13:08:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwTydbYzN4NueZ4azVuzFdL6kC22Rc1Hx+pKH9V5URzZ05pvAbOXDGWjaHZKnC8c7ku0377 X-Received: by 2002:a05:6214:c81:b0:444:1c7e:7b6f with SMTP id r1-20020a0562140c8100b004441c7e7b6fmr14954868qvr.48.1651608502616; Tue, 03 May 2022 13:08:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608502; cv=none; d=google.com; s=arc-20160816; b=DzFueFxZXcuBVoctW2uHo62l3mtXF1Cc5OwBi2urYshzRn/rR2PBUtoJOoqSMFoTIL A6EjfUXj4oX7kNNcUWW1CJiIbIFMlCMzgaYXeWuEorITpui2Yvy+1Gg5CpfYofR/SRW1 zm6uHbns/h8aaHSoIFBQ8mpKYicvWYZ0BIWGkB2lJoMu01kgwNvpGhoYOJ7eN7rdvNwJ ptwUKhNi0iWjjs3m/+1nc0Jdq9cuiIgin4Na7eyNiRaLFWiIe5FnrxOZ2hzR8HoJ9aHq Uj8tnJzlBbN9JVelg+ULy6+hSIcDYCR5vLweC61uAyxp4dhkVuVixx3J+VnpIZhdLZJz VRQA== 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=s656QJXJi/K8oez9ZtWy2poWtVIn5Z6Qh6dXSclsx7s=; b=qZsA6PJ8ICqLRP/uHcadTiPxB/QULg/sX+5X+M3xettGZBtVrWJAR4CwZqN9LwMZRj Z2iBfsUz+0nCjA4vjWO6Q6qeNuNEPEbN4xfOrGjtULqC0Hpnx3WRXRStKuV4wpJARqJl ka75fRwe/MSV3ALS9oUHtMkUA7yiyuTSz9GjkExcG5rRW8lYkWTUEWdyB2tq1o2HWLu/ al2dFes5n1ffI+pjci1wssjSg0WiPjSn6BmzDXyFU5UZGWPxSZg/63spEINsbzcyhC+5 cbAZAd7hHoLa2pKfW5LhawTNNra/wp1/VNikRWek1AsULxn/3WVUh/DuSsnF+4APO6x5 wZ1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Iwf4erPt; 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 ey2-20020a0562140b6200b0045aafe4d1d7si672889qvb.510.2022.05.03.13.08.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:08: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=Iwf4erPt; 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]:55036 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyon-0003vs-U3 for patch@linaro.org; Tue, 03 May 2022 16:08:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39280) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWL-000227-Hu for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:19 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:43598) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWE-0003b8-0E for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:12 -0400 Received: by mail-pl1-x632.google.com with SMTP id i17so6701337pla.10 for ; Tue, 03 May 2022 12:49:09 -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=s656QJXJi/K8oez9ZtWy2poWtVIn5Z6Qh6dXSclsx7s=; b=Iwf4erPtbCK3zOzEkLa4e+ZXrsNj9iI2H+aI1T5jrfwPig8XP6C5/ovRKGNcGwJXtZ IRBYO4Cd6m1HTdhFnwJ7Q3uNWcUMp8/vZdhTc/bY8qSXEhyrhHrqfWvRFs3sJJ8NES1o ETFnFUGRY+kXJB8ecx4tgi4+Cm1v5lXR22jGNWnl1K3f89bTM56Af7mtz4KZPv39M9As nZ18K5kenGeR6p1QZuh6bi5vD9189EpBdjp8femQFE1NoGHoktD7SXP0j81l1m8xsiQH 9Tcv4FXYw25CSdgnYeYC4eyqdWBXlxbq4+hSe6qi3KsC7JXEGEAeGXNsQK+1n+epsway u58Q== 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=s656QJXJi/K8oez9ZtWy2poWtVIn5Z6Qh6dXSclsx7s=; b=CWe170uy8OhMhOWsM/GY/jCX3DcTWgoSrH0qIaUGnpXtAMNB41wpiCUoKuoi4HdZLE psLCgMVWwMJgSgMLkTVec1LIeDXivNpZbT+UP34Ou+Jz2F2fFp2zciOUwqlZkPQk2OtM KJz/Xg54LOr3D/CNTjMJJhWzrVUzjXNl9jMgc/Gg5TSaPD5e6Mol8CoYfLmjkAXCtaA5 3lNh3tBlBd2b21ZiIguuvV92dokh8+8KyWFR7HeoDXiO3pL7Em+50ZQocKYoRaLFwf2L eiRj94Vk4zGlWt6H/neJHeCXLb00GbzKVzVLxOnQ/hjbQocJ+qplpHwwBav1vgnIMSW+ Hlxg== X-Gm-Message-State: AOAM531orTQSfYRPhb4goppEfcgXyvblXTI58K2+AjMBIi+AcheipVNT uKMf10+E33jD+nt1ZCT/0ZkS/qbunRcGKw== X-Received: by 2002:a17:903:240e:b0:158:eab9:2662 with SMTP id e14-20020a170903240e00b00158eab92662mr18083377plo.87.1651607348669; Tue, 03 May 2022 12:49:08 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:08 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 23/74] semihosting: Split out semihost_sys_read Date: Tue, 3 May 2022 12:47:52 -0700 Message-Id: <20220503194843.1379101-24-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::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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. Signed-off-by: Richard Henderson --- include/semihosting/syscalls.h | 8 ++++ semihosting/arm-compat-semi.c | 84 ++++++++------------------------- semihosting/syscalls.c | 85 ++++++++++++++++++++++++++++++++++ 3 files changed, 112 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 8ebe3aad55..7b6df09f35 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -233,7 +233,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: @@ -246,6 +245,24 @@ 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) { + 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 @@ -279,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); @@ -303,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); @@ -352,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); @@ -399,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); @@ -441,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; @@ -450,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 +543,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 9c4b635317..7c18f77898 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -130,6 +130,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. */ @@ -193,6 +200,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, GDB_EFAULT); + return; + } + do { + ret = read(gf->hostfd, ptr, len); + } while (ret == -1 && errno == EINTR); + if (ret == -1) { + complete(cs, -1, errno_for_gdb()); + 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, GDB_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. */ @@ -231,3 +286,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, GDB_EBADF); + } +} From patchwork Tue May 3 19:47: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: 568987 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9791829map; Tue, 3 May 2022 13:23:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJylzta6TJANiYyJraIrw1JuPR8BvlTILzx2OA83kdygpcDBANnLoXTKlZMaqpFzZPRqxXv3 X-Received: by 2002:ad4:5aaa:0:b0:45a:a137:49d3 with SMTP id u10-20020ad45aaa000000b0045aa13749d3mr4788912qvg.61.1651609387024; Tue, 03 May 2022 13:23:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609387; cv=none; d=google.com; s=arc-20160816; b=aPV8xOqxDolKwSFe6bRQnUeD5lk8TFqc8bJNzNY7JWiErZoR0ypqLA4CCwPLIa13DR x0y6YPBOkqAPP+B/+D4uMbb4N38piFtVFl5OjzQGnIomAZs24AF1vwOw6bsVXZMAOoB0 zda1ny67rU79zxzVkZ6tXuHecsJFLjG0hNDxp9OGsjtbnSvY3RgMRIrAqRjuqxnI5j1P d8JBP8Rypa3u/N71f5pIry1CVs26cKy/KTN1+98+OaE05RVwNCuMHM3GtRt4yXyqPL5r YVI04+EIyroMg+BlT3qxIhEA4tdHgenSCpQaqgx354PiFQGlcmfflZ0eot3NZNaItUAz SHXQ== 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=31j8l5Xb7Ai6yPrq7Qeaf7BC+gVujFWoD6h4E291eb8=; b=DSBR4dfiyca0CXtnL3JeDTJp8VM7tlx2znJwEpdpbSaqmv8XJcUdBdA2NOpKIEEYOM etoOcDvPACXfGViI159nhFYKd2fEecol6r4iV8SVjfCjf9p0nX0hHr67cFKs/ahI2yVp cf+uNxVQcKy2PbMFzMfTWIw+/llPMIak6rcyhAhULiYLalS1uqhe3nQB05r4tWnZm3Ka K/FnVop+enfYAa4vyA2EkfvOvDZf3Aab6fvm4QT4SQndFRiLzstK+SDHXTm2ytIXXpYU 7rNSnwE+vgXUKJGXNM1AIJb0++AwjPCkpr+w5CU3mO1bxmyvzkzFchX0e/69Gu6FHn2O 7FuQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=D49gZJTV; 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 90-20020a0c8163000000b0044a13c1317asi7928722qvc.122.2022.05.03.13.23.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:23:07 -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=D49gZJTV; 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]:59802 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz34-0004Il-Iq for patch@linaro.org; Tue, 03 May 2022 16:23:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39278) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWL-000222-IL for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:19 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:42894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWF-0003bE-Oc for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:15 -0400 Received: by mail-pj1-x1030.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so2886551pjm.1 for ; Tue, 03 May 2022 12:49:10 -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=31j8l5Xb7Ai6yPrq7Qeaf7BC+gVujFWoD6h4E291eb8=; b=D49gZJTV+uTUFX73oBJ1w4hUxykbDeUbjNE1Q+ueNvsa+EidksniAIn+Lfetky0Hb3 rgjvOwRscU4bCNUcDSWDt8RI+46GH8lYCIcEAj9gVc19JdwxZ1HKwOlNewhEEUpDOg7a W2TWMFjM2EFXgw3jCPlsC9YkFxBV5p5yWfirSLefF55FWnrgMMCYTAk3bTd25bPaSDRa uPtA8dOeiPYCLbbbNXIKEhxwNHirEbYBv8IOcWOCUzNBmYjX0klKwQSv96ybIJY9/3pk KEBKp2svEzAHbUQOP9DTZGsMgS3f3Qchjqea1N+4Pwrze+x/z6vbKizB9san5SF5M1dc 6RiA== 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=31j8l5Xb7Ai6yPrq7Qeaf7BC+gVujFWoD6h4E291eb8=; b=lN4Yzkbr8CnyetlDvRbB5CAsJoDLd/+Z+u+SIHFuMv8KVQYtyldNpUjWZ+Q2F0t/bM +ukSTnFsA2vhgnNDmBpex6lHX3fZ7p98WgTD2zN4lUDnaPqqR8Lgvg6EydPh2zAa9q+W A6dOA/TIaIgp5kJIBlsdPucAkVwLMZpL/b7OBvRn48tFp9G+TRkH7YTu4mJKg1ZBOtVX X+j82+n+LfOJcL6SYqS3HZAn1sP6eqg+lIUkyUrSYFg29qpuUrGYkWaFKWKO9oF8C9LU hF2ERGVmiUV+ExFZNkeqbwJcQa0JWxJUQQi+xrMA7ohIfmOYHQzv3tUGEeQo8N9dh254 jHyQ== X-Gm-Message-State: AOAM531qqwPIfk0uNL/ush2lprWIOgiMHvb+CXImpE5nnfo+kmyX/tYo fgg3PdxbiYmJM5IVj7zGu4jbpUyvjlZ2TQ== X-Received: by 2002:a17:90b:368e:b0:1d8:fcd2:c6ca with SMTP id mj14-20020a17090b368e00b001d8fcd2c6camr6502861pjb.44.1651607349518; Tue, 03 May 2022 12:49:09 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.08 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:09 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 24/74] semihosting: Split out semihost_sys_write Date: Tue, 3 May 2022 12:47:53 -0700 Message-Id: <20220503194843.1379101-25-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::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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. 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 7b6df09f35..12b2c2b0f7 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -217,8 +217,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) { @@ -232,9 +230,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; @@ -530,13 +486,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 7c18f77898..db4561b798 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -137,6 +137,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. */ @@ -223,6 +230,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, GDB_EFAULT); + return; + } + ret = write(gf->hostfd, ptr, len); + complete(cs, ret, ret == -1 ? errno_for_gdb() : 0); + unlock_user(ptr, buf, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -316,3 +339,34 @@ void semihost_sys_read(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, GDB_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, GDB_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, GDB_EBADF); + } +} From patchwork Tue May 3 19:47: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: 568984 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9790922map; Tue, 3 May 2022 13:21:41 -0700 (PDT) X-Google-Smtp-Source: ABdhPJym7/Mp4eP2Iud3GBpRJTWFuq5b3IvQ4Q7BGK1X0B8+9iTi+LreG172XxiMaNYRUr/H2wyR X-Received: by 2002:a05:620a:25cd:b0:699:c467:fab0 with SMTP id y13-20020a05620a25cd00b00699c467fab0mr13531077qko.395.1651609301701; Tue, 03 May 2022 13:21:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609301; cv=none; d=google.com; s=arc-20160816; b=wn+I0cKl9ulBXtpF6j8M1LG8JQQnVG2ieLB8CD0x/S+z6CNmShaWa2CGAKD/8Uk2zu WVioA8nbim2k/E3T/uz9qVl/ZSLWtxFxw/ZZwhZK8wMwCQ3dnjca6U8NWlTCzKUfeUMA TtUx9ZcUxIceGF1T+ZQ6RxSS2V0RW2fmXGekea3jo7jsh3KxXPxvNFT8kNHiu1/t42ru nnXs+AOKsf6v9i1e4E9jsMtB/qZxAmu9jNaZcotN+GdfXLUD+ohX3mGcEPXYAVbP9Fao R9nPzPL4DdQE6GTEpclOPxH4DQEtZoe6XffcllBKQYiKdjsrM6CISb2FLypkUjZKiske aZqw== 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=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=Yh8/wuj3DgD8Eu4/vMcN3QVT6wNC83a8aIiU11yS7WQvWRmEMjfn1ajBsI2Rl6ll5n DkQlYKJZqT6V2jaHAHZivwpp9KBALzOktklzc2DB7a14DJHm75O0UTrHaZrwM3nc2OsI qmuyUPxO1erys2goSL54k3DQlc/Q0UgyVT0CJIufxlkkwG7GBWQcKtw3xWcWa4CUruiL xjq2dNNOiHIxt6ADj0VuaANt0vUTWp9lwXDlD3IiC0uBwxZmReHfglNIg1yRbjZ2+6Ts OXztVdrxOHDsjRB2b2dJUIGFzwOv3c9B9KdBIhA7JR8674Xsh/M+STr/hPNDskc/e79s oWGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@linaro.org header.s=google header.b=YWJbCzWZ; 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 v21-20020a05622a189500b002f39edec499si5116896qtc.454.2022.05.03.13.21.41 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:21:41 -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=YWJbCzWZ; 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]:55762 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz1h-00012o-3t for patch@linaro.org; Tue, 03 May 2022 16:21:41 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39282) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWL-00022D-Hq for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:19 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:33769) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWH-0003bP-Jb for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:15 -0400 Received: by mail-pf1-x42a.google.com with SMTP id p12so15616324pfn.0 for ; Tue, 03 May 2022 12:49:11 -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=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=YWJbCzWZlYhjajRmYRSdmX5daSLcNOj8DJ5lI5inURV8z2D4/2BfbiWwNR5zD5/m/U Hv0FO4JtgZkTVdaiwt9ySv5sCoZXSdkw2N8dQOPOUbIANoqMQb3gaapXBtAtP6u1O5X0 Y3n9KhfRBgbkFxLXNAIoOXu1xG9fHAcD35GOyGXr0mHjchBBpkpEqaame3nI5zeVS5MG lEYYPe8utXWQ4Vyepz/1jhCFwb0IPeBJmse+rtHSmVYEnqd67XNSbx6P8YlGqHvuTfyH ciBpLbSfNKTMG4nvk1yTrXnyxG1+/pObfB0dZ0EPUlGK5/AZrSUkz/rSeGIro4MgZ9o/ lR/w== 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=vqBv2QVKsobJpocmgNSatxx08hnrv6y9/ePykNgKyQg=; b=htTGoqY8pqtlqbPUe+H1bOucSlAbMFzc2xAISm/5yqozVJgspRCzkuFJ0qTeYIMnfy N27fTuPAm/U2Q91N/dGDj32wSNtiu3Xxn+XFqhFxtvsRyRUrNWxo4hHifYZmKd5jeeaV NMwcb08v57avBAUJsim0zhz3sLtyKQq7PGdJU3P79wwaVEIpSULzWaF0+H1q4nli24Oq 6phk6c0vVAln5e+if7ZPzYLqzmdMCCoSlxClrShP2z4NdnVg5UVzRJemXJCPk1ZTE3p1 SPNI93CYoxJkAlajGy8nuwDqu3lRvob1kfReqGppoFi4hw0FlecBUZYm2QgrV1EX8Hi4 cX6g== X-Gm-Message-State: AOAM533NO3RObNUGArjzm+2zmm/06JtOTBZVN2EWdVZGxEwosKLAj1CT MtPSPFCg/DmebXiQDaExU9zWri1kPsNGlA== X-Received: by 2002:a63:90ca:0:b0:3aa:fff3:6f76 with SMTP id a193-20020a6390ca000000b003aafff36f76mr14966943pge.206.1651607350643; Tue, 03 May 2022 12:49:10 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.09 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:10 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 25/74] semihosting: Bound length for semihost_sys_{read, write} Date: Tue, 3 May 2022 12:47:54 -0700 Message-Id: <20220503194843.1379101-26-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::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" 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. 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 db4561b798..a5623ebf0f 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -313,6 +313,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); @@ -343,6 +351,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 May 3 19:47:55 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568988 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9792781map; Tue, 3 May 2022 13:24:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw4IN1D0N9svvCuHdmW/lu/+n1TwmFvek9Zvw98c5jW5xv6euY1EzypMOPv3CEh1Ryz4Nvy X-Received: by 2002:a05:6214:21e5:b0:458:1291:40c with SMTP id p5-20020a05621421e500b004581291040cmr14831731qvj.95.1651609483587; Tue, 03 May 2022 13:24:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609483; cv=none; d=google.com; s=arc-20160816; b=TWXeZ9y3BUfLbKDPFVAHvDANY7Bb+PWSMKSWipUCi5C4VfL+pyStP4ui2FGX5vZUmZ c/EwwvGIoMhZ5VIAzE9aWVPHLNbPo46WFnLXwJcFy+f5nyKBMpoMxjd+LAHdPKGzraE6 dAw0iLMSETaAUF/cP9OB0jj62ALcj+PgLwY+P+O4FBe8SKZExiY+sS7jTkIXar+7cHF4 b/RrZINxnmPisY19WBm9Gz1lSJQNYE1VQlzwAai0czukc/p8Q2IDFDeV8b1a/mOlXnfD X6xrW8PNFSL3jn9AFUJXfVL5rRxt/yV4E7CRXfO2+/cU9EU/lXtqzLZ4+KIXCSUPdbFD NMzQ== 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=uAqjsJ8QwShqmS+t+GKK061rZ5AHWSo6sjK9NNVPw50=; b=R3Vxv9wQadnsFml6v6pk4KpB/KFcrUjIjkPYfvuos4kkw7Q8NiXwq0jNtu4Ilv5JyT vlZsrM83wvx1MJ99tWpQLOmHVWcWaxHn1WzBzM1gU7tOMolyr3epbYweOAX513ZWbdcr 2U2dmtqsDRY0pNm29rafkQGXfMg70hDwBZtz0eRbuTwiiXrFCiey3JX+DPaIQIbb1RHV T5nvtIgsD/LR666+5lPU2fBw7JMRCyQxk86L1Jsf7PPLNINBvsOEQ4YC+4x+gYvPtjId jdcmzmfEvNzYhuktZI/a/5DR3vA3xp2IH+Q2+KBfitLiYtvc/Tkzw/YcELQTg4YQyKTY GUJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=juZGN7mF; 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 w1-20020a05622a134100b002f39dc48004si4934321qtk.290.2022.05.03.13.24.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:24: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=juZGN7mF; 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]:35128 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz4d-00073B-50 for patch@linaro.org; Tue, 03 May 2022 16:24:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39392) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0002Ga-0f for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pg1-x530.google.com ([2607:f8b0:4864:20::530]:34407) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWL-0003bX-Av for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:20 -0400 Received: by mail-pg1-x530.google.com with SMTP id j70so3886772pge.1 for ; Tue, 03 May 2022 12:49:12 -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=uAqjsJ8QwShqmS+t+GKK061rZ5AHWSo6sjK9NNVPw50=; b=juZGN7mFn3vqsCdraJGpVUUdnc/yY5EMBzJVWcv7QvlxK32oAdcXTSDFgrdzYaGlaO WE2m3Kw6dCkfwhdox99EQIcNd7wZfMyD3yUp+7aVckBkmPqceu/hWUlhF220dZMMcN6X ChvzDKGYFuR/Xm5BeHFQGZ18l8AEbSDRKyQWu8XsWz5TVSZdofPBPAjCQEMZR7U7xQLH jzGkvzXe6BbKA9KO8bVD7T6MLySgXc+/8g0E4EZ0zvzYVfew4jcj0/WwRkJx3IulETcK L3QIrxWa/T3Q2RJm/y4VD/rLAcRFgNCM5sAHWRBXseMlEMjLklGjxpXebSjEzY8dOAKj NM5w== 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=uAqjsJ8QwShqmS+t+GKK061rZ5AHWSo6sjK9NNVPw50=; b=4tFZApVgjgher30AdBfE6SUwIAbC3uTffeltN8qMuLrJx/YAZLuJ2FzTaFGpLgeIfg O+pXjbtXBDgL+z89pcRVBZzosh+ENQd6SfyJaI4eJAk/SaYUCPGcNLbmfPpM5xvjTeg5 E4ZSvqwi7mxA/7XtcA0rMNwJaLY7sNBMbJ/eU5AH2sI4vltCJKrb+2BvAufKVMO7OfEa Z9XUNEYqANfvdg7AqBjZ8Zu4C1uGR2sNE8A9ZeXc0rlzrrcw3xlRs5931EHeN/7NsVbO cnlRRAA08SJN4er8RpkEmcWweA/oTCMOdFr2Hpqy+w36P9Kj391NqOUnEBAeRivK9dXH owNA== X-Gm-Message-State: AOAM530mGsXHSyX3i3XaxfyXflBKy1DYiaaMkL17FFa1q+yqtsaWmNcr FEPAbnKGWoOysgvvogBQPHxJ+e53rlTJDg== X-Received: by 2002:a63:f94d:0:b0:3a9:eea2:9027 with SMTP id q13-20020a63f94d000000b003a9eea29027mr14583348pgk.484.1651607351731; Tue, 03 May 2022 12:49:11 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.10 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:11 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 26/74] semihosting: Split out semihost_sys_lseek Date: Tue, 3 May 2022 12:47:55 -0700 Message-Id: <20220503194843.1379101-27-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::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_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. 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 0a6e0d6eeb..056db1a0d0 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -42,6 +42,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 12b2c2b0f7..6f97977edf 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -226,16 +226,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); } @@ -258,6 +248,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, }, }; @@ -519,12 +499,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 a5623ebf0f..db8891535b 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -144,6 +144,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. */ @@ -246,6 +253,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_for_gdb(); + } + } else { + ret = -1; + err = GDB_EINVAL; + } + complete(cs, ret, err); +} + /* * Static file semihosting syscall implementations. */ @@ -271,6 +301,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. */ @@ -386,3 +443,27 @@ void semihost_sys_write(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, -1, GDB_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, GDB_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 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(); + } +} From patchwork Tue May 3 19:47: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: 568992 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9795527map; Tue, 3 May 2022 13:29:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzgbfCJw2Ct0/znWuKZ0WDFGYxyYzgWIzNBEbeW5dkRZ5JPWvFgjUUqDCUpUoQ3gJm3zsOI X-Received: by 2002:ac8:5c8a:0:b0:2f3:abd2:f5b8 with SMTP id r10-20020ac85c8a000000b002f3abd2f5b8mr7206393qta.554.1651609769122; Tue, 03 May 2022 13:29:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609769; cv=none; d=google.com; s=arc-20160816; b=Ibn1HQCntUlbOw2aP5XDQqXJZDk68KRCXBL7R0xoCT3F+EBL3RaWKyF5zZkHE36TvA PFoRGrgOQ5uvRaLWNc3VFOAjTfN5S8xQzRKRb10sF3gfHJmNe5+D9aqXBrlrDWDMG2Qq CTdgrK80pgHnBOklVPbY3b6b3E+/Y2E30bcukJTroiDiSWf98hMTlUdZifoW6uCAcqai 8XEmqFChgxs7bPdZA3YRrDfHRCP2UDoOJLmQiMI4vgnvHD/z5PvH0hof6DHWNpST6Ehb o3pSbLZVj72Lq01EEh5EXWjBeZAa4Yh2Ahiv7i9EjgRA55d8ep+u2KEhogZOAK4KzT8Y 7xxg== 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=KiiUe/Rg+SRimDwSRl33F/1OAQaMEIf9kHTB68MrbY4=; b=zscaz+JoMsBv6pzayM3qxbhuW8EGW7QW5EI5TcJqj5lj+01+U1RQcn/H7yXQaxnleF 16QR7GH6GD5z82LCABUBpB6YhBguu2ehVdzt/w3OCDa8ogN787SpIu/yCpDHnnp9JSTw aWSMSsYWeatHBtNaoFqY9y5vIBgNQHI87ZmNhzbE61tYGc+1wLL35MnKsij2ftjevkm+ GaG6a/4a5XnWPNp2dzffQ0lbbY22MiwXqSL9Ip4GXCkmEC4s8L1OQHu59oH2/NlY+2op WQbEtW6/ZDhc5hbQVMq6ZCTHFeukEE5Axi/qjSUnqA8N1cM71gsHW3QH56kHpPOy7eNV bVTQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MjQ2wVLQ; 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 h26-20020a0cab1a000000b00446546d1ed0si7355113qvb.483.2022.05.03.13.29.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:29: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=MjQ2wVLQ; 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]:42730 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz9D-00077q-Ey for patch@linaro.org; Tue, 03 May 2022 16:29:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39402) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWT-0002Gf-02 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:46900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWL-0003bp-B9 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:21 -0400 Received: by mail-pl1-x635.google.com with SMTP id c11so5631334plg.13 for ; Tue, 03 May 2022 12:49:14 -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=KiiUe/Rg+SRimDwSRl33F/1OAQaMEIf9kHTB68MrbY4=; b=MjQ2wVLQ9s6Co3NFp6uie1QJUG+KJJV/evpWGGRrBDBFqJPp5X6V7wy4VgQca7OQ9w pRScgA9Iway+7Y2O12i3JARa4XTY1OmgghOY2/KSHrSaqadZz1zn7xfbhEOEn710ut9S JbDBOV3+eE8+GIW/H6ZmIukqHFsRTxrIm6a0IgkTS4W0YLPpX/O8Q6+3rSUj7Tgr1zmm YwTZimqY3AYL/D2gmUYaf7jJf1akwPVmm4p8qwGyTeI01+DyNzIDgI5OCnb9Saw3esZS g+BnFTVwy4FRZPmxSGH3idRiYwQMVsm4+Eh/QObYJ1hUdmY7DPShwz6ThSuWGzGzNyJG UUXA== 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=KiiUe/Rg+SRimDwSRl33F/1OAQaMEIf9kHTB68MrbY4=; b=Vnb4CvmkkZJASsN+17kKfKwh93tC4tcb4MJ/CecD0mW+WI8tC99NhcYziYfs8kfyLz 9ahkgIGH1HFtxgHpPi3yt9y+2yQ81O/5hrPzk+5NRw20xuAcjnVrH/I4a95HZ13ELzVf GUFnrzqNHL1aLgbfbOuxJOJg/Sp9mA58mxSjwL6yXhb2mf3htsIYtCevFNlBNovsHUDy g4slIiWRysBL9PiGiohvY4+s9GLxnOXfFBcwZ7kZEbjyakxHSJyZW7DyIFEirVU0uipw dWaHkAayMsUJ1k08hC2gaUrSLUw2FP2SFiZNWyg/TkvWcH1kDn6OYi2dh/QJIjSdUKu8 1cAw== X-Gm-Message-State: AOAM530ZITOJYzGcbOGEPYoaCpet6jDU6HXfmK+t8LrKRr9KTRpKnDib hUZCsj+p+ejCxvB4EuF1PIWL/0rRxnd8Iw== X-Received: by 2002:a17:90a:f3c7:b0:1d9:6832:7be0 with SMTP id ha7-20020a17090af3c700b001d968327be0mr6423474pjb.209.1651607353736; Tue, 03 May 2022 12:49:13 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.12 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:13 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 28/74] semihosting: Split out semihost_sys_flen Date: Tue, 3 May 2022 12:47:57 -0700 Message-Id: <20220503194843.1379101-29-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::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 1 + include/semihosting/syscalls.h | 4 ++ semihosting/arm-compat-semi.c | 83 ++++++++-------------------------- semihosting/syscalls.c | 49 ++++++++++++++++++++ 4 files changed, 73 insertions(+), 64 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index fd4bc4e937..8e9cdcb1c1 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -42,6 +42,7 @@ #define GDB_ENAMETOOLONG 91 #define GDB_EUNKNOWN 9999 #define GDB_ENOTTY GDB_EUNKNOWN +#define GDB_EOVERFLOW 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 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 8fcef02386..ad43bc8b0d 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -273,41 +273,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) { - /* 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); - size = be64_to_cpu(size); - common_semi_cb(cs, -1, err); - common_semi_set_ret(cs, size); -} - -/* - * 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); + if (!err) { + /* The size is always stored in big-endian order, extract the value. */ + CPUArchState *env G_GNUC_UNUSED = cs->env_ptr; + uint64_t size; + if (get_user_u64(size, common_semi_flen_buf(cs) + + offsetof(struct gdb_stat, gdb_st_size))) { + ret = -1, err = GDB_EFAULT; + } else { + /* Undo the tswap from get_user_u64, then swap from BE. */ + size = be64_to_cpu(tswap64(size)); + ret = size; + if (ret != size) { + ret = -1, err = GDB_EOVERFLOW; + } + } } -} - -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)); + common_semi_cb(cs, ret, err); } #define SHFB_MAGIC_0 0x53 @@ -327,27 +311,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. * @@ -366,7 +329,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; @@ -479,12 +441,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: @@ -806,9 +764,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 702541b270..1425156bf6 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -157,6 +157,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. */ @@ -289,6 +295,18 @@ static void host_isatty(CPUState *cs, gdb_syscall_complete_cb complete, complete(cs, ret, ret ? 0 : errno_for_gdb()); } +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_for_gdb()); + } else { + complete(cs, buf.st_size, 0); + } +} + /* * Static file semihosting syscall implementations. */ @@ -341,6 +359,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. */ @@ -503,3 +527,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, GDB_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 May 3 19:47: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: 568979 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9786865map; Tue, 3 May 2022 13:16:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxGEG/9Ws6SQLwWrchjyAXvQ6zpTK8JGCRSVGtl8lsQ377dUVff9UWeYfPujdR20BGwTSGE X-Received: by 2002:a37:8605:0:b0:67d:2fc4:749f with SMTP id i5-20020a378605000000b0067d2fc4749fmr13700873qkd.552.1651608963897; Tue, 03 May 2022 13:16:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608963; cv=none; d=google.com; s=arc-20160816; b=SXJZZcFupb/hUpBjIMgdMdT6Ce+4rjyAip8EPWqaL1eOWviyAviDzTGVbnRAEs/qph ObHrm1AGOU7mUZ3AaAp6SPFlPmGDbBukZrVwB9iD+s7D8IiwuVZoMxyyVoWeDlEsglix kz3zTp5wI7eRlr7D+ylJPdpmwjqUI+slehK/3exU0oP0d7TyHZHXcqlx3AmNnQw2yX8n XBS1xU+hl3zdGR8fYYVdSvMc4kAYfMuGO2BNpeFqXWDh1fM/W+pGgzygyBL5SFh2hUAj e1HS4XfyErsVk1DzR8PmxynlfsVOb0hXgfTBsDPJBcA8gFySc+sCTMH6gLPJ79nb2+ma 6wog== 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=4cvH0ebqo0OJd6RBcXpOB2gOw1DN8L+GgldZsIUiDKo=; b=Cv2YafnBHaXiYzIN1ENX1RSdKIJvXg7Yi9O6i5xroY0PhHhkrKC+PRo/MF/Jo3f/NM xJOg02ndI23b8V7gzscP5dKfLNzDeZl+guU6uvLmFvlP6VjQxvzM0W57RkI4VAW4XwG9 8ONGA7ZuH8rSr0h4JYYIaAT8JawWECxifCJ6agRwyNzfb5CHwLAJyFbRQui51o4VCcBg hlyi0h4i/ufzH2p4RPtg8zJdXjDZxF3bE+l7fLY9XmCFmzUZc7KXP3jvWy2wfqo6NnW6 HFEDv0CnjvaUFvXiBG0xpah63zcy7JFKdBASrwzEw4HGjxKig8JiYHip23wdSllVP9d0 4FHg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Y4eOvP6F; 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 im2-20020a056214246200b0045a88d4f792si4443399qvb.285.2022.05.03.13.16.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:16: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=Y4eOvP6F; 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]:42520 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlywF-00005f-G4 for patch@linaro.org; Tue, 03 May 2022 16:16:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39420) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWT-0002Gi-6p for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pg1-x52c.google.com ([2607:f8b0:4864:20::52c]:39475) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWL-0003by-H8 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:21 -0400 Received: by mail-pg1-x52c.google.com with SMTP id i62so14802499pgd.6 for ; Tue, 03 May 2022 12:49:15 -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=4cvH0ebqo0OJd6RBcXpOB2gOw1DN8L+GgldZsIUiDKo=; b=Y4eOvP6FIKO9Z6vVBAbwUilWA36rzk2sajzQnm7PMOrfkjR4m8D5oMcj81T+cwslD0 /YGt2fJqqknhVK+Yw6Cvz+1NLrO0JMse0GPgWa94O6le19gFKa1kqOW4pmssbD6CKkhP INnYWQ7w1bllhEiHo+I8le3Skhy7h1LS3Hm+jge5oIYCI0bVpUisj5jJfK5VJTeVdcvU VhSevERLuoxxNmsU8w0y4/xBDMBCGjRqc9oiVGv5p7EuyBhGcC0D2zN2M5PXbym4jDqj Nmun/eUFTt3rY5Z52LUXR6AsRALWksBeBSI3MxfQCPwCSX6ddqmX4POPNl/4t6hcqCJz GacQ== 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=4cvH0ebqo0OJd6RBcXpOB2gOw1DN8L+GgldZsIUiDKo=; b=RfeJnbm3zLhccjTGk6SjsGm1DTmFxppFwLgAWr8RK0S5M6njeqzdGWRmSLoSkwHK6l C+TLjOs6vfOsbWiFJRaoIDLxMwlWTF0YFr/h+JpHjWBMg0B7gUYQh5vkUgNSnLTQ2NKv +7jZm0Ytm3CtrFMaFRUxjFlJZijZ0afS6pnwCRUf+IUnfYCvM6KALgfmNicy1nBoBG/t +oHqtBJATmrwFvIO0Ev/fW1BbYt7uy0lXqwQ5HUV/LHuWduboBjCu0zTlTb7HuxoT4ZV XXSfi2DjO7/pcvPNfNWg6TlWOWfiH26njSj/7DBWBZNGHiQbkiPjpM8uk+hP/lPX9sgZ lhAg== X-Gm-Message-State: AOAM532wToWCdrVEAmZHdCm0U8IHKSjbAdRfiDWnifv1aDdj4fRF0Hje eWbSB7S6DrYBxAqkKIDHmgcYKgr7cr1PtA== X-Received: by 2002:a63:cd41:0:b0:3c5:1242:3a0d with SMTP id a1-20020a63cd41000000b003c512423a0dmr928181pgj.266.1651607354731; Tue, 03 May 2022 12:49:14 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:14 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 29/74] semihosting: Split out semihost_sys_remove Date: Tue, 3 May 2022 12:47:58 -0700 Message-Id: <20220503194843.1379101-30-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::52c; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52c.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. 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 ad43bc8b0d..9c98af19ca 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -473,18 +473,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 1425156bf6..3464896281 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -163,6 +163,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. */ @@ -307,6 +319,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_for_gdb() : 0); + unlock_user(p, fname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -552,3 +582,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 May 3 19:47:59 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568982 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9789346map; Tue, 3 May 2022 13:19:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzL6LdbOJnwWeUmjgiaVRhjk7VsNE8k4/SVythEekNeDEcmSQMZxfo8Re3payKhUYHP68GY X-Received: by 2002:a05:6214:2a86:b0:45a:8a2d:1aa0 with SMTP id jr6-20020a0562142a8600b0045a8a2d1aa0mr9986488qvb.111.1651609168708; Tue, 03 May 2022 13:19:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609168; cv=none; d=google.com; s=arc-20160816; b=TNk4uDKsfqO0vhr+Wq1OPmGe+GgdhlxVbBeLooT4FqfP3YOfVkKUYu3JGOVCPotw5T 8ofLG10uxF//3XgsvG7DDRuI5hm6AX5/kXlIYP2vh0uX3qsfA+3ZtbvKfGhdsnLNHD9s y/LChoBUSCBGxnTJv9Z7fBkfbFcEOJcO+Mra50ek2SWHcG7zOb+udAGi/pCHeLsM6ebn A+0OVZxktWetXINgbsQoriIL+lDHGLyVA0/IKJJek5Xp4t+sPrGrURwZQE2+ycVv3TZR TYzjYsltSkdggMcsYngXLj0DB9CqJ87Ag+0MYOI3ojtjkAPMCozOUudHTMH2SkoYk3vi /eqQ== 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=GwwZTrlMnRc3NXYIV+jBGueka7cjStXbOSEZpF7o1wU=; b=05dDbJ7Jripd+/AOYNmNK149eEYj3sOXT6Hkn+iXF9bM4cxpokAraSB4Zh51tO2tBO cdQQNNdpYYsGvo5fZ8kkYdqrh9CtQDa2zqgRi0zK3XKyuoCSbqk1CFfTYp/0aUcVNrS/ 9fHNfmhXWEHcOfwkNu46KfBgoI5azpX7PbXWMSkDrqQhF0qtdgg0beCWOdQ5K51QK8/e jDDNZromuanXxOEETmBeHVcCyFC2IoCNds1hgXc0V97NKGVq9JrAluFMDqZCBhuC9rca w9pjXWgMg44EKHrljSuQiUpqOBGjgCw1RFhSgHR9rUYw8jm+t7CqIyN48LXr6peg5KU4 Dklg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Dmjuq5/o"; 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 jx7-20020a0562142b0700b00443db3daecbsi8904359qvb.108.2022.05.03.13.19.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:19:28 -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="Dmjuq5/o"; 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]:50786 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyzY-0005z5-8G for patch@linaro.org; Tue, 03 May 2022 16:19:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39394) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0002Gb-0f for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:39542) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWL-0003Wq-Au for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:19 -0400 Received: by mail-pj1-x102a.google.com with SMTP id a15-20020a17090ad80f00b001dc2e23ad84so3204444pjv.4 for ; Tue, 03 May 2022 12:49:16 -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=GwwZTrlMnRc3NXYIV+jBGueka7cjStXbOSEZpF7o1wU=; b=Dmjuq5/oO6z3ecBQT44kCnnE2X1s6LdYGs1nQhOmfFSTgVRfT5m4NxWnmBJomF6CWt eCDYfLFwqNlmDzgtzjUoKGsINHCltu97LXyFWNDc81j5Qo5FoWKWxveE6+q+iYvtNURx aRz6M+RHvm1f0UczvHri/aHXF458nmhPChiSe+ebT/hVYnGgT0aBhBoMi+Vqr9Hxr1CE 2fvhRzgBDw3nXF+P5u5+SqEMS8gx+dNRZeMwEHUcXHrShEoi2zK7fnpq/2QOYs69eJ7a 35/SCoj9qpo/JMX5EEtZPOcDtKc5Zy/6ErHnXqjQdVtEEtqsnzE7eGdiq623Onsryquj zjDQ== 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=GwwZTrlMnRc3NXYIV+jBGueka7cjStXbOSEZpF7o1wU=; b=eb2XKFx23WJ3O0GUy7VnbWTg+xDxMSpEtx2CBOLR09x9gNRZZECbnrSkZtw3F+qXo5 FaMnewWn+OW7giX4+SSm/jE2OHx5CTMMXSK/7EokbxYGV2XfG8keJsLOasEg4pAFk8Df 8bsLoYU7AxvH3u40MAhlzQbC7hMN5XAZFEdpPHPDP1rwFS4NJhfrsHCqTiV4cPxRnXlz +hcamrhYj6dKq3MAOUBDA6WYcfK1CysJDaxThtFtdUdZwHZu/dWBOku6owtwDUDUNWjn 2QVJcmRM6hajHhGVx8/6lZ8gVRztyG2AEi9FcHkhFy7EOnTZDZ8SaR3p7idipKqQo8Tl os0w== X-Gm-Message-State: AOAM533sdrQoxndKo4NakAgh1SbDuYl1yv5eIIQkyhZ8YyTN7MNNuCFK tdFoa6J8tpbuAbzDC3vr9Lz0WRiaIxhYLw== X-Received: by 2002:a17:902:7795:b0:157:c50:53a6 with SMTP id o21-20020a170902779500b001570c5053a6mr18022936pll.40.1651607355638; Tue, 03 May 2022 12:49:15 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 30/74] semihosting: Split out semihost_sys_rename Date: Tue, 3 May 2022 12:47:59 -0700 Message-Id: <20220503194843.1379101-31-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::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" Split out the non-ARM specific portions of SYS_RENAME to a reusable function. 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 9c98af19ca..f554f4761f 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -481,26 +481,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 3464896281..96d823e8b3 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -175,6 +175,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. */ @@ -337,6 +357,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_for_gdb() : 0); + unlock_user(ostr, oname, 0); + unlock_user(nstr, nname, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -592,3 +638,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 May 3 19:48:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568972 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9781890map; Tue, 3 May 2022 13:08:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNep54ha/97fWbcXzSIyXonGHpLTjinLApr84xXWeMA75zi9b+WP1G585e3dm2ZZ37lb47 X-Received: by 2002:a0c:d6c6:0:b0:456:4e6a:b875 with SMTP id l6-20020a0cd6c6000000b004564e6ab875mr15010470qvi.34.1651608511325; Tue, 03 May 2022 13:08:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608511; cv=none; d=google.com; s=arc-20160816; b=TkPa9s9VmKQStYTq0TD7q9Ntbm0Nlht7Z8Yb42zmFbqvXUT1t5MIE9+NfuiYHuJjrw kE/9hJqn5BEkxeM/4MJmErXC7UGFtNh0B1o4/B0wAkKPEJtNn6oUtPDQX6juRrG6sPTY cbwJmki/rn2wvH7ryCgqWgJT+EiNdpmUX5hykevDTxl1pNW7Xjy9DdKq8jfY1ikrnkvg 9nwVj72Q1M3LPGEBLKAd/ud6LvbiHsMPBYsC1SdJ2kO4EXGeGyfWQFeaTliOaJ+5PQwZ qrkjY5XWi0/SuF6BsAwn6OfeCLAZ05gmgJPQLM4XBaGywA61n8B9yXk1YNa/bFkhr0T5 Vy4w== 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=/Tnt2IWUsnzN1DncvQNw1ounPVnk2pgfg+nnvDvrCdE=; b=b3IEZCRCKLE9rjipCH5EO1pfaaYGzCpTvWjeP0O/wF+CrfVjkD+9utGkGR+o09pudy BrbeEeO6r9OzCr0oA8wJALFpmq0OfemBSc/9fbXqdlShW1UegnheZ0JsNBNe6gw4F7XZ QAiDpzbPBfFrZ7jtpH6Y0OxWtD8ynrENwPvRDm464pqjJ4DU1cZOccsN2yfAEteZdF/y wXrW9A5OEkMYgW7jFoPtiO0ERWpnWuD1954P/4bAutX5g8LRPLjz+N7qc9rVFSkhz6lq Xfvs+tN7A5UpJd5ZS4GSYGi27Xlos6bMG8QlOvjRVQuyVbpzMikVZz8ekYAiF/83wLmS DDaw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LUyAqobH; 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 u5-20020a37ab05000000b0069fbff7cd60si5562569qke.24.2022.05.03.13.08.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:08:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=LUyAqobH; 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]:55716 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyow-0004cQ-Tl for patch@linaro.org; Tue, 03 May 2022 16:08:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39418) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWT-0002Gh-7C for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pg1-x52f.google.com ([2607:f8b0:4864:20::52f]:43782) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWN-0003c6-6O for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:21 -0400 Received: by mail-pg1-x52f.google.com with SMTP id q76so11750651pgq.10 for ; Tue, 03 May 2022 12:49:17 -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=/Tnt2IWUsnzN1DncvQNw1ounPVnk2pgfg+nnvDvrCdE=; b=LUyAqobHP30Lh8OtIA+55QMwrRw5jqnYhqmQOvEGqYMj1i4ID6zpUKSKuc1N6tXY66 dmmVomoGcDXL9Npj6XHnHQW5topaox+SA9JamHHnvn9FMKDIWnnTeAnW0J8ctgQt7FBV 1ly+/q4fbnmmxaZW0bG5QaNZwvhWQrQ0Sg1/g1jgNfnciWqZr6yVTO2lMDzMfnOJgS/H wuyYFi4vOQyuxZGmKwt26tKwvJyoZGtUiKGYGhKw6cGnGY5ki9JFoXkGgJck/oQ/JLMl Fo4j8EslpnIzXgLhqvaIis7qncCrOXn3kT1SagsrVwBYwc7X9GgbNt3sNbbgwoKP0tCS p4gg== 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=/Tnt2IWUsnzN1DncvQNw1ounPVnk2pgfg+nnvDvrCdE=; b=oT+o+wQXT7ZfP+QIeSJrRRFTldLt5pVVECGaGlSw3EN/35LedLD7C7Yl40mJfOcpoH HzWgOBCY+LPoR+eWE1XSRAKeE66JW7hPzRyYRf7IBbNf8ebSMQ6QtEB394hcmh8K/Yjh hprzDgqgah2C+85TaEJZg98Fy7d1gXxIdQ24laAufPF8F88lkgAaJn/vHhYVTYvp2QWM FnI1H5mPO7kGwOX5MvexO29VEX/TdWFKHZsB73KuM1WmbFpRn8qNBcJMwuvRqIguFTyo PuXjs7LQlPM3PidH1T2JfPoS2YBfCRUZISGNfcsZyGCvDRDPRaDYCPl0rGm0CGlTu+rU NZGw== X-Gm-Message-State: AOAM533Q2umBvJ3l/G2NaII3SqYv3RjNzhDw5NXeWq3Z934eA8G98FLu CpxMfBtuDlKW1MPk9t8SPYAZBCtfaet+ww== X-Received: by 2002:a63:85c8:0:b0:3ab:24cf:e625 with SMTP id u191-20020a6385c8000000b003ab24cfe625mr15309386pgd.212.1651607356343; Tue, 03 May 2022 12:49:16 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.15 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:15 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 31/74] semihosting: Split out semihost_sys_system Date: Tue, 3 May 2022 12:48:00 -0700 Message-Id: <20220503194843.1379101-32-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::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" Split out the non-ARM specific portions of SYS_SYSTEM to a reusable function. 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 f554f4761f..a7520d6f41 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -496,17 +496,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 96d823e8b3..b6c395af22 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -195,6 +195,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. */ @@ -383,6 +395,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_for_gdb() : 0); + unlock_user(p, cmd, 0); +} + /* * Static file semihosting syscall implementations. */ @@ -649,3 +679,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 May 3 19:48:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568996 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9797708map; Tue, 3 May 2022 13:33:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJycM1JKZI0Hg3P+YxCrNeOPEHKx3N1m6d+e8oHC6Sy3NVdQj+peoYokggxCnxU8zDdeAlHc X-Received: by 2002:a05:622a:138d:b0:2f3:ae81:19b with SMTP id o13-20020a05622a138d00b002f3ae81019bmr4371959qtk.116.1651609983628; Tue, 03 May 2022 13:33:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609983; cv=none; d=google.com; s=arc-20160816; b=B01fFyzdZpDVAwAPvcXy1IPPQSG13at2WJC9RQ7RsPMR4uYAKOGFNPjH8EUAr2C493 GCCZ2uAjkeZtcg9vpyJh448O0pxqmvCM29LAX0UyAJ/6HBC8Wo+ssaE0aJ1EACvPf65z M56iXSWLvdYtQg9nE8A4JXkonf+OTH09tuL4gBrt8JvN+S8ymGBtthr5qpcI1q9zuJmN G4/m9arcmsT9WpRXqj/mH8zVG8DGXXrpaD0rBJME/XO/SR///YIVZ17KfkHwWsNJfeMG lNvccNWGzsd8kx9D0UBGVlEfU/5obbm2nZwVNJwuAEMP+dmvJ3GAtpheFaq5O6yGrW2/ +Jnw== 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=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=x6C0x4oqTdzfsCNrK0sf4Yrm/tk2P32f0eeZR5LAuUVqWoiP3/o/NjyB8qhLgc1/AA M7ep/YiX6+2rk52+lvfCBU+111IC1GYThoyxk63LYwvakYj9/6WPh5P8raqQsyZltmSV vYilzI7CxUV1TfwdI5gTCfm1slmG5WVJu+bTAewmPNH01onofB+PSJieHI4t4PZmAUpD JjAneX4ChcW9YO3KNkzblUUrdCj00zNwbq/twCAFxp0DbDbyVBYfubYcMhWZHnlabjGO hEqppq6XKuJpe6mfrcySf/O8ks6ke1HdbPb7XdHqyXRYLVJB5SymyFO3sa/0MWL/B36W hBXg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=WpHk3OKd; 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 n3-20020ad44a23000000b004443b158fb9si7955217qvz.412.2022.05.03.13.33.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:33: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=WpHk3OKd; 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]:50358 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzCh-0005yZ-2v for patch@linaro.org; Tue, 03 May 2022 16:33:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39422) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWT-0002Gj-7n for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pj1-x1036.google.com ([2607:f8b0:4864:20::1036]:42900) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWN-0003cN-6r for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:21 -0400 Received: by mail-pj1-x1036.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so2886784pjm.1 for ; Tue, 03 May 2022 12:49:18 -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=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=WpHk3OKdGQadFBQi9LTKD1EOge5zzf+hP5X5uue2tytY9RDaCJWffi+NxFkHRIYdlp yqneyb9lVVXhRGn7MA8sWobo5kH+v6vPAyLubXGecnmTIimfR/tOJGirZZa1PGDrvh2a uoSUpekIWW1CIsez+pJlw1ZfizbIG/NcNsTIZfdAGDXV5JTrvuDACY0r+JQg2TZDha25 zUs/Bz2BxooR8wQC0zop2swRYn2CrDB8RtlGxqOovo3g7AzaDfMC/u8XFZYMW13wgVlP y3XAse3zhmie6/v51df7vm4ZSdmjYDkSijgaCutZOVDNAMDzllHF9k8r9+5CylitfDwz /PyA== 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=7WEErp9U3fuLYooIL1EDmPgWGgYpjbgO1xt64/VLw3c=; b=fSfxk+3x12C6kOCOwwnMNBFL/ilM19CYZDn+80Ld5NNAgPJlNIsLAtzfUAR+LCUXOw NCXlmV0z95wQNrCPXJxaQHK8yOFhSAQIupob7beTg3YZxXgzcVL5L8SqHl9+nVD7uSRq lz2pzgKoUZAhQ7Knm/1kMWGW3pvK/cNsX5tAU8CYG+DvGzAA4/aSI8BI8dvPtU6wGpMo RK+cq481v4grZjOs8y5BKbR78TwzaOyNLO5pdVDY4GSK0ySoO/yEILS1Ov8xxiM5XQbf /oaG3d5I6S35WR2kOLqvVAbleRSWghDVGdCTxjsKUZUQ3ngpIszgXYfF49DRzjpumU+Y 27Jw== X-Gm-Message-State: AOAM531OFF2nmfjruS+2wE0/sycIw9SaI71oKUkt2in6g4qIALuqge8g m0nO4UPyjWRZ8qN9knypBVDqV8lpZXAmwg== X-Received: by 2002:a17:902:ab04:b0:156:1517:411a with SMTP id ik4-20020a170902ab0400b001561517411amr18089563plb.128.1651607357204; Tue, 03 May 2022 12:49:17 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.16 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:16 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 32/74] semihosting: Create semihost_sys_{stat,fstat} Date: Tue, 3 May 2022 12:48:01 -0700 Message-Id: <20220503194843.1379101-33-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::1036; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1036.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. 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 b6c395af22..7bc2640512 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -93,6 +93,52 @@ static int errno_for_gdb(void) #undef E } +/* + * 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 -GDB_EOVERFLOW; + } + + p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); + if (!p) { + return -GDB_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. */ @@ -163,6 +209,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) { @@ -351,6 +410,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_for_gdb()); + 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_for_gdb(); + } 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) { @@ -659,6 +763,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, GDB_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 May 3 19:48:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568991 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9794442map; Tue, 3 May 2022 13:27:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwlvdKY3+jQVgDXH8t/gK7TZmiEzmTGzQb7Fla30fb4OwWX1cGNL4vkVoHggx1P1MGwBtpW X-Received: by 2002:ac8:5bd6:0:b0:2e1:c841:35f6 with SMTP id b22-20020ac85bd6000000b002e1c84135f6mr16388356qtb.120.1651609650944; Tue, 03 May 2022 13:27:30 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609650; cv=none; d=google.com; s=arc-20160816; b=JQEQEOjfIjoPkK7ivLyTTpetkWwNYw3Ar3PtfDfQqE38QxuiPWzJzgm8uMNeel1DWi ZI9jzKMOS2Y5K43lgDguiafASbEHVkNNBT+0D82vzmxfKpLJ+bXrPw4rV8QV01rw9tW4 BhxuNfwXF2uVNys3RLuaVTiCm6iVgUmcg85dz1X3wU03H/KyEB4wZSPjo64HAypRAFVp nEOu1IyNbzUkoB5Re6/QWemwPlDw4cOjAGsW4osV8oaBwD7Vp7NJk3hzP9oocqLEx7ep AxGGdjH9P8IcNJYjs+6k89HNaz+hYCanPypMq3k4mmvMFOvdzxjeVAZ4JvlNZoYDTPpw 6rCQ== 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=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=iMSXCHXBa/AM8yqa8l+YDeuiC2OzlMltTCQoYGxZHAcs+o8nW9vv3c9D0TICRBk3P1 8CMoquuqQz8K4rf9IhG67olh0MioMEPhPMHKlFLYSynO+EcXuPyt2YeM6U9fLWL3HH0m Z8Zk0HPBGoUQktASbOW3we+mdEzACUqZpV/qivrRT1ybNledeRLb9nq0fpxRgtxHM1sL jNDdTQ/POKrUbucACA8Awp/uXivTjrxiCpR2cNOyR8YlIgUYOzw3ZAO84EoRMVWZKlI3 Cg3upVOHvxK5R6acCaaVh/l4n9J8i1bPv4kfqvB4dbaytTUHjF3MEudk9HRTAuweJXaF frTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fALOPF3Q; 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 bb2-20020a05621407c200b0045648f2a1a8si7675110qvb.142.2022.05.03.13.27.30 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:27: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=fALOPF3Q; 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]:38982 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz7K-0002Z7-HJ for patch@linaro.org; Tue, 03 May 2022 16:27:30 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWT-0002Gk-Bd for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:43785) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWN-0003cS-DH for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:23 -0400 Received: by mail-pg1-x532.google.com with SMTP id q76so11750698pgq.10 for ; Tue, 03 May 2022 12:49:18 -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=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=fALOPF3Q+6TIwbPSmDw4ZFH8+9IY+UTCec4JKD7MfyPrp/v32MqcHpDwF5Nj8/Ehfr jbKqksT+Zf+3BsUqk07NtiUMLJqaSNGKeezm4zE/m/3G7717CDWqDp2jxbqHWfmUx2qX UWvEc+aUCbY3jPNg4iXTFsBGGoATLo6Bvi0YqvLeeSynFD5tdiC6hnm/2kIYinvfQJiW 7w0fkd7MSVyJu4d/ByhcWjdZd7tCjprcUMO2kxufaikJHpEVkOROhqpthbi4GV0uxkiW 8zUd/yjkknFe2XNwGow1PR1EKkXANpToq3Jhot4YZ6iickOONLRrpMtyH8DWENNG/aeM HrQg== 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=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=lsSmmgjQx6qGIc8z6q5WTApvup3VSAJCbtP79WewGr40pHDYPj8ZY1cUeyAw2/bXMX k7n2oZ59vOKBBA6Xxwen+QRhrEROvR6i3aJDTrGlQ0WFNjomCBF78KYk479GudX+7kDM wCpieb+DaFOkuhgE+L44nxDtBO0Efw5Kj4SXjq52vIaT6J0UM9icGcwy5lcadxkPCEjB cPT0OP2e6e0DxUHeAy6IDZUgw8VHAMdxCXc3bUCMMvNCYDnuAcNMKq/IjcVAaSssrN3/ 0ph4hZJSR85B1WEq3FUJUeWw6369FEuaL239+FjYP6MB3/rwCHv6JbRDjkFn579GRe0e Ei5g== X-Gm-Message-State: AOAM531UwpYqPsSTFZe+/upBj/p/oFV3WHJUS+m4yRACbUC0MG6WYObQ JBvVvHKim/b2EpyDit1zZ3DxjtGyEdBYIA== X-Received: by 2002:a63:1113:0:b0:3ab:a3fc:1d8 with SMTP id g19-20020a631113000000b003aba3fc01d8mr15121040pgl.450.1651607358046; Tue, 03 May 2022 12:49:18 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:17 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 33/74] semihosting: Create semihost_sys_gettimeofday Date: Tue, 3 May 2022 12:48:02 -0700 Message-Id: <20220503194843.1379101-34-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::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" This syscall will be used by m68k and nios2 semihosting. 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 7bc2640512..269f750d98 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -266,6 +266,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. */ @@ -517,6 +523,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, GDB_EINVAL); + return; + } + + p = lock_user(VERIFY_WRITE, tv_addr, sizeof(struct gdb_timeval), 0); + if (!p) { + complete(cs, -1, GDB_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. */ @@ -826,3 +858,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 May 3 19:48:03 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568995 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9796816map; Tue, 3 May 2022 13:31:36 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyNWhZC1cgQHnbzUvBxyTn+QMnY6qvlJyhqC9hMblWuWd4AH7HprPFKH1gI5lRhdnuHaEaW X-Received: by 2002:ac8:5954:0:b0:2f3:7d71:869e with SMTP id 20-20020ac85954000000b002f37d71869emr16572786qtz.183.1651609896221; Tue, 03 May 2022 13:31:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609896; cv=none; d=google.com; s=arc-20160816; b=ggYju7YUU97FVnW7dtH3fihKuJt34hLyE6ILWhblbPah1WfMdAiSL/A6iaEmx6EBg4 S5PQo1CiarJNF143J72dA8kgB8BHAG2HMbYbfJO+CTBWJ9izhWbjMEqueG8cmoMcJe4D BfAq/60QPrnEXcAo5mRm59rzGiVzH4b0WlOFjNtgh/juaXEuwLcQ7yb2OZZQzQI2Fy86 cqsHNWg+j+Nw3NpCkZdtXp8ej11dUyQ88+u4ghNYuig+o6/unMC2j+foZMDw0qD0rzYw 5mNKhq8caWSlyNXkrPEhLgh4fDortZ/vfs5Ys6sH4gm8T/W95MCJVfL0vZ/dOO+/eysl 44Tw== 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=FaPp6XMU7/QLI/fAkjMpx5RbKj4Bgtv2vep9zbLkpHY=; b=WkOdEL8EhyV35ddwuBVaJNL1F3Cr+Jxldn6ENKBVoI2d6xuPoBzFRNbBD9+72XMtRo A8EN0HQnvfC9KjetaHGxYkPEuroLIwbDrhxTtC7Xml3MmUy5L4AY/s2gdanf3KY01IZT M+8lYWQCVrdLdIDTZ5S5rit1t8BggFarMmVimbO4MaG16kipwLoA5ACbYxenRphxIbWy H/lXX2MFqauDXvSF7GI2RMAzra4BhtB1erJ9wLq8757SVzO4l8h9yucBj249gGCv5rYr 6ChL26LR+OJ5JkrVDXtubAMyap2uAGOMTUKEW3O7WQCJfdJNDUqkT6835D3OAtWXfGd3 IjJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="ax+W/n2d"; 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 g17-20020a05620a279100b006a00ad9ef6dsi823825qkp.148.2022.05.03.13.31.36 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:31: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="ax+W/n2d"; 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]:46574 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzBH-0002fI-N3 for patch@linaro.org; Tue, 03 May 2022 16:31:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39492) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hu-M1 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pj1-x1029.google.com ([2607:f8b0:4864:20::1029]:42888) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWR-0003ce-0q for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:26 -0400 Received: by mail-pj1-x1029.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so2886841pjm.1 for ; Tue, 03 May 2022 12:49:20 -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=FaPp6XMU7/QLI/fAkjMpx5RbKj4Bgtv2vep9zbLkpHY=; b=ax+W/n2d7bqc2OJ/9rHUUHWAnnHPgCuat4gaYC3uFZz4gyIbIefpFChRPjc+cn/iq4 +NOf5OYCzPoLy13KRrUWpKQAXtme8HLuHoaDp/P6STHUltJBKwhr2RSX6zmud0VTcphk np5cQSfidafO0Zi/r7qY8XzQJXeXbdpY2u0v9fbA5idupuNonaNpyCl2stmOhysa8cT6 TdOvjBbX5IlbH8heZR2OrHv1szC/uCZvKDlhoma8Ej9HO75EDgbJziklmyTHcYlAi2YC Pga5zDcFGIxincDa/D7fIPewW9UXdPlJKrCFAJtIV647qR61Qgr8Mdy9FMcd/pwerbdx +SDA== 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=FaPp6XMU7/QLI/fAkjMpx5RbKj4Bgtv2vep9zbLkpHY=; b=7GSaNFIOqylN8Xv41tncnyongrg8KQ1+KijjS0YuVTT1k4mARsF8hIUy0h83g05kaQ P3EBhj2dFF2/K8Pwhe72nKO18nWMYZrmxRXrOnTH186lZWXprdsSEQ0kfdI8qKNONXvg QlRrHQCKrlhbJp6YwL1wsgAX1OSuyLjvLsOgBCU3HTxv/60rOQ5Rx/5Yoo6tM5wDP+pO wA0/pj2K0B9/s8CCtLoxn2kHJNcCvM+yM9JOUdYTFc7y8vFY6lMoegc63+r44S7j8J0W 3n77wlS85Hc5yjLmTx2TErtP8K8XgYsBuQABPockB1nVHebuYpN2yDIZ92wAjQpXfsYB dl3Q== X-Gm-Message-State: AOAM530mHs0T5QtzudKCpVbTamRVd8gmu9fTJOpLP9VQxSvSPMsRZF61 LmSvwhGW+kZKbb93EBpE07nHVkvrvAkGHA== X-Received: by 2002:a17:902:c2cc:b0:15b:a4e6:f58c with SMTP id c12-20020a170902c2cc00b0015ba4e6f58cmr17825157pla.149.1651607359169; Tue, 03 May 2022 12:49:19 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 34/74] gdbstub: Widen gdb_syscall_complete_cb return value Date: Tue, 3 May 2022 12:48:03 -0700 Message-Id: <20220503194843.1379101-35-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::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" Always pass a uint64_t. This resolves a FIXME in the m68k and nios2 semihosting that we've lost data. Signed-off-by: Richard Henderson --- include/exec/gdbstub.h | 3 +-- gdbstub.c | 7 ++++--- semihosting/arm-compat-semi.c | 9 ++++----- semihosting/console.c | 7 +++---- semihosting/syscalls.c | 2 +- target/m68k/m68k-semi.c | 10 +++------- target/nios2/nios2-semi.c | 8 +++----- 7 files changed, 19 insertions(+), 27 deletions(-) diff --git a/include/exec/gdbstub.h b/include/exec/gdbstub.h index 8e9cdcb1c1..63764a9766 100644 --- a/include/exec/gdbstub.h +++ b/include/exec/gdbstub.h @@ -77,8 +77,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 a3ff8702ce..5286253f8a 100644 --- a/gdbstub.c +++ b/gdbstub.c @@ -1870,11 +1870,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 a7520d6f41..3ca8b6455c 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -217,7 +217,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 @@ -234,7 +234,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) /* * 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; @@ -273,7 +272,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..3dd0ac60e2 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)", __func__, err); } } diff --git a/semihosting/syscalls.c b/semihosting/syscalls.c index 269f750d98..4c934654cd 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -145,7 +145,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 da0186f3ef..94deebf09e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,7 +93,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) || @@ -108,7 +108,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) || @@ -122,16 +122,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 May 3 19:48: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: 568976 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9784046map; Tue, 3 May 2022 13:11:58 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3P+cKKeD6YhKRP6FrlSsOet+eoIl9AIvg2BbImjPqUz+0dqY5e41OjoRkvM92iCjFm3tX X-Received: by 2002:a37:a953:0:b0:69f:9314:ba62 with SMTP id s80-20020a37a953000000b0069f9314ba62mr13348043qke.398.1651608718064; Tue, 03 May 2022 13:11:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651608718; cv=none; d=google.com; s=arc-20160816; b=M8GpXyBStOxb+g6UXXf8xeQfLeA2+8am21tUjzaEemFX9Tktw/6cFuwNdULuNlr16V 1XT8xb0cCXv9qbzQ2aNScC9G6NGfP6kfZ8RJJECpZIiZTbEaMBs5jSoMJgXpSNieJqwt +D0k8KPZtwdi9PqsLBscPdG2ZxZfLz+Fgd/hXydM2YEwYCW+e194iE5Ah9iMNSKQCvXv kKHeLDHd/IXAaG3gULuuYZ9WZs/XY6yOZSEnXIR+MQT898gl8z183/6JHkzClG6b5vhE iQYi/zsICU1hD+pzRK+ewc1pjHHqxtVDI3O1c+9+uyxynxtTWYkqNIfoJTbmVMLKRA+n 8uCg== 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=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=P4Wet2l49mr+LYb5eZv9OlmbAJ3Txu7O6ZQF8Ct8H+Reqya+Rm3aaWuksyDceIbqNH Mw9CMKw5/VUts07qBkNJbHjQhwRapUOaZqhv57ZJwFQbBBb8GPU5VheF4gijeLtb6DK7 f8qtK1giQUWHGG6EqDV03JtJEC+mtAkVAdyPxjgQ/8JBPBz62MQEWl6J4U+RqZEbPrGK aCnrCZnNChTJ0TVNw6573vmJxGfpGnlkyEpPnBdJ9ewfnSImj0QI+bpqlqExytmwhj8o IF7OJIc3/Gi3kaJDOdY3+aYhQ9G6HlC06ZYNq8WISsrn7789m7/v1OjR/aN+ttULiIQL VVLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=XqoIEfXh; 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 i11-20020a05620a27cb00b006a0094829aasi872845qkp.82.2022.05.03.13.11.58 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:11:58 -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=XqoIEfXh; 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]:35198 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlysH-0003A8-Lh for patch@linaro.org; Tue, 03 May 2022 16:11:57 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39490) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hp-Lc for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:53994) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0003cn-Op for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:27 -0400 Received: by mail-pj1-x1031.google.com with SMTP id o69so14879539pjo.3 for ; Tue, 03 May 2022 12:49:20 -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=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=XqoIEfXhd7BNceb0kMrO9zkTaldhqCjVxLq04bcUc930Z6ZsliYjlWM5p5uheI2UXG o0VmD0Y285TgVLMnHdSfL6w7pMlulkyPyvfOmmSpm6Qpwa0sDO3UfKg9bVq0caIPM7BB wvHXpYcFG6VR1YIRpX31G5FhuZD/NyLUB5AFEGUhSBGaShydujFcF01EhL4CYOHMr8nv zYtSG852v6QjDjAFEMUyxvEk46J2Q0T/+5OdOerEodalHHY6COrmYSADLtwxacfnrdjS IBwOc57uVHDxLnorIoAptMuSK3VofXVpHDHAPygVTkdInPkzYTwjJGEUMCe4zJSmaB5b aJUg== 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=xEiQkbmkP3Pvevruu+pGV3TN8GeAApZMdugII/EnImY=; b=qr8n0ORqjQIiO+BTWY+KDAx6kCll2hPhTA6ysBTbQWaMYKcB/tBPzD/VN1bfnzfmF1 q5N4iFZ+WdCdcNbwzLwsCGyxgIKzYBzQM6Yv1pNrf8JK8uFaNCQLvZGjSs4PzMwIYgzk yvHOp8ygGm2CMnBSTmVe8jh5ezv4br3N2hluKyjMlFrMLOlirbznYIcOo9CfS8uGkmz6 S33aNvBLFrc7BH8jUZEzt2asfnkZJX3tJr2d1qM8n3llcgwfcYCM+kNAdtcGbwKOUOse 0ieHM0scL9RvpDyQHrLDfmbF7mI/65IM5VBWAjr5TyfHTsUitGXy/GMk+lzDh/gbhJqB /wGQ== X-Gm-Message-State: AOAM533aZ7gqxWKeSmExHXLRifbvCwNA1LfjRqXeCectJTd77WTFjI/U yUhs+oNGa4Omgl7KkENYYLplwuyIElvhVw== X-Received: by 2002:a17:902:bc46:b0:15c:f32f:39bf with SMTP id t6-20020a170902bc4600b0015cf32f39bfmr19278504plz.32.1651607360084; Tue, 03 May 2022 12:49:20 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.19 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:19 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 35/74] semihosting: Fix docs comment for qemu_semihosting_console_inc Date: Tue, 3 May 2022 12:48:04 -0700 Message-Id: <20220503194843.1379101-36-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::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: , 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. 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 May 3 19:48: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: 568993 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9796707map; Tue, 3 May 2022 13:31:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwRAy540cfzvSvwpOqv3p+zSozkk0vryFPSSjUlK+/GkzcVPLRbfkQInyEShJCpfZvW5Igc X-Received: by 2002:a05:620a:44ca:b0:69f:9cd0:79fb with SMTP id y10-20020a05620a44ca00b0069f9cd079fbmr13350864qkp.25.1651609886443; Tue, 03 May 2022 13:31:26 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609886; cv=none; d=google.com; s=arc-20160816; b=acOo3AYHaKnNXH57bf469bsxr25NXOeVhDDTIRbuGNbfVgQKI20552UwLtttsxHD0B lX8oiduf4Z9n3sb7yFK8X4NmVtmqCaKVctHwwMHF9AS4WDmNwls7DIfaHUn/4/92Rwr8 CDT7C8k+W9URy4lHmUS5S4fRoxKNwMMTfpYzEw+VzAqxseciGw3JCoOJ+fm37Q+s8cMY pBTIWP48/Bt4rkcIDX0K/95i3s+N9gmZX3hwMcwi8MsR64gFU7Zmo1b5x2HJfPQ+kVm+ z+1haUWv8WJ30lJzfeY67cvQtckSs9eS6UO/c/ceaCXPx14QHdF4yngtikFQItK8ovh2 +Vmw== 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=OGBm2n7ExoD8rG+nhfGrAKA5WPrKK898UQl1Rl1Fe4M=; b=qOLBzmSDrZhi2o80JKcJSoarZpf5IGAvMpAjI5CVKi07u2OQpeLzDgv1eI7eMYIG5i XkVlHCIBarhhSD6jHaqEHHo90+FSjUGeti1eZyLsrBBwPqFp7id0laPGceegCHiV1NF5 DCZn5ZgZe4cj+ghnoMy2gNfoKrhFkXkZzRHe7dEL/nhfR0dy/2TZ0qVhJ0JC2AJqo0xb 7wsafp35yTcsX6ezP83CPn2j0qFAlIlsJIqMdaNaNNO+DbtFRx3QcirLsHxX0c5xUcmt Km7nYIUi5tm08Ta0K3qGuhBd0gAkuLG0MiV+sgxV0PuDpjq0UTiTa779o8si6WGya3nR O6uQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Tktp30/3"; 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 y8-20020a05620a25c800b0069c4c64290csi9501544qko.308.2022.05.03.13.31.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:31: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="Tktp30/3"; 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]:45902 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzB8-0001tO-0V for patch@linaro.org; Tue, 03 May 2022 16:31:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39494) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hv-Lx for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:36365) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWR-0003cv-Pr for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:26 -0400 Received: by mail-pf1-x430.google.com with SMTP id z16so15569197pfh.3 for ; Tue, 03 May 2022 12:49:22 -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=OGBm2n7ExoD8rG+nhfGrAKA5WPrKK898UQl1Rl1Fe4M=; b=Tktp30/3EPU1bBRlphcmNpsHS2rlR5+3jISDjJPTQfkl+fur6/LyBqjh9OHnjVxjD0 AIA8c90DIiyHHdBHmalwAWKxyLkshZwk0TMj+DrzYeBm+wd7MAN9UamD+WqKhJqHLA5e sZHZhMPipcd5DywtiI1yl/GY7t/KUxHBa/AENlqLm1e/miqR3d8UdrL75q6NV7xYYV5D WVTm/mxIc9Wt5dufXerSoX3677m/pJGY410Lb7FRBVh4irUwgW6jbSuNZhx7UT7K5T/w 8f8Af6d03euJdnBFq3x4eRaOkdTER8qXuEt6GGAXFfL8gBcT/Pkz2vB0sv68o5sJx2Fd J2Fw== 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=OGBm2n7ExoD8rG+nhfGrAKA5WPrKK898UQl1Rl1Fe4M=; b=2ZxmGDv/YF+4fCNjogh1D0ozcUV3/CoCA9UV9fSRxzsQKawlAH22nzaB8tnCdvOEkP lb/Z2Tu35A0tR8TX3VVRhZNtgXlUKlTNGJKiMPil/35yGKMfgucNLohhPKxh3M1kuyQe ejQj23ufTQ9o7Rilffr0olhWuhXOmZTmpQ2Eyudyhln6wC9D9WiiMx7tbRgYGuiglmj5 v5XJ07CKDdBCeJk7+lIQDvk3URA6d8siAeZKpOOMPz23PvKXEY+C3GoiJgZx7OhLUACk ZnZx6cy7JmRR+60wTUu7IWi5KQbkyHddN1Je6Kks+Pkp/w/SW9/PNSYJjgsTsBnDntMu F29A== X-Gm-Message-State: AOAM5315ICsgPwqk19SLdtKn0c5yHZVGnGqe4dtuyf1YfelL+1hgh7ii 4CyE2vmeOkbtvzstnVlQdtsHTfqyA8IgWw== X-Received: by 2002:a65:6149:0:b0:3a9:7e8f:6429 with SMTP id o9-20020a656149000000b003a97e8f6429mr14962164pgv.613.1651607361274; Tue, 03 May 2022 12:49:21 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.20 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:20 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 36/74] semihosting: Pass CPUState to qemu_semihosting_console_inc Date: Tue, 3 May 2022 12:48:05 -0700 Message-Id: <20220503194843.1379101-37-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::430; envelope-from=richard.henderson@linaro.org; helo=mail-pf1-x430.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. 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..afc961057c 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 + * @: 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 3ca8b6455c..c4cf33fe0e 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -418,7 +418,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 3dd0ac60e2..7b896fe43b 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 May 3 19:48: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: 568989 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9794289map; Tue, 3 May 2022 13:27:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx354KvjIiEByBPR9dxuHUuUZqDl+FahhhUuwzMrCZHlXkINHB7yvPBu6YFJFDIEWeu3ZAd X-Received: by 2002:a05:6214:19cd:b0:456:52d2:3bb7 with SMTP id j13-20020a05621419cd00b0045652d23bb7mr15155993qvc.115.1651609637317; Tue, 03 May 2022 13:27:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609637; cv=none; d=google.com; s=arc-20160816; b=sIOgPOy3pYrTiIknS9q3sGexszERbYSv3TSHq48ARM2QmhSC3DfaMjODITwYU7tF1I payiDdXeZjbrr8vzFzwdlqG1mBseGJNRMYywUu3DSt71t9fUjb7BOpMRQiawWcXM6XbL qnxXoiCdwdlPpmiSzyw8gSQmLdwuv/9zXuGkYzRuU0JQts2q0L+B/TpZT7NzAW92SsP2 EtmA1E64OgQ8x0/bickW6cjiHnIhe1FF34L8a//RypVwMmYzvocf4mIzbefBtSbogBzh HQXQDDDN5kW9wWzphAGMqDP9HTFGikOzbAxaZ0LT0DPsFVClgM79y35ciyv8y5GTOefv KgQw== 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=9xC9HPdGYz0Z+ceTMk4d0rDxEgPYsoRaTR0YGxBhWY0=; b=hCs8fzq6xHexN2iGNszZWRD6mTXQ4wP0tWsrvw+RxzBbIeQz5igUdVb8PjCjCfv4Ed uooyuaDSOh5nBcGCyOAvGeTuEYynok0HAef4Ol98jpYQeSdfBXxYJ8bMJNjskRdhbaKa WAMzQYh0UY6Q4xBY83qiNZqx+QouTJaI1QTtLvpEYsw7SavgpIpih8Q2VoN95DlRNqxF QugJ0Wj417h62k8e6Rl0O4XknxBSoXeuSC/BDYWq5FOSAxLlZPOcakuYXdeOeKwCSH7S OajtRK3iqeqBl6x4V2rDthFRpnjcvnuy0LAIIA2QUkWnBVlBabchl7cbvEFDrWQ3tG8z ZBZQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AYKCtFqb; 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 bk42-20020a05620a1a2a00b0069ff4bce510si2879762qkb.191.2022.05.03.13.27.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:27: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=AYKCtFqb; 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]:38256 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz76-0001nV-SJ for patch@linaro.org; Tue, 03 May 2022 16:27:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39498) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hx-MT for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:53997) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0003d0-VU for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:28 -0400 Received: by mail-pj1-x1034.google.com with SMTP id o69so14879610pjo.3 for ; Tue, 03 May 2022 12:49:23 -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=9xC9HPdGYz0Z+ceTMk4d0rDxEgPYsoRaTR0YGxBhWY0=; b=AYKCtFqbfUzgbf6xqzjjAhnWJ9dPDU8ZH8IpLNrlr98eS+KQsnzHYkE8MzTEJxW+TZ 52Xcxuf8eV4Vc9WriR+8A061rWRTzVoWbFBK9zQJ5MwElfrDg66yX2rBQdugMhq+koIE oRjNeH2bfi+0tLZ3QD+xvmRrfkVkvSF1BMIQ0MQd/6UDvbWxhu2vLGQZC1z5zuFJDgbL w71FqmoP3xhvvInqJrGi1UkqSDIV3CRvW3BPciNgbkIqmXf1lsIAlya+e3q6MhzUe3ru q21Mz2EDPB/SPx7o8kjz1TUnMNx7d6drGtSspq07LQw/aFbsay7QgntmFeOpzk7mT7k3 gwFw== 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=9xC9HPdGYz0Z+ceTMk4d0rDxEgPYsoRaTR0YGxBhWY0=; b=ayVKlcSemJh22n0xfUryM1389bbN7Ad3fsw5oQEhc7Wce3MITCl2G5ZhLvQSazhNZX YYGrBKVAAbyig2n7ToF+f1FX5oOpQzAzxqnPTi61QyrJ80JDUViKbG4cBDkjt/38ApfY ThRBUlK5GVuPuk3m5AvqMSU+e2/LOEx40qdkm3zGfZvVgUlUM7xiExXAAezjvOnYMJmu wrBRyRMcA7C6mIvQu0/eiDDjajhVdZTSBR8123U9G9xEkmbPjA6BH0b30YyOKSe5mfBA GzhIRics/UMxRVyDBHmqtGONrsqk+BKXvGgs+wz/dOujCgk6kttxnDXpqkQDouLm4zX5 92pA== X-Gm-Message-State: AOAM5325TSImkHyGh2Rh8f1ipqKsixI6i7apMLPQ9TQs/UE17W97oM0E YLH8PUhMs3wrNPkgUvxJ0GNJAZ4DTQqLvg== X-Received: by 2002:a17:90b:3c4e:b0:1dc:9999:44eb with SMTP id pm14-20020a17090b3c4e00b001dc999944ebmr80942pjb.179.1651607362297; Tue, 03 May 2022 12:49:22 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.21 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:21 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 37/74] semihosting: Expand qemu_semihosting_console_inc to read Date: Tue, 3 May 2022 12:48:06 -0700 Message-Id: <20220503194843.1379101-38-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::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" Allow more than one character to be read at one time. Will be used by m68k and nios2 semihosting for stdio. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 14 ++++++++------ linux-user/semihost.c | 10 ++++++---- semihosting/arm-compat-semi.c | 11 +++++++++-- semihosting/console.c | 16 ++++++++++++---- 4 files changed, 35 insertions(+), 16 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index afc961057c..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: - * @: CPUState + * 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 c4cf33fe0e..d60f7ed6a4 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -418,8 +418,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 7b896fe43b..df618a28a4 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 May 3 19:48: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: 568985 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9791644map; Tue, 3 May 2022 13:22:52 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwn12TwMtq426ug1B1I1EgqVj9HBm6cnxqAVHPMBAOC0heK+v8aa6aM4ViNsPmP0FRsCySR X-Received: by 2002:a37:62ce:0:b0:69f:b99b:ef0b with SMTP id w197-20020a3762ce000000b0069fb99bef0bmr13531532qkb.725.1651609372619; Tue, 03 May 2022 13:22:52 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609372; cv=none; d=google.com; s=arc-20160816; b=zV80aLnlhPFlZLb4SSVtBRS8Nl9GKVUi9cEF1eJIQk2pSFqUky73lobfTcDqSyIgYh akO5mSGhqj+bM63uTkD2bAE1bawXzsC838EGPa1S5i1QE1MUDoZT5ko/r8hWOpbw/zqB HB530HmW/QPaZlMPkjg+D9Xwf7kKRaQYPkvR94dGLb8Xj/PSjnnJreQ28L1pGBLEU7cC TJjAnbB41fcqwzxkJTb0n6JRKRyP5ekAQONqLpJCcfTl3yWTfD0OxkNzmqJRdpFEJhYL pfQETCU7/3tILNhJN02xj9xCTUNshvwyWADulV+E3kxg150204tf+pW2F70ZiJdkemxn cNng== 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=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=NaHfQR0n2RQ3yACWa3R17POEQPOafrrYRmzOIpwGmwPb6uw95ZPjQEwdNGLvrpGjHT eruznyCWZvmPVPe2kTcrf+g7fF07eJr58SQKVhe99KYBG5fwrymqyot+iGQOmFv0/i1p dqNAEoe/G53B2mQ//9JMhsaSbP3SdJhzf8eArlKXS1FWZX6urfEMkKk+zMzoZ6khT/R5 sg4xGYjHuXaud8PVpkbwtFqE2dX1CPiqIT4L/NI5IH9x1bxfsb8EUJPcSIcVK47fvDkT wXAFUej63uSdDnifl1WsyoIEdjI0IVVmspKOkaYF6fiW7UAmz8gN4npYxhQQ/OAdmYH3 EZdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cRIJieso; 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 u68-20020a376047000000b0069fb7937fc6si5689769qkb.476.2022.05.03.13.22.52 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:22: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=cRIJieso; 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]:59028 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz2p-0003dC-Ot for patch@linaro.org; Tue, 03 May 2022 16:22:52 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39496) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWW-0002Hw-MT for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: from mail-pf1-x433.google.com ([2607:f8b0:4864:20::433]:45898) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWS-0003d6-VL for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:27 -0400 Received: by mail-pf1-x433.google.com with SMTP id h1so15551034pfv.12 for ; Tue, 03 May 2022 12:49:24 -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=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=cRIJieso6ZCk/SZfaRT0o8vM9qNf8jMBzxUCuz33hkH6vWSIMT/CfgxUmmLYHJku/b AWLEJ98ebT5zbAMO/G944cTP0SUpWR0ii5K7rRi+egr45Qt8OX3lVWlVvkODIalzdyw6 GREjfIHSswZzMjGdbrfF00pmTSrYwXfuk3d9FTb4+MDwxhin01L3mYfZSAsooKzIyUHA K8cP1ZKCCOBIVw30kRV9fESE44sXBgT8kw21IUYKpepqYRgfiQBO4W2SVhcTRkar605i 8XMq4mmFIG8IqKpRPe3rKgnAM6wMHQpWcEmSLLUN7WHSOfMHpvNOmzXtsfVEfXnfDb3z HGaw== 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=WMI7bqILJjX6/FSY73MwMD4JpfCZEnEL2iLuRqOe/O0=; b=aeuuc9J2z6/CRNAfzvZIoyEl/paznojBQu4wEvAOnPwv2NVifdiSABCSYMFm5iujd3 LEOrZwic0rt6gDfpbfDDqFmp6ZZ/V86fLM3KJN1hCM6htMfMO0A5YPg297i6sV4eHXR9 b5Y5Wq2YiomX5xoIoxK1UNXcgVaNorq1OjLleOCTqu4lXaZeLv/iULfiGmd/Iit6GUV7 CYALqkA1qnIIQHAnYw6UgkH2r8b4dJCTNV2E1NYp7UQng7YmfkEwnDEyvTwAlUOOVBED J9233WtSrPcJGAWlQwxe24PNi+8yo5PFJKK9e3L77J4kghkPbfhCDBibaYNbRSQuSOHx dj+A== X-Gm-Message-State: AOAM533aI051HCGtSMiMxqelNuWcwuCPcG9j2MlaEbP2a7cvVN9QR6r2 0ic/BgBacs2P08FJrwGS+YOTW5mXSrW2MQ== X-Received: by 2002:a63:6682:0:b0:3c2:2f7c:cc76 with SMTP id a124-20020a636682000000b003c22f7ccc76mr8544328pgc.253.1651607363262; Tue, 03 May 2022 12:49:23 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:22 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 38/74] semihosting: Cleanup chardev init Date: Tue, 3 May 2022 12:48:07 -0700 Message-Id: <20220503194843.1379101-39-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::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" 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. 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 50d82108e6..4bca769fad 100644 --- a/semihosting/config.c +++ b/semihosting/config.c @@ -50,7 +50,6 @@ QemuOptsList qemu_semihosting_config_opts = { typedef struct SemihostingConfig { bool enabled; SemihostingTarget target; - Chardev *chardev; char **argv; int argc; const char *cmdline; /* concatenated argv */ @@ -121,11 +120,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; @@ -171,16 +165,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 df618a28a4..4088192842 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 c2919579fd..009b660588 100644 --- a/softmmu/vl.c +++ b/softmmu/vl.c @@ -2019,8 +2019,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 bool have_custom_ram_size(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 May 3 19:48: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: 568998 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9798716map; Tue, 3 May 2022 13:34:39 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxzAggcOiabWTpZSYflTJRPti/J6EwO4PSubJ7Yf3LsG2osRohRrDcKT0Yd5JFwMLZV6UQK X-Received: by 2002:a0c:8e0b:0:b0:435:1779:7b22 with SMTP id v11-20020a0c8e0b000000b0043517797b22mr15008222qvb.63.1651610079621; Tue, 03 May 2022 13:34:39 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610079; cv=none; d=google.com; s=arc-20160816; b=bDAV5exmgUW42F6YajsqqmP+7rJoNx4S0dZvHEKdInF6eUl2RFlYKz0EjA6Xlv6Jqv 1KP2kJWIMV4bN8xDNglZ8T/bSlosP2WWKFiVRtyTSdTjWMBw6Pk9dCoSMBVDxH/W7ykq G2nHcQbJsw3pM7UPFtUdWH5uEJagN1CLJ4L8LtsRzbc8Zz+an3UaFg/vzpXMcnQqqV2E kJWqHsslX7IrEgMFBmwypZri+yZOaEuU/ClrHSX73RVT4RSDoCp6eH5mlNqo2/8ZoxIp 7a6BIAoMUFbGHzZut1ag1pGXlfJSVKVjXDUhHCeQL/uQ4VD8oqag2/ffMlQxaEMqhpdN +nNw== 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=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=Dm1voH/Tt8jCYAXhzkOQ+S+yNZKBVHidOVSYOEvZNcYuW9QhSYjPqeCsRVvLHMcGQH q8zAy7Vyz6PuG3HWG/i78JeBFwS8NJtjHMU7ztXcvWvuwHIcfJKJ5kClChU+DdDxg8Me FaWHf4BYlxNWQOsw7mlWin04bD6DsfbFX9I1162SCm9Lj+7uAPIALWMxMKwc0GQlNa0/ 1yw6wA7PR/vtDwhpzJ9WaHJh9c1LEIACJghuugg0GkdrIdaejCunP3+O+v6n+hyz8kcP S9l9CGUURawLRx/39guPLvKZBCzRZ/Cm8np1GfwIhzDY7SB1JoKbf+nWO8YwJinlUhRk F0NA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="am4G/MPv"; 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 k8-20020a05622a03c800b002f37dcc3303si8291840qtx.602.2022.05.03.13.34.39 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:34:39 -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="am4G/MPv"; 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]:54194 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzEF-0000oC-6l for patch@linaro.org; Tue, 03 May 2022 16:34:39 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:39516) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyWY-0002NN-1v for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:30 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:52883) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyWU-0003dI-RY for qemu-devel@nongnu.org; Tue, 03 May 2022 15:49:29 -0400 Received: by mail-pj1-x1034.google.com with SMTP id e24so16250405pjt.2 for ; Tue, 03 May 2022 12:49:25 -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=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=am4G/MPvBfaGx4cDAOFyEwqqXcKc6dzYNglM1D6b9dwH/PFw0amtqe/c9TTT3GVXYm agB86Bf4TNjVY5iBwZOLeCIuPL+lnVlYvHx/9P0SCpwAJmxnyj9cb2CsJf0CDeUrjMop 5IMAY3mvnERzDv3zsoGuW0EDgRqatjBFRuSe4U50vY3kJ+GROMBNDEJuRB46VEKSl3+2 kM81i4N9qcN10osIl9evCD4k4Gx62UAjw2gP5JMKRz2mdKLLFDukawwrzwwrCsNNnn7a p4RDY1NdF+ElJ+AlMGw/CXwIzkNly9/dtPb3ZveqGCxng/hChGKs7EcsyG8IIplJd9rO r89A== 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=U2oK2ipOEqoaAfOulrRTtOQB2zK3TVTPXCClS/WGFgs=; b=3RZJisB/RNwCrys3dIWGVKaEptUkrImBvoAuiYBEP9XWR+7KHrmKgd1Gvt18QbDB/e c4zr4GPweR5qd0jsrt0yXcBQm7eLRUXAwAsSlnwh0CtnPoqLeslA7cQPx/2SRzxg/G6N q/U1dTGjF1HChM3pTU7YMkyiDtrgyZD3XNJKxPDBjQhw5w0dYka9OKUPiiyZwWZrovhj 0riS+njP2h4jCCfhVzYHWDdATn3A6EespH5ODxHe+whhz/PUvIRoEU+j/sG+pFTYZvu1 D1Pjwe/RbHha0Z8jWbHmkZkDQ8r+iZTIQGYBV+uj0pGGeJRYfrEC6kgH5epkv06PeV5G mh7w== X-Gm-Message-State: AOAM530mxbjE2pkTCtHKk27ZjiSnJJF0g085mt4V0wxZLFO63c1lqWbJ 1+zmNqAq9pKu5HeRKXIVxW0tkT8ZCxf/mA== X-Received: by 2002:a17:90a:8b91:b0:1be:db25:eecd with SMTP id z17-20020a17090a8b9100b001bedb25eecdmr6459833pjn.10.1651607364013; Tue, 03 May 2022 12:49:24 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id p11-20020a17090ad30b00b001cd4989fed3sm1712383pju.31.2022.05.03.12.49.23 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:49:23 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 39/74] semihosting: Create qemu_semihosting_console_write Date: Tue, 3 May 2022 12:48:08 -0700 Message-Id: <20220503194843.1379101-40-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::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" Will replace qemu_semihosting_console_{outs,outc}, but we need more plumbing first. 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 4088192842..b6a342744d 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 May 3 19:48: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: 568986 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9791793map; Tue, 3 May 2022 13:23:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzasgnBINlneXX+AncfKidABFiOZ3TbX2zsSGqE+2GGWqPUBro1Y/jl9vU10FgoBGt91yD1 X-Received: by 2002:a37:ef06:0:b0:6a0:e66:92b2 with SMTP id j6-20020a37ef06000000b006a00e6692b2mr1594271qkk.684.1651609383985; Tue, 03 May 2022 13:23:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609383; cv=none; d=google.com; s=arc-20160816; b=TsGHAGvESvIxo2YBwcBT/maS53JOY2xBAJa2nkjwZsIVRIJXst4cOsESI7rBMFt6Zd B0WzGWaGv3P1cmuYQ73MLzQ5VA7MdzEjPPMBiwwq1Lh64nvdSwSxGx7OCjFuipnVIneV jJOFrub/v23p51dmsQWSQVznEB2mRm0TBXBk9NHu4MKQAweCZ6o3z4Ec8hzzE0W+3Xyl e9mFDudNHfWRzoFhmWZSfa+7BWd4obhzCmntn7G7JFjhQ481Jg4cEn6dxiVyd+JfGQjy EnKcKNOmdwl9QbHxVhZDgtlXb2SEnO1vmikGfrnppK369BRRdujflYF6WOJTJWDb9/xE Dp/g== 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=6P93sk4kWHKA40484oabYrAFLKtkFM6g8eI+ZgtYvkQ=; b=bqBbZtutLTbOHcqOJi8SPoON0f1RnZ4Z4ZH87FzNpb4EssSrLKDLGphbIwrqdUvpTn KzHGKSFgecsmh5CL6BxCVxXuo4wBMEvJnhuBsu+HFINTHUmdX442NY61pw4pbf1Mwjno 0VValxrS+KqbIewiRItikE2Es57r1j6+Lhue3T+miv3750v9YEgKZrFWg6QakuWKMJmS oomDaiU6a4LzyubvC9ElflXv0AHNWNyhsKpZ4X1Ode/CDa98/vicgyYyMf8CGRAKa20W 3y1izsnzcORYUg04WUIe+b5KMTfnf83w6asT3MM5+JHOACfIG5J1i797XBh17aorAlbb GL0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FaVJSf4l; 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 bp16-20020a05620a459000b0069fb6de1483si6978149qkb.420.2022.05.03.13.23.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:23: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=FaVJSf4l; 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]:59608 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz31-00049K-J5 for patch@linaro.org; Tue, 03 May 2022 16:23:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40096) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZQ-0007Vr-PT for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:28 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:44603) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZO-00063S-Qd for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:28 -0400 Received: by mail-pl1-x62e.google.com with SMTP id j8so15861766pll.11 for ; Tue, 03 May 2022 12:52:26 -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=6P93sk4kWHKA40484oabYrAFLKtkFM6g8eI+ZgtYvkQ=; b=FaVJSf4lhQGEG9LjlgjqN+zXUQ/zDHW77ozJWTg/zFz3q5Q8htvfTPt0xlcF9oZIm6 SC1yIzbEQWSR85Mc2XusTXWb+eBCc1kGQ9FfEErwPpx7CxItrRuSeVCXkZPizXeju/sG W5T2DWIJZfoebroU1UC1JsMKXZdV6JbfAcs1bCHd4ZIbFrkD5AenXorRoR4mxNidZ2Tr bvuYxtD6h1rzzpUjY49LMdmG4SQuVFDQE34Q/HqjjXIiRMwtZE7nrrdsY9NKVtihoChT 6H2DFAazHicxtrEbc26UsXluUxS4/1jULlKqqQiDrE6heb+OXC2mk7LUl/QkvwseyGkq d5HA== 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=6P93sk4kWHKA40484oabYrAFLKtkFM6g8eI+ZgtYvkQ=; b=lfDOiTtEImZgo5DrK6rsnU9yop51z5CaONPHPl0fn0FcSevFn8o+BP2CibHoWebrk9 46O1pxevO8wBvPS064RyWBahwe+r3+8y5cL3IFCK0d6HPd9pB3Zvrs46TRe23JmSbovy Ykbq7KDBSJY84l5PBH54jRu5zRTlo+BRwCXmcbRXGsXfmV5rwQejnzRH5B3tcIDtNgoG vwhSAvZlnSmxqlUlcyCesNvluSoLihXuhyXwO3pRhpMvIMYzuc433rF03v/mmm7hJbcw hivz8eWzzwqLxVvLSyJFKFSLaf1IiKN6Bq0E2mG+fuScZqKl21jnpfJi7ZXStvR+0G9D dJFw== X-Gm-Message-State: AOAM530xZCrAcrpURSMf4KM0DDqiYkolSaxl27nMpGRcKJ64sgiXdHDu bCgUaVkF0HTuDfx1+PMQ4ohu+vapAVP59Q== X-Received: by 2002:a17:902:bf07:b0:158:24d9:3946 with SMTP id bi7-20020a170902bf0700b0015824d93946mr18231803plb.28.1651607545472; Tue, 03 May 2022 12:52:25 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.24 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:24 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 40/74] semihosting: Add GuestFDConsole Date: Tue, 3 May 2022 12:48:09 -0700 Message-Id: <20220503194843.1379101-41-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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. 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 5aa2722cb2..5c3e7cd538 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 4c934654cd..aa4ee47649 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 @@ -607,6 +608,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. */ @@ -638,6 +689,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: @@ -667,6 +719,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(); } @@ -702,6 +757,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, GDB_EBADF); @@ -742,6 +800,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(); } @@ -765,6 +826,9 @@ void semihost_sys_isatty(CPUState *cs, gdb_syscall_complete_cb complete, int fd) case GuestFDStatic: complete(cs, 0, GDB_ENOTTY); break; + case GuestFDConsole: + complete(cs, 1, 0); + break; default: g_assert_not_reached(); } @@ -790,6 +854,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(); } @@ -811,6 +876,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 May 3 19:48:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568999 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9800036map; Tue, 3 May 2022 13:36:55 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw78ZlY91ZaoP8DEEd1YLgXr34Y+OXWfMYGzw5nhUcHMNhspfnFe3zlAWZEAI8vplAuX54L X-Received: by 2002:ad4:458e:0:b0:456:3a36:13df with SMTP id x14-20020ad4458e000000b004563a3613dfmr14822782qvu.123.1651610215099; Tue, 03 May 2022 13:36:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610215; cv=none; d=google.com; s=arc-20160816; b=Z87N2Fg74U5bvQcG/1Spd/ZfLjWVI/nvcBHmeoX8ik0wB6UQc2RqY4WfWxGr/91CmE HE+fyPNRh9BSiTjMihrG0pjER789dlEXhf5caHDbYYKtlgzuEp4/pVXwgKNIhpt5y9t6 wSoQS8zUzafaVw2c7qQ2Hv/jo+tQ+h2XYdBaRWfxLZejTIjV1lmyjAi8OrAl7t38bzun 0G6JeX+dQfDc5jtAu1MHsdvQldImbi26dx7/U7pANI1fHmPIzr3yp94OOKNlKwLH1Wy2 GREJuvJrLvjrIN3g98IciCWX3AIdLVHRBFyycd6+i85ffJ3B1Y5Ifu7xF9072coSCrf0 VDnw== 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=Zc7fcb162n8E46W3M3k2gzkfPtgh3mAbYwEb/eTCO3o=; b=XIeLI8z72QjCNXLLU7LTGk4K5bspRJlBc44jIDZjYqJYCE8llZHqBC1IYDrRgFA1Ka Ebt71PSjP2iaHg8xlXBn+zu4rQewecTvN0qo8R9jSpfGAVFMk5A5npVRaVc7Cu5o7pdw Ezdn5Om0oV5E3IxxTUz03W/XC8UxhBTqmk1q6D+t/lvgLIskmyhnEuf0uhTs5IEZjgKT kljkZxF4oWOnnyNtHR2qzzOA4CQCbbmUB+PBU6rSfvzS4xk9TwO7IoZQVhzz38sY2lnt CKdxAFZMaMtch78SjabITj8SsgUNl1zsW1baLP7rj9eIHDERsFmXJGrbL7O2aX6A+0gl CIug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="CVZ/4Ngh"; 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 k20-20020a05622a03d400b002f360474002si8428186qtx.281.2022.05.03.13.36.54 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:36: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="CVZ/4Ngh"; 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]:56950 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzGQ-00037B-Gt for patch@linaro.org; Tue, 03 May 2022 16:36:54 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40126) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZS-0007f1-3w for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:30 -0400 Received: from mail-pl1-x636.google.com ([2607:f8b0:4864:20::636]:41528) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZQ-00065g-5D for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:29 -0400 Received: by mail-pl1-x636.google.com with SMTP id s14so15886650plk.8 for ; Tue, 03 May 2022 12:52:27 -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=Zc7fcb162n8E46W3M3k2gzkfPtgh3mAbYwEb/eTCO3o=; b=CVZ/4Ngh5/UvAosmCEZ8VjZW3s3gY+rl8DTU4ISd5YUFSlZSEuINedQPPc+udwCXRw kVg1tSl6CZ89+qWF+9776Ila84vJdaT5s9CJTKw0jfouWu9TJfMM8dVA6TbwzYGTdKcv JDGGqiuYhETSHLF9cmkckgUe9xsolR54Ye3VkhwmO9SZA71IDHxXZXHPT0ayq9+S24E1 dMv1ehkefq/jhqiyIJZWguzEUXK8EQ1TxEKDRt7Vva6Ni3rUlYfP9ONzIz2qOKKygNsc y9duzQ7al5FFcVJwM+B4LgVhrbyJzdmzyw/hLA6lbBwZsXWB6ORr3OnbKh4vbamiB+PR 3kSw== 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=Zc7fcb162n8E46W3M3k2gzkfPtgh3mAbYwEb/eTCO3o=; b=OOfnrhOARM6xjTU2jsGHpDSC16fMrcBJBa6lnNtHckV6JVwKD1Cdxfrtwi4y+6tD5N VMvoYpX9szgZpTzWZ3Iqb5eGVOdyPE1/j5Osa7i7F2B7OYRxSrio3/qHg3YoBfQEj4n6 SyIabL8If7kCk/NHdZRrsQe81i1B2Uq2tS2SzduZIM0SdpnvvkOvx65zUJsz525RsmSH P09apoGE0bptav0xAPXe/IdF/rm2S/MrXBQ1CyOpzLHOsHJnILu6RE8bHZq8+ftqGjg6 bM/4/0j8JnAXreS0I4tO1lD7/WzsBBHxXUt1u+HNMTylg07U0dJnF7rF0KzCT28x3hxM PSFw== X-Gm-Message-State: AOAM530TtsDRaFtCXoV+K6Xp01+qobKACODryrhJTqPGGaSuZ8Z/HXqs FSh4dchOPY8S8BJThrKDgMC9qCRVYdSEvQ== X-Received: by 2002:a17:902:868b:b0:156:7afb:2ce2 with SMTP id g11-20020a170902868b00b001567afb2ce2mr18070955plo.27.1651607546478; Tue, 03 May 2022 12:52:26 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.25 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 41/74] semihosting: Create qemu_semihosting_guestfd_init Date: Tue, 3 May 2022 12:48:10 -0700 Message-Id: <20220503194843.1379101-42-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::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" 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. 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 5c3e7cd538..73d8235222 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; + int alloc_guestfd(void); void dealloc_guestfd(int guestfd); GuestFD *get_guestfd(int 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 7ca48664e4..7faf390df9 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 b6a342744d..677ec2b176 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 May 3 19:48:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568990 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9794374map; Tue, 3 May 2022 13:27:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxlOPLWys6IZ67ofiiGcjvY2xMehfO62hFLAVPHs62ldpqs2rinw6kUtntMV5adXu3khU7h X-Received: by 2002:a05:622a:1195:b0:2f3:adaa:4b80 with SMTP id m21-20020a05622a119500b002f3adaa4b80mr4998720qtk.194.1651609643240; Tue, 03 May 2022 13:27:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609643; cv=none; d=google.com; s=arc-20160816; b=X+8BvNuS913i7WYClPF3JBOWHWn+o20CG+w2+R6xyA95pYelBTYKrZHPLALNjAo08Z 0ZB+klUVm57s0e7j+XGZBouFn3ckGXFaP6+eDB1sit9fFPmn2ccAbXXLKmjJWaHQkAfG /VJw2DQxkXCoanm9mt9+rdmOwL53tvM+cLVLYX0ru4XkIHM1qxx4/2ruMFVqmrTdheVF p0bHJoNHYjsBl1L8uHn2xpiXjNepQ1TQiz6YvrdOLU6ZOISX+ga5J8/x8wM2GwTwZoaR zgRf6RBxzhmPXWjAlkk9oJeLIhOP/nLtB7zKJVlye45zGir2rjPc3ukJegWm+8spi6gC 185w== 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=imisZyWOU+HOiAHcCce7P36gJQd/+JzsQTknZrdoLJI=; b=Vk4/d3CH+K2zYcXgTKFYFZmrceTqWPXjKKDaFtTnNXUeEhX2PCLBJ2TNRHqKVEZShc jdFs49uIii7WC9vf9jIrZcEVg3gvgHd1XB+1gbHANOSeNKmglO1NxJbToqonZvYhSxyl Z+kNnF5S/EojtxvY3tiKCrkqkP4zHF0re641YKBZqVzaCE5MhDkYjU/mJ0a7UPcEHRXw d6Kmg1mFQc8iHVXi8i6NBNY00dEB78brk5k2VevbAVz/HInq36lX3t2eLPWhHIVeQOa5 o9ufDkMU2cSiHCZ3bwLL7fLAUf+zuV714afv4/l+IMxH1oZNqYWy5q7+lw18bSlfhu0M 5SJg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eAi0YPW0; 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 n12-20020ac85a0c000000b002f36efe240csi3207158qta.237.2022.05.03.13.27.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:27: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=eAi0YPW0; 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]:38782 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlz7C-0002LB-Po for patch@linaro.org; Tue, 03 May 2022 16:27:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40132) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZS-0007i5-F5 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:31 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:41745) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZQ-00067g-RR for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:30 -0400 Received: by mail-pg1-x536.google.com with SMTP id t13so14802932pgn.8 for ; Tue, 03 May 2022 12:52:28 -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=imisZyWOU+HOiAHcCce7P36gJQd/+JzsQTknZrdoLJI=; b=eAi0YPW01H5a0onB+LHOge9T2anERQQxVGLvF+6xcK9X3Vno8tfitnCe63mixRDxiB bq6mvX9THRspYp2MDfwAnlKiAQ75hD86P274d7+EzBLsBsKkGsBOe3SnJLuZ1q2uTuXq n/v5a1SuyKayplF0ozD+IQRc8q63SYaigcUf8djkplkD8n8248XBSSl+mudUbIGKNHbs 7AG08Ie/4XKdCpULyPVJU2+HfpvTV4R2mPlJx+7unjtrGRpkleS+RloU/NBFreCrS3o5 OUlGmS53NOjlmc8BjSJ2wvClYOUoXqjV5Jzm6ktQU15kigCI7IqonWrPEdqqI0cimXf+ DCOA== 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=imisZyWOU+HOiAHcCce7P36gJQd/+JzsQTknZrdoLJI=; b=BdZD3hLRdizjS51j4iv7IvizYvdBujuQ0Yoaspu+/FOzg0uWXD9lvOUtftO16/hjEV wKcjZj0vtkk7EFCpUnJXpp9oWeo6jjTMxR4D3Pcc87N+7ux3nIQ0d3dNi8zkdG2DwtxQ 1bR8+4BWTpAGyv9CIqI7iS1qFqXWhzOlZpI0Oxln/iLbYG5rKJWQhqMXmJDNFIwW8vLj S70WzAA/elH0C5QzFJEA3qAF4khJFolAADgtvF0qAjJKIGnr2UGlC5kEbdW8/2tyo0Kl PzHj5swNeeXzxVOGZBjTpX3JuPqaXxQt3a90pzeC4l8Ze5cuvDsZkiIDakoTsVQGq5VR 14vA== X-Gm-Message-State: AOAM532rZN52L6aaM6H62SNAiDzrkAhbyCe8HFrE2J/FtJ0YSHjK9r6W OXJ+0CEp+nzVhAwLgLlMRIZpSaYsXiOr3g== X-Received: by 2002:a63:2b05:0:b0:3c2:3ed1:5fa9 with SMTP id r5-20020a632b05000000b003c23ed15fa9mr7681135pgr.220.1651607547367; Tue, 03 May 2022 12:52:27 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:26 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 42/74] semihosting: Use console_in_gf for SYS_READC Date: Tue, 3 May 2022 12:48:11 -0700 Message-Id: <20220503194843.1379101-43-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::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" 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 d60f7ed6a4..34d635006d 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -293,6 +293,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 @@ -418,15 +434,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 May 3 19:48: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: 569000 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9800281map; Tue, 3 May 2022 13:37:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxVs7bOjmM6F8t48wrCV3i2JMmU1RaEwvh84OOIWsiRrS9sMd3qcIMLyZSe516rvWUQ4zeN X-Received: by 2002:a05:6214:764:b0:45a:98a0:ddb0 with SMTP id f4-20020a056214076400b0045a98a0ddb0mr6491147qvz.15.1651610243116; Tue, 03 May 2022 13:37:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610243; cv=none; d=google.com; s=arc-20160816; b=x062iU1ljLE0n7KbGoRhP5eSDqquHUxd+MVZD5WtY0NtGK0wqh6uPi5rNPlrVgvVGe 2qgDxj94SxCDRf89AiNLnDnSZCjSumU2INHutkCRDsBd5De+kDt26xPsd28JymH4PRxC ceLL16Mps2Otu2u0WWCcw0PW0mul3yNHWJslVvorTSO7yt+K7ahhnmdcGlWLCRkCQ5IN weNuZmVzCAhmgYqfKoRNENFklunAFYtxq8Xru+c4zObCgN/Kvv98T8J326ruOXlCnVAP AFYSCVbbSO+n9oiAgDr46kOJX5TY0y+Q4iXAi//SlPoOoUK2R0HIpx/SKrWg9ZuJ+OAx FBzg== 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=OuPQ5G9+kppu3GspUe2XHyinl3n08DHsjMhXklSdxDY=; b=e4Ne9r1N0I9n8R3+RUocBFfb9CJ5Q+35ASpqb7jjmKGO587mRaNbCFnm/YyNggFHxp k3MFxNGXq4MpcS4eJG5pKqPHlkFrFwi/qJiQBxvsjHTaZJ15AXAyqB9rVzcZNKYy92R3 5xThQ0onMGFg3jIe3Yle5s9BjOdUFLP8NlK7d1e2mg7Xnwu6WhqiUdr7PvJ8z+2RjOWP SXvVSun0ph/WhVsMLidUuz+tPw+/QoCITlJSoN7QpAlgsbjqj7Eu+5NGRwznj/EnoZtB 6gPpsji7a8drtkyaUgq7EkXgMy9kvdbgjbQmpmnwgvKa/OgeTAlXD4aMedocjDraY9QP /IEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=CafpJ52O; 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 u12-20020a05622a010c00b002f36f148266si2726148qtw.72.2022.05.03.13.37.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:37: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=CafpJ52O; 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]:58140 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzGs-0003xn-J1 for patch@linaro.org; Tue, 03 May 2022 16:37:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40150) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZT-0007jb-CH for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:32 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:55202) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZR-0006DT-Mh for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:31 -0400 Received: by mail-pj1-x102d.google.com with SMTP id fv2so16244353pjb.4 for ; Tue, 03 May 2022 12:52:29 -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=OuPQ5G9+kppu3GspUe2XHyinl3n08DHsjMhXklSdxDY=; b=CafpJ52OJRi616BOkfEVqfnuOE/xZg6qkgWPVJSRereVqMVVZC1khsJITQ4/SB3xMK o3kqWUCgnIKTKLjwkaFiCp4t/MKECW6zlM/kc5T3A7/SW1cdaXa1eiHvGeMJ2Y1iNMX1 fZD4fRSGlZ0Lqdc58WXMSFgEK0d0vpmUIgKP1mzsgsZdzB5M8YA8R+RT7IrQ2BMCEM/b I5w8g62LKrQQskFB/XmbiQx/vC9TxznBCGV3F4s1vydqzNu3vT8iQWaGaUBqIrNgZw14 mpTTOmctOSqkutB/SZReLbXjfx4VmJacZKZHJuab+tM3ijppNn1tnvVhrJWBtlm3uK6s +mbQ== 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=OuPQ5G9+kppu3GspUe2XHyinl3n08DHsjMhXklSdxDY=; b=c1K3oLybqxUAo6ar2rwvlPbG4Nw2LtO8rGY+N0TBltDvPfQ1YNLEPw+ou5axIIA6hw VAGBXSBcwKpcChPKI/eqdbxv+/JnMen6jUP/HrP6xkE6yq6+oGBNIN5vyJXE0x/5nFJj 5uLm2JM6E+nYe6IUsGlDWiYNB3eSvBMgXRBGNeoQG8QPqKtNdHUPo5aHPQx4actLNzJf qbLUhxDfbQExJEvLB47N1C+jyNvHz7gTTXq+FtJt7XfQNFtsxoqvjq7g6VNzDggI3JTK eJyTlrFUIKqUz0eL5j/PLdQ2uTShxNnVpCcgIh32/jO9ShIuHNzQFxms/EYmDVgIpyGt IoaQ== X-Gm-Message-State: AOAM530XydXv0ds30FGlZ6YnB4Ju6tPZwpbzBBsXxT5pdAEgpE/GFt0v 7HZqltT7lhgueEAt8oMckqBlCrSHx+S1pw== X-Received: by 2002:a17:902:da90:b0:15e:bcf0:cf25 with SMTP id j16-20020a170902da9000b0015ebcf0cf25mr2914727plx.40.1651607548358; Tue, 03 May 2022 12:52:28 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.27 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:27 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 43/74] semihosting: Use console_out_gf for SYS_WRITEC Date: Tue, 3 May 2022 12:48:12 -0700 Message-Id: <20220503194843.1379101-44-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::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" 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 34d635006d..430cb4167b 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -230,6 +230,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. @@ -332,8 +341,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) { @@ -410,8 +418,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 May 3 19:48:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569003 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9801897map; Tue, 3 May 2022 13:40:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyiqA2ihWVanbpWkP4Yk98jq2HxsmN1EuVmIkhMC7EAtS8N+y7xHOOX0v0JLTkIx6U/o0tG X-Received: by 2002:a05:622a:c4:b0:2f3:a257:b60 with SMTP id p4-20020a05622a00c400b002f3a2570b60mr11678444qtw.291.1651610401600; Tue, 03 May 2022 13:40:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610401; cv=none; d=google.com; s=arc-20160816; b=lUH5vTBD0XCMLVNzP++Z/0l/eEFhtPtNYNcM4wPQmUo6x44fclZ+y+igmpzPeqk4fA isYgwVUj1zt49AI/8kdXbdzh7su+g+dYAlz8ieOhYsgg6IiR05tS5a7Spo4RvpUkHGrO kw3AlXHExLJqc4ICI8NuosoC8BnYNzGQtVi/l0pv1AXMK+lf8VhF4YdYiRpu6HkfyTEG RQgIi2wGSdFOWSWpolv7ddcOoEj6aUa1hZQhKtXo9qAVJ7xy4itnOrn5no67vio+r25r PP19LRxdRIxr/3tFDC7aZ8bkNrmVWn9sjopH+bGuPrsborvi89bLMospktAP2cKpQqcU y2Mg== 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=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=yO60wt93l47ixVwP1YMfsUabz8/LeHteLcHVnCa4Y172Fl1xR2hjFQFRUxySVG8Vh8 fWm+LfKW9sVBlRpJ2xs/1RozEpV1TZpLlfk+xr+ScxsuuTPucnQ1q6eWP/gwArsHipo0 XPgx/izoaJwymvCyjZ8wkWisR7kXLkjpZ4ppA/h8ChRNCvqAz8kfnvP7SS3gtKljNygy 3T64Bdb0DzDy78OHE/GsDSWMDOPvZ+zGaPw2walaQn5FtMJmA8OxgwnfYDLLibqMGfY1 7DlMvlNe077/qwYKvJRBTM+Aahu5MYwD7lP5++6NyzSkKKOmDaFuZ2/huQluw3Vbv97p wlvw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jrHav2i+; 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 v5-20020a05622a014500b002f368aa943dsi8448968qtw.66.2022.05.03.13.40.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:40: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=jrHav2i+; 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]:37894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzJR-0002hD-4o for patch@linaro.org; Tue, 03 May 2022 16:40:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40160) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZU-0007kf-5A for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:32 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:33363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZS-0006Gc-I9 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:31 -0400 Received: by mail-pj1-x1034.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so2552004pjb.0 for ; Tue, 03 May 2022 12:52:30 -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=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=jrHav2i+5I/qLGY9K9HW1GUG1B0v0tqQaw1sxwF8+hAXzl/nlrWcIhOBNH+MhU01jj ybi0bBD4d39hxFNlMrwfj7I2Jce4BDonJqnCvr+kLxPQXhSNoc7N6gTJmXXp9lvPKXqY 8A4X4Bzb8H6YFbH7gW8Xs82lEStXTeMOf4iTHs8nzmKZMsVmSDBudvNQu1nkr629NEMc iTL3WlJhoet6C+naIpnRPyzaJFoiJrJUqUCBxi1xFnrHsx1juSjFEZJHgOqwMonELOB7 rnp9rASI/j35SJed8jEf1Z0jov2938eOKB1WZ1S+b6hBEd7OIYXVQlxN4EkfF3gGXJJr Z1gQ== 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=3j65Vrb+cTtoRUM0a2SN2E+0qaLnPvILTBqh1dXrOWQ=; b=nGlkYv7wLrVjoyQsLv2QQR2iri1ZrQWh9nW/+8p8NynNNAfACJw7JajPCpVlpNd+y0 l53vA7qx8lmeZ0eIE1jkbw8D+0tl607nitr8oOYzSXOOCXigFwztlUvu6DkFNnhlwfQr dNhPxmMzwoAKE9JG7hkLirY7ckbfuCPSRlsGJsC6X1mYEeW8V9QcCS8IUviGf6UktPaC +Yz2VxZOazbiYN/E1YuTixViMjW6rECVtBuKhS8elouKDY4c/usDcjVs1z2DXvOQUbG9 LAzA5ktVKMm2sK2NHvGRFhhKedKTeAf6za73WfWZzo65QUklqG48p67SFCdkrkF3UvLd OhjA== X-Gm-Message-State: AOAM530mt9Ty35BtCUFCAVGRA/NQKyM40UY8LFVQ1oX8O6UktTRENnab WeJh81EZNdZtsKr/BtX1YPtptWRzYlRh9A== X-Received: by 2002:a17:902:8304:b0:155:d594:5c04 with SMTP id bd4-20020a170902830400b00155d5945c04mr17582533plb.105.1651607549270; Tue, 03 May 2022 12:52:29 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.28 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:28 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 44/74] semihosting: Remove qemu_semihosting_console_outc Date: Tue, 3 May 2022 12:48:13 -0700 Message-Id: <20220503194843.1379101-45-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::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" This function has been replaced by *_write. 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 677ec2b176..f6fab5933a 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 May 3 19:48:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569007 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9804354map; Tue, 3 May 2022 13:44:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyB103jXcXFvc8gf8ZHErfFldrXDH7UXvUC3tk9ArwTMpF4okIXSNz8Bj9qhopbaI4iSrLK X-Received: by 2002:a05:620a:2941:b0:69e:a525:8379 with SMTP id n1-20020a05620a294100b0069ea5258379mr13968337qkp.124.1651610662630; Tue, 03 May 2022 13:44:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610662; cv=none; d=google.com; s=arc-20160816; b=ODq3vWL1UD+Zdch8Qjc7wEX6KMTPnd7/oKP4Z38uhghHwvhB+6/oBIjZ+cepb/H4qm dNXYnauLltkJLV8cjOUHX3My5MVuRDqfLAWDrNfpsYBliwX41QhxTismMTr8wiF4ocwd mLKRh6h5GMlyIoyn3tybbwJoDEuQxYWgkzNG6SYjwkG07EmxrMyxMCtcwrT33X3CoyhG lEDpfmgfcLbfdyMjReF/U6gXSOyJyHlKoMwYtbkdP6m+mWoxmSSo5VstcjhkM/tQBWKT +n9lm9jVZdw1cgObUMb8emJt5cvEy9oTlhvwiWjYKAqpi9KZFNxIZiEIgKpG/nVaxL5n y6xQ== 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=WUEAwRDb5qP1q/+HL6ZwAjNwTCoe4kc7v8P7IB3q304=; b=EPIKpw6BKLwk0wl7Zh7KOv8ipDDCiAXd3z2v+fvAq9/yX3JfiX8u1FtbhMd9vH/avV JoYXAJl1BGgYyWKTgmfydByNlbijfZEiwbbzi/rcdV9gTFKVRqjVzwAm3hkWSjbhjMsR O3Mo12f2GJfOwvxZi7yixfYLu8x32F9g4/v3643Vv58lrQrBfCFh5F99W3SqPk4YieKX +XLDfCWu8ukbOcHJ58pgeREy97s2qxbvjZw4+2u3/5h7+XSTQU1wnTzIQPKnt8wTZdzK BAPwmKN7faRdRg5Kvf5ohSfdX/f/3AhdunSGGgaALGSwjZD61IrdJoTzhr1KNeHqXrY4 U+HQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=m8wAy9Wc; 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 x9-20020a05620a258900b0067e4be23a1fsi9598932qko.612.2022.05.03.13.44.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:44: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=m8wAy9Wc; 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]:45976 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzNe-0001mc-74 for patch@linaro.org; Tue, 03 May 2022 16:44:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40180) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZV-0007mt-Ac for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:33 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:55205) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZT-0006Gw-O4 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:33 -0400 Received: by mail-pj1-x1030.google.com with SMTP id fv2so16244417pjb.4 for ; Tue, 03 May 2022 12:52:31 -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=WUEAwRDb5qP1q/+HL6ZwAjNwTCoe4kc7v8P7IB3q304=; b=m8wAy9WckIp3wIFAFtgEOxPx2juQE7YbPgyd8WcRtnFEemxKCNbo9DVw7nBvcmMtrx 9m4KGAh2gAFenR0HagczRcCuVPoxMa9uDu2WJ/RjxR0ATzTHz74LC2nfxdgV5TXVrzaI vNMj7tSp88uJwwJsAzYl/93VHXKRWElntX5YVUHo5N8K3628u0RQ1pqgARMaGit8yZSu kUH2xecQc5vgLLcHhIx1qQCdwFAqDRmVkCMC/MBlFEisZXEJcGtb4FA9y4VwsVWnJpUD 8PV8OW5PJz78WdL6GoMijO20/QU3O4wk3uqSYKZLmXO94tfLidmPDlCdZfPypRSPyIH1 qMYA== 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=WUEAwRDb5qP1q/+HL6ZwAjNwTCoe4kc7v8P7IB3q304=; b=IUBbU0mhYimupL0m0r+G3A+FYyOH4XSGOfX2sAeZpMozIdIHkUuTI/verXh2c9PKIr ZJZIZAFx2Qf1wAAy0zI2MauiyDsnT8w82bJiwFOgIJHEKL9azBflDaONNO2oTkiR5fy3 spN0SRkOBatpZiuaKhdKlUMsvwH9TY1kL+WX6KpcxEKdUyEDSEW404jbxwYjRC/488zV vkSpf4R3DFWcbbv2NKQUfGHJX4SF8SVmRqn3wDw7RrdAF8+OyY+5hjb2Xz2VFxiG++7n cR1SzAWp+08hVEbPaxLMrq8f2AuO1Jm24GAgf4IrNdnxNIqGs5LWyfpbLGDMD8+l/rlQ h81Q== X-Gm-Message-State: AOAM530iFWseTGOIC4oEFqZ6WArQHyD28+P3e985LdNvXOn6SJ3xnXct fMS6b2kXvSJ9IsuGFoi7INpURsjGJ+NFEA== X-Received: by 2002:a17:90a:af98:b0:1d4:67d4:d122 with SMTP id w24-20020a17090aaf9800b001d467d4d122mr6495288pjq.166.1651607550370; Tue, 03 May 2022 12:52:30 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.29 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:29 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 45/74] semihosting: Use console_out_gf for SYS_WRITE0 Date: Tue, 3 May 2022 12:48:14 -0700 Message-Id: <20220503194843.1379101-46-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::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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" 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 430cb4167b..3f8e1b70d1 100644 --- a/semihosting/arm-compat-semi.c +++ b/semihosting/arm-compat-semi.c @@ -427,8 +427,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 May 3 19:48: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: 569006 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9804179map; Tue, 3 May 2022 13:44:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy3e8TaeUJN+Bl5uqQnDfe+VmMfmWphmvIPkgEeHEE7qD+GUuBkbUnxZOQPjfAETwurXhO8 X-Received: by 2002:a05:622a:34d:b0:2f3:44d9:41a8 with SMTP id r13-20020a05622a034d00b002f344d941a8mr16573403qtw.217.1651610643889; Tue, 03 May 2022 13:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610643; cv=none; d=google.com; s=arc-20160816; b=SgmPYrteyexdHUcPfhCw69t8hEJV3OfrXu8RD6TwpAXpV0qyFsQWJw8Dxxg7ZXcq29 r89NyY69v1KqS+ACE/cY0KQ99UVUILNzWFMfXUPprNaWB3wX4z7HQRim75M5EKFSueVS 7YxQq3BzeeHB7JMRy+XxdrlCzQ+mmw34elS7AZKUDIRkcWOk3jI5pfE9Qy33pjSWNEx8 LG/R039XFJmgxYh2ausaoE7YGDxo34HOWVEZF7Q2BaPA/WlVVO5bBZoKUyS6aGH8D2Fs V1QKQF67tST0EzY5hk380IpTvA0xKRF6dlIt+ADfzcp7g9tAt/Us5HV3oZ6uq+C2tghy AvUw== 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=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=VNMmPpq6HfKrTItqYbrZJIQUywHtWuQnXAtH5ALAK1OqXMXzspHms1+pWOpBrt2AH0 7Rfqhy8gmHZJr0xaxWSmaq8V94pyfoVEAQHP6JY66buWNl89upI0zp36vhipevhn7rjs VWBJN1kKPztR0nlxAq4nJUy37C4G0CuiSfEXmh3zDo73EpaWhmvsA63MEUF7g1IyDSrL xVqj5l7L092e4wc52SiGMfUm3JQG9+eLHnme/cx7lyEe28kvqDqlAYCBNdsMq6CpZ/9N brycIIl+IqVGxOpbjDz1ilnYJ4dU0G/nYOgDOhRCsHjeMJyexloqi/kW4D9y74dkpwsS GBKQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=vfWQt7ph; 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 o7-20020ac85a47000000b002f1fa1c23c2si8354842qta.155.2022.05.03.13.44.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:44: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=vfWQt7ph; 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]:44788 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzNL-0000ce-6t for patch@linaro.org; Tue, 03 May 2022 16:44:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40192) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZW-0007qU-6B for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:34 -0400 Received: from mail-pg1-x52b.google.com ([2607:f8b0:4864:20::52b]:35343) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZU-0006H5-Il for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:33 -0400 Received: by mail-pg1-x52b.google.com with SMTP id a191so2224580pge.2 for ; Tue, 03 May 2022 12:52:32 -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=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=vfWQt7phsrg4z/+cQTmB5XoHiL5pR35cSpU+J98bjl3RE4q2+KtUDcXKn92CMHIh/I X+dgh7H/9Jq5LSlw+l51+phSUwvx1dEKr135ZJuYCdfhz+zDWtZRJlxX108n6g97RIgh G6mo8taPkUVgfo/50Kum+G1y3hsrkdjCRhY/WyBpYQwL0H6na4/3LjHFibaBSCWbFdFM j7g65DTrbN3tYvU3vOzVGpJsoawefCkG8dtJnB/ThOIYrakzBh6i8vtqNExSa6bZboyH ms9gOzcI5DOrbIdSGo1EAJtogbXJIsGQv4ZNSdocr9L742X5zA8ncxjNIEJbmdYF/gE8 5mkw== 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=G8jUXILSyQ3ZGWS4huZP/MGa3C/uuyreOxdJ2Jh/tu0=; b=cuyrUH5UUNmXpQpoLxFiAwy7xw6ct5xIcmkS68LZtk6Stwj353sFyZ7LM7661QWvDq p6hLhGniClvmEMJgM7AaR7tGRLddXjPLcD6ZHGfHM99MUrgSqWTTaFgJYQfj8qtFQbDf n074dsYF+jx8ajfvhxw0ua2A2u0DS5W3YwIz7MPNmXp8uCGDFi6KaG+vmuxrilHjnRwC S8dhfNCt4IYlb5igANkf7ybLcMXDQ8h2wyIqn+D2E83pnYRNObMurAlmP+42LWopr9V9 F0Vxtxtia/LDDkm2zKoDyH0s2RLqD+xQvqzWgg3S1LMXUR3gljo7ivaRGgexZozihNWp J1Ug== X-Gm-Message-State: AOAM533MYOVwZO6qR2zPDFbVEMCQVltKQ5k+7yx90RV0s1AZUQ5T++Yf gDHICQrxvq8PxyIMgYn0/DJ0I2WPENXnLw== X-Received: by 2002:a63:f1e:0:b0:3c1:d54f:fc47 with SMTP id e30-20020a630f1e000000b003c1d54ffc47mr13777583pgl.51.1651607551231; Tue, 03 May 2022 12:52:31 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.30 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:30 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 46/74] semihosting: Remove qemu_semihosting_console_outs Date: Tue, 3 May 2022 12:48:15 -0700 Message-Id: <20220503194843.1379101-47-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::52b; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52b.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. 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 f6fab5933a..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)", __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 May 3 19:48:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569011 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9807070map; Tue, 3 May 2022 13:49:04 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyhbv8j84NWOMdFGuemZ26V+tiydzEQC9Y8+Pkhe0gFGqaUPcqLxkEkjFnNIbDVlm6WK2uE X-Received: by 2002:ac8:7f8a:0:b0:2f3:a31e:810 with SMTP id z10-20020ac87f8a000000b002f3a31e0810mr11740784qtj.95.1651610944020; Tue, 03 May 2022 13:49:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610944; cv=none; d=google.com; s=arc-20160816; b=kzSqLIs7BeLCjjg/5OGvw+J6U+P+lR4+vTNVetPvEg+CzmFyLiusiA2SqK05raiqql srQdeprclKJIrQEYDoRMFZJIQR3oIjoTBQGK1GxpaYmxGA6nZIoY6EWQrGzF80I0e15r ayeC7ooufkwC6UZgnjZCXI38bLVTZr4fWqAaW3ONmrZTOA5QkjQL2jo98z5b8SBvesbx ynE5n0YP6Yrk4rGxOQr7hIHh5QqCwT9G1r9Taa7YnlpbAKmAP0cHSx8SRx/9lVYAqt/Z 9gu31QvjHRpzYN6L5bOTVlwjhZMYMhhbExhNGcGa64Hl75fDCxa1Cnsx1MdTIeJoRY9H mhqA== 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=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=ZIm0+uliwLrUbhTjGQ9Bmy1b7lbzYaFJAhLRFilYpXNw3PIo11CNcoiH1IZcJjSNd0 YPzppnR5bISUmUHMMMu3xJqFX1P2yjSZYhXOMdXk7yj5ljTJ9HH3H/D0wkcKJXs+w6uj Oa3MrrBxR6zXhNxxJ2qGATZh78/EqBODLSBKkvtETTnrkqyix/27l/wRDhsKN01p9Pc5 Fo55mLshCR7cun+ssDEN4v7b0/BgefiI8eczXD66BjXpzpTo6VZ0EKlX+lwEz2dCEslx suo51xvpKABgENrVprTDD6GskI5odsg/T4NlQT3e2WcamRSumd+L5W6vZNjYEBg4Y/E2 EDjw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=njdA2acR; 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 w4-20020a05622a134400b002f3a773f630si2962036qtk.787.2022.05.03.13.49.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:49:04 -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=njdA2acR; 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]:53886 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzSB-0000DR-IG for patch@linaro.org; Tue, 03 May 2022 16:49:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40210) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZX-0007vh-7z for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:35 -0400 Received: from mail-pg1-x532.google.com ([2607:f8b0:4864:20::532]:45861) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZV-0006JU-Gb for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:34 -0400 Received: by mail-pg1-x532.google.com with SMTP id 7so10919889pga.12 for ; Tue, 03 May 2022 12:52:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=njdA2acRTXfq0e3zkWlru9Um0Vlxkk66C2P9Ew0iF6WhWmOhyew0yKSSwgqokkinsN f87EUw4aEmADhyvCVjysRwx/BEh32Q5d0zKsHhGW2A96JtoqfYFvVGDJ+ZV/x/O2B3Uu PI2LXIDv/fZB9FoEhgCAEHgxA3XAhWUoqbvR7Db2mRj1Zhg1YHSZMeO+f3xAhxep2+0E rX2MmWFg9+XGh2H07SNWxNkFH+0eogzr7t/0SbmRiWovvEsHekCfCO/nu7Kwj5cLjndp wJNYzqxCYlbfoS6c5GOZAeimI43RoW+/T9UjY0k8dTh7mHy416C9AR//pjo4sd5n7T99 nTxA== 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=yIETyNF8e+iDYubG7UAr54h79EzcA695Ph0Ym5jO9Uo=; b=X99kyDHJyZN0ZbPUKcQHpgPyvp2vs9qEmOIvgB0hM0ryOEuCkLxtf0wUV6lRKB3GTp 7dhjL/wO/216e+s9994OkMAcQLE7xUSe0ncLasXmy10vC/uGi+fOu5wohRt9yyIjPK7D +J2Qq8aFoghAluiUAaU0oRjzxMSVQfFW1YcP+txxHVyiaUcg09L01bYrISTB8vH150dK 2FVVdhRAG4lpNmsMppPBS8F72hCA3IiIuj3ZctJJawc0a1j1vuI+DM3biFzHlDn8o3b9 DOmuOdrfOCqiklrUwuYu1HZOOvCgZuDYP65PKYQJRYLNwBCdyOZaYt0/6Yg+IIFK1uWv YBdQ== X-Gm-Message-State: AOAM532IcsHf0il89cArG2ao49KQ6tPwu60NrBOw15HT8aroF2P6PEJY 9t4ZTPw6NqiyI7rMfAjrlelnKPZFHZPQIw== X-Received: by 2002:a62:6c6:0:b0:505:6713:d584 with SMTP id 189-20020a6206c6000000b005056713d584mr17655927pfg.24.1651607552198; Tue, 03 May 2022 12:52:32 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.31 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:31 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 47/74] semihosting: Create semihost_sys_poll_one Date: Tue, 3 May 2022 12:48:16 -0700 Message-Id: <20220503194843.1379101-48-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::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" 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. 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 aa4ee47649..1b87c37437 100644 --- a/semihosting/syscalls.c +++ b/semihosting/syscalls.c @@ -550,6 +550,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. */ @@ -658,6 +673,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. */ @@ -936,3 +979,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 May 3 19:48:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569002 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9801643map; Tue, 3 May 2022 13:39:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdo/GoET5ruFNUvEJMhN00QuPKEQ7ArTuxvbiSkkn6GAatrba2qHr46eJ/bcI4W8CrrUuw X-Received: by 2002:a05:622a:d5:b0:2f3:a3a5:ca7a with SMTP id p21-20020a05622a00d500b002f3a3a5ca7amr10973731qtw.560.1651610377460; Tue, 03 May 2022 13:39:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610377; cv=none; d=google.com; s=arc-20160816; b=U291vHNWWIE5mPlIhpy2Jvbb5Y2R+XTDgCHOtVmJmo0i/L+cR37RaQoKjyfWw2mAC5 2vCs4QXhMU3rfPbb8F96HTmCT94bfi8zLjqOCPjwLAhJu2MXAAFqqozNbwnVPqOk95G2 bZ955lF6if1ICP2C9+2XQqJiR+gejiFlUUa2fjuf9RS6NAqy2ZL9J0ikRBfJIOO01vQt tvL7/5KKCigKLNet7FVWHepxcRepSuexA9N0BoprtmseCfiJPP3e4bwRHgAs81M1/r8A lUekafz+ME3x72fl6LByoAWc9U1hiZyQOCtpoUD0kosidoSQ/43Z0fhGDFoUAquVWZO8 gf3w== 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=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=rgpRF8u+MPuDkrW3UYm+gG7+YtwGNjwiBxJLtcWGx/DCT36O7FyutUHCcz6x28hUm4 E1kw8efIH3fM5iZbLbHQ+kybs5VH19l24eurtdPQvJbwMazu5Hyu46GTjZIiCZATI509 czGt6gvKCylZ1ApnGMfT5GJJ+Vb49FyrnEj0JXQdY6vkE9p3PbPASIc868f/6iL6gBK5 vMcRrEUMcAq7Oc3tcfWxzTY6wlDwKW7P8jHG1f2Lynr7gPtMY3pbehA///43prYx2qNL sZpcdrWuazR4HoKnK1L7p/EPIREFFFzjjCpwfFpg7ITn7mwwjLGxZmHAPDeVb5TFsgSB XJoQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=F1Sb3G8F; 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 g22-20020a05620a40d600b0069fc9d0a292si5242827qko.569.2022.05.03.13.39.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:39:37 -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=F1Sb3G8F; 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]:36760 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzJ3-0001hd-0T for patch@linaro.org; Tue, 03 May 2022 16:39:37 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40226) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZY-00082r-A8 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:36 -0400 Received: from mail-pj1-x102e.google.com ([2607:f8b0:4864:20::102e]:51894) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZW-0006Ji-Du for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:36 -0400 Received: by mail-pj1-x102e.google.com with SMTP id p6so16255722pjm.1 for ; Tue, 03 May 2022 12:52:34 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=F1Sb3G8Fjs8G3ejJ3CdntYiRLb6RIai5QloswbaxCxNVeEo/iCYnHVclSOjU2eBm/n cTHzD7k0rxrHggiBmmgCyFr4Uo0T1npYb2VFBG4dxOCXIaM66AItDycYT6lGw0WB8i8K v0H7m8OaUw9rrWu9ZXVFPsGSSYpFTAAvnj0rs5cukwfMJtZEL4uJvZDSeA08dtIKqFRD IUqHgW7gigODgarEY8LADShS0BYf00pFLQWrdbahPUJra2abshjA4Spuu6EyWUAu/iOF ty+wyKwnZrqdHYZzMjlaRE+mHzUcqmCIT2iJHmflQyfC+myCRkT7JMx1LavUtZ0I2NJ6 wb4w== 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=wppbnjnSPA38ZbueUEu4qjUCfA8mLgkrGrV5gfq7DgQ=; b=xXTd+nDjp3BHG64JOrvraqTBxTX/4wDcsZ9WvG+XQYZwTknIwS0mtzOGbqJpJ17IoK Sh7cTqD3ScMxPXYrJ2cFNTPSErIoAxdosO2yMy/5LVzI7+QRptazFIV7jzwsI14rVpbn EjAqzwbz3WYhIATvWzCGwTZZHUABtpy5pF3tXDnRSnU2uJxPwhbMvf+vsy7Dk7nVHce1 chx2fVAGmUtWJQrl3PNd48IwkF7LYSPAj7j6Vivq4huTwR5b13n9ZYTFW5wgNnCoGn/O hDG4JZM40XbozekWpDCnHPuuU5vLsSs+KWYNTTVrUZD3WHeed9U3a/3LsKEOejIOpUoc 4JHQ== X-Gm-Message-State: AOAM530VNs3xjOmV+Ud+6PvljidykOrd3OuytQvVmI8F2i5DFipzSrME IwHmlIf27kaJcd3OiI4vOeV77lxYYWvpSQ== X-Received: by 2002:a17:90b:33ca:b0:1d4:d5ab:40b0 with SMTP id lk10-20020a17090b33ca00b001d4d5ab40b0mr6571089pjb.96.1651607553199; Tue, 03 May 2022 12:52:33 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.32 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:32 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 48/74] target/m68k: Eliminate m68k_semi_is_fseek Date: Tue, 3 May 2022 12:48:17 -0700 Message-Id: <20220503194843.1379101-49-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::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" Reorg m68k_semi_return_* to gdb_syscall_complete_cb. Use the 32-bit version normally, and the 64-bit version for HOSTED_LSEEK. 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 94deebf09e..5b4c51957e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -93,8 +93,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)) { @@ -108,8 +111,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) || @@ -120,21 +126,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. @@ -149,6 +140,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; @@ -167,7 +159,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 { @@ -188,7 +180,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); @@ -204,7 +196,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 { @@ -224,7 +216,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 { @@ -247,12 +239,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; } @@ -262,7 +253,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 { @@ -282,7 +273,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 { @@ -301,7 +292,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 { @@ -323,7 +314,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 { @@ -338,7 +329,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 { @@ -359,7 +350,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); @@ -369,7 +360,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 { @@ -427,5 +418,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 May 3 19:48:18 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568994 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9796756map; Tue, 3 May 2022 13:31:31 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy8+u3RyUf0Vl9TWOLESG5pvV5o8iXDUCqAXjfcgco1Vmol03cY7U7uNvMFwYd1EiZ2VMXK X-Received: by 2002:a05:622a:2cb:b0:2f3:646b:54b6 with SMTP id a11-20020a05622a02cb00b002f3646b54b6mr16508792qtx.380.1651609891514; Tue, 03 May 2022 13:31:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651609891; cv=none; d=google.com; s=arc-20160816; b=AS4CrKCC5zWg9KYckWTs+JmDgwFdZzsvdO23k/hHHF6KemzhfsUjh19gY86eSTHv3e SZWJrvdsB+rFRdlcdMBTqOT9V9ETSuoLueCsm+wAvdi93tcBeP7sgbY7PXSrBf7iB1Tz fGRTGb0OkcVw+77obtjoHNkHZNnP1nP51qTWqcG8FFXsRPEdQpvuJG62jAObjelffN+E TMGGISeBJRBsmsc6aHIkW1BDNNXkULPBTTGa6Mu1sLU1TJp0s19MaCent2Oq93kBvZee iZrD2+JA5grmK12cf/TPtzdt8r+dIsJBejFNsQqSOS5huOrj4kclBGzqB3mJkHn9KcF3 tj9w== 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=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=0Hp4+W/8WWtCnm7v/jny/SUxi+KyL9dX9q3/YzxPCqCUE4E+tJFJSn7u23bS41+nXa 3MIv9Qi6mcLWZGdp5zdMHIzFtPzs+Et6gHLgrfEQIPU/Oq/tqg3gtG64n/v/fejx2p6r DULE7MXYr/VtrovFxx6VEpPQVsByrKaKz3JZQMre3xNlY7X+0mQ6qeB6LoFrtrl91ly7 PSgzmGnWuwnbIfJx8duKEpknt/iA4VTzy7nkEpLmcvHptiGS2Mikqk21WdiD2uilRQbz RF5Xj1WhWP4PYrq43VpZ8wqwoiRwTMCKEUpxrifP49PCb+h4G/DPh6uWRjwpkJ8KXKHU hu+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kP2ub37s; 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 l8-20020a37f508000000b0067e4be23928si7767908qkk.365.2022.05.03.13.31.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:31:31 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=kP2ub37s; 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]:46298 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzBD-0002PI-3t for patch@linaro.org; Tue, 03 May 2022 16:31:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40242) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZZ-00088A-7J for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:37 -0400 Received: from mail-pf1-x42d.google.com ([2607:f8b0:4864:20::42d]:39629) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZX-0006Ju-G9 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:36 -0400 Received: by mail-pf1-x42d.google.com with SMTP id v11so6100304pff.6 for ; Tue, 03 May 2022 12:52:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=kP2ub37soMbISTYZmNSoTeOIKjTqgsc6T6QH6Mi4kduOyp06oeMxlIbnoDCuW9is7M kMQWX+n1m5bBv5Nr8esseJZWFb40+CMcBhfs4mrRw88sjH5sDtDB2wzPbvyFeuv4IRlI QvMjg7kahaVd6oT0OCMRNg6pOxpapb2LvzZ6IaBkPV7k3H1ePG1+2KZnf0Oz4A7q+m6R 47UhyQXwRkg728RmMqfYpOuLDYPIooQV40cCVFW1aM3bIMpB4a2USNHkrxMaT0hxUvuD hzs2RBjTl02XxjsymnJkUMD57JkN/BLdmtFrizPg0Xq08e5pG7HwN141Pj9HhLmDVJe5 fccw== 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=V7t75AdkHW0PfbXkAsxv9MftHWj0Q+Sv53bh3Cjx9bU=; b=kyCgjhd6tWraIGcZUxDO/HgSBW9JGrjOrAcxFzmZglUg3/Ir+enzeIC4yYYUJTeHhi E2BWNy75/oFEKDJRefzumPZoD1MStOp2Z5t8br8QAVdTF7EbFjoGcSKHKOI2SmCvzLHf EyGMzw+HkgffCiw3Mozqvg67G8/n5XA5HFs5xpRPlw1owqOx2vmh4275Dgxy5DtSaaws +ooRIPXZeKr+3vdACZq/KtHoxqHr/v7ukpBU9OlMSr9OFYtlc/v3Ql46k6mO3u5PQLhC +rxruWi7LUG20KwIQFS49eAdxANa/KuALLtrhnz60B44ecM+SH7abE4HC5cTq/BCiJG1 tvnQ== X-Gm-Message-State: AOAM531unzUZ7RFA+dq/TlXS6GUFG6zE0ceu54yj0ZMAvG7fWGqXIFqT TuY4cchAJbxbTLNRG/JTrkhlQzdurowoaQ== X-Received: by 2002:a05:6a00:24cc:b0:50d:58bf:5104 with SMTP id d12-20020a056a0024cc00b0050d58bf5104mr17686124pfv.36.1651607554017; Tue, 03 May 2022 12:52:34 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:33 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 49/74] target/m68k: Make semihosting system only Date: Tue, 3 May 2022 12:48:18 -0700 Message-Id: <20220503194843.1379101-50-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::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" 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. Signed-off-by: Richard Henderson --- linux-user/m68k/cpu_loop.c | 5 ----- target/m68k/m68k-semi.c | 37 +------------------------------------ target/m68k/meson.build | 6 ++++-- 3 files changed, 5 insertions(+), 43 deletions(-) diff --git a/linux-user/m68k/cpu_loop.c b/linux-user/m68k/cpu_loop.c index d1bf8548b7..fa6aa112cb 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 5b4c51957e..4b5621a101 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,13 +21,9 @@ #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/guestfd.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" -#endif #include "qemu/log.h" #define HOSTED_EXIT 0 @@ -375,43 +371,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 May 3 19:48:19 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569010 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9806711map; Tue, 3 May 2022 13:48:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwdlScHG/KZgW4xzGrn79Jqv6prfjBMC/QWmLqtXDMYw0OKBg0jDmKERJ+jiHC+CnnI8BZw X-Received: by 2002:a05:620a:4041:b0:69f:c577:be73 with SMTP id i1-20020a05620a404100b0069fc577be73mr11558073qko.530.1651610907386; Tue, 03 May 2022 13:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610907; cv=none; d=google.com; s=arc-20160816; b=i9qNFDIzPmdO/EiWEZggRTQyZYOMrPTuvh8XRuoskBMlQ4SGL3CO3gsFAB/e0WT4Dt eP/y+LBTg3ZxZyqZftU8cse7F+fuUqmA0ae4wrZNbGWF9f6JC0UovriJ1X6q1e4+9kFd R4PAP0oW4JtXym7Mmnj90lQvddK1vyYy9apLTuklnuQHxlfOJBE646HA1Mqgfef2HZH5 mwQi5AmLq1yvpqhlucJ/ENGC9nvO8IN/cg5E/If5H4UMpIW8w/M8gTk615IXW25wYPD3 xDLSqfCT9yjA3skA8a1eF8JSJhq2oOtfd56W65PyqswIv1xFHmBPblDw3RW/G3nUTLIl 4XAw== 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=xbtQNW8iXZae/AjVjCxvg2NljuQAygSZg+TBTFVvaBA=; b=LP2E/oWfdf+viqusB6f4ECaFLU9MAag8HC7TVl2q31N3mS1eVzAX/3XDsd4bJFQJru nuDi9+H6LFH0XqWfQIrh4WFakI7P2dIM3mXJMUZNx5Imk2fh93FZXVGFUeRVLW03cZ7q XO2hSD6stWHzg9kaDdxRsffFYwfUphLblyWtIDeuljmmwNW3I85GIhMDdc5aJ2Qg9BZ+ 6yzNSQiX1ICBp09oR22wovWEloUoa6DNsJcpPJrNyI+XumYj2+w0LsQMAW5zMC1fw4m1 +2oAs5YAmnK60U0a5EsccnB8gqKbDThW3Peky3KddtL34QFI5gqt2MVlPqNt+YMCwQaf FRcg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YXmWJFCa; 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 bk10-20020a05621406ea00b0045643c7cf01si7978692qvb.118.2022.05.03.13.48.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13: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=YXmWJFCa; 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]:52654 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzRa-0007iT-Uc for patch@linaro.org; Tue, 03 May 2022 16:48:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40316) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZe-0008EE-6O for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:42 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:36596) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZY-0006K7-SS for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:38 -0400 Received: by mail-pl1-x635.google.com with SMTP id j14so416741plx.3 for ; Tue, 03 May 2022 12:52:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=xbtQNW8iXZae/AjVjCxvg2NljuQAygSZg+TBTFVvaBA=; b=YXmWJFCaV34UUzF6BZ/J8pVp6DdqBDjAF0ciw4c4v3KSfomdSxtCfIQ9EmfJ5eM/rA XGnvVz3nPT3Js6FTKjJCI0ZBNZWTdRBHwx1XxhZW76bFEMZvHpWJRhdFgyZtBpI8t2o8 xOl09bNvZHdjwA6So70o506N12oNqYBw5jJzUWQGD+fpP13qOcg3SPiJ5hW2IwRyFESs 4IOTil2QhWBBtACw4FOBPlvq0ynZktI9ml/ftEc/GCj8mT5jLXMrI+05Kg9KA696ewYY x7GFBOHX7Bn/wlPNv++dugfkeaVqYcl1fKAHdw2KzcHz7N7rCLjSbJngmsBUllmOWMm0 hGJQ== 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=xbtQNW8iXZae/AjVjCxvg2NljuQAygSZg+TBTFVvaBA=; b=m9BfsxuyivnWhJ319CQJSYlyMhKBNE+0U7UMfWTdh7xkWT8gdBegcF1I0+/aKELi86 wOvAreDBQr5ZARaHUf37BJF/1TmXQtioxNHE21tFQ6RPgWsbAixTMiuoburPHLL9IuQn O1Z/dFXq3yHzi2wcRzkEadwUp5Lz9IqsB5nJLTLKufk+zMOSPtQg1D2GLQYcmEHFebzv feNaKzI4LoNdsdF69t9wHgoalSGub/YFk4IzUV4me9YAfPWMz/Efsu9kedbpWVkz4mcX gdj6gFOc6IYnTnTZmVEOrdPVN9uh/GpoEPlJLF7s/HYRw6wqQjO0kDuXZ5+nXrIO6pyE Djpw== X-Gm-Message-State: AOAM533xV650GSTbxjL96V4nSdDRJ72L75u8r9nLA7V63N+jaUVpo07W cyV5lm8mCN/b81C27pDqzd3n6JYafyyeXQ== X-Received: by 2002:a17:90b:33ca:b0:1d7:d322:9aa2 with SMTP id lk10-20020a17090b33ca00b001d7d3229aa2mr6371019pjb.21.1651607555389; Tue, 03 May 2022 12:52:35 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.34 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:34 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 50/74] target/m68k: Use semihosting/syscalls.h Date: Tue, 3 May 2022 12:48:19 -0700 Message-Id: <20220503194843.1379101-51-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::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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 separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/m68k/m68k-semi.c | 270 ++++++---------------------------------- 1 file changed, 39 insertions(+), 231 deletions(-) diff --git a/target/m68k/m68k-semi.c b/target/m68k/m68k-semi.c index 4b5621a101..d6b3b3226e 100644 --- a/target/m68k/m68k-semi.c +++ b/target/m68k/m68k-semi.c @@ -21,7 +21,7 @@ #include "cpu.h" #include "exec/gdbstub.h" -#include "semihosting/guestfd.h" +#include "semihosting/syscalls.h" #include "semihosting/softmmu-uaccess.h" #include "hw/boards.h" #include "qemu/log.h" @@ -41,54 +41,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) - hf = O_WRONLY; - else if (flags & GDB_O_RDWR) - hf = O_RDWR; - else - hf = O_RDONLY; - - if (flags & GDB_O_APPEND) hf |= O_APPEND; - if (flags & GDB_O_CREAT) hf |= O_CREAT; - if (flags & GDB_O_TRUNC) hf |= O_TRUNC; - if (flags & GDB_O_EXCL) hf |= O_EXCL; - - return hf; -} - -static void translate_stat(CPUM68KState *env, target_ulong addr, struct stat *s) -{ - struct gdb_stat *p; - - if (!(p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0))) - /* 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); - 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)); -} - static void m68k_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { M68kCPU *cpu = M68K_CPU(cs); @@ -128,8 +80,6 @@ static void m68k_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) @@ -139,237 +89,93 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) CPUState *cs = env_cpu(env); uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; args = env->dregs[1]; switch (nr) { case HOSTED_EXIT: gdb_exit(env->dregs[0]); exit(env->dregs[0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, m68k_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u64_cb, "fseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - m68k_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + GET_ARG(3); + semihost_sys_lseek(cs, m68k_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - /* FIXME - check error code? */ - result = -1; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, m68k_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0) { - translate_stat(env, arg2, &s); - } - } + semihost_sys_stat(cs, m68k_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0) { - translate_stat(env, arg1, &s); - } - } + semihost_sys_fstat(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "gettimeofday,%x,%x", - arg0, arg1); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = 0; - 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, arg0, sizeof(struct gdb_timeval)); - } - } + semihost_sys_gettimeofday(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, m68k_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(m68k_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - /* FIXME - check error code? */ - result = -1; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, m68k_semi_u32_cb, arg0, arg1); break; + case HOSTED_INIT_SIM: /* * FIXME: This is wrong for boards where RAM does not start at @@ -378,10 +184,12 @@ void do_m68k_semihosting(CPUM68KState *env, int nr) env->dregs[1] = current_machine->ram_size; env->aregs[7] = current_machine->ram_size; return; + default: cpu_abort(env_cpu(env), "Unsupported semihosting syscall %d\n", nr); - result = 0; + + failed: + m68k_semi_u32_cb(cs, -1, EFAULT); + break; } -failed: - m68k_semi_u32_cb(cs, result, errno); } From patchwork Tue May 3 19:48:20 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569014 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9809068map; Tue, 3 May 2022 13:52:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy4vhTWo7IJnYUon8LfdMoWy1lypeN9tFaN4wHkNnzFLGwtJshzx6+XpLhsxqdVsBooEdyU X-Received: by 2002:a05:6214:f0c:b0:45a:b0d5:536c with SMTP id gw12-20020a0562140f0c00b0045ab0d5536cmr314410qvb.57.1651611147338; Tue, 03 May 2022 13:52:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611147; cv=none; d=google.com; s=arc-20160816; b=QfZ6wEwU/E5f+dTdx9BRzieDfGuFRnMyb8tqKMdecWq7SILcgNyjp8xrMXNoTM/Qa4 Ev02B+jBOiimPA61dmP5WBkzEVM98eXgVqjilFKjS4YVkBp287vFg72SRl2QxtZN6BKi xOOJAWhj43TBCEoTYdTfx/9xyyYThzOHFoQzKeeUbPoYtuptnpIeAGj3JQer7IclwRwJ M/nhFGPSL+sj66zwrvWVFF2XDcx5pEjcfwd9VSFSOeko23f5oUyzU9qGtP7UQ7L7aSYP aZaAfSj5l1EJ5aQmAE91gHP+0yR3Srgrouc9WCF0DT2asFVkAAovt0UkO/LkUIPEwyd7 fUEw== 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=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=iCOCRSRwvsqoQ42zdfz3gqPPwAWRs4h/U/Ca5QDsCnV9AD/IMYSwmJvKO0miYFM7aB YAPq1MnPveTFQ83EL2VTy+TsdOz8BPxFeEJ1Rqf/xUsHnp5A3nHkuAvecKSZBHr/ks2V nXxNKAGeWRTZgOk1WczEIFO6H3/xNMmPa/6yB5UqBNKYMwHOtnSkC0a0CsoKB1YQwp1a xZ0bY//79da8SE+2412dzvAjwbzVtZFFk4/Dm8kRrgQ1M7ioGwf2dJn4K1mKOSnRzN+D UcU0whZic7pSkgxEzJWmvBRSKAcQeESENKqKmetTq+zYm4kRSCaDSs0C83H3fuuPxe3w GbzQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="NHm0POJ/"; 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 u18-20020a05620a455200b0069fb6e0e2efsi6677747qkp.44.2022.05.03.13.52.27 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:52: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="NHm0POJ/"; 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]:60496 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzVS-0005OJ-UY for patch@linaro.org; Tue, 03 May 2022 16:52:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40320) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZe-0008ER-7P for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:42 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:40953) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZZ-0006KI-Kv for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:39 -0400 Received: by mail-pl1-x635.google.com with SMTP id i1so9744723plg.7 for ; Tue, 03 May 2022 12:52:37 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=NHm0POJ/k5W8exETv800htWvSW0v6gYAFe6sxaU8Ln4BFA5++e6otKo6btl09NvduM wQEEYidd7YvmM7kK8Sjq4qNR1tHVRM9ZcMLvPq0dE+VkpylS7OvL0mGmtUs3XSTlOsbU 615WCwQscqQFqpha2yoWCQGJNhpdQZPkPQDUd6z2V/oR+xan11SHiD/LvnLNDK/MVMqj q+UGaDS4ehrNfJZGktmJGvzGDs4c0cudL4hi7K0GKT5MpmxlFQ1e75OVf/0u0pavXi8c hh6A3OJML6oX2VTtEF001YI/W8Qt5ovCTZH1F3YPWshex+0FGG2ZBWPMxfMHhEfLxABt XozA== 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=G5TUXq2IL4pMyRpoJ6zLWtNUYnfueO0F38AbAA6OUSY=; b=KCMCH3hsU3N60/LD9do7VRVxz8H9+pT4uxydj22B2qM8cD9WKSzsCyhe09ASYlsY8X qVk036Csz7FlMlsbzMKThqH112rzExk6pXY9zFRJ4AP6qNKWVz8wNJxmKfPq0IRZ486M BiiUy90AMqG9ORa82UDHJDuiAO0yzX6w547jwkRCeeKq+ouq9aqJWyOKKDNylKPGtqTk vPucYKYhnLVlCkt1rFkLU2FlgFLdUCXs9Dtx+yK4nOtAF7GZ/78DM7NZNaXlg/loW2BE MX8ye47FYNeO0gJ4NmKetSzJ8fBkAaoE3jfDuR8NYngr7wjn7jtg7fo8yGVZyVKn75rS esnA== X-Gm-Message-State: AOAM532eCq+i1gI++PN2IZ1gDEpbGSLfiC1LXypX3wmk2zCeu/1AuR6r 3kv0csH6JWzhJN+nwvodBkgVwffUDPFq/g== X-Received: by 2002:a17:90b:30c4:b0:1d8:3395:a158 with SMTP id hi4-20020a17090b30c400b001d83395a158mr6368039pjb.184.1651607556312; Tue, 03 May 2022 12:52:36 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.35 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:35 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 51/74] target/nios2: Eliminate nios2_semi_is_lseek Date: Tue, 3 May 2022 12:48:20 -0700 Message-Id: <20220503194843.1379101-52-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::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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. 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 May 3 19:48:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 568997 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9798688map; Tue, 3 May 2022 13:34:37 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzpTlCOjwl14UbyaFVlXr2rS1QV6Kf8fxRRp/SNto3GGDbpBCF7fbQyRHGlZSZhtT8Avfci X-Received: by 2002:ac8:7dcf:0:b0:2f3:83ba:4d7 with SMTP id c15-20020ac87dcf000000b002f383ba04d7mr16516920qte.151.1651610077122; Tue, 03 May 2022 13:34:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610077; cv=none; d=google.com; s=arc-20160816; b=fBuyzN60aIDOuSciFxrpr6/7i3gmDx1Hs95H4s81kEaRA4X7+CV19zrjogcis7XQBB LQ27laD2w/3UqhHMDqPOpfoL2njO+TI0UrGsPWTK1rvv0Ajbu6Dre6QwWsEQK0TdNp22 diG+Y8k37e205RaCpLT6aj6AYiJy4Qluc1fGWmxBQLGis4Hf4QwhkWoVxEGL9zw8QS6C tBpkI0bompqwifEutcQ1/ih/SMib+c4JyjSIv2YIfjtrGi3t93fzF2FtrA5jq/f9VoQb PLwA+jzHwqdqxLhLBVArCYe7lqbnCoCjueL83JSq9FCBD/nnLrAENZnNU/+ABECB8Bkd TvlA== 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=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=flfUjXa0nF55vRLp/bDbGe4ShFKvXjuSAP881rK/PkhDiMSj7Kh1RMqbOncG01OmIB LDrg2wV4g+Ma0Jh6FB5G9nwHwiGfRVGpKxKVPnn/GF2Hv7pP2KozMAokbYNANldawU8T z9Eh9S7BXIE0+l4SVDQvvKYtv4te/GRmbJrbxsYOfsKvy9byMuxEUcwaZ3KLoLbrjX3y gZjuV9RqyB2n5QyJTwC5K4oOPpIG/kbhCDZvKsAb+bpyakoxI1o6O0zlsEXpZdKNHloS zQdhQGc4DlW4LzSakf2T0z+ARO4nye1ZgcrZjwQWAu2ydEOrFBZGa6HIzRXhnqpxXDS0 GaQA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="iW/I7U/j"; 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 c21-20020a05622a025500b002f202a74212si9375967qtx.87.2022.05.03.13.34.37 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:34:37 -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="iW/I7U/j"; 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]:53894 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzEC-0000Yj-N4 for patch@linaro.org; Tue, 03 May 2022 16:34:36 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40318) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZe-0008EP-70 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:42 -0400 Received: from mail-pj1-x1030.google.com ([2607:f8b0:4864:20::1030]:51896) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZa-0006Ki-HO for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:39 -0400 Received: by mail-pj1-x1030.google.com with SMTP id p6so16255853pjm.1 for ; Tue, 03 May 2022 12:52:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=iW/I7U/jJBGN+A7kqCu0eR45y1rKsOL0eTfM0o2LgEPK8tfwtmVii8PXatWVbG/Iea ZVDhqb5MS9MlpLEgRZYBh1PUO2LajHqf7rUXYPH06s69rv2US2V/yxjL3XB6nxKhGiWw KKHWJScza/FIRmI23FXS2Z6QJO+RcDt/ujqEhShYfa+wa3WNPbAfASE5EJmreH7WcXYd KC+EoEeuA0ybjGNRl36gKozOTtqhOTRd27Ys4eY/NReqr2+mLdxedoWnEbNX/soisx14 GT0F0YUviZV6++2gfM9f3LKHJmoc8rAjw+mdjgEjH90optyj/lFm5H39gOe2ykXO+NNy zBow== 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=u2pM0xy41z8bwTr6w8WctOV/RUlItotfYG7rgV7aiRQ=; b=DyZZa13bzhPV2/twqtT5a06k9S3D9hb6o6LVMp2nFdzJncyAg5ixriwiFRe9uyun0f NNmdKkidhqp+DnyUjPZEe4UGGq78zipDBIi8X7sxRNrlaD+Wf6hkP70v2YfzD1JE2R3l zBliB7HURkfn9WMhxQvgL4oTQM6eAsL6xJ4hEuDqC3v0a8fdIODRybXjJ/X3HQx96YTH RaZpxXY1LDE9hBCavWckkc4OghVr8/tKzuz9oDZy7PDcORzZ7ym1yxiz1Yq7gGDPQWva jlVK7kUcqn2nNvFQjusEDFD9Hftljq1MgP/7ixZZX4bXFHU5n8QA0jBHUVYFD9qYbQmt sldw== X-Gm-Message-State: AOAM530dZ7C1oxy7JKKs/LitGH8T/jHIELQccDi2YEfPmbjktUQEMy38 R8bM23iOGwxWREF4x7L3aKnGYcfXt5XRBw== X-Received: by 2002:a17:902:d2ce:b0:15e:c024:6635 with SMTP id n14-20020a170902d2ce00b0015ec0246635mr1920634plc.28.1651607557188; Tue, 03 May 2022 12:52:37 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:36 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 52/74] target/nios2: Move nios2-semi.c to nios2_softmmu_ss Date: Tue, 3 May 2022 12:48:21 -0700 Message-Id: <20220503194843.1379101-53-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::1030; envelope-from=richard.henderson@linaro.org; helo=mail-pj1-x1030.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. Signed-off-by: Richard Henderson --- target/nios2/meson.build | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) 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} From patchwork Tue May 3 19:48: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: 569001 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9800934map; Tue, 3 May 2022 13:38:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw5GZOI3vrypSzqjUEFtx3XkHB4iHKBDBMjjsHbUBgDpSSV6VLYIz7F9ti7ogtZzVwwAzi2 X-Received: by 2002:a05:6214:29c5:b0:456:462b:5263 with SMTP id gh5-20020a05621429c500b00456462b5263mr15039466qvb.37.1651610312921; Tue, 03 May 2022 13:38:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610312; cv=none; d=google.com; s=arc-20160816; b=pl/BMKL4ZMTzfV7m4HfGPfW5kkVUTmipdCuytgrQ2T7jwgauhxA7Ga/zflEB8bcwAA hQzwJnETFEp20bjQot8mEScfXXZtfTgNdLqSaRuNQYRafjdxhnO/2J1lsn0wjtSCgs3Q 4ai7ZdR8QIMLuQ7IwC1UAorY5uHsHvIoQVogqWNCyknumIrEHQ0KSJFbrYYnGY32nmKp Uty8iGHmxcCSwEGvmRFX7I3Hekud+ZJ+emAmVEmvnTq/SXxWNifUQwb1lrKjdAq4HL2z 1rG0MCWIwjPsDUb64m55TdbF2M11g1WQe14Nu/45t2RaaG6QMmmvYvOA///v62pwXZ4s MJBw== 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=s6WKnfYdYMcw1Zz1TWclm7cmlzkoYCvdkNaKkdbdgBg=; b=ar91d3jXbKODmZOjEUgMA9BvYGVWjVV8V5K3cjmoDB7xoDT3j6lsQ470EPqn1Mh54w Es+TvBa3TGFE2GX2NDrzFJgeOIvnpa9hpKBlqYzWiRjUFVG9gViXgmRzVxiZWhdOw7Fo 4MqtlzHFgv65FLwq+Y6VBUfeOSIwghSvw5YKhwYRBUZPQzRLDbQ/64iv+cWODb336ojU 6+w6ajqgZYnE76tOlBAcH3iNlmcKjcX4km1WcrTnuz+vm0v0xmyAccGDn1iU5ZsbYnjx SXoIhrBISiukpwv+MVTwks5YmfxnFiAu8r4Stfj8ImSEmYZ0ayEljKssLgczJn9RxC+A nbIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IXzdISf+; 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 i17-20020ae9ee11000000b0069f82b7ecf3si7703155qkg.639.2022.05.03.13.38.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:38:32 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IXzdISf+; 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]:33584 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzI0-00078W-EX for patch@linaro.org; Tue, 03 May 2022 16:38:32 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40374) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZg-0008Qu-2T for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:44 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:37751) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZd-0006Ky-UE for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:43 -0400 Received: by mail-pj1-x1031.google.com with SMTP id t11-20020a17090ad50b00b001d95bf21996so3235104pju.2 for ; Tue, 03 May 2022 12:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=s6WKnfYdYMcw1Zz1TWclm7cmlzkoYCvdkNaKkdbdgBg=; b=IXzdISf+yY2V5SbUoQVcX3gF3KS0oyiT2dDlrjkvzb+zgpU/vepipgc+7ACUiJc8Vg GTudgo8Nb/Z7+C1oP3zNQm8J/N8aaQ0Cz8uYq5oKbC/wMDwUiH4kaMhVtZIsqHmCv0oo yCadmF34mzzzNGgW/DSa9pVvot9molxGBf/viSFf0ezYRdLxA3pEqHEG6moDAe7ejcxY oKP0FtmfTf4lFP7rrRy1r4kqv1GuBbKpGEzcv0a9iF7IGwaSzn9O/AC0bLPUPwfnWkXc Avjw3uD5NGlXR8x6JgxILFF+ncHu/GauaxChiWIbSUCSQNccej4pi6Y5q7x+GXDahTf3 NlBQ== 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=s6WKnfYdYMcw1Zz1TWclm7cmlzkoYCvdkNaKkdbdgBg=; b=H1KVwewzNFGaZxZIhmeB0CXnAELubdUyw64bEToWbyFIxZxxRezmFx03DnQDlPcwtr sUInTaLrZ3/y++8FcEs+NYMegIngrER2OYMPFEiPGqfBp7nwh9xGybAkGNHiefHCe1Mz huE2+9/ZvuCB9WEjbJTR9VRJMC32gl77CpogOf6FCwlPAEsP4jj/J9jgMXcp3Q9wYP5a 6acmkdyZyCZvJ8Lax+wPCuduFWqz7Jdug17lZZ0vNKM1vzwkvvGZu7RI0ODLrcoTx+Qy rXNc7XYSo49a4wW8w6Mm2l6CVgLnVT7VVjtYxkFhuZq6Dp8I22vvHL8uRVtUSfCuaAtq GLLQ== X-Gm-Message-State: AOAM533plgxZ4oLN4YeHXKrfDOaKZoJSnAth+PmxWh+j9Pgjafbu/gzF YJ72O30kNHvPemRBzL5xWxK4yWuEZyRrVQ== X-Received: by 2002:a17:90a:5215:b0:1ca:79cf:f3dd with SMTP id v21-20020a17090a521500b001ca79cff3ddmr6677536pjh.6.1651607558208; Tue, 03 May 2022 12:52:38 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.37 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:37 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 53/74] target/nios2: Use semihosting/syscalls.h Date: Tue, 3 May 2022 12:48:22 -0700 Message-Id: <20220503194843.1379101-54-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::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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" This separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/nios2/nios2-semi.c | 287 ++++++-------------------------------- 1 file changed, 41 insertions(+), 246 deletions(-) diff --git a/target/nios2/nios2-semi.c b/target/nios2/nios2-semi.c index bdf8849689..1b5afc9333 100644 --- a/target/nios2/nios2-semi.c +++ b/target/nios2/nios2-semi.c @@ -25,6 +25,7 @@ #include "cpu.h" #include "exec/gdbstub.h" +#include "semihosting/syscalls.h" #if defined(CONFIG_USER_ONLY) #include "qemu.h" #else @@ -47,67 +48,6 @@ #define HOSTED_ISATTY 12 #define HOSTED_SYSTEM 13 -static int translate_openflags(int flags) -{ - int hf; - - if (flags & GDB_O_WRONLY) { - hf = O_WRONLY; - } else if (flags & GDB_O_RDWR) { - hf = O_RDWR; - } else { - hf = O_RDONLY; - } - - if (flags & GDB_O_APPEND) { - hf |= O_APPEND; - } - if (flags & GDB_O_CREAT) { - hf |= O_CREAT; - } - if (flags & GDB_O_TRUNC) { - hf |= O_TRUNC; - } - if (flags & GDB_O_EXCL) { - hf |= O_EXCL; - } - - return hf; -} - -static bool translate_stat(CPUNios2State *env, target_ulong addr, - struct stat *s) -{ - struct gdb_stat *p; - - p = lock_user(VERIFY_WRITE, addr, sizeof(struct gdb_stat), 0); - - if (!p) { - return false; - } - 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 true; -} - static void nios2_semi_u32_cb(CPUState *cs, uint64_t ret, int err) { Nios2CPU *cpu = NIOS2_CPU(cs); @@ -147,8 +87,6 @@ static void nios2_semi_u64_cb(CPUState *cs, uint64_t ret, int err) */ #define GET_ARG(n) do { \ if (get_user_ual(arg ## n, args + (n) * 4)) { \ - result = -1; \ - errno = EFAULT; \ goto failed; \ } \ } while (0) @@ -159,10 +97,6 @@ void do_nios2_semihosting(CPUNios2State *env) int nr; uint32_t args; target_ulong arg0, arg1, arg2, arg3; - void *p; - void *q; - uint32_t len; - uint32_t result; nr = env->regs[R_ARG0]; args = env->regs[R_ARG1]; @@ -170,234 +104,95 @@ void do_nios2_semihosting(CPUNios2State *env) case HOSTED_EXIT: gdb_exit(env->regs[R_ARG0]); exit(env->regs[R_ARG0]); + case HOSTED_OPEN: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "open,%s,%x,%x", arg0, (int)arg1, - arg2, arg3); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = open(p, translate_openflags(arg2), arg3); - unlock_user(p, arg0, 0); - } - } + semihost_sys_open(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_CLOSE: - { - /* Ignore attempts to close stdin/out/err. */ - GET_ARG(0); - int fd = arg0; - if (fd > 2) { - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "close,%x", arg0); - return; - } else { - result = close(fd); - } - } else { - result = 0; - } - break; - } + GET_ARG(0); + semihost_sys_close(cs, nios2_semi_u32_cb, arg0); + break; + case HOSTED_READ: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "read,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_WRITE, arg1, len, 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = read(arg0, p, len); - unlock_user(p, arg1, len); - } - } + semihost_sys_read(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_WRITE: GET_ARG(0); GET_ARG(1); GET_ARG(2); - len = arg2; - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "write,%x,%x,%x", - arg0, arg1, len); - return; - } else { - p = lock_user(VERIFY_READ, arg1, len, 1); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = write(arg0, p, len); - unlock_user(p, arg0, 0); - } - } + semihost_sys_write(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_LSEEK: - { - uint64_t off; - GET_ARG(0); - GET_ARG(1); - GET_ARG(2); - GET_ARG(3); - off = (uint32_t)arg2 | ((uint64_t)arg1 << 32); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u64_cb, "lseek,%x,%lx,%x", - arg0, off, arg3); - } else { - off = lseek(arg0, off, arg3); - nios2_semi_u64_cb(cs, off, errno); - } - return; - } + GET_ARG(0); + GET_ARG(1); + GET_ARG(2); + GET_ARG(3); + semihost_sys_lseek(cs, nios2_semi_u64_cb, arg0, + deposit64(arg2, arg1, 32, 32), arg3); + break; + case HOSTED_RENAME: GET_ARG(0); GET_ARG(1); GET_ARG(2); GET_ARG(3); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "rename,%s,%s", - arg0, (int)arg1, arg2, (int)arg3); - return; - } else { - p = lock_user_string(arg0); - q = lock_user_string(arg2); - if (!p || !q) { - result = -1; - errno = EFAULT; - } else { - result = rename(p, q); - } - unlock_user(p, arg0, 0); - unlock_user(q, arg2, 0); - } + semihost_sys_rename(cs, nios2_semi_u32_cb, arg0, arg1, arg2, arg3); break; + case HOSTED_UNLINK: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "unlink,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = unlink(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_remove(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_STAT: GET_ARG(0); GET_ARG(1); GET_ARG(2); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "stat,%s,%x", - arg0, (int)arg1, arg2); - return; - } else { - struct stat s; - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = stat(p, &s); - unlock_user(p, arg0, 0); - } - if (result == 0 && !translate_stat(env, arg2, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_stat(cs, nios2_semi_u32_cb, arg0, arg1, arg2); break; + case HOSTED_FSTAT: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "fstat,%x,%x", - arg0, arg1); - return; - } else { - struct stat s; - result = fstat(arg0, &s); - if (result == 0 && !translate_stat(env, arg1, &s)) { - result = -1; - errno = EFAULT; - } - } + semihost_sys_fstat(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_GETTIMEOFDAY: - /* Only the tv parameter is used. tz is assumed NULL. */ GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "gettimeofday,%x,%x", - arg0, 0); - return; - } else { - struct gdb_timeval *p; - int64_t rt = g_get_real_time(); - p = lock_user(VERIFY_WRITE, arg0, sizeof(struct gdb_timeval), 0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = 0; - 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, arg0, sizeof(struct gdb_timeval)); - } - } + GET_ARG(1); + semihost_sys_gettimeofday(cs, nios2_semi_u32_cb, arg0, arg1); break; + case HOSTED_ISATTY: GET_ARG(0); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "isatty,%x", arg0); - return; - } else { - result = isatty(arg0); - } + semihost_sys_isatty(cs, nios2_semi_u32_cb, arg0); break; + case HOSTED_SYSTEM: GET_ARG(0); GET_ARG(1); - if (use_gdb_syscalls()) { - gdb_do_syscall(nios2_semi_u32_cb, "system,%s", - arg0, (int)arg1); - return; - } else { - p = lock_user_string(arg0); - if (!p) { - result = -1; - errno = EFAULT; - } else { - result = system(p); - unlock_user(p, arg0, 0); - } - } + semihost_sys_system(cs, nios2_semi_u32_cb, arg0, arg1); break; + default: qemu_log_mask(LOG_GUEST_ERROR, "nios2-semihosting: unsupported " "semihosting syscall %d\n", nr); - result = 0; + nios2_semi_u32_cb(cs, -1, ENOSYS); + break; + + failed: + nios2_semi_u32_cb(cs, -1, EFAULT); + break; } -failed: - nios2_semi_u32_cb(cs, result, errno); } From patchwork Tue May 3 19:48: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: 569018 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9811720map; Tue, 3 May 2022 13:57:06 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxFDEmE05Am80dx9qy/sftWUx71/KzudyZhpK+yiz/KBnWgW2c5NJmxqbouytk60JpDYkJb X-Received: by 2002:a05:620a:424c:b0:67d:2bad:4450 with SMTP id w12-20020a05620a424c00b0067d2bad4450mr13775234qko.171.1651611426080; Tue, 03 May 2022 13:57:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611426; cv=none; d=google.com; s=arc-20160816; b=KCA+Y33bu9Rzj4sJ6exlFeUiz6gOVylofYFjIZZQj1289pnxtAheUpf7mfOnsir+Vv +joqEjrqV/1YT2eEq/q3+eaUr/iOA+I5RQ5ktRRAW29CtBAFwwRQvgU3OWbINyH6I11i 0VOfqqlYjWIsMbYzzeKaFjRHpodkydWs8J1kv1Rf0nby7tdp/5EUFoet+2jz0OVfRJMD TzEsJnW4U0kiZiA/ZSUfuqIRXOk3MITRqCFLDB2Ly5XgpXp2pt3phMKazppWMT7wTMu7 LglBykpLQeIRDD252/dZPWayjiuanxYhegVCNGFnHPN93Nua1nDik7m5DHEkfu4td9U+ OAdA== 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=w4FYTiyxhI0mE5fcTHb/1MDqV87uaAoIyMIlxrvf02Y=; b=0l7LBsy67kZQICnV3mzeywaJjNxGqgEXPQJGEQ8ugiVblssHOdbHl9R57tG4+yAULC zhEZiGpcXi3mItAg8/NCTzSiDYT/brpy67dXW8O/hgftikljI4/wLMHax5JgbYqQzfB8 H7STRJkkLq6w/NIjFOX24j8Ox92gZ8to6RIskOxicQF+xmkwM1tHOThUx3mBONWwMTKR GaIMUtdDycjxzOxuSUeyOVl/193UDCYYnY+lR82xcLIlhoTyX/YDAjec6QQhfEMsgHK1 2XAcL9uOwy7Q9mge5ro0cBGLBftER+VyRZwcOz4xThDCRpuKmZR1WWffsW8eyuQm1Uya tywA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ixXlpYSR; 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 e22-20020ac85996000000b002f3ac329b2fsi2374390qte.370.2022.05.03.13.57.06 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:57:06 -0700 (PDT) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ixXlpYSR; 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]:41346 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzZx-0004Hn-Ks for patch@linaro.org; Tue, 03 May 2022 16:57:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40412) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZh-0008WJ-6s for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:45 -0400 Received: from mail-pl1-x635.google.com ([2607:f8b0:4864:20::635]:39820) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZd-0006L6-UP for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:44 -0400 Received: by mail-pl1-x635.google.com with SMTP id x18so4706959plg.6 for ; Tue, 03 May 2022 12:52:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=w4FYTiyxhI0mE5fcTHb/1MDqV87uaAoIyMIlxrvf02Y=; b=ixXlpYSRTQse5LUTrLOP6bRztHCxQ5YGYEhEkN3fV63bpnNd+v507BKD4i/xLJ2um9 tm+dTB5g/WJFZ1s8k8VpisJ1K3ZddUaKWbgcuJE1ME0ZTy0DYOwdCGAjx2a6aY/FQ4zx cyeiOmPgGujZD4Tr+TgruOQ4AJBxLAu73l0D+8RC1HwDxhTw5kxfqMTLT/BkwZA1WKes K812AOHFmSyEuYXe6P3axOnvmJaNJhfrBpPJUngzc8VaxsWzus8vu2Gh1EHvlyr7dW/V 7bzEu8KG+lRRf+JYuyu7RzG5fC9EAjyGwfwBCfVqbaCLB94IvtmHlrQZcH+shMx/f2SH Yyug== 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=w4FYTiyxhI0mE5fcTHb/1MDqV87uaAoIyMIlxrvf02Y=; b=rpON7/IHbLob6u+X8c1l20BzaGjU1wjEZjC8WJDr6FaUItIEE9woo2CYxI0jDSmbaQ dtbURWifVXDCkMFXYkIH5ISxrOzpi55RDAxUA1nFDku1eygQtpJQaCb1dWZTk88pn7Da KeB3BzhV9EoKXTwsuEnkYzOT2qfIlZUTfYPPZ4GnWUZneIXd8eJ4Is6zTnwhTRZCYsYX nhHsO+66IjgQVKKAR/csMPm/vYEfnfo5CRv57QoVK26yUXzbaFvpNaqr2jpxuGklUWsc Q26FIbraaofO5Jk3oMXw0zHpbODgRrOTnytwYYDfhp4wKGJvv/vuIwG1mgAte1S4qrft f6PA== X-Gm-Message-State: AOAM5309Wg93vv5yDIf85YxbEbwHwGP/86NAyM2zTZaEZINmGDEca0BU BtCaGdO2ZiiZm/GRGlXtfbpAIXAO0V+oMQ== X-Received: by 2002:a17:902:e78e:b0:15d:29ba:77fe with SMTP id cp14-20020a170902e78e00b0015d29ba77femr18261529plb.119.1651607559106; Tue, 03 May 2022 12:52:39 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.38 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:38 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 54/74] target/mips: Use an exception for semihosting Date: Tue, 3 May 2022 12:48:23 -0700 Message-Id: <20220503194843.1379101-55-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::635; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x635.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(). 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 5335ac10a3..f56a5a95c4 100644 --- a/target/mips/cpu.h +++ b/target/mips/cpu.h @@ -1251,8 +1251,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 6de5b66650..e554b3adcc 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 916cece4d2..5b0e4683a7 100644 --- a/target/mips/tcg/nanomips_translate.c.inc +++ b/target/mips/tcg/nanomips_translate.c.inc @@ -3691,7 +3691,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); @@ -4609,7 +4609,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 May 3 19:48: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: 569005 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9804171map; Tue, 3 May 2022 13:44:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6sU539OsE5ZCHGaGV6lpcXy4lDKdM2/B0+8dpZhL5XXTGQjNbX7xKv51l0DV7O+mqGcld X-Received: by 2002:a37:6696:0:b0:69f:c376:3762 with SMTP id a144-20020a376696000000b0069fc3763762mr13031924qkc.588.1651610643498; Tue, 03 May 2022 13:44:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610643; cv=none; d=google.com; s=arc-20160816; b=DTS2mHv/r4mz0PIgatyuywysGCYtB3AiknnT0qem4IokR3NLJKmcCE/5/GHK8sfllS 597AwPYn09hz4ijja6OkSOyFYF0ug3/9LpMvRT2QqxViaY7MI85qMQjvccitLIdCZO75 ssh2k/ztoPiHrW8QVBmBDnXfMasQMRVuU0O87KIGYY0O9OTHU4YfDVp4LR5pn3vnLxag dMtm4OEClbosKEaB0fu2c1FJlwYxGgKPv1fAsst7Gx+cd0iJ41WG7DyxSBO8XWOKRyui Kiev5GGU1s4Db65nOEVrsJfher7LYwXgLmcNiraJXIhAPTnuMukzB8eOFRDFJX6GbMBw 43ng== 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=oYsK2DCkJDRZ/LkA4A11UkQEUx69l+6MA6r9SJofgvk=; b=kTpN9AyAdYG0qRjSj+2THy2v/djXeoD2TN30YoDIM+TpJFhcyf+6VKAsmQGt7JeI+r uhBYN6zbjW2Rzn+rc6ICPMQah8HG+c6ZrvqGe95llvghClMAFbH7KoEqLrDZXMQhg179 kR7bGquvi+LI7+MWaeZfidsA54TWeIAy8nlz0wPf58XtUYGEBvfA5TiDvRhg6JuTZd48 F4lQMP4inyp/iOtnGUOup+3wWg55v9mf6jCBbUCjhLmiMzr59ABGpiqkiFSDBrjk7iak mkLC6ONuRvVjhO5+xL3yo3UJPMBmyPQ0zB0vCRy8OJa6FcGLHqmb7YtoUVcaAu0d0AXo JGEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ECwc7EXt; 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 h19-20020ac87d53000000b002e205f43237si8509893qtb.222.2022.05.03.13.44.03 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:44: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=ECwc7EXt; 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]:44816 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzNK-0000er-WD for patch@linaro.org; Tue, 03 May 2022 16:44:03 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40362) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZf-0008Nc-H8 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:43 -0400 Received: from mail-pj1-x102a.google.com ([2607:f8b0:4864:20::102a]:42903) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZd-0006LA-UW for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:43 -0400 Received: by mail-pj1-x102a.google.com with SMTP id l11-20020a17090a49cb00b001d923a9ca99so2893488pjm.1 for ; Tue, 03 May 2022 12:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=oYsK2DCkJDRZ/LkA4A11UkQEUx69l+6MA6r9SJofgvk=; b=ECwc7EXty1GffriXrCRjGcaqGc0PJxHteRqPo1NXL8thlQWB+pNNIovhjxxq8muafV W1KLZ1OTvQsJJyRLOPL7vKNuYwTc17R9o5KJLzXxYXP5abAsd+SpcSMIqBoEkq2aniFC oU9/JP8c0J9k4nPIejuz4grtip3t2VqlGF/mSJLrj9LpbxpKXUWx9HrReKnAAvxRaVUj orm64Vj0Zdz+9Ht/8ZrayBklkmhvIoTgFLGZTaTrYlwQhlSlldyL/46I3JtmGREbSUGr DQ6qKY8DdrY+nJs0NTn0Mn6qWReFaVXeHN023qqOtdfgBgniPPHKIXgnCwJvnBGZkJy8 miIQ== 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=oYsK2DCkJDRZ/LkA4A11UkQEUx69l+6MA6r9SJofgvk=; b=ruShd73Nw9C8yxxYRmGw4x1TjyOmvjwqMOc3NO4Bt2smZaDFLDskBLLSYWJGiH3oGu vvtHUh+nMPhFylia4gGH+cmv4BJXbtziZG7e0bKsfyfF9z5DeMrRfhFgPrkGyyJDanC8 YuZx55ZZMCSWbzRQXKbtezzb81qE8LS/LaMnWmzddiaEQfWQjx+NxNosgrNyIrxvviKA 8gQC7mlMJ7WhVHhPNlaVmxJuwhW9Ju4DSNHxV6i+oaKVZepGbm+KHRokwnCZ61pkZYc4 9dfoQorho94Sfy2fI3k2CJHtpGiS+McDzfmauxHfmMp2hSMJ9wW5a6bfHMjl4mlnMF0m uy9A== X-Gm-Message-State: AOAM531wuVjVFpH0rT1jpu+qKFkTP92cIgeOkZbplFG8/AoiVLzWxBSy umod/61ABdp/II0DddeXW5BmXQeRdWRfMQ== X-Received: by 2002:a17:902:a707:b0:15b:6ea2:8ea2 with SMTP id w7-20020a170902a70700b0015b6ea28ea2mr17924477plq.134.1651607560347; Tue, 03 May 2022 12:52:40 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:39 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 55/74] target/mips: Add UHI errno values Date: Tue, 3 May 2022 12:48:24 -0700 Message-Id: <20220503194843.1379101-56-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::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" >From the Unified Hosting Interface, MD01069 Reference Manual, version 1.1.6, 06 July 2015. 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 May 3 19:48: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: 569015 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9809275map; Tue, 3 May 2022 13:52:44 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxkaOLPhlRkp+JKpNQhNbd9bSzTu/426nTP/hvadmDeA2AxwM8L8FNWc7xlptZSQAG/hfqe X-Received: by 2002:a05:622a:34d:b0:2f3:44d9:41a8 with SMTP id r13-20020a05622a034d00b002f344d941a8mr16602432qtw.217.1651611164354; Tue, 03 May 2022 13:52:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611164; cv=none; d=google.com; s=arc-20160816; b=bDfo4nRz43u5BugoJ7rg+o3CCpHjxJygToc2vDx/qLAJS7IbVcfGTVew7vh2N2t7Te xjHRbbSqqpPWNBN2NArl5wzWJxbGgkx30nj82FOWe2kzC/xkJ1tvVP4ZHKrYFNJeuMOa VClk3yyyAn9wIVMOjgOE56ICwcF4wPuoyHVwxmpmzAN/AD+P+XUve0dHQpWklXY1Eyyz wHVJ95TV/1gQHna+gx17z/KvJrxj4s5+XT+a9YudlUIxJWC/zSjpB+J8C9m2Osrmo6PA AbVMgZCRyJ4xcjJwdsybIvIJvHgK/Pb2GFJ71NjQrHy3RLAg61dSiD0KdRtdNQ9RTIlY 157w== 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=HeLbzu4J7HUJ/gIyU/6OdVT7zEVHegu20jhi9pPruCA=; b=ikn4PFJzLSZvZMHeNYHEz4mheGzyk2wPkx21Trdg1Gu7uowmfWQN11ImCgVjG1SL/E UF5llZ6TXIQJUQ9RU4GdGhbHpANuD5BxD/632acVzQV0Kw56R3i9FQZ7MKAUE7kOm/AK EkFFkWKvwjlVzhZnnfK4DxajyZ0FyaUPqNQXv9uecMA0HWzwDfmK1jlGXut/APQCebP6 uPCBTF/jwHvhbTnKnm/jAjlI8QsI/epd36CRKDPYcMhBJZS5goyCFFok81rpLoPOF6wL ZUetjilRheBn3e4U0mMQQ28w8h/z/Wt0KBgeLNax09dk3PeV0P31P3EB0Tp0rvHwbprP LRdg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=djZ67NzG; 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 d7-20020ac85ac7000000b002f3a7234b18si3565400qtd.306.2022.05.03.13.52.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:52:44 -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=djZ67NzG; 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]:33378 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzVj-0006Be-PB for patch@linaro.org; Tue, 03 May 2022 16:52:43 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40408) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZh-0008VV-2q for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:45 -0400 Received: from mail-pl1-x630.google.com ([2607:f8b0:4864:20::630]:35731) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZe-0006LH-B6 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:44 -0400 Received: by mail-pl1-x630.google.com with SMTP id d15so15896872plh.2 for ; Tue, 03 May 2022 12:52:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=HeLbzu4J7HUJ/gIyU/6OdVT7zEVHegu20jhi9pPruCA=; b=djZ67NzGjP8c9+Z4Lv/14NmOl2flIAmtZ3jLkHkqPcoYWBEPUqtOc5wS8cD5TlSbMW ZO937dvXUQ2WKb4u0WduhdW6xXzkKSx5PM8nwXEDPTsByJxeSvdoMJiCxPkxwUKXmZe9 oSh9SR2GDgDHhPfc/9sED/PdW4lSdvdDQE4k+mK8mryvSBVklqnW9nER3ZTFnqIcclL3 9VSYjWmSSgOTcjmYjCvXm6dnYNYZISGOTVJHj5QtUXviPVsSIDIS2dKZJx8kUC61SyoO BSN34AvUrBz42JgA88ekUQ+0d3DLtDmlOxIKG4h4DJU3ZTOXs8XYqEHYEyZRbu7s2r/D F3eQ== 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=HeLbzu4J7HUJ/gIyU/6OdVT7zEVHegu20jhi9pPruCA=; b=4X6Yub5jjkW//2X2c1hiOXCJkHyBCkbEbqCp+8hGQecW15QIHTxoO0VEHrFoiT/4iy 16OyCssaqofQKhmhfyoNF+NVz3ZZI3mnxSNuDb3l6V14nXgpoNogV7Av1lbexepEYKN3 9e0aiWfJAV2fMkqbt7PjX5ilbFSMbFkWKTrE7SUny1jkz5hkoCXxLUsmIVK81nVjHomW AO9xEq0IFXI8sFjBgV+XXdo0I6HIunhH7unnWuFGwVrQ/YfZ0mPUEzBJkIpR9kdz59cn /9nplKTaDSbcuB3KkHPJfdj4K/J3RzqJ9CbHY+HD5DQoRstr1MplwGCUbFxw7mfVMpUx dlgA== X-Gm-Message-State: AOAM530benyV/aY7UCEzZKUzsIcIr5DwusK6wU2Gow+qRgSWpRnZkv/Y 3wNaxUUujw3yxvmIMW8FebNF7aDXbsf0oA== X-Received: by 2002:a17:902:8605:b0:15d:10dc:1c6f with SMTP id f5-20020a170902860500b0015d10dc1c6fmr18366045plo.4.1651607561110; Tue, 03 May 2022 12:52:41 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.40 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 56/74] target/mips: Create report_fault for semihosting Date: Tue, 3 May 2022 12:48:25 -0700 Message-Id: <20220503194843.1379101-57-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::630; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x630.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 UHI specification does not have an EFAULT value, and further specifies that "undefined UHI operations should not return control to the target". So, log the error and abort. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 33 ++++++++++++++---------------- 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 2a039baf4c..33221444e1 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -114,6 +114,13 @@ enum UHIErrno { UHI_EXDEV = 18, }; +static void report_fault(CPUMIPSState *env) +{ + int op = env->active_tc.gpr[25]; + error_report("Fault during UHI operation %d", op); + abort(); +} + static int errno_mips(int host_errno) { /* Errno values taken from asm-mips/errno.h */ @@ -136,8 +143,7 @@ static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src, hwaddr len = sizeof(struct UHIStat); UHIStat *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } dst->uhi_st_dev = tswap16(src->st_dev); @@ -188,8 +194,7 @@ static int write_to_file(CPUMIPSState *env, target_ulong fd, target_ulong vaddr, int num_of_bytes; void *dst = lock_user(VERIFY_READ, vaddr, len, 1); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } if (offset) { @@ -213,8 +218,7 @@ static int read_from_file(CPUMIPSState *env, target_ulong fd, int num_of_bytes; void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); if (!dst) { - errno = EFAULT; - return -1; + report_fault(env); } if (offset) { @@ -237,7 +241,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, int strsize = strlen(semihosting_get_arg(arg_num)) + 1; char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0); if (!dst) { - return -1; + report_fault(env); } strcpy(dst, semihosting_get_arg(arg_num)); @@ -250,9 +254,7 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, do { \ p = lock_user_string(addr); \ if (!p) { \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ } while (0) @@ -260,16 +262,11 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, do { \ p = lock_user_string(addr); \ if (!p) { \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ p2 = lock_user_string(addr2); \ if (!p2) { \ - unlock_user(p, addr, 0); \ - gpr[2] = -1; \ - gpr[3] = EFAULT; \ - return; \ + report_fault(env); \ } \ } while (0) @@ -400,7 +397,7 @@ void mips_semihosting(CPUMIPSState *env) break; #endif default: - fprintf(stderr, "Unknown UHI operation %d\n", op); + error_report("Unknown UHI operation %d", op); abort(); } return; From patchwork Tue May 3 19:48: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: 569009 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9806708map; Tue, 3 May 2022 13:48:27 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxW5wzZcGRKURBV7CX2kP09Ijc2xWLZ9DcXXljFmCsXHJu3eg1+hlaEIeQQG/ExvWaKRVMD X-Received: by 2002:a05:6214:c6e:b0:449:705e:6e68 with SMTP id t14-20020a0562140c6e00b00449705e6e68mr15361549qvj.61.1651610907044; Tue, 03 May 2022 13:48:27 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610907; cv=none; d=google.com; s=arc-20160816; b=buoVD/zMG28bdH6M6+sLtHt00HFcXN6XuZAY7bX+DgbMB4j7+JVQzWa6BxyLCyAuC6 uWOf02yYvEFxkFNfdCk3t+EHLnP5BYe0CiCKseBhV1etXjDujtQJ2z7kjByS5YVUyYDe 3hN0iqbn+GuJ3jh8Ry6u05hx+XTklDB4SBVdKQqDpgy12O/dcy/gg79usLCVH7Iw7lQi K2uPm5L90y/QzJNACm44Cj5CpcVh6wN9DJrPPYB9+CXPFzTUTjevvuKHorf84JWI/jgK BnvZtFzxS0SBB25PgjCv8o+bxMLP2iHW1itqPrze+8+3/xMs/zU/p0eFFa6oC38O0tLQ /TKg== 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=GB8QwFJfH3hlfZTD3yMvfbRrCq2bQTobhy4HeZnGERI=; b=mijsuss+pupakg69lPsIySCet+DH3UB/wVjO0UIbWsG1XVzE62H8jXBV3FZAw/b2w8 1b6hflv4mpdRugVpSXDkH4J3cLkGuGW+H/L5/Vyxz1vMCifLrvb4pdHsYDbShv9ql2da JbbRnIMQlZJWdwa6m52zD7BpID78p7kTyItPRixct1qS3eZAodinCYRHZ7t9ztrxDt2l 2eLr5waVNRoInGOZooXpge43tt2XpY9hxJnbBgkGQ640LZ7BCvn/ZbuXaDGnghPa07R8 YtmLUiloEdF7jOtAnfp3BLLRlmjO4YjLhGfuR1VzulPXA+fQmEMngUJJILLebn+LPLRR 9kfQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GtB5nMVs; 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 z13-20020ac87f8d000000b002f3874b5a79si7758223qtj.576.2022.05.03.13.48.26 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13: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=GtB5nMVs; 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]:52700 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzRa-0007lc-4z for patch@linaro.org; Tue, 03 May 2022 16:48:26 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40404) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZg-0008U3-S2 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:44 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:38538) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZf-0006Lg-CQ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:44 -0400 Received: by mail-pl1-x62f.google.com with SMTP id n18so15889581plg.5 for ; Tue, 03 May 2022 12:52:42 -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=GB8QwFJfH3hlfZTD3yMvfbRrCq2bQTobhy4HeZnGERI=; b=GtB5nMVsrNEpXCWZbCWF8g/W3EwF/Mua1oY9+ap3mkiUKWdwvq4ombMwk+6j2YfWxc LxyJ2hvCXet9+doyYlNi+O4KohOIpAOYg+hj8TN0qA5QCOrLTK0k8EN729Wxvl7VXh3J uA+Q50VankCW1YKTUzXrIb/BS97Iq2wBCSckHFUxo6Bri0dTWW53q8m8HbnfAVyeKzUt 9ameLXqrl13WaeKwCn87sh6+Tmq8NFKoeP7qZ7oizOhOeV3xmcp/4XtJIcxtYtrwc7Be a+rL2d7WmlxdPJCm90wj7vCeNwtEgf8RVAlipnCY8X9XzYALAqIPw+zpazktfICZwk/Y WlKQ== 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=GB8QwFJfH3hlfZTD3yMvfbRrCq2bQTobhy4HeZnGERI=; b=IY+MJZIJ23lf+pyrQIenENyvVVFioiObx+rKAzbX+vHybeXROc7nRxiqpPNnlkMYu/ 1lYYp0A1dBUysi+J0Q9bAsX9zy4LtjWIzIbyaOUj1rdl+/IH4tOc9+IrEgpsMpfJV99e usUywUaeDTOW3OLHt16QEZ1iYbbqlepLWqxfADNO1gOn9TrpTeZUbmNFwDjInAHwhgik UCd8WKGpCYd7Vm0bLsVVWPR7DFo/zezPCWDYTU4Ir6eG0aL4O+NcaaGJx7kq8f50iBTX Q4tlTAb+kVeKaUtJa5hjyDP+s5yUZYIiVZNfcI97M88qUeV6WsepxF9QG4KmTNDXqcej H5uQ== X-Gm-Message-State: AOAM533iZDIKZ+1/CcVuPIwscFpXmJxfEolPpD3GJE2gtVbg0fCqcH4M PUv2DBkqzOkYm5cSUltMO/8mXlFhUe/g4Q== X-Received: by 2002:a17:902:f652:b0:156:701b:9a2a with SMTP id m18-20020a170902f65200b00156701b9a2amr18143826plg.14.1651607562018; Tue, 03 May 2022 12:52:42 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.41 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:41 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 57/74] target/mips: Drop link syscall from semihosting Date: Tue, 3 May 2022 12:48:26 -0700 Message-Id: <20220503194843.1379101-58-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::62f; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62f.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 syscall is missing from the gdb remote file i/o interface. Since we can't implement it universally, drop it. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 9 --------- 1 file changed, 9 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 33221444e1..254c7fad9a 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -387,15 +387,6 @@ void mips_semihosting(CPUMIPSState *env) 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]); - gpr[2] = link(p, p2); - gpr[3] = errno_mips(errno); - FREE_TARGET_STRING(p2, gpr[5]); - FREE_TARGET_STRING(p, gpr[4]); - break; -#endif default: error_report("Unknown UHI operation %d", op); abort(); From patchwork Tue May 3 19:48:27 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569017 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9811113map; Tue, 3 May 2022 13:56:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwi2nT4OIn34t+qLsppSYFfpp2QYehkLfduQ/NSmwlf4MI8DWCEFDivPCKEdRDMXGMvu4UB X-Received: by 2002:a37:68d4:0:b0:60d:f4eb:fc12 with SMTP id d203-20020a3768d4000000b0060df4ebfc12mr13397473qkc.413.1651611369436; Tue, 03 May 2022 13:56:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611369; cv=none; d=google.com; s=arc-20160816; b=Vn6c8V0FReMXQQ+Gz0p7AFE72xDW3g64WHGv/7ZIzTeVO6soRFLm4r8FoO5Pyvj4K3 spebCkTQnXyHXp5ocI5p64EhjePEIsBgo8Wx2mIBpA0Cwu0W4BXI9ivmjvjOA+ffPpjg SmHhLV6+iCKd3OobbPOWxDyzVhuNZQaZLoho72iia52D710BLXRrfzIb8a3YJqlkf3fq +W7Bj3FIhLM2KGq5hukDgV+ppD+zAm6f3oJmn/QvIkAy1+NoHC+kEBHX7T/SpohfsYOB Tl6ZxP9DIP6RLIWNdUXvABQRoVTTHtojM+1tgb8jmmDZCyGaBFk/0VMSGhRob45DopxM EWKg== 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=vchvWnQo4YVofH3IH1WWni/usGrLZ5KUM5YMsZGZNkI=; b=dIVDTx1BCXMtleJZayYhI0iQaLBXKsmbwsj7l7j/YUWdh/lb6TjEK5jaEhPDkY8CaH JrLVRRLlDwClUh8JSrvp7+Zf0bO7II7KFIVwSDPPTn1DGF1Ps4VLJHytsIqHjOhrw+Dj YQ51hG9R5IKJogM5hiUB6mnZsYh6EymGkDrid6aKezA/3nqMbOkDmWhE5IeEzx2BF8I+ +qeWKvOCASAop8k3+SBx8ODZJY+Vza3zXclcYNnjpB6sxBVALl8titlX0Y6oE0UdId2K zA+edzp+wJKFD07mzEeKTghDh8Y9PWessd8bQsWAcV9mHI3z+31rUynTfr6q22W9mFd8 Eg8A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=S19xWTON; 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 s17-20020ac85cd1000000b002f35aeef1f3si8861647qta.397.2022.05.03.13.56.09 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:56: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=S19xWTON; 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]:40226 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzZ2-0002y1-Vq for patch@linaro.org; Tue, 03 May 2022 16:56:09 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40424) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZi-00008p-1m for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:46 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:36739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZg-0006Lz-9L for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:45 -0400 Received: by mail-pj1-x102d.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso3236773pjb.1 for ; Tue, 03 May 2022 12:52:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=vchvWnQo4YVofH3IH1WWni/usGrLZ5KUM5YMsZGZNkI=; b=S19xWTONITFI2jr+My+2I/32WrEJeYsStXMuRPt9I8KOqL9hqX8GHNUUQJEA8mrQsN jpNP1tPSEzf2w/Qo9DhaJA1+YnOrZeBaIkDyPCfppwwPA8bzVNtPF9xowqF4sihMQdA8 gdnpCKLZecJAv36P/Al/1aIQmFzuSxcX/m8x+tTdFoxnQqNCrHtXa9i7VbHou3Mxxi06 CTyj97zXuC3aKK1wQPQ9T6Z0uU3Y+1yTaQVWLJettVT7M2LqLENXaCRzmI5Cvk8Ba3cG wFl2RKgMqTcEIm7cQ5sHzS3xueUBRef7Tr8ch3M66yS263y6r//3MPf6ICSdah4N+5a6 2d6w== 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=vchvWnQo4YVofH3IH1WWni/usGrLZ5KUM5YMsZGZNkI=; b=BZeIqw6r3fyzbwaV+W8kLG7TNbFLNpyCcW+0gVTvGlccEKmt0aDH9+/4kKfpODeMMY hin/X9rdQccji6zJMOoMNvRqS0pDYX/8HwRCyKoPMs71XigZ40Znt5FfDCOBdzcJy5xe hZS1h4WS0tmIqruLo1f+oKNZjxxyZGV3gfwCvJAKC/we6AIkQoE3UNtMK+YVrn3Fl7EG ZacqXUNQK4/QRDmdlAFZWKTzW9ILvicoDShyETnM3J7su/SJhb9s1NFT4wWcNnk3OXQL 48pYSz5mCZqMJRAW7NTihPeVNEZXSt17W7b8fV2iFlp9uVGsd+ki8yqU+fAEtAUSeLXE Kz0A== X-Gm-Message-State: AOAM533QaBExhbKtOcm20Wr1sqBBrJ6748uDPbaZ4I6dwP3suj++bz/4 CVQpLlDvWX1C+LvxUUYYnI6VSvoLScdIQA== X-Received: by 2002:a17:90b:1bc4:b0:1dc:2133:2e01 with SMTP id oa4-20020a17090b1bc400b001dc21332e01mr6564571pjb.221.1651607563037; Tue, 03 May 2022 12:52:43 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.42 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:42 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 58/74] target/mips: Drop pread and pwrite syscalls from semihosting Date: Tue, 3 May 2022 12:48:27 -0700 Message-Id: <20220503194843.1379101-59-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::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" 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. 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 254c7fad9a..93c9d3d0b3 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -188,8 +188,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); @@ -197,23 +197,14 @@ static int write_to_file(CPUMIPSState *env, target_ulong fd, target_ulong vaddr, report_fault(env); } - 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); @@ -221,15 +212,7 @@ static int read_from_file(CPUMIPSState *env, target_ulong fd, report_fault(env); } - 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; @@ -309,11 +292,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: @@ -379,14 +362,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; default: error_report("Unknown UHI operation %d", op); abort(); From patchwork Tue May 3 19:48: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: 569022 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9815606map; Tue, 3 May 2022 14:03:16 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxsVttb5flndcC1NR/UFi6x/TexvYg3I9wx7XN9RiK1rWvckojAdZtWINlZc3p8RnMiBMkf X-Received: by 2002:a05:620a:424e:b0:67e:4c1b:c214 with SMTP id w14-20020a05620a424e00b0067e4c1bc214mr13909917qko.651.1651611795920; Tue, 03 May 2022 14:03:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611795; cv=none; d=google.com; s=arc-20160816; b=zfyYyPyHNfVQdgOnm9a3NrlbPJ4R7+LWDQCxfDhctMzxMsfBiJWuhgFLcg6XvFpRxs SmxW3qlRb8TOw3DqC+34QiWmNeAlee83UcmAWS5uJzkOMNQwHHfSKP9O20BAIdEJ75CZ pAL2HPX5nCAwNiTWe5UKq0EElZg4A9rcCxBUJvw6WtiTflEuIQT+jaDmXyHHtChzpcQ6 t48yzg8rMtScIEaXUtJ+QtS0BHTGjxNdZlM0yGqAe6qyXJavpFy+NgGwKXwBWtcN7Nyc Zh0KEoQw1cnfZ6O6kzBUjbnfdutveWZdY4n+OOoed/AhcWJXAC2yb9yducFk5DWGz8WG 1RQg== 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=zPWlxsAWmGm+DKvIMC5SOGM9iT+0ZIRbfdAuRzsXiCE=; b=cX+Rovki9PLsBqI4j/9hEXfDgNiSomG3snnlf7xFw27v8cM7sOhqBxxzjLyWbYWYRf kkLzDuKw9W6a8irpySgp2WD07QjH+NnwOpmpitngJH070Y24hrmBmBEDwxkcQ4RR425A cY83XAaWYDgYPwuZ/n/L4GpQa1jgzI3uGW+TeQI5N5YI/GeaCaDZ8ARpgV0KFV/xeNTZ Fkw/Ur6nHUdVEKI1gtidQ0L/A7Vyg+W8TX8sahEYZajGGQaFNbK3xqI9NPNUR3Y8AmJq JUtOaesYC164yxwqkJOXikyqQdZtblcaY2nmr5tjT1NY84CCJhfOnfTLRg6Q7SOvqF3L jusA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bI7luPe8; 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 d5-20020a05622a15c500b002f379278581si9021088qty.252.2022.05.03.14.03.15 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:03:15 -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=bI7luPe8; 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]:49402 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzfv-0004YO-Dc for patch@linaro.org; Tue, 03 May 2022 17:03:15 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40448) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZj-0000Is-F9 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:47 -0400 Received: from mail-pl1-x632.google.com ([2607:f8b0:4864:20::632]:38541) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZh-0006MB-Em for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:47 -0400 Received: by mail-pl1-x632.google.com with SMTP id n18so15889658plg.5 for ; Tue, 03 May 2022 12:52:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zPWlxsAWmGm+DKvIMC5SOGM9iT+0ZIRbfdAuRzsXiCE=; b=bI7luPe8EdRfPFih7iBg8fyJF47g4LoZArBjLansv7IX3Zk/xS8djk5QvEdYIDk5Uj SCdLMc/x2jUNQ86tCGZzP9O/E8ABUJSPHr2luz32ZNlWZEZg0GokDRck06QnQxTgyiI2 BsFPLfIbbw56jOnGEEedyUK27ziRP0QyMEgq7ns7I6IqgqoK2+J1cgRIfz2v+iJkNPde 5ud+KRanlVlHPdHcLAUJcmXAY7C3iAAO7hR3d+l1UF4AQsMg89nCNq+enJaZMKxz3iJq pkrKRmkEOt9qQkimaRBxHxOWsgZiJbyiVenRmmrNIKGj8NhiD6oDSIgGuffv4LMdY2Hw l7Fg== 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=zPWlxsAWmGm+DKvIMC5SOGM9iT+0ZIRbfdAuRzsXiCE=; b=p9q7q10LldnSfv41SdCmwR6R2YGwYhStgwET3s1WZ2xjpN5TQNCqDhO9GIWD4rMDhg IQ804aExrRJGdWkY7sd1TLhYc7/f6Wd3mA2WKrqy7dIzfX1PAkz55HW9MRIXKz2r/gyL Uz1oQyOqWTTfumRhO4p+5RO+bR/ASo2PrktIxtHXqy9VnOgoD+MBizVJU6CYg4I1YhQc 60124NPAzIgGldM09S0xDHDLl5o0x8oCMhwkQv0lKPj43rjxl/65y0WKwnQkMrmKNUDu WyCO6JqR6qX/I1YAFDyJBEX1QT49Phco5NR9UpBoTX/xL86OQyWFPKkdlgJsZU0EHm/u DrUg== X-Gm-Message-State: AOAM530/oyAfq80cak8cCyMKxBbye0vhszXFnuLpaK9CZ9nVzsqc/BUj jSr+S5yNJpb7/Rk2g6SrAsmP1BrNxD8NNA== X-Received: by 2002:a17:90b:4b0e:b0:1dc:658c:ae89 with SMTP id lx14-20020a17090b4b0e00b001dc658cae89mr6441016pjb.82.1651607564044; Tue, 03 May 2022 12:52:44 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.43 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:43 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 59/74] target/mips: Use semihosting/syscalls.h Date: Tue, 3 May 2022 12:48:28 -0700 Message-Id: <20220503194843.1379101-60-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::632; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x632.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 separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 219 +++++++++++++---------------- 1 file changed, 95 insertions(+), 124 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 93c9d3d0b3..2704177a95 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -20,9 +20,11 @@ #include "qemu/osdep.h" #include "cpu.h" #include "qemu/log.h" +#include "exec/gdbstub.h" #include "semihosting/softmmu-uaccess.h" #include "semihosting/semihost.h" #include "semihosting/console.h" +#include "semihosting/syscalls.h" #include "internal.h" typedef enum UHIOp { @@ -121,101 +123,79 @@ static void report_fault(CPUMIPSState *env) abort(); } -static int errno_mips(int host_errno) +static void uhi_cb(CPUState *cs, uint64_t ret, int err) { - /* Errno values taken from asm-mips/errno.h */ - switch (host_errno) { - case 0: return 0; - case ENAMETOOLONG: return 78; -#ifdef EOVERFLOW - case EOVERFLOW: return 79; -#endif -#ifdef ELOOP - case ELOOP: return 90; -#endif - default: return EINVAL; - } -} + CPUMIPSState *env = cs->env_ptr; -static int copy_stat_to_target(CPUMIPSState *env, const struct stat *src, - target_ulong vaddr) -{ - hwaddr len = sizeof(struct UHIStat); - UHIStat *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); - if (!dst) { +#define E(N) case E##N: err = UHI_E##N; break + + switch (err) { + E(PERM); + E(NOENT); + E(INTR); + E(BADF); + E(BUSY); + E(EXIST); + E(NOTDIR); + E(ISDIR); + E(INVAL); + E(NFILE); + E(MFILE); + E(FBIG); + E(NOSPC); + E(SPIPE); + E(ROFS); + E(NAMETOOLONG); + case 0: + break; + default: + err = UHI_EINVAL; + break; + case GDB_EFAULT: report_fault(env); } - dst->uhi_st_dev = tswap16(src->st_dev); - dst->uhi_st_ino = tswap16(src->st_ino); - dst->uhi_st_mode = tswap32(src->st_mode); - dst->uhi_st_nlink = tswap16(src->st_nlink); - dst->uhi_st_uid = tswap16(src->st_uid); - dst->uhi_st_gid = tswap16(src->st_gid); - dst->uhi_st_rdev = tswap16(src->st_rdev); - dst->uhi_st_size = tswap64(src->st_size); - dst->uhi_st_atime = tswap64(src->st_atime); - dst->uhi_st_mtime = tswap64(src->st_mtime); - dst->uhi_st_ctime = tswap64(src->st_ctime); -#ifdef _WIN32 - dst->uhi_st_blksize = 0; - dst->uhi_st_blocks = 0; -#else - dst->uhi_st_blksize = tswap64(src->st_blksize); - dst->uhi_st_blocks = tswap64(src->st_blocks); -#endif - unlock_user(dst, vaddr, len); - return 0; +#undef E + + env->active_tc.gpr[2] = ret; + env->active_tc.gpr[3] = err; } -static int get_open_flags(target_ulong target_flags) +static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) { - int open_flags = 0; + QEMU_BUILD_BUG_ON(sizeof(UHIStat) < sizeof(struct gdb_stat)); - if (target_flags & UHIOpen_RDWR) { - open_flags |= O_RDWR; - } else if (target_flags & UHIOpen_WRONLY) { - open_flags |= O_WRONLY; - } else { - open_flags |= O_RDONLY; + if (!err) { + CPUMIPSState *env = cs->env_ptr; + target_ulong addr = env->active_tc.gpr[5]; + UHIStat *dst = lock_user(VERIFY_WRITE, addr, sizeof(UHIStat), 1); + struct gdb_stat s; + + if (!dst) { + report_fault(env); + } + + memcpy(&s, dst, sizeof(struct gdb_stat)); + memset(dst, 0, sizeof(UHIStat)); + + dst->uhi_st_dev = tswap16(be32_to_cpu(s.gdb_st_dev)); + dst->uhi_st_ino = tswap16(be32_to_cpu(s.gdb_st_ino)); + dst->uhi_st_mode = tswap32(be32_to_cpu(s.gdb_st_mode)); + dst->uhi_st_nlink = tswap16(be32_to_cpu(s.gdb_st_nlink)); + dst->uhi_st_uid = tswap16(be32_to_cpu(s.gdb_st_uid)); + dst->uhi_st_gid = tswap16(be32_to_cpu(s.gdb_st_gid)); + dst->uhi_st_rdev = tswap16(be32_to_cpu(s.gdb_st_rdev)); + dst->uhi_st_size = tswap64(be64_to_cpu(s.gdb_st_size)); + dst->uhi_st_atime = tswap64(be32_to_cpu(s.gdb_st_atime)); + dst->uhi_st_mtime = tswap64(be32_to_cpu(s.gdb_st_mtime)); + dst->uhi_st_ctime = tswap64(be32_to_cpu(s.gdb_st_ctime)); + dst->uhi_st_blksize = tswap64(be64_to_cpu(s.gdb_st_blksize)); + dst->uhi_st_blocks = tswap64(be64_to_cpu(s.gdb_st_blocks)); + + unlock_user(dst, addr, sizeof(UHIStat)); } - open_flags |= (target_flags & UHIOpen_APPEND) ? O_APPEND : 0; - open_flags |= (target_flags & UHIOpen_CREAT) ? O_CREAT : 0; - open_flags |= (target_flags & UHIOpen_TRUNC) ? O_TRUNC : 0; - open_flags |= (target_flags & UHIOpen_EXCL) ? O_EXCL : 0; - - return open_flags; -} - -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); - if (!dst) { - report_fault(env); - } - - 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) -{ - int num_of_bytes; - void *dst = lock_user(VERIFY_WRITE, vaddr, len, 0); - if (!dst) { - report_fault(env); - } - - num_of_bytes = read(fd, dst, len); - - unlock_user(dst, vaddr, len); - return num_of_bytes; + uhi_cb(cs, ret, err); } static int copy_argn_to_target(CPUMIPSState *env, int arg_num, @@ -260,68 +240,59 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, void mips_semihosting(CPUMIPSState *env) { + CPUState *cs = env_cpu(env); target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; char *p, *p2; switch (op) { case UHI_exit: - qemu_log("UHI(%d): exit(%d)\n", op, (int)gpr[4]); + gdb_exit(gpr[4]); exit(gpr[4]); + case UHI_open: - GET_TARGET_STRING(p, gpr[4]); - if (!strcmp("/dev/stdin", p)) { - gpr[2] = 0; - } else if (!strcmp("/dev/stdout", p)) { - gpr[2] = 1; - } else if (!strcmp("/dev/stderr", p)) { - gpr[2] = 2; - } else { - gpr[2] = open(p, get_open_flags(gpr[5]), gpr[6]); - gpr[3] = errno_mips(errno); + { + int ret = -1; + + GET_TARGET_STRING(p, gpr[4]); + if (!strcmp("/dev/stdin", p)) { + ret = 0; + } else if (!strcmp("/dev/stdout", p)) { + ret = 1; + } else if (!strcmp("/dev/stderr", p)) { + ret = 2; + } + FREE_TARGET_STRING(p, gpr[4]); + + /* FIXME: reusing a guest fd doesn't seem correct. */ + if (ret >= 0) { + gpr[2] = ret; + break; + } + + semihost_sys_open(cs, uhi_cb, gpr[4], 0, gpr[5], gpr[6]); } - FREE_TARGET_STRING(p, gpr[4]); break; + case UHI_close: - if (gpr[4] < 3) { - /* ignore closing stdin/stdout/stderr */ - gpr[2] = 0; - return; - } - gpr[2] = close(gpr[4]); - gpr[3] = errno_mips(errno); + semihost_sys_close(cs, uhi_cb, gpr[4]); break; case UHI_read: - gpr[2] = read_from_file(env, gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_read(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_write: - gpr[2] = write_to_file(env, gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_write(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_lseek: - gpr[2] = lseek(gpr[4], gpr[5], gpr[6]); - gpr[3] = errno_mips(errno); + semihost_sys_lseek(cs, uhi_cb, gpr[4], gpr[5], gpr[6]); break; case UHI_unlink: - GET_TARGET_STRING(p, gpr[4]); - gpr[2] = remove(p); - gpr[3] = errno_mips(errno); - FREE_TARGET_STRING(p, gpr[4]); + semihost_sys_remove(cs, uhi_cb, gpr[4], 0); break; case UHI_fstat: - { - struct stat sbuf; - memset(&sbuf, 0, sizeof(sbuf)); - gpr[2] = fstat(gpr[4], &sbuf); - gpr[3] = errno_mips(errno); - if (gpr[2]) { - return; - } - gpr[2] = copy_stat_to_target(env, &sbuf, gpr[5]); - gpr[3] = errno_mips(errno); - } + semihost_sys_fstat(cs, uhi_fstat_cb, gpr[4], gpr[5]); break; + case UHI_argc: gpr[2] = semihosting_get_argc(); break; From patchwork Tue May 3 19:48:29 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Richard Henderson X-Patchwork-Id: 569013 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9808994map; Tue, 3 May 2022 13:52:20 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw9Cr2rJXOaweccxWoNjI8rDln6+ZcBYNnSwhQrpGRAcSC0w+iWMVNJhwFggCXjgwnEc7ch X-Received: by 2002:a05:6214:c2e:b0:45a:95ff:3391 with SMTP id a14-20020a0562140c2e00b0045a95ff3391mr7127623qvd.91.1651611140396; Tue, 03 May 2022 13:52:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611140; cv=none; d=google.com; s=arc-20160816; b=N3WSWdk8h6doasitBp9aVo1g70XkJj3kjttpe473c2WudbzDB43KUr0C1/NzAm79/A K3p822Riux4pZZXMNdH1ly8VKx5wHZ4s/fOLtVkokoUF2ubnyEk2WJKFM8/R3m2GNGxE GmHEuVZ0N3P+tvbwQaN0t7VcDja4eo2DbMINykiuiUzdMyzdCu2oUUxtH3ozvGzBJ7YJ eAPoN5zvqhziHnuiTAPSs2knzMiZFO8X3R//jtxyYjAoQs9xxOqoOSqtNUjB2ZbEXr1Y TRc9ZMK2UoaIotuN7tSWE42/+v757GvONvNL5SVo364s9hlH4jIHiQ3biTIWSgSPX//N /7KA== 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=wshqblo3GajKvQ1u/4/sDSAzNuqAbf17z7w/qZv2wdo=; b=rXAmJHAIMKX0U9xssvl55ct/81YCEAB9XxY0pjzk0HDK7Gs+BlIu0313fkQ5qw3np4 Wo3ooLUfrbLYMj/k5IVH2Lz3cy4ewhreroUustOK047voelPMZ0cniytrqZM5D3NXo/m RQe2ochkpNs7c8F32vuZ2WYyQ+XFZ0nQLqa/tmdM3B0w6FEe0v/p7wQO/Vg884CgD1lw KqiKbhWxIXYooBDYFBaKYFq9lTjCLZi3WOhxZKL7NuhBOia41NkC5iNrRQ169vmGtHIg XtSVyY4dI0Cxq4LuF98lOmMsuk2lo+YQM3D5C/mVlNie3/2+RV4V5jV8pbRTS5hg222V 7N2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=FeZKgubc; 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 c20-20020ac85a94000000b002f3b5e3d303si37907qtc.485.2022.05.03.13.52.20 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13: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=FeZKgubc; 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]:60344 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzVL-0005IJ-Th for patch@linaro.org; Tue, 03 May 2022 16:52:19 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40452) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZk-0000NZ-8K for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:48 -0400 Received: from mail-pl1-x62e.google.com ([2607:f8b0:4864:20::62e]:39814) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZi-0006MY-Hk for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:47 -0400 Received: by mail-pl1-x62e.google.com with SMTP id x18so4707153plg.6 for ; Tue, 03 May 2022 12:52:46 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=wshqblo3GajKvQ1u/4/sDSAzNuqAbf17z7w/qZv2wdo=; b=FeZKgubc1srbehQEOrBWHTwxekJuen5Oxtvob3HnAB4508UBCxM7LKPAKOJJlTaXu8 eny8JdilcN9r70kBPxA/Al3B1w0kWX+IeKk0D20em90Da/ZkSXjkF4g4CJu8of7A04FE Iht1TBTDz13tQZleOxqivqM+fiQu5vvZ/V4rynXtfn/+ise9/cH++4bG99NIdoWHkNpc crKGv9eY+pbFzsQUwM26trkpidXasvfi381WKL3Oy3aXgCnWVzcOupmUHx8rkZ5J8T71 dc268uUAxPD0UMDoyu0fz2C+rsuL20yP1YdbmJ58LdUnx59uAP2cIFd43U7jlzPo5t8L 9tgg== 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=wshqblo3GajKvQ1u/4/sDSAzNuqAbf17z7w/qZv2wdo=; b=aaUO3rKBxCR4n1LHVWqJxJTW6f9LiS4hDEO0Yq6Fw544G68r9kD8/bjIzTNmsokDW0 aStqt2CyNae1HjhrK1pkVjy5qmy2sDZDZOmfHwXJIqfGYMYPNuIGX+sqazvhbZo+SZBa epsyz7BHzpx6UCWecL1BBsJUlcUiq2gmzdn5YGn6U1dtpno8kbwirWFTNHa5VCS7dNX8 1L6QMLtGMp3w1C0ZaSlQKn99K7hNBPPfFiHBtn8NrjbTAzSRx0Fj+rsO6vjkjN1hSI7E aAnDSX4INAeBdQl97h2NxJDwB7QoAjz2oWSkha8ncx6LquR3DgytHF6ThTeY1hEKZsHI dXZg== X-Gm-Message-State: AOAM530L8xu01zK/Z5ufROhOqNBcs/FkxPbZ6koKfj1A8BOX9Q+ezD/C MljtzrJOw8OV8v89yjg5+hq4kJ+Lx0OCbQ== X-Received: by 2002:a17:90a:e7ca:b0:1dc:4aeb:be5d with SMTP id kb10-20020a17090ae7ca00b001dc4aebbe5dmr6393921pjb.185.1651607565294; Tue, 03 May 2022 12:52:45 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.44 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:44 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 60/74] target/mips: Avoid qemu_semihosting_log_out for UHI_plog Date: Tue, 3 May 2022 12:48:29 -0700 Message-Id: <20220503194843.1379101-61-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::62e; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x62e.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 semihost_sys_write and/or qemu_semihosting_console_write for implementing plog. When using gdbstub, copy the temp string below the stack so that gdb has a guest address from which to perform the log. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 52 +++++++++++++++++++++++------- 1 file changed, 41 insertions(+), 11 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 2704177a95..d8c9be5e9f 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -310,20 +310,50 @@ void mips_semihosting(CPUMIPSState *env) } gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; + case UHI_plog: - GET_TARGET_STRING(p, gpr[4]); - p2 = strstr(p, "%d"); - if (p2) { - int char_num = p2 - p; - GString *s = g_string_new_len(p, char_num); - g_string_append_printf(s, "%d%s", (int)gpr[5], p2 + 2); - gpr[2] = qemu_semihosting_log_out(s->str, s->len); - g_string_free(s, true); - } else { - gpr[2] = qemu_semihosting_log_out(p, strlen(p)); + { + target_ulong addr = gpr[4]; + ssize_t len = target_strlen(addr); + GString *str; + char *pct_d; + + if (len < 0) { + report_fault(env); + } + p = lock_user(VERIFY_READ, addr, len, 1); + if (!p) { + report_fault(env); + } + + pct_d = strstr(p, "%d"); + if (!pct_d) { + FREE_TARGET_STRING(p, addr); + semihost_sys_write(cs, uhi_cb, 2, addr, len); + break; + } + + str = g_string_new_len(p, pct_d - p); + g_string_append_printf(str, "%d%s", (int)gpr[5], pct_d + 2); + FREE_TARGET_STRING(p, addr); + + /* + * When we're using gdb, we need a guest address, so + * drop the string onto the stack below the stack pointer. + */ + if (use_gdb_syscalls()) { + addr = gpr[29] - str->len; + p = lock_user(VERIFY_WRITE, addr, str->len, 0); + memcpy(p, str->str, str->len); + unlock_user(p, addr, str->len); + semihost_sys_write(cs, uhi_cb, 2, addr, str->len); + } else { + gpr[2] = qemu_semihosting_console_write(str->str, str->len); + } + g_string_free(str, true); } - FREE_TARGET_STRING(p, gpr[4]); break; + case UHI_assert: GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); printf("assertion '"); From patchwork Tue May 3 19:48: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: 569025 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9819268map; Tue, 3 May 2022 14:07:35 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxds/jxlBKrAQjNKdetES5+0vwh+nmCZrimWFbFCfNOEe2NIIAnvMkmSXmnB9/4dhu4+47r X-Received: by 2002:a05:622a:c4:b0:2e1:cb5b:9b5c with SMTP id p4-20020a05622a00c400b002e1cb5b9b5cmr16785704qtw.69.1651612055202; Tue, 03 May 2022 14:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612055; cv=none; d=google.com; s=arc-20160816; b=KR9vu1Xqwv8MwOgLNwvh3cnuoEWAuxIPwVX6Hxvw+Q6XXtV8q7qz7f3t5ICYRwnp4J aeJWSEWRNyZ+k60nfoB4HZC4VPt7vNYkps0UejYxnMaQXeV58DrzLswo4j1ASpqqEigJ UMqQpyEHgTcCQs1AixROKiAvTpw75KWxI0O2k6fTtzjyPKJ7yl3QnSd1crm6QME4pKDS leZrc7bt+NKc5e+vIJAPBxBqG1nynITyeGqQmlrZ459mKpsKYuIxn2T816iESNbIsA82 XpLdcOgTyvJcOtRR0kIvkXDUFMXCJnck+ZS3Whwwa5JleOZHO52D74MQQXetG7uUq++J c+Vg== 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=0KmR0I9MQL8sMij82tj+TGbywtXC8SOF01Vq62VNOXc=; b=DehN7MoUoOT5Leh0Lust7VGug3pN/N4nOAa763JVnk1dTc1BMpqLydx5Q8iwq1E2vr vKJM9x4S3hweEiSUsufpm6lZhQfmLvJwkIJ4V6hvbtoG5/uZsBvMOQhe1UJl0EIVxKby p4kay/uXfrf8oqpjtKSMSokDfMsc1yu32AtYjgTRVjunys3YVn2eDbV8XMv/gIhoKsFM bItHmZyDe1kYX32Luet9Qzst1yEf2T5oYIN9WRolmSZ930TjVUkBmP+61zaHCSP21Ny2 6J0MNALgZ1H6sm47MT/VmjVBx3AMHFsCkVnP7KFmLzjt1SkxyDN3wZq1rPg9s1M+0VVE K0Nw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bj978LCY; 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 bi36-20020a05620a31a400b0069f8a2bcdc5si6318287qkb.94.2022.05.03.14.07.35 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:07: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=bj978LCY; 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]:57468 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzk6-0004dL-NC for patch@linaro.org; Tue, 03 May 2022 17:07:34 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40482) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZm-0000Xo-6M for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:50 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:41905) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZk-0006Mt-Ic for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:49 -0400 Received: by mail-pj1-x1034.google.com with SMTP id z5-20020a17090a468500b001d2bc2743c4so2917140pjf.0 for ; Tue, 03 May 2022 12:52:48 -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=0KmR0I9MQL8sMij82tj+TGbywtXC8SOF01Vq62VNOXc=; b=bj978LCYcEKh12QBdn3r1wS7KagW1xp0uHsYD9BxBUJLXw83ImhdoDrGcndFTpFRaD VLIRHpU5DB9ImBOWN8yjes7VW/fYNDxR/toHvgiPNA79G3U0o9dyilUZTixnY2Ln8KZN p/Z9e/drfrwh8YGIbIuQMk4M7NYZVhfgBcCL0pCgcEpaQW5Zwpbt/MMfCdBfTCw6IJuS sQS02IjtvUeOGyYO5aBvZd8ygljdQWuERD7KPsvzaAgq9zduBheW7W16Edg0IBpAjB49 BIEjEegpmzWwiIA1k+/8E75NI3XMRp7wkw0seJY6KU3Dmh71lMO2QoEx1m3c8hALWL6J 9D7w== 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=0KmR0I9MQL8sMij82tj+TGbywtXC8SOF01Vq62VNOXc=; b=lBgWhiKwu0OlpmkV0qVSvR5TRYC3+RvnWxgGONAExV90eyir1lgCeb/b0GiytIjy3I 8/byjARGg7Z1BueBCFUcjNNdeSLOORkUTfcXbImQxe/6y+ms2NftMBh4nQB0QFoQKFCq Qg/uTNt9jcHuchXpH4ZzDsaelzLKQGb+AxUT+1REC5xEJFHkmreBo5bWj0i/PMq2Q8XR yRD2FzisukcW2PYqhheJsga4t3QLfeWLOYcSjvCeREZbloCEBeGt5AinKGoXiptjLI8H UM526Qy/6sp6KBVBTOfKUcDDsOBGg9LlURhzg5mo3dkxhzKQvWyfkqanIaE0KGxEeQnV 5uMQ== X-Gm-Message-State: AOAM531m+pft/DquVNw8y0jcG9LD3PFgHILLR55WsOLlcxeH7oyHrkUD xYwqISd/5USB6nMc//z7s1HYyVSzdRYq/Q== X-Received: by 2002:a17:90b:704:b0:1d7:367a:f16b with SMTP id s4-20020a17090b070400b001d7367af16bmr6541124pjz.197.1651607567332; Tue, 03 May 2022 12:52:47 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.45 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:46 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 61/74] target/mips: Use error_report for UHI_assert Date: Tue, 3 May 2022 12:48:30 -0700 Message-Id: <20220503194843.1379101-62-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::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" Always log the assert locally. Do not report_fault, but instead include the fact of the fault in the assertion. Don't bother freeing allocated strings before the abort(). Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 39 ++++++++++++++---------------- 1 file changed, 18 insertions(+), 21 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index d8c9be5e9f..df1747aafe 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -221,18 +221,6 @@ static int copy_argn_to_target(CPUMIPSState *env, int arg_num, } \ } while (0) -#define GET_TARGET_STRINGS_2(p, addr, p2, addr2) \ - do { \ - p = lock_user_string(addr); \ - if (!p) { \ - report_fault(env); \ - } \ - p2 = lock_user_string(addr2); \ - if (!p2) { \ - report_fault(env); \ - } \ - } while (0) - #define FREE_TARGET_STRING(p, gpr) \ do { \ unlock_user(p, gpr, 0); \ @@ -243,7 +231,7 @@ void mips_semihosting(CPUMIPSState *env) CPUState *cs = env_cpu(env); target_ulong *gpr = env->active_tc.gpr; const UHIOp op = gpr[25]; - char *p, *p2; + char *p; switch (op) { case UHI_exit: @@ -355,14 +343,23 @@ void mips_semihosting(CPUMIPSState *env) break; case UHI_assert: - GET_TARGET_STRINGS_2(p, gpr[4], p2, gpr[5]); - printf("assertion '"); - printf("\"%s\"", p); - printf("': file \"%s\", line %d\n", p2, (int)gpr[6]); - FREE_TARGET_STRING(p2, gpr[5]); - FREE_TARGET_STRING(p, gpr[4]); - abort(); - break; + { + const char *msg, *file; + + msg = lock_user_string(gpr[4]); + if (!msg) { + msg = ""; + } + file = lock_user_string(gpr[5]); + if (!file) { + file = ""; + } + + error_report("UHI assertion \"%s\": file \"%s\", line %d", + msg, file, (int)gpr[6]); + abort(); + } + default: error_report("Unknown UHI operation %d", op); abort(); From patchwork Tue May 3 19:48: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: 569004 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9803116map; Tue, 3 May 2022 13:42:22 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzZIy7lT4BjUolaU7UxSkbS5HSOfNWbN59F15BaIjTEfemyQwDX6ofL7Uxld7abVpM2Wfxt X-Received: by 2002:a05:620a:470d:b0:69f:b40e:4980 with SMTP id bs13-20020a05620a470d00b0069fb40e4980mr13453494qkb.18.1651610542869; Tue, 03 May 2022 13:42:22 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610542; cv=none; d=google.com; s=arc-20160816; b=N1p78yGZaoUvDgwC/4s3zVkSkzcfR4U0+/HT7ihmK0xZsSb3qeIfd1Cg4RJf9bDXLM Ta8ZsIo2W4RPeTb9cYUMmdbhQxqI1viOQJIv9hzga/4R8ZRMfz4o6IH3f7wNZb4sTnCd BzYl6IX6TEuY/LyXNZ2c+lvMRuesldLrFVsVIe/DuQ5xQfOzfDK8TqAiwEQBLHlt1R3w 6D9f155thtxKnRE1R4RO7D1F5GuCSSI3tPivJDHykP5VUKOZvFjgxcUpaxYu30Kh2uBQ RaRVoCRvZK9Aq7+ifixXdfqYOc0cMFEk5GP416hlFKqbxwCdZVXKO+YdQfC/QaG0Z6mf 46sg== 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=7hrYGm6CB5wl83BARKhSg3dxjfTTX0HLuXW9+o58cZc=; b=ynnsN6p0eLZHSCpx3PE6yY8fVhClUbOW/wEZ43PWqVKDhvleQBz0e6ZPHHHDwht5t9 KfF9oE2nTHGKVntiSPb1jDkVKs3sHPtHSQ9kmEClOKSPeq8o7EaCTfS0un4a/emBZ1lR ymAoMcom/huPg1ibsH/Uir69Rg9VzLNW5k230a9Y/ewjvdrZz+8RWl7o2W8BMZ5Iga3i 5YwPGRAP02X3OnwtSvaTkuGBQzwTBo8+tDJ/mJM4pNTW16lIXKByYABw4iNjWzauoLGE gI/TS50pX4Ebx5MBNKK3W9JgoEuav+9+X+cMTg6SU+MzJH0eFgYCI76lUQnBW5Gnzvnn Dz+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="an/9bH1s"; 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 bq39-20020a05620a46a700b0069e7a0f15d1si8912709qkb.29.2022.05.03.13.42.22 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:42: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="an/9bH1s"; 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]:41648 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzLi-000663-D9 for patch@linaro.org; Tue, 03 May 2022 16:42:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40488) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZm-0000ZJ-Li for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:50 -0400 Received: from mail-pj1-x102d.google.com ([2607:f8b0:4864:20::102d]:36739) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZk-0006Lz-VJ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:50 -0400 Received: by mail-pj1-x102d.google.com with SMTP id gj17-20020a17090b109100b001d8b390f77bso3236773pjb.1 for ; Tue, 03 May 2022 12:52:48 -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=7hrYGm6CB5wl83BARKhSg3dxjfTTX0HLuXW9+o58cZc=; b=an/9bH1s1Sd2UKZccy/vCK9LjN63Y5lWUvFKNK9c7eakLmlMK/zcLoAan6KiX4/UoW /WEFmYOFMG9kUFf0njFTv54ghU4az9F6SZYr99TAbWzusTzu/ARsuwEL2Kb2jAqF94uN 22mqJ5hBzW/QIMydjGVnPU6H6Y0SvzL9L9ekrqVOtFfHmTMQq48Tejed7754G4Wcz3yo tnTA+3rndlWP9rkea5M5uORYiQnCWj/1REeQnqyHVZphOC+TbJ4D6x/Vts1/l49s+5Ay FgDHPv2SVnUMLxKkrO/s1zpYyKTj3MdIR9QRnmztyYrsoqpzlJBPOLAzk2PimqKuAli3 //Cg== 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=7hrYGm6CB5wl83BARKhSg3dxjfTTX0HLuXW9+o58cZc=; b=iN+rnx6UHbRMLf6U4NoBQhqFGWT4qEAKySUNVIhYsnARsoUT+19HEeNteNfm27GTVn xsDKrGVsfjNA+AQCJ2Mbw9FXzgTqPz5dFw9TAzjjEe4bBkBct1aoDz2D2cYvKnvceCZv o3Jbv3m97dXAYfDX+frP87BidRcTtNnXtUGsmzHsvXY3Mf3Rpo6dgXqTsfpB1ieapGet 1Tf9qcvlRKyvqMfFxqOZqduKP9aopuk4DjdoAZl5eOyd0lLll+oQhbFZ+fiwauXXtTcn T94JYoE0ApzCeFzXooQvwpTgMAe2X6tX8t/fvaPIQGtD7okEW55zE8NSadkazRAMVPIm 00oQ== X-Gm-Message-State: AOAM533B1yDc19Vy4ttrLcJjQWlMxUAQWprtoASyhi71ZxgumUCnHwBE d+SIUb7XOwVfUW84YvvklxUusCpcuaNMiQ== X-Received: by 2002:a17:90b:33c8:b0:1d9:9023:1103 with SMTP id lk8-20020a17090b33c800b001d990231103mr6394643pjb.26.1651607568148; Tue, 03 May 2022 12:52:48 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.47 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:47 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 62/74] semihosting: Remove qemu_semihosting_log_out Date: Tue, 3 May 2022 12:48:31 -0700 Message-Id: <20220503194843.1379101-63-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::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" The function is no longer used. Signed-off-by: Richard Henderson --- include/semihosting/console.h | 13 ------------- semihosting/console.c | 9 --------- 2 files changed, 22 deletions(-) diff --git a/include/semihosting/console.h b/include/semihosting/console.h index 61b0cb3a94..bd78e5f03f 100644 --- a/include/semihosting/console.h +++ b/include/semihosting/console.h @@ -40,19 +40,6 @@ int qemu_semihosting_console_read(CPUState *cs, void *buf, int len); */ int qemu_semihosting_console_write(void *buf, int len); -/** - * qemu_semihosting_log_out: - * @s: pointer to string - * @len: length of string - * - * Send a string to the debug output. Unlike console_out these strings - * can't be sent to a remote gdb instance as they don't exist in guest - * memory. - * - * Returns: number of bytes written - */ -int qemu_semihosting_log_out(const char *s, int len); - /* * qemu_semihosting_console_block_until_ready: * @cs: CPUState diff --git a/semihosting/console.c b/semihosting/console.c index cda7cf1905..5b1ec0a1c3 100644 --- a/semihosting/console.c +++ b/semihosting/console.c @@ -38,15 +38,6 @@ typedef struct SemihostingConsole { static SemihostingConsole console; -int qemu_semihosting_log_out(const char *s, int len) -{ - if (console.chr) { - return qemu_chr_write_all(console.chr, (uint8_t *) s, len); - } else { - return write(STDERR_FILENO, s, len); - } -} - #define FIFO_SIZE 1024 static int console_can_read(void *opaque) From patchwork Tue May 3 19:48: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: 569021 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9814584map; Tue, 3 May 2022 14:01:57 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz3YqeRPN8HUv8ggXI2bswJFQq4ADMWG+QpQewB8u9YGO6Ex0MKpvQYPkvHH5pTHjoMqod6 X-Received: by 2002:a05:620a:c43:b0:67d:f048:f5e9 with SMTP id u3-20020a05620a0c4300b0067df048f5e9mr13642341qki.281.1651611717307; Tue, 03 May 2022 14:01:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611717; cv=none; d=google.com; s=arc-20160816; b=oEnbhJoRESVE/3ddDdfA2s6G8cSMMeTuoV1ic7zO6o9+b84ML/OfKelP3ejnqaLqug jwyv+p3ANV01gKCCboSh+/RiEz6ML/eaRRFr/PkZ4RBhTJlfjdcemzFlnf3xitMHXrH2 ybB8SZPsJr7+sgu/1BFoQOmMszf+2BRJSvfjuvf3GPvf5sBHD5Li4AQ6eP0a7PIqJbmr /+dyOAbeUtQUfC23lGMDFFlA3jMjdMiad86xWd2dv4byko9GjfRe7UrIz0T8mjYeKY2Q hjrbrQpk5yxWEhGM8NyAZUhabu7yod2Tmd71J3oiB7GJOFlbM1oZc9Mgoyys+baGJxV/ BIrw== 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=8TFArIwYtOuJWeu7AXv9g90fK/0fq597uhKnECoQyCg=; b=zlJTsqZ+2bkLVg0ykMMnL5qUEbVXwvd/TKlGP7vpp1cZ38LEwGGCIKOoCzjzi/KWu9 tCdtx2VetAE9gNcwvsrHRv1y8Cx7ASkvyj1SHmrvnYc2+lhX5GVn80rdlEpO0d3c6iF+ pi1mJc7sYffpd5TWrYCFydTcUA6MzoL5Z+IyKpLdCctQ8vCv6jdSQjD89exWD+u/fNxb iaJgkvjI6/451lzQ1XfNLk0N2jOINweuiXvEbZsSFsY44Wws2Z5DvzXFWz+YZUCCMv8h MC9Dci+YiS2ec2aHBjV8xwYNCuWytEaS+8B0C2qgkmyEvizM9ZWt1Up3SFGLBy/OHx9i R7MA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=GbXm4OHg; 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 s18-20020a05622a179200b002f3a99c0446si2771067qtk.320.2022.05.03.14.01.57 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:01: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=GbXm4OHg; 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]:48222 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzee-0002un-O6 for patch@linaro.org; Tue, 03 May 2022 17:01:56 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40518) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZo-0000fh-1B for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:56 -0400 Received: from mail-pg1-x529.google.com ([2607:f8b0:4864:20::529]:34420) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZm-0006N4-CI for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:51 -0400 Received: by mail-pg1-x529.google.com with SMTP id j70so3893402pge.1 for ; Tue, 03 May 2022 12:52:49 -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=8TFArIwYtOuJWeu7AXv9g90fK/0fq597uhKnECoQyCg=; b=GbXm4OHgEzCA0aL5AzcAAvITrm+AKr27N1WCAdTZQ0w5qwy5M29jgYGyseh8BIaOlu lX/VLcA2xLsSzEVe4vlZ0/UNB2nbfngPPe5IDXoyybUk6Z2D5Q/ZoklFshXeAzmuykH7 bN0Stfg2ConXMcfNPVrSdbC7+97nnbbSJNw7Yge67RDfC29mRJyxxh73YoXUwqvQaITf Ds8A/3Sucu2V7Vbar0oMQEdIsy4ZL39fhBto2GMJ+y+WXwRZQNr4bJ32P/d7znVbIzU5 E7Iw5XKBvf1J2AK6OOT5i67OmQwIIvVlgTRtqzyqkwrzFBxlgqkH7T0/qnhwqsz/yVnw 1MAQ== 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=8TFArIwYtOuJWeu7AXv9g90fK/0fq597uhKnECoQyCg=; b=li3+cU7/wSA6/zbGV9He7mJoqE8k4zibDk2hdYV5Dy7CRUVao5gGlk7XPMOY6AoRRs OqyzByKtqKZrCIr8Zzvvpgvf5Nd1xBv4xp+4enW5qdIx9l4go/X1Y7zeBoOrzEdWBL/H 5sG6kyjuX8MQ6X232dhXeihqDorhTU7AK0927dCn4DTWkQvcdQgfEYgwxqCWhVnFJF8X HAatwc8+ru9pL0JWNPOevtU57LJACr6l3OUIDo56y4WmvOI+iHHkm7SM212PoYVCpAg/ OUTrEVSDwAn6ljSFhT4wH/yjtpDR8AqmD4ei4wDzLz0YM0MzgY1JGLFWb3hamaH8OeF0 iJOQ== X-Gm-Message-State: AOAM531VcgnTDnUS/YydtXkxtf3AqswtvNtEseEkwqVDQmvCZ/EJVH7p Hq5i5DPmTweLfUJuwEGiThwOSh4Ga5yaDQ== X-Received: by 2002:a63:444f:0:b0:39d:3aa5:c9f0 with SMTP id t15-20020a63444f000000b0039d3aa5c9f0mr15185449pgk.363.1651607568938; Tue, 03 May 2022 12:52:48 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:48 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 63/74] target/mips: Simplify UHI_argnlen and UHI_argn Date: Tue, 3 May 2022 12:48:32 -0700 Message-Id: <20220503194843.1379101-64-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::529; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x529.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" With semihosting_get_arg, we already have a check vs argc, so there's no point replicating it -- just check the result vs NULL. Merge copy_argn_to_target into its caller. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 44 ++++++++++++++---------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index df1747aafe..0f5b509ce2 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -198,21 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) uhi_cb(cs, ret, err); } -static int copy_argn_to_target(CPUMIPSState *env, int arg_num, - target_ulong vaddr) -{ - int strsize = strlen(semihosting_get_arg(arg_num)) + 1; - char *dst = lock_user(VERIFY_WRITE, vaddr, strsize, 0); - if (!dst) { - report_fault(env); - } - - strcpy(dst, semihosting_get_arg(arg_num)); - - unlock_user(dst, vaddr, strsize); - return 0; -} - #define GET_TARGET_STRING(p, addr) \ do { \ p = lock_user_string(addr); \ @@ -285,18 +270,31 @@ void mips_semihosting(CPUMIPSState *env) gpr[2] = semihosting_get_argc(); break; case UHI_argnlen: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + gpr[2] = s ? strlen(s) : -1; } - gpr[2] = strlen(semihosting_get_arg(gpr[4])); break; case UHI_argn: - if (gpr[4] >= semihosting_get_argc()) { - gpr[2] = -1; - return; + { + const char *s = semihosting_get_arg(gpr[4]); + target_ulong addr; + size_t len; + + if (!s) { + gpr[2] = -1; + break; + } + len = strlen(s) + 1; + addr = gpr[5]; + p = lock_user(VERIFY_WRITE, addr, len, 0); + if (!p) { + report_fault(env); + } + memcpy(p, s, len); + unlock_user(p, addr, len); + gpr[2] = 0; } - gpr[2] = copy_argn_to_target(env, gpr[4], gpr[5]); break; case UHI_plog: From patchwork Tue May 3 19:48: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: 569024 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9818697map; Tue, 3 May 2022 14:06:43 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxt2DwKDdTzjyfH1d4zcZo88ncRETvHv+IogvpF8U296cp0RC3Oz070LcLsLrZjL/VGFDt6 X-Received: by 2002:ad4:5cc8:0:b0:45a:8a4c:9d1e with SMTP id iu8-20020ad45cc8000000b0045a8a4c9d1emr10004247qvb.97.1651612003119; Tue, 03 May 2022 14:06:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612003; cv=none; d=google.com; s=arc-20160816; b=AyH3z5p+Y6mP9CvljPlNdOEX4mQESdlBHH8uNWYKFUe/fqQGIW/aqSGsIhSsLnfxJ6 qXRSn0AtcwQVi++A199/rPFV+fIWIr8NQeHkZmmYkIJLp0rKpCuzx61WD5C4YyXXnRTL rJDdmJ9jlRdq+TftT8DRQMKEHV1gKkmmjlQwYErWuuh2NcqSmCUgSgkzSlP8nI7BAc4Q ABrS3G81+Izd6dNE4sF4oT1VTytchQnw2h9h0xKxQanxr2cLzffczcqEyZqRULBHqAUd MdN5TkxVJaR/Odv+WuwVs5f3i6cHEFpxUOVow+von9ctb+63JfBbAOWjcMzFRycJNPwu d9rw== 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=b0mtvFcJe6Lm8uLKbhgRHasfTLJl7kkdx3x7RgBno1I=; b=QaYCpLuO2l8kaXu2+ucsuT8HTwnzUm7mxACcDEB9LI/fHQtUNdIik+o+zZjHS0aeUY UIufHK9GJaf8/fqsfTyvq4ooyMGyz4cy85TKFCFeHD+zUTwW44byVJz1engWPYHJHXjM HH+MVJkjAYCLECo4Q1UGLaFNx1cFyisLEbF2dqhE2F0WlDPN9RN0iSxXP8hd+ULDCnQD iCFvIqpnmYJPXBHw4zZtZmZumbH5SsFLZ7IiQ6TIPxx/j1wN3S1V9h63r1iQyUNWkrY3 UEuKbuEvL0rX91395oa93+ZIXSJQQOcK46/Jj1azGPlUpFF05hPpX53+O+JUeQ7OR69h Q+ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Cm0xXwG9; 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 ed3-20020ad44ea3000000b0045a87bf9ba1si4782390qvb.265.2022.05.03.14.06.43 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:06: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=Cm0xXwG9; 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]:56260 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzjG-0003J4-Lh for patch@linaro.org; Tue, 03 May 2022 17:06:42 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40536) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZp-0000fk-OP for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:57 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:44737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZn-0006NI-BW for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:52 -0400 Received: by mail-pj1-x102f.google.com with SMTP id m14-20020a17090a34ce00b001d5fe250e23so2882329pjf.3 for ; Tue, 03 May 2022 12:52:50 -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=b0mtvFcJe6Lm8uLKbhgRHasfTLJl7kkdx3x7RgBno1I=; b=Cm0xXwG9vnUzbCs4MuvOXR3q1/b9UnFyWNoYB7zar7GExUZR6h1+nCpu5mUd0la25f +yOSyfZSGe6FVdSaTkQCfavtUIJaQ3akU4XKRqchvk7Hnastoc25CaPbtZr0ENbPBWQU gjuaXniAjav9tl4UE+3/S3p1B/RqpXOqI20x9D78I958zA7bjnTwDfJ6HHesj9B/xhMm c4WHbDBNrcs0q8WzrtEl6PjKlLzj0XQC2ZZzK0SdvUbAtemWlV2MjstfkzMtE3GKO4Gc a2gwI26Bq2YnvV9Fez0M9pZvTzX8Fm1wQJ6FcTHktbWOrUMoZmQhmcThMn8DPvUXwsKt pZLA== 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=b0mtvFcJe6Lm8uLKbhgRHasfTLJl7kkdx3x7RgBno1I=; b=L6WUHqLRBkPghgKnFBkOJIRC23Bw7i6jQFzGTXxUtlqYMV0URhcYnmdl2/tk50yqR3 mSE8N/v0uTW4gdYJZRxPz//R0VhcMQ0gIV19Rim0dQJCOUEpZgJRgSNG5wYChQhdX21u id77M306JR0/HWJx+1qsktoGZsE2ksHWoN6X4azHDfnA1zOFuNBrs9IhCOEgU+3KGaEe eSPYhWaMDGlaJFzzAAyOla+dl/dCRmlV5WtMU3jNFmxaUig8rIrxP/nekZ66eD0SzyAl vf/iYP57FA6OroIyueVOFb1t1FfjGSjjuHN3DQuV7RnnTfbqaCkexRFM9U5JgZpYL294 axQw== X-Gm-Message-State: AOAM533muhAazbWYQx8a2Gf+3IXmpBu8PhodUHTKPQIOo40tbOrpzv1g VD++oQh7ZLDjc1P+potxNKDta5eYTDhz5A== X-Received: by 2002:a17:90b:388c:b0:1dc:542b:a596 with SMTP id mu12-20020a17090b388c00b001dc542ba596mr6500031pjb.76.1651607570053; Tue, 03 May 2022 12:52:50 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.49 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:49 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 64/74] target/mips: Remove GET_TARGET_STRING and FREE_TARGET_STRING Date: Tue, 3 May 2022 12:48:33 -0700 Message-Id: <20220503194843.1379101-65-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::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" Inline these macros into the only two callers. Signed-off-by: Richard Henderson --- target/mips/tcg/sysemu/mips-semi.c | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) diff --git a/target/mips/tcg/sysemu/mips-semi.c b/target/mips/tcg/sysemu/mips-semi.c index 0f5b509ce2..a3d5267399 100644 --- a/target/mips/tcg/sysemu/mips-semi.c +++ b/target/mips/tcg/sysemu/mips-semi.c @@ -198,19 +198,6 @@ static void uhi_fstat_cb(CPUState *cs, uint64_t ret, int err) uhi_cb(cs, ret, err); } -#define GET_TARGET_STRING(p, addr) \ - do { \ - p = lock_user_string(addr); \ - if (!p) { \ - report_fault(env); \ - } \ - } while (0) - -#define FREE_TARGET_STRING(p, gpr) \ - do { \ - unlock_user(p, gpr, 0); \ - } while (0) - void mips_semihosting(CPUMIPSState *env) { CPUState *cs = env_cpu(env); @@ -225,9 +212,13 @@ void mips_semihosting(CPUMIPSState *env) case UHI_open: { + target_ulong fname = gpr[4]; int ret = -1; - GET_TARGET_STRING(p, gpr[4]); + p = lock_user_string(fname); + if (!p) { + report_fault(env); + } if (!strcmp("/dev/stdin", p)) { ret = 0; } else if (!strcmp("/dev/stdout", p)) { @@ -235,7 +226,7 @@ void mips_semihosting(CPUMIPSState *env) } else if (!strcmp("/dev/stderr", p)) { ret = 2; } - FREE_TARGET_STRING(p, gpr[4]); + unlock_user(p, fname, 0); /* FIXME: reusing a guest fd doesn't seem correct. */ if (ret >= 0) { @@ -243,7 +234,7 @@ void mips_semihosting(CPUMIPSState *env) break; } - semihost_sys_open(cs, uhi_cb, gpr[4], 0, gpr[5], gpr[6]); + semihost_sys_open(cs, uhi_cb, fname, 0, gpr[5], gpr[6]); } break; @@ -314,14 +305,14 @@ void mips_semihosting(CPUMIPSState *env) pct_d = strstr(p, "%d"); if (!pct_d) { - FREE_TARGET_STRING(p, addr); + unlock_user(p, addr, 0); semihost_sys_write(cs, uhi_cb, 2, addr, len); break; } str = g_string_new_len(p, pct_d - p); g_string_append_printf(str, "%d%s", (int)gpr[5], pct_d + 2); - FREE_TARGET_STRING(p, addr); + unlock_user(p, addr, 0); /* * When we're using gdb, we need a guest address, so From patchwork Tue May 3 19:48: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: 569027 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9822102map; Tue, 3 May 2022 14:11:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyGYP/69vnizn9NX4fy9gCBsudkiU2InWFpSPnR7ukznVCIzhVBOxPCYDl7gNjbrjOK2gd7 X-Received: by 2002:a05:620a:31a0:b0:6a0:983:feab with SMTP id bi32-20020a05620a31a000b006a00983feabmr2277257qkb.507.1651612288603; Tue, 03 May 2022 14:11:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612288; cv=none; d=google.com; s=arc-20160816; b=MUlaPScX9KyFDGPompEn960KVMwUWsvZGWhrZBlhz9+kZN0DQ8gaQ4scgv8z9MEqcV AyW+bGX6bNihBMpyHWpKOIzEMh9+i1+m/kUdKHuFc95qG5g8xLL4sX2rviM7Ub+N68Jp tF36CvK77EMm+e49sjtfPMVGwovoNwSAJpIrtLcLcIj3WVAMX7fNqupkiQikBPMLkG9q xIRU4JINSHOkjeKIyT/zQ6jnYLVnYlk/+5px43eEoTkTKUG1/MoTVATQYC0v/1gOlOX3 SrF2IGoJrhl1B3XYzjO4Jn53vNKHuVYpnkpzNr3oXbmgapfYHJQlKdeFOA5d90/2jz6X YbLA== 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=bE76Luy7w0uXkAbzJgphYoFrwUdTwectG5vq9pZqEvA=; b=0EX7KIO/Vpo0DUmoTnt4qArF86r9c4i3ti9raoTPReI6xnZxzWqMatgQmbx/3btx6c lNfDxjevZ7xl/MZF3la+7fDiKyqGaogI4PKQ8VOdZWCkisd05X3EYrm2VVWy17p1zalT 2JkFN1o8O2F/jx32n8BpcIt3BWlvQqF+VmFpV/NPRJ4y/fita/DwzrGmVAvRKyALvJr5 AhRKKeX4fzrmESPZgyhhpaDbn2weBI4IdUppKLLnFAUA8jhJiSiUNze2aqX5/pHzYcYH 64ELmKyuJTvDDMa0JIKGvMaZyKE8EN1UKSCZI6Yk4hHjLzJsxnVuUPR5pZauCR6/kvIv pTLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=amtZ5k28; 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 t65-20020a375f44000000b0069ec8e4b6fasi8391794qkb.104.2022.05.03.14.11.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:11:28 -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=amtZ5k28; 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]:36842 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlznr-0002HQ-PQ for patch@linaro.org; Tue, 03 May 2022 17:11:27 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40562) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZr-0000fq-Im for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:57 -0400 Received: from mail-pf1-x42a.google.com ([2607:f8b0:4864:20::42a]:40693) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZo-0006NQ-Fw for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:54 -0400 Received: by mail-pf1-x42a.google.com with SMTP id i24so15568611pfa.7 for ; Tue, 03 May 2022 12:52:52 -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=bE76Luy7w0uXkAbzJgphYoFrwUdTwectG5vq9pZqEvA=; b=amtZ5k28fisP8nbDDwqUlt/+Op4kpc4KUKos2mdIdTbM8aHvUzcGyxT8BtfAJ0xIUp 93igYJUJqVn2N2F0b7BvzaxzZ+4ZNpiSAyHfrBqcK7vaLQD5bmff3m4XxyNmbQjd2jpL xelW7ZqOMLYunOvbilMwasWOhT913d9G8dDqa1giniLCiUGVwJku9p4xPo8NmMza7Xe2 OI0xuvG+PgKoBokqlACfRWJPpeXbt/BPtp5EpXrA+DQsC4RA5DgGvegoeYNYCd57YgPO KYyBjdKWk5nAueg+WNEaqCczd8mm60mv14aTOYJeA3LfKUu987ysEZ9L2fhSDRTUO9Ej Z+TA== 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=bE76Luy7w0uXkAbzJgphYoFrwUdTwectG5vq9pZqEvA=; b=fjIstt/MA3D6xpRU/FNcQOGcDnqTxjCOFLuM99jq5I9q0/HuGKcbhFcBCQXIDfX13v GfLngLTCxQdmj4wqqZ4hJF+P75LAEufXrXs8+vTVVHFm7OP3FJy0FySiTDZE62DN/S0G GkDIM0EhuVo8CZDBoS5FhJWyk8K3F+nKLCd1Brc9sIE0xMjWU8GwsrJMVFIGHtN3lIJ/ nTVad3goWWHszEGMM/pQzaMm0ZM4t81WZ1VqSbV+BJQI9YLf+oPvEg4KvZDmNM1Z/oXK xOlf9BtScHCVohgfVTw6t5eBVd4VpEvYVPIIAT1Dku2oRQ2BmKpEs7kY4PQveuQ3xDIG PhxQ== X-Gm-Message-State: AOAM531rZpPCyd7XmS/xnkoNUmdBWsjU0rbYU0ZGzkhd0bfqWvAnKJiv TB8X4NIHyCFV0zev22ijb9FFV2n+7+2EFQ== X-Received: by 2002:a05:6a00:26c3:b0:50d:d619:e4c6 with SMTP id p3-20020a056a0026c300b0050dd619e4c6mr14962734pfw.13.1651607571159; Tue, 03 May 2022 12:52:51 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:50 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 65/74] target/xtensa: Use an exception for semihosting Date: Tue, 3 May 2022 12:48:34 -0700 Message-Id: <20220503194843.1379101-66-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::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" 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(). Signed-off-by: Richard Henderson --- target/xtensa/cpu.h | 2 ++ target/xtensa/helper.h | 3 --- target/xtensa/exc_helper.c | 4 ++++ target/xtensa/translate.c | 3 ++- target/xtensa/xtensa-semi.c | 3 +-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index d4b8268146..411a128f60 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -259,6 +259,7 @@ enum { EXC_USER, EXC_DOUBLE, EXC_DEBUG, + EXC_SEMIHOST, EXC_MAX }; @@ -574,6 +575,7 @@ void xtensa_cpu_do_transaction_failed(CPUState *cs, hwaddr physaddr, vaddr addr, unsigned size, MMUAccessType access_type, int mmu_idx, MemTxAttrs attrs, MemTxResult response, uintptr_t retaddr); +void xtensa_semihosting(CPUXtensaState *env); #endif void xtensa_cpu_dump_state(CPUState *cpu, FILE *f, int flags); hwaddr xtensa_cpu_get_phys_page_debug(CPUState *cpu, vaddr addr); diff --git a/target/xtensa/helper.h b/target/xtensa/helper.h index ae938ceedb..531679cd86 100644 --- a/target/xtensa/helper.h +++ b/target/xtensa/helper.h @@ -11,9 +11,6 @@ DEF_HELPER_2(retw, void, env, i32) DEF_HELPER_3(window_check, noreturn, env, i32, i32) DEF_HELPER_1(restore_owb, void, env) DEF_HELPER_2(movsp, void, env, i32) -#ifndef CONFIG_USER_ONLY -DEF_HELPER_1(simcall, void, env) -#endif #ifndef CONFIG_USER_ONLY DEF_HELPER_3(waiti, void, env, i32, i32) diff --git a/target/xtensa/exc_helper.c b/target/xtensa/exc_helper.c index d4823a65cd..d54a518875 100644 --- a/target/xtensa/exc_helper.c +++ b/target/xtensa/exc_helper.c @@ -219,6 +219,10 @@ void xtensa_cpu_do_interrupt(CPUState *cs) } switch (cs->exception_index) { + case EXC_SEMIHOST: + xtensa_semihosting(env); + return; + case EXC_WINDOW_OVERFLOW4: case EXC_WINDOW_UNDERFLOW4: case EXC_WINDOW_OVERFLOW8: diff --git a/target/xtensa/translate.c b/target/xtensa/translate.c index 1485df2f22..6ddb2e112e 100644 --- a/target/xtensa/translate.c +++ b/target/xtensa/translate.c @@ -2416,7 +2416,8 @@ static void translate_simcall(DisasContext *dc, const OpcodeArg arg[], { #ifndef CONFIG_USER_ONLY if (semihosting_enabled()) { - gen_helper_simcall(cpu_env); + tcg_gen_movi_i32(cpu_pc, dc->base.pc_next); + gen_exception(dc, EXC_SEMIHOST); } #endif } diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index fa21b7e11f..5375f106fc 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -28,7 +28,6 @@ #include "qemu/osdep.h" #include "cpu.h" #include "chardev/char-fe.h" -#include "exec/helper-proto.h" #include "semihosting/semihost.h" #include "qapi/error.h" #include "qemu/log.h" @@ -188,7 +187,7 @@ void xtensa_sim_open_console(Chardev *chr) sim_console = &console; } -void HELPER(simcall)(CPUXtensaState *env) +void xtensa_semihosting(CPUXtensaState *env) { CPUState *cs = env_cpu(env); uint32_t *regs = env->regs; From patchwork Tue May 3 19:48: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: 569026 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9821273map; Tue, 3 May 2022 14:10:26 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxcIMvN8HFjBDTqQ6glCv0WI4p4CBOmxPGRBOiEY4PmHLgmR1MUZzC4tfIUvYJn3ohnVG+g X-Received: by 2002:a05:6214:23c8:b0:450:863a:fa1e with SMTP id hr8-20020a05621423c800b00450863afa1emr14973383qvb.54.1651612225935; Tue, 03 May 2022 14:10:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612225; cv=none; d=google.com; s=arc-20160816; b=fnC8N+Ze5Jf6iDRlZvV94txR/HWTP0xZILV8Jp3yYY78DxY+bgEJkjavwhtbx2SXfI OMPRoUgoF3nU8ffEjakTaF50qWhkAEiFm7SFTNqVtDvcfzuo8CXb9UDA8viuVgKCCDlj KPuz1AUPIEARAySs8zihKcXb5qlh022Q9bHPEjwz1+bweLBdfW+x9Tp57Gj/wFZGZjX3 TO1vd/xlDAQiT3Wi6f7rDWGYheB2AT11nuKAvQFofh6BZ9NzYpRjs4SazGMxIGaiRgOh Mdkpblzn73qJG6Lo8O+eMNdeGy8WIQc66EgBZn7WYAcjpnVo0fPaAUTU/6IdHputltQR JUuw== 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=1fJFL9WFFMMBNST5fjywcK07uYxhwGnnD8ji5QpthKs=; b=glCuk+GqyI/MbIIv2HI2nw1gzQgfQA7ZE1RQor0wxYGWgjCf3jz5K+JrMvQMQd12I/ pjTNrtCdRSTZGPxFu1LHvaJyRHfatSrlq0WdkEK/EiNxPRFPzVaRlCBs+9+F0+c0cX7n GpZoyVAqoQw9ffgF56BYn4phb396jtEmEkDm2N7/H99hld8FBr4LwI4URkgJVBfpTr6Q DYc6pn+bmHdI3dJ7eHXdEigLLsmeXiXxaUqnCACdqBCMLIaspB8jHaoAyBtYJjcM8gmr 1/Tb3DneMJQIFHH9dEJA0/FAQ6JMiUCj52SaJI2a8F9nL9oppAqEGG7ehHU5B0QtaptJ LUGA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ehea1zdk; 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 h5-20020a05620a284500b0069f61e2d348si9319934qkp.613.2022.05.03.14.10.25 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:10:25 -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=ehea1zdk; 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]:35756 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzmr-0001Yx-Cw for patch@linaro.org; Tue, 03 May 2022 17:10:25 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40590) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZt-0000hS-F5 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:57 -0400 Received: from mail-pj1-x1032.google.com ([2607:f8b0:4864:20::1032]:35737) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZp-0006NZ-Jw for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:57 -0400 Received: by mail-pj1-x1032.google.com with SMTP id w5-20020a17090aaf8500b001d74c754128so3254490pjq.0 for ; Tue, 03 May 2022 12:52:53 -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=1fJFL9WFFMMBNST5fjywcK07uYxhwGnnD8ji5QpthKs=; b=ehea1zdkqhLy37mZxw+2/QibyH93LzrgSG+NgPc0PKPBtu7lBgML8XJQir0RiQgo7/ /qEfngYz9065oKlAyHEOWXaZL9x2v4gG2/p16GCAf3EEEceIfBCwxchn5A2dNuvdaHCW UsEgp5rJDPr0zezw+5LO6J9/rLvPScSu2PprhVIjIJIEQYdxU/CRsUP+dZHqE5T90X8P Frs9A20xAYQXs/1o2pTiMA3eG+f06hh8gUq3cxQw9VPD0inD+TK80I/muribjLWJlg6n Rg6VM+hf4LxwlfXcWEFEl4ljVt8j5wwVfu8ACJcho8OhdhVxfH2xD7MXdvWcnQww5pw/ RKnQ== 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=1fJFL9WFFMMBNST5fjywcK07uYxhwGnnD8ji5QpthKs=; b=vUMtqT2nm6j6dEYxX/K601iJ7mHFu+cvduOO5ZVOnasBc+zb003XX2jYYWojhmXJDQ mvSg4kEB7jRG4cSvJOPrsg6gz53KrjYzDln00ktQcFUtVtrRMrlmSx0EdwFAnDF/VZRS Cu8NQODQWWttXDbqPM0AdWNX8oYL2+ha6oEOsXnk+B9rv5L6ONf1pXvWBvj9ErSf3ady Lg4ZtelsfEKe+3+mPLAmf7bgf6CH7YWhL9s4hwwMUPz9RdlA8IOMRo1To7zV7NI/rBgz 8bpFFVqffRRL0Oh3AMRWx1pJ8rnaw+Oa9lTb1aDai92KDiFNdtABnwtARCyzOmL4Uvzs oK1g== X-Gm-Message-State: AOAM532VcrJPX5emkXUs+MRlFu/ZHhhHsKXzL0x1zMhv5rPIuOWgim04 mB5+w8N9vickcDg/KqB7QJTj6VwwCkVtGg== X-Received: by 2002:a17:902:f2ca:b0:15d:180d:704 with SMTP id h10-20020a170902f2ca00b0015d180d0704mr17868219plc.102.1651607572145; Tue, 03 May 2022 12:52:52 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.51 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:51 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 66/74] target/xtensa: Use semihosting/syscalls.h Date: Tue, 3 May 2022 12:48:35 -0700 Message-Id: <20220503194843.1379101-67-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::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 separates guest file descriptors from host file descriptors, and utilizes shared infrastructure for integration with gdbstub. Remove the xtensa custom console handing and rely on the generic -semihosting-config handling of chardevs. Signed-off-by: Richard Henderson --- target/xtensa/cpu.h | 1 - hw/xtensa/sim.c | 3 - target/xtensa/xtensa-semi.c | 303 +++++++++--------------------------- 3 files changed, 77 insertions(+), 230 deletions(-) diff --git a/target/xtensa/cpu.h b/target/xtensa/cpu.h index 411a128f60..b1311a0530 100644 --- a/target/xtensa/cpu.h +++ b/target/xtensa/cpu.h @@ -610,7 +610,6 @@ void xtensa_translate_init(void); void **xtensa_get_regfile_by_name(const char *name, int entries, int bits); void xtensa_breakpoint_handler(CPUState *cs); void xtensa_register_core(XtensaConfigList *node); -void xtensa_sim_open_console(Chardev *chr); void check_interrupts(CPUXtensaState *s); void xtensa_irq_init(CPUXtensaState *env); qemu_irq *xtensa_get_extints(CPUXtensaState *env); diff --git a/hw/xtensa/sim.c b/hw/xtensa/sim.c index 946c71cb5b..5cca6a170e 100644 --- a/hw/xtensa/sim.c +++ b/hw/xtensa/sim.c @@ -87,9 +87,6 @@ XtensaCPU *xtensa_sim_common_init(MachineState *machine) xtensa_create_memory_regions(&sysram, "xtensa.sysram", get_system_memory()); } - if (serial_hd(0)) { - xtensa_sim_open_console(serial_hd(0)); - } return cpu; } diff --git a/target/xtensa/xtensa-semi.c b/target/xtensa/xtensa-semi.c index 5375f106fc..42baae419b 100644 --- a/target/xtensa/xtensa-semi.c +++ b/target/xtensa/xtensa-semi.c @@ -27,8 +27,10 @@ #include "qemu/osdep.h" #include "cpu.h" -#include "chardev/char-fe.h" +#include "exec/gdbstub.h" #include "semihosting/semihost.h" +#include "semihosting/syscalls.h" +#include "semihosting/softmmu-uaccess.h" #include "qapi/error.h" #include "qemu/log.h" @@ -92,99 +94,49 @@ enum { TARGET_ELOOP = 92, }; -static uint32_t errno_h2g(int host_errno) +static void xtensa_cb(CPUState *cs, uint64_t ret, int err) { - switch (host_errno) { - case 0: return 0; - case EPERM: return TARGET_EPERM; - case ENOENT: return TARGET_ENOENT; - case ESRCH: return TARGET_ESRCH; - case EINTR: return TARGET_EINTR; - case EIO: return TARGET_EIO; - case ENXIO: return TARGET_ENXIO; - case E2BIG: return TARGET_E2BIG; - case ENOEXEC: return TARGET_ENOEXEC; - case EBADF: return TARGET_EBADF; - case ECHILD: return TARGET_ECHILD; - case EAGAIN: return TARGET_EAGAIN; - case ENOMEM: return TARGET_ENOMEM; - case EACCES: return TARGET_EACCES; - case EFAULT: return TARGET_EFAULT; -#ifdef ENOTBLK - case ENOTBLK: return TARGET_ENOTBLK; -#endif - case EBUSY: return TARGET_EBUSY; - case EEXIST: return TARGET_EEXIST; - case EXDEV: return TARGET_EXDEV; - case ENODEV: return TARGET_ENODEV; - case ENOTDIR: return TARGET_ENOTDIR; - case EISDIR: return TARGET_EISDIR; - case EINVAL: return TARGET_EINVAL; - case ENFILE: return TARGET_ENFILE; - case EMFILE: return TARGET_EMFILE; - case ENOTTY: return TARGET_ENOTTY; -#ifdef ETXTBSY - case ETXTBSY: return TARGET_ETXTBSY; -#endif - case EFBIG: return TARGET_EFBIG; - case ENOSPC: return TARGET_ENOSPC; - case ESPIPE: return TARGET_ESPIPE; - case EROFS: return TARGET_EROFS; - case EMLINK: return TARGET_EMLINK; - case EPIPE: return TARGET_EPIPE; - case EDOM: return TARGET_EDOM; - case ERANGE: return TARGET_ERANGE; - case ENOSYS: return TARGET_ENOSYS; -#ifdef ELOOP - case ELOOP: return TARGET_ELOOP; -#endif - }; + CPUXtensaState *env = cs->env_ptr; - return TARGET_EINVAL; -} +#define E(N) case E##N: err = TARGET_E##N; break -typedef struct XtensaSimConsole { - CharBackend be; - struct { - char buffer[16]; - size_t offset; - } input; -} XtensaSimConsole; - -static XtensaSimConsole *sim_console; - -static IOCanReadHandler sim_console_can_read; -static int sim_console_can_read(void *opaque) -{ - XtensaSimConsole *p = opaque; - - return sizeof(p->input.buffer) - p->input.offset; -} - -static IOReadHandler sim_console_read; -static void sim_console_read(void *opaque, const uint8_t *buf, int size) -{ - XtensaSimConsole *p = opaque; - size_t copy = sizeof(p->input.buffer) - p->input.offset; - - if (size < copy) { - copy = size; + switch (err) { + 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); + case GDB_ENAMETOOLONG: + err = TARGET_EINVAL; + break; } - memcpy(p->input.buffer + p->input.offset, buf, copy); - p->input.offset += copy; + + env->regs[3] = err; + env->regs[2] = ret; + +#undef E } -void xtensa_sim_open_console(Chardev *chr) +static void xtensa_select_cb(CPUState *cs, uint64_t ret, int err) { - static XtensaSimConsole console; - - qemu_chr_fe_init(&console.be, chr, &error_abort); - qemu_chr_fe_set_handlers(&console.be, - sim_console_can_read, - sim_console_read, - NULL, NULL, &console, - NULL, true); - sim_console = &console; + if (ret & G_IO_NVAL) { + xtensa_cb(cs, -1, GDB_EBADF); + } else { + xtensa_cb(cs, ret != 0, 0); + } } void xtensa_semihosting(CPUXtensaState *env) @@ -194,165 +146,64 @@ void xtensa_semihosting(CPUXtensaState *env) switch (regs[2]) { case TARGET_SYS_exit: + gdb_exit(regs[3]); exit(regs[3]); break; case TARGET_SYS_read: + semihost_sys_read(cs, xtensa_cb, regs[3], regs[4], regs[5]); + break; case TARGET_SYS_write: - { - bool is_write = regs[2] == TARGET_SYS_write; - uint32_t fd = regs[3]; - uint32_t vaddr = regs[4]; - uint32_t len = regs[5]; - uint32_t len_done = 0; - - while (len > 0) { - hwaddr paddr = cpu_get_phys_page_debug(cs, vaddr); - uint32_t page_left = - TARGET_PAGE_SIZE - (vaddr & (TARGET_PAGE_SIZE - 1)); - uint32_t io_sz = page_left < len ? page_left : len; - hwaddr sz = io_sz; - void *buf = cpu_physical_memory_map(paddr, &sz, !is_write); - uint32_t io_done; - bool error = false; - - if (buf) { - vaddr += io_sz; - len -= io_sz; - if (fd < 3 && sim_console) { - if (is_write && (fd == 1 || fd == 2)) { - io_done = qemu_chr_fe_write_all(&sim_console->be, - buf, io_sz); - regs[3] = errno_h2g(errno); - } else if (!is_write && fd == 0) { - if (sim_console->input.offset) { - io_done = sim_console->input.offset; - if (io_sz < io_done) { - io_done = io_sz; - } - memcpy(buf, sim_console->input.buffer, io_done); - memmove(sim_console->input.buffer, - sim_console->input.buffer + io_done, - sim_console->input.offset - io_done); - sim_console->input.offset -= io_done; - qemu_chr_fe_accept_input(&sim_console->be); - } else { - io_done = -1; - regs[3] = TARGET_EAGAIN; - } - } else { - qemu_log_mask(LOG_GUEST_ERROR, - "%s fd %d is not supported with chardev console\n", - is_write ? - "writing to" : "reading from", fd); - io_done = -1; - regs[3] = TARGET_EBADF; - } - } else { - io_done = is_write ? - write(fd, buf, io_sz) : - read(fd, buf, io_sz); - regs[3] = errno_h2g(errno); - } - if (io_done == -1) { - error = true; - io_done = 0; - } - cpu_physical_memory_unmap(buf, sz, !is_write, io_done); - } else { - error = true; - regs[3] = TARGET_EINVAL; - break; - } - if (error) { - if (!len_done) { - len_done = -1; - } - break; - } - len_done += io_done; - if (io_done < io_sz) { - break; - } - } - regs[2] = len_done; - } + semihost_sys_write(cs, xtensa_cb, regs[3], regs[4], regs[5]); break; - case TARGET_SYS_open: - { - char name[1024]; - int rc; - int i; - - for (i = 0; i < ARRAY_SIZE(name); ++i) { - rc = cpu_memory_rw_debug(cs, regs[3] + i, - (uint8_t *)name + i, 1, 0); - if (rc != 0 || name[i] == 0) { - break; - } - } - - if (rc == 0 && i < ARRAY_SIZE(name)) { - regs[2] = open(name, regs[4], regs[5]); - regs[3] = errno_h2g(errno); - } else { - regs[2] = -1; - regs[3] = TARGET_EINVAL; - } - } + semihost_sys_open(cs, xtensa_cb, regs[3], 0, regs[4], regs[5]); break; - case TARGET_SYS_close: - if (regs[3] < 3) { - regs[2] = regs[3] = 0; - } else { - regs[2] = close(regs[3]); - regs[3] = errno_h2g(errno); - } + semihost_sys_close(cs, xtensa_cb, regs[3]); break; - case TARGET_SYS_lseek: - regs[2] = lseek(regs[3], (off_t)(int32_t)regs[4], regs[5]); - regs[3] = errno_h2g(errno); + semihost_sys_lseek(cs, xtensa_cb, regs[3], regs[4], regs[5]); break; case TARGET_SYS_select_one: { - uint32_t fd = regs[3]; - uint32_t rq = regs[4]; - uint32_t target_tv = regs[5]; - uint32_t target_tvv[2]; + int timeout, events; - struct timeval tv = {0}; + if (regs[5]) { + uint32_t tv_sec, tv_usec; + uint64_t msec; - if (target_tv) { - cpu_memory_rw_debug(cs, target_tv, - (uint8_t *)target_tvv, sizeof(target_tvv), 0); - tv.tv_sec = (int32_t)tswap32(target_tvv[0]); - tv.tv_usec = (int32_t)tswap32(target_tvv[1]); - } - if (fd < 3 && sim_console) { - if ((fd == 1 || fd == 2) && rq == SELECT_ONE_WRITE) { - regs[2] = 1; - } else if (fd == 0 && rq == SELECT_ONE_READ) { - regs[2] = sim_console->input.offset > 0; - } else { - regs[2] = 0; + if (get_user_u32(tv_sec, regs[5]) || + get_user_u32(tv_usec, regs[5])) { + xtensa_cb(cs, -1, GDB_EFAULT); + return; } - regs[3] = 0; - } else { - fd_set fdset; - FD_ZERO(&fdset); - FD_SET(fd, &fdset); - regs[2] = select(fd + 1, - rq == SELECT_ONE_READ ? &fdset : NULL, - rq == SELECT_ONE_WRITE ? &fdset : NULL, - rq == SELECT_ONE_EXCEPT ? &fdset : NULL, - target_tv ? &tv : NULL); - regs[3] = errno_h2g(errno); + /* Poll timeout is in milliseconds; overflow to infinity. */ + msec = tv_sec * 1000ull + DIV_ROUND_UP(tv_usec, 1000ull); + timeout = msec <= INT32_MAX ? msec : -1; + } else { + timeout = -1; } + + switch (regs[4]) { + case SELECT_ONE_READ: + events = G_IO_IN; + break; + case SELECT_ONE_WRITE: + events = G_IO_OUT; + break; + case SELECT_ONE_EXCEPT: + events = G_IO_PRI; + break; + default: + xtensa_cb(cs, -1, GDB_EINVAL); + return; + } + + semihost_sys_poll_one(cs, xtensa_select_cb, + regs[3], events, timeout); } break; From patchwork Tue May 3 19:48: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: 569028 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9824840map; Tue, 3 May 2022 14:15:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrggjGaHdzflxfv2WOQtUI7Ys2CfVZUrDy1fOVNR/uEaQV1xqOaGNny203mn7fxqsku73w X-Received: by 2002:a05:6214:2301:b0:435:38af:2f87 with SMTP id gc1-20020a056214230100b0043538af2f87mr15277180qvb.83.1651612529021; Tue, 03 May 2022 14:15:29 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612529; cv=none; d=google.com; s=arc-20160816; b=MTBOTHClUWNdHpqrD67Gf4BPcNCmpxyK8AqErxkWFepKzX5y46vu4CDyB2FSe8/oX9 IFsoQRntPW0cx7tgsZSke/SKW7J5RAFYOfdz36RXObyB8jyEP6i6n3GwszAhLzTGr2La wuxa9gkmlv8kLIj5wUjxpV1N7jBTZp8YglvA6dSSIzX/HgZSSSegLSfCr0ZmQgcu5lky 02tW2Mogpk/IsKNSZUaILVriCI2sMS/ZVi5MfC8UNqBErCiws22VYUaLgrPZgruYOhWm GXKTttBIcg4XcUhSiBUhLc5h8UAG4/QvEHEg6xMCXRrdyf1T4YYxAwy8L2aF6f3Lf4fW 2ZOg== 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=PoRUGz2szMDJicl6LiDwHi+o01/ArFupEpZx2x6+ISI=; b=XTBW2qdjT8jENAZfxFpHOHivh0gSCMoTDckb7fM11IVVMLRfE3Kh0mZ2fmz0mM06G+ DJUWW6CFlc5EF7pFiVlksLwQ5GLR9YDo8jA1/XW1mFD5ToSRVDtnKsU9pV5qT0yot6oB fZQokQ63vz54jen/vdpjXd4rVOTn7OSt7hHfxW2l5ueUlMGGb8cZW2JmC/wrXabrN/yE OOz6AKyVXzKRoC4u5AqeL+6yAdMGBrEuVYnXOC4kdPnAPbt1yKKhpuHFA+l5+Rk/6awn utcOdu6ORjxJtEdJh1K/fKptgIzpXBqXAshF1cWI5TRkVIk22wiyPpEcGWGC9cW5xtcw OgJQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UWXG/xvT"; 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 n12-20020a05622a040c00b002f1fd4f5cdasi8693687qtx.736.2022.05.03.14.15.28 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:15: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="UWXG/xvT"; 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]:43304 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzrk-0006nR-HF for patch@linaro.org; Tue, 03 May 2022 17:15:28 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40592) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZt-0000hU-FU for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:57 -0400 Received: from mail-pg1-x52d.google.com ([2607:f8b0:4864:20::52d]:37849) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZr-0006Nr-Ab for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:56 -0400 Received: by mail-pg1-x52d.google.com with SMTP id 15so14810581pgf.4 for ; Tue, 03 May 2022 12:52:54 -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=PoRUGz2szMDJicl6LiDwHi+o01/ArFupEpZx2x6+ISI=; b=UWXG/xvTRELgCqD7Gj4fW+QmJxBn2ZB/mOEaOoejrI1RBqJp67tXD/jrzjpW1MTtdW KjWko7slI/iP/Wg633Aez2qxKzeRUVUpEbzG5IEl08F0TnqAmlJV5GgFe5hMyaSN8t5S J5CkstPWLUeSLJL79fky1Y+JguYSk5/R2AsEHIFlZ4Rl/1uFw42ft/Yjism0c72GEq7m jwi7p3o4hRQRiepmKZdnbo+GBWIkECfNI4vr8Y/iB4DsvBgkGHPghM2HHK3uBycFMDk6 moHeibuFGpXdzmQsDiAmtAabxu/f4HcZ8u0pevB6RpQcBcP7XkCmm3kPfEdQLzOl/oEX soyw== 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=PoRUGz2szMDJicl6LiDwHi+o01/ArFupEpZx2x6+ISI=; b=4EdLsIe4GkLPCsWEfSsYl3Ein1IbzaH3R71GLb7yh42M2Jq4nlLH/iJC8LDMJ6sLY/ MVqf0vTum9b+R6ACW0zED9pI9HBjQJZ2TLb12u5+0+ji19rH5ycsJOLO1irisInpJHUd AfptcW4MXJ2ZD0uo2b3FbjC0E9sTJHgzmYx4vwKM4/rMreEVqC0106gvyDFthcnjG686 6Ts5AY3IuYiusVcvQG1Ecw/78Fux+YRQ4AxxWwDriODsbEh+GKYjoOtF+vka+eccDQ7D OIoqteVURhSq0ROxDBbPXAECYt6nCZ5bUa1gmVzXcWy/GP5uToVrUu4SW80myBxvd0N5 UmKg== X-Gm-Message-State: AOAM533LcRxR96qplncoM65qAUgUPwnWZR/fNHNI/0U++JUs8Q1ESWEE hVmE0pK5B5+qfL27J/DE4znp1k94ZU6MpA== X-Received: by 2002:a63:fa41:0:b0:3c2:1941:5894 with SMTP id g1-20020a63fa41000000b003c219415894mr9272333pgk.296.1651607573045; Tue, 03 May 2022 12:52:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.52 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:52 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 67/74] tests/docker: Add debian-rx-cross image Date: Tue, 3 May 2022 12:48:36 -0700 Message-Id: <20220503194843.1379101-68-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::52d; envelope-from=richard.henderson@linaro.org; helo=mail-pg1-x52d.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" Build the entire cross tool chain from source. For this reason, default to caching. Signed-off-by: Richard Henderson --- MAINTAINERS | 1 + tests/docker/Makefile.include | 6 ++ .../debian-rx-cross.d/build-toolchain.sh | 58 +++++++++++++++++++ tests/tcg/configure.sh | 6 ++ 4 files changed, 71 insertions(+) create mode 100755 tests/docker/dockerfiles/debian-rx-cross.d/build-toolchain.sh diff --git a/MAINTAINERS b/MAINTAINERS index 294c88ace9..62d2640f35 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -297,6 +297,7 @@ RENESAS RX CPUs R: Yoshinori Sato S: Orphan F: target/rx/ +F: tests/docker/dockerfiles/debian-rx-cross.d/build-toolchain.sh S390 TCG CPUs M: Richard Henderson diff --git a/tests/docker/Makefile.include b/tests/docker/Makefile.include index ca2157db46..1795a49da2 100644 --- a/tests/docker/Makefile.include +++ b/tests/docker/Makefile.include @@ -142,6 +142,10 @@ docker-image-debian-nios2-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \ $(DOCKER_FILES_DIR)/debian-nios2-cross.d/build-toolchain.sh $(call debian-toolchain, $@) +docker-image-debian-rx-cross: $(DOCKER_FILES_DIR)/debian-toolchain.docker \ + $(DOCKER_FILES_DIR)/debian-rx-cross.d/build-toolchain.sh + $(call debian-toolchain, $@) + # Specialist build images, sometimes very limited tools docker-image-debian-tricore-cross: docker-image-debian10 docker-image-debian-all-test-cross: docker-image-debian10 @@ -149,6 +153,7 @@ docker-image-debian-microblaze-cross: docker-image-debian10 docker-image-debian-nios2-cross: docker-image-debian10 docker-image-debian-powerpc-test-cross: docker-image-debian11 docker-image-debian-riscv64-test-cross: docker-image-debian11 +docker-image-debian-rx-cross: docker-image-debian10 # These images may be good enough for building tests but not for test builds DOCKER_PARTIAL_IMAGES += debian-alpha-cross @@ -158,6 +163,7 @@ DOCKER_PARTIAL_IMAGES += debian-m68k-cross debian-mips64-cross DOCKER_PARTIAL_IMAGES += debian-microblaze-cross DOCKER_PARTIAL_IMAGES += debian-nios2-cross DOCKER_PARTIAL_IMAGES += debian-riscv64-test-cross +DOCKER_PARTIAL_IMAGES += debian-rx-cross DOCKER_PARTIAL_IMAGES += debian-sh4-cross debian-sparc64-cross DOCKER_PARTIAL_IMAGES += debian-tricore-cross DOCKER_PARTIAL_IMAGES += debian-xtensa-cross diff --git a/tests/docker/dockerfiles/debian-rx-cross.d/build-toolchain.sh b/tests/docker/dockerfiles/debian-rx-cross.d/build-toolchain.sh new file mode 100755 index 0000000000..0d22280dee --- /dev/null +++ b/tests/docker/dockerfiles/debian-rx-cross.d/build-toolchain.sh @@ -0,0 +1,58 @@ +#!/bin/bash + +set -e + +TARGET=rx-elf + +J=$(expr $(nproc) / 2) +TOOLCHAIN_INSTALL=/usr/local +TOOLCHAIN_BIN=${TOOLCHAIN_INSTALL}/bin +CROSS_SYSROOT=${TOOLCHAIN_INSTALL}/$TARGET/sys-root + +export PATH=${TOOLCHAIN_BIN}:$PATH + +# +# Grab all of the source for the toolchain bootstrap. +# + +wget https://ftp.gnu.org/gnu/binutils/binutils-2.37.tar.xz +wget https://ftp.gnu.org/gnu/gcc/gcc-11.2.0/gcc-11.2.0.tar.xz + +tar axf binutils-2.37.tar.xz +tar axf gcc-11.2.0.tar.xz + +git clone --depth 1 --branch newlib-4.1.0 \ + https://sourceware.org/git/newlib-cygwin.git newlib-4.1.0 + +# Create a combined gcc/newlib source tree + +mkdir -p src/include +cd src +ln -s ../gcc*/* . || true +ln -s ../newlib*/* . || true +cd include +ln -s ../../gcc*/include/* . || true +ln -s ../../newlib*/include/* . || true +cd ../../ + +# Build binutils + +mkdir -p bld-b +cd bld-b +../binu*/configure --disable-werror \ + --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} +make -j${J} +make install +cd .. + +# Build gcc+newlib + +mkdir -p bld +cd bld +../src/configure --disable-werror --disable-shared \ + --prefix=${TOOLCHAIN_INSTALL} --with-sysroot --target=${TARGET} \ + --enable-languages=c --disable-libssp --disable-libsanitizer \ + --disable-libatomic --disable-libgomp --disable-libquadmath +make -j${J} +make install +cd .. diff --git a/tests/tcg/configure.sh b/tests/tcg/configure.sh index 691d90abac..34c94f3045 100755 --- a/tests/tcg/configure.sh +++ b/tests/tcg/configure.sh @@ -68,6 +68,7 @@ fi : ${cross_cc_ppc64le="$cross_cc_ppc64"} : ${cross_cc_cflags_ppc64le="-m64 -mlittle-endian"} : ${cross_cc_riscv64="riscv64-linux-gnu-gcc"} +: ${cross_cc_rx="rx-elf-gcc"} : ${cross_cc_s390x="s390x-linux-gnu-gcc"} : ${cross_cc_sh4="sh4-linux-gnu-gcc"} : ${cross_cc_cflags_sparc="-m32 -mv8plus -mcpu=ultrasparc"} @@ -192,6 +193,11 @@ for target in $target_list; do container_image=debian-riscv64-test-cross container_cross_cc=riscv64-linux-gnu-gcc ;; + rx-*) + container_hosts=x86_64 + container_image=debian-rx-cross + container_cross_cc=rx-elf-gcc + ;; s390x-*) container_hosts=x86_64 container_image=debian-s390x-cross From patchwork Tue May 3 19:48: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: 569012 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9808447map; Tue, 3 May 2022 13:51:23 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyqWjNIy8cY5w5VHyoPpNeZdfhLv/Doe75mL2mzgJWe/K44rcPtORuHAnkjWZmZGUG81+Tv X-Received: by 2002:a05:620a:2902:b0:69f:fcd3:a3b7 with SMTP id m2-20020a05620a290200b0069ffcd3a3b7mr4874645qkp.486.1651611083455; Tue, 03 May 2022 13:51:23 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611083; cv=none; d=google.com; s=arc-20160816; b=gND+0ijGSTbRf3izB0s6cv3p4hh1zkGyESh/flPzPqAPODpiarRwzHJquYznwyuKPM BlK3TGR2WiU3v16dYQpGvyE9pCxGhAwF6o/LrgvJG89HP8Wus8GYYm1e2YoYNy2k/PwU Q7i/Env/LmbvfSW9tXoBkSurBWsG5E7ArZIpuY1kgwy/beu63LziGuja5oBYJYe2g7lV bOnGRDtOB1AGA/eBSpjOWMB6H4nv1xryS6YInAV0RYtVMHDqXr/Ueka6YNwDWp0n1u+M rE1me+goBHETBiXaUngij+hlPGLMfGXxExSrUspde/oj8vDo4wRjpR276XWpzK6oCVtS 5MNw== 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=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=PwGP60O9ma2au0V6Oil3WuhOx1gyiTQLJ3xvLYxqsoVBK//2kCY7AzOKSGxt8m8zni PXLh8oqnnP18JGc1ujljGxXPr+7gDv+HLS6Fe5AKi+ADsh7YiDGyWEeikez8I9f6qWP5 OPkDzScOilb8LVgfEqtrm3IoJlVfp9oDUm685wvoFmJ41HCB7q2FN3IaG69gZ1Vsuw7x QuMHhHlm2+LvG+6VduZUAtHs5Xk0lU2A+gZ9WzVPWTI4gRAyxvP4wGPjMqfwFMQzOWK+ dna8ocFi+gD67YjfAF3Re9pcX99KdCSh8+6yxZ+o13Yb0KDWToj0MclcjUmbVeBVdlfg LPLw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=eUJ6tNVT; 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 u5-20020a05620a454500b0069fc79d86b8si5597276qkp.46.2022.05.03.13.51.23 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:51: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=eUJ6tNVT; 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]:57396 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzUQ-00032t-Uv for patch@linaro.org; Tue, 03 May 2022 16:51:22 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40648) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0000le-SQ for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:01 -0400 Received: from mail-pj1-x1033.google.com ([2607:f8b0:4864:20::1033]:35738) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZr-0006O0-Ap for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:59 -0400 Received: by mail-pj1-x1033.google.com with SMTP id w5-20020a17090aaf8500b001d74c754128so3254562pjq.0 for ; Tue, 03 May 2022 12:52:54 -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=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=eUJ6tNVTMwM1wm+HV9JryQMqqsYDnb7huOrG1P+TLz+Czcy2+mrfwXx37Jd6irFwEL 7D49/BSHQu3fiRquAyJ2VZjBTXmBpkp6n52MfAjpn1v2rnoGq/cQmPTWxtFSWqDvqjuG PgkUBdQC4IujNo4UcwJicw2ZFPi9wAChGyLkppGbbLNjWVGIZOhvJCR6ugcDTADRb0LC goQKKCEl2+mXawAorMQA9ChQ8rS//tjiyIpWFpZlvU10K3iW9iaqC24alU7ZkXMLic8g LEaFwpChD5Q4/Xy8nrKPmgh5t0F1ceXh4a15ZEwVU6O4hG4dNKoA/W1El/of5IvPiuCX IW7w== 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=ocWIh32CouzGFfi6GAu6bp81akmgvCStQtCfH36MgiM=; b=B6Jl3mwtMXdlaC9Db/4blZsKVJ+BeQmoTnUE/RxU4Avh+nTxFcca/6TjA20wnPCsd8 BqbXExZHcZZSytUMW1DtcpkE1K9yH7Q+NEhe/ojZvzKv5kJAqrwpb2hvVXjJjNFH6YwB KPp6oMSjCTfWb7hirKiIxxcEiUvrRbAQnDUIoHWMO80HXlez9YnYDvDZ8Sxik6N4+EJ+ nUNW3YokeZRV4I8S0pIsbaAgd7ws9KjEDSHVBkiQ+rhYEpod5B1DUmzgpK6+jhD5S00/ HEGvo4M1AVMWsXwISrLLalCMt3MCc7fuBhl4SE9DOB05dqBoj1MnFVjCHwK/s+4rWbkV Cevg== X-Gm-Message-State: AOAM530g36n+58g2VzOC2iG7ksjIattL4YJuN2zhBmoPHXNjYc7ZyZzB NqmDieOq/voqGsk1b18GKKL6plkDUHBcfA== X-Received: by 2002:a17:903:410b:b0:15c:fd57:aa34 with SMTP id r11-20020a170903410b00b0015cfd57aa34mr17922864pld.82.1651607573962; Tue, 03 May 2022 12:52:53 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.53 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:53 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 68/74] hw/rx: Handle a kernel file that is ELF Date: Tue, 3 May 2022 12:48:37 -0700 Message-Id: <20220503194843.1379101-69-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::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" Attempt to load the kernel with load_elf. If this fails with ELF_LOAD_NOT_ELF, continue to treat the kernel as a raw image. This will be handy for running semihosting programs. Signed-off-by: Richard Henderson --- hw/rx/rx-gdbsim.c | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/hw/rx/rx-gdbsim.c b/hw/rx/rx-gdbsim.c index be147b4bd9..64b533181d 100644 --- a/hw/rx/rx-gdbsim.c +++ b/hw/rx/rx-gdbsim.c @@ -26,6 +26,7 @@ #include "sysemu/device_tree.h" #include "hw/boards.h" #include "qom/object.h" +#include "elf.h" /* Same address of GDB integrated simulator */ #define SDRAM_BASE EXT_CS_BASE @@ -57,15 +58,32 @@ static void rx_load_image(RXCPU *cpu, const char *filename, uint32_t start, uint32_t size) { static uint32_t extable[32]; - long kernel_size; + ssize_t kernel_size; + uint64_t kernel_entry; int i; + /* Try an ELF image first. */ + + kernel_size = load_elf(filename, NULL, NULL, NULL, &kernel_entry, + NULL, NULL, NULL, false, EM_RX, false, false); + if (kernel_size >= 0) { + cpu_set_pc(CPU(cpu), kernel_entry); + return; + } + if (kernel_size != ELF_LOAD_NOT_ELF) { + error_report("could not load kernel '%s': %s", + filename, load_elf_strerror(kernel_size)); + exit(1); + } + + /* Not ELF: load a raw image, e.g. zImage. */ + kernel_size = load_image_targphys(filename, start, size); if (kernel_size < 0) { - fprintf(stderr, "qemu: could not load kernel '%s'\n", filename); + error_report("could not load kernel '%s'", filename); exit(1); } - cpu->env.pc = start; + cpu_set_pc(CPU(cpu), start); /* setup exception trap trampoline */ /* linux kernel only works little-endian mode */ From patchwork Tue May 3 19:48: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: 569019 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9811973map; Tue, 3 May 2022 13:57:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw272WaiyhqNEaIwTzZzmT0OBl+mwdpB8F+5VpvBGV3KVdCNqjOBT9A6dRV501ZsqePmY91 X-Received: by 2002:a37:80c4:0:b0:69f:eb02:eeae with SMTP id b187-20020a3780c4000000b0069feb02eeaemr7333417qkd.553.1651611458603; Tue, 03 May 2022 13:57:38 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611458; cv=none; d=google.com; s=arc-20160816; b=av5v2YOfzn3+pCqvKIWEQXU2USuDFfyK9JIHQ9JmAO8JP3QfBfq4UBPMdCNJwpi+GF Jw6vp3JWSG0DUHNiSIQGVtOxQlxiRKiOdGyKLjAeZ0iM8wBEfC1kTN1ER43IDwnlbs++ VFeNNmn21ZoKBHx5VEB5Ka3zO+B0nttggATHBW2nYam7wbwqDxhT5b1GopbHep0rqur0 u0R1NACke7f7iMo5VaI2/w+qVwMMeSz5BfM46NF3mrVOp4PWhWsJQ1dXW8+HfcQJNzfi ysuYXS509VPvJGGY+O+qN4uWnKl8UZOJtQUZ53S71WDvMS7MY44MIkPRed5OKwKuHRNW OImw== 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=I2B4gVVCQM10Dll/DA/iXXFd89GTR6tRg5OAZRVt3Tw=; b=ShrV9mMzSDJ+iY8AeK81pQU1zAn5a0AYCr4Z6ruhBuPNdhmBByZn3GM2pj72OJQZoe iBhvxC/uxs1DWjYug20fZd1rwWMoAXGPmCyVlzRRB3HEumcIg8eQ5lYKC1lKJfGFA7V4 b7PR3baugAAWQZV6+EmhKuBj02LW8KiqfUjQ5G/6FLt3EjKDrlQMn3XY8UzZO1oXmquv ck+VQVjlfl7bKbn/JD8N3PtTFraLRlfTEO58BevIyoliCzUAL7LSB6kC9WDs59fn5BNE T2L+y+b8GXFKS0FvX9g83bm0XKg3TvLT+CklFw4c0tZOf/KcGcSxy8BtASz4XYj41WxP e1hA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QQXS2kZR; 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 y20-20020ac85f54000000b002f3644f0947si8676787qta.339.2022.05.03.13.57.38 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:57: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=QQXS2kZR; 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]:42850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzaU-0006V2-3c for patch@linaro.org; Tue, 03 May 2022 16:57:38 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40650) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0000lf-SI for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:00 -0400 Received: from mail-pg1-x536.google.com ([2607:f8b0:4864:20::536]:34433) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZt-0006O5-5F for qemu-devel@nongnu.org; Tue, 03 May 2022 15:52:59 -0400 Received: by mail-pg1-x536.google.com with SMTP id j70so3893578pge.1 for ; Tue, 03 May 2022 12:52:55 -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=I2B4gVVCQM10Dll/DA/iXXFd89GTR6tRg5OAZRVt3Tw=; b=QQXS2kZR9D/XqZ3UjTzin5KXDBIH1D80S4oQR5bNkOMNzgdfYE1MzNQFISfn5wZwWW 5QtbrAkGInS2Q9/RlFWdOiTM5yeckR2JSBKAUqszwUJ7R3rHLAsdqgW3lqAQrQ2LrkEH 6dZagMBTZ2Ees/qBm6MgX//AFUE7aRJlPXzixLzbd11AoY2afaehS7cBcVQRCZoDKZfi H127hNY915paun6WCD26GxKXSm64nD61I2fzjI9cqZQgm0FPSwiYoGaaJhEqYMmQZP+p 72egniGySfkcpAFokLWI20G8aSj0lEPhpFzz8GpfCMApvC45tf3v3YsuTWgfqQMRF+UB TVgg== 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=I2B4gVVCQM10Dll/DA/iXXFd89GTR6tRg5OAZRVt3Tw=; b=tf8ZNe0aCBKzOODoYGfzoO1d5+LrIUPUkl2n0s4Hm4LZMx4LUAYkGkOciRmkQUth6y KwMp5ujkBolkvYAB8MvaICF8RSzr7YnFoeyrUee4iz2eSECb7ne6WRrNQyNSX9tTWYQ6 XDO4UvhOTSdnsHFJXcHLbL9pE22MDtkYpkM2ZRA5FQ41QskpR1rqs1aSNa1jILXqDfrz fWcYge9Gm+iHDUZOvbxvhqtqEPstLJFIQZ68VyB7P/r5oaGjaXsyvs12TJBKDCyIM300 a9se+gQbVSx63OPPsiO3w9p+PtYWEn7bj20CIOD89Ct3HmqmfnT13GUEcMOw/aU+UT2b 93Qw== X-Gm-Message-State: AOAM531uMfJIAQHB/WQOau96FHc3hZn7hAPsfY4vMQyx7te2IM7C4iiJ TwJVJj/6V4+IpKTgRSpgw9ptQvW8sLPFOw== X-Received: by 2002:a62:d445:0:b0:50d:b868:47bc with SMTP id u5-20020a62d445000000b0050db86847bcmr17617527pfl.73.1651607574792; Tue, 03 May 2022 12:52:54 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:54 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 69/74] target/rx: Fix the base of the fixed vector table Date: Tue, 3 May 2022 12:48:38 -0700 Message-Id: <20220503194843.1379101-70-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::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" This begins at 0xffffff80 not 0xffffffc0. This has caused exceptions to wrap around to low memory instead of being at the top. Signed-off-by: Richard Henderson --- target/rx/helper.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/target/rx/helper.c b/target/rx/helper.c index f34945e7e2..c6e285657e 100644 --- a/target/rx/helper.c +++ b/target/rx/helper.c @@ -91,7 +91,7 @@ void rx_cpu_do_interrupt(CPUState *cs) cpu_stl_data(env, env->isp, env->pc); if (vec < 0x100) { - env->pc = cpu_ldl_data(env, 0xffffffc0 + vec * 4); + env->pc = cpu_ldl_data(env, 0xffffff80 + vec * 4); } else { env->pc = cpu_ldl_data(env, env->intb + (vec & 0xff) * 4); } From patchwork Tue May 3 19:48: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: 569008 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9805935map; Tue, 3 May 2022 13:47:01 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwmP6ia3Rm2EeSarbJvOF9bBON7WW/IgFykA1osDdgt7Qo4PfB1mQoDDUDcunTsd9uM7SoL X-Received: by 2002:a05:622a:1104:b0:2f3:8fe5:9f4b with SMTP id e4-20020a05622a110400b002f38fe59f4bmr16540132qty.481.1651610821729; Tue, 03 May 2022 13:47:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651610821; cv=none; d=google.com; s=arc-20160816; b=YV3T80BbjPUXMa4mTG9M1zQdIuXgT+uHS7Il2jZU/wOnyaKJ8ndHQLr6YeykSg8YY3 1MOEwGgIAEAjiBblmvjxqwgtWQuVUdtmH9ctAbX++cTN8xqWXbCBJ/vbBtoDwLyg9GHl Ud7zbw6oEQ7BPbT5A+OR1TrpYmEzZ6BjBEH/mKnMick+ESqtjsvIDS5P4MyIB3iXNCfe cbva7KUn4Nb43NOc5fJilTVfA+66XjPOIGRkI8ghI7v+wbvIwW+7Vn/zNupnmHQxnMa8 08sgVX00XcZvD3+XRQNWYReAsQWSR+MWSV/4hgw6q0FOIiBC4hisjh4LR2BPgvVhIqhE IaCw== 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=QUpRdJbpx7VQuY/FyAcpatmDIjI0TndHoNfi0QxhsFU=; b=k/J8pJ6hb37pRDbPeRn8xXFHkY73qpNf7RhK8zUVWFsh+RIKrcaqvqiUH6oWJ2Tx08 axQwdJkVzcU5AzUoqWzoFqVF0LgXJ8K9sxGLWKxMtD6tPFoi78qMIlUatcsH3A3SZRmk gT7/n4KAryioA9zqlwv8kStwzmzACJOsKCvUVGb0NkEdXd73r3YA7g9nCpG4Ag3D0vXz cW23nmJaLWcaXWDAXBUW/DKCUVSCjjI3b4WDixDkU+veRWdOD/ZhaI8a11KycSshcDsA caO9nGjuOBEcsX9KW2/0YF8hMoiDazA15n/J9HyniDsbP083AfBTVDTWfIDmy9HBUev3 vnjA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="d/t6hJXz"; 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 bs39-20020a05620a472700b0069f4031e6a7si933519qkb.469.2022.05.03.13.47.01 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:47: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="d/t6hJXz"; 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]:49528 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzQD-0004yM-7I for patch@linaro.org; Tue, 03 May 2022 16:47:01 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40652) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0000lg-Sk for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:01 -0400 Received: from mail-pj1-x1034.google.com ([2607:f8b0:4864:20::1034]:33363) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZt-0006Gc-5j for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:00 -0400 Received: by mail-pj1-x1034.google.com with SMTP id cu23-20020a17090afa9700b001d98d8e53b7so2552004pjb.0 for ; Tue, 03 May 2022 12:52:55 -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=QUpRdJbpx7VQuY/FyAcpatmDIjI0TndHoNfi0QxhsFU=; b=d/t6hJXzAb5M3+WOQp7wV86NfCYE4d6AXt80oxmT0/PtOCtTZaGFvn5EyPZsU7kL6e NMFXNNBShL/4WHgcZo66j8qOeuua1B5uSr8wlRK78Up1XITVYml87OW8sh2Ugg1HW1lx JnRC98H+kKrbJrFhMSs1wsnNZNcwEKksJ/fLcUMAPqjZs05lbmxiJZ0eCvjw1otj6UG4 2jeZbic3vK+8UKKIkLl8teG9T14Me69lpNB+McofFIAoDWAiMbcQlQRURwA1mHZuLzbT 4Np8MwmbGb/TBkoe/Baz7lYTnQaMri9mC5uOiZSs65yRM9gOvZTaKVsoeTF3kay6U3+u 4cWQ== 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=QUpRdJbpx7VQuY/FyAcpatmDIjI0TndHoNfi0QxhsFU=; b=jGP4Z069Xr3qjWYN93oEMOw0Dt+7Pf6n3cd3RgszIXNJezvfEWT8nHoFntt89VzkHx KFnl8HqQYiW9rso9ANfMddCNMFiJUOfAv0IfmMYN2NKR9mYPUFrPa7U8vHlyvl2wnFMc b2N5Xm1neAF+nJHtd0bkM4cotWCmU3Ar7lUUzdcA+g5L0LmjsgVlp79n8mIEQfy2nOOm nLCXI3mmfm2oD9Wh+p4Jhp0s/blGbQqIb1WgNqftNr/J5blv0Y8ldJnG2fuPAGvMFFob fLg8CdefOl3RvIMH08pA2rPqTs8Ne2Q7OwBDPeiZKZL7A1JiuI+xhnUvmSsfcoqn+44e WRvw== X-Gm-Message-State: AOAM531Jlr79kdHr3izZzQz9wDBRrr2zJ6eE6Uie2d1Jd+03Hs3tw57H x90SUubPKj1DPg9ss+DFjMr04N+bsuxmVA== X-Received: by 2002:a17:90b:3e8d:b0:1dc:3db4:920a with SMTP id rj13-20020a17090b3e8d00b001dc3db4920amr6470883pjb.161.1651607575518; Tue, 03 May 2022 12:52:55 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.54 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:55 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 70/74] target/rx: Name the exceptions Date: Tue, 3 May 2022 12:48:39 -0700 Message-Id: <20220503194843.1379101-71-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::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" Provide EXCP_* names to the fixed and relocatable vector table entries. Signed-off-by: Richard Henderson --- target/rx/cpu.h | 20 ++++++++++++++++++++ target/rx/helper.c | 25 ++++++++++++++++--------- target/rx/op_helper.c | 15 +++++++-------- 3 files changed, 43 insertions(+), 17 deletions(-) diff --git a/target/rx/cpu.h b/target/rx/cpu.h index 5655dffeff..99e28fb70f 100644 --- a/target/rx/cpu.h +++ b/target/rx/cpu.h @@ -66,6 +66,26 @@ enum { NUM_REGS = 16, }; +enum { + /* + * The Fixed Vector Table begins at 0xffffff80 and contains 32 entries, + * most of which are reserved. + */ + EXCP_PRIVILEGED = 20, + EXCP_ACCESS = 21, + EXCP_UNDEFINED = 23, + EXCP_FPU = 25, + EXCP_NMI = 30, + EXCP_RESET = 31, + + /* + * The Relocatable Vector Table begins at env->intb and + * contains 256 entries. + */ + EXCP_INTB_0 = 0x100, + EXCP_INTB_255 = EXCP_INTB_0 + 255, +}; + typedef struct CPUArchState { /* CPU registers */ uint32_t regs[NUM_REGS]; /* general registers */ diff --git a/target/rx/helper.c b/target/rx/helper.c index c6e285657e..29a4b075fa 100644 --- a/target/rx/helper.c +++ b/target/rx/helper.c @@ -83,36 +83,43 @@ void rx_cpu_do_interrupt(CPUState *cs) } } else { uint32_t vec = cs->exception_index; - const char *expname = "unknown exception"; + const char *expname; env->isp -= 4; cpu_stl_data(env, env->isp, save_psw); env->isp -= 4; cpu_stl_data(env, env->isp, env->pc); - if (vec < 0x100) { + if (vec < EXCP_INTB_0) { env->pc = cpu_ldl_data(env, 0xffffff80 + vec * 4); } else { - env->pc = cpu_ldl_data(env, env->intb + (vec & 0xff) * 4); + env->pc = cpu_ldl_data(env, env->intb + (vec - EXCP_INTB_0) * 4); } switch (vec) { - case 20: + case EXCP_PRIVILEGED: expname = "privilege violation"; break; - case 21: + case EXCP_ACCESS: expname = "access exception"; break; - case 23: + case EXCP_UNDEFINED: expname = "illegal instruction"; break; - case 25: + case EXCP_FPU: expname = "fpu exception"; break; - case 30: + case EXCP_NMI: expname = "non-maskable interrupt"; break; - case 0x100 ... 0x1ff: + case EXCP_RESET: + expname = "reset interrupt"; + break; + case EXCP_INTB_0 ... EXCP_INTB_255: expname = "unconditional trap"; + break; + default: + expname = "unknown exception"; + break; } qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n", (vec & 0xff), expname); diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c index 9ca32dcc82..6ab7b070bd 100644 --- a/target/rx/op_helper.c +++ b/target/rx/op_helper.c @@ -114,7 +114,7 @@ static void update_fpsw(CPURXState *env, float32 ret, uintptr_t retaddr) enable = FIELD_EX32(env->fpsw, FPSW, ENABLE); enable |= 1 << 5; /* CE always enabled */ if (cause & enable) { - raise_exception(env, 21, retaddr); + raise_exception(env, EXCP_FPU, retaddr); } } } @@ -420,8 +420,7 @@ uint32_t helper_divu(CPURXState *env, uint32_t num, uint32_t den) /* exception */ static inline G_NORETURN -void raise_exception(CPURXState *env, int index, - uintptr_t retaddr) +void raise_exception(CPURXState *env, int index, uintptr_t retaddr) { CPUState *cs = env_cpu(env); @@ -431,17 +430,17 @@ void raise_exception(CPURXState *env, int index, G_NORETURN void helper_raise_privilege_violation(CPURXState *env) { - raise_exception(env, 20, GETPC()); + raise_exception(env, EXCP_PRIVILEGED, GETPC()); } G_NORETURN void helper_raise_access_fault(CPURXState *env) { - raise_exception(env, 21, GETPC()); + raise_exception(env, EXCP_ACCESS, GETPC()); } G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) { - raise_exception(env, 23, GETPC()); + raise_exception(env, EXCP_UNDEFINED, GETPC()); } G_NORETURN void helper_wait(CPURXState *env) @@ -456,10 +455,10 @@ G_NORETURN void helper_wait(CPURXState *env) G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) { - raise_exception(env, 0x100 + vec, 0); + raise_exception(env, EXCP_INTB_0 + vec, 0); } G_NORETURN void helper_rxbrk(CPURXState *env) { - raise_exception(env, 0x100, 0); + raise_exception(env, EXCP_INTB_0, 0); } From patchwork Tue May 3 19:48: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: 569023 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9815971map; Tue, 3 May 2022 14:03:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwsK3x0OBimrlXI/ENJkjfutgm0TRcnuvCTzXqn6O54ZHL3xhx8gpw5gA5ptZbOfddlukZY X-Received: by 2002:ae9:e404:0:b0:69f:b141:9337 with SMTP id q4-20020ae9e404000000b0069fb1419337mr14047634qkc.783.1651611820443; Tue, 03 May 2022 14:03:40 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611820; cv=none; d=google.com; s=arc-20160816; b=RI15ufcmF8IMmju93XOX1Zm6grd7p0MFjTXItmw9eFphRvr5NaaEcPSHRtOPLl0ZSZ D7ob9MELDLXslLhf0/ilN9rimVEoTM1xUtOzLr0kteM8Icm0JppAObU6ZX/XBAHadx38 6PHI4cI/Q4YCBMfKGqfzl20sxOTePzmWMxq7ALQGPbebuDI0OLrsKJEMyx/ruBuKFk9i YlO97HGMH4Mv0EST3JtP+o36KbFmIG5swHyAH2pHwzUT7enTrOAs/QbftemewmX1d55P cV1lhLDpqNed4RF7ms/+TT+9W0NC3n0aRQrDlIue+xSWiCN8L6sO7Vec3rVZDeQtB22J m8NA== 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=l75mJLkyS62K5L377zFVSd2gu1rBBy1agq6hzSt3Vpo=; b=BOkYnvLBLng7Dwztj2ngotWl6ZGdcsHowoAlM0d9lWLhgAxjvHqzIjuM9rCjgPvHjg 8gw7Xh3YSBkmySMQpIR3r1QjEA3dJ6ZRLXGG8etmyNgfdK6vcZifQB6qnZYSr9UBJ7Gc 8VhAdWJV95uj8vLIpUaZ9qeCj55bcVAugmTCVkVHC9A18yqfVcYzhYOcrEGtoXxDV5in /AWwvphZWZ5JjbEPeRIbKl4fqX4qniqtFXmb08GtbHyDQ1iIAce+ukiCfLfle90NTLPt jRbZ5TU/6Czg5d2jGfpHV6UF6UYZFM4b8Gp8vnXfNzMOjoZuYfEfuvYHywCGAYACyhT/ /UUA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=AoBEQWbf; 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 bq32-20020a05620a46a000b0069eadc82ad8si9530186qkb.27.2022.05.03.14.03.40 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:03: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=AoBEQWbf; 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]:50840 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzgJ-0006at-MR for patch@linaro.org; Tue, 03 May 2022 17:03:40 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40686) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZz-0000nd-2L for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:03 -0400 Received: from mail-pj1-x102f.google.com ([2607:f8b0:4864:20::102f]:46712) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZv-0006OH-31 for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:01 -0400 Received: by mail-pj1-x102f.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso2880353pjb.5 for ; Tue, 03 May 2022 12:52:57 -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=l75mJLkyS62K5L377zFVSd2gu1rBBy1agq6hzSt3Vpo=; b=AoBEQWbfAB7HJwFtFMDqPiV4GJRQfgl0Ue/SdQi67z3yELsujJI4hl/iiz5+MFqKNr gb3B/oexgaBUMSPChdbyt30TNNwO3upw9UKEr0+IiowBb4W2uwpOiC3+m0enuQMa7sf+ O6sr5brQcNdgkd0Uv5YyRLXvlHAtBILQM/cIaM5nGynLiXbm0ngtJxunmYgEbAqWsW9I Sz/leRGCyKz8I5gVnRxJgxoEOK3m78xnWm0kDQbcFoqHSui5UAMYl4/09cd83aWr0b+e y75WWJf/vucL6by+Nta4loXuD0AQuJcov2sEKkSp+lk/x1VBWGGGh9MEB+CGQi77cQwZ akcQ== 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=l75mJLkyS62K5L377zFVSd2gu1rBBy1agq6hzSt3Vpo=; b=jHvU/57tYycCpkd6yNpgg+HuRd08pZouDnDZrP6ssGdnHsWV5hoxgWdEtZYBdK20Mg Q3AJFF/FRMwLYDWbPKxQ/p0+EEtnglIzLm1G8MNJ5UWLAY/HmoPfS9Zlf1Y7Kxzmoqhx Vjy2h83SYov25rr0tAHbAvlvN9BKqAsOGbumgYreVP7elzTwSBnAeNV+c/orcK3PGszS ixzTBfPQTLCxoQONeS6oeowyTm5NCxIeNCYjMzGacEtxwsurikhiRzs3HD4tp9D+IHVj G74BLY659aiXmJ0wJEZONHElBLQ9yA7JiGbLqaWF+B2/xyDj0Eyo4zgbEUKMV4R1ReCy VYbQ== X-Gm-Message-State: AOAM532Cx8byqLDqH0JfJx5N/eKxipjfMzYBySCF1MfJEIeI5y/ybSbg UO42qx6Z8w5VB3pzWTekjxn2oEyyyde1qQ== X-Received: by 2002:a17:90a:c595:b0:1d9:532e:52fd with SMTP id l21-20020a17090ac59500b001d9532e52fdmr6542620pjt.79.1651607576483; Tue, 03 May 2022 12:52:56 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.55 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:56 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 71/74] target/rx: Consolidate exception helpers Date: Tue, 3 May 2022 12:48:40 -0700 Message-Id: <20220503194843.1379101-72-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::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" Replace 5 helpers with 1. Store pc before raising privileged and undefined instruction exceptions, which means we don't need to use tcg unwinding. Signed-off-by: Richard Henderson --- target/rx/helper.h | 6 +----- target/rx/op_helper.c | 25 ++++--------------------- target/rx/translate.c | 23 +++++++++++------------ 3 files changed, 16 insertions(+), 38 deletions(-) diff --git a/target/rx/helper.h b/target/rx/helper.h index ebb4739474..e6763b5a90 100644 --- a/target/rx/helper.h +++ b/target/rx/helper.h @@ -1,9 +1,5 @@ -DEF_HELPER_1(raise_illegal_instruction, noreturn, env) -DEF_HELPER_1(raise_access_fault, noreturn, env) -DEF_HELPER_1(raise_privilege_violation, noreturn, env) +DEF_HELPER_2(raise_exception, noreturn, env, i32) DEF_HELPER_1(wait, noreturn, env) -DEF_HELPER_2(rxint, noreturn, env, i32) -DEF_HELPER_1(rxbrk, noreturn, env) DEF_HELPER_FLAGS_3(fadd, TCG_CALL_NO_WG, f32, env, f32, f32) DEF_HELPER_FLAGS_3(fsub, TCG_CALL_NO_WG, f32, env, f32, f32) DEF_HELPER_FLAGS_3(fmul, TCG_CALL_NO_WG, f32, env, f32, f32) diff --git a/target/rx/op_helper.c b/target/rx/op_helper.c index 6ab7b070bd..f2b58bcad5 100644 --- a/target/rx/op_helper.c +++ b/target/rx/op_helper.c @@ -428,19 +428,12 @@ void raise_exception(CPURXState *env, int index, uintptr_t retaddr) cpu_loop_exit_restore(cs, retaddr); } -G_NORETURN void helper_raise_privilege_violation(CPURXState *env) +G_NORETURN void helper_raise_exception(CPURXState *env, uint32_t index) { - raise_exception(env, EXCP_PRIVILEGED, GETPC()); -} + CPUState *cs = env_cpu(env); -G_NORETURN void helper_raise_access_fault(CPURXState *env) -{ - raise_exception(env, EXCP_ACCESS, GETPC()); -} - -G_NORETURN void helper_raise_illegal_instruction(CPURXState *env) -{ - raise_exception(env, EXCP_UNDEFINED, GETPC()); + cs->exception_index = index; + cpu_loop_exit(cs); } G_NORETURN void helper_wait(CPURXState *env) @@ -452,13 +445,3 @@ G_NORETURN void helper_wait(CPURXState *env) env->psw_i = 1; raise_exception(env, EXCP_HLT, 0); } - -G_NORETURN void helper_rxint(CPURXState *env, uint32_t vec) -{ - raise_exception(env, EXCP_INTB_0 + vec, 0); -} - -G_NORETURN void helper_rxbrk(CPURXState *env) -{ - raise_exception(env, EXCP_INTB_0, 0); -} diff --git a/target/rx/translate.c b/target/rx/translate.c index 62aee66937..ddf31afb11 100644 --- a/target/rx/translate.c +++ b/target/rx/translate.c @@ -156,6 +156,13 @@ static void gen_goto_tb(DisasContext *dc, int n, target_ulong dest) dc->base.is_jmp = DISAS_NORETURN; } +static void gen_raise_exception(DisasContext *ctx, int vec, bool advance_pc) +{ + tcg_gen_movi_i32(cpu_pc, advance_pc ? ctx->base.pc_next : ctx->pc); + gen_helper_raise_exception(cpu_env, tcg_constant_i32(vec)); + ctx->base.is_jmp = DISAS_NORETURN; +} + /* generic load wrapper */ static inline void rx_gen_ld(unsigned int size, TCGv reg, TCGv mem) { @@ -234,7 +241,7 @@ static int is_privileged(DisasContext *ctx, int is_exception) { if (FIELD_EX32(ctx->tb_flags, PSW, PM)) { if (is_exception) { - gen_helper_raise_privilege_violation(cpu_env); + gen_raise_exception(ctx, EXCP_PRIVILEGED, false); } return 0; } else { @@ -2261,23 +2268,15 @@ static bool trans_RTE(DisasContext *ctx, arg_RTE *a) /* brk */ static bool trans_BRK(DisasContext *ctx, arg_BRK *a) { - tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next); - gen_helper_rxbrk(cpu_env); - ctx->base.is_jmp = DISAS_NORETURN; + gen_raise_exception(ctx, EXCP_INTB_0, true); return true; } /* int #imm */ static bool trans_INT(DisasContext *ctx, arg_INT *a) { - TCGv vec; - tcg_debug_assert(a->imm < 0x100); - vec = tcg_const_i32(a->imm); - tcg_gen_movi_i32(cpu_pc, ctx->base.pc_next); - gen_helper_rxint(cpu_env, vec); - tcg_temp_free(vec); - ctx->base.is_jmp = DISAS_NORETURN; + gen_raise_exception(ctx, EXCP_INTB_0 + a->imm, true); return true; } @@ -2318,7 +2317,7 @@ static void rx_tr_translate_insn(DisasContextBase *dcbase, CPUState *cs) ctx->pc = ctx->base.pc_next; insn = decode_load(ctx); if (!decode(ctx, insn)) { - gen_helper_raise_illegal_instruction(cpu_env); + gen_raise_exception(ctx, EXCP_UNDEFINED, false); } } From patchwork Tue May 3 19:48: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: 569029 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9825061map; Tue, 3 May 2022 14:15:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxbph5oz4HCgI3J6MH2q4WsqSVmc+the+uqFV2ZcKdgOnO/+f1+H6jdVxG2GnEwcs8ijF+R X-Received: by 2002:a05:622a:14cb:b0:2e1:9fc5:424d with SMTP id u11-20020a05622a14cb00b002e19fc5424dmr16208480qtx.543.1651612548338; Tue, 03 May 2022 14:15:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651612548; cv=none; d=google.com; s=arc-20160816; b=ifkKJs3tmeGpI1jX8YQ4O4Qt6gTYdBkTxlTh72z/1PPd3EtFv9BEejqD5fZKTc0/FH 5hxNfiSHilxJlN3y+3iAhg2nzFa70iKgp6bq5kBHbtZxSsklyRTJz4wz2THu+gM0wUcK F+Ks9oq/7h09DOpWXVXFezwxOoylv+jQVqOrHZyKmKzyDuMRUanzYdYCNMm1gVMeoAgE qbbOHjPkel8loffwnJvO8NjDc1i66ZvrWm/C0NBY+UEcg6ELZUCb0p2A3oZsvQ8IuLbM y+Y1cty/ejGBQxlScd5/TLFlEmeK7dkXi1rHST/ZoF3lwEaEIVlZJOTwpMscAJraxrJ1 Y1Lw== 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=zSABYP4n5j9DpaRkrATAbL9o0CDfndEvUo9tSY+Ych0=; b=KzDF/vf5Rhh/w4Q6VEwOJtzws4GzWoFl7Jn3Rr6Qr9SbI86bNVpkh3kf/PWkRUQOQo j4vNh05xgkb7TR5eVNX91/MBFBvUDTbxa6qg2sOuO80LM8KZ7BXGo80yJAZL+16RlFIC WzC6/OsU2AERifW07jaS4eD7QHb43h9a/0iXWCFw+FGck9X1wFD5t09giPH4so7UJwhM fcWZpvjf7FpFSKXrNF0zxUgD0tFmWiG62kEkOK6aDVJ12XDHzJHUCfEQo4s9rCPvDo2c MhIbBZG4szNslcwgV6ryASwT3oqHhf1sllO9ZHm+VwbD1dIMQVqX0BbEnXzJu8wPz+Ve LuEA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=Ef5saaaj; 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 i12-20020a05620a404c00b0069ffcc17816si1261999qko.109.2022.05.03.14.15.48 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 14:15: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=Ef5saaaj; 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]:44448 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzs1-0007av-9R for patch@linaro.org; Tue, 03 May 2022 17:15:45 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40688) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZz-0000ne-1v for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:03 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:44608) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0006Ob-KO for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:02 -0400 Received: by mail-pl1-x631.google.com with SMTP id j8so15862848pll.11 for ; Tue, 03 May 2022 12:52:58 -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=zSABYP4n5j9DpaRkrATAbL9o0CDfndEvUo9tSY+Ych0=; b=Ef5saaaj5hJEJ5KnBAj9hB8RkLBpZoilw0vNu9Y3kretFp+rixJqjwjb5OgVeoOZOv 95w+s4jSQy/Qf8+nS+0LqYUeujvC+33YGLo8MmvM0coZRVplTGOAnT0NlhALh3smsAl8 stiPFR4BmWm9SiUwjh3J3QVjtah/CCIv6UwZgbDkmNo7vkKL94QdDbSfOIERJAWiG8T4 v7WwQh/sEMviMyLe1/hmvBiknQzVmkzD125DPODM3Jg2MzVPBgIxo+se/8MtelNCt1HZ 76w15DFW7VFbIM0Ds/wmGNlIe2Ft7Hpvn9+Om190W78t8G1aftNJwGkLGDyHs8VpvagX 3YvQ== 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=zSABYP4n5j9DpaRkrATAbL9o0CDfndEvUo9tSY+Ych0=; b=XHMDvofTFzgmf3HcHyfnXUtfSwTV3P6xnrBxekvucOleA2JDg3Zkx2FcUa9XgX5CDx by9bCge3WXFeTpBukcHuWrt9aVDKLujr5XNmUEsT+wyPbZ52tWoy1b9V1TLYsXGCHU4/ 9TUkyrbh2wbPzY9MirgJiI4owNMFLcWtFY/jdE26E/odKuL3FGE8zH7UQSuQFheX0r79 zu9v9z0HkjjCaXo82mzHmnMix1YucpyzNlLLdsc+2yio2YSP7ezJr8Sj7llZFRMcG+7Z E1lD62wkGQCrD+BK8CmJjlpWHcgVtmT536oP5kyHIiSPBDA/rPOrF7yxkEgtq2Q4g0dJ VG5A== X-Gm-Message-State: AOAM533gkQW0GFTVtNN4i9AWad5Gee7k4poPqPi+6EZbkaZe+LSy6WXY SFHVgHBj8qaBvoi70o3nPpWSLWmHO+JgHA== X-Received: by 2002:a17:90b:1c04:b0:1dc:4dfd:5a43 with SMTP id oc4-20020a17090b1c0400b001dc4dfd5a43mr6628138pjb.160.1651607577572; Tue, 03 May 2022 12:52:57 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:57 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 72/74] target/rx: Cleanup rx_cpu_do_interrupt Date: Tue, 3 May 2022 12:48:41 -0700 Message-Id: <20220503194843.1379101-73-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::631; envelope-from=richard.henderson@linaro.org; helo=mail-pl1-x631.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" Introduce EXCP_IRQ and EXCP_FIRQ to remember the decision that we made in rx_cpu_exec_interrupt. Use a switch to select between exceptions; unify stacked interrupt frame creation; abort if unknown exception. Signed-off-by: Richard Henderson --- target/rx/cpu.h | 4 ++ target/rx/helper.c | 118 ++++++++++++++++++++++----------------------- 2 files changed, 61 insertions(+), 61 deletions(-) diff --git a/target/rx/cpu.h b/target/rx/cpu.h index 99e28fb70f..5b93c0dcb0 100644 --- a/target/rx/cpu.h +++ b/target/rx/cpu.h @@ -84,6 +84,10 @@ enum { */ EXCP_INTB_0 = 0x100, EXCP_INTB_255 = EXCP_INTB_0 + 255, + + /* Private to the qemu implementation. */ + EXCP_IRQ, + EXCP_FIRQ, }; typedef struct CPUArchState { diff --git a/target/rx/helper.c b/target/rx/helper.c index 29a4b075fa..d12e551cc2 100644 --- a/target/rx/helper.c +++ b/target/rx/helper.c @@ -42,12 +42,13 @@ void rx_cpu_unpack_psw(CPURXState *env, uint32_t psw, int rte) #ifndef CONFIG_USER_ONLY -#define INT_FLAGS (CPU_INTERRUPT_HARD | CPU_INTERRUPT_FIR) void rx_cpu_do_interrupt(CPUState *cs) { RXCPU *cpu = RX_CPU(cs); CPURXState *env = &cpu->env; - int do_irq = cs->interrupt_request & INT_FLAGS; + uint32_t vec = cs->exception_index; + target_ulong vec_table = 0xffffff80u; /* fixed vector table */ + const char *expname; uint32_t save_psw; env->in_sleep = 0; @@ -60,69 +61,62 @@ void rx_cpu_do_interrupt(CPUState *cs) save_psw = rx_cpu_pack_psw(env); env->psw_pm = env->psw_i = env->psw_u = 0; - if (do_irq) { - if (do_irq & CPU_INTERRUPT_FIR) { - env->bpc = env->pc; - env->bpsw = save_psw; - env->pc = env->fintv; - env->psw_ipl = 15; - cs->interrupt_request &= ~CPU_INTERRUPT_FIR; - qemu_set_irq(env->ack, env->ack_irq); - qemu_log_mask(CPU_LOG_INT, "fast interrupt raised\n"); - } else if (do_irq & CPU_INTERRUPT_HARD) { - env->isp -= 4; - cpu_stl_data(env, env->isp, save_psw); - env->isp -= 4; - cpu_stl_data(env, env->isp, env->pc); - env->pc = cpu_ldl_data(env, env->intb + env->ack_irq * 4); - env->psw_ipl = env->ack_ipl; - cs->interrupt_request &= ~CPU_INTERRUPT_HARD; - qemu_set_irq(env->ack, env->ack_irq); - qemu_log_mask(CPU_LOG_INT, - "interrupt 0x%02x raised\n", env->ack_irq); - } - } else { - uint32_t vec = cs->exception_index; - const char *expname; + switch (vec) { + case EXCP_FIRQ: + env->bpc = env->pc; + env->bpsw = save_psw; + env->pc = env->fintv; + env->psw_ipl = 15; + cs->interrupt_request &= ~CPU_INTERRUPT_FIR; + qemu_set_irq(env->ack, env->ack_irq); + qemu_log_mask(CPU_LOG_INT, "fast interrupt raised\n"); + break; + case EXCP_IRQ: + env->psw_ipl = env->ack_ipl; + cs->interrupt_request &= ~CPU_INTERRUPT_HARD; + qemu_set_irq(env->ack, env->ack_irq); + expname = "interrupt"; + vec_table = env->intb; + vec = env->ack_ipl; + goto do_stacked; + + case EXCP_PRIVILEGED: + expname = "privilege violation"; + goto do_stacked; + case EXCP_ACCESS: + expname = "access exception"; + goto do_stacked; + case EXCP_UNDEFINED: + expname = "illegal instruction"; + goto do_stacked; + case EXCP_FPU: + expname = "fpu exception"; + goto do_stacked; + case EXCP_NMI: + expname = "non-maskable interrupt"; + goto do_stacked; + case EXCP_RESET: + expname = "reset interrupt"; + goto do_stacked; + + case EXCP_INTB_0 ... EXCP_INTB_255: + expname = "unconditional trap"; + vec_table = env->intb; + vec -= EXCP_INTB_0; + goto do_stacked; + + do_stacked: env->isp -= 4; cpu_stl_data(env, env->isp, save_psw); env->isp -= 4; cpu_stl_data(env, env->isp, env->pc); + env->pc = cpu_ldl_data(env, vec_table + vec * 4); + qemu_log_mask(CPU_LOG_INT, "%s raised (0x%02x)\n", expname, vec); + break; - if (vec < EXCP_INTB_0) { - env->pc = cpu_ldl_data(env, 0xffffff80 + vec * 4); - } else { - env->pc = cpu_ldl_data(env, env->intb + (vec - EXCP_INTB_0) * 4); - } - switch (vec) { - case EXCP_PRIVILEGED: - expname = "privilege violation"; - break; - case EXCP_ACCESS: - expname = "access exception"; - break; - case EXCP_UNDEFINED: - expname = "illegal instruction"; - break; - case EXCP_FPU: - expname = "fpu exception"; - break; - case EXCP_NMI: - expname = "non-maskable interrupt"; - break; - case EXCP_RESET: - expname = "reset interrupt"; - break; - case EXCP_INTB_0 ... EXCP_INTB_255: - expname = "unconditional trap"; - break; - default: - expname = "unknown exception"; - break; - } - qemu_log_mask(CPU_LOG_INT, "exception 0x%02x [%s] raised\n", - (vec & 0xff), expname); + default: + g_assert_not_reached(); } env->regs[0] = env->isp; } @@ -132,19 +126,21 @@ bool rx_cpu_exec_interrupt(CPUState *cs, int interrupt_request) RXCPU *cpu = RX_CPU(cs); CPURXState *env = &cpu->env; int accept = 0; + /* hardware interrupt (Normal) */ if ((interrupt_request & CPU_INTERRUPT_HARD) && env->psw_i && (env->psw_ipl < env->req_ipl)) { env->ack_irq = env->req_irq; env->ack_ipl = env->req_ipl; - accept = 1; + accept = EXCP_IRQ; } /* hardware interrupt (FIR) */ if ((interrupt_request & CPU_INTERRUPT_FIR) && env->psw_i && (env->psw_ipl < 15)) { - accept = 1; + accept = EXCP_FIRQ; } if (accept) { + cs->exception_index = accept; rx_cpu_do_interrupt(cs); return true; } From patchwork Tue May 3 19:48: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: 569016 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9810104map; Tue, 3 May 2022 13:54:17 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyrC3mJJx+WhG0uxd2itTu+JYhnH8brNAvZdjN2EO6Fsvy3TDrK6WfVO9mBHSh4uOEjOcYD X-Received: by 2002:a05:6214:2522:b0:456:3eb8:17dc with SMTP id gg2-20020a056214252200b004563eb817dcmr15298897qvb.78.1651611257228; Tue, 03 May 2022 13:54:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611257; cv=none; d=google.com; s=arc-20160816; b=ottk4gtbbjQmuwMShqkbuvqFl3rQ/J6cDUIuVPeg9PUlBHVnYvKdNykuqo2GKHvtXY C6l1p5BEVXROlOZADDjeg7uJ0z+Ox920RcsIpEZuMKQ5nEhhWh+FYLzpCWKC/bBXyvU8 H+5JWqxXOdkLTKEI5r4dWxPbnckI5g89lCiJl0DrfA0SR+xL8H3brghUz3fWKvK27C7E Pb9bvo6ZWYwaD7PX/fHQXEvH9r9W8dZnCX0h+EfKeWxLjbzBzuG2ADu8CZDFrvHqD6Tl 7V2WahVNvICawVkibEF6UnN2HPSZvkqR5NWr3n+CUKQlJPwWqIc+rl5J84HSC4F2LTWK xvNQ== 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=M6M9lcOtJHcXS0OKn/tF20xzatLhV5u4RJXc0wtgF7E=; b=A8Fs6yqjbuqOVsJgY8YxfkCooSy86+uut1PHcxUjD9Q+IvIYEXMbvNipApF8kDeqkB ehcyy/z+FcjnNhml/DRQ33bhopmDMsJB5/2IUc6IhBYp6pR3Nio8wuHIilICTT2f9iME ReTAL5eWHz+bQT+X/7ZiT0xB6wc3IAZuXOTGXz4PK4SQhuigu8FQbpG0UQnBh3swWlGi lTnKIVeH/bI0dYH8n4/ICUG9jo0MbYVy0X7mxMmzSi9H3GKCir2dow5CeU2x6vhhbd0R sR3yQL+Dv0BFutfoRspXGnJsRuKoJcYlH3qnNGJ4+ER/tAaChZMTUdS37zJGLNAnEiCK 9IEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=IIsJn8nE; 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 a19-20020a05622a02d300b002f368c7dc14si4018555qtx.719.2022.05.03.13.54.17 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:54: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=IIsJn8nE; 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]:37058 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzXD-0000ah-Kv for patch@linaro.org; Tue, 03 May 2022 16:54:16 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40690) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlyZz-0000np-3s for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:03 -0400 Received: from mail-pj1-x1031.google.com ([2607:f8b0:4864:20::1031]:46714) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZw-0006Og-Kq for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:02 -0400 Received: by mail-pj1-x1031.google.com with SMTP id cq17-20020a17090af99100b001dc0386cd8fso2880402pjb.5 for ; Tue, 03 May 2022 12:52:59 -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=M6M9lcOtJHcXS0OKn/tF20xzatLhV5u4RJXc0wtgF7E=; b=IIsJn8nEcvEVsQqLbbj1DUQtXzbnRWqguqyho+nZiwXNBOZ5dfHa3hR8kiiiBONZC3 4jOsJsqzg3aS3ACXD8H90Lro2pvSo90S9tSUhO+dpJyQo6ubzEMP3qIpL7fvOy5/lhTY 8tSDF9Rpk89ej0lsjyPh8Ki603PpRy2VHfizlqbrqu5cXKj+pif+H54GZkiQfAJlLEb4 tWTspQEpblWTN3B6ELHSFdVpDagW4ga/L4A36Kd660wmgXCPl5IcIL09LaC5AF62Qqdh HUyC/p9sjADWFKF3+mahYgJ6bbPPETUT1urhxL0f9FDWfuHjxPNbiIGaHRDJc5Jow4e9 Kzng== 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=M6M9lcOtJHcXS0OKn/tF20xzatLhV5u4RJXc0wtgF7E=; b=32KwjiEVHRX8e/7+lvZ5AAL/V+ic051TMsdQcNCUCwTXiNiz1+tvOTIuF3LIDqTna8 cnB+qXcYAMbdoEibfY4dbjzb7mpfvU6EQBRd8jF1UyYcj4h3uxPSEWkIxs0xnSVKgM3O ma+60ZPy4uXYsVfvXTgW9BlI0D/TnbvSyOCqGpvQQZxbbHExgx2bDjxLOhWVa8iZDWrD UCol5B6NRSjJnxYb4Kro5FD7GOsswvfKbfT41+5VGCRXOhmj711SCA20W231H0XaGoid +Tv4d5oOJ6ZqEe+gmnobaO1hfD+oR/ycfjiYB5hqJLZIPG1QgfsxYGuoyHNLFmykCL2H jPQQ== X-Gm-Message-State: AOAM5308WhvWa+cRG7W+A5Z8s1TyILVfkYMqKRO5oPWFU9gfwa86DMOe ay/4WdDzZwieteZpSU5XlkFrewWMBfw5/Q== X-Received: by 2002:a17:903:3009:b0:15c:f92b:7fba with SMTP id o9-20020a170903300900b0015cf92b7fbamr18075831pla.82.1651607578586; Tue, 03 May 2022 12:52:58 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.57 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:52:58 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 73/74] target/rx: Implement libgloss semihosting Date: Tue, 3 May 2022 12:48:42 -0700 Message-Id: <20220503194843.1379101-74-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::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: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: "Qemu-devel" Signed-off-by: Richard Henderson --- configs/devices/rx-softmmu/default.mak | 1 + target/rx/cpu.h | 2 + target/rx/helper.c | 5 + target/rx/rx-semi.c | 165 +++++++++++++++++++++++++ target/rx/translate.c | 7 +- qemu-options.hx | 13 +- target/rx/meson.build | 4 +- 7 files changed, 189 insertions(+), 8 deletions(-) create mode 100644 target/rx/rx-semi.c diff --git a/configs/devices/rx-softmmu/default.mak b/configs/devices/rx-softmmu/default.mak index df2b4e4f42..5c1033a2d3 100644 --- a/configs/devices/rx-softmmu/default.mak +++ b/configs/devices/rx-softmmu/default.mak @@ -1,3 +1,4 @@ # Default configuration for rx-softmmu CONFIG_RX_GDBSIM=y +CONFIG_SEMIHOSTING=y diff --git a/target/rx/cpu.h b/target/rx/cpu.h index 5b93c0dcb0..117cfea027 100644 --- a/target/rx/cpu.h +++ b/target/rx/cpu.h @@ -88,6 +88,7 @@ enum { /* Private to the qemu implementation. */ EXCP_IRQ, EXCP_FIRQ, + EXCP_SEMIHOST, }; typedef struct CPUArchState { @@ -147,6 +148,7 @@ const char *rx_crname(uint8_t cr); #ifndef CONFIG_USER_ONLY void rx_cpu_do_interrupt(CPUState *cpu); bool rx_cpu_exec_interrupt(CPUState *cpu, int int_req); +void rx_cpu_do_semihosting(CPURXState *env); #endif /* !CONFIG_USER_ONLY */ void rx_cpu_dump_state(CPUState *cpu, FILE *f, int flags); int rx_cpu_gdb_read_register(CPUState *cpu, GByteArray *buf, int reg); diff --git a/target/rx/helper.c b/target/rx/helper.c index d12e551cc2..00f72b2090 100644 --- a/target/rx/helper.c +++ b/target/rx/helper.c @@ -53,6 +53,11 @@ void rx_cpu_do_interrupt(CPUState *cs) env->in_sleep = 0; + if (vec == EXCP_SEMIHOST) { + rx_cpu_do_semihosting(env); + return; + } + if (env->psw_u) { env->usp = env->regs[0]; } else { diff --git a/target/rx/rx-semi.c b/target/rx/rx-semi.c new file mode 100644 index 0000000000..f2406ad219 --- /dev/null +++ b/target/rx/rx-semi.c @@ -0,0 +1,165 @@ +/* + * gdbsim semihosting syscall interface. + * The semihosting protocol implemented here is described in + * + * libgloss sources: + * https://sourceware.org/git/gitweb.cgi?p=newlib-cygwin.git;a=blob;f=libgloss/syscall.h;hb=HEAD + * + * gdb sources: + * https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;a=blob;f=sim/rx/syscalls.c;hb=HEAD + * + * Copyright (c) 2022 Linaro, Ltd. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include "qemu/osdep.h" +#include "cpu.h" +#include "exec/gdbstub.h" +#include "semihosting/syscalls.h" +#include "qemu/log.h" + +/* + * These are the syscall numbers from libgloss/syscall.h, + * but note that not all of them are implemented. + */ +enum { + TARGET_SYS_exit = 1, + TARGET_SYS_open, + TARGET_SYS_close, + TARGET_SYS_read, + TARGET_SYS_write, + TARGET_SYS_lseek, + TARGET_SYS_unlink, + TARGET_SYS_getpid, + TARGET_SYS_kill, + TARGET_SYS_fstat, + TARGET_SYS_sbrk, + TARGET_SYS_argvlen, + TARGET_SYS_argv, + TARGET_SYS_chdir, + TARGET_SYS_stat, + TARGET_SYS_chmod, + TARGET_SYS_utime, + TARGET_SYS_time, + TARGET_SYS_gettimeofday, + TARGET_SYS_times, + TARGET_SYS_link, + TARGET_SYS_argc, + TARGET_SYS_argnlen, + TARGET_SYS_argn, + TARGET_SYS_reconfig, +}; + +static void rx_semi_cb(CPUState *cs, uint64_t ret, int err) +{ + CPURXState *env = cs->env_ptr; + + /* There is no concept of errno in this interface. */ + env->regs[1] = ret; +} + +static bool rx_semi_arg(CPURXState *env, uint32_t *ret, int argn) +{ + if (argn < 4) { + *ret = env->regs[argn + 1]; + } else { + uint32_t stack_addr = env->regs[0] + 4 + (argn - 4) * 4; + if (cpu_memory_rw_debug(env_cpu(env), stack_addr, ret, 4, 0)) { + return false; + } + tswap32s(ret); + } + return true; +} + +#define GET_ARG(E, N) \ + ({ uint32_t v_; if (!rx_semi_arg((E), &v_, (N))) goto failed; v_; }) + +void rx_cpu_do_semihosting(CPURXState *env) +{ + CPUState *cs = env_cpu(env); + uint32_t nr = env->regs[5]; + uint32_t a0, a1, a2; + + switch (nr) { + case TARGET_SYS_exit: + a0 = GET_ARG(env, 0); + gdb_exit(a0); + exit(a0); + + case TARGET_SYS_open: + /* + * This function is declared int open(char *path, int flags, ...), + * which means that only the first argument is in registers. + */ + a0 = GET_ARG(env, 0); + a1 = GET_ARG(env, 4); + a2 = GET_ARG(env, 5); + semihost_sys_open(cs, rx_semi_cb, a0, 0, a1, a2); + break; + + case TARGET_SYS_close: + a0 = GET_ARG(env, 0); + semihost_sys_close(cs, rx_semi_cb, a0); + break; + + case TARGET_SYS_read: + a0 = GET_ARG(env, 0); + a1 = GET_ARG(env, 1); + a2 = GET_ARG(env, 2); + semihost_sys_read(cs, rx_semi_cb, a0, a1, a2); + break; + + case TARGET_SYS_write: + a0 = GET_ARG(env, 0); + a1 = GET_ARG(env, 1); + a2 = GET_ARG(env, 2); + semihost_sys_write(cs, rx_semi_cb, a0, a1, a2); + break; + + case TARGET_SYS_getpid: + rx_semi_cb(cs, 42, 0); + break; + + case TARGET_SYS_gettimeofday: + a0 = GET_ARG(env, 0); + semihost_sys_gettimeofday(cs, rx_semi_cb, a0, 0); + break; + + case TARGET_SYS_kill: + a0 = GET_ARG(env, 0); + if (a0 != 42) { + goto failed; + } + /* Without defined signal numbers, pretend they're all SIGABRT. */ + gdb_exit(-1); + abort(); + + default: + qemu_log_mask(LOG_GUEST_ERROR, "rx-semihosting: unsupported " + "semihosting syscall %u\n", nr); + /* fall through */ + + failed: + rx_semi_cb(cs, -1, 0); + break; + } + + /* + * Skip the semihosting insn (int #255). + * Must be done after any cpu_loop_exit() within the syscalls. + */ + env->pc += 3; +} diff --git a/target/rx/translate.c b/target/rx/translate.c index ddf31afb11..4a072661ca 100644 --- a/target/rx/translate.c +++ b/target/rx/translate.c @@ -27,6 +27,7 @@ #include "exec/helper-gen.h" #include "exec/translator.h" #include "exec/log.h" +#include "semihosting/semihost.h" typedef struct DisasContext { DisasContextBase base; @@ -2276,7 +2277,11 @@ static bool trans_BRK(DisasContext *ctx, arg_BRK *a) static bool trans_INT(DisasContext *ctx, arg_INT *a) { tcg_debug_assert(a->imm < 0x100); - gen_raise_exception(ctx, EXCP_INTB_0 + a->imm, true); + if (semihosting_enabled() && a->imm == 0xff) { + gen_raise_exception(ctx, EXCP_SEMIHOST, false); + } else { + gen_raise_exception(ctx, EXCP_INTB_0 + a->imm, true); + } return true; } diff --git a/qemu-options.hx b/qemu-options.hx index 5f69b94b8e..4feb969b14 100644 --- a/qemu-options.hx +++ b/qemu-options.hx @@ -4530,10 +4530,11 @@ ERST DEF("semihosting", 0, QEMU_OPTION_semihosting, "-semihosting semihosting mode\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | - QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) + QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV | QEMU_ARCH_RX) SRST ``-semihosting`` - Enable semihosting mode (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V only). + Enable semihosting mode + (Only ARM, M68K, Xtensa, MIPS, Nios II, RISC-V, RX). Note that this allows guest direct access to the host filesystem, so should only be used with a trusted guest OS. @@ -4545,11 +4546,11 @@ DEF("semihosting-config", HAS_ARG, QEMU_OPTION_semihosting_config, "-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]\n" \ " semihosting configuration\n", QEMU_ARCH_ARM | QEMU_ARCH_M68K | QEMU_ARCH_XTENSA | -QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV) +QEMU_ARCH_MIPS | QEMU_ARCH_NIOS2 | QEMU_ARCH_RISCV | QEMU_ARCH_RX) SRST ``-semihosting-config [enable=on|off][,target=native|gdb|auto][,chardev=id][,arg=str[,...]]`` - Enable and configure semihosting (ARM, M68K, Xtensa, MIPS, Nios II, RISC-V - only). + Enable and configure semihosting + (Only ARM, M68K, Xtensa, MIPS, Nios II, RISC-V, RX). Note that this allows guest direct access to the host filesystem, so should only be used with a trusted guest OS. @@ -4557,7 +4558,7 @@ SRST On Arm this implements the standard semihosting API, version 2.0. On M68K this implements the "ColdFire GDB" interface used by - libgloss. + libgloss. Nios II and RX also use the libgloss interface. Xtensa semihosting provides basic file IO calls, such as open/read/write/seek/select. Tensilica baremetal libc for ISS and diff --git a/target/rx/meson.build b/target/rx/meson.build index 8de0ad49b9..2eeac0c1b5 100644 --- a/target/rx/meson.build +++ b/target/rx/meson.build @@ -10,7 +10,9 @@ rx_ss.add(files( 'helper.c', 'cpu.c', 'gdbstub.c', - 'disas.c')) + 'disas.c', + 'rx-semi.c', +)) target_arch += {'rx': rx_ss} target_softmmu_arch += {'rx': ss.source_set()} From patchwork Tue May 3 19:48: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: 569020 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp9812815map; Tue, 3 May 2022 13:59:12 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzSGlwtC4+dLEbbg/oN8lUg4DS5ttwDcTUxHgATcqVs+URK0QGT+ZB041ue2pyPVOYZqzQH X-Received: by 2002:a37:a7c7:0:b0:69f:b4fd:4fa3 with SMTP id q190-20020a37a7c7000000b0069fb4fd4fa3mr13826246qke.557.1651611552803; Tue, 03 May 2022 13:59:12 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1651611552; cv=none; d=google.com; s=arc-20160816; b=apT5qxZNjmyF3bny+HMpu1IN/drlguh9qJ0MB9BZXed3pfYXbruycjAYgJDchsUA7d 0AmV7koHbTvqClTMz+VKDEWoBfZS0LN9DymgbI3wn3lnDmrTxDJhMXVDKJYkZ9jyuCQT ELy9ELgm6WeSFUap0ms+8LtlZru+A+M5Dzm+EIOPdzG2gCovDGIpuLNPif+8iZVapwBS B+MfWgYvSLnwFM4QqIaqwISWj56qs3vxnjtLT4q/EKU7DacwZuKg+6+x3Hlx6yOyNYdo 6iGw7/VFefVoXVTJZp8cV6fnlWgdHWT8mFF1NDuSpVdXezUt9WYkcSFWseLPkKXsXXNN kFpA== 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=sy4e+GA4siKpkmbYnx/SmxHTQKZjthdwLglaK4m7nGc=; b=t0/uBOkMTtMa9TPxyC6Tgh71gH2jeA5ToNmvPw3w2+a5ziUiQbXuRDFxO3W4tJv/LZ L/a7aTCC3PErtdXdcftWS6TxAhE06uJu8EJjkBuM3RHmQmJ1cIX3Sud7RAr6L2C7o3nG wDQpAVQn6aX2+xXZk4WvbElg2e9TR8cMTUUqwzx3E4LbsULU/WtpxiKnlsC1pUn8bR3v 2S9Bd2pyXBJWZX5a6iV72NtrRSSGniroMfsQQ0PdPDDKlcrQ4A4sxQ+QvWW0Bgpsv368 QrpvcoK0CEuKJoW1Tg8CAEmDNyS9arWIL2TbKVJdfbndsoTvC7R8b+kpM1tDC7hvVto9 SKhQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=bnm700Ov; 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 bq39-20020a05620a46a700b0069e7a0f15d1si8930113qkb.29.2022.05.03.13.59.12 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Tue, 03 May 2022 13:59: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=bnm700Ov; 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]:45110 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlzc0-0008QS-0B for patch@linaro.org; Tue, 03 May 2022 16:59:12 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:40700) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nlya0-0000r8-6Y for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:04 -0400 Received: from mail-pg1-x52a.google.com ([2607:f8b0:4864:20::52a]:46724) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nlyZx-0006P4-Qk for qemu-devel@nongnu.org; Tue, 03 May 2022 15:53:03 -0400 Received: by mail-pg1-x52a.google.com with SMTP id 6so3178141pgb.13 for ; Tue, 03 May 2022 12:53:01 -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=sy4e+GA4siKpkmbYnx/SmxHTQKZjthdwLglaK4m7nGc=; b=bnm700Ov3cN4Mn7/s9nRHWlAqpin4qDrn39pZMYTJwYiXEiEmDfCCSGmdgyYpMCPVt N6NwNMy8auxJKYW8aIW9tzkiTwQ3CmqJuO3RJSIB0CVwdtfITF+8nGvg2oQO1LXnbajF wGN5mwCCPZkhIB7p3tvSZOk86RB1JTqsG7X/fXjfwJpSpDJlnvqiq6MZmBhIiqTZ9jrz CNbivUplEmuGMdmFe7GAfe9kv9eJyI+WaKIo6sDZtdwiH6Kp0vJQpKLskNwaQ4l35dWH xJzCD5LEyM2VmTEY1iidt7wCeCZ3+eY6bL5nfqi/TLt2gDnTqHllJspTMRx6xzYAJESC wG4w== 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=sy4e+GA4siKpkmbYnx/SmxHTQKZjthdwLglaK4m7nGc=; b=kKFOk8GRj9mV2QNIhImiambfvVY0DOHjNa65XtkucXPE92tC031NQ2X/bxmKHGVrQB M/7rqeZI/6I3PdOOaWR6l1EfKgYmTgBKlGkyIt0OaZeP7TkRo5BknugpK4BBgfncDv+j YhL9bHPDphV/Dz0Fnb3BRkGEDZslirRSVKZxaBbo0u3p/zMvB2jXkydnUMovD9q0meGR THu0KZuvbpYgGYj0/t3W4yt25iIgEQh8pwBu/CdZWyyqewqSLB7uJMVcJCRHNF3GnsWj dkI/iDtf5gUlTvyTZoCeMsW8bd9pkZYzwlgh2LR7QafR3L2689CLLjcn9jISZXd2kLn2 IVCA== X-Gm-Message-State: AOAM532/pFTuJS+Tkv26nB6iiwaoGiyQ6ptFIA+YvZkvJSxKqnu4KLlO 08iCLfaICJMJE3Q6LIZE/uWrY6hGpJRWkQ== X-Received: by 2002:a63:d50c:0:b0:39d:61df:ad7b with SMTP id c12-20020a63d50c000000b0039d61dfad7bmr15255632pgg.47.1651607580518; Tue, 03 May 2022 12:53:00 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id fz16-20020a17090b025000b001dbe11be891sm1692286pjb.44.2022.05.03.12.52.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 03 May 2022 12:53:00 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Subject: [PATCH v2 74/74] tests/tcg/rx: Enable semihosting multiarch tests Date: Tue, 3 May 2022 12:48:43 -0700 Message-Id: <20220503194843.1379101-75-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::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" Signed-off-by: Richard Henderson --- tests/tcg/rx/outc.c | 15 +++++++++++++++ tests/tcg/rx/Makefile.softmmu-target | 24 ++++++++++++++++++++++++ 2 files changed, 39 insertions(+) create mode 100644 tests/tcg/rx/outc.c create mode 100644 tests/tcg/rx/Makefile.softmmu-target diff --git a/tests/tcg/rx/outc.c b/tests/tcg/rx/outc.c new file mode 100644 index 0000000000..3f8720d7ca --- /dev/null +++ b/tests/tcg/rx/outc.c @@ -0,0 +1,15 @@ +/* + * minilib.h compatibility code + * + * Copyright Linaro Ltd 2022 + * + * Rely on newlib/libgloss for functionality. + */ + +#include "minilib.h" +#include + +void __sys_outc(char c) +{ + write(1, &c, 1); +} diff --git a/tests/tcg/rx/Makefile.softmmu-target b/tests/tcg/rx/Makefile.softmmu-target new file mode 100644 index 0000000000..aaa1cebb92 --- /dev/null +++ b/tests/tcg/rx/Makefile.softmmu-target @@ -0,0 +1,24 @@ +# +# RX system tests +# + +RX_SYSTEM_SRC = $(SRC_PATH)/tests/tcg/rx +VPATH += $(RX_SYSTEM_SRC) + +TESTS += $(MULTIARCH_TESTS) + +CFLAGS += -Og -g $(MINILIB_INC) +LDFLAGS += -msim + +MINILIB_OBJS += outc.o +.PRECIOUS: $(MINILIB_OBJS) + +%.o: %.c + $(call quiet-command, $(CC) $(CFLAGS) $(EXTRA_CFLAGS) -c $< -o $@, CC, $@) + +%: %.o $(LINK_SCRIPT) $(MINILIB_OBJS) + $(call quiet-command, $(CC) $(CFLAGS) $(EXTRA_CFLAGS) $< -o $@ $(LDFLAGS) $(MINILIB_OBJS), LD, $@) + +QEMU_OPTS = -M gdbsim-r5f562n7 -m 128 -semihosting-config enable=on,target=native,chardev=output -kernel + +memory: CFLAGS+=-DCHECK_UNALIGNED=0