2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include <linux/compiler.h>
7 #include "linux/sched.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);
26 printk(KERN_WARNING "arch_switch_tls failed, errno %d, not EINVAL\n", -err);
28 printk(KERN_WARNING "arch_switch_tls failed, errno = EINVAL\n");
31 int is_syscall(unsigned long addr)
36 n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
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 "
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)
63 if (value && (value & 3) != 3)
65 PT_REGS_FS(&child->thread.regs) = value;
68 if (value && (value & 3) != 3)
70 PT_REGS_GS(&child->thread.regs) = value;
74 if (value && (value & 3) != 3)
86 value |= PT_REGS_EFLAGS(&child->thread.regs);
89 PT_REGS_SET(&child->thread.regs, regno, value);
93 int poke_user(struct task_struct *child, long addr, long data)
95 if ((addr & 3) || addr < 0)
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]);
105 if((addr == 4) || (addr == 5)) return -EIO;
106 child->thread.arch.debugregs[addr] = data;
112 unsigned long getreg(struct task_struct *child, int regno)
114 unsigned long retval = ~0UL;
127 retval &= PT_REG(&child->thread.regs, regno);
132 int peek_user(struct task_struct *child, long addr, long data)
134 /* read the word at location addr in the USER area. */
137 if ((addr & 3) || addr < 0)
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]);
148 tmp = child->thread.arch.debugregs[addr];
150 return put_user(tmp, (unsigned long __user *) data);
153 struct i387_fxsave_struct {
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 */
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) */
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 */
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;
192 unsigned long ret = 0xffff0000;
195 #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
197 for ( i = 0 ; i < 8 ; i++ ) {
199 st = (struct _fpxreg *) FPREG_ADDR( fxsave, i );
201 switch ( st->exponent & 0x7fff ) {
203 tag = 2; /* Special */
206 if ( !st->significand[0] &&
207 !st->significand[1] &&
208 !st->significand[2] &&
209 !st->significand[3] ) {
212 tag = 2; /* Special */
216 if ( st->significand[3] & 0x8000 ) {
219 tag = 2; /* Special */
226 ret |= (tag << (2 * i));
232 static inline int convert_fxsr_to_user(struct _fpstate __user *buf,
233 struct pt_regs *regs)
238 static inline int convert_fxsr_from_user(struct pt_regs *regs,
239 struct _fpstate __user *buf)
244 int get_fpregs(unsigned long buf, struct task_struct *child)
248 err = convert_fxsr_to_user((struct _fpstate __user *) buf,
249 &child->thread.regs);
250 if(err) return(-EFAULT);
254 int set_fpregs(unsigned long buf, struct task_struct *child)
258 err = convert_fxsr_from_user(&child->thread.regs,
259 (struct _fpstate __user *) buf);
260 if(err) return(-EFAULT);
264 int get_fpxregs(unsigned long buf, struct task_struct *tsk)
269 int set_fpxregs(unsigned long buf, struct task_struct *tsk)
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));
285 memcpy(fpu->st_space, (void *) SC_FP_ST(PT_REGS_SC(regs)),
286 sizeof(fpu->st_space));
291 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
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
301 * ---------------------------------------------------------------------------
303 * c-file-style: "linux"