2 * RISC-V CPU init and loop
4 * Copyright (c) 2019 Mark Corbin
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 #ifndef TARGET_ARCH_CPU_H
21 #define TARGET_ARCH_CPU_H
23 #include "target_arch.h"
24 #include "signal-common.h"
26 #define TARGET_DEFAULT_CPU_MODEL "max"
28 static inline void target_cpu_init(CPURISCVState
*env
,
29 struct target_pt_regs
*regs
)
33 for (i
= 1; i
< 32; i
++) {
34 env
->gpr
[i
] = regs
->regs
[i
];
40 static inline void target_cpu_loop(CPURISCVState
*env
)
42 CPUState
*cs
= env_cpu(env
);
45 unsigned int syscall_num
;
50 trapnr
= cpu_exec(cs
);
52 process_queued_cpu_work(cs
);
58 /* just indicate that signals should be handled asap */
61 cpu_exec_step_atomic(cs
);
63 case RISCV_EXCP_U_ECALL
:
64 syscall_num
= env
->gpr
[xT0
];
65 env
->pc
+= TARGET_INSN_SIZE
;
66 /* Compare to cpu_fetch_syscall_args() in riscv/riscv/trap.c */
67 if (TARGET_FREEBSD_NR___syscall
== syscall_num
||
68 TARGET_FREEBSD_NR_syscall
== syscall_num
) {
69 ret
= do_freebsd_syscall(env
,
80 ret
= do_freebsd_syscall(env
,
94 * Compare to cpu_set_syscall_retval() in
95 * riscv/riscv/vm_machdep.c
100 } else if (ret
== -TARGET_ERESTART
) {
101 env
->pc
-= TARGET_INSN_SIZE
;
102 } else if (ret
!= -TARGET_EJUSTRETURN
) {
103 env
->gpr
[xA0
] = -ret
;
107 case RISCV_EXCP_ILLEGAL_INST
:
108 signo
= TARGET_SIGILL
;
109 code
= TARGET_ILL_ILLOPC
;
111 case RISCV_EXCP_BREAKPOINT
:
112 signo
= TARGET_SIGTRAP
;
113 code
= TARGET_TRAP_BRKPT
;
116 signo
= TARGET_SIGTRAP
;
117 code
= TARGET_TRAP_BRKPT
;
120 fprintf(stderr
, "qemu: unhandled CPU exception "
121 "0x%x - aborting\n", trapnr
);
122 cpu_dump_state(cs
, stderr
, 0);
127 force_sig_fault(signo
, code
, env
->pc
);
130 process_pending_signals(env
);
134 static inline void target_cpu_clone_regs(CPURISCVState
*env
, target_ulong newsp
)
137 env
->gpr
[xSP
] = newsp
;
144 static inline void target_cpu_reset(CPUArchState
*env
)
148 #endif /* TARGET_ARCH_CPU_H */