-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdriver.c
More file actions
67 lines (53 loc) · 1.68 KB
/
driver.c
File metadata and controls
67 lines (53 loc) · 1.68 KB
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
#include <linux/module.h>
#include <linux/moduleparam.h>
#include "lib/include/core.h"
MODULE_AUTHOR("MicroOperations");
MODULE_DESCRIPTION("Driver for our predecode cache reversing");
MODULE_VERSION("1.0.0");
MODULE_LICENSE("GPL");
static u32 pmc_no = 0;
module_param(pmc_no, uint, 0);
MODULE_PARM_DESC(pmc_no, "pmc no (default: 0)");
static u32 pmc_event_no = 0;
module_param(pmc_event_no, uint, 0);
MODULE_PARM_DESC(pmc_event_no,
"pmc event no (default: 0):\n"
" 0: predecode cache mispred\n"
" 1: icache miss\n"
" 2: machine clears\n"
" 3. unhalted core cycles");
struct predecode_re rawr = {};
struct pmc_event pmc_events[] = {
{PRED_WRONG_EVTSEL, PRED_WRONG_UMASK, "predecode cache mispredictions"},
{ICACHE_MISSES_EVTSEL, ICACHE_MISSES_UMASK, "icache misses"},
{MACHINE_CLEARS_EVTSEL, MACHINE_CLEARS_UMASK, "machine clears"},
{UNHALTED_CYCLES_EVTSEL, UNHALTED_CYCLES_UMASK, "unhalted core cycles"}
};
static int __init driver_entry(void)
{
meow(KERN_DEBUG, "driver loaded");
/* validate params */
if (!is_arch_pmc_no_supported(pmc_no)) {
meow(KERN_ERR, "invalid pmc no");
return -EINVAL;
}
if (pmc_event_no >= ARRAY_SIZE(pmc_events)) {
meow(KERN_ERR, "invalid event option");
return -EINVAL;
}
rawr.params.pmc_no = pmc_no;
rawr.params.event = pmc_events[pmc_event_no];
/* do the frickin analysis stuff */
int ret = __analysis(&rawr);
if (ret < 0)
meow(KERN_ERR, "analysis failed");
else
meow(KERN_DEBUG, "analysis successful");
return ret;
}
static void __exit driver_exit(void)
{
meow(KERN_DEBUG, "driver unloaded");
}
module_init(driver_entry);
module_exit(driver_exit);