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-common.h"
22 #include "qemu/error-report.h"
24 #include "cpu_loop-common.h"
26 #include "semihosting/common-semi.h"
28 void cpu_loop(CPURISCVState
*env
)
30 CPUState
*cs
= env_cpu(env
);
31 int trapnr
, signum
, sigcode
;
37 trapnr
= cpu_exec(cs
);
39 process_queued_cpu_work(cs
);
47 /* just indicate that signals should be handled asap */
50 cpu_exec_step_atomic(cs
);
52 case RISCV_EXCP_U_ECALL
:
54 if (env
->gpr
[xA7
] == TARGET_NR_arch_specific_syscall
+ 15) {
55 /* riscv_flush_icache_syscall is a no-op in QEMU as
56 self-modifying code is automatically detected */
60 env
->gpr
[(env
->elf_flags
& EF_RISCV_RVE
)
70 if (ret
== -TARGET_ERESTARTSYS
) {
72 } else if (ret
!= -TARGET_QEMU_ESIGRETURN
) {
75 if (cs
->singlestep_enabled
) {
79 case RISCV_EXCP_ILLEGAL_INST
:
80 signum
= TARGET_SIGILL
;
81 sigcode
= TARGET_ILL_ILLOPC
;
83 case RISCV_EXCP_BREAKPOINT
:
84 signum
= TARGET_SIGTRAP
;
85 sigcode
= TARGET_TRAP_BRKPT
;
88 case RISCV_EXCP_INST_PAGE_FAULT
:
89 case RISCV_EXCP_LOAD_PAGE_FAULT
:
90 case RISCV_EXCP_STORE_PAGE_FAULT
:
91 signum
= TARGET_SIGSEGV
;
92 sigcode
= TARGET_SEGV_MAPERR
;
93 sigaddr
= env
->badaddr
;
95 case RISCV_EXCP_SEMIHOST
:
96 env
->gpr
[xA0
] = do_common_semihosting(cs
);
101 signum
= TARGET_SIGTRAP
;
102 sigcode
= TARGET_TRAP_BRKPT
;
105 EXCP_DUMP(env
, "\nqemu: unhandled CPU exception %#x - aborting\n",
111 target_siginfo_t info
= {
115 ._sifields
._sigfault
._addr
= sigaddr
117 queue_signal(env
, info
.si_signo
, QEMU_SI_FAULT
, &info
);
120 process_pending_signals(env
);
124 void target_cpu_copy_regs(CPUArchState
*env
, struct target_pt_regs
*regs
)
126 CPUState
*cpu
= env_cpu(env
);
127 TaskState
*ts
= cpu
->opaque
;
128 struct image_info
*info
= ts
->info
;
130 env
->pc
= regs
->sepc
;
131 env
->gpr
[xSP
] = regs
->sp
;
132 env
->elf_flags
= info
->elf_flags
;
134 if ((env
->misa
& RVE
) && !(env
->elf_flags
& EF_RISCV_RVE
)) {
135 error_report("Incompatible ELF: RVE cpu requires RVE ABI binary");
139 ts
->stack_base
= info
->start_stack
;
140 ts
->heap_base
= info
->brk
;
141 /* This will be filled in on the first SYS_HEAPINFO call. */