From nobody Tue Feb 10 23:55:26 2026 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=linaro.org ARC-Seal: i=1; a=rsa-sha256; t=1651608489; cv=none; d=zohomail.com; s=zohoarc; b=UmkAuKYoCTOCDw3TqEeW+/oVpJfnHUQhUkhflYRzktHms4Q1uNjvw07yOwnyqiP6iz8Vb6lgQ9cOMGsOIW/36RBpH5tRlrGY+nf3UocJLapq81+vcK+zG0oOiXmBRQpzkc9Wiw6m1cUMVvsnKj4Lf4OxVlZp+fg3ieqYAbcOYeI= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651608489; h=Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=ePCmgB81KOph48TAJ6SLINByRDQqJIYEYHjh8/K/gAE=; b=kjzgopkSeAv8+oawwCzDHDAd2D1+K9oxfIkeJfptCV/q7JoY5Z7rxaIGIZ7L6nKfUkvTVuWkt1Ix5GY1ZgF0IDszbNDd4BwNBtoyfMMw6renMWmhSKYSa2C70Z0OwXG2zqZ18ikzuuw8rz6NoP5a29oOK3DUTBwqB2NimIkqLSs= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651608489742712.4287283800556; Tue, 3 May 2022 13:08:09 -0700 (PDT) Received: from localhost ([::1]:55724 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nlyoa-0004cg-Md for importer@patchew.org; Tue, 03 May 2022 16:08:08 -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) 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) 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-Google-Smtp-Source: ABdhPJxFCEUhUjNDiXi9xiV9savM93zlwI1Bg4VomajbTyVNJCHBK9j5GfOpg9fIIZ2iKG17yGEOFQ== 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) 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 Content-Transfer-Encoding: quoted-printable Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; 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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @linaro.org) X-ZM-MESSAGEID: 1651608491700100001 Content-Type: text/plain; charset="utf-8" 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 =3D 0, GuestFDHost =3D 1, GuestFDGDB =3D 2, - GuestFDFeatureFile =3D 3, + GuestFDStatic =3D 3, } GuestFDType; =20 /* @@ -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; =20 @@ -35,6 +39,6 @@ void dealloc_guestfd(int guestfd); GuestFD *get_guestfd(int guestfd); =20 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); =20 #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[] =3D { SH_EXT_EXIT_EXTENDED | SH_EXT_STDOUT_STDERR, /* Feature byte 0 */ }; =20 -static uint32_t featurefile_closefn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_closefn(CPUState *cs, GuestFD *gf) { /* Nothing to do */ return 0; } =20 -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, Guest= FD *gf, return set_swi_errno(cs, -1); } =20 -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 =3D cs->env_ptr; @@ -582,11 +582,11 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, } =20 for (i =3D 0; i < len; i++) { - if (gf->featurefile_offset >=3D sizeof(featurefile_data)) { + if (gf->staticfile.off >=3D gf->staticfile.len) { break; } - s[i] =3D featurefile_data[gf->featurefile_offset]; - gf->featurefile_offset++; + s[i] =3D gf->staticfile.data[gf->staticfile.off]; + gf->staticfile.off++; } =20 unlock_user(s, buf, len); @@ -595,21 +595,21 @@ static uint32_t featurefile_readfn(CPUState *cs, Gues= tFD *gf, return len - i; } =20 -static uint32_t featurefile_isattyfn(CPUState *cs, GuestFD *gf) +static uint32_t staticfile_isattyfn(CPUState *cs, GuestFD *gf) { return 0; } =20 -static uint32_t featurefile_seekfn(CPUState *cs, GuestFD *gf, +static uint32_t staticfile_seekfn(CPUState *cs, GuestFD *gf, target_ulong offset) { - gf->featurefile_offset =3D offset; + gf->staticfile.off =3D offset; return 0; } =20 -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; } =20 typedef struct GuestFDFunctions { @@ -638,13 +638,13 @@ static const GuestFDFunctions guestfd_fns[] =3D { .seekfn =3D gdb_seekfn, .flenfn =3D gdb_flenfn, }, - [GuestFDFeatureFile] =3D { - .closefn =3D featurefile_closefn, - .writefn =3D featurefile_writefn, - .readfn =3D featurefile_readfn, - .isattyfn =3D featurefile_isattyfn, - .seekfn =3D featurefile_seekfn, - .flenfn =3D featurefile_flenfn, + [GuestFDStatic] =3D { + .closefn =3D staticfile_closefn, + .writefn =3D staticfile_writefn, + .readfn =3D staticfile_readfn, + .isattyfn =3D staticfile_isattyfn, + .seekfn =3D staticfile_seekfn, + .flenfn =3D staticfile_flenfn, }, }; =20 @@ -765,7 +765,8 @@ target_ulong do_common_semihosting(CPUState *cs) errno =3D EACCES; return set_swi_errno(cs, -1); } - init_featurefile_guestfd(guestfd); + staticfile_guestfd(guestfd, featurefile_data, + sizeof(featurefile_data)); return guestfd; } =20 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 =3D hostfd; } =20 -void init_featurefile_guestfd(int guestfd) +void staticfile_guestfd(int guestfd, const uint8_t *data, size_t len) { GuestFD *gf =3D do_get_guestfd(guestfd); =20 assert(gf); - gf->type =3D GuestFDFeatureFile; - gf->featurefile_offset =3D 0; + gf->type =3D GuestFDStatic; + gf->staticfile.data =3D data; + gf->staticfile.len =3D len; + gf->staticfile.off =3D 0; } =20 /* --=20 2.34.1