1 /*
2 * Copyright (c) 2022, Arm Limited. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 *
6 */
7
8 #include "test_interrupt.h"
9
10 #if defined(TEST_NS_FPU) || defined(TEST_S_FPU)
TFM_FPU_S_TEST_Handler(void)11 __attribute__((naked)) void TFM_FPU_S_TEST_Handler(void)
12 {
13 __asm volatile(
14 "mov r0, #0x000000E0 \n"
15 "vmov s0, r0 \n"
16 "mov r0, #0x000000E1 \n"
17 "vmov s1, r0 \n"
18 "mov r0, #0x000000E2 \n"
19 "vmov s2, r0 \n"
20 "mov r0, #0x000000E3 \n"
21 "vmov s3, r0 \n"
22 "mov r0, #0x000000E4 \n"
23 "vmov s4, r0 \n"
24 "mov r0, #0x000000E5 \n"
25 "vmov s5, r0 \n"
26 "mov r0, #0x000000E6 \n"
27 "vmov s6, r0 \n"
28 "mov r0, #0x000000E7 \n"
29 "vmov s7, r0 \n"
30 "mov r0, #0x000000E8 \n"
31 "vmov s8, r0 \n"
32 "mov r0, #0x000000E9 \n"
33 "vmov s9, r0 \n"
34 "mov r0, #0x000000EA \n"
35 "vmov s10, r0 \n"
36 "mov r0, #0x000000EB \n"
37 "vmov s11, r0 \n"
38 "mov r0, #0x000000EC \n"
39 "vmov s12, r0 \n"
40 "mov r0, #0x000000ED \n"
41 "vmov s13, r0 \n"
42 "mov r0, #0x000000EE \n"
43 "vmov s14, r0 \n"
44 "mov r0, #0x000000EF \n"
45 "vmov s15, r0 \n"
46 "mov r0, #0x000000F0 \n"
47 "vmov s16, r0 \n"
48 "mov r0, #0x000000F1 \n"
49 "vmov s17, r0 \n"
50 "mov r0, #0x000000F2 \n"
51 "vmov s18, r0 \n"
52 "mov r0, #0x000000F3 \n"
53 "vmov s19, r0 \n"
54 "mov r0, #0x000000F4 \n"
55 "vmov s20, r0 \n"
56 "mov r0, #0x000000F5 \n"
57 "vmov s21, r0 \n"
58 "mov r0, #0x000000F6 \n"
59 "vmov s22, r0 \n"
60 "mov r0, #0x000000F7 \n"
61 "vmov s23, r0 \n"
62 "mov r0, #0x000000F8 \n"
63 "vmov s24, r0 \n"
64 "mov r0, #0x000000F9 \n"
65 "vmov s25, r0 \n"
66 "mov r0, #0x000000FA \n"
67 "vmov s26, r0 \n"
68 "mov r0, #0x000000FB \n"
69 "vmov s27, r0 \n"
70 "mov r0, #0x000000FC \n"
71 "vmov s28, r0 \n"
72 "mov r0, #0x000000FD \n"
73 "vmov s29, r0 \n"
74 "mov r0, #0x000000FE \n"
75 "vmov s30, r0 \n"
76 "mov r0, #0x000000FF \n"
77 "vmov s31, r0 \n"
78 "bx lr \n"
79 );
80 }
81 #endif
82
83 #ifdef TEST_NS_FPU
is_non_zero(uint32_t * p,uint32_t n)84 __attribute__((used)) static uint32_t is_non_zero(uint32_t *p, uint32_t n)
85 {
86
87 while(n && p[n - 1] == 0) {
88 n--;
89 }
90 return n;
91 }
92
TFM_FPU_NS_TEST_Handler(void)93 __attribute__((naked)) void TFM_FPU_NS_TEST_Handler(void)
94 {
95 __asm volatile(
96 /*
97 * If LR.BIT[6] equals 1, the interrupt is triggerred by secure thread.
98 */
99 "ands r0, lr, #0x40 \n"
100 "cmp r0, 0x40 \n"
101 "bne change_regs \n"
102 "push {r7, lr} \n"
103 "vpush {s0-s15} \n"
104 "vpush {s16-s31} \n"
105 "mov r0, sp \n"
106 "mov r1, #32 \n"
107 "bl is_non_zero \n"
108 "vpop {s16-s31} \n"
109 "vpop {s0-s15} \n"
110 "pop {r7, lr} \n"
111 "cmp r0, #0 \n"
112 "bne panic \n"
113 "change_regs: \n"
114 "mov r0, #0x000000E0 \n"
115 "vmov s0, r0 \n"
116 "mov r0, #0x000000E1 \n"
117 "vmov s1, r0 \n"
118 "mov r0, #0x000000E2 \n"
119 "vmov s2, r0 \n"
120 "mov r0, #0x000000E3 \n"
121 "vmov s3, r0 \n"
122 "mov r0, #0x000000E4 \n"
123 "vmov s4, r0 \n"
124 "mov r0, #0x000000E5 \n"
125 "vmov s5, r0 \n"
126 "mov r0, #0x000000E6 \n"
127 "vmov s6, r0 \n"
128 "mov r0, #0x000000E7 \n"
129 "vmov s7, r0 \n"
130 "mov r0, #0x000000E8 \n"
131 "vmov s8, r0 \n"
132 "mov r0, #0x000000E9 \n"
133 "vmov s9, r0 \n"
134 "mov r0, #0x000000EA \n"
135 "vmov s10, r0 \n"
136 "mov r0, #0x000000EB \n"
137 "vmov s11, r0 \n"
138 "mov r0, #0x000000EC \n"
139 "vmov s12, r0 \n"
140 "mov r0, #0x000000ED \n"
141 "vmov s13, r0 \n"
142 "mov r0, #0x000000EE \n"
143 "vmov s14, r0 \n"
144 "mov r0, #0x000000EF \n"
145 "vmov s15, r0 \n"
146 "mov r0, #0x000000F0 \n"
147 "vmov s16, r0 \n"
148 "mov r0, #0x000000F1 \n"
149 "vmov s17, r0 \n"
150 "mov r0, #0x000000F2 \n"
151 "vmov s18, r0 \n"
152 "mov r0, #0x000000F3 \n"
153 "vmov s19, r0 \n"
154 "mov r0, #0x000000F4 \n"
155 "vmov s20, r0 \n"
156 "mov r0, #0x000000F5 \n"
157 "vmov s21, r0 \n"
158 "mov r0, #0x000000F6 \n"
159 "vmov s22, r0 \n"
160 "mov r0, #0x000000F7 \n"
161 "vmov s23, r0 \n"
162 "mov r0, #0x000000F8 \n"
163 "vmov s24, r0 \n"
164 "mov r0, #0x000000F9 \n"
165 "vmov s25, r0 \n"
166 "mov r0, #0x000000FA \n"
167 "vmov s26, r0 \n"
168 "mov r0, #0x000000FB \n"
169 "vmov s27, r0 \n"
170 "mov r0, #0x000000FC \n"
171 "vmov s28, r0 \n"
172 "mov r0, #0x000000FD \n"
173 "vmov s29, r0 \n"
174 "mov r0, #0x000000FE \n"
175 "vmov s30, r0 \n"
176 "mov r0, #0x000000FF \n"
177 "vmov s31, r0 \n"
178 "bx lr \n"
179 "panic: \n"
180 "b . \n"
181 );
182 }
183 #endif
184