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