Linux 3.8-rc7
[cris-mirror.git] / arch / x86 / um / os-Linux / registers.c
blob41bfe84e11ab0e2bfad89a2e4e1d994f1c8fc288
1 /*
2 * Copyright (C) 2004 PathScale, Inc
3 * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
4 * Licensed under the GPL
5 */
7 #include <errno.h>
8 #include <sys/ptrace.h>
9 #ifdef __i386__
10 #include <sys/user.h>
11 #endif
12 #include <longjmp.h>
13 #include <sysdep/ptrace_user.h>
15 int save_fp_registers(int pid, unsigned long *fp_regs)
17 if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
18 return -errno;
19 return 0;
22 int restore_fp_registers(int pid, unsigned long *fp_regs)
24 if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
25 return -errno;
26 return 0;
29 #ifdef __i386__
30 int have_fpx_regs = 1;
31 int save_fpx_registers(int pid, unsigned long *fp_regs)
33 if (ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0)
34 return -errno;
35 return 0;
38 int restore_fpx_registers(int pid, unsigned long *fp_regs)
40 if (ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0)
41 return -errno;
42 return 0;
45 int get_fp_registers(int pid, unsigned long *regs)
47 if (have_fpx_regs)
48 return save_fpx_registers(pid, regs);
49 else
50 return save_fp_registers(pid, regs);
53 int put_fp_registers(int pid, unsigned long *regs)
55 if (have_fpx_regs)
56 return restore_fpx_registers(pid, regs);
57 else
58 return restore_fp_registers(pid, regs);
61 void arch_init_registers(int pid)
63 struct user_fpxregs_struct fpx_regs;
64 int err;
66 err = ptrace(PTRACE_GETFPXREGS, pid, 0, &fpx_regs);
67 if (!err)
68 return;
70 if (errno != EIO)
71 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
72 errno);
74 have_fpx_regs = 0;
76 #else
78 int get_fp_registers(int pid, unsigned long *regs)
80 return save_fp_registers(pid, regs);
83 int put_fp_registers(int pid, unsigned long *regs)
85 return restore_fp_registers(pid, regs);
88 #endif
90 unsigned long get_thread_reg(int reg, jmp_buf *buf)
92 switch (reg) {
93 #ifdef __i386__
94 case HOST_IP:
95 return buf[0]->__eip;
96 case HOST_SP:
97 return buf[0]->__esp;
98 case HOST_BP:
99 return buf[0]->__ebp;
100 #else
101 case HOST_IP:
102 return buf[0]->__rip;
103 case HOST_SP:
104 return buf[0]->__rsp;
105 case HOST_BP:
106 return buf[0]->__rbp;
107 #endif
108 default:
109 printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",
110 reg);
111 return 0;