From patchwork Mon Oct 14 16:03:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Peter Maydell X-Patchwork-Id: 176321 Delivered-To: patch@linaro.org Received: by 2002:a92:7e96:0:0:0:0:0 with SMTP id q22csp4762279ill; Mon, 14 Oct 2019 09:57:36 -0700 (PDT) X-Google-Smtp-Source: APXvYqwSHLdRpu6c3UeXnRVEe7oXsuE+mIe7+p+uBJaNI3R6swESwPTJOhqXu3uuztaXp0c2TnZz X-Received: by 2002:a05:6402:1454:: with SMTP id d20mr14669241edx.53.1571072256811; Mon, 14 Oct 2019 09:57:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571072256; cv=none; d=google.com; s=arc-20160816; b=uXMzTJD2yaz1LRT3UKyCpohkBI7iMoxdGKFcs6UICV0QvzUgxWRhQmYW/KzxIu1Rr2 +vxKAHqIZnzh07ADjiaLgx/Ohvm42nJiLufiT/rViEtYLe8HMwRDQni4E+3ZXon5R6B8 M9QvUJQqEHh9Q7/U2yA45gccs1vCIRXPh/DsFq/6nslxBF41oqZTDhGtCcw6MRBXsIqZ 2+b8Ftqx+TvmaTWqtZfE4ba8/RZZs8YgTXwUS49ij9Y0kKMG/XnB8D47D6w4Wo+oXEcu upblKfjybjhyuunYY/ZbJ5F7NSbhOkts/1j5HlA9MepYx5ugovNr0pcCmFtaqQrWbjuN 90fA== 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=DKGrYcoSwF8i1yBqgJnCMl96wMrcE5OTnAG0MbPbFs4=; b=Adoi8Ui6gIl3U5tP52U3tYurEXQpoeitV9BtlYGuTWDxxOiXiB71S0w05DZeSB0xGz kW7r+gRJh9ETAmizuV+QLvLlscU53fHpOUw2TdvEdCAxsnlYlColnWIlYxWnxJnAV6PI OuVQ6x4OWRa7gpEN/tvxVY2CzQgUt7jT8OPPDHcZ0Lj8rqVUiJcEA7l/fogN+2xpcV9I 4coJx+K9enBfDGc8ZevtJ7PNvl0aoNI5NR1a8NNWIlnb3dYSxFG8A9pP07PWJCpkg6I6 FyS5E6j9qxD9njswwojwLh9VgJjz3b//Y5nCEURA8otGTx3rN8R9p1yHMiywZHXyzCwY 5BEQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=cCVBuCvy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as 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 q35si14169250eda.122.2019.10.14.09.57.36 for (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 14 Oct 2019 09:57: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=cCVBuCvy; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 209.51.188.17 as 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]:53850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK3f5-0004NO-GG for patch@linaro.org; Mon, 14 Oct 2019 12:57:35 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:37164) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1iK2qM-0004Xh-0q for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:11 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1iK2qK-0007lI-Uk for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:09 -0400 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]:36795) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1iK2qK-0007jQ-OD for qemu-devel@nongnu.org; Mon, 14 Oct 2019 12:05:08 -0400 Received: by mail-wr1-x443.google.com with SMTP id y19so20401301wrd.3 for ; Mon, 14 Oct 2019 09:05: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=DKGrYcoSwF8i1yBqgJnCMl96wMrcE5OTnAG0MbPbFs4=; b=cCVBuCvyzKFvmJen8qHaWR3HQPgJukXqNRhsWrKlMOlX2ik7s3pk1ymd7uTZPRhG47 iGI0BUFLYmDHUfMuggQDAM8TvknhO4ZVc+5E8dNkx0QO/TFVJ5weX3XqIncSzFhzt6Gj oWsfWFrEtbYqmFL4lrqlyuBTVo38AXmqG+UbJGguEGgcLeWwV/TtfN6v8StHY2VTlpF3 bSXSig9lPooSo9iGK4xhmWDM4MmCYym5yF7DB6nrhWUTyoYhrt8cYy5UhOflSmmzsbf6 jFRYgj4CAq7l8PVN819mn+elQliVFS58JG+NTpQCIkn8OSJxUEB08Wue+QKFqd2Zbsv6 zZoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=DKGrYcoSwF8i1yBqgJnCMl96wMrcE5OTnAG0MbPbFs4=; b=Cnpyt7k3LOt7995X+nFwG5endMqX1+01ZdD7EvTBIrzF69WftB01ihkDgzA2wln98y Jo5kl/tXeMn3NYQqMUlf61jgVcZ4R2Ll7W1fqVaEv11hBBPnR0jzalRXqa2q4/jxuX4c 42RS0miNBpZw9fTH0ft6atILeBiNbQfvfuvjBOGoLiUoVbZ8Krlf0YX7TzIeIFvYx1HT cAcek4Jb6yn0TWEZnXN0hl/YPuFSEBvvoTRAr+6YbBMs2j6RqnKfI1MTSNXs4sJgL7Md F/L3iRA1tN8JW/gLYWYvb6y++c/3LXV0qvhrAfBtVHEE0klJT0p/Crg9XPFm5MDKRxDf qByw== X-Gm-Message-State: APjAAAUpZyHSq2lP0TCWaPxwGCpyuloP9hgFh4UJpQF4t1JbVtp0H7z9 dQgy9JsO/ufogwA1QGPZyfJt3KfpYKc6rg== X-Received: by 2002:adf:e2c5:: with SMTP id d5mr12604292wrj.283.1571069107427; Mon, 14 Oct 2019 09:05:07 -0700 (PDT) Received: from orth.archaic.org.uk (orth.archaic.org.uk. [81.2.115.148]) by smtp.gmail.com with ESMTPSA id 5sm18029779wrk.86.2019.10.14.09.05.06 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 14 Oct 2019 09:05:06 -0700 (PDT) From: Peter Maydell To: qemu-devel@nongnu.org Subject: [PULL 35/68] target/arm/arm-semi: Factor out implementation of SYS_SEEK Date: Mon, 14 Oct 2019 17:03:31 +0100 Message-Id: <20191014160404.19553-36-peter.maydell@linaro.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20191014160404.19553-1-peter.maydell@linaro.org> References: <20191014160404.19553-1-peter.maydell@linaro.org> MIME-Version: 1.0 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::443 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 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" Factor out the implementation of SYS_SEEK via the new function tables. Signed-off-by: Peter Maydell Reviewed-by: Philippe Mathieu-Daudé Message-id: 20190916141544.17540-12-peter.maydell@linaro.org --- target/arm/arm-semi.c | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) -- 2.20.1 diff --git a/target/arm/arm-semi.c b/target/arm/arm-semi.c index ecd51338fd3..b5e1d73eb80 100644 --- a/target/arm/arm-semi.c +++ b/target/arm/arm-semi.c @@ -389,6 +389,8 @@ typedef uint32_t sys_writefn(ARMCPU *cpu, GuestFD *gf, typedef uint32_t sys_readfn(ARMCPU *cpu, GuestFD *gf, target_ulong buf, uint32_t len); typedef uint32_t sys_isattyfn(ARMCPU *cpu, GuestFD *gf); +typedef uint32_t sys_seekfn(ARMCPU *cpu, GuestFD *gf, + target_ulong offset); static uint32_t host_closefn(ARMCPU *cpu, GuestFD *gf) { @@ -442,6 +444,16 @@ static uint32_t host_isattyfn(ARMCPU *cpu, GuestFD *gf) return isatty(gf->hostfd); } +static uint32_t host_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset) +{ + CPUARMState *env = &cpu->env; + uint32_t ret = set_swi_errno(env, lseek(gf->hostfd, offset, SEEK_SET)); + if (ret == (uint32_t)-1) { + return -1; + } + return 0; +} + static uint32_t gdb_closefn(ARMCPU *cpu, GuestFD *gf) { return arm_gdb_syscall(cpu, arm_semi_cb, "close,%x", gf->hostfd); @@ -468,11 +480,18 @@ static uint32_t gdb_isattyfn(ARMCPU *cpu, GuestFD *gf) return arm_gdb_syscall(cpu, arm_semi_cb, "isatty,%x", gf->hostfd); } +static uint32_t gdb_seekfn(ARMCPU *cpu, GuestFD *gf, target_ulong offset) +{ + return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", + gf->hostfd, offset); +} + typedef struct GuestFDFunctions { sys_closefn *closefn; sys_writefn *writefn; sys_readfn *readfn; sys_isattyfn *isattyfn; + sys_seekfn *seekfn; } GuestFDFunctions; static const GuestFDFunctions guestfd_fns[] = { @@ -481,12 +500,14 @@ static const GuestFDFunctions guestfd_fns[] = { .writefn = host_writefn, .readfn = host_readfn, .isattyfn = host_isattyfn, + .seekfn = host_seekfn, }, [GuestFDGDB] = { .closefn = gdb_closefn, .writefn = gdb_writefn, .readfn = gdb_readfn, .isattyfn = gdb_isattyfn, + .seekfn = gdb_seekfn, }, }; @@ -656,15 +677,7 @@ target_ulong do_arm_semihosting(CPUARMState *env) return set_swi_errno(env, -1); } - if (use_gdb_syscalls()) { - return arm_gdb_syscall(cpu, arm_semi_cb, "lseek,%x,%x,0", - gf->hostfd, arg1); - } else { - ret = set_swi_errno(env, lseek(gf->hostfd, arg1, SEEK_SET)); - if (ret == (uint32_t)-1) - return -1; - return 0; - } + return guestfd_fns[gf->type].seekfn(cpu, gf, arg1); case TARGET_SYS_FLEN: GET_ARG(0);