OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-7.2/] [gdb/] [i386-linux-tdep.c] - Blame information for rev 468

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 330 jeremybenn
/* Target-dependent code for GNU/Linux i386.
2
 
3
   Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2007, 2008, 2009, 2010
4
   Free Software Foundation, Inc.
5
 
6
   This file is part of GDB.
7
 
8
   This program is free software; you can redistribute it and/or modify
9
   it under the terms of the GNU General Public License as published by
10
   the Free Software Foundation; either version 3 of the License, or
11
   (at your option) any later version.
12
 
13
   This program is distributed in the hope that it will be useful,
14
   but WITHOUT ANY WARRANTY; without even the implied warranty of
15
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16
   GNU General Public License for more details.
17
 
18
   You should have received a copy of the GNU General Public License
19
   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
20
 
21
#include "defs.h"
22
#include "gdbcore.h"
23
#include "frame.h"
24
#include "value.h"
25
#include "regcache.h"
26
#include "regset.h"
27
#include "inferior.h"
28
#include "osabi.h"
29
#include "reggroups.h"
30
#include "dwarf2-frame.h"
31
#include "gdb_string.h"
32
 
33
#include "i386-tdep.h"
34
#include "i386-linux-tdep.h"
35
#include "linux-tdep.h"
36
#include "glibc-tdep.h"
37
#include "solib-svr4.h"
38
#include "symtab.h"
39
#include "arch-utils.h"
40
#include "xml-syscall.h"
41
 
42
#include "i387-tdep.h"
43
#include "i386-xstate.h"
44
 
45
/* The syscall's XML filename for i386.  */
46
#define XML_SYSCALL_FILENAME_I386 "syscalls/i386-linux.xml"
47
 
48
#include "record.h"
49
#include "linux-record.h"
50
#include <stdint.h>
51
 
52
#include "features/i386/i386-linux.c"
53
#include "features/i386/i386-mmx-linux.c"
54
#include "features/i386/i386-avx-linux.c"
55
 
56
/* Supported register note sections.  */
57
static struct core_regset_section i386_linux_regset_sections[] =
58
{
59
  { ".reg", 68, "general-purpose" },
60
  { ".reg2", 108, "floating-point" },
61
  { NULL, 0 }
62
};
63
 
64
static struct core_regset_section i386_linux_sse_regset_sections[] =
65
{
66
  { ".reg", 68, "general-purpose" },
67
  { ".reg-xfp", 512, "extended floating-point" },
68
  { NULL, 0 }
69
};
70
 
71
static struct core_regset_section i386_linux_avx_regset_sections[] =
72
{
73
  { ".reg", 68, "general-purpose" },
74
  { ".reg-xstate", I386_XSTATE_MAX_SIZE, "XSAVE extended state" },
75
  { NULL, 0 }
76
};
77
 
78
/* Return non-zero, when the register is in the corresponding register
79
   group.  Put the LINUX_ORIG_EAX register in the system group.  */
80
static int
81
i386_linux_register_reggroup_p (struct gdbarch *gdbarch, int regnum,
82
                                struct reggroup *group)
83
{
84
  if (regnum == I386_LINUX_ORIG_EAX_REGNUM)
85
    return (group == system_reggroup
86
            || group == save_reggroup
87
            || group == restore_reggroup);
88
  return i386_register_reggroup_p (gdbarch, regnum, group);
89
}
90
 
91
 
92
/* Recognizing signal handler frames.  */
93
 
94
/* GNU/Linux has two flavors of signals.  Normal signal handlers, and
95
   "realtime" (RT) signals.  The RT signals can provide additional
96
   information to the signal handler if the SA_SIGINFO flag is set
97
   when establishing a signal handler using `sigaction'.  It is not
98
   unlikely that future versions of GNU/Linux will support SA_SIGINFO
99
   for normal signals too.  */
100
 
101
/* When the i386 Linux kernel calls a signal handler and the
102
   SA_RESTORER flag isn't set, the return address points to a bit of
103
   code on the stack.  This function returns whether the PC appears to
104
   be within this bit of code.
105
 
106
   The instruction sequence for normal signals is
107
       pop    %eax
108
       mov    $0x77, %eax
109
       int    $0x80
110
   or 0x58 0xb8 0x77 0x00 0x00 0x00 0xcd 0x80.
111
 
112
   Checking for the code sequence should be somewhat reliable, because
113
   the effect is to call the system call sigreturn.  This is unlikely
114
   to occur anywhere other than in a signal trampoline.
115
 
116
   It kind of sucks that we have to read memory from the process in
117
   order to identify a signal trampoline, but there doesn't seem to be
118
   any other way.  Therefore we only do the memory reads if no
119
   function name could be identified, which should be the case since
120
   the code is on the stack.
121
 
122
   Detection of signal trampolines for handlers that set the
123
   SA_RESTORER flag is in general not possible.  Unfortunately this is
124
   what the GNU C Library has been doing for quite some time now.
125
   However, as of version 2.1.2, the GNU C Library uses signal
126
   trampolines (named __restore and __restore_rt) that are identical
127
   to the ones used by the kernel.  Therefore, these trampolines are
128
   supported too.  */
129
 
130
#define LINUX_SIGTRAMP_INSN0    0x58    /* pop %eax */
131
#define LINUX_SIGTRAMP_OFFSET0  0
132
#define LINUX_SIGTRAMP_INSN1    0xb8    /* mov $NNNN, %eax */
133
#define LINUX_SIGTRAMP_OFFSET1  1
134
#define LINUX_SIGTRAMP_INSN2    0xcd    /* int */
135
#define LINUX_SIGTRAMP_OFFSET2  6
136
 
