~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

TOMOYO Linux Cross Reference
Linux/arch/x86_64/kernel/i387.c

Version: ~ [ linux-5.8 ] ~ [ linux-5.7.12 ] ~ [ linux-5.6.19 ] ~ [ linux-5.5.19 ] ~ [ linux-5.4.55 ] ~ [ linux-5.3.18 ] ~ [ linux-5.2.21 ] ~ [ linux-5.1.21 ] ~ [ linux-5.0.21 ] ~ [ linux-4.20.17 ] ~ [ linux-4.19.136 ] ~ [ linux-4.18.20 ] ~ [ linux-4.17.19 ] ~ [ linux-4.16.18 ] ~ [ linux-4.15.18 ] ~ [ linux-4.14.191 ] ~ [ linux-4.13.16 ] ~ [ linux-4.12.14 ] ~ [ linux-4.11.12 ] ~ [ linux-4.10.17 ] ~ [ linux-4.9.232 ] ~ [ linux-4.8.17 ] ~ [ linux-4.7.10 ] ~ [ linux-4.6.7 ] ~ [ linux-4.5.7 ] ~ [ linux-4.4.232 ] ~ [ linux-4.3.6 ] ~ [ linux-4.2.8 ] ~ [ linux-4.1.52 ] ~ [ linux-4.0.9 ] ~ [ linux-3.19.8 ] ~ [ linux-3.18.140 ] ~ [ linux-3.17.8 ] ~ [ linux-3.16.85 ] ~ [ linux-3.15.10 ] ~ [ linux-3.14.79 ] ~ [ linux-3.13.11 ] ~ [ linux-3.12.74 ] ~ [ linux-3.11.10 ] ~ [ linux-3.10.108 ] ~ [ linux-2.6.32.71 ] ~ [ linux-2.6.0 ] ~ [ linux-2.4.37.11 ] ~ [ unix-v6-master ] ~ [ ccs-tools-1.8.5 ] ~ [ policy-sample ] ~
Architecture: ~ [ i386 ] ~ [ alpha ] ~ [ m68k ] ~ [ mips ] ~ [ ppc ] ~ [ sparc ] ~ [ sparc64 ] ~

  1 /*
  2  *  linux/arch/x86_64/kernel/i387.c
  3  *
  4  *  Copyright (C) 1994 Linus Torvalds
  5  *  Copyright (C) 2002 Andi Kleen, SuSE Labs
  6  *
  7  *  Pentium III FXSR, SSE support
  8  *  General FPU state handling cleanups
  9  *      Gareth Hughes <gareth@valinux.com>, May 2000
 10  * 
 11  *  x86-64 rework 2002 Andi Kleen. 
 12  *  Does direct fxsave in and out of user space now for signal handlers.
 13  *  All the FSAVE<->FXSAVE conversion code has been moved to the 32bit emulation,
 14  *  the 64bit user space sees a FXSAVE frame directly. 
 15  */
 16 
 17 #include <linux/config.h>
 18 #include <linux/sched.h>
 19 #include <linux/init.h>
 20 #include <asm/processor.h>
 21 #include <asm/i387.h>
 22 #include <asm/sigcontext.h>
 23 #include <asm/user.h>
 24 #include <asm/ptrace.h>
 25 #include <asm/uaccess.h>
 26 
 27 /*
 28  * Called at bootup to set up the initial FPU state that is later cloned
 29  * into all processes.
 30  */
 31 void __init fpu_init(void)
 32 {
 33         unsigned long oldcr0 = read_cr0();
 34         extern void __bad_fxsave_alignment(void);
 35                 
 36         if (offsetof(struct task_struct, thread.i387.fxsave) & 15)
 37                 __bad_fxsave_alignment();
 38         set_in_cr4(X86_CR4_OSFXSR);
 39         set_in_cr4(X86_CR4_OSXMMEXCPT);
 40 
 41         write_cr0(oldcr0 & ~((1UL<<3)|(1UL<<2))); /* clear TS and EM */
 42 
 43         /* clean state in init */
 44         stts();
 45         current_thread_info()->status = 0;
 46         current->used_math = 0;
 47 }
 48 
 49 /*
 50  * The _current_ task is using the FPU for the first time
 51  * so initialize it and set the mxcsr to its default.
 52  * remember the current task has used the FPU.
 53  */
 54 void init_fpu(struct task_struct *child)
 55 {
 56         if (child->used_math) { 
 57                 if (child == current)
 58                         unlazy_fpu(child);
 59                 return;
 60         }       
 61         memset(&child->thread.i387.fxsave, 0, sizeof(struct i387_fxsave_struct));
 62         child->thread.i387.fxsave.cwd = 0x37f;
 63         child->thread.i387.fxsave.mxcsr = 0x1f80;
 64         child->used_math = 1;
 65 }
 66 
 67 /*
 68  * Signal frame handlers.
 69  */
 70 
 71 int save_i387(struct _fpstate *buf)
 72 {
 73         struct task_struct *tsk = current;
 74         int err = 0;
 75 
 76         { 
 77                 extern void bad_user_i387_struct(void); 
 78                 if (sizeof(struct user_i387_struct) != sizeof(tsk->thread.i387.fxsave))
 79                         bad_user_i387_struct();
 80         } 
 81 
 82         if ((unsigned long)buf % 16) 
 83                 printk("save_i387: bad fpstate %p\n",buf); 
 84 
 85         if (!tsk->used_math) 
 86                 return 0;
 87         tsk->used_math = 0; /* trigger finit */ 
 88         if (tsk->thread_info->status & TS_USEDFPU) {
 89                 err = save_i387_checking((struct i387_fxsave_struct *)buf);
 90                 if (err) return err;
 91                 stts();
 92                 } else {
 93                 if (__copy_to_user(buf, &tsk->thread.i387.fxsave, 
 94                                    sizeof(struct i387_fxsave_struct)))
 95                         return -1;
 96         } 
 97                 return 1;
 98 }
 99 
100 /*
101  * ptrace request handlers.
102  */
103 
104 int get_fpregs(struct user_i387_struct *buf, struct task_struct *tsk)
105 {
106         init_fpu(tsk);
107         return __copy_to_user((void *)buf, &tsk->thread.i387.fxsave,
108                                sizeof(struct user_i387_struct)) ? -EFAULT : 0;
109 }
110 
111 int set_fpregs(struct task_struct *tsk, struct user_i387_struct *buf)
112 {
113         if (__copy_from_user(&tsk->thread.i387.fxsave, buf, 
114                              sizeof(struct user_i387_struct)))
115                 return -EFAULT;
116                 return 0;
117 }
118 
119 /*
120  * FPU state for core dumps.
121  */
122 
123 int dump_fpu( struct pt_regs *regs, struct user_i387_struct *fpu )
124 {
125         struct task_struct *tsk = current;
126 
127         if (!tsk->used_math) 
128                 return 0;
129 
130         unlazy_fpu(tsk);
131         memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct)); 
132         return 1; 
133 }
134 
135 int dump_task_fpu(struct task_struct *tsk, struct user_i387_struct *fpu)
136 {
137         int fpvalid = tsk->used_math;
138 
139         if (fpvalid) {
140                 if (tsk == current)
141                         unlazy_fpu(tsk);
142                 memcpy(fpu, &tsk->thread.i387.fxsave, sizeof(struct user_i387_struct));         
143 }
144         return fpvalid;
145 }
146 

~ [ source navigation ] ~ [ diff markup ] ~ [ identifier search ] ~

kernel.org | git.kernel.org | LWN.net | Project Home | Wiki (Japanese) | Wiki (English) | SVN repository | Mail admin

Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.

osdn.jp