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); + } +}