1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20#include "qemu/osdep.h"
21#include "cpu.h"
22#include "tcg/helper-tcg.h"
23
24#include "sysemu/sysemu.h"
25#include "qemu/units.h"
26#include "exec/address-spaces.h"
27
28#include "tcg/tcg-cpu.h"
29
30static void tcg_cpu_machine_done(Notifier *n, void *unused)
31{
32 X86CPU *cpu = container_of(n, X86CPU, machine_done);
33 MemoryRegion *smram =
34 (MemoryRegion *) object_resolve_path("/machine/smram", NULL);
35
36 if (smram) {
37 cpu->smram = g_new(MemoryRegion, 1);
38 memory_region_init_alias(cpu->smram, OBJECT(cpu), "smram",
39 smram, 0, 4 * GiB);
40 memory_region_set_enabled(cpu->smram, true);
41 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0,
42 cpu->smram, 1);
43 }
44}
45
46bool tcg_cpu_realizefn(CPUState *cs, Error **errp)
47{
48 X86CPU *cpu = X86_CPU(cs);
49
50
51
52
53
54
55
56
57
58
59 cpu->cpu_as_mem = g_new(MemoryRegion, 1);
60 cpu->cpu_as_root = g_new(MemoryRegion, 1);
61
62
63 memory_region_init(cpu->cpu_as_root, OBJECT(cpu), "memory", ~0ull);
64 memory_region_set_enabled(cpu->cpu_as_root, true);
65
66
67
68
69
70 memory_region_init_alias(cpu->cpu_as_mem, OBJECT(cpu), "memory",
71 get_system_memory(), 0, ~0ull);
72 memory_region_add_subregion_overlap(cpu->cpu_as_root, 0, cpu->cpu_as_mem, 0);
73 memory_region_set_enabled(cpu->cpu_as_mem, true);
74
75 cs->num_ases = 2;
76 cpu_address_space_init(cs, 0, "cpu-memory", cs->memory);
77 cpu_address_space_init(cs, 1, "cpu-smm", cpu->cpu_as_root);
78
79
80 cpu->machine_done.notify = tcg_cpu_machine_done;
81 qemu_add_machine_init_done_notifier(&cpu->machine_done);
82 return true;
83}
84