-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinstr.h
More file actions
368 lines (322 loc) · 7.76 KB
/
Copy pathinstr.h
File metadata and controls
368 lines (322 loc) · 7.76 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
#ifndef INSTR_H
#define INSTR_H
#define ARM 1
#define THUMB 2
#define ARMBRANCHIMM_NUM 1
#define ARMBRANCHREG_NUM 2
#define ARMLOADSINGAL_NUM 3
#define ARMLOADMUL_NUM 4
#define TBRANCHREG_NUM 5
#define ARMPOPMUL_NUM 6
#define ARMPOPSINGAL_NUM 7
#define ARMDATAPOCREG_NUM 8
#define ARMDATAPRCIMM_NUM 9
#define TBRANCHIMM_NUM 10
#define TCMPBRANCH_NUM 11
#define TMOVREG_NUM 12
#define TADDREG_NUM 13
#define TBRANCHMISCELL_NUM 14
#define TLOADMUL_NUM 15
#define TPOPSINAL_NUM 16
#define TTABLEBRANCH_NUM 17
#define TLOADWORD_NUM 18
#define HEX__(n) 0x##n##LU
/* 8-bit conversion function */
#define B8__(x) ((x&0x0000000FLU)?1:0) \
+((x&0x000000F0LU)?2:0) \
+((x&0x00000F00LU)?4:0) \
+((x&0x0000F000LU)?8:0) \
+((x&0x000F0000LU)?16:0) \
+((x&0x00F00000LU)?32:0) \
+((x&0x0F000000LU)?64:0) \
+((x&0xF0000000LU)?128:0)
/* *** user macros ***/
/* for upto 8-bit binary constants */
#define B8(d) ((unsigned char)B8__(HEX__(d)))
/* for upto 16-bit binary constants, MSB first */
#define B16(dmsb,dlsb) (((unsigned short)B8(dmsb)<<8) \
+ B8(dlsb))
/* for upto 32-bit binary constants, MSB first */
#define B32(dmsb,db2,db3,dlsb) (((unsigned long)B8(dmsb)<<24) \
+ ((unsigned long)B8(db2)<<16) \
+ ((unsigned long)B8(db3)<<8) \
+ B8(dlsb))
typedef unsigned int BITS32;
int state;
//int IsGotoInstr(INSTR instr);
//arm
/**arm instruction:(b bl blx)immediate
*b:cond!=1111,link=0,imm32=imm24:0
*bl:cond!=1111,link=1,imm32=imm24:0
*blx:cond=1111,imm32=imm24:link:0
*/
typedef struct BRANCHIMMEDIATE_st
{
BITS32 imm24 : 24;
BITS32 link : 1;
BITS32 be101 : 3;
BITS32 cond : 4;
}BRANCHIMMEDIATE;
/*
arm inastruction:(blx bx bxj)register
blx:cond!=1111,notbe00=11,register=rm
bx:cond!=1111,notbe=01,register=rm
bxj:cond!=1111,notbe=10,register=rm
*/
typedef struct BRANCHRES_st
{
BITS32 rm : 4;
BITS32 notBe00 : 2;
BITS32 be00 : 2;
BITS32 notUsed : 12;
BITS32 be00010010 : 8;
BITS32 cond : 4;
}BRANCHRES;
/*
load instruction
*/
typedef struct LOADSINGLE_st
{
BITS32 bits1 : 4;
BITS32 b : 1;
BITS32 bits2 : 11;
BITS32 rn : 4;
BITS32 be1 : 1;
BITS32 w : 1;
BITS32 be0 : 1;
BITS32 u : 1;
BITS32 p : 1;
BITS32 a : 1;
BITS32 be01 : 2;
BITS32 cond : 4;
}LOADSINGLE;
/*
LDM/LDMIA/LDMFD,LDMDA/LDMFA,LDMDB/LDMEA,LDMIB/LDMED
registers(15)=1,then ldm(DA/DB/IB) is a branch instruction
*/
typedef struct LOADMULTIPLE_st
{
BITS32 registers : 15;
BITS32 rn : 4;
BITS32 be1 : 1;
BITS32 w : 1;
BITS32 is1 : 1;
BITS32 state : 2;
BITS32 be100 : 3;
BITS32 cond : 4;
}LOADMULTIPLE;
/*
pop more than one register
if bits1[15]=1,then it is a branch instruction
*/
typedef struct POPMUL_st
{
BITS32 bits : 16;
BITS32 be100010111101 : 12;
BITS32 cond : 4;
}POPMUL;
/*
pop one register
if rt=1,then it is a branch instruction
*/
typedef struct POPSINGAL_st
{
BITS32 be000000000100 : 12;
BITS32 rt : 4;
BITS32 be010010011101 : 12;
BITS32 cond : 4;
}POPSINGAL;
/*
date processing register
bits2[0..3]=15,then date processing register is a branch instruction */
/************************************************************************/
typedef struct DATEPROCESSINGRES_st
{
BITS32 bits1 : 4;
BITS32 be0 : 1;
BITS32 op3 : 2;
BITS32 op2 : 5;
BITS32 bits2 : 8;
BITS32 op1 : 5;
BITS32 be000 : 3;
BITS32 cond : 4;
}DATEPROCESSINGRES;
/*
date processing immediate
bits1[12..15]=15,then date processing immdiate is a branch instruction */
/************************************************************************/
typedef struct DATEPROCESSINGIMM_st
{
BITS32 bits1 : 16;
BITS32 rn : 4;
BITS32 op : 5;
BITS32 be001 : 3;
BITS32 cond : 4;
}DATEPROCESSINGIMM;
//thumb 16bits
/*
thumb 16bits b instruction
tb1(cond) not be 111x,not permitted in IT Block.
*/
typedef struct TB1_st
{
BITS32 imm8 : 8;
BITS32 cond : 4;
BITS32 be1101 : 4;
}TB1;
typedef struct TB2_st
{
BITS32 imm11 : 11;
BITS32 be11100 : 5;
}TB2;
typedef union TB_st
{
TB1 tB1;
TB2 tB2;
}TB;
/*
bx blx register
blx:l==1,bx l==0;
*/
typedef struct TBRANCHRES_st
{
BITS32 notUsed : 3;
BITS32 rm : 4;
BITS32 l : 1;
BITS32 be01000111 : 8;
}TBRANCHRES;
/*
CBNZ ,CBZ
*/
typedef struct COMPAREBRANCH_st
{
BITS32 rn : 4;
BITS32 imm5 : 5;
BITS32 be1 : 1;
BITS32 i : 1;
BITS32 be0 : 1;
BITS32 op : 1;
BITS32 be1011 : 4;
}COMPAREBRANCH;
/*
*mov register instruction
*rd=[rd2:rd1],rd=15,then it is a branch instruction
**/
typedef struct TMOVERES1_st
{
BITS32 rd1 : 3;
BITS32 rm : 4;
BITS32 rd2 : 1;
BITS32 be01000110 : 8;
}TMOVERES1;
typedef struct TMOVERES2_st
{
BITS32 rd : 4;
BITS32 rm : 4;
BITS32 be0000000000 : 10;
}TMOVERES2;
typedef union TMOVERES_st
{
TMOVERES1 tMoveRes1;
TMOVERES2 tMoveRes2;
}TMOVERES;
/*
* ADD register instruction
* rd=[rd2:rd1],rd=15,then it is a branch instruction
* */
typedef struct TADDRES_st
{
BITS32 rd1 : 3;
BITS32 rm : 4;
BITS32 rd2 : 1;
BITS32 be01000100 : 8;
}TADDRES;
//thumb 32 bits
/*
* branch and miscellaneous control instrucition
* b:op1=0x0,op[4:5]!=111 or op1=0x1
* blx:op1=1x0
* bl:op1=1x1
* bxj :op1=0x0,op=0111100
* subs pc,lr:op1=0x0,op=0111101
*/
typedef struct T2BRANCHANDMISCONTROL_st
{
BITS32 bits1 : 8;
BITS32 op2 : 4;
BITS32 op1 : 3;
BITS32 be1 : 1;
BITS32 bits2 : 4;
BITS32 op : 7;
BITS32 be11110 : 5;
}TBRANCHANDMISCONTROL;
/* load multiple and pop instruction
* if bits[15]=15 ,it is a branch instruction
* */
typedef struct T2LOADMULTIPLE_st
{
BITS32 bits1 : 16;
BITS32 rn : 4;
BITS32 be1 : 1;
BITS32 bits2 : 1;
BITS32 be1110100010 : 10;
}TLOADMULTIPLE;
/* load word
*if bits2=15,then it is a branch instruction
*/
typedef struct T2LOADWORD_st
{
BITS32 bits1 : 6;
BITS32 op2 : 6;
BITS32 bits2 : 4;
BITS32 rn : 4;
BITS32 be101 : 3;
BITS32 op1 : 2;
BITS32 be1111100 : 7;
}TLOADWORD;
typedef struct T2TABLEBRANCH_st
{
BITS32 rm : 4;
BITS32 h : 1;
BITS32 be000 : 3;
BITS32 notUsed : 8;
BITS32 rn : 4;
BITS32 be111010001101 : 12;
}TTABLEBRANCH;
/*
pop contains one register
rt=15,it is a branch instruction
*/
typedef struct T2POPSINGAL_st
{
BITS32 be101100000100 : 12;
BITS32 rt : 4;
BITS32 be1111100001011101 : 16;
}TPOPSINGAL;
//instruction
typedef union INSTR_st
{
//arm
BRANCHIMMEDIATE branchImmediate;
BRANCHRES branchGes;
LOADSINGLE loadSingle;
LOADMULTIPLE loadMultiple;
POPMUL popMul;
POPSINGAL popSingal;
DATEPROCESSINGRES dataProcssingRes;
DATEPROCESSINGIMM dataProcssingImm;
//thumb 16
TB tb;
TBRANCHRES tbranchRes;
COMPAREBRANCH compareBranch;
TMOVERES tmoveRes;
TADDRES taddRes;
//thumb 32
TBRANCHANDMISCONTROL tbranchAndMis;
TLOADWORD tloadWord;
TLOADMULTIPLE tloadMultiple;
TTABLEBRANCH ttableBranch;
TPOPSINGAL tpopSingal;
BITS32 instr;
}INSTR;
#endif