1/*
2 * Copyright (c) 2015, Google Inc. All rights reserved
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining
5 * a copy of this software and associated documentation files
6 * (the "Software"), to deal in the Software without restriction,
7 * including without limitation the rights to use, copy, modify, merge,
8 * publish, distribute, sublicense, and/or sell copies of the Software,
9 * and to permit persons to whom the Software is furnished to do so,
10 * subject to the following conditions:
11 *
12 * The above copyright notice and this permission notice shall be
13 * included in all copies or substantial portions of the Software.
14 *
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
18 * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
19 * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
20 * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
21 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22 */
23
24#include <asm.h>
25
26.altmacro
27
28.macro init_regs val=x0, reg=0
29    fmov    d\reg, \val
30    add     \val, \val, #1
31    fmov    v\reg&.d[1], \val
32.if \reg < 31
33    add     \val, \val, #1
34    init_regs   \val, %(\reg+1)
35.endif
36.endm
37
38/* clear reserved bits */
39.macro fpcrval val, base
40    add     \val, \base, #1
41    lsl     \val, \val, #22
42    bic     \val, \val, #(~0 << 27)
43.endm
44
45/* clear reserved bits */
46.macro fpsrval val, base
47    add     \val, \base, #2
48    bic     \val, \val, #(3 << 5)
49    bic     \val, \val, #((~0 << 8) ^ (~0 << 27))
50.endm
51
52FUNCTION(fptest_arch_init)
53    init_regs
54    fpcrval     x9, x0
55    msr     fpcr, x9
56    fpsrval     x9, x0
57    msr     fpsr, x9
58    ret
59
60.macro check_val errors, val1, val2
61    cmp     \val1, \val2
62    cinc    \errors, \errors, ne
63.endm
64
65.macro check_regs errors, val, tmp, reg=0
66    fmov    \tmp, d\reg
67    check_val   \errors, \val, \tmp
68    add     \val, \val, #1
69    fmov    \tmp, v\reg&.d[1]
70    check_val   \errors, \val, \tmp
71.if \reg < 31
72    add     \val, \val, #1
73    check_regs  \errors, \val, \tmp, %(\reg+1)
74.endif
75.endm
76
77FUNCTION(fptest_arch_check_state)
78    mov     x9, x0
79    mov     x0, #0
80    check_regs  x0, x9, x10
81    mrs     x10, fpcr
82    fpcrval     x11, x9
83    check_val   x0, x11, x10
84    mrs     x10, fpsr
85    fpsrval     x11, x9
86    check_val   x0, x11, x10
87    ret
88