137
static const gdb_byte linux_sigtramp_code[] =
138
{
139
  LINUX_SIGTRAMP_INSN0,                                 /* pop %eax */
140
  LINUX_SIGTRAMP_INSN1, 0x77, 0x00, 0x00, 0x00,         /* mov $0x77, %eax */
141
  LINUX_SIGTRAMP_INSN2, 0x80                            /* int $0x80 */
142
};
143
 
144
#define LINUX_SIGTRAMP_LEN (sizeof linux_sigtramp_code)
145
 
146
/* If THIS_FRAME is a sigtramp routine, return the address of the
147
   start of the routine.  Otherwise, return 0.  */
148
 
149
static CORE_ADDR
150
i386_linux_sigtramp_start (struct frame_info *this_frame)
151
{
152
  CORE_ADDR pc = get_frame_pc (this_frame);
153
  gdb_byte buf[LINUX_SIGTRAMP_LEN];
154
 
155
  /* We only recognize a signal trampoline if PC is at the start of
156
     one of the three instructions.  We optimize for finding the PC at
157
     the start, as will be the case when the trampoline is not the
158
     first frame on the stack.  We assume that in the case where the
159
     PC is not at the start of the instruction sequence, there will be
160
     a few trailing readable bytes on the stack.  */
161
 
162
  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
163
    return 0;
164
 
165
  if (buf[0] != LINUX_SIGTRAMP_INSN0)
166
    {
167
      int adjust;
168
 
169
      switch (buf[0])
170
        {
171
        case LINUX_SIGTRAMP_INSN1:
172
          adjust = LINUX_SIGTRAMP_OFFSET1;
173
          break;
174
        case LINUX_SIGTRAMP_INSN2:
175
          adjust = LINUX_SIGTRAMP_OFFSET2;
176
          break;
177
        default:
178
          return 0;
179
        }
180
 
181
      pc -= adjust;
182
 
183
      if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_SIGTRAMP_LEN))
184
        return 0;
185
    }
186
 
187
  if (memcmp (buf, linux_sigtramp_code, LINUX_SIGTRAMP_LEN) != 0)
188
    return 0;
189
 
190
  return pc;
191
}
192
 
193
/* This function does the same for RT signals.  Here the instruction
194
   sequence is
195
       mov    $0xad, %eax
196
       int    $0x80
197
   or 0xb8 0xad 0x00 0x00 0x00 0xcd 0x80.
198
 
199
   The effect is to call the system call rt_sigreturn.  */
200
 
201
#define LINUX_RT_SIGTRAMP_INSN0         0xb8 /* mov $NNNN, %eax */
202
#define LINUX_RT_SIGTRAMP_OFFSET0       0
203
#define LINUX_RT_SIGTRAMP_INSN1         0xcd /* int */
204
#define LINUX_RT_SIGTRAMP_OFFSET1       5
205
 
206
static const gdb_byte linux_rt_sigtramp_code[] =
207
{
208
  LINUX_RT_SIGTRAMP_INSN0, 0xad, 0x00, 0x00, 0x00,      /* mov $0xad, %eax */
209
  LINUX_RT_SIGTRAMP_INSN1, 0x80                         /* int $0x80 */
210
};
211
 
212
#define LINUX_RT_SIGTRAMP_LEN (sizeof linux_rt_sigtramp_code)
213
 
214
/* If THIS_FRAME is an RT sigtramp routine, return the address of the
215
   start of the routine.  Otherwise, return 0.  */
216
 
217
static CORE_ADDR
218
i386_linux_rt_sigtramp_start (struct frame_info *this_frame)
219
{
220
  CORE_ADDR pc = get_frame_pc (this_frame);
221
  gdb_byte buf[LINUX_RT_SIGTRAMP_LEN];
222
 
223
  /* We only recognize a signal trampoline if PC is at the start of
224
     one of the two instructions.  We optimize for finding the PC at
225
     the start, as will be the case when the trampoline is not the
226
     first frame on the stack.  We assume that in the case where the
227
     PC is not at the start of the instruction sequence, there will be
228
     a few trailing readable bytes on the stack.  */
229
 
230
  if (!safe_frame_unwind_memory (this_frame, pc, buf, LINUX_RT_SIGTRAMP_LEN))
231
    return 0;
232
 
233
  if (buf[0] != LINUX_RT_SIGTRAMP_INSN0)
234
    {
235
      if (buf[0] != LINUX_RT_SIGTRAMP_INSN1)
236
        return 0;
237
 
238
      pc -= LINUX_RT_SIGTRAMP_OFFSET1;
239
 
240
      if (!safe_frame_unwind_memory (this_frame, pc, buf,
241
                                     LINUX_RT_SIGTRAMP_LEN))
242
        return 0;
243
    }
244
 
245
  if (memcmp (buf, linux_rt_sigtramp_code, LINUX_RT_SIGTRAMP_LEN) != 0)
246
    return 0;
247
 
248
  return pc;
249
}
250
 
251
/* Return whether THIS_FRAME corresponds to a GNU/Linux sigtramp
252
   routine.  */
253
 
