xref: /qemu/hw/core/cpu-system.c (revision eaa910b14773403963316cfe3617eecc9e02356a)
1 /*
2  * QEMU CPU model (system specific)
3  *
4  * Copyright (c) 2012-2014 SUSE LINUX Products GmbH
5  *
6  * This program is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU General Public License
8  * as published by the Free Software Foundation; either version 2
9  * of the License, or (at your option) any later version.
10  *
11  * This program 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
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, see
18  * <http://www.gnu.org/licenses/gpl-2.0.html>
19  */
20 
21 #include "qemu/osdep.h"
22 #include "qapi/error.h"
23 #include "exec/tswap.h"
24 #include "hw/core/sysemu-cpu-ops.h"
25 
26 bool cpu_paging_enabled(const CPUState *cpu)
27 {
28     CPUClass *cc = CPU_GET_CLASS(cpu);
29 
30     if (cc->sysemu_ops->get_paging_enabled) {
31         return cc->sysemu_ops->get_paging_enabled(cpu);
32     }
33 
34     return false;
35 }
36 
37 bool cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list,
38                             Error **errp)
39 {
40     CPUClass *cc = CPU_GET_CLASS(cpu);
41 
42     if (cc->sysemu_ops->get_memory_mapping) {
43         return cc->sysemu_ops->get_memory_mapping(cpu, list, errp);
44     }
45 
46     error_setg(errp, "Obtaining memory mappings is unsupported on this CPU.");
47     return false;
48 }
49 
50 hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr,
51                                      MemTxAttrs *attrs)
52 {
53     CPUClass *cc = CPU_GET_CLASS(cpu);
54     hwaddr paddr;
55 
56     if (cc->sysemu_ops->get_phys_page_attrs_debug) {
57         paddr = cc->sysemu_ops->get_phys_page_attrs_debug(cpu, addr, attrs);
58     } else {
59         /* Fallback for CPUs which don't implement the _attrs_ hook */
60         *attrs = MEMTXATTRS_UNSPECIFIED;
61         paddr = cc->sysemu_ops->get_phys_page_debug(cpu, addr);
62     }
63     /* Indicate that this is a debug access. */
64     attrs->debug = 1;
65     return paddr;
66 }
67 
68 hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr)
69 {
70     MemTxAttrs attrs = {};
71 
72     return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs);
73 }
74 
75 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs)
76 {
77     int ret = 0;
78 
79     if (cpu->cc->sysemu_ops->asidx_from_attrs) {
80         ret = cpu->cc->sysemu_ops->asidx_from_attrs(cpu, attrs);
81         assert(ret < cpu->num_ases && ret >= 0);
82     }
83     return ret;
84 }
85 
86 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
87                              void *opaque)
88 {
89     CPUClass *cc = CPU_GET_CLASS(cpu);
90 
91     if (!cc->sysemu_ops->write_elf32_qemunote) {
92         return 0;
93     }
94     return (*cc->sysemu_ops->write_elf32_qemunote)(f, cpu, opaque);
95 }
96 
97 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu,
98                          int cpuid, void *opaque)
99 {
100     CPUClass *cc = CPU_GET_CLASS(cpu);
101 
102     if (!cc->sysemu_ops->write_elf32_note) {
103         return -1;
104     }
105     return (*cc->sysemu_ops->write_elf32_note)(f, cpu, cpuid, opaque);
106 }
107 
108 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu,
109                              void *opaque)
110 {
111     CPUClass *cc = CPU_GET_CLASS(cpu);
112 
113     if (!cc->sysemu_ops->write_elf64_qemunote) {
114         return 0;
115     }
116     return (*cc->sysemu_ops->write_elf64_qemunote)(f, cpu, opaque);
117 }
118 
119 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu,
120                          int cpuid, void *opaque)
121 {
122     CPUClass *cc = CPU_GET_CLASS(cpu);
123 
124     if (!cc->sysemu_ops->write_elf64_note) {
125         return -1;
126     }
127     return (*cc->sysemu_ops->write_elf64_note)(f, cpu, cpuid, opaque);
128 }
129 
130 bool cpu_virtio_is_big_endian(CPUState *cpu)
131 {
132     CPUClass *cc = CPU_GET_CLASS(cpu);
133 
134     if (cc->sysemu_ops->virtio_is_big_endian) {
135         return cc->sysemu_ops->virtio_is_big_endian(cpu);
136     }
137     return target_words_bigendian();
138 }
139 
140 GuestPanicInformation *cpu_get_crash_info(CPUState *cpu)
141 {
142     CPUClass *cc = CPU_GET_CLASS(cpu);
143     GuestPanicInformation *res = NULL;
144 
145     if (cc->sysemu_ops->get_crash_info) {
146         res = cc->sysemu_ops->get_crash_info(cpu);
147     }
148     return res;
149 }
150