Add cpu_raise_excp without host state restoration and cpu_raise_excp_restore with explicit state restoration.
Signed-off-by: Yonggang Luo <[email protected]> --- accel/tcg/cpu-exec-common.c | 13 +++++++++++++ include/accel/tcg/cpu-loop.h | 22 ++++++++++++++++++++++ 2 files changed, 35 insertions(+) diff --git a/accel/tcg/cpu-exec-common.c b/accel/tcg/cpu-exec-common.c index d20cece1c5f..b551c1439ec 100644 --- a/accel/tcg/cpu-exec-common.c +++ b/accel/tcg/cpu-exec-common.c @@ -118,6 +118,19 @@ void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc) cpu_loop_exit(cpu); } +void cpu_raise_excp(CPUState *cpu, int exception_index) +{ + cpu->exception_index = exception_index; + cpu_loop_exit(cpu); +} + +void cpu_raise_excp_restore(CPUState *cpu, int exception_index, + uintptr_t retaddr) +{ + cpu->exception_index = exception_index; + cpu_loop_exit_restore(cpu, retaddr); +} + void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc) { /* Prevent looping if already executing in a serial context. */ diff --git a/include/accel/tcg/cpu-loop.h b/include/accel/tcg/cpu-loop.h index f4d38bc2bca..5282c70d5e4 100644 --- a/include/accel/tcg/cpu-loop.h +++ b/include/accel/tcg/cpu-loop.h @@ -65,6 +65,28 @@ G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu); G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t host_pc); G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t host_pc); +/** + * cpu_raise_excp: + * @cpu: the cpu context + * @exception_index: EXCP_* or target trap number + * + * Raise @exception_index and exit the current TB without restoring guest + * state. + */ +G_NORETURN void cpu_raise_excp(CPUState *cpu, int exception_index); + +/** + * cpu_raise_excp_restore: + * @cpu: the cpu context + * @exception_index: EXCP_* or target trap number + * @retaddr: the host pc within the translation + * + * Raise @exception_index and exit the current TB. Restore guest state from + * @retaddr when nonzero; otherwise, behave like cpu_raise_excp(). + */ +G_NORETURN void cpu_raise_excp_restore(CPUState *cpu, int exception_index, + uintptr_t retaddr); + /** * cpu_loop_exit: * @cpu: the cpu context -- 2.52.0.windows.1
