Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 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" |
Pierrick Bouvier | 8d535c3 | 2025-03-24 21:58:48 -0700 | [diff] [blame] | 21 | #include "cpu.h" |
Philippe Mathieu-Daudé | 0f66536 | 2025-01-23 13:39:05 +0100 | [diff] [blame] | 22 | #include "system/accel-ops.h" |
Philippe Mathieu-Daudé | 32cad1f | 2024-12-03 15:20:13 +0100 | [diff] [blame] | 23 | #include "system/cpus.h" |
Pierrick Bouvier | d97c3b06 | 2025-03-24 21:58:59 -0700 | [diff] [blame] | 24 | #include "exec/cpu-common.h" |
Philippe Mathieu-Daudé | 4250826 | 2023-12-12 11:34:25 +0100 | [diff] [blame] | 25 | #include "exec/tswap.h" |
Philippe Mathieu-Daudé | 5b5968c | 2022-12-19 18:09:43 +0100 | [diff] [blame] | 26 | #include "exec/replay-core.h" |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 27 | #include "exec/log.h" |
Philippe Mathieu-Daudé | 2492008 | 2025-04-02 05:32:03 +0200 | [diff] [blame] | 28 | #include "hw/core/cpu.h" |
Richard Henderson | ad1a706 | 2021-07-01 08:10:53 -0700 | [diff] [blame] | 29 | #include "trace/trace-root.h" |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 30 | |
Pierrick Bouvier | 8d535c3 | 2025-03-24 21:58:48 -0700 | [diff] [blame] | 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 | |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 35 | /* enable or disable single step mode. EXCP_DEBUG is returned by the |
| 36 | CPU loop after each instruction */ |
| 37 | void cpu_single_step(CPUState *cpu, int enabled) |
| 38 | { |
| 39 | if (cpu->singlestep_enabled != enabled) { |
| 40 | cpu->singlestep_enabled = enabled; |
Mads Ynddal | 412ae12 | 2023-03-02 18:58:05 -0800 | [diff] [blame] | 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); |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 46 | } |
Mads Ynddal | 412ae12 | 2023-03-02 18:58:05 -0800 | [diff] [blame] | 47 | #endif |
| 48 | |
Richard Henderson | ad1a706 | 2021-07-01 08:10:53 -0700 | [diff] [blame] | 49 | trace_breakpoint_singlestep(cpu->cpu_index, enabled); |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 50 | } |
| 51 | } |
| 52 | |
| 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()) { |
Richard Henderson | c60f599 | 2022-04-17 11:29:47 -0700 | [diff] [blame] | 65 | FILE *logfile = qemu_log_trylock(); |
Richard Henderson | 78b5485 | 2022-04-17 11:29:49 -0700 | [diff] [blame] | 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); |
Richard Henderson | 78b5485 | 2022-04-17 11:29:49 -0700 | [diff] [blame] | 71 | qemu_log_unlock(logfile); |
| 72 | } |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 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 | |
Philippe Mathieu-Daudé | b939b8e | 2025-04-17 09:31:24 +0200 | [diff] [blame] | 89 | #undef target_big_endian |
| 90 | bool target_big_endian(void) |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 91 | { |
Thomas Huth | ded625e | 2023-09-07 13:35:00 +0200 | [diff] [blame] | 92 | return TARGET_BIG_ENDIAN; |
Paolo Bonzini | d9f24bf | 2020-10-06 09:05:29 +0200 | [diff] [blame] | 93 | } |