1 /* MN10300 FPU management
3 * Copyright (C) 2007 Red Hat, Inc. All Rights Reserved.
4 * Written by David Howells (dhowells@redhat.com)
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public Licence
8 * as published by the Free Software Foundation; either version
9 * 2 of the Licence, or (at your option) any later version.
11 #include <asm/uaccess.h>
14 #include <asm/exceptions.h>
16 #ifdef CONFIG_LAZY_SAVE_FPU
17 struct task_struct
*fpu_state_owner
;
21 * error functions in FPU disabled exception
23 asmlinkage
void fpu_disabled_in_kernel(struct pt_regs
*regs
)
25 die_if_no_fixup("An FPU Disabled exception happened in kernel space\n",
26 regs
, EXCEP_FPU_DISABLED
);
30 * handle an FPU operational exception
31 * - there's a possibility that if the FPU is asynchronous, the signal might
32 * be meant for a process other than the current one
34 asmlinkage
void fpu_exception(struct pt_regs
*regs
, enum exception_code code
)
36 struct task_struct
*tsk
= current
;
41 die_if_no_fixup("An FPU Operation exception happened in"
45 if (!is_using_fpu(tsk
))
46 die_if_no_fixup("An FPU Operation exception happened,"
47 " but the FPU is not in use",
50 info
.si_signo
= SIGFPE
;
52 info
.si_addr
= (void *) tsk
->thread
.uregs
->pc
;
53 info
.si_code
= FPE_FLTINV
;
57 fpcr
= tsk
->thread
.fpu_state
.fpcr
;
60 info
.si_code
= FPE_FLTDIV
;
61 else if (fpcr
& FPCR_EC_O
)
62 info
.si_code
= FPE_FLTOVF
;
63 else if (fpcr
& FPCR_EC_U
)
64 info
.si_code
= FPE_FLTUND
;
65 else if (fpcr
& FPCR_EC_I
)
66 info
.si_code
= FPE_FLTRES
;
68 force_sig_info(SIGFPE
, &info
, tsk
);
72 * save the FPU state to a signal context
74 int fpu_setup_sigcontext(struct fpucontext
*fpucontext
)
76 struct task_struct
*tsk
= current
;
78 if (!is_using_fpu(tsk
))
81 /* transfer the current FPU state to memory and cause fpu_init() to be
82 * triggered by the next attempted FPU operation by the current
87 #ifndef CONFIG_LAZY_SAVE_FPU
88 if (tsk
->thread
.fpu_flags
& THREAD_HAS_FPU
) {
89 fpu_save(&tsk
->thread
.fpu_state
);
90 tsk
->thread
.uregs
->epsw
&= ~EPSW_FE
;
91 tsk
->thread
.fpu_flags
&= ~THREAD_HAS_FPU
;
93 #else /* !CONFIG_LAZY_SAVE_FPU */
94 if (fpu_state_owner
== tsk
) {
95 fpu_save(&tsk
->thread
.fpu_state
);
96 fpu_state_owner
->thread
.uregs
->epsw
&= ~EPSW_FE
;
97 fpu_state_owner
= NULL
;
99 #endif /* !CONFIG_LAZY_SAVE_FPU */
103 /* we no longer have a valid current FPU state */
104 clear_using_fpu(tsk
);
106 /* transfer the saved FPU state onto the userspace stack */
107 if (copy_to_user(fpucontext
,
108 &tsk
->thread
.fpu_state
,
109 min(sizeof(struct fpu_state_struct
),
110 sizeof(struct fpucontext
))))
117 * kill a process's FPU state during restoration after signal handling
119 void fpu_kill_state(struct task_struct
*tsk
)
121 /* disown anything left in the FPU */
124 #ifndef CONFIG_LAZY_SAVE_FPU
125 if (tsk
->thread
.fpu_flags
& THREAD_HAS_FPU
) {
126 tsk
->thread
.uregs
->epsw
&= ~EPSW_FE
;
127 tsk
->thread
.fpu_flags
&= ~THREAD_HAS_FPU
;
129 #else /* !CONFIG_LAZY_SAVE_FPU */
130 if (fpu_state_owner
== tsk
) {
131 fpu_state_owner
->thread
.uregs
->epsw
&= ~EPSW_FE
;
132 fpu_state_owner
= NULL
;
134 #endif /* !CONFIG_LAZY_SAVE_FPU */
138 /* we no longer have a valid current FPU state */
139 clear_using_fpu(tsk
);
143 * restore the FPU state from a signal context
145 int fpu_restore_sigcontext(struct fpucontext
*fpucontext
)
147 struct task_struct
*tsk
= current
;
150 /* load up the old FPU state */
151 ret
= copy_from_user(&tsk
->thread
.fpu_state
, fpucontext
,
152 min(sizeof(struct fpu_state_struct
),
153 sizeof(struct fpucontext
)));
161 * fill in the FPU structure for a core dump
163 int dump_fpu(struct pt_regs
*regs
, elf_fpregset_t
*fpreg
)
165 struct task_struct
*tsk
= current
;
168 fpvalid
= is_using_fpu(tsk
);
171 memcpy(fpreg
, &tsk
->thread
.fpu_state
, sizeof(*fpreg
));