-
Notifications
You must be signed in to change notification settings - Fork 0
/
generator.c
48 lines (40 loc) · 1.18 KB
/
generator.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
#include <common.h>
#include <stdio.h>
#include <isa.h>
#include <string.h>
#define GPR_LEN 16
static word_t gpr_pre[GPR_LEN];
static word_t pc_pre=0x80000000;
FILE* gsnapshot_fp;
#define gsnapshot_write(...) do { \
if(gsnapshot_fp){ \
fprintf(gsnapshot_fp, __VA_ARGS__); \
fflush(gsnapshot_fp); \
} \
} while (0) \
void init_gpr_snapshot(const char *snapshot_file){
gsnapshot_fp = fopen(snapshot_file, "w");
if(gsnapshot_fp==NULL){
Log("gsnapshot disabled");
return;
}
Assert(gsnapshot_fp, "Can not open '%s'", snapshot_file);
Log("gsnapshot is written to %s", snapshot_file);
}
void update_gpr_snapshot(){
if(gsnapshot_fp==NULL) return;
if(cpu.pc!=pc_pre+4){
gsnapshot_write("%x %x\n", GPR_LEN, cpu.pc);
}
pc_pre = cpu.pc;
if(memcmp(cpu.gpr, gpr_pre, sizeof(gpr_pre))==0) return;
for(int i=0;i<GPR_LEN;++i)
if(cpu.gpr[i]!=gpr_pre[i]){
gsnapshot_write("%x %x\n", i, cpu.gpr[i]);
}
memcpy(gpr_pre, cpu.gpr, sizeof(gpr_pre));
}
void update_gpr_snapshot_record_store(uint32_t addr, word_t val){
if(gsnapshot_fp==NULL) return;
gsnapshot_write("%x %x\n", addr, val);
}