1 /* 2 * QEMU CPU model (system emulation 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 "hw/core/cpu.h" 24 25 bool cpu_paging_enabled(const CPUState *cpu) 26 { 27 CPUClass *cc = CPU_GET_CLASS(cpu); 28 29 if (cc->get_paging_enabled) { 30 return cc->get_paging_enabled(cpu); 31 } 32 33 return false; 34 } 35 36 void cpu_get_memory_mapping(CPUState *cpu, MemoryMappingList *list, 37 Error **errp) 38 { 39 CPUClass *cc = CPU_GET_CLASS(cpu); 40 41 if (cc->get_memory_mapping) { 42 cc->get_memory_mapping(cpu, list, errp); 43 return; 44 } 45 46 error_setg(errp, "Obtaining memory mappings is unsupported on this CPU."); 47 } 48 49 hwaddr cpu_get_phys_page_attrs_debug(CPUState *cpu, vaddr addr, 50 MemTxAttrs *attrs) 51 { 52 CPUClass *cc = CPU_GET_CLASS(cpu); 53 54 if (cc->get_phys_page_attrs_debug) { 55 return cc->get_phys_page_attrs_debug(cpu, addr, attrs); 56 } 57 /* Fallback for CPUs which don't implement the _attrs_ hook */ 58 *attrs = MEMTXATTRS_UNSPECIFIED; 59 return cc->get_phys_page_debug(cpu, addr); 60 } 61 62 hwaddr cpu_get_phys_page_debug(CPUState *cpu, vaddr addr) 63 { 64 MemTxAttrs attrs = {}; 65 66 return cpu_get_phys_page_attrs_debug(cpu, addr, &attrs); 67 } 68 69 int cpu_asidx_from_attrs(CPUState *cpu, MemTxAttrs attrs) 70 { 71 CPUClass *cc = CPU_GET_CLASS(cpu); 72 int ret = 0; 73 74 if (cc->asidx_from_attrs) { 75 ret = cc->asidx_from_attrs(cpu, attrs); 76 assert(ret < cpu->num_ases && ret >= 0); 77 } 78 return ret; 79 } 80 81 int cpu_write_elf32_qemunote(WriteCoreDumpFunction f, CPUState *cpu, 82 void *opaque) 83 { 84 CPUClass *cc = CPU_GET_CLASS(cpu); 85 86 if (!cc->write_elf32_qemunote) { 87 return 0; 88 } 89 return (*cc->write_elf32_qemunote)(f, cpu, opaque); 90 } 91 92 int cpu_write_elf32_note(WriteCoreDumpFunction f, CPUState *cpu, 93 int cpuid, void *opaque) 94 { 95 CPUClass *cc = CPU_GET_CLASS(cpu); 96 97 if (!cc->write_elf32_note) { 98 return -1; 99 } 100 return (*cc->write_elf32_note)(f, cpu, cpuid, opaque); 101 } 102 103 int cpu_write_elf64_qemunote(WriteCoreDumpFunction f, CPUState *cpu, 104 void *opaque) 105 { 106 CPUClass *cc = CPU_GET_CLASS(cpu); 107 108 if (!cc->write_elf64_qemunote) { 109 return 0; 110 } 111 return (*cc->write_elf64_qemunote)(f, cpu, opaque); 112 } 113 114 int cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cpu, 115 int cpuid, void *opaque) 116 { 117 CPUClass *cc = CPU_GET_CLASS(cpu); 118 119 if (!cc->write_elf64_note) { 120 return -1; 121 } 122 return (*cc->write_elf64_note)(f, cpu, cpuid, opaque); 123 } 124 125 bool cpu_virtio_is_big_endian(CPUState *cpu) 126 { 127 CPUClass *cc = CPU_GET_CLASS(cpu); 128 129 if (cc->virtio_is_big_endian) { 130 return cc->virtio_is_big_endian(cpu); 131 } 132 return target_words_bigendian(); 133 } 134 135 GuestPanicInformation *cpu_get_crash_info(CPUState *cpu) 136 { 137 CPUClass *cc = CPU_GET_CLASS(cpu); 138 GuestPanicInformation *res = NULL; 139 140 if (cc->get_crash_info) { 141 res = cc->get_crash_info(cpu); 142 } 143 return res; 144 } 145