]>
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(void)
20 update_debugregs(current
->thread
.arch
.debugregs_seq
);
23 int is_syscall(unsigned long addr
)
28 n
= copy_from_user(&instr
, (void __user
*) addr
, sizeof(instr
));
30 /* access_process_vm() grants access to vsyscall and stub,
31 * while copy_from_user doesn't. Maybe access_process_vm is
32 * slow, but that doesn't matter, since it will be called only
33 * in case of singlestepping, if copy_from_user failed.
35 n
= access_process_vm(current
, addr
, &instr
, sizeof(instr
), 0);
36 if(n
!= sizeof(instr
)) {
37 printk("is_syscall : failed to read instruction from "
42 /* int 0x80 or sysenter */
43 return((instr
== 0x80cd) || (instr
== 0x340f));
46 /* determines which flags the user has access to. */
47 /* 1 = access 0 = no access */
48 #define FLAG_MASK 0x00044dd5
50 int putreg(struct task_struct
*child
, int regno
, unsigned long value
)
55 if (value
&& (value
& 3) != 3)
57 PT_REGS_FS(&child
->thread
.regs
) = value
;
60 if (value
&& (value
& 3) != 3)
62 PT_REGS_GS(&child
->thread
.regs
) = value
;
66 if (value
&& (value
& 3) != 3)
78 value
|= PT_REGS_EFLAGS(&child
->thread
.regs
);
81 PT_REGS_SET(&child
->thread
.regs
, regno
, value
);
85 int poke_user(struct task_struct
*child
, long addr
, long data
)
87 if ((addr
& 3) || addr
< 0)
90 if (addr
< MAX_REG_OFFSET
)
91 return putreg(child
, addr
, data
);
93 else if((addr
>= offsetof(struct user
, u_debugreg
[0])) &&
94 (addr
<= offsetof(struct user
, u_debugreg
[7]))){
95 addr
-= offsetof(struct user
, u_debugreg
[0]);
97 if((addr
== 4) || (addr
== 5)) return -EIO
;
98 child
->thread
.arch
.debugregs
[addr
] = data
;
104 unsigned long getreg(struct task_struct
*child
, int regno
)
106 unsigned long retval
= ~0UL;
119 retval
&= PT_REG(&child
->thread
.regs
, regno
);
124 int peek_user(struct task_struct
*child
, long addr
, long data
)
126 /* read the word at location addr in the USER area. */
129 if ((addr
& 3) || addr
< 0)
132 tmp
= 0; /* Default return condition */
133 if(addr
< MAX_REG_OFFSET
){
134 tmp
= getreg(child
, addr
);
136 else if((addr
>= offsetof(struct user
, u_debugreg
[0])) &&
137 (addr
<= offsetof(struct user
, u_debugreg
[7]))){
138 addr
-= offsetof(struct user
, u_debugreg
[0]);
140 tmp
= child
->thread
.arch
.debugregs
[addr
];
142 return put_user(tmp
, (unsigned long *) data
);
145 struct i387_fxsave_struct
{
156 long st_space
[32]; /* 8*16 bytes for each FP-reg = 128 bytes */
157 long xmm_space
[32]; /* 8*16 bytes for each XMM-reg = 128 bytes */
162 * FPU tag word conversions.
165 static inline unsigned short twd_i387_to_fxsr( unsigned short twd
)
167 unsigned int tmp
; /* to avoid 16 bit prefixes in the code */
169 /* Transform each pair of bits into 01 (valid) or 00 (empty) */
171 tmp
= (tmp
| (tmp
>>1)) & 0x5555; /* 0V0V0V0V0V0V0V0V */
172 /* and move the valid bits to the lower byte. */
173 tmp
= (tmp
| (tmp
>> 1)) & 0x3333; /* 00VV00VV00VV00VV */
174 tmp
= (tmp
| (tmp
>> 2)) & 0x0f0f; /* 0000VVVV0000VVVV */
175 tmp
= (tmp
| (tmp
>> 4)) & 0x00ff; /* 00000000VVVVVVVV */
179 static inline unsigned long twd_fxsr_to_i387( struct i387_fxsave_struct
*fxsave
)
181 struct _fpxreg
*st
= NULL
;
182 unsigned long twd
= (unsigned long) fxsave
->twd
;
184 unsigned long ret
= 0xffff0000;
187 #define FPREG_ADDR(f, n) ((char *)&(f)->st_space + (n) * 16);
189 for ( i
= 0 ; i
< 8 ; i
++ ) {
191 st
= (struct _fpxreg
*) FPREG_ADDR( fxsave
, i
);
193 switch ( st
->exponent
& 0x7fff ) {
195 tag
= 2; /* Special */
198 if ( !st
->significand
[0] &&
199 !st
->significand
[1] &&
200 !st
->significand
[2] &&
201 !st
->significand
[3] ) {
204 tag
= 2; /* Special */
208 if ( st
->significand
[3] & 0x8000 ) {
211 tag
= 2; /* Special */
218 ret
|= (tag
<< (2 * i
));
225 * FXSR floating point environment conversions.
228 #ifdef CONFIG_MODE_TT
229 static inline int convert_fxsr_to_user_tt(struct _fpstate __user
*buf
,
230 struct pt_regs
*regs
)
232 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
233 unsigned long env
[7];
234 struct _fpreg __user
*to
;
235 struct _fpxreg
*from
;
238 env
[0] = (unsigned long)fxsave
->cwd
| 0xffff0000;
239 env
[1] = (unsigned long)fxsave
->swd
| 0xffff0000;
240 env
[2] = twd_fxsr_to_i387(fxsave
);
241 env
[3] = fxsave
->fip
;
242 env
[4] = fxsave
->fcs
| ((unsigned long)fxsave
->fop
<< 16);
243 env
[5] = fxsave
->foo
;
244 env
[6] = fxsave
->fos
;
246 if ( __copy_to_user( buf
, env
, 7 * sizeof(unsigned long) ) )
250 from
= (struct _fpxreg
*) &fxsave
->st_space
[0];
251 for ( i
= 0 ; i
< 8 ; i
++, to
++, from
++ ) {
252 if ( __copy_to_user( to
, from
, sizeof(*to
) ) )
259 static inline int convert_fxsr_to_user(struct _fpstate __user
*buf
,
260 struct pt_regs
*regs
)
262 return(CHOOSE_MODE(convert_fxsr_to_user_tt(buf
, regs
), 0));
265 #ifdef CONFIG_MODE_TT
266 static inline int convert_fxsr_from_user_tt(struct pt_regs
*regs
,
267 struct _fpstate __user
*buf
)
269 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
270 unsigned long env
[7];
272 struct _fpreg __user
*from
;
275 if ( __copy_from_user( env
, buf
, 7 * sizeof(long) ) )
278 fxsave
->cwd
= (unsigned short)(env
[0] & 0xffff);
279 fxsave
->swd
= (unsigned short)(env
[1] & 0xffff);
280 fxsave
->twd
= twd_i387_to_fxsr((unsigned short)(env
[2] & 0xffff));
281 fxsave
->fip
= env
[3];
282 fxsave
->fop
= (unsigned short)((env
[4] & 0xffff0000) >> 16);
283 fxsave
->fcs
= (env
[4] & 0xffff);
284 fxsave
->foo
= env
[5];
285 fxsave
->fos
= env
[6];
287 to
= (struct _fpxreg
*) &fxsave
->st_space
[0];
289 for ( i
= 0 ; i
< 8 ; i
++, to
++, from
++ ) {
290 if ( __copy_from_user( to
, from
, sizeof(*from
) ) )
297 static inline int convert_fxsr_from_user(struct pt_regs
*regs
,
298 struct _fpstate __user
*buf
)
300 return(CHOOSE_MODE(convert_fxsr_from_user_tt(regs
, buf
), 0));
303 int get_fpregs(unsigned long buf
, struct task_struct
*child
)
307 err
= convert_fxsr_to_user((struct _fpstate __user
*) buf
,
308 &child
->thread
.regs
);
309 if(err
) return(-EFAULT
);
313 int set_fpregs(unsigned long buf
, struct task_struct
*child
)
317 err
= convert_fxsr_from_user(&child
->thread
.regs
,
318 (struct _fpstate __user
*) buf
);
319 if(err
) return(-EFAULT
);
323 #ifdef CONFIG_MODE_TT
324 int get_fpxregs_tt(unsigned long buf
, struct task_struct
*tsk
)
326 struct pt_regs
*regs
= &tsk
->thread
.regs
;
327 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
330 err
= __copy_to_user((void __user
*) buf
, fxsave
,
331 sizeof(struct user_fxsr_struct
));
332 if(err
) return -EFAULT
;
337 int get_fpxregs(unsigned long buf
, struct task_struct
*tsk
)
339 return(CHOOSE_MODE(get_fpxregs_tt(buf
, tsk
), 0));
342 #ifdef CONFIG_MODE_TT
343 int set_fpxregs_tt(unsigned long buf
, struct task_struct
*tsk
)
345 struct pt_regs
*regs
= &tsk
->thread
.regs
;
346 struct i387_fxsave_struct
*fxsave
= SC_FXSR_ENV(PT_REGS_SC(regs
));
349 err
= __copy_from_user(fxsave
, (void __user
*) buf
,
350 sizeof(struct user_fxsr_struct
) );
351 if(err
) return -EFAULT
;
356 int set_fpxregs(unsigned long buf
, struct task_struct
*tsk
)
358 return(CHOOSE_MODE(set_fpxregs_tt(buf
, tsk
), 0));
362 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
364 fpu
->cwd
= (((SC_FP_CW(PT_REGS_SC(regs
)) & 0xffff) << 16) |
365 (SC_FP_SW(PT_REGS_SC(regs
)) & 0xffff));
366 fpu
->swd
= SC_FP_CSSEL(PT_REGS_SC(regs
)) & 0xffff;
367 fpu
->twd
= SC_FP_IPOFF(PT_REGS_SC(regs
));
368 fpu
->fip
= SC_FP_CSSEL(PT_REGS_SC(regs
)) & 0xffff;
369 fpu
->fcs
= SC_FP_DATAOFF(PT_REGS_SC(regs
));
370 fpu
->foo
= SC_FP_DATASEL(PT_REGS_SC(regs
));
372 memcpy(fpu
->st_space
, (void *) SC_FP_ST(PT_REGS_SC(regs
)),
373 sizeof(fpu
->st_space
));
378 #ifdef CONFIG_MODE_TT
379 static inline void copy_fpu_fxsave_tt(struct pt_regs
*regs
,
380 struct user_i387_struct
*buf
)
382 struct i387_fxsave_struct
*fpu
= SC_FXSR_ENV(PT_REGS_SC(regs
));
384 unsigned short *from
;
387 memcpy( buf
, fpu
, 7 * sizeof(long) );
389 to
= (unsigned short *) &buf
->st_space
[0];
390 from
= (unsigned short *) &fpu
->st_space
[0];
391 for ( i
= 0 ; i
< 8 ; i
++, to
+= 5, from
+= 8 ) {
392 memcpy( to
, from
, 5 * sizeof(unsigned short) );
397 static inline void copy_fpu_fxsave(struct pt_regs
*regs
,
398 struct user_i387_struct
*buf
)
400 (void) CHOOSE_MODE(copy_fpu_fxsave_tt(regs
, buf
), 0);
403 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpu
)
405 copy_fpu_fxsave(regs
, (struct user_i387_struct
*) fpu
);
410 * Overrides for Emacs so that we follow Linus's tabbing style.
411 * Emacs will notice this stuff at the end of the file and automatically
412 * adjust the settings for this buffer only. This must remain at the end
414 * ---------------------------------------------------------------------------
416 * c-file-style: "linux"