-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdisas_driver_impl.c
59 lines (49 loc) · 1.33 KB
/
disas_driver_impl.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
#include "disas_driver_impl.h"
#include "disas.h"
typedef struct disas_driver {
disas_ref disas;
FILE *out_fp;
char *out_path;
} disas_driver_t;
void disas_driver_destroy(disas_driver_ref self)
{
if (self) {
if (self->out_fp) {
fclose(self->out_fp);
}
FREE(self->out_path);
FREE(self);
}
}
disas_driver_ref disas_driver_create(core_ref core, const char *out_path)
{
disas_driver_ref self = NULL;
TALLOC(self);
GUARD(out_path);
GUARD(self->out_path = strdup(out_path));
GUARD(self->out_fp = fopen(self->out_path, "wx"));
GUARD(self->disas = disas_create(core->mapper));
return self;
error:
disas_driver_destroy(self);
return NULL;
}
void disas_driver_on_cpu_decode(disas_driver_ref self, cpu_ref cpu, uint16_t pc)
{
disas_mark_op_runtime(self->disas, cpu->reg.pc, cpu->last_op == OP_20_JSR);
}
void disas_driver_on_core_start(disas_driver_ref self, core_ref core)
{
disas_mark_from_vectors(self->disas);
}
void disas_driver_on_core_quit(disas_driver_ref self, core_ref core)
{
disas_dump(self->disas, self->out_fp);
}
void disas_driver_on_cpu_read(disas_driver_ref self, cpu_ref cpu, uint16_t addr,
size_t length)
{
if (addr >= 0x8000) {
disas_mark_data_runtime(self->disas, addr, length);
}
}