From patchwork Wed Nov 25 00:37:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jones X-Patchwork-Id: 57283 Delivered-To: patch@linaro.org Received: by 10.112.155.196 with SMTP id vy4csp2434185lbb; Tue, 24 Nov 2015 16:42:29 -0800 (PST) X-Received: by 10.31.11.204 with SMTP id 195mr30398045vkl.23.1448412149135; Tue, 24 Nov 2015 16:42:29 -0800 (PST) Return-Path: Received: from lists.gnu.org (lists.gnu.org. [2001:4830:134:3::11]) by mx.google.com with ESMTPS id b17si21017478vka.132.2015.11.24.16.42.28 for (version=TLS1 cipher=AES128-SHA bits=128/128); Tue, 24 Nov 2015 16:42:29 -0800 (PST) Received-SPF: pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) client-ip=2001:4830:134:3::11; Authentication-Results: mx.google.com; spf=pass (google.com: domain of qemu-devel-bounces+patch=linaro.org@nongnu.org designates 2001:4830:134:3::11 as permitted sender) smtp.mailfrom=qemu-devel-bounces+patch=linaro.org@nongnu.org Received: from localhost ([::1]:42302 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1OAG-0004KM-M9 for patch@linaro.org; Tue, 24 Nov 2015 19:42:28 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:43696) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1O6Y-0006Cy-UN for qemu-devel@nongnu.org; Tue, 24 Nov 2015 19:38:40 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1a1O6W-0002Qr-Kk for qemu-devel@nongnu.org; Tue, 24 Nov 2015 19:38:38 -0500 Received: from mx1.redhat.com ([209.132.183.28]:54401) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1a1O6S-0002Nv-9I; Tue, 24 Nov 2015 19:38:32 -0500 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (Postfix) with ESMTPS id ED365B5E8D; Wed, 25 Nov 2015 00:38:31 +0000 (UTC) Received: from hawk.localdomain.com (ovpn-116-38.ams2.redhat.com [10.36.116.38]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id tAP0c1s3014074; Tue, 24 Nov 2015 19:38:28 -0500 From: Andrew Jones To: qemu-devel@nongnu.org Date: Tue, 24 Nov 2015 19:37:57 -0500 Message-Id: <1448411877-22019-7-git-send-email-drjones@redhat.com> In-Reply-To: <1448411877-22019-1-git-send-email-drjones@redhat.com> References: <1448411877-22019-1-git-send-email-drjones@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 X-detected-operating-system: by eggs.gnu.org: GNU/Linux 3.x X-Received-From: 209.132.183.28 Cc: peter.maydell@linaro.org, agraf@suse.de, armbru@redhat.com, qemu-arm@nongnu.org, qemu-ppc@nongnu.org, afaerber@suse.de, rth@twiddle.net Subject: [Qemu-devel] [PATCH v2 6/6] target-arm: dump-guest-memory: add fpregset notes X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+patch=linaro.org@nongnu.org Sender: qemu-devel-bounces+patch=linaro.org@nongnu.org Also refactors note init code to avoid code duplication. Signed-off-by: Andrew Jones --- target-arm/arch_dump.c | 161 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 139 insertions(+), 22 deletions(-) -- 2.4.3 diff --git a/target-arm/arch_dump.c b/target-arm/arch_dump.c index 5debe549d721d..8d74788411d79 100644 --- a/target-arm/arch_dump.c +++ b/target-arm/arch_dump.c @@ -35,6 +35,16 @@ struct aarch64_user_regs { QEMU_BUILD_BUG_ON(sizeof(struct aarch64_user_regs) != 272); +/* struct user_fpsimd_state from arch/arm64/include/uapi/asm/ptrace.h */ +struct aarch64_user_vfp_state { + uint64_t vregs[64]; + uint32_t fpsr; + uint32_t fpcr; + char pad[8]; +} QEMU_PACKED; + +QEMU_BUILD_BUG_ON(sizeof(struct aarch64_user_vfp_state) != 528); + /* struct elf_prstatus from include/uapi/linux/elfcore.h */ struct aarch64_elf_prstatus { char pad1[32]; /* 32 == offsetof(struct elf_prstatus, pr_pid) */ @@ -51,10 +61,77 @@ QEMU_BUILD_BUG_ON(sizeof(struct aarch64_elf_prstatus) != 392); struct aarch64_note { Elf64_Nhdr hdr; char name[QEMU_ALIGN_UP(NOTE_NAMESZ, 4)]; - struct aarch64_elf_prstatus prstatus; + union { + struct aarch64_elf_prstatus prstatus; + struct aarch64_user_vfp_state vfp; + }; } QEMU_PACKED; -QEMU_BUILD_BUG_ON(sizeof(struct aarch64_note) != 412); +#define AARCH64_NOTE_HEADER_SIZE offsetof(struct aarch64_note, prstatus) +#define AARCH64_PRSTATUS_NOTE_SIZE \ + (AARCH64_NOTE_HEADER_SIZE + sizeof(struct aarch64_elf_prstatus)) +#define AARCH64_FPREGSET_NOTE_SIZE \ + (AARCH64_NOTE_HEADER_SIZE + sizeof(struct aarch64_user_vfp_state)) + +static void aarch64_note_init(struct aarch64_note *note, DumpState *s, + Elf64_Word type, Elf64_Word descsz) +{ + memset(note, 0, sizeof(*note)); + + note->hdr.n_namesz = cpu_to_dump32(s, NOTE_NAMESZ); + note->hdr.n_descsz = cpu_to_dump32(s, descsz); + note->hdr.n_type = cpu_to_dump32(s, type); + + memcpy(note->name, NOTE_NAME, NOTE_NAMESZ); +} + +static void arm_write_vregs(uint64_t *vregs, int num_regs, + CPUARMState *env, DumpState *s) +{ + int i; + + for (i = 0; i < num_regs; ++i) { + vregs[i] = cpu_to_dump64(s, env->vfp.regs[i]); + } + + if (s->dump_info.d_endian == ELFDATA2MSB) { + /* We must always swap vfp.regs's 2n and 2n+1 entries when + * generating BE notes, because even big endian hosts use + * 2n+1 for the high half. + */ + for (i = 0; i < num_regs/2; ++i) { + uint64_t tmp = vregs[2*i]; + vregs[2*i] = vregs[2*i+1]; + vregs[2*i+1] = tmp; + } + } +} + +static int +aarch64_write_elf64_fpregset(WriteCoreDumpFunction f, CPUARMState *env, + int id, DumpState *s) +{ + struct aarch64_note note; + int ret; + + aarch64_note_init(¬e, s, NT_FPREGSET, sizeof(note.vfp)); + + if (is_a64(env)) { + arm_write_vregs(note.vfp.vregs, 64, env, s); + } else { + arm_write_vregs(note.vfp.vregs, 32, env, s); + } + + note.vfp.fpsr = cpu_to_dump32(s, vfp_get_fpsr(env)); + note.vfp.fpcr = cpu_to_dump32(s, vfp_get_fpcr(env)); + + ret = f(¬e, AARCH64_FPREGSET_NOTE_SIZE, s); + if (ret < 0) { + return -1; + } + + return 0; +} static int aarch64_write_elf64_note(WriteCoreDumpFunction f, CPUARMState *env, @@ -63,13 +140,8 @@ aarch64_write_elf64_note(WriteCoreDumpFunction f, CPUARMState *env, struct aarch64_note note; int ret, i; - memset(¬e, 0, sizeof(note)); - - note.hdr.n_namesz = cpu_to_dump32(s, NOTE_NAMESZ); - note.hdr.n_descsz = cpu_to_dump32(s, sizeof(note.prstatus)); - note.hdr.n_type = cpu_to_dump32(s, NT_PRSTATUS); + aarch64_note_init(¬e, s, NT_PRSTATUS, sizeof(note.prstatus)); - memcpy(note.name, NOTE_NAME, NOTE_NAMESZ); note.prstatus.pr_pid = cpu_to_dump32(s, id); if (is_a64(env)) { @@ -89,12 +161,12 @@ aarch64_write_elf64_note(WriteCoreDumpFunction f, CPUARMState *env, note.prstatus.pr_reg.pstate = cpu_to_dump64(s, cpsr_read(env)); } - ret = f(¬e, sizeof(note), s); + ret = f(¬e, AARCH64_PRSTATUS_NOTE_SIZE, s); if (ret < 0) { return -1; } - return 0; + return aarch64_write_elf64_fpregset(f, env, id, s); } /* struct pt_regs from arch/arm/include/asm/ptrace.h */ @@ -105,6 +177,14 @@ struct arm_user_regs { QEMU_BUILD_BUG_ON(sizeof(struct arm_user_regs) != 72); +/* struct user_vfp from arch/arm/include/asm/user.h */ +struct arm_user_vfp_state { + uint64_t vregs[32]; + uint32_t fpscr; +} QEMU_PACKED; + +QEMU_BUILD_BUG_ON(sizeof(struct arm_user_vfp_state) != 260); + /* struct elf_prstatus from include/uapi/linux/elfcore.h */ struct arm_elf_prstatus { char pad1[24]; /* 24 == offsetof(struct elf_prstatus, pr_pid) */ @@ -120,10 +200,50 @@ QEMU_BUILD_BUG_ON(sizeof(struct arm_elf_prstatus) != 148); struct arm_note { Elf32_Nhdr hdr; char name[QEMU_ALIGN_UP(NOTE_NAMESZ, 4)]; - struct arm_elf_prstatus prstatus; + union { + struct arm_elf_prstatus prstatus; + struct arm_user_vfp_state vfp; + }; } QEMU_PACKED; -QEMU_BUILD_BUG_ON(sizeof(struct arm_note) != 168); +#define ARM_NOTE_HEADER_SIZE offsetof(struct arm_note, prstatus) +#define ARM_PRSTATUS_NOTE_SIZE \ + (ARM_NOTE_HEADER_SIZE + sizeof(struct arm_elf_prstatus)) +#define ARM_FPREGSET_NOTE_SIZE \ + (ARM_NOTE_HEADER_SIZE + sizeof(struct arm_user_vfp_state)) + +static void arm_note_init(struct arm_note *note, DumpState *s, + Elf32_Word type, Elf32_Word descsz) +{ + memset(note, 0, sizeof(*note)); + + note->hdr.n_namesz = cpu_to_dump32(s, NOTE_NAMESZ); + note->hdr.n_descsz = cpu_to_dump32(s, descsz); + note->hdr.n_type = cpu_to_dump32(s, type); + + memcpy(note->name, NOTE_NAME, NOTE_NAMESZ); +} + +static int +arm_write_elf32_fpregset(WriteCoreDumpFunction f, CPUARMState *env, + int id, DumpState *s) +{ + struct arm_note note; + int ret; + + arm_note_init(¬e, s, NT_FPREGSET, sizeof(note.vfp)); + + arm_write_vregs(note.vfp.vregs, 32, env, s); + + note.vfp.fpscr = cpu_to_dump32(s, vfp_get_fpscr(env)); + + ret = f(¬e, ARM_FPREGSET_NOTE_SIZE, s); + if (ret < 0) { + return -1; + } + + return 0; +} static int arm_write_elf32_note(WriteCoreDumpFunction f, CPUARMState *env, @@ -132,13 +252,8 @@ arm_write_elf32_note(WriteCoreDumpFunction f, CPUARMState *env, struct arm_note note; int ret, i; - memset(¬e, 0, sizeof(note)); - - note.hdr.n_namesz = cpu_to_dump32(s, NOTE_NAMESZ); - note.hdr.n_descsz = cpu_to_dump32(s, sizeof(note.prstatus)); - note.hdr.n_type = cpu_to_dump32(s, NT_PRSTATUS); + arm_note_init(¬e, s, NT_PRSTATUS, sizeof(note.prstatus)); - memcpy(note.name, NOTE_NAME, NOTE_NAMESZ); note.prstatus.pr_pid = cpu_to_dump32(s, id); for (i = 0; i < 16; ++i) { @@ -146,12 +261,12 @@ arm_write_elf32_note(WriteCoreDumpFunction f, CPUARMState *env, } note.prstatus.pr_reg.regs[16] = cpu_to_dump32(s, cpsr_read(env)); - ret = f(¬e, sizeof(note), s); + ret = f(¬e, ARM_PRSTATUS_NOTE_SIZE, s); if (ret < 0) { return -1; } - return 0; + return arm_write_elf32_fpregset(f, env, id, s); } int arm_cpu_write_elf64_note(WriteCoreDumpFunction f, CPUState *cs, @@ -221,9 +336,11 @@ ssize_t cpu_get_note_size(int class, int machine, int nr_cpus) size_t note_size; if (class == ELFCLASS64) { - note_size = sizeof(struct aarch64_note); + note_size = AARCH64_PRSTATUS_NOTE_SIZE; + note_size += AARCH64_FPREGSET_NOTE_SIZE; } else { - note_size = sizeof(struct arm_note); + note_size = ARM_PRSTATUS_NOTE_SIZE; + note_size += ARM_FPREGSET_NOTE_SIZE; } return note_size * nr_cpus;