Blame view

arch/x86/um/os-Linux/registers.c 2.1 KB
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
1
2
  /*
   * Copyright (C) 2004 PathScale, Inc
f0c4cad99   Jeff Dike   uml: style fixes ...
3
   * Copyright (C) 2004 - 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
4
5
6
7
   * Licensed under the GPL
   */
  
  #include <errno.h>
3787fa6df   Al Viro   fix include order...
8
  #include <sys/ptrace.h>
38b64aed7   Richard Weinberger   um: we need sys/u...
9
  #ifdef __i386__
14c8a77e1   Jeff Dike   uml: remove inclu...
10
  #include <sys/user.h>
38b64aed7   Richard Weinberger   um: we need sys/u...
11
  #endif
13c06be39   Jeff Dike   [PATCH] uml: Use ...
12
  #include "longjmp.h"
f0c4cad99   Jeff Dike   uml: style fixes ...
13
  #include "sysdep/ptrace_user.h"
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
14

1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
15
16
  int save_fp_registers(int pid, unsigned long *fp_regs)
  {
f0c4cad99   Jeff Dike   uml: style fixes ...
17
  	if (ptrace(PTRACE_GETFPREGS, pid, 0, fp_regs) < 0)
6c59e2f59   Jeff Dike   [PATCH] uml: regi...
18
19
  		return -errno;
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
20
21
22
23
  }
  
  int restore_fp_registers(int pid, unsigned long *fp_regs)
  {
f0c4cad99   Jeff Dike   uml: style fixes ...
24
  	if (ptrace(PTRACE_SETFPREGS, pid, 0, fp_regs) < 0)
6c59e2f59   Jeff Dike   [PATCH] uml: regi...
25
26
  		return -errno;
  	return 0;
1da177e4c   Linus Torvalds   Linux-2.6.12-rc2
27
  }
51d347490   Al Viro   um: merge arch/um...
28
29
  #ifdef __i386__
  int have_fpx_regs = 1;
a5f6096c8   Jeff Dike   uml: floating poi...
30
31
  int save_fpx_registers(int pid, unsigned long *fp_regs)
  {
f0c4cad99   Jeff Dike   uml: style fixes ...
32
  	if (ptrace(PTRACE_GETFPXREGS, pid, 0, fp_regs) < 0)
a5f6096c8   Jeff Dike   uml: floating poi...
33
34
35
36
37
38
  		return -errno;
  	return 0;
  }
  
  int restore_fpx_registers(int pid, unsigned long *fp_regs)
  {
f0c4cad99   Jeff Dike   uml: style fixes ...
39
  	if (ptrace(PTRACE_SETFPXREGS, pid, 0, fp_regs) < 0)
a5f6096c8   Jeff Dike   uml: floating poi...
40
41
42
  		return -errno;
  	return 0;
  }
2f56debd7   Jeff Dike   uml: fix FP regis...
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
  int get_fp_registers(int pid, unsigned long *regs)
  {
  	if (have_fpx_regs)
  		return save_fpx_registers(pid, regs);
  	else
  		return save_fp_registers(pid, regs);
  }
  
  int put_fp_registers(int pid, unsigned long *regs)
  {
  	if (have_fpx_regs)
  		return restore_fpx_registers(pid, regs);
  	else
  		return restore_fp_registers(pid, regs);
  }
a5f6096c8   Jeff Dike   uml: floating poi...
58
59
  void arch_init_registers(int pid)
  {
14c8a77e1   Jeff Dike   uml: remove inclu...
60
  	struct user_fpxregs_struct fpx_regs;
a5f6096c8   Jeff Dike   uml: floating poi...
61
  	int err;
47906dd9e   Jeff Dike   uml: tidy ptrace ...
62
  	err = ptrace(PTRACE_GETFPXREGS, pid, 0, &fpx_regs);
5134d8fea   Jeff Dike   uml: style fixes ...
63
  	if (!err)
a5f6096c8   Jeff Dike   uml: floating poi...
64
  		return;
5134d8fea   Jeff Dike   uml: style fixes ...
65
  	if (errno != EIO)
a5f6096c8   Jeff Dike   uml: floating poi...
66
67
68
69
70
  		panic("check_ptrace : PTRACE_GETFPXREGS failed, errno = %d",
  		      errno);
  
  	have_fpx_regs = 0;
  }
51d347490   Al Viro   um: merge arch/um...
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
  #else
  
  int get_fp_registers(int pid, unsigned long *regs)
  {
  	return save_fp_registers(pid, regs);
  }
  
  int put_fp_registers(int pid, unsigned long *regs)
  {
  	return restore_fp_registers(pid, regs);
  }
  
  #endif
  
  unsigned long get_thread_reg(int reg, jmp_buf *buf)
  {
  	switch (reg) {
  #ifdef __i386__
a10c95d84   Al Viro   um: unify KSTK_...
89
  	case HOST_IP:
51d347490   Al Viro   um: merge arch/um...
90
  		return buf[0]->__eip;
a10c95d84   Al Viro   um: unify KSTK_...
91
  	case HOST_SP:
51d347490   Al Viro   um: merge arch/um...
92
  		return buf[0]->__esp;
a10c95d84   Al Viro   um: unify KSTK_...
93
  	case HOST_BP:
51d347490   Al Viro   um: merge arch/um...
94
95
  		return buf[0]->__ebp;
  #else
a10c95d84   Al Viro   um: unify KSTK_...
96
  	case HOST_IP:
51d347490   Al Viro   um: merge arch/um...
97
  		return buf[0]->__rip;
a10c95d84   Al Viro   um: unify KSTK_...
98
  	case HOST_SP:
51d347490   Al Viro   um: merge arch/um...
99
  		return buf[0]->__rsp;
a10c95d84   Al Viro   um: unify KSTK_...
100
  	case HOST_BP:
51d347490   Al Viro   um: merge arch/um...
101
102
103
104
105
106
107
108
109
  		return buf[0]->__rbp;
  #endif
  	default:
  		printk(UM_KERN_ERR "get_thread_regs - unknown register %d
  ",
  		       reg);
  		return 0;
  	}
  }