@@ -23,6 +23,7 @@
#include <signal.h>
#include "hw/qdev-core.h"
#include "qemu/thread.h"
+#include "qemu/typedefs.h"
typedef int (*WriteCoreDumpFunction)(void *buf, size_t size, void *opaque);
@@ -49,6 +50,7 @@ typedef struct CPUState CPUState;
* @do_interrupt: Callback for interrupt handling.
* @get_arch_id: Callback for getting architecture-dependent CPU ID.
* @get_paging_enabled: Callback for inquiring whether paging is enabled.
+ * @get_memory_mapping: Callback for obtaining the memory mappings.
* @vmsd: State description for migration.
*
* Represents a CPU family or model.
@@ -64,6 +66,7 @@ typedef struct CPUClass {
void (*do_interrupt)(CPUState *cpu);
int64_t (*get_arch_id)(CPUState *cpu);
bool (*get_paging_enabled)(CPUState *cpu);
+ int (*get_memory_mapping)(CPUState *cpu, MemoryMappingList *list);
const struct VMStateDescription *vmsd;
int (*write_elf64_note)(WriteCoreDumpFunction f, CPUState *cpu,
@@ -148,6 +151,14 @@ struct CPUState {
bool cpu_paging_enabled(CPUState *cpu);
/**
+ * @cpu: The CPU whose memory mappings are to be obtained.
+ * @list: Where to write the memory mappings to.
+ *
+ * Returns: 0 if successful.
+ */
+int cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list);
+
+/**
* cpu_write_elf64_note:
* @f: pointer to a function that writes memory to a file
* @cpu: The CPU whose memory is to be dumped
@@ -31,8 +31,6 @@ struct MemoryMappingList {
QTAILQ_HEAD(, MemoryMapping) head;
};
-int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env);
-
/*
* add or merge the memory region [phys_addr, phys_addr + length) into the
* memory mapping's list. The region's virtual address starts with virt_addr,
@@ -19,9 +19,3 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
{
return -2;
}
-
-int cpu_get_memory_mapping(MemoryMappingList *list,
- CPUArchState *env)
-{
- return -1;
-}
@@ -188,7 +188,7 @@ int qemu_get_guest_memory_mapping(MemoryMappingList *list)
first_paging_enabled_cpu = find_paging_enabled_cpu(first_cpu);
if (first_paging_enabled_cpu) {
for (env = first_paging_enabled_cpu; env != NULL; env = env->next_cpu) {
- ret = cpu_get_memory_mapping(list, env);
+ ret = cpu_get_memory_mapping(ENV_GET_CPU(env), list);
if (ret < 0) {
return -1;
}
@@ -62,6 +62,19 @@ static bool cpu_common_get_paging_enabled(CPUState *cpu)
return true;
}
+int cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list)
+{
+ CPUClass *cc = CPU_GET_CLASS(cpu);
+
+ return cc->get_memory_mapping(cpu, list);
+}
+
+static int cpu_common_get_memory_mapping(CPUState *cpu,
+ MemoryMappingList *list)
+{
+ return -1;
+}
+
/* CPU hot-plug notifiers */
static NotifierList cpu_added_notifiers =
NOTIFIER_LIST_INITIALIZER(cpu_add_notifiers);
@@ -189,6 +202,7 @@ static void cpu_class_init(ObjectClass *klass, void *data)
k->reset = cpu_common_reset;
k->get_arch_id = cpu_common_get_arch_id;
k->get_paging_enabled = cpu_common_get_paging_enabled;
+ k->get_memory_mapping = cpu_common_get_memory_mapping;
k->write_elf32_qemunote = cpu_common_write_elf32_qemunote;
k->write_elf32_note = cpu_common_write_elf32_note;
k->write_elf64_qemunote = cpu_common_write_elf64_qemunote;
@@ -237,9 +237,12 @@ static void walk_pml4e(MemoryMappingList *list,
}
#endif
-int cpu_get_memory_mapping(MemoryMappingList *list, CPUArchState *env)
+int x86_cpu_get_memory_mapping(CPUState *cs, MemoryMappingList *list)
{
- if (!cpu_paging_enabled(ENV_GET_CPU(env))) {
+ X86CPU *cpu = X86_CPU(cs);
+ CPUX86State *env = &cpu->env;
+
+ if (!cpu_paging_enabled(cs)) {
/* paging is disabled */
return 0;
}
@@ -98,4 +98,6 @@ int x86_cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
int x86_cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
void *opaque);
+int x86_cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list);
+
#endif
@@ -2529,6 +2529,7 @@ static void x86_cpu_common_class_init(ObjectClass *oc, void *data)
cc->get_arch_id = x86_cpu_get_arch_id;
cc->get_paging_enabled = x86_cpu_get_paging_enabled;
#ifndef CONFIG_USER_ONLY
+ cc->get_memory_mapping = x86_cpu_get_memory_mapping;
cc->write_elf64_note = x86_cpu_write_elf64_note;
cc->write_elf64_qemunote = x86_cpu_write_elf64_qemunote;
cc->write_elf32_note = x86_cpu_write_elf32_note;
Signed-off-by: Andreas Färber <afaerber@suse.de> --- include/qom/cpu.h | 11 +++++++++++ include/sysemu/memory_mapping.h | 2 -- memory_mapping-stub.c | 6 ------ memory_mapping.c | 2 +- qom/cpu.c | 14 ++++++++++++++ target-i386/arch_memory_mapping.c | 7 +++++-- target-i386/cpu-qom.h | 2 ++ target-i386/cpu.c | 1 + 8 files changed, 34 insertions(+), 11 deletions(-)