2024-04-24 18:04:09 +02:00
|
|
|
/*
|
|
|
|
|
* CPU interfaces that are target independent.
|
|
|
|
|
*
|
|
|
|
|
* Copyright (c) 2003 Fabrice Bellard
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: LGPL-2.1+
|
|
|
|
|
*/
|
2009-05-19 16:17:58 +01:00
|
|
|
#ifndef CPU_COMMON_H
|
2016-06-29 15:29:06 +02:00
|
|
|
#define CPU_COMMON_H
|
2009-05-19 16:17:58 +01:00
|
|
|
|
2026-06-17 13:10:22 +02:00
|
|
|
#include "qemu/thread.h"
|
2024-01-19 15:40:06 +01:00
|
|
|
#include "hw/core/cpu.h"
|
2010-04-01 19:57:10 +02:00
|
|
|
|
2023-09-14 20:57:07 +02:00
|
|
|
#define EXCP_INTERRUPT 0x10000 /* async interruption */
|
|
|
|
|
#define EXCP_HLT 0x10001 /* hlt instruction reached */
|
|
|
|
|
#define EXCP_DEBUG 0x10002 /* cpu stopped after a breakpoint or singlestep */
|
|
|
|
|
#define EXCP_HALTED 0x10003 /* cpu is halted (waiting for external event) */
|
|
|
|
|
#define EXCP_YIELD 0x10004 /* cpu wants to yield timeslice to another */
|
|
|
|
|
#define EXCP_ATOMIC 0x10005 /* stop-the-world and emulate atomic */
|
|
|
|
|
|
2022-03-23 19:57:22 +04:00
|
|
|
#define REAL_HOST_PAGE_ALIGN(addr) ROUND_UP((addr), qemu_real_host_page_size())
|
2022-01-20 01:08:36 +01:00
|
|
|
|
2017-08-04 23:46:31 -04:00
|
|
|
/* The CPU list lock nests outside page_(un)lock or mmap_(un)lock */
|
2023-04-27 03:09:24 +01:00
|
|
|
extern QemuMutex qemu_cpu_list_lock;
|
2016-08-28 03:45:14 +02:00
|
|
|
void qemu_init_cpu_list(void);
|
|
|
|
|
void cpu_list_lock(void);
|
|
|
|
|
void cpu_list_unlock(void);
|
2022-06-26 01:38:31 +08:00
|
|
|
unsigned int cpu_list_generation_id_get(void);
|
2016-08-28 03:45:14 +02:00
|
|
|
|
2024-06-18 13:53:53 +05:30
|
|
|
int cpu_get_free_index(void);
|
|
|
|
|
|
2021-05-16 19:01:31 +02:00
|
|
|
/**
|
|
|
|
|
* cpu_address_space_init:
|
|
|
|
|
* @cpu: CPU to add this address space to
|
|
|
|
|
* @asidx: integer index of this address space
|
|
|
|
|
* @prefix: prefix to be used as name of address space
|
|
|
|
|
* @mr: the root memory region of address space
|
|
|
|
|
*
|
|
|
|
|
* Add the specified address space to the CPU's cpu_ases list.
|
|
|
|
|
* The address space added with @asidx 0 is the one used for the
|
|
|
|
|
* convenience pointer cpu->as.
|
|
|
|
|
* The target-specific code which registers ASes is responsible
|
|
|
|
|
* for defining what semantics address space 0, 1, 2, etc have.
|
|
|
|
|
*
|
|
|
|
|
* Note that with KVM only one address space is supported.
|
|
|
|
|
*/
|
|
|
|
|
void cpu_address_space_init(CPUState *cpu, int asidx,
|
|
|
|
|
const char *prefix, MemoryRegion *mr);
|
2024-07-16 12:15:01 +01:00
|
|
|
/**
|
2025-09-29 15:42:28 +01:00
|
|
|
* cpu_destroy_address_spaces:
|
|
|
|
|
* @cpu: CPU for which address spaces need to be destroyed
|
2024-07-16 12:15:01 +01:00
|
|
|
*
|
2025-09-29 15:42:28 +01:00
|
|
|
* Destroy all address spaces associated with this CPU; this
|
|
|
|
|
* is called as part of unrealizing the CPU.
|
2024-07-16 12:15:01 +01:00
|
|
|
*/
|
2025-09-29 15:42:28 +01:00
|
|
|
void cpu_destroy_address_spaces(CPUState *cpu);
|
2021-05-16 19:01:31 +02:00
|
|
|
|
2020-10-28 08:04:08 -04:00
|
|
|
/* vl.c */
|
2023-04-19 14:48:31 +02:00
|
|
|
void list_cpus(void);
|
2022-03-14 15:01:08 +01:00
|
|
|
|
2023-09-14 20:57:08 +02:00
|
|
|
#ifdef CONFIG_TCG
|
2024-12-17 14:47:19 +01:00
|
|
|
#include "qemu/atomic.h"
|
2024-01-10 18:09:56 +01:00
|
|
|
|
2024-12-17 14:47:19 +01:00
|
|
|
/**
|
|
|
|
|
* cpu_loop_exit_requested:
|
|
|
|
|
* @cpu: The CPU state to be tested
|
|
|
|
|
*
|
|
|
|
|
* Indicate if somebody asked for a return of the CPU to the main loop
|
|
|
|
|
* (e.g., via cpu_exit() or cpu_interrupt()).
|
|
|
|
|
*
|
|
|
|
|
* This is helpful for architectures that support interruptible
|
|
|
|
|
* instructions. After writing back all state to registers/memory, this
|
|
|
|
|
* call can be used to check if it makes sense to return to the main loop
|
|
|
|
|
* or to continue executing the interruptible instruction.
|
|
|
|
|
*/
|
|
|
|
|
static inline bool cpu_loop_exit_requested(CPUState *cpu)
|
|
|
|
|
{
|
|
|
|
|
return (int32_t)qatomic_read(&cpu->neg.icount_decr.u32) < 0;
|
|
|
|
|
}
|
|
|
|
|
|
2023-09-14 20:57:08 +02:00
|
|
|
G_NORETURN void cpu_loop_exit_noexc(CPUState *cpu);
|
|
|
|
|
G_NORETURN void cpu_loop_exit_atomic(CPUState *cpu, uintptr_t pc);
|
2025-09-24 18:50:39 +02:00
|
|
|
G_NORETURN void cpu_loop_exit_restore(CPUState *cpu, uintptr_t pc);
|
2023-09-14 20:57:08 +02:00
|
|
|
#endif /* CONFIG_TCG */
|
|
|
|
|
G_NORETURN void cpu_loop_exit(CPUState *cpu);
|
|
|
|
|
|
2024-01-19 15:40:06 +01:00
|
|
|
/**
|
|
|
|
|
* env_archcpu(env)
|
|
|
|
|
* @env: The architecture environment
|
|
|
|
|
*
|
|
|
|
|
* Return the ArchCPU associated with the environment.
|
|
|
|
|
*/
|
|
|
|
|
static inline ArchCPU *env_archcpu(CPUArchState *env)
|
|
|
|
|
{
|
|
|
|
|
return (void *)env - sizeof(CPUState);
|
|
|
|
|
}
|
|
|
|
|
|
2024-09-12 11:28:20 +02:00
|
|
|
/**
|
|
|
|
|
* env_cpu_const(env)
|
|
|
|
|
* @env: The architecture environment
|
|
|
|
|
*
|
|
|
|
|
* Return the CPUState associated with the environment.
|
|
|
|
|
*/
|
|
|
|
|
static inline const CPUState *env_cpu_const(const CPUArchState *env)
|
|
|
|
|
{
|
|
|
|
|
return (void *)env - sizeof(CPUState);
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-19 15:40:06 +01:00
|
|
|
/**
|
|
|
|
|
* env_cpu(env)
|
|
|
|
|
* @env: The architecture environment
|
|
|
|
|
*
|
|
|
|
|
* Return the CPUState associated with the environment.
|
|
|
|
|
*/
|
|
|
|
|
static inline CPUState *env_cpu(CPUArchState *env)
|
|
|
|
|
{
|
2024-09-12 11:28:20 +02:00
|
|
|
return (CPUState *)env_cpu_const(env);
|
2024-01-19 15:40:06 +01:00
|
|
|
}
|
|
|
|
|
|
2016-06-29 15:29:06 +02:00
|
|
|
#endif /* CPU_COMMON_H */
|