]>
git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blob - arch/um/sys-i386/ptrace.c
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"
11 #include "asm/ptrace.h"
12 #include "asm/uaccess.h"
13 #include "asm/unistd.h"
14 #include "sysdep/ptrace.h"
15 #include "sysdep/sigcontext.h"
16 #include "sysdep/sc.h"
18 void arch_switch_to_tt(struct task_struct
*from
, struct task_struct
*to
)
20 update_debugregs(to
->thread
.arch
.debugregs_seq
);
21 arch_switch_tls_tt(from
, to
);
24 void arch_switch_to_skas(struct task_struct
*from
, struct task_struct
*to
)
26 int err
= arch_switch_tls_skas(from
, to
);
31 printk(KERN_WARNING
"arch_switch_tls_skas failed, errno %d, not EINVAL\n", -err
);
33 printk(KERN_WARNING
"arch_switch_tls_skas failed, errno = EINVAL\n");
36 int is_syscall(unsigned long addr
)
41 n
= copy_from_user(&instr
, (void __user
*) addr
, sizeof(instr
));
43 /* access_process_vm() grants access to vsyscall and stub,
44 * while copy_from_user doesn't. Maybe access_process_vm is
45 * slow, but that doesn't matter, since it will be called only
46 * in case of singlestepping, if copy_from_user failed.
48 n
= access_process_vm(current
, addr
, &instr
, sizeof(instr
), 0);
49 if(n
!= sizeof(instr
)) {
50 printk("is_syscall : failed to read instruction from "
55 /* int 0x80 or sysenter */
56 return((instr
== 0x80cd) || (instr
== 0x340f));
59 /* determines which flags the user has access to. */
60 /* 1 = access 0 = no access */
61 #define FLAG_MASK 0x00044dd5
63 int putreg(struct task_struct
*child
, int regno
, unsigned long value
)
68 if (value
&& (value
& 3) != 3)
70 PT_REGS_FS(&child
->thread
.regs
) = value
;
73 if (value
&& (value
& 3) != 3)
75 PT_REGS_GS(&child
->thread
.regs
) = value
;
79 if (value
&& (value
& 3) != 3)
91 value
|= PT_REGS_EFLAGS(&child
->thread
.regs
);
94 PT_REGS_SET(&child
->thread
.regs
, regno
, value
);
98 int poke_user(struct task_struct
*child
, long addr
, long data
)
100 if ((addr
& 3) || addr
< 0)
103 if (addr
< MAX_REG_OFFSET
)
104 return putreg(child
, addr
, data
);
106 else if((addr
>= offsetof(struct user
, u_debugreg
[0])) &&
107 (addr
<= offsetof(struct user
, u_debugreg
[7]))){
108 addr
-= offsetof(struct user
, u_debugreg
[0]);
110 if((addr
== 4) || (addr
== 5)) return -EIO
;
111 child
->thread
.arch
.debugregs
[addr
] = data
;
117 unsigned long getreg(struct task_struct
*child
, int regno
)
119 unsigned long retval
= ~0UL;
132 retval
&= PT_REG(&child
->thread
.regs
, regno
);
137 int peek_user(struct task_struct
*child
, long addr
, long data
)
139 /* read the word at location addr in the USER area. */
142 if ((addr
& 3) || addr
< 0)
145 tmp
= 0; /* Default return condition */
146 if(addr
< MAX_REG_OFFSET
){
147 tmp
= getreg(child
, addr
);
149 else if((addr
>= offsetof(struct user
, u_debugreg
[0])) &&
150 (addr
<= offsetof(struct user
, u_debugreg
[7]))){
151 addr
-= offsetof(struct user
, u_debugreg
[0]);
153 tmp
= child
->thread
.arch
.debugregs
[addr
];
155 return put_user(tmp
, (unsigned long __user
*) data
);
158 struct i387_fxsave_struct
{
169 long st_space
[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
170 long xmm_space
[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
175 * FPU tag word conversions.
178 static inline unsigned short twd_i387_to_fxsr( unsigned short twd
)
180 unsigned int tmp
; /* to avoid 16 bit prefixes in the code */
182 /* Transform each pair of bits into 01 (valid) or 00 (empty) */
184 tmp
= (tmp
| (tmp
>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
185 /* and move the valid bits to the lower byte. */
186 tmp
= (tmp
| (tmp
>> 1)) & 0x3333; /* 00VV00VV00VV00VV */
187 tmp
= (tmp
| (tmp
>> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
188 tmp
= (tmp
| (tmp
>> 4)) & 0x00ff; /* 00000000VVVVVVVV */
192 static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct
*fxsave
)
194 struct _fpxreg
*st
= NULL
;
195 unsigned long twd
= (unsigned long) fxsave
->twd
;
197 unsigned long ret
= 0xffff0000;
200 #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
202 for ( i
= 0 ; i
< 8 ; i
++ ) {
204 st
= (struct _fpxreg
*) FPREG_ADDR( fxsave
, i
);
206 switch ( st
->exponent
& 0x7fff ) {
208 tag
= 2; /* Special */
211 if ( !st
->significand
[0] &&
212 !st
->significand
[1] &&
213 !st
->significand
[2] &&
214 !st
->significand
[3] ) {
217 tag
= 2; /* Special */
221 if ( st
->significand
[3] & 0x8000 ) {
224 tag
= 2; /* Special */
231 ret
|= (tag
<< (2 * i
));
238 * FXSR floating point environment conversions.
241 #ifdef CONFIG_MODE_TT
242 static inline int convert_fxsr_to_user_tt(struct _fpstate __user
*buf
,
243 struct pt_regs
*regs
)
245 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
246 unsigned long env
[7];
247 struct _fpreg __user
*to
;
248 struct _fpxreg
*from
;
251 env
[0] = (unsigned long)fxsave
->cwd
| 0xffff0000;
252 env
[1] = (unsigned long)fxsave
->swd
| 0xffff0000;
253 env
[2] = twd_fxsr_to_i387(fxsave
);
254 env
[3] = fxsave
->fip
;
255 env
[4] = fxsave
->fcs
| ((unsigned long)fxsave
->fop
<< 16);
256 env
[5] = fxsave
->foo
;
257 env
[6] = fxsave
->fos
;
259 if ( __copy_to_user( buf
, env
, 7 * sizeof(unsigned long) ) )
263 from
= (struct _fpxreg
*) &fxsave
->st_space
[0];
264 for ( i
= 0 ; i
< 8 ; i
++, to
++, from
++ ) {
265 if ( __copy_to_user( to
, from
, sizeof(*to
) ) )
272 static inline int convert_fxsr_to_user(struct _fpstate __user
*buf
,
273 struct pt_regs
*regs
)
275 return(CHOOSE_MODE(convert_fxsr_to_user_tt(buf
, regs
), 0));
278 #ifdef CONFIG_MODE_TT
279 static inline int convert_fxsr_from_user_tt(struct pt_regs
*regs
,
280 struct _fpstate __user
*buf
)
282 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
283 unsigned long env
[7];
285 struct _fpreg __user
*from
;
288 if ( __copy_from_user( env
, buf
, 7 * sizeof(long) ) )
291 fxsave
->cwd
= (unsigned short)(env
[0] & 0xffff);
292 fxsave
->swd
= (unsigned short)(env
[1] & 0xffff);
293 fxsave
->twd
= twd_i387_to_fxsr((unsigned short)(env
[2] & 0xffff));
294 fxsave
->fip
= env
[3];
295 fxsave
->fop
= (unsigned short)((env
[4] & 0xffff0000) >> 16);
296 fxsave
->fcs
= (env
[4] & 0xffff);
297 fxsave
->foo
= env
[5];
298 fxsave
->fos
= env
[6];
300 to
= (struct _fpxreg
*) &fxsave
->st_space
[0];
302 for ( i
= 0 ; i
< 8 ; i
++, to
++, from
++ ) {
303 if ( __copy_from_user( to
, from
, sizeof(*from
) ) )
310 static inline int convert_fxsr_from_user(struct pt_regs
*regs
,
311 struct _fpstate __user
*buf
)
313 return(CHOOSE_MODE(convert_fxsr_from_user_tt(regs
, buf
), 0));
316 int get_fpregs(unsigned long buf
, struct task_struct
*child
)
320 err
= convert_fxsr_to_user((struct _fpstate __user
*) buf
,
321 &child
->thread
.regs
);
322 if(err
) return(-EFAULT
);
326 int set_fpregs(unsigned long buf
, struct task_struct
*child
)
330 err
= convert_fxsr_from_user(&child
->thread
.regs
,
331 (struct _fpstate __user
*) buf
);
332 if(err
) return(-EFAULT
);
336 #ifdef CONFIG_MODE_TT
337 int get_fpxregs_tt(unsigned long buf
, struct task_struct
*tsk
)
339 struct pt_regs
*regs
= &tsk
->thread
.regs
;
340 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
343 err
= __copy_to_user((void __user
*) buf
, fxsave
,
344 sizeof(struct user_fxsr_struct
));
345 if(err
) return -EFAULT
;
350 int get_fpxregs(unsigned long buf
, struct task_struct
*tsk
)
352 return(CHOOSE_MODE(get_fpxregs_tt(buf
, tsk
), 0));
355 #ifdef CONFIG_MODE_TT
356 int set_fpxregs_tt(unsigned long buf
, struct task_struct
*tsk
)
358 struct pt_regs
*regs
= &tsk
->thread
.regs
;
359 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
362 err
= __copy_from_user(fxsave
, (void __user
*) buf
,
363 sizeof(struct user_fxsr_struct
) );
364 if(err
) return -EFAULT
;
369 int set_fpxregs(unsigned long buf
, struct task_struct
*tsk
)
371 return(CHOOSE_MODE(set_fpxregs_tt(buf
, tsk
), 0));
375 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
377 fpu
->cwd
= (((SC_FP_CW(PT_REGS_SC(regs
)) & 0xffff) << 16) |
378 (SC_FP_SW(PT_REGS_SC(regs
)) & 0xffff));
379 fpu
->swd
= SC_FP_CSSEL(PT_REGS_SC(regs
)) & 0xffff;
380 fpu
->twd
= SC_FP_IPOFF(PT_REGS_SC(regs
));
381 fpu
->fip
= SC_FP_CSSEL(PT_REGS_SC(regs
)) & 0xffff;
382 fpu
->fcs
= SC_FP_DATAOFF(PT_REGS_SC(regs
));
383 fpu
->foo
= SC_FP_DATASEL(PT_REGS_SC(regs
));
385 memcpy(fpu
->st_space
, (void *) SC_FP_ST(PT_REGS_SC(regs
)),
386 sizeof(fpu
->st_space
));
391 #ifdef CONFIG_MODE_TT
392 static inline void copy_fpu_fxsave_tt(struct pt_regs
*regs
,
393 struct user_i387_struct
*buf
)
395 struct i387_fxsave_struct
*fpu
= SC_FXSR_ENV(PT_REGS_SC(regs
));
397 unsigned short *from
;
400 memcpy( buf
, fpu
, 7 * sizeof(long) );
402 to
= (unsigned short *) &buf
->st_space
[0];
403 from
= (unsigned short *) &fpu
->st_space
[0];
404 for ( i
= 0 ; i
< 8 ; i
++, to
+= 5, from
+= 8 ) {
405 memcpy( to
, from
, 5 * sizeof(unsigned short) );
410 static inline void copy_fpu_fxsave(struct pt_regs
*regs
,
411 struct user_i387_struct
*buf
)
413 (void) CHOOSE_MODE(copy_fpu_fxsave_tt(regs
, buf
), 0);
416 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
418 copy_fpu_fxsave(regs
, (struct user_i387_struct
*) fpu
);
423 * Overrides for Emacs so that we follow Linus's tabbing style.
424 * Emacs will notice this stuff at the end of the file and automatically
425 * adjust the settings for this buffer only. This must remain at the end
427 * ---------------------------------------------------------------------------
429 * c-file-style: "linux"