-
Notifications
You must be signed in to change notification settings - Fork 17
/
qsim_magic.h
44 lines (33 loc) · 962 Bytes
/
qsim_magic.h
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
#ifndef _QSIM_MAGIC_H
#define _QSIM_MAGIC_H
#include <signal.h>
#include <stdlib.h>
#include <stdio.h>
#if defined(__arm__) || defined(__aarch64__)
#define qsim_magic_enable() \
asm volatile("msr pmcr_el0, %0" :: "r" (0xaaaaaaaa));
#define qsim_magic_disable() \
asm volatile("msr pmcr_el0, %0" :: "r" (0xfa11dead));
#elif defined(__i386__) || defined(__x86_64__)
#define qsim_magic_enable() \
asm volatile("cpuid;"::"a"(0xaaaaaaaa):"ebx","ecx","edx");
#define qsim_magic_disable() \
asm volatile("cpuid;"::"a"(0xfa11dead):"ebx","ecx","edx");
#endif
#define APP_START() qsim_magic_enable()
#define APP_END() qsim_magic_disable()
__attribute__((unused))
static void qsim_sig_handler(int signo)
{
char c;
qsim_magic_disable();
printf("Callbacks disabled. Quit(y/n)?");
scanf("%c", &c);
if (c == 'y')
exit(0);
}
#define qsim_init() \
do { \
signal(SIGINT, qsim_sig_handler); \
} while(0);
#endif /* _QSIM_MAGIC_H */