2 * Copyright (C) 2000, 2001, 2002 Jeff Dike (jdike@karaya.com)
3 * Licensed under the GPL
6 #include <linux/config.h>
7 #include <linux/compiler.h>
8 #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 void arch_switch(void)
19 update_debugregs(current->thread.arch.debugregs_seq);
22 int is_syscall(unsigned long addr)
27 n = copy_from_user(&instr, (void __user *) addr, sizeof(instr));
29 printk("is_syscall : failed to read instruction from 0x%lx\n",
33 /* int 0x80 or sysenter */
34 return((instr == 0x80cd) || (instr == 0x340f));
37 /* determines which flags the user has access to. */
38 /* 1 = access 0 = no access */
39 #define FLAG_MASK 0x00044dd5
41 int putreg(struct task_struct *child, int regno, unsigned long value)
46 if (value && (value & 3) != 3)
48 PT_REGS_FS(&child->thread.regs) = value;
51 if (value && (value & 3) != 3)
53 PT_REGS_GS(&child->thread.regs) = value;
57 if (value && (value & 3) != 3)
69 value |= PT_REGS_EFLAGS(&child->thread.regs);
72 PT_REGS_SET(&child->thread.regs, regno, value);
76 unsigned long getreg(struct task_struct *child, int regno)
78 unsigned long retval = ~0UL;
91 retval &= PT_REG(&child->thread.regs, regno);
96 struct i387_fxsave_struct {
107 long st_space[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
108 long xmm_space[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
113 * FPU tag word conversions.
116 static inline unsigned short twd_i387_to_fxsr( unsigned short twd )
118 unsigned int tmp; /* to avoid 16 bit prefixes in the code */
120 /* Transform each pair of bits into 01 (valid) or 00 (empty) */
122 tmp = (tmp | (tmp>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
123 /* and move the valid bits to the lower byte. */
124 tmp = (tmp | (tmp >> 1)) & 0x3333; /* 00VV00VV00VV00VV */
125 tmp = (tmp | (tmp >> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
126 tmp = (tmp | (tmp >> 4)) & 0x00ff; /* 00000000VVVVVVVV */
130 static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct *fxsave )
132 struct _fpxreg *st = NULL;
133 unsigned long twd = (unsigned long) fxsave->twd;
135 unsigned long ret = 0xffff0000;
138 #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
140 for ( i = 0 ; i < 8 ; i++ ) {
142 st = (struct _fpxreg *) FPREG_ADDR( fxsave, i );
144 switch ( st->exponent & 0x7fff ) {
146 tag = 2; /* Special */
149 if ( !st->significand[0] &&
150 !st->significand[1] &&
151 !st->significand[2] &&
152 !st->significand[3] ) {
155 tag = 2; /* Special */
159 if ( st->significand[3] & 0x8000 ) {
162 tag = 2; /* Special */
169 ret |= (tag << (2 * i));
176 * FXSR floating point environment conversions.
179 #ifdef CONFIG_MODE_TT
180 static inline int convert_fxsr_to_user_tt(struct _fpstate __user *buf,
181 struct pt_regs *regs)
183 struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
184 unsigned long env[7];
185 struct _fpreg __user *to;
186 struct _fpxreg *from;
189 env[0] = (unsigned long)fxsave->cwd | 0xffff0000;
190 env[1] = (unsigned long)fxsave->swd | 0xffff0000;
191 env[2] = twd_fxsr_to_i387(fxsave);
192 env[3] = fxsave->fip;
193 env[4] = fxsave->fcs | ((unsigned long)fxsave->fop << 16);
194 env[5] = fxsave->foo;
195 env[6] = fxsave->fos;
197 if ( __copy_to_user( buf, env, 7 * sizeof(unsigned long) ) )
201 from = (struct _fpxreg *) &fxsave->st_space[0];
202 for ( i = 0 ; i < 8 ; i++, to++, from++ ) {
203 if ( __copy_to_user( to, from, sizeof(*to) ) )
210 static inline int convert_fxsr_to_user(struct _fpstate __user *buf,
211 struct pt_regs *regs)
213 return(CHOOSE_MODE(convert_fxsr_to_user_tt(buf, regs), 0));
216 #ifdef CONFIG_MODE_TT
217 static inline int convert_fxsr_from_user_tt(struct pt_regs *regs,
218 struct _fpstate __user *buf)
220 struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
221 unsigned long env[7];
223 struct _fpreg __user *from;
226 if ( __copy_from_user( env, buf, 7 * sizeof(long) ) )
229 fxsave->cwd = (unsigned short)(env[0] & 0xffff);
230 fxsave->swd = (unsigned short)(env[1] & 0xffff);
231 fxsave->twd = twd_i387_to_fxsr((unsigned short)(env[2] & 0xffff));
232 fxsave->fip = env[3];
233 fxsave->fop = (unsigned short)((env[4] & 0xffff0000) >> 16);
234 fxsave->fcs = (env[4] & 0xffff);
235 fxsave->foo = env[5];
236 fxsave->fos = env[6];
238 to = (struct _fpxreg *) &fxsave->st_space[0];
240 for ( i = 0 ; i < 8 ; i++, to++, from++ ) {
241 if ( __copy_from_user( to, from, sizeof(*from) ) )
248 static inline int convert_fxsr_from_user(struct pt_regs *regs,
249 struct _fpstate __user *buf)
251 return(CHOOSE_MODE(convert_fxsr_from_user_tt(regs, buf), 0));
254 int get_fpregs(unsigned long buf, struct task_struct *child)
258 err = convert_fxsr_to_user((struct _fpstate __user *) buf,
259 &child->thread.regs);
260 if(err) return(-EFAULT);
264 int set_fpregs(unsigned long buf, struct task_struct *child)
268 err = convert_fxsr_from_user(&child->thread.regs,
269 (struct _fpstate __user *) buf);
270 if(err) return(-EFAULT);
274 #ifdef CONFIG_MODE_TT
275 int get_fpxregs_tt(unsigned long buf, struct task_struct *tsk)
277 struct pt_regs *regs = &tsk->thread.regs;
278 struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
281 err = __copy_to_user((void __user *) buf, fxsave,
282 sizeof(struct user_fxsr_struct));
283 if(err) return -EFAULT;
288 int get_fpxregs(unsigned long buf, struct task_struct *tsk)
290 return(CHOOSE_MODE(get_fpxregs_tt(buf, tsk), 0));
293 #ifdef CONFIG_MODE_TT
294 int set_fpxregs_tt(unsigned long buf, struct task_struct *tsk)
296 struct pt_regs *regs = &tsk->thread.regs;
297 struct i387_fxsave_struct *fxsave = SC_FXSR_ENV(PT_REGS_SC(regs));
300 err = __copy_from_user(fxsave, (void __user *) buf,
301 sizeof(struct user_fxsr_struct) );
302 if(err) return -EFAULT;
307 int set_fpxregs(unsigned long buf, struct task_struct *tsk)
309 return(CHOOSE_MODE(set_fpxregs_tt(buf, tsk), 0));
313 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu)
315 fpu->cwd = (((SC_FP_CW(PT_REGS_SC(regs)) & 0xffff) << 16) |
316 (SC_FP_SW(PT_REGS_SC(regs)) & 0xffff));
317 fpu->swd = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
318 fpu->twd = SC_FP_IPOFF(PT_REGS_SC(regs));
319 fpu->fip = SC_FP_CSSEL(PT_REGS_SC(regs)) & 0xffff;
320 fpu->fcs = SC_FP_DATAOFF(PT_REGS_SC(regs));
321 fpu->foo = SC_FP_DATASEL(PT_REGS_SC(regs));
323 memcpy(fpu->st_space, (void *) SC_FP_ST(PT_REGS_SC(regs)),
324 sizeof(fpu->st_space));
329 #ifdef CONFIG_MODE_TT
330 static inline void copy_fpu_fxsave_tt(struct pt_regs *regs,
331 struct user_i387_struct *buf)
333 struct i387_fxsave_struct *fpu = SC_FXSR_ENV(PT_REGS_SC(regs));
335 unsigned short *from;
338 memcpy( buf, fpu, 7 * sizeof(long) );
340 to = (unsigned short *) &buf->st_space[0];
341 from = (unsigned short *) &fpu->st_space[0];
342 for ( i = 0 ; i < 8 ; i++, to += 5, from += 8 ) {
343 memcpy( to, from, 5 * sizeof(unsigned short) );
348 static inline void copy_fpu_fxsave(struct pt_regs *regs,
349 struct user_i387_struct *buf)
351 (void) CHOOSE_MODE(copy_fpu_fxsave_tt(regs, buf), 0);
354 int dump_fpu(struct pt_regs *regs, elf_fpregset_t *fpu )
356 copy_fpu_fxsave(regs, (struct user_i387_struct *) fpu);
361 * Overrides for Emacs so that we follow Linus's tabbing style.
362 * Emacs will notice this stuff at the end of the file and automatically
363 * adjust the settings for this buffer only. This must remain at the end
365 * ---------------------------------------------------------------------------
367 * c-file-style: "linux"