]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/i386-linux-tdep.c
Generate c for feature instead of tdesc
[thirdparty/binutils-gdb.git] / gdb / i386-linux-tdep.c
CommitLineData
871fbe6a 1/* Target-dependent code for GNU/Linux i386.
ca557f44 2
61baf725 3 Copyright (C) 2000-2017 Free Software Foundation, Inc.
e7ee86a9
JB
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
a9762ec7 9 the Free Software Foundation; either version 3 of the License, or
e7ee86a9
JB
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
a9762ec7 18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
e7ee86a9
JB
19
20#include "defs.h"
21#include "gdbcore.h"
22#include "frame.h"
23#include "value.h"
4e052eda 24#include "regcache.h"
c131fcee 25#include "regset.h"
6441c4a0 26#include "inferior.h"
0670c0aa 27#include "osabi.h"
38c968cf 28#include "reggroups.h"
5cb2fe25 29#include "dwarf2-frame.h"
8201327c
MK
30#include "i386-tdep.h"
31#include "i386-linux-tdep.h"
4aa995e1 32#include "linux-tdep.h"
012b3a21 33#include "utils.h"
0670c0aa 34#include "glibc-tdep.h"
871fbe6a 35#include "solib-svr4.h"
982e9687 36#include "symtab.h"
237fc4c9 37#include "arch-utils.h"
a96d9b2e
SDJ
38#include "xml-syscall.h"
39
c131fcee 40#include "i387-tdep.h"
df7e5265 41#include "x86-xstate.h"
c131fcee 42
a96d9b2e
SDJ
43/* The syscall's XML filename for i386. */
44#define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
17ea7499 45
d02ed0bb 46#include "record-full.h"
77fcef51 47#include "linux-record.h"
90884b2b 48#include "features/i386/i386-linux.c"
3a13a53b 49#include "features/i386/i386-mmx-linux.c"
1dbcd68c 50#include "features/i386/i386-mpx-linux.c"
2b863f51 51#include "features/i386/i386-avx-mpx-linux.c"
c131fcee 52#include "features/i386/i386-avx-linux.c"
a1fa17ee 53#include "features/i386/i386-avx-avx512-linux.c"
51547df6 54#include "features/i386/i386-avx-mpx-avx512-pku-linux.c"
90884b2b 55
38c968cf
AC
56/* Return non-zero, when the register is in the corresponding register
57 group. Put the LINUX_ORIG_EAX register in the system group. */
58static int
59i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
60 struct reggroup *group)
61{
62 if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
63 return (group == system_reggroup
64 || group == save_reggroup
65 || group == restore_reggroup);
66 return i386_register_reggroup_p (gdbarch, regnum, group);
67}
68
e7ee86a9
JB
69\f
70/* Recognizing signal handler frames. */
71
ca557f44 72/* GNU/Linux has two flavors of signals. Normal signal handlers, and
e7ee86a9
JB
73 "realtime" (RT) signals. The RT signals can provide additional
74 information to the signal handler if the SA_SIGINFO flag is set
75 when establishing a signal handler using `sigaction'. It is not
ca557f44
AC
76 unlikely that future versions of GNU/Linux will support SA_SIGINFO
77 for normal signals too. */
e7ee86a9
JB
78
79/* When the i386 Linux kernel calls a signal handler and the
80 SA_RESTORER flag isn't set, the return address points to a bit of
81 code on the stack. This function returns whether the PC appears to
82 be within this bit of code.
83
84 The instruction sequence for normal signals is
85 pop %eax
acd5c798 86 mov $0x77, %eax
e7ee86a9
JB
87 int $0x80
88 or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
89
90 Checking for the code sequence should be somewhat reliable, because
91 the effect is to call the system call sigreturn. This is unlikely
911bc6ee 92 to occur anywhere other than in a signal trampoline.
e7ee86a9
JB
93
94 It kind of sucks that we have to read memory from the process in
95 order to identify a signal trampoline, but there doesn't seem to be
911bc6ee
MK
96 any other way. Therefore we only do the memory reads if no
97 function name could be identified, which should be the case since
98 the code is on the stack.
e7ee86a9
JB
99
100 Detection of signal trampolines for handlers that set the
101 SA_RESTORER flag is in general not possible. Unfortunately this is
102 what the GNU C Library has been doing for quite some time now.
103 However, as of version 2.1.2, the GNU C Library uses signal
104 trampolines (named __restore and __restore_rt) that are identical
105 to the ones used by the kernel. Therefore, these trampolines are
106 supported too. */
107
acd5c798
MK
108#define LINUX_SIGTRAMP_INSN0 0x58 /* pop %eax */
109#define LINUX_SIGTRAMP_OFFSET0 0
110#define LINUX_SIGTRAMP_INSN1 0xb8 /* mov $NNNN, %eax */
111#define LINUX_SIGTRAMP_OFFSET1 1
112#define LINUX_SIGTRAMP_INSN2 0xcd /* int */
113#define LINUX_SIGTRAMP_OFFSET2 6
e7ee86a9 114
4252dc94 115static const gdb_byte linux_sigtramp_code[] =
e7ee86a9
JB
116{
117 LINUX_SIGTRAMP_INSN0, /* pop %eax */
acd5c798 118 LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00, /* mov $0x77, %eax */
e7ee86a9
JB
119 LINUX_SIGTRAMP_INSN2, 0x80 /* int $0x80 */
120};
121
122#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
123
10458914
DJ
124/* If THIS_FRAME is a sigtramp routine, return the address of the
125 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
126
127static CORE_ADDR
10458914 128i386_linux_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 129{
10458914 130 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 131 gdb_byte buf[LINUX_SIGTRAMP_LEN];
e7ee86a9
JB
132
133 /* We only recognize a signal trampoline if PC is at the start of
134 one of the three instructions. We optimize for finding the PC at
135 the start, as will be the case when the trampoline is not the
136 first frame on the stack. We assume that in the case where the
137 PC is not at the start of the instruction sequence, there will be
138 a few trailing readable bytes on the stack. */
139
10458914 140 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
141 return 0;
142
143 if (buf[0] != LINUX_SIGTRAMP_INSN0)
144 {
145 int adjust;
146
147 switch (buf[0])
148 {
149 case LINUX_SIGTRAMP_INSN1:
150 adjust = LINUX_SIGTRAMP_OFFSET1;
151 break;
152 case LINUX_SIGTRAMP_INSN2:
153 adjust = LINUX_SIGTRAMP_OFFSET2;
154 break;
155 default:
156 return 0;
157 }
158
159 pc -= adjust;
160
10458914 161 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
e7ee86a9
JB
162 return 0;
163 }
164
165 if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
166 return 0;
167
168 return pc;
169}
170
171/* This function does the same for RT signals. Here the instruction
172 sequence is
acd5c798 173 mov $0xad, %eax
e7ee86a9
JB
174 int $0x80
175 or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
176
177 The effect is to call the system call rt_sigreturn. */
178
acd5c798
MK
179#define LINUX_RT_SIGTRAMP_INSN0 0xb8 /* mov $NNNN, %eax */
180#define LINUX_RT_SIGTRAMP_OFFSET0 0
181#define LINUX_RT_SIGTRAMP_INSN1 0xcd /* int */
182#define LINUX_RT_SIGTRAMP_OFFSET1 5
e7ee86a9 183
4252dc94 184static const gdb_byte linux_rt_sigtramp_code[] =
e7ee86a9 185{
acd5c798 186 LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00, /* mov $0xad, %eax */
e7ee86a9
JB
187 LINUX_RT_SIGTRAMP_INSN1, 0x80 /* int $0x80 */
188};
189
190#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
191
10458914
DJ
192/* If THIS_FRAME is an RT sigtramp routine, return the address of the
193 start of the routine. Otherwise, return 0. */
e7ee86a9
JB
194
195static CORE_ADDR
10458914 196i386_linux_rt_sigtramp_start (struct frame_info *this_frame)
e7ee86a9 197{
10458914 198 CORE_ADDR pc = get_frame_pc (this_frame);
4252dc94 199 gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
e7ee86a9
JB
200
201 /* We only recognize a signal trampoline if PC is at the start of
202 one of the two instructions. We optimize for finding the PC at
203 the start, as will be the case when the trampoline is not the
204 first frame on the stack. We assume that in the case where the
205 PC is not at the start of the instruction sequence, there will be
206 a few trailing readable bytes on the stack. */
207
10458914 208 if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
209 return 0;
210
211 if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
212 {
213 if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
214 return 0;
215
216 pc -= LINUX_RT_SIGTRAMP_OFFSET1;
217
10458914 218 if (!safe_frame_unwind_memory (this_frame, pc, buf,
8e6bed05 219 LINUX_RT_SIGTRAMP_LEN))
e7ee86a9
JB
220 return 0;
221 }
222
223 if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
224 return 0;
225
226 return pc;
227}
228
10458914
DJ
229/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
230 routine. */
e7ee86a9 231
8201327c 232static int
10458914 233i386_linux_sigtramp_p (struct frame_info *this_frame)
e7ee86a9 234{
10458914 235 CORE_ADDR pc = get_frame_pc (this_frame);
2c02bd72 236 const char *name;
911bc6ee
MK
237
238 find_pc_partial_function (pc, &name, NULL, NULL);
239
ef17e74b
DJ
240 /* If we have NAME, we can optimize the search. The trampolines are
241 named __restore and __restore_rt. However, they aren't dynamically
242 exported from the shared C library, so the trampoline may appear to
243 be part of the preceding function. This should always be sigaction,
244 __sigaction, or __libc_sigaction (all aliases to the same function). */
245 if (name == NULL || strstr (name, "sigaction") != NULL)
10458914
DJ
246 return (i386_linux_sigtramp_start (this_frame) != 0
247 || i386_linux_rt_sigtramp_start (this_frame) != 0);
ef17e74b
DJ
248
249 return (strcmp ("__restore", name) == 0
250 || strcmp ("__restore_rt", name) == 0);
e7ee86a9
JB
251}
252
4a4e5149
DJ
253/* Return one if the PC of THIS_FRAME is in a signal trampoline which
254 may have DWARF-2 CFI. */
12b8a2cb
DJ
255
256static int
257i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
4a4e5149 258 struct frame_info *this_frame)
12b8a2cb 259{
4a4e5149 260 CORE_ADDR pc = get_frame_pc (this_frame);
2c02bd72 261 const char *name;
12b8a2cb
DJ
262
263 find_pc_partial_function (pc, &name, NULL, NULL);
264
265 /* If a vsyscall DSO is in use, the signal trampolines may have these
266 names. */
267 if (name && (strcmp (name, "__kernel_sigreturn") == 0
268 || strcmp (name, "__kernel_rt_sigreturn") == 0))
269 return 1;
270
271 return 0;
272}
273
acd5c798
MK
274/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>. */
275#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
276
10458914
DJ
277/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
278 address of the associated sigcontext structure. */
e7ee86a9 279
b7d15bf7 280static CORE_ADDR
10458914 281i386_linux_sigcontext_addr (struct frame_info *this_frame)
e7ee86a9 282{
e17a4113
UW
283 struct gdbarch *gdbarch = get_frame_arch (this_frame);
284 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
e7ee86a9 285 CORE_ADDR pc;
acd5c798 286 CORE_ADDR sp;
4252dc94 287 gdb_byte buf[4];
acd5c798 288
10458914 289 get_frame_register (this_frame, I386_ESP_REGNUM, buf);
e17a4113 290 sp = extract_unsigned_integer (buf, 4, byte_order);
e7ee86a9 291
10458914 292 pc = i386_linux_sigtramp_start (this_frame);
e7ee86a9
JB
293 if (pc)
294 {
acd5c798
MK
295 /* The sigcontext structure lives on the stack, right after
296 the signum argument. We determine the address of the
297 sigcontext structure by looking at the frame's stack
298 pointer. Keep in mind that the first instruction of the
299 sigtramp code is "pop %eax". If the PC is after this
300 instruction, adjust the returned value accordingly. */
10458914 301 if (pc == get_frame_pc (this_frame))
e7ee86a9
JB
302 return sp + 4;
303 return sp;
304 }
305
10458914 306 pc = i386_linux_rt_sigtramp_start (this_frame);
e7ee86a9
JB
307 if (pc)
308 {
acd5c798
MK
309 CORE_ADDR ucontext_addr;
310
311 /* The sigcontext structure is part of the user context. A
312 pointer to the user context is passed as the third argument
313 to the signal handler. */
314 read_memory (sp + 8, buf, 4);
e17a4113 315 ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
acd5c798 316 return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
e7ee86a9
JB
317 }
318
8a3fe4f8 319 error (_("Couldn't recognize signal trampoline."));
e7ee86a9
JB
320 return 0;
321}
322
6441c4a0
MK
323/* Set the program counter for process PTID to PC. */
324
8201327c 325static void
61a1198a 326i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
6441c4a0 327{
61a1198a 328 regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc);
6441c4a0
MK
329
330 /* We must be careful with modifying the program counter. If we
331 just interrupted a system call, the kernel might try to restart
332 it when we resume the inferior. On restarting the system call,
333 the kernel will try backing up the program counter even though it
334 no longer points at the system call. This typically results in a
335 SIGSEGV or SIGILL. We can prevent this by writing `-1' in the
336 "orig_eax" pseudo-register.
337
338 Note that "orig_eax" is saved when setting up a dummy call frame.
339 This means that it is properly restored when that frame is
340 popped, and that the interrupted system call will be restarted
341 when we resume the inferior on return from a function call from
342 within GDB. In all other cases the system call will not be
343 restarted. */
61a1198a 344 regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
6441c4a0 345}
77fcef51 346
8a2e0e28
HZ
347/* Record all registers but IP register for process-record. */
348
349static int
350i386_all_but_ip_registers_record (struct regcache *regcache)
351{
25ea693b 352 if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM))
8a2e0e28 353 return -1;
25ea693b 354 if (record_full_arch_list_add_reg (regcache, I386_ECX_REGNUM))
8a2e0e28 355 return -1;
25ea693b 356 if (record_full_arch_list_add_reg (regcache, I386_EDX_REGNUM))
8a2e0e28 357 return -1;
25ea693b 358 if (record_full_arch_list_add_reg (regcache, I386_EBX_REGNUM))
8a2e0e28 359 return -1;
25ea693b 360 if (record_full_arch_list_add_reg (regcache, I386_ESP_REGNUM))
8a2e0e28 361 return -1;
25ea693b 362 if (record_full_arch_list_add_reg (regcache, I386_EBP_REGNUM))
8a2e0e28 363 return -1;
25ea693b 364 if (record_full_arch_list_add_reg (regcache, I386_ESI_REGNUM))
8a2e0e28 365 return -1;
25ea693b 366 if (record_full_arch_list_add_reg (regcache, I386_EDI_REGNUM))
8a2e0e28 367 return -1;
25ea693b 368 if (record_full_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
8a2e0e28
HZ
369 return -1;
370
371 return 0;
372}
13b6d1d4
MS
373
374/* i386_canonicalize_syscall maps from the native i386 Linux set
375 of syscall ids into a canonical set of syscall ids used by
376 process record (a mostly trivial mapping, since the canonical
377 set was originally taken from the i386 set). */
378
379static enum gdb_syscall
380i386_canonicalize_syscall (int syscall)
381{
382 enum { i386_syscall_max = 499 };
383
384 if (syscall <= i386_syscall_max)
aead7601 385 return (enum gdb_syscall) syscall;
13b6d1d4 386 else
f486487f 387 return gdb_sys_no_syscall;
13b6d1d4
MS
388}
389
012b3a21
WT
390/* Value of the sigcode in case of a boundary fault. */
391
392#define SIG_CODE_BONDARY_FAULT 3
393
394/* i386 GNU/Linux implementation of the handle_segmentation_fault
395 gdbarch hook. Displays information related to MPX bound
396 violations. */
397void
398i386_linux_handle_segmentation_fault (struct gdbarch *gdbarch,
399 struct ui_out *uiout)
400{
166616ce
SM
401 /* -Wmaybe-uninitialized */
402 CORE_ADDR lower_bound = 0, upper_bound = 0, access = 0;
012b3a21
WT
403 int is_upper;
404 long sig_code = 0;
405
406 if (!i386_mpx_enabled ())
407 return;
408
409 TRY
410 {
411 /* Sigcode evaluates if the actual segfault is a boundary violation. */
412 sig_code = parse_and_eval_long ("$_siginfo.si_code\n");
413
414 lower_bound
415 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._lower");
416 upper_bound
417 = parse_and_eval_long ("$_siginfo._sifields._sigfault._addr_bnd._upper");
418 access
419 = parse_and_eval_long ("$_siginfo._sifields._sigfault.si_addr");
420 }
421 CATCH (exception, RETURN_MASK_ALL)
422 {
423 return;
424 }
425 END_CATCH
426
427 /* If this is not a boundary violation just return. */
428 if (sig_code != SIG_CODE_BONDARY_FAULT)
429 return;
430
431 is_upper = (access > upper_bound ? 1 : 0);
432
112e8700 433 uiout->text ("\n");
012b3a21 434 if (is_upper)
112e8700 435 uiout->field_string ("sigcode-meaning", _("Upper bound violation"));
012b3a21 436 else
112e8700 437 uiout->field_string ("sigcode-meaning", _("Lower bound violation"));
012b3a21 438
112e8700
SM
439 uiout->text (_(" while accessing address "));
440 uiout->field_fmt ("bound-access", "%s", paddress (gdbarch, access));
012b3a21 441
112e8700
SM
442 uiout->text (_("\nBounds: [lower = "));
443 uiout->field_fmt ("lower-bound", "%s", paddress (gdbarch, lower_bound));
012b3a21 444
112e8700
SM
445 uiout->text (_(", upper = "));
446 uiout->field_fmt ("upper-bound", "%s", paddress (gdbarch, upper_bound));
012b3a21 447
112e8700 448 uiout->text (_("]"));
012b3a21
WT
449}
450
77fcef51
HZ
451/* Parse the arguments of current system call instruction and record
452 the values of the registers and memory that will be changed into
453 "record_arch_list". This instruction is "int 0x80" (Linux
454 Kernel2.4) or "sysenter" (Linux Kernel 2.6).
455
456 Return -1 if something wrong. */
457
8a2e0e28
HZ
458static struct linux_record_tdep i386_linux_record_tdep;
459
77fcef51 460static int
ffdf6de5 461i386_linux_intx80_sysenter_syscall_record (struct regcache *regcache)
77fcef51
HZ
462{
463 int ret;
13b6d1d4
MS
464 LONGEST syscall_native;
465 enum gdb_syscall syscall_gdb;
466
467 regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
77fcef51 468
13b6d1d4 469 syscall_gdb = i386_canonicalize_syscall (syscall_native);
2c543fc4 470
13b6d1d4 471 if (syscall_gdb < 0)
2c543fc4
HZ
472 {
473 printf_unfiltered (_("Process record and replay target doesn't "
13b6d1d4
MS
474 "support syscall number %s\n"),
475 plongest (syscall_native));
2c543fc4
HZ
476 return -1;
477 }
77fcef51 478
8a2e0e28
HZ
479 if (syscall_gdb == gdb_sys_sigreturn
480 || syscall_gdb == gdb_sys_rt_sigreturn)
481 {
482 if (i386_all_but_ip_registers_record (regcache))
483 return -1;
484 return 0;
485 }
486
13b6d1d4 487 ret = record_linux_system_call (syscall_gdb, regcache,
77fcef51
HZ
488 &i386_linux_record_tdep);
489 if (ret)
490 return ret;
491
492 /* Record the return value of the system call. */
25ea693b 493 if (record_full_arch_list_add_reg (regcache, I386_EAX_REGNUM))
77fcef51
HZ
494 return -1;
495
496 return 0;
497}
8a2e0e28
HZ
498
499#define I386_LINUX_xstate 270
500#define I386_LINUX_frame_size 732
501
70221824 502static int
8a2e0e28
HZ
503i386_linux_record_signal (struct gdbarch *gdbarch,
504 struct regcache *regcache,
2ea28649 505 enum gdb_signal signal)
8a2e0e28
HZ
506{
507 ULONGEST esp;
508
509 if (i386_all_but_ip_registers_record (regcache))
510 return -1;
511
25ea693b 512 if (record_full_arch_list_add_reg (regcache, I386_EIP_REGNUM))
8a2e0e28
HZ
513 return -1;
514
515 /* Record the change in the stack. */
516 regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
517 /* This is for xstate.
518 sp -= sizeof (struct _fpstate); */
519 esp -= I386_LINUX_xstate;
520 /* This is for frame_size.
521 sp -= sizeof (struct rt_sigframe); */
522 esp -= I386_LINUX_frame_size;
25ea693b
MM
523 if (record_full_arch_list_add_mem (esp,
524 I386_LINUX_xstate + I386_LINUX_frame_size))
8a2e0e28
HZ
525 return -1;
526
25ea693b 527 if (record_full_arch_list_add_end ())
8a2e0e28
HZ
528 return -1;
529
530 return 0;
531}
6441c4a0 532\f
8201327c 533
9a7f938f
JK
534/* Core of the implementation for gdbarch get_syscall_number. Get pending
535 syscall number from REGCACHE. If there is no pending syscall -1 will be
536 returned. Pending syscall means ptrace has stepped into the syscall but
537 another ptrace call will step out. PC is right after the int $0x80
538 / syscall / sysenter instruction in both cases, PC does not change during
539 the second ptrace step. */
540
a96d9b2e 541static LONGEST
9a7f938f 542i386_linux_get_syscall_number_from_regcache (struct regcache *regcache)
a96d9b2e 543{
9a7f938f 544 struct gdbarch *gdbarch = get_regcache_arch (regcache);
a96d9b2e
SDJ
545 enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
546 /* The content of a register. */
547 gdb_byte buf[4];
548 /* The result. */
549 LONGEST ret;
550
551 /* Getting the system call number from the register.
552 When dealing with x86 architecture, this information
553 is stored at %eax register. */
554 regcache_cooked_read (regcache, I386_LINUX_ORIG_EAX_REGNUM, buf);
555
556 ret = extract_signed_integer (buf, 4, byte_order);
557
558 return ret;
559}
560
9a7f938f
JK
561/* Wrapper for i386_linux_get_syscall_number_from_regcache to make it
562 compatible with gdbarch get_syscall_number method prototype. */
563
564static LONGEST
565i386_linux_get_syscall_number (struct gdbarch *gdbarch,
566 ptid_t ptid)
567{
568 struct regcache *regcache = get_thread_regcache (ptid);
569
570 return i386_linux_get_syscall_number_from_regcache (regcache);
571}
572
e9f1aad5
MK
573/* The register sets used in GNU/Linux ELF core-dumps are identical to
574 the register sets in `struct user' that are used for a.out
575 core-dumps. These are also used by ptrace(2). The corresponding
576 types are `elf_gregset_t' for the general-purpose registers (with
577 `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
578 for the floating-point registers.
579
580 Those types used to be available under the names `gregset_t' and
581 `fpregset_t' too, and GDB used those names in the past. But those
582 names are now used for the register sets used in the `mcontext_t'
583 type, which have a different size and layout. */
584
585/* Mapping between the general-purpose registers in `struct user'
586 format and GDB's register cache layout. */
587
588/* From <sys/reg.h>. */
be0d2954 589int i386_linux_gregset_reg_offset[] =
e9f1aad5
MK
590{
591 6 * 4, /* %eax */
592 1 * 4, /* %ecx */
593 2 * 4, /* %edx */
594 0 * 4, /* %ebx */
595 15 * 4, /* %esp */
596 5 * 4, /* %ebp */
597 3 * 4, /* %esi */
598 4 * 4, /* %edi */
599 12 * 4, /* %eip */
600 14 * 4, /* %eflags */
601 13 * 4, /* %cs */
602 16 * 4, /* %ss */
603 7 * 4, /* %ds */
604 8 * 4, /* %es */
605 9 * 4, /* %fs */
606 10 * 4, /* %gs */
607 -1, -1, -1, -1, -1, -1, -1, -1,
608 -1, -1, -1, -1, -1, -1, -1, -1,
609 -1, -1, -1, -1, -1, -1, -1, -1,
610 -1,
c131fcee 611 -1, -1, -1, -1, -1, -1, -1, -1,
01f9f808
MS
612 -1, -1, -1, -1, /* MPX registers BND0 ... BND3. */
613 -1, -1, /* MPX registers BNDCFGU, BNDSTATUS. */
614 -1, -1, -1, -1, -1, -1, -1, -1, /* k0 ... k7 (AVX512) */
615 -1, -1, -1, -1, -1, -1, -1, -1, /* zmm0 ... zmm7 (AVX512) */
51547df6 616 -1, /* PKRU register */
01f9f808 617 11 * 4, /* "orig_eax" */
e9f1aad5
MK
618};
619
620/* Mapping between the general-purpose registers in `struct
621 sigcontext' format and GDB's register cache layout. */
622
a3386186 623/* From <asm/sigcontext.h>. */
bb489b3c 624static int i386_linux_sc_reg_offset[] =
a3386186
MK
625{
626 11 * 4, /* %eax */
627 10 * 4, /* %ecx */
628 9 * 4, /* %edx */
629 8 * 4, /* %ebx */
630 7 * 4, /* %esp */
631 6 * 4, /* %ebp */
632 5 * 4, /* %esi */
633 4 * 4, /* %edi */
634 14 * 4, /* %eip */
635 16 * 4, /* %eflags */
636 15 * 4, /* %cs */
637 18 * 4, /* %ss */
638 3 * 4, /* %ds */
639 2 * 4, /* %es */
640 1 * 4, /* %fs */
641 0 * 4 /* %gs */
642};
643
c131fcee
L
644/* Get XSAVE extended state xcr0 from core dump. */
645
646uint64_t
6df81a63 647i386_linux_core_read_xcr0 (bfd *abfd)
c131fcee
L
648{
649 asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
650 uint64_t xcr0;
651
652 if (xstate)
653 {
654 size_t size = bfd_section_size (abfd, xstate);
655
656 /* Check extended state size. */
df7e5265
GB
657 if (size < X86_XSTATE_AVX_SIZE)
658 xcr0 = X86_XSTATE_SSE_MASK;
c131fcee
L
659 else
660 {
661 char contents[8];
662
663 if (! bfd_get_section_contents (abfd, xstate, contents,
664 I386_LINUX_XSAVE_XCR0_OFFSET,
665 8))
666 {
1777feb0
MS
667 warning (_("Couldn't read `xcr0' bytes from "
668 "`.reg-xstate' section in core file."));
c131fcee
L
669 return 0;
670 }
671
672 xcr0 = bfd_get_64 (abfd, contents);
673 }
674 }
675 else
f335d1b3 676 xcr0 = 0;
c131fcee
L
677
678 return xcr0;
679}
680
35b4818d 681/* See i386-linux-tdep.h. */
90884b2b 682
35b4818d
YQ
683const struct target_desc *
684i386_linux_read_description (uint64_t xcr0)
90884b2b 685{
df7e5265 686 switch ((xcr0 & X86_XSTATE_ALL_MASK))
f335d1b3 687 {
51547df6
MS
688 case X86_XSTATE_AVX_MPX_AVX512_PKU_MASK:
689 return tdesc_i386_avx_mpx_avx512_pku_linux;
a1fa17ee
MS
690 case X86_XSTATE_AVX_AVX512_MASK:
691 return tdesc_i386_avx_avx512_linux;
df7e5265 692 case X86_XSTATE_MPX_MASK:
1dbcd68c 693 return tdesc_i386_mpx_linux;
2b863f51
WT
694 case X86_XSTATE_AVX_MPX_MASK:
695 return tdesc_i386_avx_mpx_linux;
df7e5265 696 case X86_XSTATE_AVX_MASK:
f335d1b3 697 return tdesc_i386_avx_linux;
df7e5265 698 case X86_XSTATE_SSE_MASK:
f335d1b3 699 return tdesc_i386_linux;
df7e5265 700 case X86_XSTATE_X87_MASK:
f335d1b3
L
701 return tdesc_i386_mmx_linux;
702 default:
703 break;
704 }
705
35b4818d
YQ
706 return NULL;
707}
708
709/* Get Linux/x86 target description from core dump. */
710
711static const struct target_desc *
712i386_linux_core_read_description (struct gdbarch *gdbarch,
713 struct target_ops *target,
714 bfd *abfd)
715{
716 /* Linux/i386. */
717 uint64_t xcr0 = i386_linux_core_read_xcr0 (abfd);
718 const struct target_desc *tdesc = i386_linux_read_description (xcr0);
719
720 if (tdesc != NULL)
721 return tdesc;
722
f335d1b3 723 if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
35b4818d 724 return i386_linux_read_description (X86_XSTATE_SSE_MASK);
f335d1b3 725 else
35b4818d 726 return i386_linux_read_description (X86_XSTATE_X87_MASK);
90884b2b
L
727}
728
8f0435f7
AA
729/* Similar to i386_supply_fpregset, but use XSAVE extended state. */
730
731static void
732i386_linux_supply_xstateregset (const struct regset *regset,
733 struct regcache *regcache, int regnum,
734 const void *xstateregs, size_t len)
735{
736 i387_supply_xsave (regcache, regnum, xstateregs);
737}
738
190b495d
WT
739struct type *
740x86_linux_get_siginfo_type (struct gdbarch *gdbarch)
741{
742 return linux_get_siginfo_type_with_fields (gdbarch, LINUX_SIGINFO_FIELD_ADDR_BND);
743}
744
8f0435f7
AA
745/* Similar to i386_collect_fpregset, but use XSAVE extended state. */
746
747static void
748i386_linux_collect_xstateregset (const struct regset *regset,
749 const struct regcache *regcache,
750 int regnum, void *xstateregs, size_t len)
751{
752 i387_collect_xsave (regcache, regnum, xstateregs, 1);
753}
754
755/* Register set definitions. */
756
757static const struct regset i386_linux_xstateregset =
758 {
759 NULL,
760 i386_linux_supply_xstateregset,
761 i386_linux_collect_xstateregset
762 };
763
5aa82d05
AA
764/* Iterate over core file register note sections. */
765
766static void
767i386_linux_iterate_over_regset_sections (struct gdbarch *gdbarch,
768 iterate_over_regset_sections_cb *cb,
769 void *cb_data,
770 const struct regcache *regcache)
771{
772 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
773
8f0435f7 774 cb (".reg", 68, &i386_gregset, NULL, cb_data);
5aa82d05
AA
775
776 if (tdep->xcr0 & X86_XSTATE_AVX)
dde9acd6 777 cb (".reg-xstate", X86_XSTATE_SIZE (tdep->xcr0),
8f0435f7 778 &i386_linux_xstateregset, "XSAVE extended state", cb_data);
5aa82d05 779 else if (tdep->xcr0 & X86_XSTATE_SSE)
8f0435f7
AA
780 cb (".reg-xfp", 512, &i386_fpregset, "extended floating-point",
781 cb_data);
5aa82d05 782 else
8f0435f7 783 cb (".reg2", 108, &i386_fpregset, NULL, cb_data);
5aa82d05
AA
784}
785
9a7f938f
JK
786/* Linux kernel shows PC value after the 'int $0x80' instruction even if
787 inferior is still inside the syscall. On next PTRACE_SINGLESTEP it will
788 finish the syscall but PC will not change.
789
790 Some vDSOs contain 'int $0x80; ret' and during stepping out of the syscall
791 i386_displaced_step_fixup would keep PC at the displaced pad location.
792 As PC is pointing to the 'ret' instruction before the step
793 i386_displaced_step_fixup would expect inferior has just executed that 'ret'
794 and PC should not be adjusted. In reality it finished syscall instead and
795 PC should get relocated back to its vDSO address. Hide the 'ret'
796 instruction by 'nop' so that i386_displaced_step_fixup is not confused.
797
798 It is not fully correct as the bytes in struct displaced_step_closure will
799 not match the inferior code. But we would need some new flag in
800 displaced_step_closure otherwise to keep the state that syscall is finishing
801 for the later i386_displaced_step_fixup execution as the syscall execution
802 is already no longer detectable there. The new flag field would mean
803 i386-linux-tdep.c needs to wrap all the displacement methods of i386-tdep.c
804 which does not seem worth it. The same effect is achieved by patching that
805 'nop' instruction there instead. */
806
693be288 807static struct displaced_step_closure *
9a7f938f
JK
808i386_linux_displaced_step_copy_insn (struct gdbarch *gdbarch,
809 CORE_ADDR from, CORE_ADDR to,
810 struct regcache *regs)
811{
812 struct displaced_step_closure *closure;
813
814 closure = i386_displaced_step_copy_insn (gdbarch, from, to, regs);
815
816 if (i386_linux_get_syscall_number_from_regcache (regs) != -1)
817 {
818 /* Since we use simple_displaced_step_copy_insn, our closure is a
819 copy of the instruction. */
820 gdb_byte *insn = (gdb_byte *) closure;
821
822 /* Fake nop. */
823 insn[0] = 0x90;
824 }
825
826 return closure;
827}
828
8201327c
MK
829static void
830i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
831{
832 struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
90884b2b 833 const struct target_desc *tdesc = info.target_desc;
9a3c8263
SM
834 struct tdesc_arch_data *tdesc_data
835 = (struct tdesc_arch_data *) info.tdep_info;
90884b2b
L
836 const struct tdesc_feature *feature;
837 int valid_p;
838
839 gdb_assert (tdesc_data);
8201327c 840
a5ee0f0c
PA
841 linux_init_abi (info, gdbarch);
842
8201327c
MK
843 /* GNU/Linux uses ELF. */
844 i386_elf_init_abi (info, gdbarch);
845
90884b2b
L
846 /* Reserve a number for orig_eax. */
847 set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
848
849 if (! tdesc_has_registers (tdesc))
35b4818d 850 tdesc = i386_linux_read_description (X86_XSTATE_SSE_MASK);
90884b2b
L
851 tdep->tdesc = tdesc;
852
853 feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
854 if (feature == NULL)
855 return;
8201327c 856
90884b2b
L
857 valid_p = tdesc_numbered_register (feature, tdesc_data,
858 I386_LINUX_ORIG_EAX_REGNUM,
859 "orig_eax");
860 if (!valid_p)
861 return;
862
863 /* Add the %orig_eax register used for syscall restarting. */
8201327c 864 set_gdbarch_write_pc (gdbarch, i386_linux_write_pc);
90884b2b
L
865
866 tdep->register_reggroup_p = i386_linux_register_reggroup_p;
8201327c 867
e9f1aad5
MK
868 tdep->gregset_reg_offset = i386_linux_gregset_reg_offset;
869 tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
870 tdep->sizeof_gregset = 17 * 4;
871
8201327c
MK
872 tdep->jb_pc_offset = 20; /* From <bits/setjmp.h>. */
873
911bc6ee 874 tdep->sigtramp_p = i386_linux_sigtramp_p;
b7d15bf7 875 tdep->sigcontext_addr = i386_linux_sigcontext_addr;
a3386186 876 tdep->sc_reg_offset = i386_linux_sc_reg_offset;
bb489b3c 877 tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
8201327c 878
c131fcee
L
879 tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
880
a6b808b4 881 set_gdbarch_process_record (gdbarch, i386_process_record);
8a2e0e28 882 set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
a6b808b4 883
77fcef51 884 /* Initialize the i386_linux_record_tdep. */
5e31abdf
HZ
885 /* These values are the size of the type that will be used in a system
886 call. They are obtained from Linux Kernel source. */
2c543fc4
HZ
887 i386_linux_record_tdep.size_pointer
888 = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
889 i386_linux_record_tdep.size__old_kernel_stat = 32;
890 i386_linux_record_tdep.size_tms = 16;
891 i386_linux_record_tdep.size_loff_t = 8;
892 i386_linux_record_tdep.size_flock = 16;
893 i386_linux_record_tdep.size_oldold_utsname = 45;
894 i386_linux_record_tdep.size_ustat = 20;
7571f7f2
MK
895 i386_linux_record_tdep.size_old_sigaction = 16;
896 i386_linux_record_tdep.size_old_sigset_t = 4;
5e31abdf
HZ
897 i386_linux_record_tdep.size_rlimit = 8;
898 i386_linux_record_tdep.size_rusage = 72;
899 i386_linux_record_tdep.size_timeval = 8;
900 i386_linux_record_tdep.size_timezone = 8;
901 i386_linux_record_tdep.size_old_gid_t = 2;
902 i386_linux_record_tdep.size_old_uid_t = 2;
903 i386_linux_record_tdep.size_fd_set = 128;
72aded86 904 i386_linux_record_tdep.size_old_dirent = 268;
5e31abdf
HZ
905 i386_linux_record_tdep.size_statfs = 64;
906 i386_linux_record_tdep.size_statfs64 = 84;
907 i386_linux_record_tdep.size_sockaddr = 16;
2c543fc4
HZ
908 i386_linux_record_tdep.size_int
909 = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
910 i386_linux_record_tdep.size_long
911 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
912 i386_linux_record_tdep.size_ulong
913 = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
5e31abdf
HZ
914 i386_linux_record_tdep.size_msghdr = 28;
915 i386_linux_record_tdep.size_itimerval = 16;
916 i386_linux_record_tdep.size_stat = 88;
917 i386_linux_record_tdep.size_old_utsname = 325;
918 i386_linux_record_tdep.size_sysinfo = 64;
919 i386_linux_record_tdep.size_msqid_ds = 88;
920 i386_linux_record_tdep.size_shmid_ds = 84;
921 i386_linux_record_tdep.size_new_utsname = 390;
922 i386_linux_record_tdep.size_timex = 128;
923 i386_linux_record_tdep.size_mem_dqinfo = 24;
924 i386_linux_record_tdep.size_if_dqblk = 68;
925 i386_linux_record_tdep.size_fs_quota_stat = 68;
926 i386_linux_record_tdep.size_timespec = 8;
927 i386_linux_record_tdep.size_pollfd = 8;
928 i386_linux_record_tdep.size_NFS_FHSIZE = 32;
929 i386_linux_record_tdep.size_knfsd_fh = 132;
930 i386_linux_record_tdep.size_TASK_COMM_LEN = 16;
7571f7f2 931 i386_linux_record_tdep.size_sigaction = 20;
5e31abdf
HZ
932 i386_linux_record_tdep.size_sigset_t = 8;
933 i386_linux_record_tdep.size_siginfo_t = 128;
934 i386_linux_record_tdep.size_cap_user_data_t = 12;
935 i386_linux_record_tdep.size_stack_t = 12;
936 i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long;
937 i386_linux_record_tdep.size_stat64 = 96;
d625f9a9
MK
938 i386_linux_record_tdep.size_gid_t = 4;
939 i386_linux_record_tdep.size_uid_t = 4;
5e31abdf
HZ
940 i386_linux_record_tdep.size_PAGE_SIZE = 4096;
941 i386_linux_record_tdep.size_flock64 = 24;
942 i386_linux_record_tdep.size_user_desc = 16;
943 i386_linux_record_tdep.size_io_event = 32;
944 i386_linux_record_tdep.size_iocb = 64;
945 i386_linux_record_tdep.size_epoll_event = 12;
2c543fc4
HZ
946 i386_linux_record_tdep.size_itimerspec
947 = i386_linux_record_tdep.size_timespec * 2;
5e31abdf 948 i386_linux_record_tdep.size_mq_attr = 32;
5e31abdf
HZ
949 i386_linux_record_tdep.size_termios = 36;
950 i386_linux_record_tdep.size_termios2 = 44;
951 i386_linux_record_tdep.size_pid_t = 4;
952 i386_linux_record_tdep.size_winsize = 8;
953 i386_linux_record_tdep.size_serial_struct = 60;
954 i386_linux_record_tdep.size_serial_icounter_struct = 80;
955 i386_linux_record_tdep.size_hayes_esp_config = 12;
2c543fc4
HZ
956 i386_linux_record_tdep.size_size_t = 4;
957 i386_linux_record_tdep.size_iovec = 8;
b80d067f 958 i386_linux_record_tdep.size_time_t = 4;
5e31abdf
HZ
959
960 /* These values are the second argument of system call "sys_ioctl".
961 They are obtained from Linux Kernel source. */
962 i386_linux_record_tdep.ioctl_TCGETS = 0x5401;
963 i386_linux_record_tdep.ioctl_TCSETS = 0x5402;
964 i386_linux_record_tdep.ioctl_TCSETSW = 0x5403;
965 i386_linux_record_tdep.ioctl_TCSETSF = 0x5404;
966 i386_linux_record_tdep.ioctl_TCGETA = 0x5405;
967 i386_linux_record_tdep.ioctl_TCSETA = 0x5406;
968 i386_linux_record_tdep.ioctl_TCSETAW = 0x5407;
969 i386_linux_record_tdep.ioctl_TCSETAF = 0x5408;
970 i386_linux_record_tdep.ioctl_TCSBRK = 0x5409;
971 i386_linux_record_tdep.ioctl_TCXONC = 0x540A;
972 i386_linux_record_tdep.ioctl_TCFLSH = 0x540B;
973 i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
974 i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
975 i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
976 i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
977 i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
978 i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
979 i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
980 i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
981 i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
982 i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
983 i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
984 i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
985 i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
986 i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
987 i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
988 i386_linux_record_tdep.ioctl_FIONREAD = 0x541B;
989 i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD;
990 i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
991 i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
992 i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
993 i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
994 i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
995 i386_linux_record_tdep.ioctl_FIONBIO = 0x5421;
996 i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
997 i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
998 i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
999 i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
1000 i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
1001 i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
1002 i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
1003 i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
1004 i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
1005 i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
1006 i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
1007 i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
1008 i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
1009 i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
1010 i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
1011 i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
1012 i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
1013 i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
1014 i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
1015 i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
1016 i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
1017 i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
1018 i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
1019 i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
1020 i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
1021 i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
1022 i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
1023 i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
1024 i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
1025 i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
1026 i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
1027
1028 /* These values are the second argument of system call "sys_fcntl"
1029 and "sys_fcntl64". They are obtained from Linux Kernel source. */
1030 i386_linux_record_tdep.fcntl_F_GETLK = 5;
1031 i386_linux_record_tdep.fcntl_F_GETLK64 = 12;
1032 i386_linux_record_tdep.fcntl_F_SETLK64 = 13;
1033 i386_linux_record_tdep.fcntl_F_SETLKW64 = 14;
50ef67b3 1034
77fcef51
HZ
1035 i386_linux_record_tdep.arg1 = I386_EBX_REGNUM;
1036 i386_linux_record_tdep.arg2 = I386_ECX_REGNUM;
1037 i386_linux_record_tdep.arg3 = I386_EDX_REGNUM;
1038 i386_linux_record_tdep.arg4 = I386_ESI_REGNUM;
1039 i386_linux_record_tdep.arg5 = I386_EDI_REGNUM;
2c543fc4 1040 i386_linux_record_tdep.arg6 = I386_EBP_REGNUM;
77fcef51 1041
ffdf6de5
JK
1042 tdep->i386_intx80_record = i386_linux_intx80_sysenter_syscall_record;
1043 tdep->i386_sysenter_record = i386_linux_intx80_sysenter_syscall_record;
1044 tdep->i386_syscall_record = i386_linux_intx80_sysenter_syscall_record;
77fcef51 1045
203c3895 1046 /* N_FUN symbols in shared libaries have 0 for their values and need
1777feb0 1047 to be relocated. */
203c3895
UW
1048 set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
1049
871fbe6a 1050 /* GNU/Linux uses SVR4-style shared libraries. */
982e9687 1051 set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
871fbe6a
MK
1052 set_solib_svr4_fetch_link_map_offsets
1053 (gdbarch, svr4_ilp32_fetch_link_map_offsets);
1054
1055 /* GNU/Linux uses the dynamic linker included in the GNU C Library. */
bb41a796 1056 set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
12b8a2cb
DJ
1057
1058 dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
b2756930
KB
1059
1060 /* Enable TLS support. */
1061 set_gdbarch_fetch_tls_load_module_address (gdbarch,
1062 svr4_fetch_objfile_link_map);
237fc4c9 1063
5aa82d05
AA
1064 /* Core file support. */
1065 set_gdbarch_iterate_over_regset_sections
1066 (gdbarch, i386_linux_iterate_over_regset_sections);
90884b2b
L
1067 set_gdbarch_core_read_description (gdbarch,
1068 i386_linux_core_read_description);
1069
237fc4c9
PA
1070 /* Displaced stepping. */
1071 set_gdbarch_displaced_step_copy_insn (gdbarch,
9a7f938f 1072 i386_linux_displaced_step_copy_insn);
237fc4c9 1073 set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup);
237fc4c9 1074 set_gdbarch_displaced_step_location (gdbarch,
906d60cf 1075 linux_displaced_step_location);
4aa995e1 1076
a96d9b2e 1077 /* Functions for 'catch syscall'. */
458c8db8 1078 set_xml_syscall_file_name (gdbarch, XML_SYSCALL_FILENAME_I386);
a96d9b2e
SDJ
1079 set_gdbarch_get_syscall_number (gdbarch,
1080 i386_linux_get_syscall_number);
190b495d
WT
1081
1082 set_gdbarch_get_siginfo_type (gdbarch, x86_linux_get_siginfo_type);
012b3a21
WT
1083 set_gdbarch_handle_segmentation_fault (gdbarch,
1084 i386_linux_handle_segmentation_fault);
8201327c
MK
1085}
1086
1087/* Provide a prototype to silence -Wmissing-prototypes. */
1088extern void _initialize_i386_linux_tdep (void);
1089
1090void
1091_initialize_i386_linux_tdep (void)
1092{
05816f70 1093 gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
8201327c 1094 i386_linux_init_abi);
90884b2b 1095
1777feb0 1096 /* Initialize the Linux target description. */
90884b2b 1097 initialize_tdesc_i386_linux ();
3a13a53b 1098 initialize_tdesc_i386_mmx_linux ();
c131fcee 1099 initialize_tdesc_i386_avx_linux ();
1dbcd68c 1100 initialize_tdesc_i386_mpx_linux ();
2b863f51 1101 initialize_tdesc_i386_avx_mpx_linux ();
a1fa17ee 1102 initialize_tdesc_i386_avx_avx512_linux ();
51547df6 1103 initialize_tdesc_i386_avx_mpx_avx512_pku_linux ();
8201327c 1104}