2 * writing ELF notes for s390x arch
5 * Copyright IBM Corp. 2012, 2013
7 * Ekaterina Tumanova <tumanova@linux.vnet.ibm.com>
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"
18 #include "sysemu/dump.h"
21 struct S390xUserRegsStruct
{
27 typedef struct S390xUserRegsStruct S390xUserRegs
;
29 struct S390xElfPrstatusStruct
{
37 typedef struct S390xElfPrstatusStruct S390xElfPrstatus
;
39 struct S390xElfFpregsetStruct
{
45 typedef struct S390xElfFpregsetStruct S390xElfFpregset
;
47 struct S390xElfVregsLoStruct
{
51 typedef struct S390xElfVregsLoStruct S390xElfVregsLo
;
53 struct S390xElfVregsHiStruct
{
54 uint64_t vregs
[16][2];
57 typedef struct S390xElfVregsHiStruct S390xElfVregsHi
;
59 struct S390xElfGSCBStruct
{
63 typedef struct S390xElfGSCBStruct S390xElfGSCB
;
65 typedef struct noteStruct
{
69 S390xElfPrstatus prstatus
;
70 S390xElfFpregset fpregset
;
71 S390xElfVregsLo vregslo
;
72 S390xElfVregsHi vregshi
;
82 static void s390x_write_elf64_prstatus(Note
*note
, S390CPU
*cpu
, int id
)
87 note
->hdr
.n_type
= cpu_to_be32(NT_PRSTATUS
);
89 regs
= &(note
->contents
.prstatus
.regs
);
90 regs
->psw
[0] = cpu_to_be64(cpu
->env
.psw
.mask
);
91 regs
->psw
[1] = cpu_to_be64(cpu
->env
.psw
.addr
);
92 for (i
= 0; i
<= 15; i
++) {
93 regs
->acrs
[i
] = cpu_to_be32(cpu
->env
.aregs
[i
]);
94 regs
->gprs
[i
] = cpu_to_be64(cpu
->env
.regs
[i
]);
96 note
->contents
.prstatus
.pid
= id
;
99 static void s390x_write_elf64_fpregset(Note
*note
, S390CPU
*cpu
, int id
)
102 CPUS390XState
*cs
= &cpu
->env
;
104 note
->hdr
.n_type
= cpu_to_be32(NT_FPREGSET
);
105 note
->contents
.fpregset
.fpc
= cpu_to_be32(cpu
->env
.fpc
);
106 for (i
= 0; i
<= 15; i
++) {
107 note
->contents
.fpregset
.fprs
[i
] = cpu_to_be64(get_freg(cs
, i
)->ll
);
111 static void s390x_write_elf64_vregslo(Note
*note
, S390CPU
*cpu
, int id
)
115 note
->hdr
.n_type
= cpu_to_be32(NT_S390_VXRS_LOW
);
116 for (i
= 0; i
<= 15; i
++) {
117 note
->contents
.vregslo
.vregs
[i
] = cpu_to_be64(cpu
->env
.vregs
[i
][1].ll
);
121 static void s390x_write_elf64_vregshi(Note
*note
, S390CPU
*cpu
, int id
)
124 S390xElfVregsHi
*temp_vregshi
;
126 temp_vregshi
= ¬e
->contents
.vregshi
;
128 note
->hdr
.n_type
= cpu_to_be32(NT_S390_VXRS_HIGH
);
129 for (i
= 0; i
<= 15; i
++) {
130 temp_vregshi
->vregs
[i
][0] = cpu_to_be64(cpu
->env
.vregs
[i
+ 16][0].ll
);
131 temp_vregshi
->vregs
[i
][1] = cpu_to_be64(cpu
->env
.vregs
[i
+ 16][1].ll
);
135 static void s390x_write_elf64_gscb(Note
*note
, S390CPU
*cpu
, int id
)
139 note
->hdr
.n_type
= cpu_to_be32(NT_S390_GS_CB
);
140 for (i
= 0; i
< 4; i
++) {
141 note
->contents
.gscb
.gsregs
[i
] = cpu_to_be64(cpu
->env
.gscb
[i
]);
145 static void s390x_write_elf64_timer(Note
*note
, S390CPU
*cpu
, int id
)
147 note
->hdr
.n_type
= cpu_to_be32(NT_S390_TIMER
);
148 note
->contents
.timer
= cpu_to_be64((uint64_t)(cpu
->env
.cputm
));
151 static void s390x_write_elf64_todcmp(Note
*note
, S390CPU
*cpu
, int id
)
153 note
->hdr
.n_type
= cpu_to_be32(NT_S390_TODCMP
);
154 note
->contents
.todcmp
= cpu_to_be64((uint64_t)(cpu
->env
.ckc
));
157 static void s390x_write_elf64_todpreg(Note
*note
, S390CPU
*cpu
, int id
)
159 note
->hdr
.n_type
= cpu_to_be32(NT_S390_TODPREG
);
160 note
->contents
.todpreg
= cpu_to_be32((uint32_t)(cpu
->env
.todpr
));
163 static void s390x_write_elf64_ctrs(Note
*note
, S390CPU
*cpu
, int id
)
167 note
->hdr
.n_type
= cpu_to_be32(NT_S390_CTRS
);
169 for (i
= 0; i
<= 15; i
++) {
170 note
->contents
.ctrs
[i
] = cpu_to_be64(cpu
->env
.cregs
[i
]);
174 static void s390x_write_elf64_prefix(Note
*note
, S390CPU
*cpu
, int id
)
176 note
->hdr
.n_type
= cpu_to_be32(NT_S390_PREFIX
);
177 note
->contents
.prefix
= cpu_to_be32((uint32_t)(cpu
->env
.psa
));
181 typedef struct NoteFuncDescStruct
{
183 void (*note_contents_func
)(Note
*note
, S390CPU
*cpu
, int id
);
186 static const NoteFuncDesc note_core
[] = {
187 {sizeof(((Note
*)0)->contents
.prstatus
), s390x_write_elf64_prstatus
},
188 {sizeof(((Note
*)0)->contents
.fpregset
), s390x_write_elf64_fpregset
},
192 static const NoteFuncDesc note_linux
[] = {
193 {sizeof(((Note
*)0)->contents
.prefix
), s390x_write_elf64_prefix
},
194 {sizeof(((Note
*)0)->contents
.ctrs
), s390x_write_elf64_ctrs
},
195 {sizeof(((Note
*)0)->contents
.timer
), s390x_write_elf64_timer
},
196 {sizeof(((Note
*)0)->contents
.todcmp
), s390x_write_elf64_todcmp
},
197 {sizeof(((Note
*)0)->contents
.todpreg
), s390x_write_elf64_todpreg
},
198 {sizeof(((Note
*)0)->contents
.vregslo
), s390x_write_elf64_vregslo
},
199 {sizeof(((Note
*)0)->contents
.vregshi
), s390x_write_elf64_vregshi
},
200 {sizeof(((Note
*)0)->contents
.gscb
), s390x_write_elf64_gscb
},
204 static int s390x_write_elf64_notes(const char *note_name
,
205 WriteCoreDumpFunction f
,
206 S390CPU
*cpu
, int id
,
208 const NoteFuncDesc
*funcs
)
211 const NoteFuncDesc
*nf
;
215 for (nf
= funcs
; nf
->note_contents_func
; nf
++) {
216 memset(¬e
, 0, sizeof(note
));
217 note
.hdr
.n_namesz
= cpu_to_be32(strlen(note_name
) + 1);
218 note
.hdr
.n_descsz
= cpu_to_be32(nf
->contents_size
);
219 strncpy(note
.name
, note_name
, sizeof(note
.name
));
220 (*nf
->note_contents_func
)(¬e
, cpu
, id
);
222 note_size
= sizeof(note
) - sizeof(note
.contents
) + nf
->contents_size
;
223 ret
= f(¬e
, note_size
, opaque
);
235 int s390_cpu_write_elf64_note(WriteCoreDumpFunction f
, CPUState
*cs
,
236 int cpuid
, void *opaque
)
238 S390CPU
*cpu
= S390_CPU(cs
);
241 r
= s390x_write_elf64_notes("CORE", f
, cpu
, cpuid
, opaque
, note_core
);
245 return s390x_write_elf64_notes("LINUX", f
, cpu
, cpuid
, opaque
, note_linux
);
248 int cpu_get_dump_info(ArchDumpInfo
*info
,
249 const struct GuestPhysBlockList
*guest_phys_blocks
)
251 info
->d_machine
= EM_S390
;
252 info
->d_endian
= ELFDATA2MSB
;
253 info
->d_class
= ELFCLASS64
;
258 ssize_t
cpu_get_note_size(int class, int machine
, int nr_cpus
)
260 int name_size
= 8; /* "LINUX" or "CORE" + pad */
261 size_t elf_note_size
= 0;
263 const NoteFuncDesc
*nf
;
265 assert(class == ELFCLASS64
);
266 assert(machine
== EM_S390
);
268 note_head_size
= sizeof(Elf64_Nhdr
);
270 for (nf
= note_core
; nf
->note_contents_func
; nf
++) {
271 elf_note_size
= elf_note_size
+ note_head_size
+ name_size
+
274 for (nf
= note_linux
; nf
->note_contents_func
; nf
++) {
275 elf_note_size
= elf_note_size
+ note_head_size
+ name_size
+
279 return (elf_note_size
) * nr_cpus
;