annotate objgrep/mkpattern.c @ 302:844ebeb9a5c6

dsample-fw-disasm: rf_program() and l1dmacro_agc() analysed
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 05 Oct 2019 23:47:32 +0000
parents 77cd647375e5
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
1 /*
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
2 * objgrep: preparation of matching pattern
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
3 */
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
4
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
5 #include <sys/types.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
6 #include <stdio.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
7 #include <stdint.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
8 #include <stdlib.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
9 #include <string.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
10 #include <strings.h>
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
11 #include "filestruct.h"
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
12 #include "intstruct.h"
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
13 #include "coffconst.h"
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
14 #include "globals.h"
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
15
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
16 extern unsigned get_u16(), get_u32();
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
17
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
18 static unsigned
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
19 arm_branch_reloc(origbits, location)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
20 u_char *origbits;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
21 unsigned location;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
22 {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
23 unsigned word, dest;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
24
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
25 word = get_u32(origbits + location);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
26 if ((word & 0x0E000000) != 0x0A000000) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
27 fprintf(stderr,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
28 "error: invalid ARM_B reloc: opcode not B or BL\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
29 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
30 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
31 dest = (word & 0x00FFFFFF) << 2;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
32 if (dest & 0x02000000)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
33 dest |= 0xFC000000;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
34 dest += location + 8;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
35 return(dest);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
36 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
37
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
38 static unsigned
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
39 thumb_bl_reloc(origbits, location)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
40 u_char *origbits;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
41 unsigned location;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
42 {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
43 unsigned ins1, ins2;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
44 unsigned dest;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
45
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
46 ins1 = get_u16(origbits + location);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
47 ins2 = get_u16(origbits + location + 2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
48 if ((ins1 & 0xF800) != 0xF000 || (ins2 & 0xF800) != 0xF800) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
49 fprintf(stderr,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
50 "error: invalid Thumb_BL reloc: opcode not BL\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
51 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
52 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
53 dest = ((ins1 & 0x7FF) << 12) | ((ins2 & 0x7FF) << 1);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
54 if (dest & 0x00400000)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
55 dest |= 0xFF800000;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
56 dest += location + 4;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
57 return(dest);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
58 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
59
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
60 prepare_pattern()
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
61 {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
62 u_char *origbits;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
63 unsigned pad, n;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
64 struct internal_reloc *irel;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
65 struct external_reloc *xrel;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
66 unsigned lastloc, symidx;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
67 struct internal_syment *sym;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
68
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
69 origbits = objfilemap + grep_section->data_offset;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
70 pattern_len = (grep_section->size + 3) & ~3;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
71 pattern_match = malloc(pattern_len);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
72 if (!pattern_match) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
73 perror("malloc");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
74 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
75 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
76 bcopy(origbits, pattern_match, grep_section->size);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
77 pattern_mask = malloc(pattern_len);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
78 if (!pattern_mask) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
79 perror("malloc");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
80 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
81 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
82 memset(pattern_mask, 0xFF, grep_section->size);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
83 pad = pattern_len - grep_section->size;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
84 if (pad) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
85 bzero(pattern_match + grep_section->size, pad);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
86 bzero(pattern_mask + grep_section->size, pad);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
87 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
88 if (!grep_section->nreloc)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
89 return(0);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
90 xrel = (struct external_reloc *)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
91 (objfilemap + grep_section->reloc_offset);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
92 irel = malloc(sizeof(struct internal_reloc) * grep_section->nreloc);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
93 if (!irel) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
94 perror("malloc");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
95 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
96 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
97 relocs = irel;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
98 for (n = 0; n < grep_section->nreloc; n++, xrel++, irel++) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
99 irel->location = get_u32(xrel->r_vaddr);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
100 if (n && irel->location < lastloc) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
101 fprintf(stderr, "error: non-increasing reloc order\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
102 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
103 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
104 lastloc = irel->location + 4;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
105 if (lastloc > grep_section->size) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
106 fprintf(stderr,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
107 "error: reloc spills past the end of the section\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
108 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
109 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
110 symidx = get_u32(xrel->r_symndx);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
111 if (symidx == 0xFFFFFFFF)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
112 sym = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
113 else if (symidx >= nsymtab || !symtab[symidx]) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
114 fprintf(stderr,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
115 "error: reloc references invalid symbol #%u\n",
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
116 symidx);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
117 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
118 } else
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
119 sym = symtab[symidx];
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
120 if (sym && sym->value) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
121 fprintf(stderr,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
122 "error: symbol #%u referenced by reloc has nonzero value\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
123 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
124 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
125 if (!sym) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
126 irel->secbase = grep_section;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
127 irel->extsym = 0;
173
77cd647375e5 objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 168
diff changeset
128 nreloc_int++;
168
ed1a06bf525d objgrep: works after fixing a buglet
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 167
diff changeset
129 } else if (sym->class == C_EXT && sym->scnum == 0) {
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
130 irel->extsym = sym;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
131 irel->secbase = 0;
173
77cd647375e5 objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 168
diff changeset
132 nreloc_ext++;
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
133 } else if (sym->class == C_STAT && sym->section &&
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
134 !strcmp(sym->name, sym->section->name)) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
135 irel->secbase = sym->section;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
136 irel->extsym = 0;
173
77cd647375e5 objgrep -r: dump symbols in other sections recovered through relocs
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents: 168
diff changeset
137 nreloc_int++;
167
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
138 } else {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
139 fprintf(stderr, "error: unable to grok reloc\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
140 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
141 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
142 irel->type = get_u16(xrel->r_type);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
143 switch (irel->type) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
144 case RTYPE_LONG:
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
145 if (irel->location & 3) {
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
146 align_error: fprintf(stderr, "error: misaligned reloc\n");
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
147 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
148 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
149 irel->addend = get_u32(origbits + irel->location);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
150 *(uint32_t *)(pattern_match + irel->location) = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
151 *(uint32_t *)(pattern_mask + irel->location) = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
152 break;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
153 case RTYPE_ARM_B:
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
154 if (irel->location & 3)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
155 goto align_error;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
156 irel->addend = arm_branch_reloc(origbits,
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
157 irel->location);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
158 bzero(pattern_match + irel->location, 3);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
159 bzero(pattern_mask + irel->location, 3);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
160 break;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
161 case RTYPE_THUMB_BL:
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
162 if (irel->location & 1)
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
163 goto align_error;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
164 irel->addend = thumb_bl_reloc(origbits, irel->location);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
165 pattern_match[irel->location+0] = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
166 pattern_match[irel->location+1] &= 0xF8;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
167 pattern_match[irel->location+2] = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
168 pattern_match[irel->location+3] &= 0xF8;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
169 pattern_mask[irel->location+0] = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
170 pattern_mask[irel->location+1] = 0xF8;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
171 pattern_mask[irel->location+2] = 0;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
172 pattern_mask[irel->location+3] = 0xF8;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
173 break;
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
174 default:
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
175 fprintf(stderr, "error: reloc type 0x%x unsupported\n",
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
176 irel->type);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
177 exit(2);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
178 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
179 }
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
180 return(1);
c25367bb7656 objgrep: written, compiles
Michael Spacefalcon <msokolov@ivan.Harhan.ORG>
parents:
diff changeset
181 }