Move cpu_xxx functions to qom/cpu.h
This patch moves a few CPU-releated function declarations to
include/qom/cpu.h, while changing their signature to take a
CPUState instead of a CPUOldState.
Change-Id: I5f09b522dc755be334973a27f58b6704fbccc4c6
diff --git a/cpu-exec.c b/cpu-exec.c
index 3cfc079..026a251 100644
--- a/cpu-exec.c
+++ b/cpu-exec.c
@@ -45,9 +45,9 @@
//#define CONFIG_DEBUG_EXEC
//#define DEBUG_SIGNAL
-bool qemu_cpu_has_work(CPUOldState *env)
+bool qemu_cpu_has_work(CPUState *cpu)
{
- return cpu_has_work(ENV_GET_CPU(env));
+ return cpu_has_work(cpu);
}
void cpu_loop_exit(CPUArchState* env)
@@ -547,16 +547,16 @@
#if defined(TARGET_I386)
env->eflags = env->eflags | cpu_cc_compute_all(env, CC_OP)
| (DF & DF_MASK);
- log_cpu_state(env, X86_DUMP_CCOP);
+ log_cpu_state(cpu, X86_DUMP_CCOP);
env->eflags &= ~(DF_MASK | CC_O | CC_S | CC_Z | CC_A | CC_P | CC_C);
#elif defined(TARGET_M68K)
cpu_m68k_flush_flags(env, env->cc_op);
env->cc_op = CC_OP_FLAGS;
env->sr = (env->sr & 0xffe0)
| env->cc_dest | (env->cc_x << 4);
- log_cpu_state(env, 0);
+ log_cpu_state(cpu, 0);
#else
- log_cpu_state(env, 0);
+ log_cpu_state(cpu, 0);
#endif
}
#endif /* DEBUG_DISAS || CONFIG_DEBUG_EXEC */
diff --git a/cpus.c b/cpus.c
index ed08a34..02829f6 100644
--- a/cpus.c
+++ b/cpus.c
@@ -99,9 +99,9 @@
return 0;
}
-void qemu_init_vcpu(void *_env)
+void qemu_init_vcpu(CPUState *cpu)
{
- CPUOldState *env = _env;
+ CPUArchState *env = cpu->env_ptr;
if (kvm_enabled())
kvm_init_vcpu(env);
@@ -112,9 +112,9 @@
return;
}
-int qemu_cpu_self(void *env)
+bool qemu_cpu_is_self(CPUState *cpu)
{
- return 1;
+ return true;
}
void resume_all_vcpus(void)
@@ -125,7 +125,7 @@
{
}
-void qemu_cpu_kick(void *env)
+void qemu_cpu_kick(CPUState *cpu)
{
return;
}
@@ -140,7 +140,7 @@
CPUState *cpu = current_cpu;
if (cpu) {
- cpu_exit(cpu->env_ptr);
+ cpu_exit(cpu);
/*
* This is mainly for the Windows host, where the timer may be in
* a different thread with vcpu. Thus the timer function needs to
diff --git a/exec.c b/exec.c
index 8c1639f..e0a0e31 100644
--- a/exec.c
+++ b/exec.c
@@ -153,15 +153,15 @@
}
#endif
-CPUArchState *qemu_get_cpu(int cpu_index)
+CPUState *qemu_get_cpu(int cpu_index)
{
CPUState *cpu;
CPU_FOREACH(cpu) {
if (cpu->cpu_index == cpu_index)
- break;
+ return cpu;
}
- return cpu ? cpu->env_ptr : NULL;
+ return NULL;
}
void cpu_exec_init(CPUArchState *env)
@@ -457,21 +457,21 @@
spin_unlock(&interrupt_lock);
}
-void cpu_reset_interrupt(CPUOldState *env, int mask)
+void cpu_reset_interrupt(CPUState *cpu, int mask)
{
- CPUState *cpu = ENV_GET_CPU(env);
cpu->interrupt_request &= ~mask;
}
-void cpu_exit(CPUOldState *env)
+void cpu_exit(CPUState *cpu)
{
- CPUState *cpu = ENV_GET_CPU(env);
cpu->exit_request = 1;
- cpu_unlink_tb(env);
+ cpu_unlink_tb(cpu->env_ptr);
}
void cpu_abort(CPUArchState *env, const char *fmt, ...)
{
+ CPUState *cpu = ENV_GET_CPU(env);
+
va_list ap;
va_list ap2;
@@ -481,18 +481,18 @@
vfprintf(stderr, fmt, ap);
fprintf(stderr, "\n");
#ifdef TARGET_I386
- cpu_dump_state(env, stderr, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
+ cpu_dump_state(cpu, stderr, fprintf, X86_DUMP_FPU | X86_DUMP_CCOP);
#else
- cpu_dump_state(env, stderr, fprintf, 0);
+ cpu_dump_state(cpu, stderr, fprintf, 0);
#endif
if (qemu_log_enabled()) {
qemu_log("qemu: fatal: ");
qemu_log_vprintf(fmt, ap2);
qemu_log("\n");
#ifdef TARGET_I386
- log_cpu_state(env, X86_DUMP_FPU | X86_DUMP_CCOP);
+ log_cpu_state(cpu, X86_DUMP_FPU | X86_DUMP_CCOP);
#else
- log_cpu_state(env, 0);
+ log_cpu_state(cpu, 0);
#endif
qemu_log_flush();
qemu_log_close();
@@ -1539,7 +1539,8 @@
/* Generate a debug exception if a watchpoint has been hit. */
static void check_watchpoint(int offset, int len_mask, int flags)
{
- CPUArchState *env = cpu_single_env;
+ CPUState *cpu = current_cpu;
+ CPUArchState *env = cpu->env_ptr;
target_ulong pc, cs_base;
target_ulong vaddr;
CPUWatchpoint *wp;
@@ -1549,7 +1550,7 @@
/* We re-entered the check after replacing the TB. Now raise
* the debug interrupt so that is will trigger after the
* current instruction. */
- cpu_interrupt(env, CPU_INTERRUPT_DEBUG);
+ cpu_interrupt(cpu, CPU_INTERRUPT_DEBUG);
return;
}
vaddr = (env->mem_io_vaddr & TARGET_PAGE_MASK) + offset;
diff --git a/gdbstub.c b/gdbstub.c
index 28cfe1c..e18ee33 100644
--- a/gdbstub.c
+++ b/gdbstub.c
@@ -2065,7 +2065,7 @@
#ifdef CONFIG_USER_ONLY
gdb_handlesig(s->c_cpu, 0);
#else
- cpu_exit(s->c_cpu);
+ cpu_exit(ENV_GET_CPU(s->c_cpu));
#endif
}
diff --git a/hw/arm/boot.c b/hw/arm/boot.c
index 9465330..4c90148 100644
--- a/hw/arm/boot.c
+++ b/hw/arm/boot.c
@@ -46,7 +46,7 @@
{
CPUARMState *env = opaque;
- cpu_reset(env);
+ cpu_reset(ENV_GET_CPU(env));
if (env->boot_info)
arm_load_kernel(env, (struct arm_boot_info*)env->boot_info);
diff --git a/hw/arm/pic.c b/hw/arm/pic.c
index d542a82..8915f9e 100644
--- a/hw/arm/pic.c
+++ b/hw/arm/pic.c
@@ -25,18 +25,19 @@
static void arm_pic_cpu_handler(void *opaque, int irq, int level)
{
CPUOldState *env = (CPUOldState *)opaque;
+ CPUState *cpu = ENV_GET_CPU(env);
switch (irq) {
case ARM_PIC_CPU_IRQ:
if (level)
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(cpu, CPU_INTERRUPT_HARD);
else
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD);
break;
case ARM_PIC_CPU_FIQ:
if (level)
- cpu_interrupt(env, CPU_INTERRUPT_FIQ);
+ cpu_interrupt(cpu, CPU_INTERRUPT_FIQ);
else
- cpu_reset_interrupt(env, CPU_INTERRUPT_FIQ);
+ cpu_reset_interrupt(cpu, CPU_INTERRUPT_FIQ);
break;
default:
hw_error("arm_pic_cpu_handler: Bad interrput line %d\n", irq);
diff --git a/hw/core/dma.c b/hw/core/dma.c
index 93695ff..5a7d874 100644
--- a/hw/core/dma.c
+++ b/hw/core/dma.c
@@ -449,9 +449,9 @@
/* request the emulator to transfer a new DMA memory block ASAP */
void DMA_schedule(int nchan)
{
- CPUOldState *env = cpu_single_env;
- if (env)
- cpu_exit(env);
+ CPUState *cpu = current_cpu;
+ if (cpu)
+ cpu_exit(cpu);
}
static void dma_reset(void *opaque)
diff --git a/hw/i386/pc.c b/hw/i386/pc.c
index c7b2474..a58aed2 100644
--- a/hw/i386/pc.c
+++ b/hw/i386/pc.c
@@ -158,9 +158,9 @@
}
} else {
if (level)
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(cpu, CPU_INTERRUPT_HARD);
else
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD);
}
}
@@ -764,7 +764,7 @@
static void main_cpu_reset(void *opaque)
{
CPUOldState *env = opaque;
- cpu_reset(env);
+ cpu_reset(ENV_GET_CPU(env));
}
static const int ide_iobase[2] = { 0x1f0, 0x170 };
diff --git a/hw/intc/apic.c b/hw/intc/apic.c
index 5398966..2b81648 100644
--- a/hw/intc/apic.c
+++ b/hw/intc/apic.c
@@ -138,6 +138,7 @@
static void apic_local_deliver(CPUOldState *env, int vector)
{
+ CPUState *cpu = ENV_GET_CPU(env);
APICState *s = env->apic_state;
uint32_t lvt = s->lvt[vector];
int trigger_mode;
@@ -147,15 +148,15 @@
switch ((lvt >> 8) & 7) {
case APIC_DM_SMI:
- cpu_interrupt(env, CPU_INTERRUPT_SMI);
+ cpu_interrupt(cpu, CPU_INTERRUPT_SMI);
break;
case APIC_DM_NMI:
- cpu_interrupt(env, CPU_INTERRUPT_NMI);
+ cpu_interrupt(cpu, CPU_INTERRUPT_NMI);
break;
case APIC_DM_EXTINT:
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(cpu, CPU_INTERRUPT_HARD);
break;
case APIC_DM_FIXED:
@@ -182,7 +183,7 @@
reset_bit(s->irr, lvt & 0xff);
/* fall through */
case APIC_DM_EXTINT:
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(ENV_GET_CPU(env), CPU_INTERRUPT_HARD);
break;
}
}
@@ -239,18 +240,18 @@
case APIC_DM_SMI:
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_SMI) );
+ cpu_interrupt(ENV_GET_CPU(apic_iter->cpu_env), CPU_INTERRUPT_SMI) );
return;
case APIC_DM_NMI:
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_NMI) );
+ cpu_interrupt(ENV_GET_CPU(apic_iter->cpu_env), CPU_INTERRUPT_NMI) );
return;
case APIC_DM_INIT:
/* normal INIT IPI sent to processors */
foreach_apic(apic_iter, deliver_bitmask,
- cpu_interrupt(apic_iter->cpu_env, CPU_INTERRUPT_INIT) );
+ cpu_interrupt(ENV_GET_CPU(apic_iter->cpu_env), CPU_INTERRUPT_INIT) );
return;
case APIC_DM_EXTINT:
@@ -365,7 +366,7 @@
ppr = apic_get_ppr(s);
if (ppr && (irrv & 0xf0) <= (ppr & 0xf0))
return;
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(ENV_GET_CPU(s->cpu_env), CPU_INTERRUPT_HARD);
}
void apic_reset_irq_delivered(void)
@@ -487,14 +488,15 @@
static void apic_startup(APICState *s, int vector_num)
{
s->sipi_vector = vector_num;
- cpu_interrupt(s->cpu_env, CPU_INTERRUPT_SIPI);
+ cpu_interrupt(ENV_GET_CPU(s->cpu_env), CPU_INTERRUPT_SIPI);
}
void apic_sipi(CPUOldState *env)
{
+ CPUState *cpu = ENV_GET_CPU(env);
APICState *s = env->apic_state;
- cpu_reset_interrupt(env, CPU_INTERRUPT_SIPI);
+ cpu_reset_interrupt(cpu, CPU_INTERRUPT_SIPI);
if (!s->wait_for_sipi)
return;
@@ -502,7 +504,7 @@
env->eip = 0;
cpu_x86_load_seg_cache(env, R_CS, s->sipi_vector << 8, s->sipi_vector << 12,
0xffff, 0);
- ENV_GET_CPU(env)->halted = 0;
+ cpu->halted = 0;
s->wait_for_sipi = 0;
}
@@ -908,7 +910,7 @@
s->apicbase = 0xfee00000 |
(bsp ? MSR_IA32_APICBASE_BSP : 0) | MSR_IA32_APICBASE_ENABLE;
- cpu_reset(s->cpu_env);
+ cpu_reset(ENV_GET_CPU(s->cpu_env));
apic_init_reset(s->cpu_env);
if (bsp) {
diff --git a/hw/mips/mips_int.c b/hw/mips/mips_int.c
index 6a09c17..6fc3d05 100644
--- a/hw/mips/mips_int.c
+++ b/hw/mips/mips_int.c
@@ -6,16 +6,18 @@
IRQ may change */
void cpu_mips_update_irq(CPUOldState *env)
{
+ CPUState *cpu = ENV_GET_CPU(env);
+
if ((env->CP0_Status & (1 << CP0St_IE)) &&
!(env->CP0_Status & (1 << CP0St_EXL)) &&
!(env->CP0_Status & (1 << CP0St_ERL)) &&
!(env->hflags & MIPS_HFLAG_DM)) {
if ((env->CP0_Status & env->CP0_Cause & CP0Ca_IP_mask) &&
- !(ENV_GET_CPU(env)->interrupt_request & CPU_INTERRUPT_HARD)) {
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ !(cpu->interrupt_request & CPU_INTERRUPT_HARD)) {
+ cpu_interrupt(cpu, CPU_INTERRUPT_HARD);
}
} else
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(cpu, CPU_INTERRUPT_HARD);
}
static void cpu_mips_irq_request(void *opaque, int irq, int level)
diff --git a/hw/mips/mips_pic.c b/hw/mips/mips_pic.c
index 7f6abab..bb54037 100644
--- a/hw/mips/mips_pic.c
+++ b/hw/mips/mips_pic.c
@@ -26,10 +26,10 @@
causebit = 0x00000100 << irq;
if (level) {
env->CP0_Cause |= causebit;
- cpu_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_interrupt(ENV_GET_CPU(env), CPU_INTERRUPT_HARD);
} else {
env->CP0_Cause &= ~causebit;
- cpu_reset_interrupt(env, CPU_INTERRUPT_HARD);
+ cpu_reset_interrupt(ENV_GET_CPU(env), CPU_INTERRUPT_HARD);
}
}
diff --git a/include/exec/cpu-all.h b/include/exec/cpu-all.h
index d79680c..8a9b71c 100644
--- a/include/exec/cpu-all.h
+++ b/include/exec/cpu-all.h
@@ -361,16 +361,6 @@
int page_check_range(target_ulong start, target_ulong len, int flags);
#endif
-CPUArchState *cpu_copy(CPUArchState *env);
-CPUArchState *qemu_get_cpu(int cpu);
-
-#define CPU_DUMP_CODE 0x00010000
-
-void cpu_dump_state(CPUArchState *env, FILE *f, fprintf_function cpu_fprintf,
- int flags);
-void cpu_dump_statistics(CPUArchState *env, FILE *f, fprintf_function cpu_fprintf,
- int flags);
-
void QEMU_NORETURN cpu_abort(CPUArchState *env, const char *fmt, ...)
GCC_FMT_ATTR(2, 3);
@@ -424,13 +414,6 @@
| CPU_INTERRUPT_TGT_EXT_3 \
| CPU_INTERRUPT_TGT_EXT_4)
-void cpu_interrupt(CPUOldState *s, int mask);
-void cpu_reset_interrupt(CPUOldState *env, int mask);
-
-void cpu_exit(CPUOldState *s);
-
-bool qemu_cpu_has_work(CPUOldState *env);
-
/* Breakpoint/watchpoint flags */
#define BP_MEM_READ 0x01
#define BP_MEM_WRITE 0x02
@@ -457,9 +440,6 @@
#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
void cpu_single_step(CPUState *cpu, int enabled);
-void cpu_reset(CPUOldState *s);
-int cpu_is_stopped(CPUOldState *env);
-void run_on_cpu(CPUOldState *env, void (*func)(void *data), void *data);
/* IO ports API */
#include "exec/ioport.h"
diff --git a/include/qemu-common.h b/include/qemu-common.h
index a033ee4..0a7fd4c 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -319,10 +319,6 @@
/* Force QEMU to process pending events */
void qemu_notify_event(void);
-/* Unblock cpu */
-void qemu_cpu_kick(void *env);
-int qemu_cpu_self(void *env);
-
/* work queue */
struct qemu_work_item {
struct qemu_work_item *next;
@@ -331,12 +327,6 @@
int done;
};
-#ifdef CONFIG_USER_ONLY
-#define qemu_init_vcpu(env) do { } while (0)
-#else
-void qemu_init_vcpu(void *env);
-#endif
-
typedef struct QEMUIOVector {
struct iovec *iov;
int niov;
diff --git a/include/qemu/log.h b/include/qemu/log.h
index 9072588..fe47eca 100644
--- a/include/qemu/log.h
+++ b/include/qemu/log.h
@@ -81,7 +81,7 @@
*
* Logs the output of cpu_dump_state().
*/
-static inline void log_cpu_state(CPUOldState *cpu, int flags)
+static inline void log_cpu_state(CPUState *cpu, int flags)
{
if (qemu_log_enabled()) {
cpu_dump_state(cpu, qemu_logfile, fprintf, flags);
@@ -95,7 +95,7 @@
*
* Logs the output of cpu_dump_state() if loglevel includes @mask.
*/
-static inline void log_cpu_state_mask(int mask, CPUOldState *cpu, int flags)
+static inline void log_cpu_state_mask(int mask, CPUState *cpu, int flags)
{
if (qemu_loglevel & mask) {
log_cpu_state(cpu, flags);
diff --git a/include/qom/cpu.h b/include/qom/cpu.h
index af747cf..dcab7d4 100644
--- a/include/qom/cpu.h
+++ b/include/qom/cpu.h
@@ -1,3 +1,22 @@
+/*
+ * QEMU CPU model
+ *
+ * Copyright (c) 2012 SUSE LINUX Products GmbH
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, see
+ * <http://www.gnu.org/licenses/gpl-2.0.html>
+ */
#ifndef QEMU_CPU_H
#define QEMU_CPU_H
@@ -9,7 +28,6 @@
#include "qemu/tls.h"
#include "qemu/typedefs.h"
-
typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaque);
/**
@@ -35,10 +53,9 @@
// TODO(digit): Make this a proper QOM object that inherits from
// DeviceState/DeviceClass.
struct CPUState {
- int nr_cores; /* number of cores within this CPU package */
- int nr_threads;/* number of threads within this CPU */
- int numa_node; /* NUMA node this cpu is belonging to */
-
+ int nr_cores;
+ int nr_threads;
+ int numa_node;
struct QemuThread *thread;
@@ -90,4 +107,160 @@
// TODO(digit): Remove this.
#define cpu_single_env ((CPUArchState*)current_cpu->env_ptr)
+/**
+ * CPUDumpFlags:
+ * @CPU_DUMP_CODE:
+ * @CPU_DUMP_FPU: dump FPU register state, not just integer
+ * @CPU_DUMP_CCOP: dump info about TCG QEMU's condition code optimization state
+ */
+enum CPUDumpFlags {
+ CPU_DUMP_CODE = 0x00010000,
+ CPU_DUMP_FPU = 0x00020000,
+ CPU_DUMP_CCOP = 0x00040000,
+};
+
+/**
+ * cpu_dump_state:
+ * @cpu: The CPU whose state is to be dumped.
+ * @f: File to dump to.
+ * @cpu_fprintf: Function to dump with.
+ * @flags: Flags what to dump.
+ *
+ * Dumps CPU state.
+ */
+void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
+ int flags);
+
+/**
+ * cpu_dump_statistics:
+ * @cpu: The CPU whose state is to be dumped.
+ * @f: File to dump to.
+ * @cpu_fprintf: Function to dump with.
+ * @flags: Flags what to dump.
+ *
+ * Dumps CPU statistics.
+ */
+void cpu_dump_statistics(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
+ int flags);
+
+/**
+ * cpu_reset:
+ * @cpu: The CPU whose state is to be reset.
+ */
+void cpu_reset(CPUState *cpu);
+
+/**
+ * qemu_cpu_has_work:
+ * @cpu: The vCPU to check.
+ *
+ * Checks whether the CPU has work to do.
+ *
+ * Returns: %true if the CPU has work, %false otherwise.
+ */
+bool qemu_cpu_has_work(CPUState *cpu);
+
+/**
+ * qemu_cpu_is_self:
+ * @cpu: The vCPU to check against.
+ *
+ * Checks whether the caller is executing on the vCPU thread.
+ *
+ * Returns: %true if called from @cpu's thread, %false otherwise.
+ */
+bool qemu_cpu_is_self(CPUState *cpu);
+
+/**
+ * qemu_cpu_kick:
+ * @cpu: The vCPU to kick.
+ *
+ * Kicks @cpu's thread.
+ */
+void qemu_cpu_kick(CPUState *cpu);
+
+/**
+ * cpu_is_stopped:
+ * @cpu: The CPU to check.
+ *
+ * Checks whether the CPU is stopped.
+ *
+ * Returns: %true if run state is not running or if artificially stopped;
+ * %false otherwise.
+ */
+bool cpu_is_stopped(CPUState *cpu);
+
+/**
+ * run_on_cpu:
+ * @cpu: The vCPU to run on.
+ * @func: The function to be executed.
+ * @data: Data to pass to the function.
+ *
+ * Schedules the function @func for execution on the vCPU @cpu.
+ */
+void run_on_cpu(CPUState *cpu, void (*func)(void *data), void *data);
+
+/**
+ * qemu_get_cpu:
+ * @index: The CPUState@cpu_index value of the CPU to obtain.
+ *
+ * Gets a CPU matching @index.
+ *
+ * Returns: The CPU or %NULL if there is no matching CPU.
+ */
+CPUState *qemu_get_cpu(int index);
+
+/**
+ * cpu_interrupt:
+ * @cpu: The CPU to set an interrupt on.
+ * @mask: The interupts to set.
+ *
+ * Invokes the interrupt handler.
+ */
+void cpu_interrupt(CPUState *cpu, int mask);
+
+/**
+ * cpu_reset_interrupt:
+ * @cpu: The CPU to clear the interrupt on.
+ * @mask: The interrupt mask to clear.
+ *
+ * Resets interrupts on the vCPU @cpu.
+ */
+void cpu_reset_interrupt(CPUState *cpu, int mask);
+
+/**
+ * cpu_exit:
+ * @cpu: The CPU to exit.
+ *
+ * Requests the CPU @cpu to exit execution.
+ */
+void cpu_exit(CPUState *cpu);
+
+/**
+ * cpu_resume:
+ * @cpu: The CPU to resume.
+ *
+ * Resumes CPU, i.e. puts CPU into runnable state.
+ */
+void cpu_resume(CPUState *cpu);
+
+/**
+ * qemu_init_vcpu:
+ * @cpu: The vCPU to initialize.
+ *
+ * Initializes a vCPU.
+ */
+void qemu_init_vcpu(CPUState *cpu);
+
+#define SSTEP_ENABLE 0x1 /* Enable simulated HW single stepping */
+#define SSTEP_NOIRQ 0x2 /* Do not use IRQ while single stepping */
+#define SSTEP_NOTIMER 0x4 /* Do not Timers while single stepping */
+
+/**
+ * cpu_single_step:
+ * @cpu: CPU to the flags for.
+ * @enabled: Flags to enable.
+ *
+ * Enables or disables single-stepping for @cpu.
+ */
+void cpu_single_step(CPUState *cpu, int enabled);
+
#endif // QEMU_CPU_H
diff --git a/include/qom/object.h b/include/qom/object.h
index e420e10..a275db2 100644
--- a/include/qom/object.h
+++ b/include/qom/object.h
@@ -985,12 +985,12 @@
* ambiguous match
*
* There are two types of supported paths--absolute paths and partial paths.
- *
+ *
* Absolute paths are derived from the root object and can follow child<> or
* link<> properties. Since they can follow link<> properties, they can be
* arbitrarily long. Absolute paths look like absolute filenames and are
* prefixed with a leading slash.
- *
+ *
* Partial paths look like relative filenames. They do not begin with a
* prefix. The matching rules for partial paths are subtle but designed to make
* specifying objects easy. At each level of the composition tree, the partial
diff --git a/target-arm/arm-semi.c b/target-arm/arm-semi.c
index f3726e3..7c12598 100644
--- a/target-arm/arm-semi.c
+++ b/target-arm/arm-semi.c
@@ -549,7 +549,7 @@
exit(0);
default:
fprintf(stderr, "qemu: Unsupported SemiHosting SWI 0x%02x\n", nr);
- cpu_dump_state(env, stderr, fprintf, 0);
+ cpu_dump_state(ENV_GET_CPU(env), stderr, fprintf, 0);
abort();
}
}
diff --git a/target-arm/helper.c b/target-arm/helper.c
index d339ea9..3877055 100644
--- a/target-arm/helper.c
+++ b/target-arm/helper.c
@@ -293,13 +293,14 @@
}
}
-void cpu_reset(CPUARMState *env)
+void cpu_reset(CPUState *cpu)
{
+ CPUARMState *env = cpu->env_ptr;
uint32_t id;
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
- qemu_log("CPU Reset (CPU %d)\n", ENV_GET_CPU(env)->cpu_index);
- log_cpu_state(env, 0);
+ qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
+ log_cpu_state(cpu, 0);
}
id = env->cp15.c0_cpuid;
@@ -425,15 +426,16 @@
env = &arm_cpu->env;
ENV_GET_CPU(env)->env_ptr = env;
+ CPUState *cpu = ENV_GET_CPU(env);
cpu_exec_init(env);
if (!inited) {
inited = 1;
arm_translate_init();
}
- ENV_GET_CPU(env)->cpu_model_str = cpu_model;
+ cpu->cpu_model_str = cpu_model;
env->cp15.c0_cpuid = id;
- cpu_reset(env);
+ cpu_reset(cpu);
if (arm_feature(env, ARM_FEATURE_NEON)) {
gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
51, "arm-neon.xml", 0);
@@ -444,7 +446,7 @@
gdb_register_coprocessor(env, vfp_gdb_get_reg, vfp_gdb_set_reg,
19, "arm-vfp.xml", 0);
}
- qemu_init_vcpu(env);
+ qemu_init_vcpu(cpu);
return env;
}
@@ -1867,7 +1869,7 @@
env->cp15.c15_threadid = val & 0xffff;
break;
case 8: /* Wait-for-interrupt (deprecated). */
- cpu_interrupt(env, CPU_INTERRUPT_HALT);
+ cpu_interrupt(ENV_GET_CPU(env), CPU_INTERRUPT_HALT);
break;
default:
goto bad_reg;
diff --git a/target-arm/translate.c b/target-arm/translate.c
index 24c881d..609fc69 100644
--- a/target-arm/translate.c
+++ b/target-arm/translate.c
@@ -9989,9 +9989,10 @@
"???", "???", "???", "und", "???", "???", "???", "sys"
};
-void cpu_dump_state(CPUARMState *env, FILE *f, fprintf_function cpu_fprintf,
+void cpu_dump_state(CPUState *cpu, FILE *f, fprintf_function cpu_fprintf,
int flags)
{
+ CPUARMState *env = cpu->env_ptr;
int i;
#if 0
union {
diff --git a/target-i386/helper.c b/target-i386/helper.c
index 70a440a..ff236ce 100644
--- a/target-i386/helper.c
+++ b/target-i386/helper.c
@@ -462,13 +462,14 @@
}
/* NOTE: must be called outside the CPU execute loop */
-void cpu_reset(CPUX86State *env)
+void cpu_reset(CPUState *cpu)
{
+ CPUX86State *env = cpu->env_ptr;
int i;
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
- qemu_log("CPU Reset (CPU %d)\n", ENV_GET_CPU(env)->cpu_index);
- log_cpu_state(env, X86_DUMP_FPU | X86_DUMP_CCOP);
+ qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
+ log_cpu_state(cpu, X86_DUMP_FPU | X86_DUMP_CCOP);
}
memset(env, 0, offsetof(CPUX86State, breakpoints));
@@ -651,10 +652,11 @@
cpu_fprintf(f, "\n");
}
-void cpu_dump_state(CPUX86State *env, FILE *f,
+void cpu_dump_state(CPUState *cpu, FILE *f,
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
int flags)
{
+ CPUX86State *env = cpu->env_ptr;
int eflags, i, nb;
char cc_op_name[32];
static const char *seg_name[6] = { "ES", "CS", "SS", "DS", "FS", "GS" };
@@ -704,7 +706,7 @@
(env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
(int)(env->a20_mask >> 20) & 1,
(env->hflags >> HF_SMM_SHIFT) & 1,
- ENV_GET_CPU(env)->halted);
+ cpu->halted);
} else
#endif
{
@@ -731,7 +733,7 @@
(env->hflags >> HF_INHIBIT_IRQ_SHIFT) & 1,
(int)(env->a20_mask >> 20) & 1,
(env->hflags >> HF_SMM_SHIFT) & 1,
- ENV_GET_CPU(env)->halted);
+ cpu->halted);
}
for(i = 0; i < 6; i++) {
@@ -842,7 +844,7 @@
#endif
/* if the cpu is currently executing code, we must unlink it and
all the potentially executing TB */
- cpu_interrupt(env, CPU_INTERRUPT_EXITTB);
+ cpu_interrupt(ENV_GET_CPU(env), CPU_INTERRUPT_EXITTB);
/* when a20 is changed, all the MMU mappings are invalid, so
we must flush everything */
@@ -1479,7 +1481,7 @@
banks[3] = misc;
cenv->mcg_status = mcg_status;
banks[1] = status;
- cpu_interrupt(cenv, CPU_INTERRUPT_MCE);
+ cpu_interrupt(ENV_GET_CPU(cenv), CPU_INTERRUPT_MCE);
} else if (!(banks[1] & MCI_STATUS_VAL)
|| !(banks[1] & MCI_STATUS_UC)) {
if (banks[1] & MCI_STATUS_VAL)
@@ -1751,9 +1753,11 @@
x86_cpu = g_malloc0(sizeof(X86CPU));
env = &x86_cpu->env;
ENV_GET_CPU(env)->env_ptr = env;
+ CPUState *cpu = ENV_GET_CPU(env);
cpu_exec_init(env);
- ENV_GET_CPU(env)->cpu_model_str = cpu_model;
+ cpu->cpu_model_str = cpu_model;
+
/* init various static tables */
if (!inited) {
@@ -1768,9 +1772,9 @@
return NULL;
}
mce_init(env);
- cpu_reset(env);
+ cpu_reset(cpu);
- qemu_init_vcpu(env);
+ qemu_init_vcpu(cpu);
if (kvm_enabled()) {
kvm_trim_features(&env->cpuid_features,
@@ -1795,7 +1799,7 @@
{
CPUState *cpu = ENV_GET_CPU(env);
int sipi = cpu->interrupt_request & CPU_INTERRUPT_SIPI;
- cpu_reset(env);
+ cpu_reset(cpu);
cpu->interrupt_request = sipi;
apic_init_reset(env);
}
diff --git a/target-i386/op_helper.c b/target-i386/op_helper.c
index 6c1d277..66b90b7 100644
--- a/target-i386/op_helper.c
+++ b/target-i386/op_helper.c
@@ -1343,7 +1343,7 @@
qemu_log(" EAX=" TARGET_FMT_lx, EAX);
}
qemu_log("\n");
- log_cpu_state(env, X86_DUMP_CCOP);
+ log_cpu_state(ENV_GET_CPU(env), X86_DUMP_CCOP);
#if 0
{
int i;
@@ -1529,7 +1529,7 @@
int i, offset;
qemu_log_mask(CPU_LOG_INT, "SMM: enter\n");
- log_cpu_state_mask(CPU_LOG_INT, env, X86_DUMP_CCOP);
+ log_cpu_state_mask(CPU_LOG_INT, ENV_GET_CPU(env), X86_DUMP_CCOP);
env->hflags |= HF_SMM_MASK;
cpu_smm_update(env);
@@ -1770,7 +1770,7 @@
cpu_smm_update(env);
qemu_log_mask(CPU_LOG_INT, "SMM: after RSM\n");
- log_cpu_state_mask(CPU_LOG_INT, env, X86_DUMP_CCOP);
+ log_cpu_state_mask(CPU_LOG_INT, ENV_GET_CPU(env), X86_DUMP_CCOP);
}
#endif /* !CONFIG_USER_ONLY */
diff --git a/target-i386/translate.c b/target-i386/translate.c
index a9cf004..3f8e040 100644
--- a/target-i386/translate.c
+++ b/target-i386/translate.c
@@ -7941,7 +7941,7 @@
}
#ifdef DEBUG_DISAS
- log_cpu_state_mask(CPU_LOG_TB_CPU, env, X86_DUMP_CCOP);
+ log_cpu_state_mask(CPU_LOG_TB_CPU, ENV_GET_CPU(env), X86_DUMP_CCOP);
if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)) {
int disas_flags;
qemu_log("----------------\n");
diff --git a/target-mips/helper.c b/target-mips/helper.c
index 433ad39..b9ad090 100644
--- a/target-mips/helper.c
+++ b/target-mips/helper.c
@@ -645,7 +645,7 @@
env->active_tc.PC = (int32_t)0xBFC00480;
break;
case EXCP_RESET:
- cpu_reset(env);
+ cpu_reset(ENV_GET_CPU(env));
break;
case EXCP_SRESET:
env->CP0_Status |= (1 << CP0St_SR);
diff --git a/target-mips/op_helper.c b/target-mips/op_helper.c
index 6429d97..3ff3cc2 100644
--- a/target-mips/op_helper.c
+++ b/target-mips/op_helper.c
@@ -662,7 +662,6 @@
walking the list of CPUMIPSStates. */
static CPUMIPSState *mips_cpu_map_tc(CPUMIPSState *env, int *tc)
{
- CPUMIPSState *other;
int vpe_idx, nr_threads = ENV_GET_CPU(env)->nr_threads;
int tc_idx = *tc;
@@ -674,8 +673,8 @@
vpe_idx = tc_idx / nr_threads;
*tc = tc_idx % nr_threads;
- other = qemu_get_cpu(vpe_idx);
- return other ? other : env;
+ CPUState *other = qemu_get_cpu(vpe_idx);
+ return other ? other->env_ptr : env;
}
/* The per VPE CP0_Status register shares some fields with the per TC
diff --git a/target-mips/translate.c b/target-mips/translate.c
index 3952979..08c1ca4 100755
--- a/target-mips/translate.c
+++ b/target-mips/translate.c
@@ -8317,7 +8317,7 @@
#ifdef DEBUG_DISAS
qemu_log_mask(CPU_LOG_TB_CPU, "------------------------------------------------\n");
/* FIXME: This may print out stale hflags from env... */
- log_cpu_state_mask(CPU_LOG_TB_CPU, env, 0);
+ log_cpu_state_mask(CPU_LOG_TB_CPU, ENV_GET_CPU(env), 0);
#endif
LOG_DISAS("\ntb %p idx %d hflags %04x\n", tb, ctx.mem_idx, ctx.hflags);
gen_icount_start();
@@ -8503,10 +8503,11 @@
}
#endif
-void cpu_dump_state (CPUMIPSState *env, FILE *f,
+void cpu_dump_state (CPUState *cpu, FILE *f,
int (*cpu_fprintf)(FILE *f, const char *fmt, ...),
int flags)
{
+ CPUMIPSState *env = cpu->env_ptr;
int i;
cpu_fprintf(f, "pc=0x" TARGET_FMT_lx " HI=0x" TARGET_FMT_lx " LO=0x" TARGET_FMT_lx " ds %04x " TARGET_FMT_lx " %d\n",
@@ -8604,16 +8605,18 @@
#endif
mvp_init(env, def);
mips_tcg_init();
- cpu_reset(env);
- qemu_init_vcpu(env);
+ cpu_reset(cpu);
+ qemu_init_vcpu(cpu);
return env;
}
-void cpu_reset (CPUMIPSState *env)
+void cpu_reset(CPUState *cpu)
{
+ CPUMIPSState *env = cpu->env_ptr;
+
if (qemu_loglevel_mask(CPU_LOG_RESET)) {
- qemu_log("CPU Reset (CPU %d)\n", ENV_GET_CPU(env)->cpu_index);
- log_cpu_state(env, 0);
+ qemu_log("CPU Reset (CPU %d)\n", cpu->cpu_index);
+ log_cpu_state(cpu, 0);
}
memset(env, 0, offsetof(CPUMIPSState, breakpoints));
diff --git a/translate-all.c b/translate-all.c
index 55a511a..b655ef1 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -1176,7 +1176,7 @@
if (env) {
env->current_tb = saved_tb;
if (cpu->interrupt_request && env->current_tb) {
- cpu_interrupt(env, cpu->interrupt_request);
+ cpu_interrupt(cpu, cpu->interrupt_request);
}
}
}
@@ -1474,9 +1474,9 @@
#ifndef CONFIG_USER_ONLY
/* mask must never be zero, except for A20 change call */
-void cpu_interrupt(CPUArchState *env, int mask)
+void cpu_interrupt(CPUState *cpu, int mask)
{
- CPUState *cpu = ENV_GET_CPU(env);
+ CPUArchState *env = cpu->env_ptr;
int old_mask;
old_mask = cpu->interrupt_request;
@@ -1486,7 +1486,7 @@
* If called from iothread context, wake the target cpu in
* case its halted.
*/
- if (!qemu_cpu_self(cpu)) {
+ if (!qemu_cpu_is_self(cpu)) {
qemu_cpu_kick(cpu);
return;
}