4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, see <http://www.gnu.org/licenses/>.
20 #include "qemu/osdep.h"
21 #include "qemu/error-report.h"
23 #include "cpu_loop-common.h"
26 void cpu_loop(CPURISCVState
*env
)
28 CPUState
*cs
= CPU(riscv_env_get_cpu(env
));
29 int trapnr
, signum
, sigcode
;
35 trapnr
= cpu_exec(cs
);
37 process_queued_cpu_work(cs
);
45 /* just indicate that signals should be handled asap */
48 cpu_exec_step_atomic(cs
);
50 case RISCV_EXCP_U_ECALL
:
52 if (env
->gpr
[xA7
] == TARGET_NR_arch_specific_syscall
+ 15) {
53 /* riscv_flush_icache_syscall is a no-op in QEMU as
54 self-modifying code is automatically detected */
58 env
->gpr
[(env
->elf_flags
& EF_RISCV_RVE
)
68 if (ret
== -TARGET_ERESTARTSYS
) {
70 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
73 if (cs
->singlestep_enabled
) {
77 case RISCV_EXCP_ILLEGAL_INST
:
78 signum
= TARGET_SIGILL
;
79 sigcode
= TARGET_ILL_ILLOPC
;
81 case RISCV_EXCP_BREAKPOINT
:
82 signum
= TARGET_SIGTRAP
;
83 sigcode
= TARGET_TRAP_BRKPT
;
86 case RISCV_EXCP_INST_PAGE_FAULT
:
87 case RISCV_EXCP_LOAD_PAGE_FAULT
:
88 case RISCV_EXCP_STORE_PAGE_FAULT
:
89 signum
= TARGET_SIGSEGV
;
90 sigcode
= TARGET_SEGV_MAPERR
;
94 signum
= TARGET_SIGTRAP
;
95 sigcode
= TARGET_TRAP_BRKPT
;
98 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
104 target_siginfo_t info
= {
108 ._sifields
._sigfault
._addr
= sigaddr
110 queue_signal(env
, info
.si_signo
, QEMU_SI_KILL
, &info
);
113 process_pending_signals(env
);
117 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
119 CPUState
*cpu
= ENV_GET_CPU(env
);
120 TaskState
*ts
= cpu
->opaque
;
121 struct image_info
*info
= ts
->info
;
123 env
->pc
= regs
->sepc
;
124 env
->gpr
[xSP
] = regs
->sp
;
125 env
->elf_flags
= info
->elf_flags
;
127 if ((env
->misa
& RVE
) && !(env
->elf_flags
& EF_RISCV_RVE
)) {
128 error_report("Incompatible ELF: RVE cpu requires RVE ABI binary");