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. */
28 xsave_feature_offset (uint64_t xcr0
, int feature
)
32 if ((xcr0
& (1ULL << feature
)) == 0)
35 if (!x86_cpuid_count (0xd, feature
, nullptr, &ebx
, nullptr, nullptr))
40 /* See x86-xstate.h. */
47 if (!x86_cpuid_count (0xd, 0, nullptr, &ebx
, nullptr, nullptr))
52 /* See x86-xstate.h. */
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
);