aboutsummaryrefslogtreecommitdiffstats
path: root/demos/STM32/RT-STM32F407-DISCOVERY-fault_handlers/crash_test_asm.S
blob: 57a2f8a1084a2ef7fe3637443de26c8870bca9a7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
/* Copyright (C) 2018  Adam Green (https://github.com/adamgreen)

   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at

       http://www.apache.org/licenses/LICENSE-2.0

   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
*/
/* Implementation of code to generate various crash scenarios for testing. */
    .text
    .syntax unified

    .global testMspMultipleOf8
    .type testMspMultipleOf8, %function
    .thumb_func
    /* extern "C" void testMspMultipleOf8(void);
       Uses MSP and has it pointing to an even multiple of 8.
    */
testMspMultipleOf8:
    // Make SP, an even multiple of 8.
    mov     r0, sp
    movs    r1, #4
    bics    r0, r1
    mov     sp, r0
    // Load 0xFFFFFFFF into LR
    movs    r1, #1
    rsbs    r0, r1, #0
    mov     lr, r0
    // Load known values into R0-R12
    movs    r0, #0
    // r1 was already set correctly above when initializing LR.
    movs    r2, #2
    movs    r3, #3
    movs    r4, #4
    movs    r5, #5
    movs    r6, #6
    movs    r7, #7
    mov     r8, r7
    mov     r9, r7
    mov     r10, r7
    mov     r11, r7
    mov     r12, r7
    add     r8, r1
    add     r9, r2
    add     r10, r3
    add     r11, r4
    add     r12, r5
    // Generate a hard fault by executing an undefined instruction.
    .word 0xDE00
    // CrashCatcher_Entry() shouldn't return but if it does, just infinite loop here.
    b       .
    // Let assembler know that we have hit the end of the function.
    .pool
    .size   testMspMultipleOf8, .-testMspMultipleOf8


    .global testMspNotMultipleOf8
    .type testMspNotMultipleOf8, %function
    .thumb_func
    /* extern "C" void testMspNotMultipleOf8(void);
       Uses MSP and has it not pointing to an even multiple of 8.
    */
testMspNotMultipleOf8:
    // Make SP, not an even multiple of 8.
    mov     r0, sp
    subs    r0, #8
    movs    r1, #4
    orrs    r0, r1
    mov     sp, r0
    // Load 0xFFFFFFFF into LR
    movs    r1, #1
    rsbs    r0, r1, #0
    mov     lr, r0
    // Load known values into R0-R12
    movs    r0, #0
    // r1 was already set correctly above when initializing LR.
    movs    r2, #2
    movs    r3, #3
    movs    r4, #4
    movs    r5, #5
    movs    r6, #6
    movs    r7, #7
    mov     r8, r7
    mov     r9, r7
    mov     r10, r7
    mov     r11, r7
    mov     r12, r7
    add     r8, r1
    add     r9, r2
    add     r10, r3
    add     r11, r4
    add     r12, r5
    // Generate a hard fault by executing an undefined instruction.
    .word 0xDE00
    // CrashCatcher_Entry() shouldn't return but if it does, just infinite loop here.
    b       .
    // Let assembler know that we have hit the end of the function.
    .pool
    .size   testMspNotMultipleOf8, .-testMspNotMultipleOf8


    .global testPspMultipleOf8
    .type testPspMultipleOf8, %function
    .thumb_func
    /* extern "C" void testPspMultipleOf8(void);
       Uses MSP and has it pointing to an even multiple of 8.
    */
