1 /* Copyright (c) 2011 Tensilica Inc. ALL RIGHTS RESERVED.
2
3 Redistribution and use in source and binary forms, with or without
4 modification, are permitted provided that the following conditions
5 are met:
6
7 1. Redistributions of source code must retain the above copyright
8 notice, this list of conditions and the following disclaimer.
9
10 2. Redistributions in binary form must reproduce the above
11 copyright notice, this list of conditions and the following
12 disclaimer in the documentation and/or other materials provided
13 with the distribution.
14
15 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
19 TENSILICA INCORPORATED BE LIABLE FOR ANY DIRECT, INDIRECT,
20 INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
22 SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
24 STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
26 OF THE POSSIBILITY OF SUCH DAMAGE. */
27
28
29 #include <machine/core-isa.h>
30
31 #if XCHAL_HAVE_FP || XCHAL_HAVE_DFP
32
33 /* Xtensa doesn't trap, so setting the flags is the best we can
34 do. */
35
36 #include <fenv.h>
37
feraiseexcept(int excepts)38 int feraiseexcept(int excepts)
39 {
40 fexcept_t current;
41
42 if (excepts & ~FE_ALL_EXCEPT)
43 return -1;
44 __asm__("rur.fsr %0" : "=a"(current));
45 current |= excepts << _FE_EXCEPTION_FLAGS_OFFSET;
46 __asm__("wur.fsr %0" : : "a"(current));
47 return 0;
48 }
49
50 #else
51 #include "../../fenv/feraiseexcept.c"
52 #endif
53