c6183e7aec3d73cb2a4d0b70e27578b7a364afc1
[pandora-kernel.git] / arch / um / os-Linux / sys-i386 / registers.c
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  */
6
7 #include <errno.h>
8 #include <asm/user.h>
9 #include "kern_constants.h"
10 #include "longjmp.h"
11 #include "user.h"
12 #include "sysdep/ptrace_user.h"
13
14 int save_fp_registers(int pid, unsigned long *fp_regs)
15 {
16         if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
17                 return -errno;
18         return 0;
19 }
20
21 int restore_fp_registers(int pid, unsigned long *fp_regs)
22 {
23         if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
24                 return -errno;
25         return 0;
26 }
27
28 int save_fpx_registers(int pid, unsigned long *fp_regs)
29 {
30         if (ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0)
31                 return -errno;
32         return 0;
33 }
34
35 int restore_fpx_registers(int pid, unsigned long *fp_regs)
36 {
37         if (ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0)
38                 return -errno;
39         return 0;
40 }
41
42 unsigned long get_thread_reg(int reg, jmp_buf *buf)
43 {
44         switch (reg) {
45         case EIP:
46                 return buf[0]->__eip;
47         case UESP:
48                 return buf[0]->__esp;
49         case EBP:
50                 return buf[0]->__ebp;
51         default:
52                 printk(UM_KERN_ERR "get_thread_regs - unknown register %d\n",
53                        reg);
54                 return 0;
55         }
56 }
57
58 int have_fpx_regs = 1;
59
60 int get_fp_registers(int pid, unsigned long *regs)
61 {
62         if (have_fpx_regs)
63                 return save_fpx_registers(pid, regs);
64         else
65                 return save_fp_registers(pid, regs);
66 }
67
68 int put_fp_registers(int pid, unsigned long *regs)
69 {
70         if (have_fpx_regs)
71                 return restore_fpx_registers(pid, regs);
72         else
73                 return restore_fp_registers(pid, regs);
74 }
75
76 void arch_init_registers(int pid)
77 {
78         struct user_fxsr_struct fpx_regs;
79         int err;
80
81         err = ptrace(PTRACE_GETFPXREGS, pid, 0, &fpx_regs);
82         if (!err)
83                 return;
84
85         if (errno != EIO)
86                 panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
87                       errno);
88
89         have_fpx_regs = 0;
90 }