2 * writing ELF notes for s390x arch
5 * Copyright IBM Corp. 2012, 2013
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
17 #include "exec/cpu-all.h"
18 #include "sysemu/dump.h"
19 #include "sysemu/kvm.h"
22 struct S390xUserRegsStruct {
28 typedef struct S390xUserRegsStruct S390xUserRegs;
30 struct S390xElfPrstatusStruct {
38 typedef struct S390xElfPrstatusStruct S390xElfPrstatus;
40 struct S390xElfFpregsetStruct {
46 typedef struct S390xElfFpregsetStruct S390xElfFpregset;
48 struct S390xElfVregsLoStruct {
52 typedef struct S390xElfVregsLoStruct S390xElfVregsLo;
54 struct S390xElfVregsHiStruct {
55 uint64_t vregs[16][2];
58 typedef struct S390xElfVregsHiStruct S390xElfVregsHi;
60 typedef struct noteStruct {
65 S390xElfPrstatus prstatus;
66 S390xElfFpregset fpregset;
67 S390xElfVregsLo vregslo;
68 S390xElfVregsHi vregshi;
77 static void s390x_write_elf64_prstatus(Note *note, S390CPU *cpu)
82 note->hdr.n_type = cpu_to_be32(NT_PRSTATUS);
84 regs = &(note->contents.prstatus.regs);
85 regs->psw[0] = cpu_to_be64(cpu->env.psw.mask);
86 regs->psw[1] = cpu_to_be64(cpu->env.psw.addr);
87 for (i = 0; i <= 15; i++) {
88 regs->acrs[i] = cpu_to_be32(cpu->env.aregs[i]);
89 regs->gprs[i] = cpu_to_be64(cpu->env.regs[i]);
93 static void s390x_write_elf64_fpregset(Note *note, S390CPU *cpu)
96 CPUS390XState *cs = &cpu->env;
98 note->hdr.n_type = cpu_to_be32(NT_FPREGSET);
99 note->contents.fpregset.fpc = cpu_to_be32(cpu->env.fpc);
100 for (i = 0; i <= 15; i++) {
101 note->contents.fpregset.fprs[i] = cpu_to_be64(get_freg(cs, i)->ll);
105 static void s390x_write_elf64_vregslo(Note *note, S390CPU *cpu)
109 note->hdr.n_type = cpu_to_be32(NT_S390_VXRS_LOW);
110 for (i = 0; i <= 15; i++) {
111 note->contents.vregslo.vregs[i] = cpu_to_be64(cpu->env.vregs[i][1].ll);
115 static void s390x_write_elf64_vregshi(Note *note, S390CPU *cpu)
118 S390xElfVregsHi *temp_vregshi;
120 temp_vregshi = ¬e->contents.vregshi;
122 note->hdr.n_type = cpu_to_be32(NT_S390_VXRS_HIGH);
123 for (i = 0; i <= 15; i++) {
124 temp_vregshi->vregs[i][0] = cpu_to_be64(cpu->env.vregs[i + 16][0].ll);
125 temp_vregshi->vregs[i][1] = cpu_to_be64(cpu->env.vregs[i + 16][1].ll);
129 static void s390x_write_elf64_timer(Note *note, S390CPU *cpu)
131 note->hdr.n_type = cpu_to_be32(NT_S390_TIMER);
132 note->contents.timer = cpu_to_be64((uint64_t)(cpu->env.cputm));
135 static void s390x_write_elf64_todcmp(Note *note, S390CPU *cpu)
137 note->hdr.n_type = cpu_to_be32(NT_S390_TODCMP);
138 note->contents.todcmp = cpu_to_be64((uint64_t)(cpu->env.ckc));
141 static void s390x_write_elf64_todpreg(Note *note, S390CPU *cpu)
143 note->hdr.n_type = cpu_to_be32(NT_S390_TODPREG);
144 note->contents.todpreg = cpu_to_be32((uint32_t)(cpu->env.todpr));
147 static void s390x_write_elf64_ctrs(Note *note, S390CPU *cpu)
151 note->hdr.n_type = cpu_to_be32(NT_S390_CTRS);
153 for (i = 0; i <= 15; i++) {
154 note->contents.ctrs[i] = cpu_to_be64(cpu->env.cregs[i]);
158 static void s390x_write_elf64_prefix(Note *note, S390CPU *cpu)
160 note->hdr.n_type = cpu_to_be32(NT_S390_PREFIX);
161 note->contents.prefix = cpu_to_be32((uint32_t)(cpu->env.psa));
165 static const struct NoteFuncDescStruct {
167 void (*note_contents_func)(Note *note, S390CPU *cpu);
169 {sizeof(((Note *)0)->contents.prstatus), s390x_write_elf64_prstatus},
170 {sizeof(((Note *)0)->contents.prefix), s390x_write_elf64_prefix},
171 {sizeof(((Note *)0)->contents.fpregset), s390x_write_elf64_fpregset},
172 {sizeof(((Note *)0)->contents.ctrs), s390x_write_elf64_ctrs},
173 {sizeof(((Note *)0)->contents.timer), s390x_write_elf64_timer},
174 {sizeof(((Note *)0)->contents.todcmp), s390x_write_elf64_todcmp},
175 {sizeof(((Note *)0)->contents.todpreg), s390x_write_elf64_todpreg},
176 {sizeof(((Note *)0)->contents.vregslo), s390x_write_elf64_vregslo},
177 {sizeof(((Note *)0)->contents.vregshi), s390x_write_elf64_vregshi},
181 typedef struct NoteFuncDescStruct NoteFuncDesc;
184 static int s390x_write_all_elf64_notes(const char *note_name,
185 WriteCoreDumpFunction f,
186 S390CPU *cpu, int id,
190 const NoteFuncDesc *nf;
194 for (nf = note_func; nf->note_contents_func; nf++) {
195 memset(¬e, 0, sizeof(note));
196 note.hdr.n_namesz = cpu_to_be32(sizeof(note.name));
197 note.hdr.n_descsz = cpu_to_be32(nf->contents_size);
198 strncpy(note.name, note_name, sizeof(note.name));
199 (*nf->note_contents_func)(¬e, cpu);
201 note_size = sizeof(note) - sizeof(note.contents) + nf->contents_size;
202 ret = f(¬e, note_size, opaque);
214 int s390_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
215 int cpuid, void *opaque)
217 S390CPU *cpu = S390_CPU(cs);
218 return s390x_write_all_elf64_notes("CORE", f, cpu, cpuid, opaque);
221 int cpu_get_dump_info(ArchDumpInfo *info,
222 const struct GuestPhysBlockList *guest_phys_blocks)
224 info->d_machine = EM_S390;
225 info->d_endian = ELFDATA2MSB;
226 info->d_class = ELFCLASS64;
231 ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
233 int name_size = 8; /* "CORE" or "QEMU" rounded */
234 size_t elf_note_size = 0;
236 const NoteFuncDesc *nf;
238 assert(class == ELFCLASS64);
239 assert(machine == EM_S390);
241 note_head_size = sizeof(Elf64_Nhdr);
243 for (nf = note_func; nf->note_contents_func; nf++) {
244 elf_note_size = elf_note_size + note_head_size + name_size +
248 return (elf_note_size) * nr_cpus;