block/iscsi: clarify the meaning of ISCSI_CHECKALLOC_THRES
[qemu/cris-port.git] / target-ppc / arch_dump.c
blob9dccf1ae1f8ffb560fb1b3a2aa48826f1a24f599
1 /*
2 * writing ELF notes for ppc64 arch
5 * Copyright IBM, Corp. 2013
7 * Authors:
8 * Aneesh Kumar K.V <aneesh.kumar@linux.vnet.ibm.com>
10 * This work is licensed under the terms of the GNU GPL, version 2. See
11 * the COPYING file in the top-level directory.
15 #include "cpu.h"
16 #include "elf.h"
17 #include "exec/cpu-all.h"
18 #include "sysemu/dump.h"
19 #include "sysemu/kvm.h"
21 struct PPC64UserRegStruct {
22 uint64_t gpr[32];
23 uint64_t nip;
24 uint64_t msr;
25 uint64_t orig_gpr3;
26 uint64_t ctr;
27 uint64_t link;
28 uint64_t xer;
29 uint64_t ccr;
30 uint64_t softe;
31 uint64_t trap;
32 uint64_t dar;
33 uint64_t dsisr;
34 uint64_t result;
35 } QEMU_PACKED;
37 struct PPC64ElfPrstatus {
38 char pad1[112];
39 struct PPC64UserRegStruct pr_reg;
40 uint64_t pad2[4];
41 } QEMU_PACKED;
44 struct PPC64ElfFpregset {
45 uint64_t fpr[32];
46 uint64_t fpscr;
47 } QEMU_PACKED;
50 struct PPC64ElfVmxregset {
51 ppc_avr_t avr[32];
52 ppc_avr_t vscr;
53 union {
54 ppc_avr_t unused;
55 uint32_t value;
56 } vrsave;
57 } QEMU_PACKED;
59 struct PPC64ElfVsxregset {
60 uint64_t vsr[32];
61 } QEMU_PACKED;
63 struct PPC64ElfSperegset {
64 uint32_t evr[32];
65 uint64_t spe_acc;
66 uint32_t spe_fscr;
67 } QEMU_PACKED;
69 typedef struct noteStruct {
70 Elf64_Nhdr hdr;
71 char name[5];
72 char pad3[3];
73 union {
74 struct PPC64ElfPrstatus prstatus;
75 struct PPC64ElfFpregset fpregset;
76 struct PPC64ElfVmxregset vmxregset;
77 struct PPC64ElfVsxregset vsxregset;
78 struct PPC64ElfSperegset speregset;
79 } contents;
80 } QEMU_PACKED Note;
83 static void ppc64_write_elf64_prstatus(Note *note, PowerPCCPU *cpu)
85 int i;
86 uint64_t cr;
87 struct PPC64ElfPrstatus *prstatus;
88 struct PPC64UserRegStruct *reg;
90 note->hdr.n_type = cpu_to_be32(NT_PRSTATUS);
92 prstatus = &note->contents.prstatus;
93 memset(prstatus, 0, sizeof(*prstatus));
94 reg = &prstatus->pr_reg;
96 for (i = 0; i < 32; i++) {
97 reg->gpr[i] = cpu_to_be64(cpu->env.gpr[i]);
99 reg->nip = cpu_to_be64(cpu->env.nip);
100 reg->msr = cpu_to_be64(cpu->env.msr);
101 reg->ctr = cpu_to_be64(cpu->env.ctr);
102 reg->link = cpu_to_be64(cpu->env.lr);
103 reg->xer = cpu_to_be64(cpu_read_xer(&cpu->env));
105 cr = 0;
106 for (i = 0; i < 8; i++) {
107 cr |= (cpu->env.crf[i] & 15) << (4 * (7 - i));
109 reg->ccr = cpu_to_be64(cr);
112 static void ppc64_write_elf64_fpregset(Note *note, PowerPCCPU *cpu)
114 int i;
115 struct PPC64ElfFpregset *fpregset;
117 note->hdr.n_type = cpu_to_be32(NT_PRFPREG);
119 fpregset = &note->contents.fpregset;
120 memset(fpregset, 0, sizeof(*fpregset));
122 for (i = 0; i < 32; i++) {
123 fpregset->fpr[i] = cpu_to_be64(cpu->env.fpr[i]);
125 fpregset->fpscr = cpu_to_be64(cpu->env.fpscr);
128 static void ppc64_write_elf64_vmxregset(Note *note, PowerPCCPU *cpu)
130 int i;
131 struct PPC64ElfVmxregset *vmxregset;
133 note->hdr.n_type = cpu_to_be32(NT_PPC_VMX);
134 vmxregset = &note->contents.vmxregset;
135 memset(vmxregset, 0, sizeof(*vmxregset));
137 for (i = 0; i < 32; i++) {
138 vmxregset->avr[i].u64[0] = cpu_to_be64(cpu->env.avr[i].u64[0]);
139 vmxregset->avr[i].u64[1] = cpu_to_be64(cpu->env.avr[i].u64[1]);
141 vmxregset->vscr.u32[3] = cpu_to_be32(cpu->env.vscr);
143 static void ppc64_write_elf64_vsxregset(Note *note, PowerPCCPU *cpu)
145 int i;
146 struct PPC64ElfVsxregset *vsxregset;
148 note->hdr.n_type = cpu_to_be32(NT_PPC_VSX);
149 vsxregset = &note->contents.vsxregset;
150 memset(vsxregset, 0, sizeof(*vsxregset));
152 for (i = 0; i < 32; i++) {
153 vsxregset->vsr[i] = cpu_to_be64(cpu->env.vsr[i]);
156 static void ppc64_write_elf64_speregset(Note *note, PowerPCCPU *cpu)
158 struct PPC64ElfSperegset *speregset;
159 note->hdr.n_type = cpu_to_be32(NT_PPC_SPE);
160 speregset = &note->contents.speregset;
161 memset(speregset, 0, sizeof(*speregset));
163 speregset->spe_acc = cpu_to_be64(cpu->env.spe_acc);
164 speregset->spe_fscr = cpu_to_be32(cpu->env.spe_fscr);
167 static const struct NoteFuncDescStruct {
168 int contents_size;
169 void (*note_contents_func)(Note *note, PowerPCCPU *cpu);
170 } note_func[] = {
171 {sizeof(((Note *)0)->contents.prstatus), ppc64_write_elf64_prstatus},
172 {sizeof(((Note *)0)->contents.fpregset), ppc64_write_elf64_fpregset},
173 {sizeof(((Note *)0)->contents.vmxregset), ppc64_write_elf64_vmxregset},
174 {sizeof(((Note *)0)->contents.vsxregset), ppc64_write_elf64_vsxregset},
175 {sizeof(((Note *)0)->contents.speregset), ppc64_write_elf64_speregset},
176 { 0, NULL}
179 typedef struct NoteFuncDescStruct NoteFuncDesc;
181 int cpu_get_dump_info(ArchDumpInfo *info,
182 const struct GuestPhysBlockList *guest_phys_blocks)
185 * Currently only handling PPC64 big endian.
187 info->d_machine = EM_PPC64;
188 info->d_endian = ELFDATA2MSB;
189 info->d_class = ELFCLASS64;
191 return 0;
194 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
196 int name_size = 8; /* "CORE" or "QEMU" rounded */
197 size_t elf_note_size = 0;
198 int note_head_size;
199 const NoteFuncDesc *nf;
201 if (class != ELFCLASS64) {
202 return -1;
204 assert(machine == EM_PPC64);
206 note_head_size = sizeof(Elf64_Nhdr);
208 for (nf = note_func; nf->note_contents_func; nf++) {
209 elf_note_size = elf_note_size + note_head_size + name_size +
210 nf->contents_size;
213 return (elf_note_size) * nr_cpus;
216 static int ppc64_write_all_elf64_notes(const char *note_name,
217 WriteCoreDumpFunction f,
218 PowerPCCPU *cpu, int id,
219 void *opaque)
221 Note note;
222 int ret = -1;
223 int note_size;
224 const NoteFuncDesc *nf;
226 for (nf = note_func; nf->note_contents_func; nf++) {
227 note.hdr.n_namesz = cpu_to_be32(sizeof(note.name));
228 note.hdr.n_descsz = cpu_to_be32(nf->contents_size);
229 strncpy(note.name, note_name, sizeof(note.name));
231 (*nf->note_contents_func)(&note, cpu);
233 note_size = sizeof(note) - sizeof(note.contents) + nf->contents_size;
234 ret = f(&note, note_size, opaque);
235 if (ret < 0) {
236 return -1;
239 return 0;
242 int ppc64_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
243 int cpuid, void *opaque)
245 PowerPCCPU *cpu = POWERPC_CPU(cs);
246 return ppc64_write_all_elf64_notes("CORE", f, cpu, cpuid, opaque);
249 int ppc64_cpu_write_elf64_qemunote(WriteCoreDumpFunction f,
250 CPUState *cpu, void *opaque)
252 return 0;