]>
Commit | Line | Data |
---|---|---|
9c986f87 | 1 | /* Raise given exceptions. |
d4697bc9 | 2 | Copyright (C) 2006-2014 Free Software Foundation, Inc. |
9c986f87 AS |
3 | This file is part of the GNU C Library. |
4 | ||
5 | The GNU C Library is free software; you can redistribute it and/or | |
6 | modify it under the terms of the GNU Lesser General Public | |
7 | License as published by the Free Software Foundation; either | |
8 | version 2.1 of the License, or (at your option) any later version. | |
9 | ||
10 | The GNU C Library is distributed in the hope that it will be useful, | |
11 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
13 | Lesser General Public License for more details. | |
14 | ||
15 | You should have received a copy of the GNU Lesser General Public | |
ab84e3ff PE |
16 | License along with the GNU C Library. If not, see |
17 | <http://www.gnu.org/licenses/>. */ | |
9c986f87 AS |
18 | |
19 | #include <fenv.h> | |
20 | #include <float.h> | |
21 | #include <math.h> | |
22 | ||
23 | int | |
0747f818 | 24 | __feraiseexcept (int excepts) |
9c986f87 AS |
25 | { |
26 | /* Raise exceptions represented by EXCEPTS. But we must raise only one | |
27 | signal at a time. It is important that if the overflow/underflow | |
28 | exception and the divide by zero exception are given at the same | |
29 | time, the overflow/underflow exception follows the divide by zero | |
30 | exception. | |
31 | ||
32 | The Coldfire FPU allows an exception to be raised by asserting | |
33 | the associated EXC bit and then executing an arbitrary arithmetic | |
34 | instruction. fmove.l is classified as an arithmetic instruction | |
35 | and suffices for this purpose. | |
36 | ||
37 | We therefore raise an exception by setting both the EXC and AEXC | |
38 | bit associated with the exception (the former being 6 bits to the | |
39 | left of the latter) and then loading the longword at (%sp) into an | |
40 | FP register. */ | |
41 | ||
42 | inline void | |
43 | raise_one_exception (int mask) | |
44 | { | |
45 | if (excepts & mask) | |
46 | { | |
47 | int fpsr; | |
48 | double unused; | |
49 | ||
50 | asm volatile ("fmove%.l %/fpsr,%0" : "=d" (fpsr)); | |
51 | fpsr |= (mask << 6) | mask; | |
52 | asm volatile ("fmove%.l %0,%/fpsr" :: "d" (fpsr)); | |
53 | asm volatile ("fmove%.l (%%sp),%0" : "=f" (unused)); | |
54 | } | |
55 | } | |
56 | ||
57 | raise_one_exception (FE_INVALID); | |
58 | raise_one_exception (FE_DIVBYZERO); | |
59 | raise_one_exception (FE_OVERFLOW); | |
60 | raise_one_exception (FE_UNDERFLOW); | |
61 | raise_one_exception (FE_INEXACT); | |
62 | ||
63 | /* Success. */ | |
64 | return 0; | |
65 | } | |
0747f818 JM |
66 | libm_hidden_def (__feraiseexcept) |
67 | weak_alias (__feraiseexcept, feraiseexcept) | |
68 | libm_hidden_weak (feraiseexcept) |