Rev 3011 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
4039 | heavyiron | 1 | |
2 | ; Copyright (c) 1999-2013, Tomasz Grysztar. |
||
3 | ; All rights reserved. |
||
4 | |||
5 | |||
6 | mov edi,[code_start] |
||
7 | call setup_dump_header |
||
8 | mov esi,[input_file] |
||
9 | call copy_asciiz |
||
10 | cmp edi,[tagged_blocks] |
||
11 | jae out_of_memory |
||
12 | mov eax,edi |
||
13 | sub eax,ebx |
||
14 | mov [ebx-40h+0Ch],eax |
||
15 | mov esi,[output_file] |
||
16 | call copy_asciiz |
||
17 | cmp edi,[tagged_blocks] |
||
18 | jae out_of_memory |
||
19 | mov edx,[symbols_stream] |
||
20 | mov ebp,[free_additional_memory] |
||
21 | and [number_of_sections],0 |
||
22 | cmp [output_format],4 |
||
23 | je prepare_strings_table |
||
24 | cmp [output_format],5 |
||
25 | jne strings_table_ready |
||
26 | bt [format_flags],0 |
||
27 | jc strings_table_ready |
||
28 | prepare_strings_table: |
||
29 | cmp edx,ebp |
||
30 | je strings_table_ready |
||
31 | mov al,[edx] |
||
32 | test al,al |
||
33 | jz prepare_string |
||
34 | cmp al,80h |
||
35 | je prepare_string |
||
36 | add edx,0Ch |
||
37 | cmp al,0C0h |
||
38 | jb prepare_strings_table |
||
39 | add edx,4 |
||
40 | jmp prepare_strings_table |
||
41 | prepare_string: |
||
42 | mov esi,edi |
||
43 | sub esi,ebx |
||
44 | xchg esi,[edx+4] |
||
45 | test al,al |
||
46 | jz prepare_section_string |
||
47 | or dword [edx+4],1 shl 31 |
||
48 | add edx,0Ch |
||
49 | prepare_external_string: |
||
50 | mov ecx,[esi] |
||
51 | add esi,4 |
||
52 | rep movs byte [edi],[esi] |
||
53 | mov byte [edi],0 |
||
54 | inc edi |
||
55 | cmp edi,[tagged_blocks] |
||
56 | jae out_of_memory |
||
57 | jmp prepare_strings_table |
||
58 | prepare_section_string: |
||
59 | mov ecx,[number_of_sections] |
||
60 | mov eax,ecx |
||
61 | inc eax |
||
62 | mov [number_of_sections],eax |
||
63 | xchg eax,[edx+4] |
||
64 | shl ecx,2 |
||
65 | add ecx,[free_additional_memory] |
||
66 | mov [ecx],eax |
||
67 | add edx,20h |
||
68 | test esi,esi |
||
69 | jz prepare_default_section_string |
||
70 | cmp [output_format],5 |
||
71 | jne prepare_external_string |
||
72 | bt [format_flags],0 |
||
73 | jc prepare_external_string |
||
74 | mov esi,[esi] |
||
75 | add esi,[resource_data] |
||
76 | copy_elf_section_name: |
||
77 | lods byte [esi] |
||
78 | cmp edi,[tagged_blocks] |
||
79 | jae out_of_memory |
||
80 | stos byte [edi] |
||
81 | test al,al |
||
82 | jnz copy_elf_section_name |
||
83 | jmp prepare_strings_table |
||
84 | prepare_default_section_string: |
||
85 | mov eax,'.fla' |
||
86 | stos dword [edi] |
||
87 | mov ax,'t' |
||
88 | stos word [edi] |
||
89 | cmp edi,[tagged_blocks] |
||
90 | jae out_of_memory |
||
91 | jmp prepare_strings_table |
||
92 | strings_table_ready: |
||
93 | mov edx,[tagged_blocks] |
||
94 | mov ebp,[memory_end] |
||
95 | sub ebp,[labels_list] |
||
96 | add ebp,edx |
||
97 | prepare_labels_dump: |
||
98 | cmp edx,ebp |
||
99 | je labels_dump_ok |
||
100 | mov eax,[edx+24] |
||
101 | test eax,eax |
||
102 | jz label_dump_name_ok |
||
103 | cmp eax,[memory_start] |
||
104 | jb label_name_outside_source |
||
105 | cmp eax,[source_start] |
||
106 | ja label_name_outside_source |
||
107 | sub eax,[memory_start] |
||
108 | dec eax |
||
109 | mov [edx+24],eax |
||
110 | jmp label_dump_name_ok |
||
111 | label_name_outside_source: |
||
112 | mov esi,eax |
||
113 | mov eax,edi |
||
114 | sub eax,ebx |
||
115 | or eax,1 shl 31 |
||
116 | mov [edx+24],eax |
||
117 | movzx ecx,byte [esi-1] |
||
118 | lea eax,[edi+ecx+1] |
||
119 | cmp edi,[tagged_blocks] |
||
120 | jae out_of_memory |
||
121 | rep movsb |
||
122 | xor al,al |
||
123 | stosb |
||
124 | label_dump_name_ok: |
||
125 | mov eax,[edx+28] |
||
126 | test eax,eax |
||
127 | jz label_dump_line_ok |
||
128 | sub eax,[memory_start] |
||
129 | mov [edx+28],eax |
||
130 | label_dump_line_ok: |
||
131 | test byte [edx+9],4 |
||
132 | jz convert_base_symbol_for_label |
||
133 | xor eax,eax |
||
134 | mov [edx],eax |
||
135 | mov [edx+4],eax |
||
136 | jmp base_symbol_for_label_ok |
||
137 | convert_base_symbol_for_label: |
||
138 | mov eax,[edx+20] |
||
139 | test eax,eax |
||
140 | jz base_symbol_for_label_ok |
||
141 | cmp eax,[symbols_stream] |
||
142 | mov eax,[eax+4] |
||
143 | jae base_symbol_for_label_ok |
||
144 | xor eax,eax |
||
145 | base_symbol_for_label_ok: |
||
146 | mov [edx+20],eax |
||
147 | mov ax,[current_pass] |
||
148 | cmp ax,[edx+16] |
||
149 | je label_defined_flag_ok |
||
150 | and byte [edx+8],not 1 |
||
151 | label_defined_flag_ok: |
||
152 | cmp ax,[edx+18] |
||
153 | je label_used_flag_ok |
||
154 | and byte [edx+8],not 8 |
||
155 | label_used_flag_ok: |
||
156 | add edx,LABEL_STRUCTURE_SIZE |
||
157 | jmp prepare_labels_dump |
||
158 | labels_dump_ok: |
||
159 | mov eax,edi |
||
160 | sub eax,ebx |
||
161 | mov [ebx-40h+14h],eax |
||
162 | add eax,40h |
||
163 | mov [ebx-40h+18h],eax |
||
164 | mov ecx,[memory_end] |
||
165 | sub ecx,[labels_list] |
||
166 | mov [ebx-40h+1Ch],ecx |
||
167 | add eax,ecx |
||
168 | mov [ebx-40h+20h],eax |
||
169 | mov ecx,[source_start] |
||
170 | sub ecx,[memory_start] |
||
171 | mov [ebx-40h+24h],ecx |
||
172 | add eax,ecx |
||
173 | mov [ebx-40h+28h],eax |
||
174 | mov eax,[number_of_sections] |
||
175 | shl eax,2 |
||
176 | mov [ebx-40h+34h],eax |
||
177 | call prepare_preprocessed_source |
||
178 | mov esi,[labels_list] |
||
179 | mov ebp,edi |
||
180 | make_lines_dump: |
||
181 | cmp esi,[tagged_blocks] |
||
182 | je lines_dump_ok |
||
183 | mov eax,[esi-4] |
||
184 | mov ecx,[esi-8] |
||
185 | sub esi,8 |
||
186 | sub esi,ecx |
||
187 | cmp eax,1 |
||
188 | je process_line_dump |
||
189 | cmp eax,2 |
||
190 | jne make_lines_dump |
||
191 | add dword [ebx-40h+3Ch],8 |
||
192 | jmp make_lines_dump |
||
193 | process_line_dump: |
||
194 | push ebx |
||
195 | mov ebx,[esi+8] |
||
196 | mov eax,[esi+4] |
||
197 | sub eax,[code_start] |
||
198 | add eax,[headers_size] |
||
199 | test byte [ebx+0Ah],1 |
||
200 | jz store_offset |
||
201 | xor eax,eax |
||
202 | store_offset: |
||
203 | stos dword [edi] |
||
204 | mov eax,[esi] |
||
205 | sub eax,[memory_start] |
||
206 | stos dword [edi] |
||
207 | mov eax,[esi+4] |
||
208 | xor edx,edx |
||
209 | xor cl,cl |
||
210 | sub eax,[ebx] |
||
211 | sbb edx,[ebx+4] |
||
212 | sbb cl,[ebx+8] |
||
213 | stos dword [edi] |
||
214 | mov eax,edx |
||
215 | stos dword [edi] |
||
216 | mov eax,[ebx+10h] |
||
217 | stos dword [edi] |
||
218 | mov eax,[ebx+14h] |
||
219 | test eax,eax |
||
220 | jz base_symbol_for_line_ok |
||
221 | cmp eax,[symbols_stream] |
||
222 | mov eax,[eax+4] |
||
223 | jae base_symbol_for_line_ok |
||
224 | xor eax,eax |
||
225 | base_symbol_for_line_ok: |
||
226 | stos dword [edi] |
||
227 | mov al,[ebx+9] |
||
228 | stos byte [edi] |
||
229 | mov al,[esi+10h] |
||
230 | stos byte [edi] |
||
231 | mov al,[ebx+0Ah] |
||
232 | and al,1 |
||
233 | stos byte [edi] |
||
234 | mov al,cl |
||
235 | stos byte [edi] |
||
236 | pop ebx |
||
237 | cmp edi,[tagged_blocks] |
||
238 | jae out_of_memory |
||
239 | mov eax,edi |
||
240 | sub eax,1Ch |
||
241 | sub eax,ebp |
||
242 | mov [esi],eax |
||
243 | jmp make_lines_dump |
||
244 | lines_dump_ok: |
||
245 | mov edx,edi |
||
246 | mov eax,[current_offset] |
||
247 | sub eax,[code_start] |
||
248 | add eax,[headers_size] |
||
249 | stos dword [edi] |
||
250 | mov ecx,edi |
||
251 | sub ecx,ebx |
||
252 | sub ecx,[ebx-40h+14h] |
||
253 | mov [ebx-40h+2Ch],ecx |
||
254 | add ecx,[ebx-40h+28h] |
||
255 | mov [ebx-40h+30h],ecx |
||
256 | add ecx,[ebx-40h+34h] |
||
257 | mov [ebx-40h+38h],ecx |
||
258 | find_inexisting_offsets: |
||
259 | sub edx,1Ch |
||
260 | cmp edx,ebp |
||
261 | jb write_symbols |
||
262 | test byte [edx+1Ah],1 |
||
263 | jnz find_inexisting_offsets |
||
264 | cmp eax,[edx] |
||
265 | jb correct_inexisting_offset |
||
266 | mov eax,[edx] |
||
267 | jmp find_inexisting_offsets |
||
268 | correct_inexisting_offset: |
||
269 | and dword [edx],0 |
||
270 | or byte [edx+1Ah],2 |
||
271 | jmp find_inexisting_offsets |
||
272 | write_symbols: |
||
273 | mov edx,[symbols_file] |
||
274 | call create |
||
275 | jc write_failed |
||
276 | mov edx,[code_start] |
||
277 | mov ecx,[edx+14h] |
||
278 | add ecx,40h |
||
279 | call write |
||
280 | jc write_failed |
||
281 | mov edx,[tagged_blocks] |
||
282 | mov ecx,[memory_end] |
||
283 | sub ecx,[labels_list] |
||
284 | call write |
||
285 | jc write_failed |
||
286 | mov edx,[memory_start] |
||
287 | mov ecx,[source_start] |
||
288 | sub ecx,edx |
||
289 | call write |
||
290 | jc write_failed |
||
291 | mov edx,ebp |
||
292 | mov ecx,edi |
||
293 | sub ecx,edx |
||
294 | call write |
||
295 | jc write_failed |
||
296 | mov edx,[free_additional_memory] |
||
297 | mov ecx,[number_of_sections] |
||
298 | shl ecx,2 |
||
299 | call write |
||
300 | jc write_failed |
||
301 | mov esi,[labels_list] |
||
302 | mov edi,[memory_start] |
||
303 | make_references_dump: |
||
304 | cmp esi,[tagged_blocks] |
||
305 | je references_dump_ok |
||
306 | mov eax,[esi-4] |
||
307 | mov ecx,[esi-8] |
||
308 | sub esi,8 |
||
309 | sub esi,ecx |
||
310 | cmp eax,2 |
||
311 | je dump_reference |
||
312 | cmp eax,1 |
||
313 | jne make_references_dump |
||
314 | mov edx,[esi] |
||
315 | jmp make_references_dump |
||
316 | dump_reference: |
||
317 | mov eax,[memory_end] |
||
318 | sub eax,[esi] |
||
319 | sub eax,LABEL_STRUCTURE_SIZE |
||
320 | stosd |
||
321 | mov eax,edx |
||
322 | stosd |
||
323 | cmp edi,[tagged_blocks] |
||
324 | jb make_references_dump |
||
325 | jmp out_of_memory |
||
326 | references_dump_ok: |
||
327 | mov edx,[memory_start] |
||
328 | mov ecx,edi |
||
329 | sub ecx,edx |
||
330 | call write |
||
331 | jc write_failed |
||
332 | call close |
||
333 | ret |
||
334 | setup_dump_header: |
||
335 | xor eax,eax |
||
336 | mov ecx,40h shr 2 |
||
337 | rep stos dword [edi] |
||
338 | mov ebx,edi |
||
339 | mov dword [ebx-40h],'fas'+1Ah shl 24 |
||
340 | mov dword [ebx-40h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 40h shl 16 |
||
341 | mov dword [ebx-40h+10h],40h |
||
342 | ret |
||
343 | prepare_preprocessed_source: |
||
344 | mov esi,[memory_start] |
||
345 | mov ebp,[source_start] |
||
346 | test ebp,ebp |
||
347 | jnz prepare_preprocessed_line |
||
348 | mov ebp,[current_line] |
||
349 | inc ebp |
||
350 | prepare_preprocessed_line: |
||
351 | cmp esi,ebp |
||
352 | jae preprocessed_source_ok |
||
353 | mov eax,[memory_start] |
||
354 | mov edx,[input_file] |
||
355 | cmp [esi],edx |
||
356 | jne line_not_from_main_input |
||
357 | mov [esi],eax |
||
358 | line_not_from_main_input: |
||
359 | sub [esi],eax |
||
360 | test byte [esi+7],1 shl 7 |
||
361 | jz prepare_next_preprocessed_line |
||
362 | sub [esi+8],eax |
||
363 | sub [esi+12],eax |
||
364 | prepare_next_preprocessed_line: |
||
365 | call skip_preprocessed_line |
||
366 | jmp prepare_preprocessed_line |
||
367 | preprocessed_source_ok: |
||
368 | ret |
||
369 | skip_preprocessed_line: |
||
370 | add esi,16 |
||
371 | skip_preprocessed_line_content: |
||
372 | lods byte [esi] |
||
373 | cmp al,1Ah |
||
374 | je skip_preprocessed_symbol |
||
375 | cmp al,3Bh |
||
376 | je skip_preprocessed_symbol |
||
377 | cmp al,22h |
||
378 | je skip_preprocessed_string |
||
379 | or al,al |
||
380 | jnz skip_preprocessed_line_content |
||
381 | ret |
||
382 | skip_preprocessed_string: |
||
383 | lods dword [esi] |
||
384 | add esi,eax |
||
385 | jmp skip_preprocessed_line_content |
||
386 | skip_preprocessed_symbol: |
||
387 | lods byte [esi] |
||
388 | movzx eax,al |
||
389 | add esi,eax |
||
390 | jmp skip_preprocessed_line_content |
||
391 | restore_preprocessed_source: |
||
392 | mov esi,[memory_start] |
||
393 | mov ebp,[source_start] |
||
394 | test ebp,ebp |
||
395 | jnz restore_preprocessed_line |
||
396 | mov ebp,[current_line] |
||
397 | inc ebp |
||
398 | restore_preprocessed_line: |
||
399 | cmp esi,ebp |
||
400 | jae preprocessed_source_restored |
||
401 | mov eax,[memory_start] |
||
402 | add [esi],eax |
||
403 | cmp [esi],eax |
||
404 | jne preprocessed_line_source_restored |
||
405 | mov edx,[input_file] |
||
406 | mov [esi],edx |
||
407 | preprocessed_line_source_restored: |
||
408 | test byte [esi+7],1 shl 7 |
||
409 | jz restore_next_preprocessed_line |
||
410 | add [esi+8],eax |
||
411 | add [esi+12],eax |
||
412 | restore_next_preprocessed_line: |
||
413 | call skip_preprocessed_line |
||
414 | jmp restore_preprocessed_line |
||
415 | preprocessed_source_restored: |
||
416 | ret |
||
417 | dump_preprocessed_source: |
||
418 | mov edi,[free_additional_memory] |
||
419 | call setup_dump_header |
||
420 | mov esi,[input_file] |
||
421 | call copy_asciiz |
||
422 | cmp edi,[additional_memory_end] |
||
423 | jae out_of_memory |
||
424 | mov eax,edi |
||
425 | sub eax,ebx |
||
426 | dec eax |
||
427 | mov [ebx-40h+0Ch],eax |
||
428 | mov eax,edi |
||
429 | sub eax,ebx |
||
430 | mov [ebx-40h+14h],eax |
||
431 | add eax,40h |
||
432 | mov [ebx-40h+20h],eax |
||
433 | call prepare_preprocessed_source |
||
434 | sub esi,[memory_start] |
||
435 | mov [ebx-40h+24h],esi |
||
436 | mov edx,[symbols_file] |
||
437 | call create |
||
438 | jc write_failed |
||
439 | mov edx,[free_additional_memory] |
||
440 | mov ecx,[edx+14h] |
||
441 | add ecx,40h |
||
442 | call write |
||
443 | jc write_failed |
||
444 | mov edx,[memory_start] |
||
445 | mov ecx,esi |
||
446 | call write |
||
447 | jc write_failed |
||
448 | call close |
||
449 | ret |
||
2665 | dunkaist | 450 |