testPspMultipleOf8:
    // Make PSP, an even multiple of 8.
    mov     r0, sp
    movs    r1, #4
    bics    r0, r1
    msr     psp, r0
    // Switch to use of PSP.
    movs    r0, #3
    msr     control,r0
    // Flush instructions so that control mods take effect.
    isb
    // Load 0xFFFFFFFF into LR
    movs    r1, #1
    rsbs    r0, r1, #0
    mov     lr, r0
    // Load known values into R0-R12
    movs    r0, #0
    // r1 was already set correctly above when initializing LR.
    movs    r2, #2
    movs    r3, #3
    movs    r4, #4
    movs    r5, #5
    movs    r6, #6
    movs    r7, #7
    mov     r8, r7
    mov     r9, r7
    mov     r10, r7
    mov     r11, r7
    mov     r12, r7
    add     r8, r1
    add     r9, r2
    add     r10, r3
    add     r11, r4
    add     r12, r5
    // Generate a hard fault by executing an undefined instruction.
    .word 0xDE00
    // CrashCatcher_Entry() shouldn't return but if it does, just infinite loop here.
    b       .
    // Let assembler know that we have hit the end of the function.
    .pool
    .size   testPspMultipleOf8, .-testPspMultipleOf8


    .global testBreakpoints
    .type testBreakpoints, %function
    .thumb_func
    /* extern "C" void testBreakpoints(void);
       Set registers to known values, breakpoint, allow continuation, and breakpoint again to see if anything changed.
    */
testBreakpoints:
    // Save away non-volatile registers that will be modified for testing.
    mov     r0, r8
    mov     r1, r9
    mov     r2, r10
    mov     r3, r11
    push    {r0-r7}

    // Load incrementing values into R0-R12
    movs    r0, #0
    movs    r1, #1
    movs    r2, #2
    movs    r3, #3
    movs    r4, #4
    movs    r5, #5
    movs    r6, #6
    movs    r7, #7
    mov     r8, r7
    mov     r9, r7
    mov     r10, r7
    mov     r11, r7
    mov     r12, r7
    add     r8, r1
    add     r9, r2
    add     r10, r3
    add     r11, r4
    add     r12, r5

    // Issue one hard coded breakpoint.
    bkpt    #0

    // Issue another hard coded breakpoint and see if dumps contain same values for all registers other than PC.
    bkpt    #255

    // Restore non-volatile registers and return to caller.
    pop     {r0-r7}
    mov     r8, r0
    mov     r9, r1
    mov     r10, r2
    mov     r11, r3
    bx      lr

    // Let assembler know that we have hit the end of the function.
    .pool
    .size   testBreakpoints, .-testBreakpoints


#if defined(TARGET_M4)

    .global testInitFPURegisters
    .type testInitFPURegisters, %function
    .thumb_func
    /* extern "C" void testInitFPURegisters(void);
       Initialize FPU registers to known values.
    */
testInitFPURegisters:
    vmov.f32    s0, #-1.0
    vmov.f32    s1, #1.0
    vmov.f32    s2, #2.0
    vmov.f32    s3, #3.0
    vmov.f32    s4, #4.0
    vmov.f32    s5, #5.0
    vmov.f32    s6, #6.0
    vmov.f32    s7, #7.0
    vmov.f32    s8, #8.0
    vmov.f32    s9, #9.0
    vmov.f32    s10, #10.0
    vmov.f32    s11, #11.0
    vmov.f32    s12, #12.0
    vmov.f32    s13, #13.0
    vmov.f32    s14, #14.0
    vmov.f32    s15, #15.0
    vmov.f32    s16, #16.0
    vmov.f32    s17, #17.0
    vmov.f32    s18, #18.0
    vmov.f32    s19, #19.0
    vmov.f32    s20, #20.0
    vmov.f32    s21, #21.0
    vmov.f32    s22, #22.0
    vmov.f32    s23, #23.0
    vmov.f32    s24, #24.0
    vmov.f32    s25, #25.0
    vmov.f32    s26, #26.0
    vmov.f32    s27, #27.0
    vmov.f32    s28, #28.0
    vmov.f32    s29, #29.0
    vmov.f32    s30, #30.0
    vmov.f32    s31, #31.0
    ldr         r0, =0xBAADFEED
    vmsr        fpscr, r0
    bx          lr
    .pool
    .size   testInitFPURegisters, .-testInitFPURegisters

#else

    .global testInitFPURegisters
    .type testInitFPURegisters, %function
    .thumb_func
    /* extern "C" void testInitFPURegisters(void);
       Initialize FPU registers to known values.
    */
testInitFPURegisters:
    bx      lr
    .pool
    .size   testInitFPURegisters, .-testInitFPURegisters

#endif


    .end