254
static int
255
i386_linux_sigtramp_p (struct frame_info *this_frame)
256
{
257
  CORE_ADDR pc = get_frame_pc (this_frame);
258
  char *name;
259
 
260
  find_pc_partial_function (pc, &name, NULL, NULL);
261
 
262
  /* If we have NAME, we can optimize the search.  The trampolines are
263
     named __restore and __restore_rt.  However, they aren't dynamically
264
     exported from the shared C library, so the trampoline may appear to
265
     be part of the preceding function.  This should always be sigaction,
266
     __sigaction, or __libc_sigaction (all aliases to the same function).  */
267
  if (name == NULL || strstr (name, "sigaction") != NULL)
268
    return (i386_linux_sigtramp_start (this_frame) != 0
269
            || i386_linux_rt_sigtramp_start (this_frame) != 0);
270
 
271
  return (strcmp ("__restore", name) == 0
272
          || strcmp ("__restore_rt", name) == 0);
273
}
274
 
275
/* Return one if the PC of THIS_FRAME is in a signal trampoline which
276
   may have DWARF-2 CFI.  */
277
 
278
static int
279
i386_linux_dwarf_signal_frame_p (struct gdbarch *gdbarch,
280
                                 struct frame_info *this_frame)
281
{
282
  CORE_ADDR pc = get_frame_pc (this_frame);
283
  char *name;
284
 
285
  find_pc_partial_function (pc, &name, NULL, NULL);
286
 
287
  /* If a vsyscall DSO is in use, the signal trampolines may have these
288
     names.  */
289
  if (name && (strcmp (name, "__kernel_sigreturn") == 0
290
               || strcmp (name, "__kernel_rt_sigreturn") == 0))
291
    return 1;
292
 
293
  return 0;
294
}
295
 
296
/* Offset to struct sigcontext in ucontext, from <asm/ucontext.h>.  */
297
#define I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET 20
298
 
299
/* Assuming THIS_FRAME is a GNU/Linux sigtramp routine, return the
300
   address of the associated sigcontext structure.  */
301
 
302
static CORE_ADDR
303
i386_linux_sigcontext_addr (struct frame_info *this_frame)
304
{
305
  struct gdbarch *gdbarch = get_frame_arch (this_frame);
306
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
307
  CORE_ADDR pc;
308
  CORE_ADDR sp;
309
  gdb_byte buf[4];
310
 
311
  get_frame_register (this_frame, I386_ESP_REGNUM, buf);
312
  sp = extract_unsigned_integer (buf, 4, byte_order);
313
 
314
  pc = i386_linux_sigtramp_start (this_frame);
315
  if (pc)
316
    {
317
      /* The sigcontext structure lives on the stack, right after
318
         the signum argument.  We determine the address of the
319
         sigcontext structure by looking at the frame's stack
320
         pointer.  Keep in mind that the first instruction of the
321
         sigtramp code is "pop %eax".  If the PC is after this
322
         instruction, adjust the returned value accordingly.  */
323
      if (pc == get_frame_pc (this_frame))
324
        return sp + 4;
325
      return sp;
326
    }
327
 
328
  pc = i386_linux_rt_sigtramp_start (this_frame);
329
  if (pc)
330
    {
331
      CORE_ADDR ucontext_addr;
332
 
333
      /* The sigcontext structure is part of the user context.  A
334
         pointer to the user context is passed as the third argument
335
         to the signal handler.  */
336
      read_memory (sp + 8, buf, 4);
337
      ucontext_addr = extract_unsigned_integer (buf, 4, byte_order);
338
      return ucontext_addr + I386_LINUX_UCONTEXT_SIGCONTEXT_OFFSET;
339
    }
340
 
341
  error (_("Couldn't recognize signal trampoline."));
342
  return 0;
343
}
344
 
345
/* Set the program counter for process PTID to PC.  */
346
 
347
static void
348
i386_linux_write_pc (struct regcache *regcache, CORE_ADDR pc)
349
{
350
  regcache_cooked_write_unsigned (regcache, I386_EIP_REGNUM, pc);
351
 
352
  /* We must be careful with modifying the program counter.  If we
353
     just interrupted a system call, the kernel might try to restart
354
     it when we resume the inferior.  On restarting the system call,
355
     the kernel will try backing up the program counter even though it
356
     no longer points at the system call.  This typically results in a
357
     SIGSEGV or SIGILL.  We can prevent this by writing `-1' in the
358
     "orig_eax" pseudo-register.
359
 
360
     Note that "orig_eax" is saved when setting up a dummy call frame.
361
     This means that it is properly restored when that frame is
362
     popped, and that the interrupted system call will be restarted
363
     when we resume the inferior on return from a function call from
364
     within GDB.  In all other cases the system call will not be
365
     restarted.  */
366
  regcache_cooked_write_unsigned (regcache, I386_LINUX_ORIG_EAX_REGNUM, -1);
367
}
368
 
369
/* Record all registers but IP register for process-record.  */
370
 
371
static int
372
i386_all_but_ip_registers_record (struct regcache *regcache)
373
{
374
  if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
375
    return -1;
376
  if (record_arch_list_add_reg (regcache, I386_ECX_REGNUM))
377
    return -1;
378
  if (record_arch_list_add_reg (regcache, I386_EDX_REGNUM))
379
    return -1;
380
  if (record_arch_list_add_reg (regcache, I386_EBX_REGNUM))
381
    return -1;
382
  if (record_arch_list_add_reg (regcache, I386_ESP_REGNUM))
383
    return -1;
384
  if (record_arch_list_add_reg (regcache, I386_EBP_REGNUM))
385
    return -1;
386
  if (record_arch_list_add_reg (regcache, I386_ESI_REGNUM))
387
    return -1;
388
  if (record_arch_list_add_reg (regcache, I386_EDI_REGNUM))
389
    return -1;
390
  if (record_arch_list_add_reg (regcache, I386_EFLAGS_REGNUM))
391
    return -1;
392
 
393
  return 0;
394
}
395
 
