-
-
Notifications
You must be signed in to change notification settings - Fork 596
/
m5ops.c
90 lines (87 loc) · 1.89 KB
/
m5ops.c
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
/* https://github.com/cirosantilli/linux-kernel-module-cheat#m5ops-instructions */
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#define ENABLED 1
#if defined(__arm__)
static void m5_checkpoint(void)
{
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x43 << 16);");
};
static void m5_dump_stats(void)
{
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x41 << 16);");
};
static void m5_exit()
{
__asm__ __volatile__ ("mov r0, #0; .inst 0xEE000110 | (0x21 << 16);");
};
static void m5_fail_1(void)
{
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #1; mov r3, #0; .inst 0xEE000110 | (0x22 << 16);");
};
static void m5_reset_stats(void)
{
__asm__ __volatile__ ("mov r0, #0; mov r1, #0; mov r2, #0; mov r3, #0; .inst 0xEE000110 | (0x40 << 16);");
};
#elif defined(__aarch64__)
static void m5_checkpoint(void)
{
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x43 << 16);");
};
static void m5_dump_stats(void)
{
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0xFF000110 | (0x41 << 16);");
};
static void m5_exit(void)
{
__asm__ __volatile__ ("mov x0, #0; .inst 0XFF000110 | (0x21 << 16);");
};
static void m5_fail_1(void)
{
__asm__ __volatile__ ("mov x0, #0; mov x1, #1; .inst 0xFF000110 | (0x22 << 16);");
};
static void m5_reset_stats(void)
{
__asm__ __volatile__ ("mov x0, #0; mov x1, #0; .inst 0XFF000110 | (0x40 << 16);");
};
#else
#undef ENABLED
#define ENABLED 0
#endif
int main(
#if ENABLED
int argc, char **argv
#else
void
#endif
)
{
#if ENABLED
char action;
if (argc > 1) {
action = argv[1][0];
} else {
action = 'e';
}
switch (action)
{
case 'c':
m5_checkpoint();
break;
case 'd':
m5_dump_stats();
break;
case 'e':
m5_exit();
break;
case 'f':
m5_fail_1();
break;
case 'r':
m5_reset_stats();
break;
}
#endif
return EXIT_SUCCESS;
}