xref: /qemu/cpu-target.c (revision 3d881164d4fb2b0f6791cf28d9725926b8ded0d6)
1 /*
2  * Target-specific parts of the CPU object
3  *
4  *  Copyright (c) 2003 Fabrice Bellard
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2 of the License, or (at your option) any later version.
10  *
11  * This library 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 GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 #include "qemu/osdep.h"
21 #include "cpu.h"
22 #include "system/accel-ops.h"
23 #include "system/cpus.h"
24 #include "exec/cpu-common.h"
25 #include "exec/tswap.h"
26 #include "exec/replay-core.h"
27 #include "exec/log.h"
28 #include "hw/core/cpu.h"
29 #include "trace/trace-root.h"
30 
31 /* Validate correct placement of CPUArchState. */
32 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
33 QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
34 
35 /* enable or disable single step mode. EXCP_DEBUG is returned by the
36    CPU loop after each instruction */
cpu_single_step(CPUState * cpu,int enabled)37 void cpu_single_step(CPUState *cpu, int enabled)
38 {
39     if (cpu->singlestep_enabled != enabled) {
40         cpu->singlestep_enabled = enabled;
41 
42 #if !defined(CONFIG_USER_ONLY)
43         const AccelOpsClass *ops = cpus_get_accel();
44         if (ops->update_guest_debug) {
45             ops->update_guest_debug(cpu);
46         }
47 #endif
48 
49         trace_breakpoint_singlestep(cpu->cpu_index, enabled);
50     }
51 }
52 
cpu_abort(CPUState * cpu,const char * fmt,...)53 void cpu_abort(CPUState *cpu, const char *fmt, ...)
54 {
55     va_list ap;
56     va_list ap2;
57 
58     va_start(ap, fmt);
59     va_copy(ap2, ap);
60     fprintf(stderr, "qemu: fatal: ");
61     vfprintf(stderr, fmt, ap);
62     fprintf(stderr, "\n");
63     cpu_dump_state(cpu, stderr, CPU_DUMP_FPU | CPU_DUMP_CCOP);
64     if (qemu_log_separate()) {
65         FILE *logfile = qemu_log_trylock();
66         if (logfile) {
67             fprintf(logfile, "qemu: fatal: ");
68             vfprintf(logfile, fmt, ap2);
69             fprintf(logfile, "\n");
70             cpu_dump_state(cpu, logfile, CPU_DUMP_FPU | CPU_DUMP_CCOP);
71             qemu_log_unlock(logfile);
72         }
73     }
74     va_end(ap2);
75     va_end(ap);
76     replay_finish();
77 #if defined(CONFIG_USER_ONLY)
78     {
79         struct sigaction act;
80         sigfillset(&act.sa_mask);
81         act.sa_handler = SIG_DFL;
82         act.sa_flags = 0;
83         sigaction(SIGABRT, &act, NULL);
84     }
85 #endif
86     abort();
87 }
88 
89 #undef target_big_endian
target_big_endian(void)90 bool target_big_endian(void)
91 {
92     return TARGET_BIG_ENDIAN;
93 }
94