396
/* i386_canonicalize_syscall maps from the native i386 Linux set
397
   of syscall ids into a canonical set of syscall ids used by
398
   process record (a mostly trivial mapping, since the canonical
399
   set was originally taken from the i386 set).  */
400
 
401
static enum gdb_syscall
402
i386_canonicalize_syscall (int syscall)
403
{
404
  enum { i386_syscall_max = 499 };
405
 
406
  if (syscall <= i386_syscall_max)
407
    return syscall;
408
  else
409
    return -1;
410
}
411
 
412
/* Parse the arguments of current system call instruction and record
413
   the values of the registers and memory that will be changed into
414
   "record_arch_list".  This instruction is "int 0x80" (Linux
415
   Kernel2.4) or "sysenter" (Linux Kernel 2.6).
416
 
417
   Return -1 if something wrong.  */
418
 
419
static struct linux_record_tdep i386_linux_record_tdep;
420
 
421
static int
422
i386_linux_intx80_sysenter_record (struct regcache *regcache)
423
{
424
  int ret;
425
  LONGEST syscall_native;
426
  enum gdb_syscall syscall_gdb;
427
 
428
  regcache_raw_read_signed (regcache, I386_EAX_REGNUM, &syscall_native);
429
 
430
  syscall_gdb = i386_canonicalize_syscall (syscall_native);
431
 
432
  if (syscall_gdb < 0)
433
    {
434
      printf_unfiltered (_("Process record and replay target doesn't "
435
                           "support syscall number %s\n"),
436
                         plongest (syscall_native));
437
      return -1;
438
    }
439
 
440
  if (syscall_gdb == gdb_sys_sigreturn
441
      || syscall_gdb == gdb_sys_rt_sigreturn)
442
   {
443
     if (i386_all_but_ip_registers_record (regcache))
444
       return -1;
445
     return 0;
446
   }
447
 
448
  ret = record_linux_system_call (syscall_gdb, regcache,
449
                                  &i386_linux_record_tdep);
450
  if (ret)
451
    return ret;
452
 
453
  /* Record the return value of the system call.  */
454
  if (record_arch_list_add_reg (regcache, I386_EAX_REGNUM))
455
    return -1;
456
 
457
  return 0;
458
}
459
 
460
#define I386_LINUX_xstate       270
461
#define I386_LINUX_frame_size   732
462
 
463
int
464
i386_linux_record_signal (struct gdbarch *gdbarch,
465
                          struct regcache *regcache,
466
                          enum target_signal signal)
467
{
468
  ULONGEST esp;
469
 
470
  if (i386_all_but_ip_registers_record (regcache))
471
    return -1;
472
 
473
  if (record_arch_list_add_reg (regcache, I386_EIP_REGNUM))
474
    return -1;
475
 
476
  /* Record the change in the stack.  */
477
  regcache_raw_read_unsigned (regcache, I386_ESP_REGNUM, &esp);
478
  /* This is for xstate.
479
     sp -= sizeof (struct _fpstate);  */
480
  esp -= I386_LINUX_xstate;
481
  /* This is for frame_size.
482
     sp -= sizeof (struct rt_sigframe);  */
483
  esp -= I386_LINUX_frame_size;
484
  if (record_arch_list_add_mem (esp,
485
                                I386_LINUX_xstate + I386_LINUX_frame_size))
486
    return -1;
487
 
488
  if (record_arch_list_add_end ())
489
    return -1;
490
 
491
  return 0;
492
}
493
 
494
 
495
static LONGEST
496
i386_linux_get_syscall_number (struct gdbarch *gdbarch,
497
                               ptid_t ptid)
498
{
499
  struct regcache *regcache = get_thread_regcache (ptid);
500
  enum bfd_endian byte_order = gdbarch_byte_order (gdbarch);
501
  /* The content of a register.  */
502
  gdb_byte buf[4];
503
  /* The result.  */
504
  LONGEST ret;
505
 
506
  /* Getting the system call number from the register.
507
     When dealing with x86 architecture, this information
508
     is stored at %eax register.  */
509
  regcache_cooked_read (regcache, I386_LINUX_ORIG_EAX_REGNUM, buf);
510
 
511
  ret = extract_signed_integer (buf, 4, byte_order);
512
 
513
  return ret;
514
}
515
 
516
/* The register sets used in GNU/Linux ELF core-dumps are identical to
517
   the register sets in `struct user' that are used for a.out
518
   core-dumps.  These are also used by ptrace(2).  The corresponding
519
   types are `elf_gregset_t' for the general-purpose registers (with
520
   `elf_greg_t' the type of a single GP register) and `elf_fpregset_t'
521
   for the floating-point registers.
522
 
523
   Those types used to be available under the names `gregset_t' and
524
   `fpregset_t' too, and GDB used those names in the past.  But those
525
   names are now used for the register sets used in the `mcontext_t'
526
   type, which have a different size and layout.  */
527
 
528
/* Mapping between the general-purpose registers in `struct user'
529
   format and GDB's register cache layout.  */
530
 
