1 /*
2 * Copyright (c) 2024 Huawei Device Co., Ltd.
3 * Licensed under the Apache License, Version 2.0 (the "License");
4 * you may not use this file except in compliance with the License.
5 * You may obtain a copy of the License at
6 *
7 * http://www.apache.org/licenses/LICENSE-2.0
8 *
9 * Unless required by applicable law or agreed to in writing, software
10 * distributed under the License is distributed on an "AS IS" BASIS,
11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 * See the License for the specific language governing permissions and
13 * limitations under the License.
14 */
15
16 #ifndef DFX_CRASHER
17 #define DFX_CRASHER
18 static const int ARG1024 = 1024;
19 static const int ARG128 = 128;
20
ProgramVolatile(void)21 void ProgramVolatile(void)
22 {
23 #if defined(__arm__)
24 __asm__ volatile (
25 "mov r0, #0x00\n mov lr, pc\n bx r0\n"
26 );
27 #elif defined(__aarch64__)
28 __asm__ volatile (
29 "movz x0, #0x0\n"
30 "adr x30, .\n"
31 "br x0\n"
32 );
33 #elif defined(__loongarch_lp64)
34 __asm__ volatile (
35 "pcaddi $ra, 0\n"
36 "jr $zero\n"
37 );
38 #endif
39 }
40
IllegalVolatile(void)41 void IllegalVolatile(void)
42 {
43 #if defined(__aarch64__)
44 __asm__ volatile(".word 0\n");
45 #elif defined(__arm__)
46 __asm__ volatile(".word 0xe7f0def0\n");
47 #elif defined(__x86_64__)
48 __asm__ volatile("ud2\n");
49 #elif defined(__loongarch_lp64)
50 // Effective illegal instruction on LoongArch64: amswap.w $zero, $ra, $zero
51 __asm__ volatile(".word 0x38600400\n");
52 #else
53 #error
54 #endif
55 }
56
57 #endif // DFX_CRASHER
58