GDBserver
Loading...
Searching...
No Matches
x86-xstate.c
Go to the documentation of this file.
1/* x86 XSAVE extended state functions.
2
3 Copyright (C) 2022-2023 Free Software Foundation, Inc.
4
5 This file is part of GDB.
6
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.
11
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.
16
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/>. */
19
20#include "gdbsupport/common-defs.h"
21#include "gdbsupport/x86-xstate.h"
22#include "nat/x86-cpuid.h"
23#include "nat/x86-xstate.h"
24
25/* Fetch the offset of a specific XSAVE extended region. */
26
27static int
28xsave_feature_offset (uint64_t xcr0, int feature)
29{
30 uint32_t ebx;
31
32 if ((xcr0 & (1ULL << feature)) == 0)
33 return 0;
34
35 if (!x86_cpuid_count (0xd, feature, nullptr, &ebx, nullptr, nullptr))
36 return 0;
37 return ebx;
38}
39
40/* See x86-xstate.h. */
41
42int
44{
45 uint32_t ebx;
46
47 if (!x86_cpuid_count (0xd, 0, nullptr, &ebx, nullptr, nullptr))
48 return 0;
49 return ebx;
50}
51
52/* See x86-xstate.h. */
53
54x86_xsave_layout
55x86_fetch_xsave_layout (uint64_t xcr0, int len)
56{
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;
67}
static __inline int x86_cpuid_count(unsigned int __level, unsigned int __sublevel, unsigned int *__eax, unsigned int *__ebx, unsigned int *__ecx, unsigned int *__edx)
Definition x86-cpuid.h:92
x86_xsave_layout x86_fetch_xsave_layout(uint64_t xcr0, int len)
Definition x86-xstate.c:55
static int xsave_feature_offset(uint64_t xcr0, int feature)
Definition x86-xstate.c:28
int x86_xsave_length()
Definition x86-xstate.c:43