2 * writing ELF notes for ppc64 arch
5 * Copyright IBM, Corp. 2013
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.
17 #include "exec/cpu-all.h"
18 #include "sysemu/dump.h"
19 #include "sysemu/kvm.h"
21 struct PPC64UserRegStruct
{
37 struct PPC64ElfPrstatus
{
39 struct PPC64UserRegStruct pr_reg
;
44 struct PPC64ElfFpregset
{
50 struct PPC64ElfVmxregset
{
59 struct PPC64ElfVsxregset
{
63 struct PPC64ElfSperegset
{
69 typedef struct noteStruct
{
74 struct PPC64ElfPrstatus prstatus
;
75 struct PPC64ElfFpregset fpregset
;
76 struct PPC64ElfVmxregset vmxregset
;
77 struct PPC64ElfVsxregset vsxregset
;
78 struct PPC64ElfSperegset speregset
;
83 static void ppc64_write_elf64_prstatus(Note
*note
, PowerPCCPU
*cpu
)
87 struct PPC64ElfPrstatus
*prstatus
;
88 struct PPC64UserRegStruct
*reg
;
90 note
->hdr
.n_type
= cpu_to_be32(NT_PRSTATUS
);
92 prstatus
= ¬e
->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
));
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
)
115 struct PPC64ElfFpregset
*fpregset
;
117 note
->hdr
.n_type
= cpu_to_be32(NT_PRFPREG
);
119 fpregset
= ¬e
->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
)
131 struct PPC64ElfVmxregset
*vmxregset
;
133 note
->hdr
.n_type
= cpu_to_be32(NT_PPC_VMX
);
134 vmxregset
= ¬e
->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
)
146 struct PPC64ElfVsxregset
*vsxregset
;
148 note
->hdr
.n_type
= cpu_to_be32(NT_PPC_VSX
);
149 vsxregset
= ¬e
->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
= ¬e
->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 struct NoteFuncDescStruct
{
169 void (*note_contents_func
)(Note
*note
, PowerPCCPU
*cpu
);
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
},
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
;
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;
201 if (class != ELFCLASS64
) {
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
+
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
,
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
)(¬e
, cpu
);
233 note_size
= sizeof(note
) - sizeof(note
.contents
) + nf
->contents_size
;
234 ret
= f(¬e
, note_size
, opaque
);
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
)