uml: remove code made redundant by CHOOSE_MODE removal
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / arch / um / sys-i386 / ptrace.c
blobdcf0c6b310c84671da7a77c446059f19293a279f
1 /*
2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
4 */
6 #include <linux/compiler.h>
7 #include "linux/sched.h"
8 #include "linux/mm.h"
9 #include "asm/elf.h"
10 #include "asm/ptrace.h"
11 #include "asm/uaccess.h"
12 #include "asm/unistd.h"
13 #include "sysdep/ptrace.h"
14 #include "sysdep/sigcontext.h"
15 #include "sysdep/sc.h"
17 extern int arch_switch_tls(struct task_struct *from, struct task_struct *to);
19 void arch_switch_to(struct task_struct *from, struct task_struct *to)
21 int err = arch_switch_tls(from, to);
22 if (!err)
23 return;
25 if (err != -EINVAL)
26 printk(KERN_WARNING "arch_switch_tls failed, errno %d, not EINVAL\n", -err);
27 else
28 printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
31 int is_syscall(unsigned long addr)
33 unsigned short instr;
34 int n;
36 n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
37 if(n){
38 /* access_process_vm() grants access to vsyscall and stub,
39 * while copy_from_user doesn't. Maybe access_process_vm is
40 * slow, but that doesn't matter, since it will be called only
41 * in case of singlestepping, if copy_from_user failed.
43 n = access_process_vm(current, addr, &instr, sizeof(instr), 0);
44 if(n != sizeof(instr)) {
45 printk("is_syscall : failed to read instruction from "
46 "0x%lx\n", addr);
47 return(1);
50 /* int 0x80 or sysenter */
51 return((instr == 0x80cd) || (instr == 0x340f));
54 /* determines which flags the user has access to. */
55 /* 1 = access 0 = no access */
56 #define FLAG_MASK 0x00044dd5
58 int putreg(struct task_struct *child, int regno, unsigned long value)
60 regno >>= 2;
61 switch (regno) {
62 case FS:
63 if (value && (value & 3) != 3)
64 return -EIO;
65 PT_REGS_FS(&child->thread.regs) = value;
66 return 0;
67 case GS:
68 if (value && (value & 3) != 3)
69 return -EIO;
70 PT_REGS_GS(&child->thread.regs) = value;
71 return 0;
72 case DS:
73 case ES:
74 if (value && (value & 3) != 3)
75 return -EIO;
76 value &= 0xffff;
77 break;
78 case SS:
79 case CS:
80 if ((value & 3) != 3)
81 return -EIO;
82 value &= 0xffff;
83 break;
84 case EFL:
85 value &= FLAG_MASK;
86 value |= PT_REGS_EFLAGS(&child->thread.regs);
87 break;
89 PT_REGS_SET(&child->thread.regs, regno, value);
90 return 0;
93 int poke_user(struct task_struct *child, long addr, long data)
95 if ((addr & 3) || addr < 0)
96 return -EIO;
98 if (addr < MAX_REG_OFFSET)
99 return putreg(child, addr, data);
101 else if((addr >= offsetof(struct user, u_debugreg[0])) &&
102 (addr <= offsetof(struct user, u_debugreg[7]))){
103 addr -= offsetof(struct user, u_debugreg[0]);
104 addr = addr >> 2;
105 if((addr == 4) || (addr == 5)) return -EIO;
106 child->thread.arch.debugregs[addr] = data;
107 return 0;
109 return -EIO;
112 unsigned long getreg(struct task_struct *child, int regno)
114 unsigned long retval = ~0UL;
116 regno >>= 2;
117 switch (regno) {
118 case FS:
119 case GS:
120 case DS:
121 case ES:
122 case SS:
123 case CS:
124 retval = 0xffff;
125 /* fall through */
126 default:
127 retval &= PT_REG(&child->thread.regs, regno);
129 return retval;
132 int peek_user(struct task_struct *child, long addr, long data)
134 /* read the word at location addr in the USER area. */
135 unsigned long tmp;
137 if ((addr & 3) || addr < 0)
138 return -EIO;
140 tmp = 0; /* Default return condition */
141 if(addr < MAX_REG_OFFSET){
142 tmp = getreg(child, addr);
144 else if((addr >= offsetof(struct user, u_debugreg[0])) &&
145 (addr <= offsetof(struct user, u_debugreg[7]))){
146 addr -= offsetof(struct user, u_debugreg[0]);
147 addr = addr >> 2;
148 tmp = child->thread.arch.debugregs[addr];
150 return put_user(tmp, (unsigned long __user *) data);
153 struct i387_fxsave_struct {
154 unsigned short cwd;
155 unsigned short swd;
156 unsigned short twd;
157 unsigned short fop;
158 long fip;
159 long fcs;
160 long foo;
161 long fos;
162 long mxcsr;
163 long reserved;
164 long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
165 long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
166 long padding[56];
170 * FPU tag word conversions.
173 static inline unsigned short twd_i387_to_fxsr( unsigned short twd )
175 unsigned int tmp; /* to avoid 16 bit prefixes in the code */
177 /* Transform each pair of bits into 01 (valid) or 00 (empty) */
178 tmp = ~twd;
179 tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
180 /* and move the valid bits to the lower byte. */
181 tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */
182 tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
183 tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */
184 return tmp;
187 static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave )
189 struct _fpxreg *st = NULL;
190 unsigned long twd = (unsigned long) fxsave->twd;
191 unsigned long tag;
192 unsigned long ret = 0xffff0000;
193 int i;
195 #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
197 for ( i = 0 ; i < 8 ; i++ ) {
198 if ( twd & 0x1 ) {
199 st = (struct _fpxreg *) FPREG_ADDR( fxsave, i );
201 switch ( st->exponent & 0x7fff ) {
202 case 0x7fff:
203 tag = 2; /* Special */
204 break;
205 case 0x0000:
206 if ( !st->significand[0] &&
207 !st->significand[1] &&
208 !st->significand[2] &&
209 !st->significand[3] ) {
210 tag = 1; /* Zero */
211 } else {
212 tag = 2; /* Special */
214 break;
215 default:
216 if ( st->significand[3] & 0x8000 ) {
217 tag = 0; /* Valid */
218 } else {
219 tag = 2; /* Special */
221 break;
223 } else {
224 tag = 3; /* Empty */
226 ret |= (tag << (2 * i));
227 twd = twd >> 1;
229 return ret;
232 static inline int convert_fxsr_to_user(struct _fpstate __user *buf,
233 struct pt_regs *regs)
235 return 0;
238 static inline int convert_fxsr_from_user(struct pt_regs *regs,
239 struct _fpstate __user *buf)
241 return 0;
244 int get_fpregs(unsigned long buf, struct task_struct *child)
246 int err;
248 err = convert_fxsr_to_user((struct _fpstate __user *) buf,
249 &child->thread.regs);
250 if(err) return(-EFAULT);
251 else return(0);
254 int set_fpregs(unsigned long buf, struct task_struct *child)
256 int err;
258 err = convert_fxsr_from_user(&child->thread.regs,
259 (struct _fpstate __user *) buf);
260 if(err) return(-EFAULT);
261 else return(0);
264 int get_fpxregs(unsigned long buf, struct task_struct *tsk)
266 return 0;
269 int set_fpxregs(unsigned long buf, struct task_struct *tsk)
271 return 0;
274 #ifdef notdef
275 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
277 fpu->cwd = (((SC_FP_CW(PT_REGS_SC(regs)) & 0xffff) << 16) |
278 (SC_FP_SW(PT_REGS_SC(regs)) & 0xffff));
279 fpu->swd = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
280 fpu->twd = SC_FP_IPOFF(PT_REGS_SC(regs));
281 fpu->fip = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
282 fpu->fcs = SC_FP_DATAOFF(PT_REGS_SC(regs));
283 fpu->foo = SC_FP_DATASEL(PT_REGS_SC(regs));
284 fpu->fos = 0;
285 memcpy(fpu->st_space, (void *) SC_FP_ST(PT_REGS_SC(regs)),
286 sizeof(fpu->st_space));
287 return(1);
289 #endif
291 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
293 return 1;
297 * Overrides for Emacs so that we follow Linus's tabbing style.
298 * Emacs will notice this stuff at the end of the file and automatically
299 * adjust the settings for this buffer only. This must remain at the end
300 * of the file.
301 * ---------------------------------------------------------------------------
302 * Local variables:
303 * c-file-style: "linux"
304 * End: