From patchwork Sat May 21 00:03: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: 574939 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:1f0e:0:0:0:0 with SMTP id hs14csp2681429mab; Fri, 20 May 2022 17:59:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJzOHE8WpW73fWkXdOm5U2SridcCa/DZdSoR+4d311VrHG83/S83TEXWFBaX+YXSy0daUMxT X-Received: by 2002:a05:620a:84b:b0:6a3:4895:d272 with SMTP id u11-20020a05620a084b00b006a34895d272mr5092783qku.338.1653094772255; Fri, 20 May 2022 17:59:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653094772; cv=none; d=google.com; s=arc-20160816; b=GQ6hc0aaRenpGA4OJx5wwe3Qa6QQB5ETU2KoDZJChlx/dnIBry62K3aZE/1bwPi84C tTy1vINuOpl8fN2UC4f74mLWvGpfFmfuRQ8LF9IICBIUOgZj63j/HO+ZUSX/nRJ3SHS/ bkuZW6ixL29BTbtjfRuvXlG+FW/BzfkP0AlrTkQPvv1CRX8DxzhpxCYEKSTc8MciC+1Z Y4uJatV+KDu5pMoxLC3yXAFQ75RO0U8l7k2xPs2YjkekgZU+PNmiW7jh8ZAt+KDp67BE NlrbnX7aVZSlWyvfn+WryBRsuiE7/xr47Kq+G/+Q/FiXV3QogRVJT3UvC9ypcEFZjO+O OMLw== 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:cc:to :from:dkim-signature; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=cZBPE9ZHKC8vyDYpkyAf8uiLhs+MH4BpKK1snvvJqauJHuyJ59B6pF5QiSFdWNhTlw KmwtpYlV+3C5nCkS2TIKi9jF5c9Kt0KytTPTAhwq1KYKbnfK51b4VCfxrPlEZji8TKTE pkaJmTTduWT32tUHU7invDdFKDrcGGUp0QBZsRjHKrJNtHusNP1Ht14CC7rMxJxDfM31 WaAkk19P207N7KXJWRWVO86zR+rnnQdMFq1MkcIFsgnNwFMUs3EBe6Hfo4hL4E821POr YIVbJhgH0YFETdyYNwEssJIPHqi3+ZaOI5glUIsHFzTcHgdbmdNVqKkr5IyFce9HC7fl WWpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=tnBWdMIO; 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 u31-20020a05622a199f00b002e1fbf3beeasi430674qtc.219.2022.05.20.17.59.32 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Fri, 20 May 2022 17:59: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=tnBWdMIO; 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]:42232 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nsDSt-0003Os-Sd for patch@linaro.org; Fri, 20 May 2022 20:59:31 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:59656) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nsCc8-0008Cf-BR for qemu-devel@nongnu.org; Fri, 20 May 2022 20:05:01 -0400 Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]:39766) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nsCby-00042b-Na for qemu-devel@nongnu.org; Fri, 20 May 2022 20:04:58 -0400 Received: by mail-pl1-x631.google.com with SMTP id bh5so8560536plb.6 for ; Fri, 20 May 2022 17:04:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=tnBWdMIOBpml/OZsk2CnHbv0WVbl+fOG+e4KlC1smReheAPN1bL1GPT11jmhnFCs3M IvDZQCoLIFW+LX6bGIbhY2AnzR2vpBJL5M8aLT5MbbRQquvHGDBGL9LEJEAJ+X8pXLK0 XkQUwFtcCa+Ppc8jgln5J3oEojolWSwyy2ETAo+GaMp+ph0OJCd14gewruKN4b0+wUVX Ztg2uywNBg5LrC+qV/yQ8WjMcBYgcVx6w+psxEMYZSHD34hQM3odNjyCQR5B74qnrLFR XYePugXlmj+EggMfC4t4w46SjkKJ6znl09DRykPIsjTWkHqsGVG6tMpQr0EBk5+bfAnJ afnQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=Bust6mppvMbdx6gzfuXbL5YS3wUCsmb4mW+3d0C8Dpw=; b=noVwNCQw1Dz1qg4sg087hCfluQOnJEg/Dr3D7xhZsBTQBE64ymc2bfxdzqvYPXQz3t l2LDG1ukKmOVRRpnj8/AYzSF2snYmHXp6sPE7ftVs1eUgFZQUq7u3QNSHAUn/o+l+hrU /qLEBZkhxzxaypVE2s6FLMlpIWEk9dNiU6msessaTLtwvzgOLQ1ywEo5NlyexQs1XpFl Y7WgesqGAoCZVqSwHafSCisUzSJETTC42C7/6f0pRWog2dDkMVLXToTcVR1Ea+ZB68ts xZncAK+0gGpwVKcK6McODb12/bmtxe7M87xF8aoFXehF7uuzihqDEwagOLbfMHebD+WQ aprQ== X-Gm-Message-State: AOAM531pEg1o362Nyf0wjShrtLK7WJo2ff6WFt9FsU7zbPjjcNbDvymk fDlhT4f6cd0Dln9DkCN+srZjgbt2rCO1NA== X-Received: by 2002:a17:902:8c92:b0:161:e861:861f with SMTP id t18-20020a1709028c9200b00161e861861fmr7965542plo.33.1653091480761; Fri, 20 May 2022 17:04:40 -0700 (PDT) Received: from stoup.. ([71.212.142.129]) by smtp.gmail.com with ESMTPSA id h8-20020a654808000000b003f9d1c020cbsm306369pgs.51.2022.05.20.17.04.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 20 May 2022 17:04:40 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: peter.maydell@linaro.org, alex.bennee@linaro.org Subject: [PATCH v3 35/49] semihosting: Create semihost_sys_gettimeofday Date: Fri, 20 May 2022 17:03:46 -0700 Message-Id: <20220521000400.454525-36-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220521000400.454525-1-richard.henderson@linaro.org> References: <20220521000400.454525-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" 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); + } +}