2 * Copyright (C) 2004 PathScale, Inc
3 * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 * Licensed under the GPL
9 #include <sys/ptrace.h>
14 #include <sysdep/ptrace_user.h>
16 #include <asm/sigcontext.h>
17 #include <linux/elf.h>
19 int have_xstate_support;
21 int save_i387_registers(int pid, unsigned long *fp_regs)
23 if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
28 int save_fp_registers(int pid, unsigned long *fp_regs)
30 #ifdef PTRACE_GETREGSET
33 if (have_xstate_support) {
34 iov.iov_base = fp_regs;
35 iov.iov_len = FP_SIZE * sizeof(unsigned long);
36 if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
41 return save_i387_registers(pid, fp_regs);
44 int restore_i387_registers(int pid, unsigned long *fp_regs)
46 if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
51 int restore_fp_registers(int pid, unsigned long *fp_regs)
53 #ifdef PTRACE_SETREGSET
55 if (have_xstate_support) {
56 iov.iov_base = fp_regs;
57 iov.iov_len = FP_SIZE * sizeof(unsigned long);
58 if (ptrace(PTRACE_SETREGSET, pid, NT_X86_XSTATE, &iov) < 0)
63 return restore_i387_registers(pid, fp_regs);
67 int have_fpx_regs = 1;
68 int save_fpx_registers(int pid, unsigned long *fp_regs)
70 if (ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0)
75 int restore_fpx_registers(int pid, unsigned long *fp_regs)
77 if (ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0)
82 int get_fp_registers(int pid, unsigned long *regs)
85 return save_fpx_registers(pid, regs);
87 return save_fp_registers(pid, regs);
90 int put_fp_registers(int pid, unsigned long *regs)
93 return restore_fpx_registers(pid, regs);
95 return restore_fp_registers(pid, regs);
98 void arch_init_registers(int pid)
100 struct user_fpxregs_struct fpx_regs;
103 err = ptrace(PTRACE_GETFPXREGS, pid, 0, &fpx_regs);
108 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
115 int get_fp_registers(int pid, unsigned long *regs)
117 return save_fp_registers(pid, regs);
120 int put_fp_registers(int pid, unsigned long *regs)
122 return restore_fp_registers(pid, regs);
125 void arch_init_registers(int pid)
127 #ifdef PTRACE_GETREGSET
131 fp_regs = malloc(FP_SIZE * sizeof(unsigned long));
135 iov.iov_base = fp_regs;
136 iov.iov_len = FP_SIZE * sizeof(unsigned long);
137 if (ptrace(PTRACE_GETREGSET, pid, NT_X86_XSTATE, &iov) == 0)
138 have_xstate_support = 1;
145 unsigned long get_thread_reg(int reg, jmp_buf *buf)
150 return buf[0]->__eip;
152 return buf[0]->__esp;
154 return buf[0]->__ebp;
157 return buf[0]->__rip;
159 return buf[0]->__rsp;
161 return buf[0]->__rbp;
164 printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",