531
/* From <sys/reg.h>.  */
532
int i386_linux_gregset_reg_offset[] =
533
{
534
  6 * 4,                        /* %eax */
535
  1 * 4,                        /* %ecx */
536
  2 * 4,                        /* %edx */
537
 
538
  15 * 4,                       /* %esp */
539
  5 * 4,                        /* %ebp */
540
  3 * 4,                        /* %esi */
541
  4 * 4,                        /* %edi */
542
  12 * 4,                       /* %eip */
543
  14 * 4,                       /* %eflags */
544
  13 * 4,                       /* %cs */
545
  16 * 4,                       /* %ss */
546
  7 * 4,                        /* %ds */
547
  8 * 4,                        /* %es */
548
  9 * 4,                        /* %fs */
549
  10 * 4,                       /* %gs */
550
  -1, -1, -1, -1, -1, -1, -1, -1,
551
  -1, -1, -1, -1, -1, -1, -1, -1,
552
  -1, -1, -1, -1, -1, -1, -1, -1,
553
  -1,
554
  -1, -1, -1, -1, -1, -1, -1, -1,
555
  11 * 4                        /* "orig_eax" */
556
};
557
 
558
/* Mapping between the general-purpose registers in `struct
559
   sigcontext' format and GDB's register cache layout.  */
560
 
561
/* From <asm/sigcontext.h>.  */
562
static int i386_linux_sc_reg_offset[] =
563
{
564
  11 * 4,                       /* %eax */
565
  10 * 4,                       /* %ecx */
566
  9 * 4,                        /* %edx */
567
  8 * 4,                        /* %ebx */
568
  7 * 4,                        /* %esp */
569
  6 * 4,                        /* %ebp */
570
  5 * 4,                        /* %esi */
571
  4 * 4,                        /* %edi */
572
  14 * 4,                       /* %eip */
573
  16 * 4,                       /* %eflags */
574
  15 * 4,                       /* %cs */
575
  18 * 4,                       /* %ss */
576
  3 * 4,                        /* %ds */
577
  2 * 4,                        /* %es */
578
  1 * 4,                        /* %fs */
579
 
580
};
581
 
582
/* Get XSAVE extended state xcr0 from core dump.  */
583
 
584
uint64_t
585
i386_linux_core_read_xcr0 (struct gdbarch *gdbarch,
586
                           struct target_ops *target, bfd *abfd)
587
{
588
  asection *xstate = bfd_get_section_by_name (abfd, ".reg-xstate");
589
  uint64_t xcr0;
590
 
591
  if (xstate)
592
    {
593
      size_t size = bfd_section_size (abfd, xstate);
594
 
595
      /* Check extended state size.  */
596
      if (size < I386_XSTATE_AVX_SIZE)
597
        xcr0 = I386_XSTATE_SSE_MASK;
598
      else
599
        {
600
          char contents[8];
601
 
602
          if (! bfd_get_section_contents (abfd, xstate, contents,
603
                                          I386_LINUX_XSAVE_XCR0_OFFSET,
604
                                          8))
605
            {
606
              warning (_("Couldn't read `xcr0' bytes from `.reg-xstate' section in core file."));
607
              return 0;
608
            }
609
 
610
          xcr0 = bfd_get_64 (abfd, contents);
611
        }
612
    }
613
  else
614
    xcr0 = 0;
615
 
616
  return xcr0;
617
}
618
 
619
/* Get Linux/x86 target description from core dump.  */
620
 
621
static const struct target_desc *
622
i386_linux_core_read_description (struct gdbarch *gdbarch,
623
                                  struct target_ops *target,
624
                                  bfd *abfd)
625
{
626
  /* Linux/i386.  */
627
  uint64_t xcr0 = i386_linux_core_read_xcr0 (gdbarch, target, abfd);
628
  switch ((xcr0 & I386_XSTATE_AVX_MASK))
629
    {
630
    case I386_XSTATE_AVX_MASK:
631
      return tdesc_i386_avx_linux;
632
    case I386_XSTATE_SSE_MASK:
633
      return tdesc_i386_linux;
634
    case I386_XSTATE_X87_MASK:
635
      return tdesc_i386_mmx_linux;
636
    default:
637
      break;
638
    }
639
 
640
  if (bfd_get_section_by_name (abfd, ".reg-xfp") != NULL)
641
    return tdesc_i386_linux;
642
  else
643
    return tdesc_i386_mmx_linux;
644
}
645
 
