Path: blob/main/contrib/llvm-project/lldb/source/Plugins/Process/Utility/LinuxPTraceDefines_arm64sve.h
39642 views
//===-- LinuxPTraceDefines_arm64sve.h ------------------------- -*- C++ -*-===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//78#ifndef LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H9#define LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H1011#include <cstdint>1213namespace lldb_private {14namespace sve {1516/*17* The SVE architecture leaves space for future expansion of the18* vector length beyond its initial architectural limit of 2048 bits19* (16 quadwords).20*21* See <Linux kernel source tree>/Documentation/arm64/sve.rst for a description22* of the vl/vq terminology.23*/2425const uint16_t vq_bytes = 16; /* number of bytes per quadword */2627const uint16_t vq_min = 1;28const uint16_t vq_max = 512;2930const uint16_t vl_min = vq_min * vq_bytes;31const uint16_t vl_max = vq_max * vq_bytes;3233const uint16_t num_of_zregs = 32;34const uint16_t num_of_pregs = 16;3536inline uint16_t vl_valid(uint16_t vl) {37return (vl % vq_bytes == 0 && vl >= vl_min && vl <= vl_max);38}3940inline uint16_t vq_from_vl(uint16_t vl) { return vl / vq_bytes; }41inline uint16_t vl_from_vq(uint16_t vq) { return vq * vq_bytes; }4243/* A new signal frame record sve_context encodes the SVE Registers on signal44* delivery. sve_context struct definition may be included in asm/sigcontext.h.45* We define sve_context_size which will be used by LLDB sve helper functions.46* More information on sve_context can be found in Linux kernel source tree at47* Documentation/arm64/sve.rst.48*/4950const uint16_t sve_context_size = 16;5152/*53* If the SVE registers are currently live for the thread at signal delivery,54* sve_context.head.size >=55* SigContextSize(vq_from_vl(sve_context.vl))56* and the register data may be accessed using the Sig*() functions.57*58* If sve_context.head.size <59* SigContextSize(vq_from_vl(sve_context.vl)),60* the SVE registers were not live for the thread and no register data61* is included: in this case, the Sig*() functions should not be62* used except for this check.63*64* The same convention applies when returning from a signal: a caller65* will need to remove or resize the sve_context block if it wants to66* make the SVE registers live when they were previously non-live or67* vice-versa. This may require the caller to allocate fresh68* memory and/or move other context blocks in the signal frame.69*70* Changing the vector length during signal return is not permitted:71* sve_context.vl must equal the thread's current vector length when72* doing a sigreturn.73*74*75* Note: for all these functions, the "vq" argument denotes the SVE76* vector length in quadwords (i.e., units of 128 bits).77*78* The correct way to obtain vq is to use vq_from_vl(vl). The79* result is valid if and only if vl_valid(vl) is true. This is80* guaranteed for a struct sve_context written by the kernel.81*82*83* Additional functions describe the contents and layout of the payload.84* For each, Sig*Offset(args) is the start offset relative to85* the start of struct sve_context, and Sig*Size(args) is the86* size in bytes:87*88* x type description89* - ---- -----------90* REGS the entire SVE context91*92* ZREGS __uint128_t[num_of_zregs][vq] all Z-registers93* ZREG __uint128_t[vq] individual Z-register Zn94*95* PREGS uint16_t[num_of_pregs][vq] all P-registers96* PREG uint16_t[vq] individual P-register Pn97*98* FFR uint16_t[vq] first-fault status register99*100* Additional data might be appended in the future.101*/102103inline uint16_t SigZRegSize(uint16_t vq) { return vq * vq_bytes; }104inline uint16_t SigPRegSize(uint16_t vq) { return vq * vq_bytes / 8; }105inline uint16_t SigFFRSize(uint16_t vq) { return SigPRegSize(vq); }106107inline uint32_t SigRegsOffset() {108return (sve_context_size + vq_bytes - 1) / vq_bytes * vq_bytes;109}110111inline uint32_t SigZRegsOffset() { return SigRegsOffset(); }112113inline uint32_t SigZRegOffset(uint16_t vq, uint16_t n) {114return SigRegsOffset() + SigZRegSize(vq) * n;115}116117inline uint32_t SigZRegsSize(uint16_t vq) {118return SigZRegOffset(vq, num_of_zregs) - SigRegsOffset();119}120121inline uint32_t SigPRegsOffset(uint16_t vq) {122return SigRegsOffset() + SigZRegsSize(vq);123}124125inline uint32_t SigPRegOffset(uint16_t vq, uint16_t n) {126return SigPRegsOffset(vq) + SigPRegSize(vq) * n;127}128129inline uint32_t SigpRegsSize(uint16_t vq) {130return SigPRegOffset(vq, num_of_pregs) - SigPRegsOffset(vq);131}132133inline uint32_t SigFFROffset(uint16_t vq) {134return SigPRegsOffset(vq) + SigpRegsSize(vq);135}136137inline uint32_t SigRegsSize(uint16_t vq) {138return SigFFROffset(vq) + SigFFRSize(vq) - SigRegsOffset();139}140141inline uint32_t SVESigContextSize(uint16_t vq) {142return SigRegsOffset() + SigRegsSize(vq);143}144145struct user_sve_header {146uint32_t size; /* total meaningful regset content in bytes */147uint32_t max_size; /* maxmium possible size for this thread */148uint16_t vl; /* current vector length */149uint16_t max_vl; /* maximum possible vector length */150uint16_t flags;151uint16_t reserved;152};153154using user_za_header = user_sve_header;155156/* Definitions for user_sve_header.flags: */157const uint16_t ptrace_regs_mask = 1 << 0;158const uint16_t ptrace_regs_fpsimd = 0;159const uint16_t ptrace_regs_sve = ptrace_regs_mask;160161/*162* The remainder of the SVE state follows struct user_sve_header. The163* total size of the SVE state (including header) depends on the164* metadata in the header: PTraceSize(vq, flags) gives the total size165* of the state in bytes, including the header.166*167* Refer to <asm/sigcontext.h> for details of how to pass the correct168* "vq" argument to these macros.169*/170171/* Offset from the start of struct user_sve_header to the register data */172inline uint16_t PTraceRegsOffset() {173return (sizeof(struct user_sve_header) + vq_bytes - 1) / vq_bytes * vq_bytes;174}175176/*177* The register data content and layout depends on the value of the178* flags field.179*/180181/*182* (flags & ptrace_regs_mask) == ptrace_regs_fpsimd case:183*184* The payload starts at offset PTraceFPSIMDOffset, and is of type185* struct user_fpsimd_state. Additional data might be appended in the186* future: use PTraceFPSIMDSize(vq, flags) to compute the total size.187* PTraceFPSIMDSize(vq, flags) will never be less than188* sizeof(struct user_fpsimd_state).189*/190191const uint32_t ptrace_fpsimd_offset = PTraceRegsOffset();192193/* Return size of struct user_fpsimd_state from asm/ptrace.h */194inline uint32_t PTraceFPSIMDSize(uint16_t vq, uint16_t flags) { return 528; }195196/*197* (flags & ptrace_regs_mask) == ptrace_regs_sve case:198*199* The payload starts at offset PTraceSVEOffset, and is of size200* PTraceSVESize(vq, flags).201*202* Additional functions describe the contents and layout of the payload.203* For each, PTrace*X*Offset(args) is the start offset relative to204* the start of struct user_sve_header, and PTrace*X*Size(args) is205* the size in bytes:206*207* x type description208* - ---- -----------209* ZREGS \210* ZREG |211* PREGS | refer to <asm/sigcontext.h>212* PREG |213* FFR /214*215* FPSR uint32_t FPSR216* FPCR uint32_t FPCR217*218* Additional data might be appended in the future.219*/220221inline uint32_t PTraceZRegSize(uint16_t vq) { return SigZRegSize(vq); }222223inline uint32_t PTracePRegSize(uint16_t vq) { return SigPRegSize(vq); }224225inline uint32_t PTraceFFRSize(uint16_t vq) { return SigFFRSize(vq); }226227const uint32_t fpsr_size = sizeof(uint32_t);228const uint32_t fpcr_size = sizeof(uint32_t);229230inline uint32_t SigToPTrace(uint32_t offset) {231return offset - SigRegsOffset() + PTraceRegsOffset();232}233234const uint32_t ptrace_sve_offset = PTraceRegsOffset();235236inline uint32_t PTraceZRegsOffset(uint16_t vq) {237return SigToPTrace(SigZRegsOffset());238}239240inline uint32_t PTraceZRegOffset(uint16_t vq, uint16_t n) {241return SigToPTrace(SigZRegOffset(vq, n));242}243244inline uint32_t PTraceZRegsSize(uint16_t vq) {245return PTraceZRegOffset(vq, num_of_zregs) - SigToPTrace(SigRegsOffset());246}247248inline uint32_t PTracePRegsOffset(uint16_t vq) {249return SigToPTrace(SigPRegsOffset(vq));250}251252inline uint32_t PTracePRegOffset(uint16_t vq, uint16_t n) {253return SigToPTrace(SigPRegOffset(vq, n));254}255256inline uint32_t PTracePRegsSize(uint16_t vq) {257return PTracePRegOffset(vq, num_of_pregs) - PTracePRegsOffset(vq);258}259260inline uint32_t PTraceFFROffset(uint16_t vq) {261return SigToPTrace(SigFFROffset(vq));262}263264inline uint32_t PTraceFPSROffset(uint16_t vq) {265return (PTraceFFROffset(vq) + PTraceFFRSize(vq) + (vq_bytes - 1)) / vq_bytes *266vq_bytes;267}268269inline uint32_t PTraceFPCROffset(uint16_t vq) {270return PTraceFPSROffset(vq) + fpsr_size;271}272273/*274* Any future extension appended after FPCR must be aligned to the next275* 128-bit boundary.276*/277278inline uint32_t PTraceSVESize(uint16_t vq, uint16_t flags) {279return (PTraceFPCROffset(vq) + fpcr_size - ptrace_sve_offset + vq_bytes - 1) /280vq_bytes * vq_bytes;281}282283inline uint32_t PTraceSize(uint16_t vq, uint16_t flags) {284return (flags & ptrace_regs_mask) == ptrace_regs_sve285? ptrace_sve_offset + PTraceSVESize(vq, flags)286: ptrace_fpsimd_offset + PTraceFPSIMDSize(vq, flags);287}288289} // namespace SVE290} // namespace lldb_private291292#endif // LLDB_SOURCE_PLUGINS_PROCESS_UTILITY_LINUXPTRACEDEFINES_ARM64SVE_H293294295