aboutsummaryrefslogtreecommitdiff
path: root/target/mips/tcg/lcsr_translate.c
blob: 352b0f43282de0d98653c9b2762ad59dc98d7b69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
 * Loongson CSR instructions translation routines
 *
 *  Copyright (c) 2023 Jiaxun Yang <jiaxun.yang@flygoat.com>
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "qemu/osdep.h"
#include "cpu.h"
#include "tcg/tcg-op.h"
#include "tcg/tcg-op-gvec.h"
#include "exec/helper-gen.h"
#include "translate.h"

/* Include the auto-generated decoder.  */
#include "decode-lcsr.c.inc"

static bool trans_CPUCFG(DisasContext *ctx, arg_CPUCFG *a)
{
    TCGv dest = tcg_temp_new();
    TCGv src1 = tcg_temp_new();

    gen_load_gpr(src1, a->rs);
    gen_helper_lcsr_cpucfg(dest, tcg_env, src1);
    gen_store_gpr(dest, a->rd);

    return true;
}

#ifndef CONFIG_USER_ONLY
static bool gen_rdcsr(DisasContext *ctx, arg_r *a,
                        void (*func)(TCGv, TCGv_ptr, TCGv))
{
    TCGv dest = tcg_temp_new();
    TCGv src1 = tcg_temp_new();

    check_cp0_enabled(ctx);
    gen_load_gpr(src1, a->rs);
    func(dest, tcg_env, src1);
    gen_store_gpr(dest, a->rd);

    return true;
}

static bool gen_wrcsr(DisasContext *ctx, arg_r *a,
                        void (*func)(TCGv_ptr, TCGv, TCGv))
{
    TCGv val = tcg_temp_new();
    TCGv addr = tcg_temp_new();

    check_cp0_enabled(ctx);
    gen_load_gpr(addr, a->rs);
    gen_load_gpr(val, a->rd);
    func(tcg_env, addr, val);

    return true;
}

TRANS(RDCSR, gen_rdcsr, gen_helper_lcsr_rdcsr)
TRANS(DRDCSR, gen_rdcsr, gen_helper_lcsr_drdcsr)
TRANS(WRCSR, gen_wrcsr, gen_helper_lcsr_wrcsr)
TRANS(DWRCSR, gen_wrcsr, gen_helper_lcsr_dwrcsr)
#else
#define GEN_FALSE_TRANS(name)   \
static bool trans_##name(DisasContext *ctx, arg_##name * a)  \
{   \
    return false;   \
}

GEN_FALSE_TRANS(RDCSR)
GEN_FALSE_TRANS(DRDCSR)
GEN_FALSE_TRANS(WRCSR)
GEN_FALSE_TRANS(DWRCSR)
#endif