Commit | Line | Data |
---|---|---|
f49ff000 YQ |
1 | /* GNU/Linux/x86-64 specific target description, for the remote server |
2 | for GDB. | |
b811d2c2 | 3 | Copyright (C) 2017-2020 Free Software Foundation, Inc. |
f49ff000 YQ |
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 "server.h" | |
21 | #include "tdesc.h" | |
22 | #include "linux-x86-tdesc.h" | |
5f035c07 | 23 | #include "arch/i386.h" |
268a13a5 | 24 | #include "gdbsupport/x86-xstate.h" |
b4570e4b YQ |
25 | #ifdef __x86_64__ |
26 | #include "arch/amd64.h" | |
27 | #endif | |
190852c8 | 28 | #include "x86-tdesc.h" |
f49ff000 | 29 | |
b4570e4b YQ |
30 | /* Return the right x86_linux_tdesc index for a given XCR0. Return |
31 | X86_TDESC_LAST if can't find a match. */ | |
f49ff000 | 32 | |
b4570e4b YQ |
33 | static enum x86_linux_tdesc |
34 | xcr0_to_tdesc_idx (uint64_t xcr0, bool is_x32) | |
f49ff000 | 35 | { |
f49ff000 | 36 | if (xcr0 & X86_XSTATE_PKRU) |
b4570e4b YQ |
37 | { |
38 | if (is_x32) | |
39 | { | |
40 | /* No x32 MPX and PKU, fall back to avx_avx512. */ | |
41 | return X86_TDESC_AVX_AVX512; | |
42 | } | |
43 | else | |
44 | return X86_TDESC_AVX_MPX_AVX512_PKU; | |
45 | } | |
f49ff000 | 46 | else if (xcr0 & X86_XSTATE_AVX512) |
b4570e4b | 47 | return X86_TDESC_AVX_AVX512; |
f49ff000 | 48 | else if ((xcr0 & X86_XSTATE_AVX_MPX_MASK) == X86_XSTATE_AVX_MPX_MASK) |
b4570e4b YQ |
49 | { |
50 | if (is_x32) /* No MPX on x32. */ | |
51 | return X86_TDESC_AVX; | |
52 | else | |
53 | return X86_TDESC_AVX_MPX; | |
54 | } | |
f49ff000 | 55 | else if (xcr0 & X86_XSTATE_MPX) |
b4570e4b YQ |
56 | { |
57 | if (is_x32) /* No MPX on x32. */ | |
58 | return X86_TDESC_AVX; | |
59 | else | |
60 | return X86_TDESC_MPX; | |
61 | } | |
f49ff000 | 62 | else if (xcr0 & X86_XSTATE_AVX) |
b4570e4b | 63 | return X86_TDESC_AVX; |
f49ff000 | 64 | else if (xcr0 & X86_XSTATE_SSE) |
b4570e4b | 65 | return X86_TDESC_SSE; |
f49ff000 | 66 | else if (xcr0 & X86_XSTATE_X87) |
b4570e4b YQ |
67 | return X86_TDESC_MMX; |
68 | else | |
69 | return X86_TDESC_LAST; | |
70 | } | |
f49ff000 | 71 | |
b4570e4b YQ |
72 | #if defined __i386__ || !defined IN_PROCESS_AGENT |
73 | ||
b0a7723d TT |
74 | static struct target_desc *i386_tdescs[X86_TDESC_LAST] = { }; |
75 | ||
b4570e4b YQ |
76 | /* Return the target description according to XCR0. */ |
77 | ||
78 | const struct target_desc * | |
79 | i386_linux_read_description (uint64_t xcr0) | |
80 | { | |
81 | enum x86_linux_tdesc idx = xcr0_to_tdesc_idx (xcr0, false); | |
82 | ||
83 | if (idx == X86_TDESC_LAST) | |
f49ff000 YQ |
84 | return NULL; |
85 | ||
b4570e4b YQ |
86 | struct target_desc **tdesc = &i386_tdescs[idx]; |
87 | ||
f49ff000 YQ |
88 | if (*tdesc == NULL) |
89 | { | |
1163a4b7 | 90 | *tdesc = i386_create_target_description (xcr0, true, false); |
f49ff000 | 91 | |
190852c8 | 92 | init_target_desc (*tdesc, i386_expedite_regs); |
f49ff000 YQ |
93 | } |
94 | ||
95 | return *tdesc;; | |
96 | } | |
97 | #endif | |
98 | ||
b4570e4b YQ |
99 | #ifdef __x86_64__ |
100 | ||
101 | static target_desc *amd64_tdescs[X86_TDESC_LAST] = { }; | |
102 | static target_desc *x32_tdescs[X86_TDESC_LAST] = { }; | |
103 | ||
104 | const struct target_desc * | |
105 | amd64_linux_read_description (uint64_t xcr0, bool is_x32) | |
106 | { | |
107 | enum x86_linux_tdesc idx = xcr0_to_tdesc_idx (xcr0, is_x32); | |
108 | ||
109 | if (idx == X86_TDESC_LAST) | |
110 | return NULL; | |
111 | ||
112 | struct target_desc **tdesc = NULL; | |
113 | ||
114 | if (is_x32) | |
115 | tdesc = &x32_tdescs[idx]; | |
116 | else | |
117 | tdesc = &amd64_tdescs[idx]; | |
118 | ||
119 | if (*tdesc == NULL) | |
120 | { | |
c0867626 | 121 | *tdesc = amd64_create_target_description (xcr0, is_x32, true, true); |
b4570e4b | 122 | |
190852c8 | 123 | init_target_desc (*tdesc, amd64_expedite_regs); |
b4570e4b YQ |
124 | } |
125 | return *tdesc; | |
126 | } | |
127 | ||
128 | #endif | |
129 | ||
f49ff000 | 130 | #ifndef IN_PROCESS_AGENT |
b4570e4b | 131 | |
f49ff000 YQ |
132 | int |
133 | i386_get_ipa_tdesc_idx (const struct target_desc *tdesc) | |
134 | { | |
135 | for (int i = 0; i < X86_TDESC_LAST; i++) | |
136 | { | |
137 | if (tdesc == i386_tdescs[i]) | |
138 | return i; | |
139 | } | |
140 | ||
141 | /* If none tdesc is found, return the one with minimum features. */ | |
142 | return X86_TDESC_MMX; | |
143 | } | |
144 | ||
b4570e4b YQ |
145 | #if defined __x86_64__ |
146 | int | |
147 | amd64_get_ipa_tdesc_idx (const struct target_desc *tdesc) | |
148 | { | |
149 | for (int i = 0; i < X86_TDESC_LAST; i++) | |
150 | { | |
151 | if (tdesc == amd64_tdescs[i]) | |
152 | return i; | |
153 | } | |
154 | for (int i = 0; i < X86_TDESC_LAST; i++) | |
155 | { | |
156 | if (tdesc == x32_tdescs[i]) | |
157 | return i; | |
158 | } | |
159 | ||
160 | return X86_TDESC_SSE; | |
161 | } | |
162 | ||
163 | #endif | |
f49ff000 | 164 | #endif |