xref: /qemu/include/user/cpu_loop.h (revision 1bf0d6e476f34aadda8b052f747a5a5026119de2)
1cd71c089SLaurent Vivier /*
2cd71c089SLaurent Vivier  *  qemu user cpu loop
3cd71c089SLaurent Vivier  *
4cd71c089SLaurent Vivier  *  Copyright (c) 2003-2008 Fabrice Bellard
5cd71c089SLaurent Vivier  *
6cd71c089SLaurent Vivier  *  This program is free software; you can redistribute it and/or modify
7cd71c089SLaurent Vivier  *  it under the terms of the GNU General Public License as published by
8cd71c089SLaurent Vivier  *  the Free Software Foundation; either version 2 of the License, or
9cd71c089SLaurent Vivier  *  (at your option) any later version.
10cd71c089SLaurent Vivier  *
11cd71c089SLaurent Vivier  *  This program is distributed in the hope that it will be useful,
12cd71c089SLaurent Vivier  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13cd71c089SLaurent Vivier  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14cd71c089SLaurent Vivier  *  GNU General Public License for more details.
15cd71c089SLaurent Vivier  *
16cd71c089SLaurent Vivier  *  You should have received a copy of the GNU General Public License
17cd71c089SLaurent Vivier  *  along with this program; if not, see <http://www.gnu.org/licenses/>.
18cd71c089SLaurent Vivier  */
19cd71c089SLaurent Vivier 
20b74c8981SPhilippe Mathieu-Daudé #ifndef USER_CPU_LOOP_H
21b74c8981SPhilippe Mathieu-Daudé #define USER_CPU_LOOP_H
22cd71c089SLaurent Vivier 
23*1bf0d6e4SPhilippe Mathieu-Daudé #include "exec/abi_ptr.h"
24*1bf0d6e4SPhilippe Mathieu-Daudé #include "exec/mmu-access-type.h"
25cd71c089SLaurent Vivier #include "exec/log.h"
26*1bf0d6e4SPhilippe Mathieu-Daudé #include "exec/target_long.h"
275da4063fSRichard Henderson #include "special-errno.h"
28cd71c089SLaurent Vivier 
29*1bf0d6e4SPhilippe Mathieu-Daudé /**
30*1bf0d6e4SPhilippe Mathieu-Daudé  * adjust_signal_pc:
31*1bf0d6e4SPhilippe Mathieu-Daudé  * @pc: raw pc from the host signal ucontext_t.
32*1bf0d6e4SPhilippe Mathieu-Daudé  * @is_write: host memory operation was write, or read-modify-write.
33*1bf0d6e4SPhilippe Mathieu-Daudé  *
34*1bf0d6e4SPhilippe Mathieu-Daudé  * Alter @pc as required for unwinding.  Return the type of the
35*1bf0d6e4SPhilippe Mathieu-Daudé  * guest memory access -- host reads may be for guest execution.
36*1bf0d6e4SPhilippe Mathieu-Daudé  */
37*1bf0d6e4SPhilippe Mathieu-Daudé MMUAccessType adjust_signal_pc(uintptr_t *pc, bool is_write);
38*1bf0d6e4SPhilippe Mathieu-Daudé 
39*1bf0d6e4SPhilippe Mathieu-Daudé /**
40*1bf0d6e4SPhilippe Mathieu-Daudé  * handle_sigsegv_accerr_write:
41*1bf0d6e4SPhilippe Mathieu-Daudé  * @cpu: the cpu context
42*1bf0d6e4SPhilippe Mathieu-Daudé  * @old_set: the sigset_t from the signal ucontext_t
43*1bf0d6e4SPhilippe Mathieu-Daudé  * @host_pc: the host pc, adjusted for the signal
44*1bf0d6e4SPhilippe Mathieu-Daudé  * @host_addr: the host address of the fault
45*1bf0d6e4SPhilippe Mathieu-Daudé  *
46*1bf0d6e4SPhilippe Mathieu-Daudé  * Return true if the write fault has been handled, and should be re-tried.
47*1bf0d6e4SPhilippe Mathieu-Daudé  */
48*1bf0d6e4SPhilippe Mathieu-Daudé bool handle_sigsegv_accerr_write(CPUState *cpu, sigset_t *old_set,
49*1bf0d6e4SPhilippe Mathieu-Daudé                                  uintptr_t host_pc, abi_ptr guest_addr);
50*1bf0d6e4SPhilippe Mathieu-Daudé 
51*1bf0d6e4SPhilippe Mathieu-Daudé /**
52*1bf0d6e4SPhilippe Mathieu-Daudé  * cpu_loop_exit_sigsegv:
53*1bf0d6e4SPhilippe Mathieu-Daudé  * @cpu: the cpu context
54*1bf0d6e4SPhilippe Mathieu-Daudé  * @addr: the guest address of the fault
55*1bf0d6e4SPhilippe Mathieu-Daudé  * @access_type: access was read/write/execute
56*1bf0d6e4SPhilippe Mathieu-Daudé  * @maperr: true for invalid page, false for permission fault
57*1bf0d6e4SPhilippe Mathieu-Daudé  * @ra: host pc for unwinding
58*1bf0d6e4SPhilippe Mathieu-Daudé  *
59*1bf0d6e4SPhilippe Mathieu-Daudé  * Use the TCGCPUOps hook to record cpu state, do guest operating system
60*1bf0d6e4SPhilippe Mathieu-Daudé  * specific things to raise SIGSEGV, and jump to the main cpu loop.
61*1bf0d6e4SPhilippe Mathieu-Daudé  */
62*1bf0d6e4SPhilippe Mathieu-Daudé G_NORETURN void cpu_loop_exit_sigsegv(CPUState *cpu, target_ulong addr,
63*1bf0d6e4SPhilippe Mathieu-Daudé                                       MMUAccessType access_type,
64*1bf0d6e4SPhilippe Mathieu-Daudé                                       bool maperr, uintptr_t ra);
65*1bf0d6e4SPhilippe Mathieu-Daudé 
66*1bf0d6e4SPhilippe Mathieu-Daudé /**
67*1bf0d6e4SPhilippe Mathieu-Daudé  * cpu_loop_exit_sigbus:
68*1bf0d6e4SPhilippe Mathieu-Daudé  * @cpu: the cpu context
69*1bf0d6e4SPhilippe Mathieu-Daudé  * @addr: the guest address of the alignment fault
70*1bf0d6e4SPhilippe Mathieu-Daudé  * @access_type: access was read/write/execute
71*1bf0d6e4SPhilippe Mathieu-Daudé  * @ra: host pc for unwinding
72*1bf0d6e4SPhilippe Mathieu-Daudé  *
73*1bf0d6e4SPhilippe Mathieu-Daudé  * Use the TCGCPUOps hook to record cpu state, do guest operating system
74*1bf0d6e4SPhilippe Mathieu-Daudé  * specific things to raise SIGBUS, and jump to the main cpu loop.
75*1bf0d6e4SPhilippe Mathieu-Daudé  */
76*1bf0d6e4SPhilippe Mathieu-Daudé G_NORETURN void cpu_loop_exit_sigbus(CPUState *cpu, target_ulong addr,
77*1bf0d6e4SPhilippe Mathieu-Daudé                                      MMUAccessType access_type,
78*1bf0d6e4SPhilippe Mathieu-Daudé                                      uintptr_t ra);
79*1bf0d6e4SPhilippe Mathieu-Daudé 
80166a4b6eSPhilippe Mathieu-Daudé G_NORETURN void cpu_loop(CPUArchState *env);
81166a4b6eSPhilippe Mathieu-Daudé 
82bd5ccd61SHelge Deller void target_exception_dump(CPUArchState *env, const char *fmt, int code);
83bd5ccd61SHelge Deller #define EXCP_DUMP(env, fmt, code) \
84bd5ccd61SHelge Deller     target_exception_dump(env, fmt, code)
85cd71c089SLaurent Vivier 
86fb5c28e1SPhilippe Mathieu-Daudé typedef struct target_pt_regs target_pt_regs;
87fb5c28e1SPhilippe Mathieu-Daudé 
88fb5c28e1SPhilippe Mathieu-Daudé void target_cpu_copy_regs(CPUArchState *env, target_pt_regs *regs);
89fb5c28e1SPhilippe Mathieu-Daudé 
90cd71c089SLaurent Vivier #endif
91