This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: RISCV NFPREG?
- From: "Maciej W. Rozycki" <macro at wdc dot com>
- To: Jim Wilson <jimw at sifive dot com>
- Cc: Palmer Dabbelt <palmer at sifive dot com>, GNU C Library <libc-alpha at sourceware dot org>
- Date: Thu, 10 Oct 2019 15:40:36 +0100 (BST)
- Subject: Re: RISCV NFPREG?
- Ironport-sdr: gIwZHyCKL3sRPxYlUolOBvc5ZIq1z/epcTB/+82E0adKf/imezeCBanZcv0YROeu1LVpI5z9TO OHNfHywmwLhtr7Pw2DkfboJOnvHFUEBdofQoW+BHt/OPzJPEOibCYwFB5OK9OX5P7/XLhfK5vP sJ3x2kUyPot+Bn6ysUGrcHJpAzwZY1kGAF6Di3TiW4piptA+YJeRM39j1GdWjmi1f4RMtykn+d pCQzSy+Jp+rcAsvEsLreULGgJl/RCZvyWwlIZnnP73stpEPMAb0oulBuEfgS3Cf0ulxjaXWvFg Vfk=
- Ironport-sdr: ZyfU8JoO9G3tDx4AQ1RqCecXa6bxzbe47q613BDvuvySgAgTaz6bb+8MWuNdrJU5ZDcgoz3/3r iyqJUmWHuoOXe7eKmKePMVgArL5RtmfJOlmTUzFjLtsvmGZ7rbWSDRpzOSwY9NI+gMM5g79NmA 9HNK7Hcs7s8+UMnxfa+2VotHQy1oailCSk4D+KjLBeU5a9FDZ+SsTOHJLaM9LZ69KDYzOCrxc1 ZXYKcgeMmFnMNVJV3D5KbrEx0t7HynBYQ1XZPHR8K8+WsVWIriRR4ZW+IRG6l1nDMwXGfy1SfW WXadV/zN9ktCWUqK7e5eWmUg
- Ironport-sdr: wIMJDLTqh5VibzvC6raga7BxwYeBBBtigUFU0S5zXKynNocArYrxCxzuWnuQ0DjOGpzz+NvXO1 GsSZah6q0MFFMgxc9/e0R8gFRyOjfFNL3oCRNfZoPP7wkeW60/wTQudvfGk0SoECgO93lzFWLQ XTso1zEjQGUmi95Qh5GU8TmDlFIvZEiOLVATpZS+ohq11LtxsNYRWxA4x34U0oJaiGU4fyNpJI zLfM8q+B5lwlnoRZKAGH29d1VgzFpg5zIPJQaxMd+QOSQwr/NwLSE0WTmOkbXe32c+EQQBXzRg Jyg=
- References: <alpine.LFD.2.21.1910090618530.8305@redsun52.ssa.fujisawa.hgst.com> <CAFyWVaYN+nnbMY3_S1tws1sVS5RujTgNaDcDgr0vXvL551+fWw@mail.gmail.com>
- Wdcironportexception: Internal
On Wed, 9 Oct 2019, Jim Wilson wrote:
> > We have this:
> > #define ELF_NFPREG NFPREG
> > in sysdeps/unix/sysv/linux/riscv/bits/procfs.h, however NFPREG is nowhere
> > defined. This has come from your initial commit 7f33b09c65e3 ("RISC-V:
> > Linux ABI"). Do you happen to remember what the intent was here if any?
>
> I don't know the history here, but looking at an old pre-upstream copy
> of the glibc port, I see in ucontext.h
>
> /* Number of general registers. */
> #define NGREG 32
> #define NFPREG 32
>
> and
>
> /* Container for all general registers. */
> typedef greg_t gregset_t[NGREG];
>
> /* Container for all FPU registers. */
> typedef fpreg_t fpregset_t[NFPREG];
Right, this isn't exactly right.
> So it was probably dropped when fpregset was expanded to include fcsr.
> That poses a problem, because we have 32 FP regs which may be 32-bit,
> 64-bit, or 128-bit, and 1 fcsr reg which is always 32-bit, so how
> exactly do we count the number of FP regs when we have two different
> types of FP registers that may be of two different sizes? It is
> simpler to say that we don't have a fixed number of FP registers and
> not define NFPREG. That forces people to parse the fpregset
> structure, instead of trying to index into it as an array of registers
> which doesn't work. When NFPREG was dropped, they probably missed the
> use in procfs.h. I had to deal with some of these problems when I
> added the FP reg ptrace support to the linux kernel and gdb. Anyways,
> I'd suggest just removing the useless NFPREG stuff in profcs.h.
These are all good points.
Please observe however that for ELF we actually have 33 uniform FPR slots
in the NT_PRFPREG core file note, because this is how Linux regsets work,
even though the FCSR slot is only partially occupied; consequently this
also applies to PTRACE_GETREGSET/PTRACE_SETREGSET ptrace(2) requests.
Here's how the kernel definition of the regset looks like:
[REGSET_F] = {
.core_note_type = NT_PRFPREG,
.n = ELF_NFPREG,
.size = sizeof(elf_fpreg_t),
.align = sizeof(elf_fpreg_t),
.get = &riscv_fpr_get,
.set = &riscv_fpr_set,
},
and then arch/riscv/include/uapi/asm/elf.h has this:
#define ELF_NFPREG (sizeof(struct __riscv_d_ext_state) / sizeof(elf_fpreg_t))
(which amounts to 33). And given that this is a Linux's user API header
technically we have this macro as a part of the API already.
> I'm puzzled by your gdb comment though, because as far as I know the
> riscv gdb port isn't using NFPREG, and shouldn't need it. Though
> maybe you are working on the missing gdbserver support for RISC-V?
Correct; I've been cleaning up some corresponding native GDB/Linux stuff
too, which can ultimately be shared (I'll do that as a part of the patch
series).
> If
> you do readd NFPREG or __NFPREG it is probably worth adding a comment
> explaining that you can't just iterate through the fpregset as an
> array because of the different sized fcsr register.
Correct, but PTRACE_GETREGSET/PTRACE_SETREGSET requests need to have the
FPR regset size specified as `33 * flen'.
So I think we should follow Linux and either include <asm/elf.h> in
<bits/procfs.h> for the kernel-provided definition or fix our own.
Maciej