646
static void
647
i386_linux_init_abi (struct gdbarch_info info, struct gdbarch *gdbarch)
648
{
649
  struct gdbarch_tdep *tdep = gdbarch_tdep (gdbarch);
650
  const struct target_desc *tdesc = info.target_desc;
651
  struct tdesc_arch_data *tdesc_data = (void *) info.tdep_info;
652
  const struct tdesc_feature *feature;
653
  int valid_p;
654
 
655
  gdb_assert (tdesc_data);
656
 
657
  /* GNU/Linux uses ELF.  */
658
  i386_elf_init_abi (info, gdbarch);
659
 
660
  /* Reserve a number for orig_eax.  */
661
  set_gdbarch_num_regs (gdbarch, I386_LINUX_NUM_REGS);
662
 
663
  if (! tdesc_has_registers (tdesc))
664
    tdesc = tdesc_i386_linux;
665
  tdep->tdesc = tdesc;
666
 
667
  feature = tdesc_find_feature (tdesc, "org.gnu.gdb.i386.linux");
668
  if (feature == NULL)
669
    return;
670
 
671
  valid_p = tdesc_numbered_register (feature, tdesc_data,
672
                                     I386_LINUX_ORIG_EAX_REGNUM,
673
                                     "orig_eax");
674
  if (!valid_p)
675
    return;
676
 
677
  /* Add the %orig_eax register used for syscall restarting.  */
678
  set_gdbarch_write_pc (gdbarch, i386_linux_write_pc);
679
 
680
  tdep->register_reggroup_p = i386_linux_register_reggroup_p;
681
 
682
  tdep->gregset_reg_offset = i386_linux_gregset_reg_offset;
683
  tdep->gregset_num_regs = ARRAY_SIZE (i386_linux_gregset_reg_offset);
684
  tdep->sizeof_gregset = 17 * 4;
685
 
686
  tdep->jb_pc_offset = 20;      /* From <bits/setjmp.h>.  */
687
 
688
  tdep->sigtramp_p = i386_linux_sigtramp_p;
689
  tdep->sigcontext_addr = i386_linux_sigcontext_addr;
690
  tdep->sc_reg_offset = i386_linux_sc_reg_offset;
691
  tdep->sc_num_regs = ARRAY_SIZE (i386_linux_sc_reg_offset);
692
 
693
  tdep->xsave_xcr0_offset = I386_LINUX_XSAVE_XCR0_OFFSET;
694
 
695
  set_gdbarch_process_record (gdbarch, i386_process_record);
696
  set_gdbarch_process_record_signal (gdbarch, i386_linux_record_signal);
697
 
698
  /* Initialize the i386_linux_record_tdep.  */
699
  /* These values are the size of the type that will be used in a system
700
     call.  They are obtained from Linux Kernel source.  */
701
  i386_linux_record_tdep.size_pointer
702
    = gdbarch_ptr_bit (gdbarch) / TARGET_CHAR_BIT;
703
  i386_linux_record_tdep.size__old_kernel_stat = 32;
704
  i386_linux_record_tdep.size_tms = 16;
705
  i386_linux_record_tdep.size_loff_t = 8;
706
  i386_linux_record_tdep.size_flock = 16;
707
  i386_linux_record_tdep.size_oldold_utsname = 45;
708
  i386_linux_record_tdep.size_ustat = 20;
709
  i386_linux_record_tdep.size_old_sigaction = 140;
710
  i386_linux_record_tdep.size_old_sigset_t = 128;
711
  i386_linux_record_tdep.size_rlimit = 8;
712
  i386_linux_record_tdep.size_rusage = 72;
713
  i386_linux_record_tdep.size_timeval = 8;
714
  i386_linux_record_tdep.size_timezone = 8;
715
  i386_linux_record_tdep.size_old_gid_t = 2;
716
  i386_linux_record_tdep.size_old_uid_t = 2;
717
  i386_linux_record_tdep.size_fd_set = 128;
718
  i386_linux_record_tdep.size_dirent = 268;
719
  i386_linux_record_tdep.size_dirent64 = 276;
720
  i386_linux_record_tdep.size_statfs = 64;
721
  i386_linux_record_tdep.size_statfs64 = 84;
722
  i386_linux_record_tdep.size_sockaddr = 16;
723
  i386_linux_record_tdep.size_int
724
    = gdbarch_int_bit (gdbarch) / TARGET_CHAR_BIT;
725
  i386_linux_record_tdep.size_long
726
    = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
727
  i386_linux_record_tdep.size_ulong
728
    = gdbarch_long_bit (gdbarch) / TARGET_CHAR_BIT;
729
  i386_linux_record_tdep.size_msghdr = 28;
730
  i386_linux_record_tdep.size_itimerval = 16;
731
  i386_linux_record_tdep.size_stat = 88;
732
  i386_linux_record_tdep.size_old_utsname = 325;
733
  i386_linux_record_tdep.size_sysinfo = 64;
734
  i386_linux_record_tdep.size_msqid_ds = 88;
735
  i386_linux_record_tdep.size_shmid_ds = 84;
736
  i386_linux_record_tdep.size_new_utsname = 390;
737
  i386_linux_record_tdep.size_timex = 128;
738
  i386_linux_record_tdep.size_mem_dqinfo = 24;
739
  i386_linux_record_tdep.size_if_dqblk = 68;
740
  i386_linux_record_tdep.size_fs_quota_stat = 68;
741
  i386_linux_record_tdep.size_timespec = 8;
742
  i386_linux_record_tdep.size_pollfd = 8;
743
  i386_linux_record_tdep.size_NFS_FHSIZE = 32;
744
  i386_linux_record_tdep.size_knfsd_fh = 132;
745
  i386_linux_record_tdep.size_TASK_COMM_LEN = 16;
746
  i386_linux_record_tdep.size_sigaction = 140;
747
  i386_linux_record_tdep.size_sigset_t = 8;
748
  i386_linux_record_tdep.size_siginfo_t = 128;
749
  i386_linux_record_tdep.size_cap_user_data_t = 12;
750
  i386_linux_record_tdep.size_stack_t = 12;
751
  i386_linux_record_tdep.size_off_t = i386_linux_record_tdep.size_long;
752
  i386_linux_record_tdep.size_stat64 = 96;
753
  i386_linux_record_tdep.size_gid_t = 2;
754
  i386_linux_record_tdep.size_uid_t = 2;
755
  i386_linux_record_tdep.size_PAGE_SIZE = 4096;
756
  i386_linux_record_tdep.size_flock64 = 24;
757
  i386_linux_record_tdep.size_user_desc = 16;
758
  i386_linux_record_tdep.size_io_event = 32;
759
  i386_linux_record_tdep.size_iocb = 64;
760
  i386_linux_record_tdep.size_epoll_event = 12;
761
  i386_linux_record_tdep.size_itimerspec
762
    = i386_linux_record_tdep.size_timespec * 2;
763
  i386_linux_record_tdep.size_mq_attr = 32;
764
  i386_linux_record_tdep.size_siginfo = 128;
765
  i386_linux_record_tdep.size_termios = 36;
766
  i386_linux_record_tdep.size_termios2 = 44;
767
  i386_linux_record_tdep.size_pid_t = 4;
768
  i386_linux_record_tdep.size_winsize = 8;
769
  i386_linux_record_tdep.size_serial_struct = 60;
770
  i386_linux_record_tdep.size_serial_icounter_struct = 80;
771
  i386_linux_record_tdep.size_hayes_esp_config = 12;
772
  i386_linux_record_tdep.size_size_t = 4;
773
  i386_linux_record_tdep.size_iovec = 8;
774
 
775
  /* These values are the second argument of system call "sys_ioctl".
776
     They are obtained from Linux Kernel source.  */
777
  i386_linux_record_tdep.ioctl_TCGETS = 0x5401;
778
  i386_linux_record_tdep.ioctl_TCSETS = 0x5402;
779
  i386_linux_record_tdep.ioctl_TCSETSW = 0x5403;
780
  i386_linux_record_tdep.ioctl_TCSETSF = 0x5404;
781
  i386_linux_record_tdep.ioctl_TCGETA = 0x5405;
782
  i386_linux_record_tdep.ioctl_TCSETA = 0x5406;
783
  i386_linux_record_tdep.ioctl_TCSETAW = 0x5407;
784
  i386_linux_record_tdep.ioctl_TCSETAF = 0x5408;
785
  i386_linux_record_tdep.ioctl_TCSBRK = 0x5409;
786
  i386_linux_record_tdep.ioctl_TCXONC = 0x540A;
787
  i386_linux_record_tdep.ioctl_TCFLSH = 0x540B;
788
  i386_linux_record_tdep.ioctl_TIOCEXCL = 0x540C;
789
  i386_linux_record_tdep.ioctl_TIOCNXCL = 0x540D;
790
  i386_linux_record_tdep.ioctl_TIOCSCTTY = 0x540E;
791
  i386_linux_record_tdep.ioctl_TIOCGPGRP = 0x540F;
792
  i386_linux_record_tdep.ioctl_TIOCSPGRP = 0x5410;
793
  i386_linux_record_tdep.ioctl_TIOCOUTQ = 0x5411;
794
  i386_linux_record_tdep.ioctl_TIOCSTI = 0x5412;
795
  i386_linux_record_tdep.ioctl_TIOCGWINSZ = 0x5413;
796
  i386_linux_record_tdep.ioctl_TIOCSWINSZ = 0x5414;
797
  i386_linux_record_tdep.ioctl_TIOCMGET = 0x5415;
798
  i386_linux_record_tdep.ioctl_TIOCMBIS = 0x5416;
799
  i386_linux_record_tdep.ioctl_TIOCMBIC = 0x5417;
800
  i386_linux_record_tdep.ioctl_TIOCMSET = 0x5418;
801
  i386_linux_record_tdep.ioctl_TIOCGSOFTCAR = 0x5419;
802
  i386_linux_record_tdep.ioctl_TIOCSSOFTCAR = 0x541A;
803
  i386_linux_record_tdep.ioctl_FIONREAD = 0x541B;
804
  i386_linux_record_tdep.ioctl_TIOCINQ = i386_linux_record_tdep.ioctl_FIONREAD;
805
  i386_linux_record_tdep.ioctl_TIOCLINUX = 0x541C;
806
  i386_linux_record_tdep.ioctl_TIOCCONS = 0x541D;
807
  i386_linux_record_tdep.ioctl_TIOCGSERIAL = 0x541E;
808
  i386_linux_record_tdep.ioctl_TIOCSSERIAL = 0x541F;
809
  i386_linux_record_tdep.ioctl_TIOCPKT = 0x5420;
810
  i386_linux_record_tdep.ioctl_FIONBIO = 0x5421;
811
  i386_linux_record_tdep.ioctl_TIOCNOTTY = 0x5422;
812
  i386_linux_record_tdep.ioctl_TIOCSETD = 0x5423;
813
  i386_linux_record_tdep.ioctl_TIOCGETD = 0x5424;
814
  i386_linux_record_tdep.ioctl_TCSBRKP = 0x5425;
815
  i386_linux_record_tdep.ioctl_TIOCTTYGSTRUCT = 0x5426;
816
  i386_linux_record_tdep.ioctl_TIOCSBRK = 0x5427;
817
  i386_linux_record_tdep.ioctl_TIOCCBRK = 0x5428;
818
  i386_linux_record_tdep.ioctl_TIOCGSID = 0x5429;
819
  i386_linux_record_tdep.ioctl_TCGETS2 = 0x802c542a;
820
  i386_linux_record_tdep.ioctl_TCSETS2 = 0x402c542b;
821
  i386_linux_record_tdep.ioctl_TCSETSW2 = 0x402c542c;
822
  i386_linux_record_tdep.ioctl_TCSETSF2 = 0x402c542d;
823
  i386_linux_record_tdep.ioctl_TIOCGPTN = 0x80045430;
824
  i386_linux_record_tdep.ioctl_TIOCSPTLCK = 0x40045431;
825
  i386_linux_record_tdep.ioctl_FIONCLEX = 0x5450;
826
  i386_linux_record_tdep.ioctl_FIOCLEX = 0x5451;
827
  i386_linux_record_tdep.ioctl_FIOASYNC = 0x5452;
828
  i386_linux_record_tdep.ioctl_TIOCSERCONFIG = 0x5453;
829
  i386_linux_record_tdep.ioctl_TIOCSERGWILD = 0x5454;
830
  i386_linux_record_tdep.ioctl_TIOCSERSWILD = 0x5455;
831
  i386_linux_record_tdep.ioctl_TIOCGLCKTRMIOS = 0x5456;
832
  i386_linux_record_tdep.ioctl_TIOCSLCKTRMIOS = 0x5457;
833
  i386_linux_record_tdep.ioctl_TIOCSERGSTRUCT = 0x5458;
834
  i386_linux_record_tdep.ioctl_TIOCSERGETLSR = 0x5459;
835
  i386_linux_record_tdep.ioctl_TIOCSERGETMULTI = 0x545A;
836
  i386_linux_record_tdep.ioctl_TIOCSERSETMULTI = 0x545B;
837
  i386_linux_record_tdep.ioctl_TIOCMIWAIT = 0x545C;
838
  i386_linux_record_tdep.ioctl_TIOCGICOUNT = 0x545D;
839
  i386_linux_record_tdep.ioctl_TIOCGHAYESESP = 0x545E;
840
  i386_linux_record_tdep.ioctl_TIOCSHAYESESP = 0x545F;
841
  i386_linux_record_tdep.ioctl_FIOQSIZE = 0x5460;
842
 
843
  /* These values are the second argument of system call "sys_fcntl"
844
     and "sys_fcntl64".  They are obtained from Linux Kernel source.  */
845
  i386_linux_record_tdep.fcntl_F_GETLK = 5;
846
  i386_linux_record_tdep.fcntl_F_GETLK64 = 12;
847
  i386_linux_record_tdep.fcntl_F_SETLK64 = 13;
848
  i386_linux_record_tdep.fcntl_F_SETLKW64 = 14;
849
 
850
  i386_linux_record_tdep.arg1 = I386_EBX_REGNUM;
851
  i386_linux_record_tdep.arg2 = I386_ECX_REGNUM;
852
  i386_linux_record_tdep.arg3 = I386_EDX_REGNUM;
853
  i386_linux_record_tdep.arg4 = I386_ESI_REGNUM;
854
  i386_linux_record_tdep.arg5 = I386_EDI_REGNUM;
855
  i386_linux_record_tdep.arg6 = I386_EBP_REGNUM;
856
 
857
  tdep->i386_intx80_record = i386_linux_intx80_sysenter_record;
858
  tdep->i386_sysenter_record = i386_linux_intx80_sysenter_record;
859
 
860
  /* N_FUN symbols in shared libaries have 0 for their values and need
861
     to be relocated. */
862
  set_gdbarch_sofun_address_maybe_missing (gdbarch, 1);
863
 
864
  /* GNU/Linux uses SVR4-style shared libraries.  */
865
  set_gdbarch_skip_trampoline_code (gdbarch, find_solib_trampoline_target);
866
  set_solib_svr4_fetch_link_map_offsets
867
    (gdbarch, svr4_ilp32_fetch_link_map_offsets);
868
 
869
  /* GNU/Linux uses the dynamic linker included in the GNU C Library.  */
870
  set_gdbarch_skip_solib_resolver (gdbarch, glibc_skip_solib_resolver);
871
 
872
  dwarf2_frame_set_signal_frame_p (gdbarch, i386_linux_dwarf_signal_frame_p);
873
 
874
  /* Enable TLS support.  */
875
  set_gdbarch_fetch_tls_load_module_address (gdbarch,
876
                                             svr4_fetch_objfile_link_map);
877
 
878
  /* Install supported register note sections.  */
879
  if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.avx"))
880
    set_gdbarch_core_regset_sections (gdbarch, i386_linux_avx_regset_sections);
881
  else if (tdesc_find_feature (tdesc, "org.gnu.gdb.i386.sse"))
882
    set_gdbarch_core_regset_sections (gdbarch, i386_linux_sse_regset_sections);
883
  else
884
    set_gdbarch_core_regset_sections (gdbarch, i386_linux_regset_sections);
885
 
886
  set_gdbarch_core_read_description (gdbarch,
887
                                     i386_linux_core_read_description);
888
 
889
  /* Displaced stepping.  */
890
  set_gdbarch_displaced_step_copy_insn (gdbarch,
891
                                        i386_displaced_step_copy_insn);
892
  set_gdbarch_displaced_step_fixup (gdbarch, i386_displaced_step_fixup);
893
  set_gdbarch_displaced_step_free_closure (gdbarch,
894
                                           simple_displaced_step_free_closure);
895
  set_gdbarch_displaced_step_location (gdbarch,
896
                                       displaced_step_at_entry_point);
897
 
898
  /* Functions for 'catch syscall'.  */
899
  set_xml_syscall_file_name (XML_SYSCALL_FILENAME_I386);
900
  set_gdbarch_get_syscall_number (gdbarch,
901
                                  i386_linux_get_syscall_number);
902
 
903
  set_gdbarch_get_siginfo_type (gdbarch, linux_get_siginfo_type);
904
}
905
 
906
/* Provide a prototype to silence -Wmissing-prototypes.  */
907
extern void _initialize_i386_linux_tdep (void);
908
 
909
void
910
_initialize_i386_linux_tdep (void)
911
{
912
  gdbarch_register_osabi (bfd_arch_i386, 0, GDB_OSABI_LINUX,
913
                          i386_linux_init_abi);
914
 
915
  /* Initialize the Linux target description  */
916
  initialize_tdesc_i386_linux ();
917
  initialize_tdesc_i386_mmx_linux ();
918
  initialize_tdesc_i386_avx_linux ();
919
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.