blob: 1c90a30759352b529697fd5780a6470b08b17bf7 [file] [log] [blame]
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +02001/*
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"
Pierrick Bouvier8d535c32025-03-24 21:58:48 -070021#include "cpu.h"
Philippe Mathieu-Daudé0f665362025-01-23 13:39:05 +010022#include "system/accel-ops.h"
Philippe Mathieu-Daudé32cad1f2024-12-03 15:20:13 +010023#include "system/cpus.h"
Pierrick Bouvierd97c3b062025-03-24 21:58:59 -070024#include "exec/cpu-common.h"
Philippe Mathieu-Daudé42508262023-12-12 11:34:25 +010025#include "exec/tswap.h"
Philippe Mathieu-Daudé5b5968c2022-12-19 18:09:43 +010026#include "exec/replay-core.h"
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020027#include "exec/log.h"
Philippe Mathieu-Daudé24920082025-04-02 05:32:03 +020028#include "hw/core/cpu.h"
Richard Hendersonad1a7062021-07-01 08:10:53 -070029#include "trace/trace-root.h"
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020030
Pierrick Bouvier8d535c32025-03-24 21:58:48 -070031/* Validate correct placement of CPUArchState. */
32QEMU_BUILD_BUG_ON(offsetof(ArchCPU, parent_obj) != 0);
33QEMU_BUILD_BUG_ON(offsetof(ArchCPU, env) != sizeof(CPUState));
34
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020035/* enable or disable single step mode. EXCP_DEBUG is returned by the
36 CPU loop after each instruction */
37void cpu_single_step(CPUState *cpu, int enabled)
38{
39 if (cpu->singlestep_enabled != enabled) {
40 cpu->singlestep_enabled = enabled;
Mads Ynddal412ae122023-03-02 18:58:05 -080041
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);
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020046 }
Mads Ynddal412ae122023-03-02 18:58:05 -080047#endif
48
Richard Hendersonad1a7062021-07-01 08:10:53 -070049 trace_breakpoint_singlestep(cpu->cpu_index, enabled);
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020050 }
51}
52
53void 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()) {
Richard Hendersonc60f5992022-04-17 11:29:47 -070065 FILE *logfile = qemu_log_trylock();
Richard Henderson78b54852022-04-17 11:29:49 -070066 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);
Richard Henderson78b54852022-04-17 11:29:49 -070071 qemu_log_unlock(logfile);
72 }
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020073 }
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
Philippe Mathieu-Daudéb939b8e2025-04-17 09:31:24 +020089#undef target_big_endian
90bool target_big_endian(void)
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020091{
Thomas Huthded625e2023-09-07 13:35:00 +020092 return TARGET_BIG_ENDIAN;
Paolo Bonzinid9f24bf2020-10-06 09:05:29 +020093}