2 * RISC-V translation routines for the RISC-V privileged instructions.
4 * Copyright (c) 2016-2017 Sagar Karandikar, sagark@eecs.berkeley.edu
5 * Copyright (c) 2018 Peer Adelt, peer.adelt@hni.uni-paderborn.de
6 * Bastian Koppelmann, kbastian@mail.uni-paderborn.de
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms and conditions of the GNU General Public License,
10 * version 2 or later, as published by the Free Software Foundation.
12 * This program is distributed in the hope it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program. If not, see <http://www.gnu.org/licenses/>.
21 static bool trans_ecall(DisasContext
*ctx
, arg_ecall
*a
)
23 /* always generates U-level ECALL, fixed in do_interrupt handler */
24 generate_exception(ctx
, RISCV_EXCP_U_ECALL
);
25 exit_tb(ctx
); /* no chaining */
26 ctx
->base
.is_jmp
= DISAS_NORETURN
;
30 static bool trans_ebreak(DisasContext
*ctx
, arg_ebreak
*a
)
32 generate_exception(ctx
, RISCV_EXCP_BREAKPOINT
);
33 exit_tb(ctx
); /* no chaining */
34 ctx
->base
.is_jmp
= DISAS_NORETURN
;
38 static bool trans_uret(DisasContext
*ctx
, arg_uret
*a
)
43 static bool trans_sret(DisasContext
*ctx
, arg_sret
*a
)
45 #ifndef CONFIG_USER_ONLY
46 tcg_gen_movi_tl(cpu_pc
, ctx
->base
.pc_next
);
48 if (has_ext(ctx
, RVS
)) {
49 gen_helper_sret(cpu_pc
, cpu_env
, cpu_pc
);
50 exit_tb(ctx
); /* no chaining */
51 ctx
->base
.is_jmp
= DISAS_NORETURN
;
61 static bool trans_mret(DisasContext
*ctx
, arg_mret
*a
)
63 #ifndef CONFIG_USER_ONLY
64 tcg_gen_movi_tl(cpu_pc
, ctx
->base
.pc_next
);
65 gen_helper_mret(cpu_pc
, cpu_env
, cpu_pc
);
66 exit_tb(ctx
); /* no chaining */
67 ctx
->base
.is_jmp
= DISAS_NORETURN
;
74 static bool trans_wfi(DisasContext
*ctx
, arg_wfi
*a
)
76 #ifndef CONFIG_USER_ONLY
77 tcg_gen_movi_tl(cpu_pc
, ctx
->pc_succ_insn
);
78 gen_helper_wfi(cpu_env
);
85 static bool trans_sfence_vma(DisasContext
*ctx
, arg_sfence_vma
*a
)
87 #ifndef CONFIG_USER_ONLY
88 if (ctx
->priv_ver
>= PRIV_VERSION_1_10_0
) {
89 gen_helper_tlb_flush(cpu_env
);
96 static bool trans_sfence_vm(DisasContext
*ctx
, arg_sfence_vm
*a
)
98 #ifndef CONFIG_USER_ONLY
99 if (ctx
->priv_ver
<= PRIV_VERSION_1_09_1
) {
100 gen_helper_tlb_flush(cpu_env
);
107 static bool trans_hfence_gvma(DisasContext
*ctx
, arg_sfence_vma
*a
)
109 #ifndef CONFIG_USER_ONLY
110 if (ctx
->priv_ver
>= PRIV_VERSION_1_10_0
&&
112 /* Hpervisor extensions exist */
114 * if (env->priv == PRV_M ||
115 * (env->priv == PRV_S &&
116 * !riscv_cpu_virt_enabled(env) &&
117 * get_field(ctx->mstatus_fs, MSTATUS_TVM))) {
119 gen_helper_tlb_flush(cpu_env
);
127 static bool trans_hfence_bvma(DisasContext
*ctx
, arg_sfence_vma
*a
)
129 #ifndef CONFIG_USER_ONLY
130 if (ctx
->priv_ver
>= PRIV_VERSION_1_10_0
&&
132 /* Hpervisor extensions exist */
134 * if (env->priv == PRV_M ||
135 * (env->priv == PRV_S &&
136 * !riscv_cpu_virt_enabled(env) &&
137 * get_field(ctx->mstatus_fs, MSTATUS_TVM))) {
139 gen_helper_tlb_flush(cpu_env
);