Skip to content

Commit 5aab9e6

Browse files
8785benjaminLapshin
authored andcommitted
esp32ulp: fix generation of relocation information
Merges espressif/binutils-esp32ulp#11 Closes espressif/binutils-esp32ulp#9 Closes espressif/binutils-esp32ulp#8
1 parent 4eedf57 commit 5aab9e6

File tree

1 file changed

+16
-29
lines changed

1 file changed

+16
-29
lines changed

gas/config/tc-esp32ulp.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,8 @@ This is called for every line that contains real assembly code. */
166166
void
167167
md_assemble(char *line)
168168
{
169-
char *toP = 0;
170-
int size, insn_size;
171-
struct esp32ulp_insn *tmp_insn;
169+
char *toP ;
170+
int insn_size;
172171
size_t len;
173172
static size_t buffer_len = 0;
174173
static char *current_inputline;
@@ -184,47 +183,35 @@ md_assemble(char *line)
184183
current_inputline[len] = ';';
185184
current_inputline[len + 1] = '\0';
186185

187-
//if (insn) //DEBUG_TRACE("dya_pass 222 insn old =%08x\n", (unsigned int)insn->value);
186+
// run the parser on the instruction
187+
// it will return a list of chained "insn",
188+
// the first contains the opcode of the instruction
189+
// and may be followed by other "insn" like an address
188190
state = parse(current_inputline);
189-
//if (insn) //DEBUG_TRACE("dya_pass 222 insn new =%08x\n", (unsigned int)insn->value);
190-
if (state == NO_INSN_GENERATED)
191+
if (state == NO_INSN_GENERATED || !insn)
191192
return;
192193

193-
for (insn_size = 0, tmp_insn = insn; tmp_insn; tmp_insn = tmp_insn->next)
194-
if (!tmp_insn->reloc || !tmp_insn->exp->symbol)
195-
insn_size += 2;
196-
// TODO:DYA insn_size - must be 4 in any case
194+
// add 4 bytes to the fragment code buffer to put the new instruction
195+
// and get buffer pointer (toP) on where to write the instruction
197196
insn_size = 4;
198-
if (insn_size)
199-
toP = frag_more(insn_size);
200-
201-
last_insn_size = insn_size;
197+
toP = frag_more(insn_size);
202198

203199
#ifdef DEBUG
204200
printf("INS: %s\n", line);
205201
#endif
202+
md_number_to_chars(toP, insn->value, insn_size); // put the 4-byte instruction into the current fragment code buffer
203+
206204
while (insn)
207205
{
208206
if (insn->reloc && insn->exp->symbol)
209207
{
210-
size = 4;
211208
//DEBUG_TRACE("insn->reloc && insn->exp->symbol BFD_ARELOC_ESP32ULP_PUSH size =%i, insn->exp->value=%i, insn->pcrel=%i, insn->reloc=%i\n", size, (unsigned int)insn->exp->value, insn->pcrel, insn->reloc);
212209

213-
//char *prev_toP = toP - 2;
214-
//fix_new(frag_now, (prev_toP - frag_now->fr_literal), size, insn->exp->symbol, insn->exp->value, insn->pcrel, insn->reloc);
215-
// were - shift from current word...
216-
fix_new(frag_now, 0, size, insn->exp->symbol, insn->exp->value, insn->pcrel, insn->reloc);
217-
}
218-
else
219-
{
220-
//DEBUG_TRACE("md_number_to_chars insn->value =%08x\n", (unsigned int)insn->value);
221-
//md_number_to_chars(toP, insn->value, 2);
222-
//toP += 2;
223-
// TODO:DYA - this is main changes for 32 bit words!!!!! changes stop work
224-
md_number_to_chars(toP, insn->value, 4);
225-
toP += 4;
210+
// generate a relocation request for this instruction so that linker will put the right address
211+
// toP is the pointer on this instruction in the buffer of the current code fragment
212+
// frag_now->fr_literal is the pointer on the begining of the buffer of the current code fragment
213+
fix_new(frag_now, toP - frag_now->fr_literal, insn_size, insn->exp->symbol, insn->exp->value, insn->pcrel, insn->reloc);
226214
}
227-
size = 4;
228215
#ifdef DEBUG
229216
//DEBUG_TRACE(" reloc : value = %08x, pc=%08x, reloc=%08x BFD_RELOC_ESP32ULP_PLTPC = %08x\n", (unsigned int)insn->value, (unsigned int)insn->pcrel, (unsigned int)insn->reloc, BFD_RELOC_ESP32ULP_PLTPC);
230217
if (insn->exp != ((void*)(0)))

0 commit comments

Comments
 (0)