-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathjptable.c
78 lines (71 loc) · 1.84 KB
/
jptable.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
#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include "jptable.h"
jptb * pjptb;
int bjptb = 0;
int njp;
int lookup_jptable(addr_t adr){
int i;
int num = 0;
for(i = 0; i < njp; i++){
if(pjptb[i].adr == adr ){
num = pjptb[i].ntarget;
}
}
return num;
}
void get_jptable(addr_t src,int index, addr_t * target){
int i;
for(i = 0; i < njp; i++){
if(pjptb[i].adr == src){
*target = pjptb[i].ptarget[index];
break;
}
}
assert(i < njp);
}
int get_jptable_static(addr_t src, addr_t * target){
int i,j;
int tail = -1;
for(i = 0; i < njp; i++){
if(pjptb[i].adr == src){
j = pjptb[i].index;
*target = pjptb[i].ptarget[j];
pjptb[i].index++;
if(pjptb[i].index == pjptb[i].ntarget)
tail = 0;
else
tail = 1;
break;
}
}
//assert(i < njp);
return tail;
}
void read_injp(char * objfile){
int tablesize,i,j;
char file[100];
FILE *ftable;
sprintf(file,"%s.jtable",objfile);
ftable = fopen(file,"r");
if(!ftable){
// no indirect jump
bjptb = 0;
}else{
bjptb = 1;
fscanf(ftable,"%d",&tablesize);
njp = tablesize;
pjptb = (jptb *)calloc(tablesize, sizeof(jptb));
for(i = 0; i < tablesize; i++){
fscanf(ftable,"%08x",&pjptb[i].adr);
fscanf(ftable,"%d",&pjptb[i].ntarget);
pjptb[i].index = 0;
pjptb[i].ptarget = (addr_t *)calloc(pjptb[i].ntarget, sizeof(addr_t));
for(j = 0; j < pjptb[i].ntarget; j++)
fscanf(ftable,"%08x",&pjptb[i].ptarget[j]);
}
fclose(ftable);
}
//printf("bool: %d\n",bjptb);
}