@@ -166,9 +166,8 @@ This is called for every line that contains real assembly code. */
166
166
void
167
167
md_assemble (char * line )
168
168
{
169
- char * toP = 0 ;
170
- int size , insn_size ;
171
- struct esp32ulp_insn * tmp_insn ;
169
+ char * toP ;
170
+ int insn_size ;
172
171
size_t len ;
173
172
static size_t buffer_len = 0 ;
174
173
static char * current_inputline ;
@@ -184,47 +183,35 @@ md_assemble(char *line)
184
183
current_inputline [len ] = ';' ;
185
184
current_inputline [len + 1 ] = '\0' ;
186
185
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
188
190
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 )
191
192
return ;
192
193
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
197
196
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 );
202
198
203
199
#ifdef DEBUG
204
200
printf ("INS: %s\n" , line );
205
201
#endif
202
+ md_number_to_chars (toP , insn -> value , insn_size ); // put the 4-byte instruction into the current fragment code buffer
203
+
206
204
while (insn )
207
205
{
208
206
if (insn -> reloc && insn -> exp -> symbol )
209
207
{
210
- size = 4 ;
211
208
//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);
212
209
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 );
226
214
}
227
- size = 4 ;
228
215
#ifdef DEBUG
229
216
//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);
230
217
if (insn -> exp != ((void * )(0 )))
0 commit comments