]> git.sur5r.net Git - freertos/blob - FreeRTOS/Demo/CORTEX_MPU_CEC_MEC_17xx_51xx_Keil_GCC/GCC_Specific/RegTest.c
0307f86141276bb216bd56d4877900fcf0c7627b
[freertos] / FreeRTOS / Demo / CORTEX_MPU_CEC_MEC_17xx_51xx_Keil_GCC / GCC_Specific / RegTest.c
1 /*\r
2  * FreeRTOS Kernel V10.3.0\r
3  * Copyright (C) 2020 Amazon.com, Inc. or its affiliates.  All Rights Reserved.\r
4  *\r
5  * Permission is hereby granted, free of charge, to any person obtaining a copy of\r
6  * this software and associated documentation files (the "Software"), to deal in\r
7  * the Software without restriction, including without limitation the rights to\r
8  * use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of\r
9  * the Software, and to permit persons to whom the Software is furnished to do so,\r
10  * subject to the following conditions:\r
11  *\r
12  * The above copyright notice and this permission notice shall be included in all\r
13  * copies or substantial portions of the Software.\r
14  *\r
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\r
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS\r
17  * FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR\r
18  * COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER\r
19  * IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
20  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r
21  *\r
22  * http://www.FreeRTOS.org\r
23  * http://aws.amazon.com/freertos\r
24  *\r
25  * 1 tab == 4 spaces!\r
26  */\r
27 \r
28 /* FreeRTOS includes. */\r
29 #include "FreeRTOS.h"\r
30 #include "queue.h"\r
31 \r
32 /*\r
33  * "Reg test" tasks - These fill the registers with known values, then check\r
34  * that each register maintains its expected value for the lifetime of the\r
35  * task.  Each task uses a different set of values.  The reg test tasks execute\r
36  * with a very low priority, so get preempted very frequently.  A register\r
37  * containing an unexpected value is indicative of an error in the context\r
38  * switching mechanism.\r
39  */\r
40 \r
41 void vRegTest1Implementation( void *pvParameters );\r
42 void vRegTest2Implementation( void *pvParameters );\r
43 void vRegTest3Implementation( void ) __attribute__ ((naked));\r
44 void vRegTest4Implementation( void ) __attribute__ ((naked));\r
45 \r
46 /*\r
47  * Used as an easy way of deleting a task from inline assembly.\r
48  */\r
49 extern void vMainDeleteMe( void ) __attribute__((noinline));\r
50 \r
51 /*\r
52  * Used by the first two reg test tasks and a software timer callback function\r
53  * to send messages to the check task.  The message just lets the check task\r
54  * know that the tasks and timer are still functioning correctly.  If a reg test\r
55  * task detects an error it will delete itself, and in so doing prevent itself\r
56  * from sending any more 'I'm Alive' messages to the check task.\r
57  */\r
58 extern void vMainSendImAlive( QueueHandle_t xHandle, uint32_t ulTaskNumber );\r
59 \r
60 /* The queue used to send a message to the check task. */\r
61 extern QueueHandle_t xGlobalScopeCheckQueue;\r
62 \r
63 /*-----------------------------------------------------------*/\r
64 \r
65 void vRegTest1Implementation( void *pvParameters )\r
66 {\r
67 /* This task is created in privileged mode so can access the file scope\r
68 queue variable.  Take a stack copy of this before the task is set into user\r
69 mode.  Once this task is in user mode the file scope queue variable will no\r
70 longer be accessible but the stack copy will. */\r
71 QueueHandle_t xQueue = xGlobalScopeCheckQueue;\r
72 \r
73         /* Now the queue handle has been obtained the task can switch to user\r
74         mode.  This is just one method of passing a handle into a protected\r
75         task, the other reg test task uses the task parameter instead. */\r
76         portSWITCH_TO_USER_MODE();\r
77 \r
78         /* First check that the parameter value is as expected. */\r
79         if( pvParameters != ( void * ) configREG_TEST_TASK_1_PARAMETER )\r
80         {\r
81                 /* Error detected.  Delete the task so it stops communicating with\r
82                 the check task. */\r
83                 vMainDeleteMe();\r
84         }\r
85 \r
86         for( ;; )\r
87         {\r
88                 /* This task tests the kernel context switch mechanism by reading and\r
89                 writing directly to registers - which requires the test to be written\r
90                 in assembly code. */\r
91                 __asm volatile\r
92                 (\r
93                         "               MOV     R4, #104                        \n" /* Set registers to a known value.  R0 to R1 are done in the loop below. */\r
94                         "               MOV     R5, #105                        \n"\r
95                         "               MOV     R6, #106                        \n"\r
96                         "               MOV     R8, #108                        \n"\r
97                         "               MOV     R9, #109                        \n"\r
98                         "               MOV     R10, #110                       \n"\r
99                         "               MOV     R11, #111                       \n"\r
100                         "reg1loop:                                              \n"\r
101                         "               MOV     R0, #100                        \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
102                         "               MOV     R1, #101                        \n"\r
103                         "               MOV     R2, #102                        \n"\r
104                         "               MOV R3, #103                    \n"\r
105                         "               MOV     R12, #112                       \n"\r
106                         "               SVC #1                                  \n" /* Yield just to increase test coverage. */\r
107                         "               CMP     R0, #100                        \n" /* Check all the registers still contain their expected values. */\r
108                         "               BNE     vMainDeleteMe           \n" /* Value was not as expected, delete the task so it stops communicating with the check task. */\r
109                         "               CMP     R1, #101                        \n"\r
110                         "               BNE     vMainDeleteMe           \n"\r
111                         "               CMP     R2, #102                        \n"\r
112                         "               BNE     vMainDeleteMe           \n"\r
113                         "               CMP R3, #103                    \n"\r
114                         "               BNE     vMainDeleteMe           \n"\r
115                         "               CMP     R4, #104                        \n"\r
116                         "               BNE     vMainDeleteMe           \n"\r
117                         "               CMP     R5, #105                        \n"\r
118                         "               BNE     vMainDeleteMe           \n"\r
119                         "               CMP     R6, #106                        \n"\r
120                         "               BNE     vMainDeleteMe           \n"\r
121                         "               CMP     R8, #108                        \n"\r
122                         "               BNE     vMainDeleteMe           \n"\r
123                         "               CMP     R9, #109                        \n"\r
124                         "               BNE     vMainDeleteMe           \n"\r
125                         "               CMP     R10, #110                       \n"\r
126                         "               BNE     vMainDeleteMe           \n"\r
127                         "               CMP     R11, #111                       \n"\r
128                         "               BNE     vMainDeleteMe           \n"\r
129                         "               CMP     R12, #112                       \n"\r
130                         "               BNE     vMainDeleteMe           \n"\r
131                         :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
132                 );\r
133 \r
134                 /* Send configREG_TEST_1_STILL_EXECUTING to the check task to indicate that this\r
135                 task is still functioning. */\r
136                 vMainSendImAlive( xQueue, configREG_TEST_1_STILL_EXECUTING );\r
137 \r
138                 /* Go back to check all the register values again. */\r
139                 __asm volatile( "               B reg1loop      " );\r
140         }\r
141 }\r
142 /*-----------------------------------------------------------*/\r
143 \r
144 void vRegTest2Implementation( void *pvParameters )\r
145 {\r
146 /* The queue handle is passed in as the task parameter.  This is one method of\r
147 passing data into a protected task, the other reg test task uses a different\r
148 method. */\r
149 QueueHandle_t xQueue = ( QueueHandle_t ) pvParameters;\r
150 \r
151         for( ;; )\r
152         {\r
153                 /* This task tests the kernel context switch mechanism by reading and\r
154                 writing directly to registers - which requires the test to be written\r
155                 in assembly code. */\r
156                 __asm volatile\r
157                 (\r
158                         "               MOV     R4, #4                          \n" /* Set registers to a known value.  R0 to R1 are done in the loop below. */\r
159                         "               MOV     R5, #5                          \n"\r
160                         "               MOV     R6, #6                          \n"\r
161                         "               MOV     R8, #8                          \n" /* Frame pointer is omitted as it must not be changed. */\r
162                         "               MOV     R9, #9                          \n"\r
163                         "               MOV     R10, 10                         \n"\r
164                         "               MOV     R11, #11                        \n"\r
165                         "reg2loop:                                              \n"\r
166                         "               MOV     R0, #13                         \n" /* Set the scratch registers to known values - done inside the loop as they get clobbered. */\r
167                         "               MOV     R1, #1                          \n"\r
168                         "               MOV     R2, #2                          \n"\r
169                         "               MOV R3, #3                              \n"\r
170                         "               MOV     R12, #12                        \n"\r
171                         "               CMP     R0, #13                         \n" /* Check all the registers still contain their expected values. */\r
172                         "               BNE     vMainDeleteMe           \n" /* Value was not as expected, delete the task so it stops communicating with the check task */\r
173                         "               CMP     R1, #1                          \n"\r
174                         "               BNE     vMainDeleteMe           \n"\r
175                         "               CMP     R2, #2                          \n"\r
176                         "               BNE     vMainDeleteMe           \n"\r
177                         "               CMP R3, #3                              \n"\r
178                         "               BNE     vMainDeleteMe           \n"\r
179                         "               CMP     R4, #4                          \n"\r
180                         "               BNE     vMainDeleteMe           \n"\r
181                         "               CMP     R5, #5                          \n"\r
182                         "               BNE     vMainDeleteMe           \n"\r
183                         "               CMP     R6, #6                          \n"\r
184                         "               BNE     vMainDeleteMe           \n"\r
185                         "               CMP     R8, #8                          \n"\r
186                         "               BNE     vMainDeleteMe           \n"\r
187                         "               CMP     R9, #9                          \n"\r
188                         "               BNE     vMainDeleteMe           \n"\r
189                         "               CMP     R10, #10                        \n"\r
190                         "               BNE     vMainDeleteMe           \n"\r
191                         "               CMP     R11, #11                        \n"\r
192                         "               BNE     vMainDeleteMe           \n"\r
193                         "               CMP     R12, #12                        \n"\r
194                         "               BNE     vMainDeleteMe           \n"\r
195                         :::"r0", "r1", "r2", "r3", "r4", "r5", "r6", "r8", "r9", "r10", "r11", "r12"\r
196                 );\r
197 \r
198                 /* Send configREG_TEST_2_STILL_EXECUTING to the check task to indicate that this\r
199                 task is still functioning. */\r
200                 vMainSendImAlive( xQueue, configREG_TEST_2_STILL_EXECUTING );\r
201 \r
202                 /* Go back to check all the register values again. */\r
203                 __asm volatile( "               B reg2loop      " );\r
204         }\r
205 }\r
206 /*-----------------------------------------------------------*/\r
207 \r
208 void vRegTest3Implementation( void )\r
209 {\r
210         __asm volatile\r
211         (\r
212                 ".extern pulRegTest3LoopCounter \n"\r
213                 "/* Fill the core registers with known values. */               \n"\r
214                 "mov    r0, #100                        \n"\r
215                 "mov    r1, #101                        \n"\r
216                 "mov    r2, #102                        \n"\r
217                 "mov    r3, #103                        \n"\r
218                 "mov    r4, #104                        \n"\r
219                 "mov    r5, #105                        \n"\r
220                 "mov    r6, #106                        \n"\r
221                 "mov    r7, #107                        \n"\r
222                 "mov    r8, #108                        \n"\r
223                 "mov    r9, #109                        \n"\r
224                 "mov    r10, #110                       \n"\r
225                 "mov    r11, #111                       \n"\r
226                 "mov    r12, #112                       \n"\r
227 \r
228                 "/* Fill the VFP registers with known values. */                \n"\r
229                 "vmov   d0, r0, r1                      \n"\r
230                 "vmov   d1, r2, r3                      \n"\r
231                 "vmov   d2, r4, r5                      \n"\r
232                 "vmov   d3, r6, r7                      \n"\r
233                 "vmov   d4, r8, r9                      \n"\r
234                 "vmov   d5, r10, r11            \n"\r
235                 "vmov   d6, r0, r1                      \n"\r
236                 "vmov   d7, r2, r3                      \n"\r
237                 "vmov   d8, r4, r5                      \n"\r
238                 "vmov   d9, r6, r7                      \n"\r
239                 "vmov   d10, r8, r9                     \n"\r
240                 "vmov   d11, r10, r11           \n"\r
241                 "vmov   d12, r0, r1                     \n"\r
242                 "vmov   d13, r2, r3                     \n"\r
243                 "vmov   d14, r4, r5                     \n"\r
244                 "vmov   d15, r6, r7                     \n"\r
245 \r
246         "reg1_loop:                                             \n"\r
247                 "/* Check all the VFP registers still contain the values set above.             \n"\r
248                 "First save registers that are clobbered by the test. */                                \n"\r
249                 "push { r0-r1 }                         \n"\r
250 \r
251                 "vmov   r0, r1, d0                      \n"\r
252                 "cmp    r0, #100                        \n"\r
253                 "bne    reg1_error_loopf        \n"\r
254                 "cmp    r1, #101                        \n"\r
255                 "bne    reg1_error_loopf        \n"\r
256                 "vmov   r0, r1, d1                      \n"\r
257                 "cmp    r0, #102                        \n"\r
258                 "bne    reg1_error_loopf        \n"\r
259                 "cmp    r1, #103                        \n"\r
260                 "bne    reg1_error_loopf        \n"\r
261                 "vmov   r0, r1, d2                      \n"\r
262                 "cmp    r0, #104                        \n"\r
263                 "bne    reg1_error_loopf        \n"\r
264                 "cmp    r1, #105                        \n"\r
265                 "bne    reg1_error_loopf        \n"\r
266                 "vmov   r0, r1, d3                      \n"\r
267                 "cmp    r0, #106                        \n"\r
268                 "bne    reg1_error_loopf        \n"\r
269                 "cmp    r1, #107                        \n"\r
270                 "bne    reg1_error_loopf        \n"\r
271                 "vmov   r0, r1, d4                      \n"\r
272                 "cmp    r0, #108                        \n"\r
273                 "bne    reg1_error_loopf        \n"\r
274                 "cmp    r1, #109                        \n"\r
275                 "bne    reg1_error_loopf        \n"\r
276                 "vmov   r0, r1, d5                      \n"\r
277                 "cmp    r0, #110                        \n"\r
278                 "bne    reg1_error_loopf        \n"\r
279                 "cmp    r1, #111                        \n"\r
280                 "bne    reg1_error_loopf        \n"\r
281                 "vmov   r0, r1, d6                      \n"\r
282                 "cmp    r0, #100                        \n"\r
283                 "bne    reg1_error_loopf        \n"\r
284                 "cmp    r1, #101                        \n"\r
285                 "bne    reg1_error_loopf        \n"\r
286                 "vmov   r0, r1, d7                      \n"\r
287                 "cmp    r0, #102                        \n"\r
288                 "bne    reg1_error_loopf        \n"\r
289                 "cmp    r1, #103                        \n"\r
290                 "bne    reg1_error_loopf        \n"\r
291                 "vmov   r0, r1, d8                      \n"\r
292                 "cmp    r0, #104                        \n"\r
293                 "bne    reg1_error_loopf        \n"\r
294                 "cmp    r1, #105                        \n"\r
295                 "bne    reg1_error_loopf        \n"\r
296                 "vmov   r0, r1, d9                      \n"\r
297                 "cmp    r0, #106                        \n"\r
298                 "bne    reg1_error_loopf        \n"\r
299                 "cmp    r1, #107                        \n"\r
300                 "bne    reg1_error_loopf        \n"\r
301                 "vmov   r0, r1, d10                     \n"\r
302                 "cmp    r0, #108                        \n"\r
303                 "bne    reg1_error_loopf        \n"\r
304                 "cmp    r1, #109                        \n"\r
305                 "bne    reg1_error_loopf        \n"\r
306                 "vmov   r0, r1, d11                     \n"\r
307                 "cmp    r0, #110                        \n"\r
308                 "bne    reg1_error_loopf        \n"\r
309                 "cmp    r1, #111                        \n"\r
310                 "bne    reg1_error_loopf        \n"\r
311                 "vmov   r0, r1, d12                     \n"\r
312                 "cmp    r0, #100                        \n"\r
313                 "bne    reg1_error_loopf        \n"\r
314                 "cmp    r1, #101                        \n"\r
315                 "bne    reg1_error_loopf        \n"\r
316                 "vmov   r0, r1, d13                     \n"\r
317                 "cmp    r0, #102                        \n"\r
318                 "bne    reg1_error_loopf        \n"\r
319                 "cmp    r1, #103                        \n"\r
320                 "bne    reg1_error_loopf        \n"\r
321                 "vmov   r0, r1, d14                     \n"\r
322                 "cmp    r0, #104                        \n"\r
323                 "bne    reg1_error_loopf        \n"\r
324                 "cmp    r1, #105                        \n"\r
325                 "bne    reg1_error_loopf        \n"\r
326                 "vmov   r0, r1, d15                     \n"\r
327                 "cmp    r0, #106                        \n"\r
328                 "bne    reg1_error_loopf        \n"\r
329                 "cmp    r1, #107                        \n"\r
330                 "bne    reg1_error_loopf        \n"\r
331 \r
332                 "/* Restore the registers that were clobbered by the test. */           \n"\r
333                 "pop    {r0-r1}                         \n"\r
334 \r
335                 "/* VFP register test passed.  Jump to the core register test. */       \n"\r
336                 "b              reg1_loopf_pass         \n"\r
337 \r
338         "reg1_error_loopf:                              \n"\r
339                 "/* If this line is hit then a VFP register value was found to be incorrect. */         \n"\r
340                 "b reg1_error_loopf                     \n"\r
341 \r
342         "reg1_loopf_pass:                               \n"\r
343 \r
344                 "cmp    r0, #100                        \n"\r
345                 "bne    reg1_error_loop         \n"\r
346                 "cmp    r1, #101                        \n"\r
347                 "bne    reg1_error_loop         \n"\r
348                 "cmp    r2, #102                        \n"\r
349                 "bne    reg1_error_loop         \n"\r
350                 "cmp    r3, #103                        \n"\r
351                 "bne    reg1_error_loop         \n"\r
352                 "cmp    r4, #104                        \n"\r
353                 "bne    reg1_error_loop         \n"\r
354                 "cmp    r5, #105                        \n"\r
355                 "bne    reg1_error_loop         \n"\r
356                 "cmp    r6, #106                        \n"\r
357                 "bne    reg1_error_loop         \n"\r
358                 "cmp    r7, #107                        \n"\r
359                 "bne    reg1_error_loop         \n"\r
360                 "cmp    r8, #108                        \n"\r
361                 "bne    reg1_error_loop         \n"\r
362                 "cmp    r9, #109                        \n"\r
363                 "bne    reg1_error_loop         \n"\r
364                 "cmp    r10, #110                       \n"\r
365                 "bne    reg1_error_loop         \n"\r
366                 "cmp    r11, #111                       \n"\r
367                 "bne    reg1_error_loop         \n"\r
368                 "cmp    r12, #112                       \n"\r
369                 "bne    reg1_error_loop         \n"\r
370 \r
371                 "/* Everything passed, increment the loop counter. */   \n"\r
372                 "push   { r0-r1 }                       \n"\r
373                 "ldr    r0, =pulRegTest3LoopCounter     \n"\r
374                 "ldr    r0, [r0]                        \n"\r
375                 "ldr    r1, [r0]                        \n"\r
376                 "adds   r1, r1, #1                      \n"\r
377                 "str    r1, [r0]                        \n"\r
378                 "pop    { r0-r1 }                       \n"\r
379 \r
380                 "/* Start again. */                     \n"\r
381                 "b              reg1_loop                       \n"\r
382 \r
383         "reg1_error_loop:                               \n"\r
384                 "/* If this line is hit then there was an error in a core register value. \n"\r
385                 "The loop ensures the loop counter stops incrementing. */       \n"\r
386                 "b      reg1_error_loop                 \n"\r
387                 "nop                                            "\r
388         ); /* __asm volatile. */\r
389 }\r
390 /*-----------------------------------------------------------*/\r
391 \r
392 void vRegTest4Implementation( void )\r
393 {\r
394         __asm volatile\r
395         (\r
396                 ".extern pulRegTest4LoopCounter \n"\r
397                 "/* Set all the core registers to known values. */      \n"\r
398                 "mov    r0, #-1                         \n"\r
399                 "mov    r1, #1                          \n"\r
400                 "mov    r2, #2                          \n"\r
401                 "mov    r3, #3                          \n"\r
402                 "mov    r4, #4                          \n"\r
403                 "mov    r5, #5                          \n"\r
404                 "mov    r6, #6                          \n"\r
405                 "mov    r7, #7                          \n"\r
406                 "mov    r8, #8                          \n"\r
407                 "mov    r9, #9                          \n"\r
408                 "mov    r10, #10                        \n"\r
409                 "mov    r11, #11                        \n"\r
410                 "mov    r12, #12                        \n"\r
411 \r
412                 "/* Set all the VFP to known values. */  \n"\r
413                 "vmov   d0, r0, r1                      \n"\r
414                 "vmov   d1, r2, r3                      \n"\r
415                 "vmov   d2, r4, r5                      \n"\r
416                 "vmov   d3, r6, r7                      \n"\r
417                 "vmov   d4, r8, r9                      \n"\r
418                 "vmov   d5, r10, r11            \n"\r
419                 "vmov   d6, r0, r1                      \n"\r
420                 "vmov   d7, r2, r3                      \n"\r
421                 "vmov   d8, r4, r5                      \n"\r
422                 "vmov   d9, r6, r7                      \n"\r
423                 "vmov   d10, r8, r9                     \n"\r
424                 "vmov   d11, r10, r11           \n"\r
425                 "vmov   d12, r0, r1                     \n"\r
426                 "vmov   d13, r2, r3                     \n"\r
427                 "vmov   d14, r4, r5                     \n"\r
428                 "vmov   d15, r6, r7                     \n"\r
429 \r
430         "reg2_loop:                                             \n"\r
431 \r
432                 "/* Check all the VFP registers still contain the values set above.             \n"\r
433                 "First save registers that are clobbered by the test. */                                \n"\r
434                 "push { r0-r1 }                         \n"\r
435 \r
436                 "vmov   r0, r1, d0                      \n"\r
437                 "cmp    r0, #-1                         \n"\r
438                 "bne    reg2_error_loopf        \n"\r
439                 "cmp    r1, #1                          \n"\r
440                 "bne    reg2_error_loopf        \n"\r
441                 "vmov   r0, r1, d1                      \n"\r
442                 "cmp    r0, #2                          \n"\r
443                 "bne    reg2_error_loopf        \n"\r
444                 "cmp    r1, #3                          \n"\r
445                 "bne    reg2_error_loopf        \n"\r
446                 "vmov   r0, r1, d2                      \n"\r
447                 "cmp    r0, #4                          \n"\r
448                 "bne    reg2_error_loopf        \n"\r
449                 "cmp    r1, #5                          \n"\r
450                 "bne    reg2_error_loopf        \n"\r
451                 "vmov   r0, r1, d3                      \n"\r
452                 "cmp    r0, #6                          \n"\r
453                 "bne    reg2_error_loopf        \n"\r
454                 "cmp    r1, #7                          \n"\r
455                 "bne    reg2_error_loopf        \n"\r
456                 "vmov   r0, r1, d4                      \n"\r
457                 "cmp    r0, #8                          \n"\r
458                 "bne    reg2_error_loopf        \n"\r
459                 "cmp    r1, #9                          \n"\r
460                 "bne    reg2_error_loopf        \n"\r
461                 "vmov   r0, r1, d5                      \n"\r
462                 "cmp    r0, #10                         \n"\r
463                 "bne    reg2_error_loopf        \n"\r
464                 "cmp    r1, #11                         \n"\r
465                 "bne    reg2_error_loopf        \n"\r
466                 "vmov   r0, r1, d6                      \n"\r
467                 "cmp    r0, #-1                         \n"\r
468                 "bne    reg2_error_loopf        \n"\r
469                 "cmp    r1, #1                          \n"\r
470                 "bne    reg2_error_loopf        \n"\r
471                 "vmov   r0, r1, d7                      \n"\r
472                 "cmp    r0, #2                          \n"\r
473                 "bne    reg2_error_loopf        \n"\r
474                 "cmp    r1, #3                          \n"\r
475                 "bne    reg2_error_loopf        \n"\r
476                 "vmov   r0, r1, d8                      \n"\r
477                 "cmp    r0, #4                          \n"\r
478                 "bne    reg2_error_loopf        \n"\r
479                 "cmp    r1, #5                          \n"\r
480                 "bne    reg2_error_loopf        \n"\r
481                 "vmov   r0, r1, d9                      \n"\r
482                 "cmp    r0, #6                          \n"\r
483                 "bne    reg2_error_loopf        \n"\r
484                 "cmp    r1, #7                          \n"\r
485                 "bne    reg2_error_loopf        \n"\r
486                 "vmov   r0, r1, d10                     \n"\r
487                 "cmp    r0, #8                          \n"\r
488                 "bne    reg2_error_loopf        \n"\r
489                 "cmp    r1, #9                          \n"\r
490                 "bne    reg2_error_loopf        \n"\r
491                 "vmov   r0, r1, d11                     \n"\r
492                 "cmp    r0, #10                         \n"\r
493                 "bne    reg2_error_loopf        \n"\r
494                 "cmp    r1, #11                         \n"\r
495                 "bne    reg2_error_loopf        \n"\r
496                 "vmov   r0, r1, d12                     \n"\r
497                 "cmp    r0, #-1                         \n"\r
498                 "bne    reg2_error_loopf        \n"\r
499                 "cmp    r1, #1                          \n"\r
500                 "bne    reg2_error_loopf        \n"\r
501                 "vmov   r0, r1, d13                     \n"\r
502                 "cmp    r0, #2                          \n"\r
503                 "bne    reg2_error_loopf        \n"\r
504                 "cmp    r1, #3                          \n"\r
505                 "bne    reg2_error_loopf        \n"\r
506                 "vmov   r0, r1, d14                     \n"\r
507                 "cmp    r0, #4                          \n"\r
508                 "bne    reg2_error_loopf        \n"\r
509                 "cmp    r1, #5                          \n"\r
510                 "bne    reg2_error_loopf        \n"\r
511                 "vmov   r0, r1, d15                     \n"\r
512                 "cmp    r0, #6                          \n"\r
513                 "bne    reg2_error_loopf        \n"\r
514                 "cmp    r1, #7                          \n"\r
515                 "bne    reg2_error_loopf        \n"\r
516 \r
517                 "/* Restore the registers that were clobbered by the test. */           \n"\r
518                 "pop    {r0-r1}                         \n"\r
519 \r
520                 "/* VFP register test passed.  Jump to the core register test. */               \n"\r
521                 "b              reg2_loopf_pass         \n"\r
522 \r
523         "reg2_error_loopf:                              \n"\r
524                 "/* If this line is hit then a VFP register value was found to be               \n"\r
525                 "incorrect. */                          \n"\r
526                 "b reg2_error_loopf                     \n"\r
527 \r
528         "reg2_loopf_pass:                               \n"\r
529 \r
530                 "cmp    r0, #-1                         \n"\r
531                 "bne    reg2_error_loop         \n"\r
532                 "cmp    r1, #1                          \n"\r
533                 "bne    reg2_error_loop         \n"\r
534                 "cmp    r2, #2                          \n"\r
535                 "bne    reg2_error_loop         \n"\r
536                 "cmp    r3, #3                          \n"\r
537                 "bne    reg2_error_loop         \n"\r
538                 "cmp    r4, #4                          \n"\r
539                 "bne    reg2_error_loop         \n"\r
540                 "cmp    r5, #5                          \n"\r
541                 "bne    reg2_error_loop         \n"\r
542                 "cmp    r6, #6                          \n"\r
543                 "bne    reg2_error_loop         \n"\r
544                 "cmp    r7, #7                          \n"\r
545                 "bne    reg2_error_loop         \n"\r
546                 "cmp    r8, #8                          \n"\r
547                 "bne    reg2_error_loop         \n"\r
548                 "cmp    r9, #9                          \n"\r
549                 "bne    reg2_error_loop         \n"\r
550                 "cmp    r10, #10                        \n"\r
551                 "bne    reg2_error_loop         \n"\r
552                 "cmp    r11, #11                        \n"\r
553                 "bne    reg2_error_loop         \n"\r
554                 "cmp    r12, #12                        \n"\r
555                 "bne    reg2_error_loop         \n"\r
556 \r
557                 "/* Increment the loop counter so the check task knows this task is \n"\r
558                 "still running. */                      \n"\r
559                 "push   { r0-r1 }                       \n"\r
560                 "ldr    r0, =pulRegTest4LoopCounter     \n"\r
561                 "ldr    r0, [r0]                        \n"\r
562                 "ldr    r1, [r0]                        \n"\r
563                 "adds   r1, r1, #1                      \n"\r
564                 "str    r1, [r0]                        \n"\r
565                 "pop { r0-r1 }                          \n"\r
566 \r
567                 "/* Yield to increase test coverage. */                 \n"\r
568                 "SVC #1                                         \n"\r
569 \r
570                 "/* Start again. */                     \n"\r
571                 "b reg2_loop                            \n"\r
572 \r
573         "reg2_error_loop:                               \n"\r
574                 "/* If this line is hit then there was an error in a core register value.       \n"\r
575                 "This loop ensures the loop counter variable stops incrementing. */                     \n"\r
576                 "b reg2_error_loop                      \n"\r
577         ); /* __asm volatile */\r
578 }\r
579 /*-----------------------------------------------------------*/\r
580 \r
581 /* Fault handlers are here for convenience as they use compiler specific syntax\r
582 and this file is specific to the GCC compiler. */\r
583 void hard_fault_handler( uint32_t * hardfault_args )\r
584 {\r
585 volatile uint32_t stacked_r0;\r
586 volatile uint32_t stacked_r1;\r
587 volatile uint32_t stacked_r2;\r
588 volatile uint32_t stacked_r3;\r
589 volatile uint32_t stacked_r12;\r
590 volatile uint32_t stacked_lr;\r
591 volatile uint32_t stacked_pc;\r
592 volatile uint32_t stacked_psr;\r
593 \r
594         stacked_r0 = ((uint32_t) hardfault_args[ 0 ]);\r
595         stacked_r1 = ((uint32_t) hardfault_args[ 1 ]);\r
596         stacked_r2 = ((uint32_t) hardfault_args[ 2 ]);\r
597         stacked_r3 = ((uint32_t) hardfault_args[ 3 ]);\r
598 \r
599         stacked_r12 = ((uint32_t) hardfault_args[ 4 ]);\r
600         stacked_lr = ((uint32_t) hardfault_args[ 5 ]);\r
601         stacked_pc = ((uint32_t) hardfault_args[ 6 ]);\r
602         stacked_psr = ((uint32_t) hardfault_args[ 7 ]);\r
603 \r
604         /* Inspect stacked_pc to locate the offending instruction. */\r
605         for( ;; );\r
606 \r
607         ( void ) stacked_psr;\r
608         ( void ) stacked_pc;\r
609         ( void ) stacked_lr;\r
610         ( void ) stacked_r12;\r
611     ( void ) stacked_r0;\r
612     ( void ) stacked_r1;\r
613     ( void ) stacked_r2;\r
614     ( void ) stacked_r3;\r
615 }\r
616 /*-----------------------------------------------------------*/\r
617 \r
618 void HardFault_Handler( void ) __attribute__((naked));\r
619 void HardFault_Handler( void )\r
620 {\r
621         __asm volatile\r
622         (\r
623                 " tst lr, #4                                                                            \n"\r
624                 " ite eq                                                                                        \n"\r
625                 " mrseq r0, msp                                                                         \n"\r
626                 " mrsne r0, psp                                                                         \n"\r
627                 " ldr r1, [r0, #24]                                                                     \n"\r
628                 " ldr r2, handler_address_const                                         \n"\r
629                 " bx r2                                                                                         \n"\r
630                 " handler_address_const: .word hard_fault_handler       \n"\r
631         );\r
632 }\r
633 /*-----------------------------------------------------------*/\r
634 \r
635 void MemManage_Handler( void ) __attribute__((naked));\r
636 void MemManage_Handler( void )\r
637 {\r
638         __asm volatile\r
639         (\r
640                 " tst lr, #4                                                                            \n"\r
641                 " ite eq                                                                                        \n"\r
642                 " mrseq r0, msp                                                                         \n"\r
643                 " mrsne r0, psp                                                                         \n"\r
644                 " ldr r1, [r0, #24]                                                                     \n"\r
645                 " ldr r2, handler2_address_const                                        \n"\r
646                 " bx r2                                                                                         \n"\r
647                 " handler2_address_const: .word hard_fault_handler      \n"\r
648         );\r
649 }/*-----------------------------------------------------------*/\r
650 \r