]> git.proxmox.com Git - mirror_qemu.git/blame - target-s390x/arch_dump.c
s390x: s390_cpu_get_phys_page_debug has to return -1
[mirror_qemu.git] / target-s390x / arch_dump.c
CommitLineData
9b4f38e1
ET
1/*
2 * writing ELF notes for s390x arch
3 *
4 *
5 * Copyright IBM Corp. 2012, 2013
6 *
7 * Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
8 *
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.
11 *
12 */
13
14#include "cpu.h"
15#include "elf.h"
16#include "exec/cpu-all.h"
17#include "sysemu/dump.h"
18#include "sysemu/kvm.h"
19
20
21struct S390xUserRegsStruct {
22 uint64_t psw[2];
23 uint64_t gprs[16];
24 uint32_t acrs[16];
25} QEMU_PACKED;
26
27typedef struct S390xUserRegsStruct S390xUserRegs;
28
29struct S390xElfPrstatusStruct {
30 uint8_t pad1[32];
31 uint32_t pid;
32 uint8_t pad2[76];
33 S390xUserRegs regs;
34 uint8_t pad3[16];
35} QEMU_PACKED;
36
37typedef struct S390xElfPrstatusStruct S390xElfPrstatus;
38
39struct S390xElfFpregsetStruct {
40 uint32_t fpc;
41 uint32_t pad;
42 uint64_t fprs[16];
43} QEMU_PACKED;
44
45typedef struct S390xElfFpregsetStruct S390xElfFpregset;
46
3ceeb293
EF
47struct S390xElfVregsLoStruct {
48 uint64_t vregs[16];
49} QEMU_PACKED;
50
51typedef struct S390xElfVregsLoStruct S390xElfVregsLo;
52
53struct S390xElfVregsHiStruct {
54 uint64_t vregs[16][2];
55} QEMU_PACKED;
56
57typedef struct S390xElfVregsHiStruct S390xElfVregsHi;
58
9b4f38e1
ET
59typedef struct noteStruct {
60 Elf64_Nhdr hdr;
61 char name[5];
62 char pad3[3];
63 union {
64 S390xElfPrstatus prstatus;
65 S390xElfFpregset fpregset;
3ceeb293
EF
66 S390xElfVregsLo vregslo;
67 S390xElfVregsHi vregshi;
9b4f38e1
ET
68 uint32_t prefix;
69 uint64_t timer;
70 uint64_t todcmp;
71 uint32_t todpreg;
72 uint64_t ctrs[16];
73 } contents;
74} QEMU_PACKED Note;
75
76static void s390x_write_elf64_prstatus(Note *note, S390CPU *cpu)
77{
78 int i;
79 S390xUserRegs *regs;
80
81 note->hdr.n_type = cpu_to_be32(NT_PRSTATUS);
82
83 regs = &(note->contents.prstatus.regs);
84 regs->psw[0] = cpu_to_be64(cpu->env.psw.mask);
85 regs->psw[1] = cpu_to_be64(cpu->env.psw.addr);
86 for (i = 0; i <= 15; i++) {
87 regs->acrs[i] = cpu_to_be32(cpu->env.aregs[i]);
88 regs->gprs[i] = cpu_to_be64(cpu->env.regs[i]);
89 }
90}
91
92static void s390x_write_elf64_fpregset(Note *note, S390CPU *cpu)
93{
94 int i;
c498d8e3 95 CPUS390XState *cs = &cpu->env;
9b4f38e1
ET
96
97 note->hdr.n_type = cpu_to_be32(NT_FPREGSET);
98 note->contents.fpregset.fpc = cpu_to_be32(cpu->env.fpc);
99 for (i = 0; i <= 15; i++) {
c498d8e3 100 note->contents.fpregset.fprs[i] = cpu_to_be64(get_freg(cs, i)->ll);
9b4f38e1
ET
101 }
102}
103
3ceeb293
EF
104static void s390x_write_elf64_vregslo(Note *note, S390CPU *cpu)
105{
106 int i;
107
108 note->hdr.n_type = cpu_to_be32(NT_S390_VXRS_LOW);
109 for (i = 0; i <= 15; i++) {
110 note->contents.vregslo.vregs[i] = cpu_to_be64(cpu->env.vregs[i][1].ll);
111 }
112}
113
114static void s390x_write_elf64_vregshi(Note *note, S390CPU *cpu)
115{
116 int i;
117 S390xElfVregsHi *temp_vregshi;
118
119 temp_vregshi = &note->contents.vregshi;
120
121 note->hdr.n_type = cpu_to_be32(NT_S390_VXRS_HIGH);
122 for (i = 0; i <= 15; i++) {
123 temp_vregshi->vregs[i][0] = cpu_to_be64(cpu->env.vregs[i + 16][0].ll);
124 temp_vregshi->vregs[i][1] = cpu_to_be64(cpu->env.vregs[i + 16][1].ll);
125 }
126}
9b4f38e1
ET
127
128static void s390x_write_elf64_timer(Note *note, S390CPU *cpu)
129{
130 note->hdr.n_type = cpu_to_be32(NT_S390_TIMER);
131 note->contents.timer = cpu_to_be64((uint64_t)(cpu->env.cputm));
132}
133
134static void s390x_write_elf64_todcmp(Note *note, S390CPU *cpu)
135{
136 note->hdr.n_type = cpu_to_be32(NT_S390_TODCMP);
137 note->contents.todcmp = cpu_to_be64((uint64_t)(cpu->env.ckc));
138}
139
140static void s390x_write_elf64_todpreg(Note *note, S390CPU *cpu)
141{
142 note->hdr.n_type = cpu_to_be32(NT_S390_TODPREG);
143 note->contents.todpreg = cpu_to_be32((uint32_t)(cpu->env.todpr));
144}
145
146static void s390x_write_elf64_ctrs(Note *note, S390CPU *cpu)
147{
148 int i;
149
150 note->hdr.n_type = cpu_to_be32(NT_S390_CTRS);
151
152 for (i = 0; i <= 15; i++) {
153 note->contents.ctrs[i] = cpu_to_be64(cpu->env.cregs[i]);
154 }
155}
156
157static void s390x_write_elf64_prefix(Note *note, S390CPU *cpu)
158{
159 note->hdr.n_type = cpu_to_be32(NT_S390_PREFIX);
160 note->contents.prefix = cpu_to_be32((uint32_t)(cpu->env.psa));
161}
162
163
ecb4e01e 164static const struct NoteFuncDescStruct {
9b4f38e1
ET
165 int contents_size;
166 void (*note_contents_func)(Note *note, S390CPU *cpu);
167} note_func[] = {
168 {sizeof(((Note *)0)->contents.prstatus), s390x_write_elf64_prstatus},
169 {sizeof(((Note *)0)->contents.prefix), s390x_write_elf64_prefix},
170 {sizeof(((Note *)0)->contents.fpregset), s390x_write_elf64_fpregset},
171 {sizeof(((Note *)0)->contents.ctrs), s390x_write_elf64_ctrs},
172 {sizeof(((Note *)0)->contents.timer), s390x_write_elf64_timer},
173 {sizeof(((Note *)0)->contents.todcmp), s390x_write_elf64_todcmp},
174 {sizeof(((Note *)0)->contents.todpreg), s390x_write_elf64_todpreg},
3ceeb293
EF
175 {sizeof(((Note *)0)->contents.vregslo), s390x_write_elf64_vregslo},
176 {sizeof(((Note *)0)->contents.vregshi), s390x_write_elf64_vregshi},
9b4f38e1
ET
177 { 0, NULL}
178};
179
180typedef struct NoteFuncDescStruct NoteFuncDesc;
181
182
183static int s390x_write_all_elf64_notes(const char *note_name,
184 WriteCoreDumpFunction f,
185 S390CPU *cpu, int id,
186 void *opaque)
187{
188 Note note;
ecb4e01e 189 const NoteFuncDesc *nf;
9b4f38e1
ET
190 int note_size;
191 int ret = -1;
192
193 for (nf = note_func; nf->note_contents_func; nf++) {
abd137a1 194 memset(&note, 0, sizeof(note));
9b4f38e1
ET
195 note.hdr.n_namesz = cpu_to_be32(sizeof(note.name));
196 note.hdr.n_descsz = cpu_to_be32(nf->contents_size);
197 strncpy(note.name, note_name, sizeof(note.name));
198 (*nf->note_contents_func)(&note, cpu);
199
200 note_size = sizeof(note) - sizeof(note.contents) + nf->contents_size;
201 ret = f(&note, note_size, opaque);
202
203 if (ret < 0) {
204 return -1;
205 }
206
207 }
208
209 return 0;
210}
211
212
213int s390_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs,
214 int cpuid, void *opaque)
215{
216 S390CPU *cpu = S390_CPU(cs);
217 return s390x_write_all_elf64_notes("CORE", f, cpu, cpuid, opaque);
218}
219
56c4bfb3
LE
220int cpu_get_dump_info(ArchDumpInfo *info,
221 const struct GuestPhysBlockList *guest_phys_blocks)
9b4f38e1
ET
222{
223 info->d_machine = EM_S390;
224 info->d_endian = ELFDATA2MSB;
225 info->d_class = ELFCLASS64;
226
227 return 0;
228}
229
230ssize_t cpu_get_note_size(int class, int machine, int nr_cpus)
231{
232 int name_size = 8; /* "CORE" or "QEMU" rounded */
233 size_t elf_note_size = 0;
234 int note_head_size;
ecb4e01e 235 const NoteFuncDesc *nf;
9b4f38e1
ET
236
237 assert(class == ELFCLASS64);
238 assert(machine == EM_S390);
239
240 note_head_size = sizeof(Elf64_Nhdr);
241
242 for (nf = note_func; nf->note_contents_func; nf++) {
243 elf_note_size = elf_note_size + note_head_size + name_size +
244 nf->contents_size;
245 }
246
247 return (elf_note_size) * nr_cpus;
248}