diff options
author | jhb <jhb@FreeBSD.org> | 2015-02-23 18:38:41 +0000 |
---|---|---|
committer | jhb <jhb@FreeBSD.org> | 2015-02-23 18:38:41 +0000 |
commit | 4ee9c49971462598e86cded5dec28bd933b91fc9 (patch) | |
tree | 8d545a55b1f8a364c5e8fe792781dcb94afc7a15 /sys/i386/i386 | |
parent | bddd935ed9588effa40aa2a0581dc92d44e4c10c (diff) | |
download | FreeBSD-src-4ee9c49971462598e86cded5dec28bd933b91fc9.zip FreeBSD-src-4ee9c49971462598e86cded5dec28bd933b91fc9.tar.gz |
MFC 274817,274878,276801,276840,278976:
Improve support for XSAVE with debuggers.
- Dump an NT_X86_XSTATE note if XSAVE is in use. This note is designed
to match what Linux does in that 1) it dumps the entire XSAVE area
including the fxsave state, and 2) it stashes a copy of the current
xsave mask in the unused padding between the fxsave state and the
xstate header at the same location used by Linux.
- Teach readelf() to recognize NT_X86_XSTATE notes.
- Change PT_GET/SETXSTATE to take the entire XSAVE state instead of
only the extra portion. This avoids having to always make two
ptrace() calls to get or set the full XSAVE state.
- Add a PT_GET_XSTATE_INFO which returns the length of the current
XSTATE save area (so the size of the buffer needed for PT_GETXSTATE)
and the current XSAVE mask (%xcr0).
Diffstat (limited to 'sys/i386/i386')
-rw-r--r-- | sys/i386/i386/elf_machdep.c | 32 | ||||
-rw-r--r-- | sys/i386/i386/ptrace_machdep.c | 39 |
2 files changed, 66 insertions, 5 deletions
diff --git a/sys/i386/i386/elf_machdep.c b/sys/i386/i386/elf_machdep.c index 034b4c4..8cd4440 100644 --- a/sys/i386/i386/elf_machdep.c +++ b/sys/i386/i386/elf_machdep.c @@ -26,6 +26,8 @@ #include <sys/cdefs.h> __FBSDID("$FreeBSD$"); +#include "opt_cpu.h" + #include <sys/param.h> #include <sys/kernel.h> #include <sys/systm.h> @@ -45,6 +47,11 @@ __FBSDID("$FreeBSD$"); #include <machine/elf.h> #include <machine/md_var.h> +#include <machine/npx.h> + +#if !defined(CPU_DISABLE_SSE) && defined(I686_CPU) +#define CPU_ENABLE_SSE +#endif struct sysentvec elf32_freebsd_sysvec = { .sv_size = SYS_MAXSYSCALL, @@ -134,12 +141,31 @@ SYSINIT(kelf32, SI_SUB_EXEC, SI_ORDER_ANY, void -elf32_dump_thread(struct thread *td __unused, void *dst __unused, - size_t *off __unused) +elf32_dump_thread(struct thread *td, void *dst, size_t *off) { +#ifdef CPU_ENABLE_SSE + void *buf; +#endif + size_t len; + + len = 0; +#ifdef CPU_ENABLE_SSE + if (use_xsave) { + if (dst != NULL) { + npxgetregs(td); + len += elf32_populate_note(NT_X86_XSTATE, + get_pcb_user_save_td(td), dst, + cpu_max_ext_state_size, &buf); + *(uint64_t *)((char *)buf + X86_XSTATE_XCR0_OFFSET) = + xsave_mask; + } else + len += elf32_populate_note(NT_X86_XSTATE, NULL, NULL, + cpu_max_ext_state_size, NULL); + } +#endif + *off = len; } - /* Process one elf relocation with addend. */ static int elf_reloc_internal(linker_file_t lf, Elf_Addr relocbase, const void *data, diff --git a/sys/i386/i386/ptrace_machdep.c b/sys/i386/i386/ptrace_machdep.c index 870d69b..e6248a2 100644 --- a/sys/i386/i386/ptrace_machdep.c +++ b/sys/i386/i386/ptrace_machdep.c @@ -46,6 +46,7 @@ __FBSDID("$FreeBSD$"); static int cpu_ptrace_xstate(struct thread *td, int req, void *addr, int data) { + struct ptrace_xstate_info info; char *savefpu; int error; @@ -53,14 +54,14 @@ cpu_ptrace_xstate(struct thread *td, int req, void *addr, int data) return (EOPNOTSUPP); switch (req) { - case PT_GETXSTATE: + case PT_GETXSTATE_OLD: npxgetregs(td); savefpu = (char *)(get_pcb_user_save_td(td) + 1); error = copyout(savefpu, addr, cpu_max_ext_state_size - sizeof(union savefpu)); break; - case PT_SETXSTATE: + case PT_SETXSTATE_OLD: if (data > cpu_max_ext_state_size - sizeof(union savefpu)) { error = EINVAL; break; @@ -74,6 +75,37 @@ cpu_ptrace_xstate(struct thread *td, int req, void *addr, int data) free(savefpu, M_TEMP); break; + case PT_GETXSTATE_INFO: + if (data != sizeof(info)) { + error = EINVAL; + break; + } + info.xsave_len = cpu_max_ext_state_size; + info.xsave_mask = xsave_mask; + error = copyout(&info, addr, data); + break; + + case PT_GETXSTATE: + npxgetregs(td); + savefpu = (char *)(get_pcb_user_save_td(td)); + error = copyout(savefpu, addr, cpu_max_ext_state_size); + break; + + case PT_SETXSTATE: + if (data < sizeof(union savefpu) || + data > cpu_max_ext_state_size) { + error = EINVAL; + break; + } + savefpu = malloc(data, M_TEMP, M_WAITOK); + error = copyin(addr, savefpu, data); + if (error == 0) + error = npxsetregs(td, (union savefpu *)savefpu, + savefpu + sizeof(union savefpu), data - + sizeof(union savefpu)); + free(savefpu, M_TEMP); + break; + default: error = EINVAL; break; @@ -106,6 +138,9 @@ cpu_ptrace(struct thread *td, int req, void *addr, int data) fpstate->sv_env.en_mxcsr &= cpu_mxcsr_mask; break; + case PT_GETXSTATE_OLD: + case PT_SETXSTATE_OLD: + case PT_GETXSTATE_INFO: case PT_GETXSTATE: case PT_SETXSTATE: error = cpu_ptrace_xstate(td, req, addr, data); |