FreeCalypso > hg > freecalypso-reveng
annotate arm7dis/armdis.c @ 87:f7fba8518fa2
armdis: skeleton compiles
author | Michael Spacefalcon <msokolov@ivan.Harhan.ORG> |
---|---|
date | Sat, 29 Mar 2014 00:23:16 +0000 |
parents | 537cf2245d98 |
children | 691551f0635b |
rev | line source |
---|---|
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
1 #include <sys/types.h> |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
2 #include <stdio.h> |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
3 #include <stdlib.h> |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
4 |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
5 extern char *binfilename; |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
6 extern u_char *filemap; |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
7 extern unsigned disasm_len, base_vma; |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
8 |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
9 extern unsigned get_u16(), get_u32(); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
10 |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
11 extern char *regnames[16], *condition_decode[16]; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
12 |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
13 static void |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
14 arm_branch(off, word) |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
15 unsigned off, word; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
16 { |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
17 unsigned dest; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
18 |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
19 dest = (word & 0x00FFFFFF) << 2; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
20 if (dest & 0x02000000) |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
21 dest |= 0xFC000000; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
22 dest += base_vma + off + 8; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
23 printf("b%s%s\t0x%x\n", word&0x1000000 ? "l" : "", |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
24 condition_decode[word>>28], dest); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
25 } |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
26 |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
27 void |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
28 arm_disasm_line(off) |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
29 unsigned off; |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
30 { |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
31 unsigned word; |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
32 |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
33 word = get_u32(filemap + off); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
34 printf("%8x:\t%08x\t", base_vma + off, word); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
35 if ((word >> 28) == 0xF) { |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
36 printf("invalid-F\n"); |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
37 return; |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
38 } |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
39 switch ((word >> 24) & 0xF) { |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
40 case 0: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
41 case 1: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
42 printf("<data processing, register operand>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
43 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
44 case 2: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
45 case 3: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
46 printf("<data processing, immediate operand>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
47 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
48 case 4: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
49 case 5: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
50 printf("<ldr/str, immediate offset>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
51 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
52 case 6: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
53 case 7: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
54 printf("<ldr/str, register offset>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
55 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
56 case 8: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
57 case 9: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
58 printf("<ldm/stm>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
59 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
60 case 0xA: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
61 case 0xB: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
62 arm_branch(off, word); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
63 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
64 case 0xC: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
65 case 0xD: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
66 case 0xE: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
67 printf("<COPROCESSOR>\n"); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
68 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
69 case 0xF: |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
70 printf("swi%s\t0x%x\n", condition_decode[word>>28], |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
71 word & 0xFFFFFF); |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
72 return; |
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
73 } |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
74 } |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
75 |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
76 main(argc, argv) |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
77 char **argv; |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
78 { |
87
f7fba8518fa2
armdis: skeleton compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
86
diff
changeset
|
79 unsigned off; |
86
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
80 |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
81 common_init(argc, argv, 4); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
82 for (off = 0; off < disasm_len; off += 4) |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
83 arm_disasm_line(off); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
84 exit(0); |
537cf2245d98
beginning of ARM7 disassembler
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff
changeset
|
85 } |