Fix: strip --strip-debug breaks relocations
[binutils-gdb.git] / gdb / nat / x86-xstate.c
blob5ae014af4f491766ec672b80784599d79a59b983
1 /* x86 XSAVE extended state functions.
3 Copyright (C) 2022-2023 Free Software Foundation, Inc.
5 This file is part of GDB.
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
20 #include "gdbsupport/common-defs.h"
21 #include "gdbsupport/x86-xstate.h"
22 #include "nat/x86-cpuid.h"
23 #include "nat/x86-xstate.h"
25 /* Fetch the offset of a specific XSAVE extended region. */
27 static int
28 xsave_feature_offset (uint64_t xcr0, int feature)
30 uint32_t ebx;
32 if ((xcr0 & (1ULL << feature)) == 0)
33 return 0;
35 if (!x86_cpuid_count (0xd, feature, nullptr, &ebx, nullptr, nullptr))
36 return 0;
37 return ebx;
40 /* See x86-xstate.h. */
42 int
43 x86_xsave_length ()
45 uint32_t ebx;
47 if (!x86_cpuid_count (0xd, 0, nullptr, &ebx, nullptr, nullptr))
48 return 0;
49 return ebx;
52 /* See x86-xstate.h. */
54 x86_xsave_layout
55 x86_fetch_xsave_layout (uint64_t xcr0, int len)
57 x86_xsave_layout layout;
58 layout.sizeof_xsave = len;
59 layout.avx_offset = xsave_feature_offset (xcr0, X86_XSTATE_AVX_ID);
60 layout.bndregs_offset = xsave_feature_offset (xcr0, X86_XSTATE_BNDREGS_ID);
61 layout.bndcfg_offset = xsave_feature_offset (xcr0, X86_XSTATE_BNDCFG_ID);
62 layout.k_offset = xsave_feature_offset (xcr0, X86_XSTATE_K_ID);
63 layout.zmm_h_offset = xsave_feature_offset (xcr0, X86_XSTATE_ZMM_H_ID);
64 layout.zmm_offset = xsave_feature_offset (xcr0, X86_XSTATE_ZMM_ID);
65 layout.pkru_offset = xsave_feature_offset (xcr0, X86_XSTATE_PKRU_ID);
66 return layout;