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 tcg_gen_exit_tb(NULL
, 0); /* 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 tcg_gen_exit_tb(NULL
, 0); /* 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 tcg_gen_exit_tb(NULL
, 0); /* no chaining */
51 ctx
->base
.is_jmp
= DISAS_NORETURN
;
61 static bool trans_hret(DisasContext
*ctx
, arg_hret
*a
)
66 static bool trans_mret(DisasContext
*ctx
, arg_mret
*a
)
68 #ifndef CONFIG_USER_ONLY
69 tcg_gen_movi_tl(cpu_pc
, ctx
->base
.pc_next
);
70 gen_helper_mret(cpu_pc
, cpu_env
, cpu_pc
);
71 tcg_gen_exit_tb(NULL
, 0); /* no chaining */
72 ctx
->base
.is_jmp
= DISAS_NORETURN
;
79 static bool trans_wfi(DisasContext
*ctx
, arg_wfi
*a
)
81 #ifndef CONFIG_USER_ONLY
82 tcg_gen_movi_tl(cpu_pc
, ctx
->pc_succ_insn
);
83 gen_helper_wfi(cpu_env
);
90 static bool trans_sfence_vma(DisasContext
*ctx
, arg_sfence_vma
*a
)
92 #ifndef CONFIG_USER_ONLY
93 if (ctx
->priv_ver
== PRIV_VERSION_1_10_0
) {
94 gen_helper_tlb_flush(cpu_env
);
101 static bool trans_sfence_vm(DisasContext
*ctx
, arg_sfence_vm
*a
)
103 #ifndef CONFIG_USER_ONLY
104 if (ctx
->priv_ver
<= PRIV_VERSION_1_09_1
) {
105 gen_helper_tlb_flush(cpu_env
);