From patchwork Mon Jun 6 23:14: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: 578966 Delivered-To: patch@linaro.org Received: by 2002:a5d:6706:0:0:0:0:0 with SMTP id o6csp3065085wru; Mon, 6 Jun 2022 16:43:13 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyFZifMXWNNIcWVXrYWRQ1ZUKQzE+2lO0I7b9bdq+LITb9BOlDVU4ZeP6TTkX74FRZHEQv5 X-Received: by 2002:a37:b6c1:0:b0:6a6:349d:6e81 with SMTP id g184-20020a37b6c1000000b006a6349d6e81mr17607311qkf.508.1654558993187; Mon, 06 Jun 2022 16:43:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1654558993; cv=none; d=google.com; s=arc-20160816; b=KiHE9xDs7VjZdQ8uCLvWGVlnvCLGfdt6tCMO5jctzqt+W3ArsVCXuOuzicmJgYS59k NXtRmaLJeTPbE6ZdzS1coJ2GgBsFot5Hh1qOKB+KMDsYm43KKxBkxTBd+rERialWAO4l rxGdDyyxKDYPavTBvHVpaB6YDz0xLWQc5LqNrYUpdE5m4K2fc8tAJ2YMBblaHfS5gmFS IoxgYpTUgUxVs9A2+QcvZ7zLUCi53YOSyvEBdwjNe/HSpCH7Z6aEJ/1hA9INjT9jzM97 Y6Tn0eZFBrlxOHiXh29Rhr2MlP8cYnL8yCFeSjoq3XiI40uLeXWyRvXP/vCidblO7Jny DA9g== 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=O2QqbKzAwr9vjS4vmaM7pFsZLapi/ItG1evQoSB6fco=; b=dcaUqODpg1FV4EW7iUf89AcNLmcfaeF9PIOGMsF6/In/3iKetF6RbOgTFPstBiDw1M uCgTEv7w378gFkgb6fzWjlhAxdh9mlOZQbQLcDo/sxLozqOxoVWU8h7YPoGULVK22WQa BhdMplFrKcPr2IWvjxxjk4MpACbtsYSwlPiDRQt2d/U3zo9D6WunO1wm89FQp5mZ8AWH Tco75NcY89icGtn/KQqlqZEE38L6Y94WO+x8zn+bBWaeYeK7Og1j8utTqAQwqv4Y0bKw nvLgCS1DOldzjU5UOxFO75lfxD8T9xQX4SZaQT5IZfn1FRja2m7GeH/5ahM4W4/oPzg0 Wv0g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MKXRZ54j; 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 a11-20020ad45c4b000000b004542667c953si9729783qva.199.2022.06.06.16.43.13 for (version=TLS1_2 cipher=ECDHE-ECDSA-CHACHA20-POLY1305 bits=256/256); Mon, 06 Jun 2022 16:43:13 -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=MKXRZ54j; 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]:50926 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nyMNI-0004cT-RT for patch@linaro.org; Mon, 06 Jun 2022 19:43:10 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:35188) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nyLwT-0001kD-PC for qemu-devel@nongnu.org; Mon, 06 Jun 2022 19:15:27 -0400 Received: from mail-pf1-x430.google.com ([2607:f8b0:4864:20::430]:44697) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nyLwP-0003zT-4u for qemu-devel@nongnu.org; Mon, 06 Jun 2022 19:15:24 -0400 Received: by mail-pf1-x430.google.com with SMTP id g205so13912606pfb.11 for ; Mon, 06 Jun 2022 16:15:19 -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=O2QqbKzAwr9vjS4vmaM7pFsZLapi/ItG1evQoSB6fco=; b=MKXRZ54jgOkKGBldYc5otUOkeJFjrz8Hq8ec/kHabA3W/Tzd8v2/SfYfoNkuFmTAm7 E13YTwhf/OoeLxpdTEg74NUDgOC2swMIJaoJOYAfjXOAOBf8Qcnrhjmg7Skt3IAHu51H 7E4WggneYML3HhHLdMSYWS+y/KyhRzLnDA7X8NltAk8gXtvpPzofl5Opop8NF7/7IKvC 9uvvce1prNJfmImd57Fi4kYpsx4XFkL95cbIDcmzBSgcvieIgrwbGth3cZXU4Tzhtmwc rgL1sy7lic+wEDHZevJOUZeYYhixKISil38xpniBW+F1O5Tuu+NW7KaBJSjpXIkV6uBm GdSg== 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=O2QqbKzAwr9vjS4vmaM7pFsZLapi/ItG1evQoSB6fco=; b=zppO4jWRwvx2lxxxfQOC3XLtaCJ7m9XL7eaGyyu2B0n2PvXbUaXG6+WUXk7weKowU0 ek875f1yW6sV0MhjsuoMCLdBwxvZOx1+GQ32ymRuQ1CF94WA+x/l1wCRTfxXSiKE0iut RsmqzrqE64VTEnOyRdD9DqdLeddeC1v8auWhqAR1AYMsY32xdFsogKKuIt8u/guOMLg8 lKXBl3nbKo8FoijyBeZA3STJcF8caAKthHhW9P1wdsG+QAQ5U3taYiDxfHnQ/VHdfxlf x3ja316EQlyr+WXQUDfVY/m9tNnfA/PFgoP8wGh+D6pbcW7us/EdL6FmK1218C/rufEe Kg8A== X-Gm-Message-State: AOAM530KmBoIOuM/1b6/FExqHuuSNYoB8q2VfC1wKyYcJHcOFx8oBEfl rd4hfcI4tYTq7lvsiwbF/CjmfJ0NUv1OSA== X-Received: by 2002:a63:8241:0:b0:3fc:aa22:7f3e with SMTP id w62-20020a638241000000b003fcaa227f3emr23689890pgd.2.1654557318806; Mon, 06 Jun 2022 16:15:18 -0700 (PDT) Received: from stoup.. ([2602:ae:1547:e101:dd1c:9738:3e40:ffe0]) by smtp.gmail.com with ESMTPSA id 2-20020a170902c24200b00162523fdb8fsm10954623plg.252.2022.06.06.16.15.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 06 Jun 2022 16:15:18 -0700 (PDT) From: Richard Henderson To: qemu-devel@nongnu.org Cc: =gaosong@loongson.cn, yangxiaojuan@loongson.cn, Song Gao Subject: [PULL 29/43] target/loongarch: Add timer related instructions support. Date: Mon, 6 Jun 2022 16:14:36 -0700 Message-Id: <20220606231450.448443-30-richard.henderson@linaro.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220606231450.448443-1-richard.henderson@linaro.org> References: <20220606231450.448443-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" From: Xiaojuan Yang This includes: -RDTIME{L/H}.W -RDTIME.D Signed-off-by: Xiaojuan Yang Signed-off-by: Song Gao Reviewed-by: Richard Henderson Message-Id: <20220606124333.2060567-30-yangxiaojuan@loongson.cn> Signed-off-by: Richard Henderson --- target/loongarch/helper.h | 2 ++ target/loongarch/insns.decode | 3 ++ target/loongarch/disas.c | 3 ++ target/loongarch/op_helper.c | 13 ++++++++ target/loongarch/translate.c | 2 ++ target/loongarch/insn_trans/trans_extra.c.inc | 33 +++++++++++++++++++ 6 files changed, 56 insertions(+) diff --git a/target/loongarch/helper.h b/target/loongarch/helper.h index 626fc32e1e..85c11a60d4 100644 --- a/target/loongarch/helper.h +++ b/target/loongarch/helper.h @@ -93,6 +93,8 @@ DEF_HELPER_2(frint_d, i64, env, i64) DEF_HELPER_FLAGS_2(set_rounding_mode, TCG_CALL_NO_RWG, void, env, i32) +DEF_HELPER_1(rdtime_d, i64, env) + /* CSRs helper */ DEF_HELPER_1(csrrd_pgd, i64, env) DEF_HELPER_1(csrrd_tval, i64, env) diff --git a/target/loongarch/insns.decode b/target/loongarch/insns.decode index ebd3d505fb..3fdc6e148c 100644 --- a/target/loongarch/insns.decode +++ b/target/loongarch/insns.decode @@ -309,6 +309,9 @@ break 0000 00000010 10100 ............... @i15 syscall 0000 00000010 10110 ............... @i15 asrtle_d 0000 00000000 00010 ..... ..... 00000 @rr_jk asrtgt_d 0000 00000000 00011 ..... ..... 00000 @rr_jk +rdtimel_w 0000 00000000 00000 11000 ..... ..... @rr +rdtimeh_w 0000 00000000 00000 11001 ..... ..... @rr +rdtime_d 0000 00000000 00000 11010 ..... ..... @rr cpucfg 0000 00000000 00000 11011 ..... ..... @rr # diff --git a/target/loongarch/disas.c b/target/loongarch/disas.c index 9d790b172c..858dfcc53a 100644 --- a/target/loongarch/disas.c +++ b/target/loongarch/disas.c @@ -352,6 +352,9 @@ INSN(bitrev_w, rr) INSN(bitrev_d, rr) INSN(ext_w_h, rr) INSN(ext_w_b, rr) +INSN(rdtimel_w, rr) +INSN(rdtimeh_w, rr) +INSN(rdtime_d, rr) INSN(cpucfg, rr) INSN(asrtle_d, rr_jk) INSN(asrtgt_d, rr_jk) diff --git a/target/loongarch/op_helper.c b/target/loongarch/op_helper.c index a9ba72d5b2..d87049851f 100644 --- a/target/loongarch/op_helper.c +++ b/target/loongarch/op_helper.c @@ -84,6 +84,19 @@ target_ulong helper_cpucfg(CPULoongArchState *env, target_ulong rj) return rj > 21 ? 0 : env->cpucfg[rj]; } +uint64_t helper_rdtime_d(CPULoongArchState *env) +{ + uint64_t plv; + LoongArchCPU *cpu = env_archcpu(env); + + plv = FIELD_EX64(env->CSR_CRMD, CSR_CRMD, PLV); + if (extract64(env->CSR_MISC, R_CSR_MISC_DRDTL_SHIFT + plv, 1)) { + do_raise_exception(env, EXCCODE_IPE, GETPC()); + } + + return cpu_loongarch_get_constant_timer_counter(cpu); +} + void helper_ertn(CPULoongArchState *env) { uint64_t csr_pplv, csr_pie; diff --git a/target/loongarch/translate.c b/target/loongarch/translate.c index 0f098924a3..c9afd11420 100644 --- a/target/loongarch/translate.c +++ b/target/loongarch/translate.c @@ -25,6 +25,8 @@ static TCGv cpu_lladdr, cpu_llval; TCGv_i32 cpu_fcsr0; TCGv_i64 cpu_fpr[32]; +#include "exec/gen-icount.h" + #define DISAS_STOP DISAS_TARGET_0 #define DISAS_EXIT DISAS_TARGET_1 #define DISAS_EXIT_UPDATE DISAS_TARGET_2 diff --git a/target/loongarch/insn_trans/trans_extra.c.inc b/target/loongarch/insn_trans/trans_extra.c.inc index 549f75a867..ad713cd61e 100644 --- a/target/loongarch/insn_trans/trans_extra.c.inc +++ b/target/loongarch/insn_trans/trans_extra.c.inc @@ -33,6 +33,39 @@ static bool trans_asrtgt_d(DisasContext *ctx, arg_asrtgt_d * a) return true; } +static bool gen_rdtime(DisasContext *ctx, arg_rr *a, + bool word, bool high) +{ + TCGv dst1 = gpr_dst(ctx, a->rd, EXT_NONE); + TCGv dst2 = gpr_dst(ctx, a->rj, EXT_NONE); + + if (tb_cflags(ctx->base.tb) & CF_USE_ICOUNT) { + gen_io_start(); + } + gen_helper_rdtime_d(dst1, cpu_env); + if (word) { + tcg_gen_sextract_tl(dst1, dst1, high ? 32 : 0, 32); + } + tcg_gen_ld_i64(dst2, cpu_env, offsetof(CPULoongArchState, CSR_TID)); + + return true; +} + +static bool trans_rdtimel_w(DisasContext *ctx, arg_rdtimel_w *a) +{ + return gen_rdtime(ctx, a, 1, 0); +} + +static bool trans_rdtimeh_w(DisasContext *ctx, arg_rdtimeh_w *a) +{ + return gen_rdtime(ctx, a, 1, 1); +} + +static bool trans_rdtime_d(DisasContext *ctx, arg_rdtime_d *a) +{ + return gen_rdtime(ctx, a, 0, 0); +} + static bool trans_cpucfg(DisasContext *ctx, arg_cpucfg *a) { TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);