diff options
author | H.J. Lu <hjl.tools@gmail.com> | 2010-04-07 18:46:50 +0000 |
---|---|---|
committer | H.J. Lu <hjl.tools@gmail.com> | 2010-04-07 18:46:50 +0000 |
commit | a055a18785d694f50a4ebc8d36579ed20ffd3069 (patch) | |
tree | a10bec1357e03752dcbd479658e33b87ba98cd21 /gdb/amd64-linux-nat.c | |
parent | 31aeac7844e6e347a01fa69178fd1014e69578c0 (diff) | |
download | gdb-a055a18785d694f50a4ebc8d36579ed20ffd3069.zip gdb-a055a18785d694f50a4ebc8d36579ed20ffd3069.tar.gz gdb-a055a18785d694f50a4ebc8d36579ed20ffd3069.tar.bz2 |
Support amd64 AVX.
gdb/
2010-04-07 H.J. Lu <hongjiu.lu@intel.com>
* amd64-linux-nat.c: Include "regset.h", "elf/common.h",
<sys/uio.h> and "i386-xstate.h".
(PTRACE_GETREGSET): New.
(PTRACE_SETREGSET): Likewise.
(have_ptrace_getregset): Likewise.
(amd64_linux_gregset64_reg_offset): Include 16 upper YMM
registers.
(amd64_linux_gregset32_reg_offset): Include 8 upper YMM
registers.
(amd64_linux_fetch_inferior_registers): Support PTRACE_GETFPREGS.
(amd64_linux_store_inferior_registers): Likewise.
(amd64_linux_read_description): Check and enable AVX target
descriptions.
* amd64-linux-tdep.c: Include "regset.h", "i386-linux-tdep.h"
and "features/i386/amd64-avx-linux.c".
(amd64_linux_regset_sections): New.
(amd64_linux_core_read_description): Check and enable AVX
target description.
(amd64_linux_init_abi): Set xsave_xcr0_offset. Call
set_gdbarch_core_regset_sections.
(_initialize_amd64_linux_tdep): Call
initialize_tdesc_amd64_avx_linux.
* amd64-linux-tdep.h (AMD64_LINUX_ORIG_RAX_REGNUM): Replace
AMD64_MXCSR_REGNUM with AMD64_YMM15H_REGNUM.
(tdesc_amd64_avx_linux): New.
(amd64_linux_update_xstateregset): Likewise.
* amd64-tdep.c: Include "features/i386/amd64-avx.c".
(amd64_ymm_names): New.
(amd64_ymmh_names): Likewise.
(amd64_register_name): Likewise.
(amd64_supply_xstateregset): Likewise.
(amd64_collect_xstateregset): Likewise.
(amd64_supply_xsave): Likewise.
(amd64_collect_xsave): Likewise.
(AMD64_NUM_REGS): Removed.
(amd64_dwarf_reg_to_regnum): Return %ymmN register number for
%xmmN if AVX is available.
(amd64_pseudo_register_name): Support pseudo YMM registers.
(amd64_regset_from_core_section): Support .reg-xstate section.
(amd64_init_abi): Set ymmh_register_names, num_ymm_regs
and ymm0h_regnum. Call set_gdbarch_register_name.
(amd64_init_abi): Call initialize_tdesc_amd64_avx.
* amd64-tdep.h (amd64_regnum): Add AMD64_YMM0H_REGNUM and
AMD64_YMM15H_REGNUM.
(AMD64_NUM_REGS): New.
(amd64_supply_xsave): Likewise.
(amd64_collect_xsave): Likewise.
(amd64_register_name): Removed.
(amd64_register_type): Likewise.
gdb/testsuite/
2010-04-07 H.J. Lu <hongjiu.lu@intel.com>
* gdb.arch/i386-avx.c: New.
* gdb.arch/i386-avx.exp: Likewise.
* gdb.arch/i386-cpuid.h: Updated from gcc 4.4.
Diffstat (limited to 'gdb/amd64-linux-nat.c')
-rw-r--r-- | gdb/amd64-linux-nat.c | 114 |
1 files changed, 102 insertions, 12 deletions
diff --git a/gdb/amd64-linux-nat.c b/gdb/amd64-linux-nat.c index b9d5833..9812610 100644 --- a/gdb/amd64-linux-nat.c +++ b/gdb/amd64-linux-nat.c @@ -23,11 +23,14 @@ #include "inferior.h" #include "gdbcore.h" #include "regcache.h" +#include "regset.h" #include "linux-nat.h" #include "amd64-linux-tdep.h" #include "gdb_assert.h" #include "gdb_string.h" +#include "elf/common.h" +#include <sys/uio.h> #include <sys/ptrace.h> #include <sys/debugreg.h> #include <sys/syscall.h> @@ -51,6 +54,18 @@ #include "i386-linux-tdep.h" #include "amd64-nat.h" #include "i386-nat.h" +#include "i386-xstate.h" + +#ifndef PTRACE_GETREGSET +#define PTRACE_GETREGSET 0x4204 +#endif + +#ifndef PTRACE_SETREGSET +#define PTRACE_SETREGSET 0x4205 +#endif + +/* Does the current host support PTRACE_GETREGSET? */ +static int have_ptrace_getregset = -1; /* Mapping between the general-purpose registers in GNU/Linux x86-64 `struct user' format and GDB's register cache layout. */ @@ -73,6 +88,8 @@ static int amd64_linux_gregset64_reg_offset[] = -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, ORIG_RAX * 8 }; @@ -99,6 +116,7 @@ static int amd64_linux_gregset32_reg_offset[] = -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, + -1, -1, -1, -1, -1, -1, -1, -1, ORIG_RAX * 8 /* "orig_eax" */ }; @@ -183,10 +201,26 @@ amd64_linux_fetch_inferior_registers (struct target_ops *ops, { elf_fpregset_t fpregs; - if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) - perror_with_name (_("Couldn't get floating point status")); + if (have_ptrace_getregset) + { + char xstateregs[I386_XSTATE_MAX_SIZE]; + struct iovec iov; + + iov.iov_base = xstateregs; + iov.iov_len = sizeof (xstateregs); + if (ptrace (PTRACE_GETREGSET, tid, + (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) + perror_with_name (_("Couldn't get extended state status")); - amd64_supply_fxsave (regcache, -1, &fpregs); + amd64_supply_xsave (regcache, -1, xstateregs); + } + else + { + if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) + perror_with_name (_("Couldn't get floating point status")); + + amd64_supply_fxsave (regcache, -1, &fpregs); + } } } @@ -226,15 +260,33 @@ amd64_linux_store_inferior_registers (struct target_ops *ops, { elf_fpregset_t fpregs; - if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) - perror_with_name (_("Couldn't get floating point status")); + if (have_ptrace_getregset) + { + char xstateregs[I386_XSTATE_MAX_SIZE]; + struct iovec iov; + + iov.iov_base = xstateregs; + iov.iov_len = sizeof (xstateregs); + if (ptrace (PTRACE_GETREGSET, tid, + (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) + perror_with_name (_("Couldn't get extended state status")); - amd64_collect_fxsave (regcache, regnum, &fpregs); + amd64_collect_xsave (regcache, regnum, xstateregs, 0); + + if (ptrace (PTRACE_SETREGSET, tid, + (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) + perror_with_name (_("Couldn't write extended state status")); + } + else + { + if (ptrace (PTRACE_GETFPREGS, tid, 0, (long) &fpregs) < 0) + perror_with_name (_("Couldn't get floating point status")); - if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0) - perror_with_name (_("Couldn't write floating point status")); + amd64_collect_fxsave (regcache, regnum, &fpregs); - return; + if (ptrace (PTRACE_SETFPREGS, tid, 0, (long) &fpregs) < 0) + perror_with_name (_("Couldn't write floating point status")); + } } } @@ -688,6 +740,8 @@ amd64_linux_read_description (struct target_ops *ops) { unsigned long cs; int tid; + int is_64bit; + static uint64_t xcr0; /* GNU/Linux LWP ID's are process ID's. */ tid = TIDGET (inferior_ptid); @@ -701,10 +755,46 @@ amd64_linux_read_description (struct target_ops *ops) if (errno != 0) perror_with_name (_("Couldn't get CS register")); - if (cs == AMD64_LINUX_USER64_CS) - return tdesc_amd64_linux; + is_64bit = cs == AMD64_LINUX_USER64_CS; + + if (have_ptrace_getregset == -1) + { + uint64_t xstateregs[(I386_XSTATE_SSE_SIZE / sizeof (uint64_t))]; + struct iovec iov; + + iov.iov_base = xstateregs; + iov.iov_len = sizeof (xstateregs); + + /* Check if PTRACE_GETREGSET works. */ + if (ptrace (PTRACE_GETREGSET, tid, + (unsigned int) NT_X86_XSTATE, (long) &iov) < 0) + have_ptrace_getregset = 0; + else + { + have_ptrace_getregset = 1; + + /* Get XCR0 from XSAVE extended state. */ + xcr0 = xstateregs[(I386_LINUX_XSAVE_XCR0_OFFSET + / sizeof (uint64_t))]; + } + } + + /* Check the native XCR0 only if PTRACE_GETREGSET is available. */ + if (have_ptrace_getregset + && (xcr0 & I386_XSTATE_AVX_MASK) == I386_XSTATE_AVX_MASK) + { + if (is_64bit) + return tdesc_amd64_avx_linux; + else + return tdesc_i386_avx_linux; + } else - return tdesc_i386_linux; + { + if (is_64bit) + return tdesc_amd64_linux; + else + return tdesc_i386_linux; + } } /* Provide a prototype to silence -Wmissing-prototypes. */ |