From: Richard Henderson <richard.henderson@linaro.org>
To: Xiaojuan Yang <yangxiaojuan@loongson.cn>, qemu-devel@nongnu.org
Cc: peter.maydell@linaro.org, thuth@redhat.com,
chenhuacai@loongson.cn, mst@redhat.com, philmd@redhat.com,
mark.cave-ayland@ilande.co.uk, laurent@vivier.eu,
peterx@redhat.com, f4bug@amsat.org, alistair.francis@wdc.com,
maobibo@loongson.cn, gaosong@loongson.cn, pbonzini@redhat.com,
bmeng.cn@gmail.com, alex.bennee@linaro.org,
david@gibson.dropbear.id.au
Subject: Re: [PATCH 07/31] target/loongarch: Add loongarch csr/iocsr instruction support
Date: Tue, 19 Oct 2021 18:36:46 -0700 [thread overview]
Message-ID: <cb33aeb0-3a82-1300-cbbc-3e260cee8a5f@linaro.org> (raw)
In-Reply-To: <1634628917-10031-8-git-send-email-yangxiaojuan@loongson.cn>
On 10/19/21 12:34 AM, Xiaojuan Yang wrote:
> +target_ulong helper_csr_rdq(CPULoongArchState *env, uint64_t csr)
> +{
> + int64_t v;
> +
> +#define CASE_CSR_RDQ(csr) \
> + case LOONGARCH_CSR_ ## csr: \
> + { \
> + v = env->CSR_ ## csr; \
> + break; \
> + }; \
There's absolutely no reason to call a helper function for a simple load.
> + case LOONGARCH_CSR_PGD:
> +
> + if (env->CSR_TLBRERA & 0x1) {
> + v = env->CSR_TLBRBADV;
> + } else {
> + v = env->CSR_BADV;
> + }
> +
> + if ((v >> 63) & 0x1) {
> + v = env->CSR_PGDH;
> + } else {
> + v = env->CSR_PGDL;
> + }
> + break;
This is the only one that requires a helper on read.
> + if (csr == LOONGARCH_CSR_ASID) {
> + if (old_v != val) {
> + tlb_flush(env_cpu(env));
> + }
> + }
And this is the only one that requires a helper on write.
> + case LOONGARCH_CSR_ESTAT:
> + qatomic_and(&env->CSR_ESTAT, ~mask);
Why do you believe this requires an atomic update?
What is going to race with the update to a cpu private value?
> +static bool trans_csrrd(DisasContext *ctx, unsigned rd, unsigned csr)
> +{
> + TCGv dest = gpr_dst(ctx, rd, EXT_NONE);
> + gen_helper_csr_rdq(dest, cpu_env, tcg_constant_i64(csr));
> + return true;
> +}
> +
> +static bool trans_csrwr(DisasContext *ctx, unsigned rd, unsigned csr)
> +{
> + TCGv dest = gpr_dst(ctx, rd, EXT_NONE);
> + TCGv src1 = gpr_src(ctx, rd, EXT_NONE);
> +
> + switch (csr) {
> + case LOONGARCH_CSR_CRMD:
> + tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next);
> + gen_helper_csr_wrq(dest, cpu_env, src1, tcg_constant_i64(LOONGARCH_CSR_CRMD));
> + tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next + 4);
> + ctx->base.is_jmp = DISAS_EXIT;
> + break;
> + case LOONGARCH_CSR_EUEN:
> + gen_helper_csr_wrq(dest, cpu_env, src1, tcg_constant_i64(LOONGARCH_CSR_EUEN));
> + /* Stop translation */
> + tcg_gen_movi_tl(cpu_pc, ctx->base.pc_next + 4);
> + ctx->base.is_jmp = DISAS_EXIT;
> + break;
> + default:
> + gen_helper_csr_wrq(dest, cpu_env, src1, tcg_constant_i64(csr));
> + break;
> + }
> + return true;
> +}
> +
> +static bool trans_csrxchg(DisasContext *ctx, arg_csrxchg *a)
> +{
> + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
> + TCGv src1 = gpr_src(ctx, a->rd, EXT_NONE);
> + TCGv src2 = gpr_src(ctx, a->rj, EXT_NONE);
> +
> + if (a->rj == 0) {
> + return trans_csrrd(ctx, a->rd, a->csr);
> + } else if (a->rj == 1) {
> + return trans_csrwr(ctx, a->rd, a->csr);
> + }
These should have been decoded separately; see below.
You're missing the check for priv 0 here and in all other functions.
> +
> + if (a->rd == 0) {
> + gen_helper_csr_xchgq_r0(cpu_env, src2, tcg_constant_i64(a->csr));
> + } else {
> + gen_helper_csr_xchgq(dest, cpu_env, src1, src2, tcg_constant_i64(a->csr));
> + }
Why do you believe r0 to require a special case?
> +static bool trans_iocsrrd_b(DisasContext *ctx, arg_iocsrrd_b *a)
> +{
> + TCGv tmp = tcg_temp_new();
> + TCGv dest = gpr_dst(ctx, a->rd, EXT_NONE);
> + TCGv src1 = gpr_src(ctx, a->rj, EXT_NONE);
> +
> + gen_helper_iocsr_read(tmp, cpu_env, src1);
> + tcg_gen_qemu_ld_tl(dest, tmp, ctx->mem_idx, MO_SB);
This is wrong. From the manual:
All IOCSR registers use independent addressing space
therefore you cannot simply read from a modified address, you must use a completely
different address space.
There are a couple of different solutions that are possible.
(1) Use helper functions calling address_space_ld/st*.
(2) Use a separate mmu_idx, which uses its own address space.
This requires bouncing through MemTxAttrs, since
cpu_asidx_from_attrs only take attrs and not mmu_idx.
The second one is may be overkill, unless there will be any cachable memory in iospace. I
would expect most of it to be device memory.
> +csrxchg 0000 0100 .............. ..... ..... @fmt_rdrjcsr
{
csrrd 0000 0100 .............. 00000 ..... @fmt_rdcsr
csrwr 0000 0100 .............. 00001 ..... @fmt_rdcsr
csrxchg 0000 0100 .............. ..... ..... @fmt_rdrjcsr
}
r~
next prev parent reply other threads:[~2021-10-20 1:37 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-10-19 7:34 [PATCH 00/31] Add Loongarch softmmu support Xiaojuan Yang
2021-10-19 7:34 ` [PATCH 02/31] target/loongarch: Add CSR registers definition Xiaojuan Yang
2021-10-19 19:10 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 03/31] target/loongarch: Set default csr values Xiaojuan Yang
2021-10-19 19:18 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 04/31] target/loongarch: Add basic vmstate description of CPU Xiaojuan Yang
2021-10-19 19:35 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 05/31] target/loongarch: Implement qmp_query_cpu_definitions() Xiaojuan Yang
2021-10-19 20:25 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 08/31] target/loongarch: Add tlb instruction support Xiaojuan Yang
2021-10-20 4:19 ` Richard Henderson
2021-10-29 7:01 ` yangxiaojuan
2021-10-29 17:48 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 09/31] target/loongarch: Add other core instructions support Xiaojuan Yang
2021-10-20 4:45 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 10/31] target/loongarch: Add loongarch interrupt and exception handle Xiaojuan Yang
2021-10-20 4:59 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 11/31] target/loongarch: Add stabletimer support Xiaojuan Yang
2021-10-19 7:34 ` [PATCH 12/31] target/loongarch: Add timer related instructions support Xiaojuan Yang
2021-10-20 5:17 ` Richard Henderson
2021-10-19 7:34 ` [PATCH 13/31] hw/pci-host: Add ls7a1000 PCIe Host bridge support for Loongson Platform Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 14/31] hw/loongarch: Add a virt loongarch 3A5000 board support Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 15/31] hw/loongarch: Add loongarch cpu interrupt support(CPUINTC) Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 16/31] hw/loongarch: Add loongarch ipi interrupt support(IPI) Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 17/31] hw/intc: Add loongarch ls7a interrupt controller support(PCH-PIC) Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 18/31] hw/intc: Add loongarch ls7a msi interrupt controller support(PCH-MSI) Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 19/31] hw/intc: Add loongarch extioi interrupt controller(EIOINTC) Xiaojuan Yang
2021-10-19 7:35 ` [PATCH 20/31] hw/loongarch: Add irq hierarchy for the system Xiaojuan Yang
2021-10-19 14:52 ` [PATCH 00/31] Add Loongarch softmmu support WANG Xuerui
[not found] ` <7d933f8d.228e.17c9b556e98.Coremail.yangxiaojuan@loongson.cn>
2021-10-20 5:11 ` WANG Xuerui
[not found] ` <1634628917-10031-24-git-send-email-yangxiaojuan@loongson.cn>
2021-10-19 16:19 ` [PATCH 23/31] hw/loongarch: Add default bios startup support Michael S. Tsirkin
[not found] ` <1634628917-10031-2-git-send-email-yangxiaojuan@loongson.cn>
2021-10-19 18:56 ` [PATCH 01/31] target/loongarch: Upate the README for the softmmu Richard Henderson
2021-10-22 2:25 ` yangxiaojuan
[not found] ` <1634628917-10031-7-git-send-email-yangxiaojuan@loongson.cn>
2021-10-19 21:11 ` [PATCH 06/31] target/loongarch: Add mmu support for Loongarch CPU Richard Henderson
[not found] ` <1634628917-10031-8-git-send-email-yangxiaojuan@loongson.cn>
2021-10-20 1:36 ` Richard Henderson [this message]
2021-10-29 6:26 ` [PATCH 07/31] target/loongarch: Add loongarch csr/iocsr instruction support yangxiaojuan
2021-10-29 17:38 ` Richard Henderson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=cb33aeb0-3a82-1300-cbbc-3e260cee8a5f@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=alistair.francis@wdc.com \
--cc=bmeng.cn@gmail.com \
--cc=chenhuacai@loongson.cn \
--cc=david@gibson.dropbear.id.au \
--cc=f4bug@amsat.org \
--cc=gaosong@loongson.cn \
--cc=laurent@vivier.eu \
--cc=maobibo@loongson.cn \
--cc=mark.cave-ayland@ilande.co.uk \
--cc=mst@redhat.com \
--cc=pbonzini@redhat.com \
--cc=peter.maydell@linaro.org \
--cc=peterx@redhat.com \
--cc=philmd@redhat.com \
--cc=qemu-devel@nongnu.org \
--cc=thuth@redhat.com \
--cc=yangxiaojuan@loongson.cn \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).