Subversion Repositories Kolibri OS

Rev

Rev 2664 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2665 dunkaist 1
 
2
; Copyright (c) 1999-2012, Tomasz Grysztar.
3
; All rights reserved.
4
5
 
6
	mov	edi,[code_start]
2287 heavyiron 7
	call	setup_dump_header
8
	mov	esi,[input_file]
9
	call	copy_asciiz
10
	cmp	edi,[display_buffer]
11
	jae	out_of_memory
2665 dunkaist 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,[display_buffer]
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
2287 heavyiron 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,[display_buffer]
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,[display_buffer]
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,[display_buffer]
90
	jae	out_of_memory
91
	jmp	prepare_strings_table
92
      strings_table_ready:
93
	mov	edx,[display_buffer]
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]
692 heavyiron 118
	lea	eax,[edi+ecx+1]
2287 heavyiron 119
	cmp	edi,[display_buffer]
120
	jae	out_of_memory
121
	rep	movsb
692 heavyiron 122
	xor	al,al
2287 heavyiron 123
	stosb
692 heavyiron 124
      label_dump_name_ok:
2287 heavyiron 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
	mov	eax,[edx+20]
132
	test	eax,eax
133
	jz	base_symbol_for_label_ok
134
	cmp	eax,[symbols_stream]
135
	mov	eax,[eax+4]
136
	jae	base_symbol_for_label_ok
137
	xor	eax,eax
138
      base_symbol_for_label_ok:
139
	mov	[edx+20],eax
140
	mov	ax,[current_pass]
141
	cmp	ax,[edx+16]
142
	je	label_defined_flag_ok
143
	and	byte [edx+8],not 1
144
      label_defined_flag_ok:
145
	cmp	ax,[edx+18]
146
	je	label_used_flag_ok
147
	and	byte [edx+8],not 8
148
      label_used_flag_ok:
149
	add	edx,LABEL_STRUCTURE_SIZE
150
	jmp	prepare_labels_dump
151
      labels_dump_ok:
2665 dunkaist 152
	mov	eax,edi
153
	sub	eax,ebx
154
	mov	[ebx-40h+14h],eax
155
	add	eax,40h
156
	mov	[ebx-40h+18h],eax
157
	mov	ecx,[memory_end]
158
	sub	ecx,[labels_list]
159
	mov	[ebx-40h+1Ch],ecx
160
	add	eax,ecx
161
	mov	[ebx-40h+20h],eax
162
	mov	ecx,[source_start]
163
	sub	ecx,[memory_start]
164
	mov	[ebx-40h+24h],ecx
165
	add	eax,ecx
166
	mov	[ebx-40h+28h],eax
167
	mov	eax,[number_of_sections]
168
	shl	eax,2
169
	mov	[ebx-40h+34h],eax
170
	call	prepare_preprocessed_source
171
	mov	esi,[labels_list]
172
	mov	ebp,edi
173
      make_lines_dump:
2287 heavyiron 174
	cmp	esi,[display_buffer]
175
	je	lines_dump_ok
176
	mov	eax,[esi-4]
177
	mov	ecx,[esi-8]
178
	sub	esi,8
2665 dunkaist 179
	sub	esi,ecx
180
	cmp	eax,1
181
	je	process_line_dump
182
	cmp	eax,2
183
	jne	make_lines_dump
184
	add	dword [ebx-40h+3Ch],8
185
	jmp	make_lines_dump
186
      process_line_dump:
187
	mov	eax,[esi+4]
188
	sub	eax,[code_start]
189
	add	eax,[headers_size]
190
	cmp	byte [esi+1Ah],0
2287 heavyiron 191
	je	store_offset
192
	xor	eax,eax
193
      store_offset:
194
	stos	dword [edi]
195
	mov	eax,[esi]
196
	sub	eax,[memory_start]
197
	stos	dword [edi]
2665 dunkaist 198
	mov	eax,[esi+4]
199
	xor	edx,edx
200
	xor	cl,cl
201
	sub	eax,[esi+8]
202
	sbb	edx,[esi+8+4]
203
	sbb	cl,[esi+1Bh]
204
	stos	dword [edi]
205
	mov	eax,edx
206
	stos	dword [edi]
207
	mov	eax,[esi+10h]
2287 heavyiron 208
	stos	dword [edi]
209
	mov	eax,[esi+14h]
210
	test	eax,eax
211
	jz	base_symbol_for_line_ok
212
	cmp	eax,[symbols_stream]
213
	mov	eax,[eax+4]
214
	jae	base_symbol_for_line_ok
215
	xor	eax,eax
216
      base_symbol_for_line_ok:
2665 dunkaist 217
	stos	dword [edi]
218
	mov	eax,[esi+18h]
219
	and	eax,01FFFFh
220
	stos	dword [edi]
221
	mov	[edi-1],cl
222
	cmp	edi,[display_buffer]
223
	jae	out_of_memory
224
	mov	eax,edi
225
	sub	eax,1Ch
226
	sub	eax,ebp
227
	mov	[esi],eax
228
	jmp	make_lines_dump
229
      lines_dump_ok:
230
	mov	edx,edi
231
	mov	eax,[current_offset]
2287 heavyiron 232
	sub	eax,[code_start]
233
	add	eax,[headers_size]
234
	stos	dword [edi]
2665 dunkaist 235
	mov	ecx,edi
236
	sub	ecx,ebx
237
	sub	ecx,[ebx-40h+14h]
238
	mov	[ebx-40h+2Ch],ecx
239
	add	ecx,[ebx-40h+28h]
240
	mov	[ebx-40h+30h],ecx
241
	add	ecx,[ebx-40h+34h]
242
	mov	[ebx-40h+38h],ecx
243
      find_inexisting_offsets:
244
	sub	edx,1Ch
245
	cmp	edx,ebp
246
	jb	write_symbols
2287 heavyiron 247
	test	byte [edx+1Ah],1
248
	jnz	find_inexisting_offsets
249
	cmp	eax,[edx]
250
	jb	correct_inexisting_offset
251
	mov	eax,[edx]
2665 dunkaist 252
	jmp	find_inexisting_offsets
253
      correct_inexisting_offset:
254
	and	dword [edx],0
255
	or	byte [edx+1Ah],2
256
	jmp	find_inexisting_offsets
257
      write_symbols:
258
	mov	edx,[symbols_file]
2287 heavyiron 259
	call	create
692 heavyiron 260
	jc	write_failed
2665 dunkaist 261
	mov	edx,[code_start]
262
	mov	ecx,[edx+14h]
263
	add	ecx,40h
264
	call	write
265
	jc	write_failed
266
	mov	edx,[display_buffer]
267
	mov	ecx,[memory_end]
2287 heavyiron 268
	sub	ecx,[labels_list]
269
	call	write
270
	jc	write_failed
271
	mov	edx,[memory_start]
272
	mov	ecx,[source_start]
273
	sub	ecx,edx
274
	call	write
275
	jc	write_failed
276
	mov	edx,ebp
277
	mov	ecx,edi
692 heavyiron 278
	sub	ecx,edx
279
	call	write
280
	jc	write_failed
2287 heavyiron 281
	mov	edx,[free_additional_memory]
282
	mov	ecx,[number_of_sections]
283
	shl	ecx,2
2665 dunkaist 284
	call	write
285
	jc	write_failed
286
	mov	esi,[labels_list]
287
	mov	edi,[memory_start]
288
      make_references_dump:
289
	cmp	esi,[display_buffer]
290
	je	references_dump_ok
291
	mov	eax,[esi-4]
292
	mov	ecx,[esi-8]
293
	sub	esi,8
294
	sub	esi,ecx
295
	cmp	eax,2
296
	je	dump_reference
297
	cmp	eax,1
298
	jne	make_references_dump
299
	mov	edx,[esi]
300
	jmp	make_references_dump
301
      dump_reference:
302
	mov	eax,[memory_end]
303
	sub	eax,[esi]
304
	sub	eax,LABEL_STRUCTURE_SIZE
305
	stosd
306
	mov	eax,edx
307
	stosd
308
	cmp	edi,[display_buffer]
309
	jb	make_references_dump
310
	jmp	out_of_memory
311
      references_dump_ok:
312
	mov	edx,[memory_start]
313
	mov	ecx,edi
314
	sub	ecx,edx
315
	call	write
316
	jc	write_failed
317
	call	close
318
	ret
319
      setup_dump_header:
320
	xor	eax,eax
321
	mov	ecx,40h shr 2
322
	rep	stos dword [edi]
323
	mov	ebx,edi
324
	mov	dword [ebx-40h],'fas'+1Ah shl 24
325
	mov	dword [ebx-40h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 40h shl 16
326
	mov	dword [ebx-40h+10h],40h
327
	ret
328
prepare_preprocessed_source:
329
	mov	esi,[memory_start]
330
	mov	ebp,[source_start]
2287 heavyiron 331
	test	ebp,ebp
332
	jnz	prepare_preprocessed_line
333
	mov	ebp,[current_line]
334
	inc	ebp
335
      prepare_preprocessed_line:
336
	cmp	esi,ebp
337
	jae	preprocessed_source_ok
338
	mov	eax,[memory_start]
339
	mov	edx,[input_file]
340
	cmp	[esi],edx
341
	jne	line_not_from_main_input
342
	mov	[esi],eax
343
      line_not_from_main_input:
344
	sub	[esi],eax
345
	test	byte [esi+7],1 shl 7
346
	jz	prepare_next_preprocessed_line
347
	sub	[esi+8],eax
348
	sub	[esi+12],eax
349
      prepare_next_preprocessed_line:
350
	call	skip_preprocessed_line
351
	jmp	prepare_preprocessed_line
352
      preprocessed_source_ok:
353
	ret
354
      skip_preprocessed_line:
355
	add	esi,16
356
      skip_preprocessed_line_content:
357
	lods	byte [esi]
358
	cmp	al,1Ah
359
	je	skip_preprocessed_symbol
360
	cmp	al,3Bh
361
	je	skip_preprocessed_symbol
362
	cmp	al,22h
363
	je	skip_preprocessed_string
364
	or	al,al
365
	jnz	skip_preprocessed_line_content
366
	ret
367
      skip_preprocessed_string:
368
	lods	dword [esi]
369
	add	esi,eax
370
	jmp	skip_preprocessed_line_content
371
      skip_preprocessed_symbol:
372
	lods	byte [esi]
373
	movzx	eax,al
374
	add	esi,eax
375
	jmp	skip_preprocessed_line_content
376
restore_preprocessed_source:
377
	mov	esi,[memory_start]
378
	mov	ebp,[source_start]
379
	test	ebp,ebp
380
	jnz	restore_preprocessed_line
381
	mov	ebp,[current_line]
382
	inc	ebp
383
      restore_preprocessed_line:
384
	cmp	esi,ebp
385
	jae	preprocessed_source_restored
386
	mov	eax,[memory_start]
387
	add	[esi],eax
388
	cmp	[esi],eax
389
	jne	preprocessed_line_source_restored
390
	mov	edx,[input_file]
391
	mov	[esi],edx
392
      preprocessed_line_source_restored:
393
	test	byte [esi+7],1 shl 7
394
	jz	restore_next_preprocessed_line
395
	add	[esi+8],eax
396
	add	[esi+12],eax
397
      restore_next_preprocessed_line:
398
	call	skip_preprocessed_line
399
	jmp	restore_preprocessed_line
400
      preprocessed_source_restored:
401
	ret
402
dump_preprocessed_source:
403
	mov	edi,[free_additional_memory]
404
	call	setup_dump_header
405
	mov	esi,[input_file]
406
	call	copy_asciiz
407
	cmp	edi,[additional_memory_end]
408
	jae	out_of_memory
409
	mov	eax,edi
2665 dunkaist 410
	sub	eax,ebx
411
	dec	eax
412
	mov	[ebx-40h+0Ch],eax
413
	mov	eax,edi
414
	sub	eax,ebx
415
	mov	[ebx-40h+14h],eax
416
	add	eax,40h
417
	mov	[ebx-40h+20h],eax
418
	call	prepare_preprocessed_source
419
	sub	esi,[memory_start]
420
	mov	[ebx-40h+24h],esi
421
	mov	edx,[symbols_file]
422
	call	create
423
	jc	write_failed
424
	mov	edx,[free_additional_memory]
425
	mov	ecx,[edx+14h]
426
	add	ecx,40h
427
	call	write
428
	jc	write_failed
429
	mov	edx,[memory_start]
430
	mov	ecx,esi
2287 heavyiron 431
	call	write
432
	jc	write_failed
433
	call	close
434
	ret
2665 dunkaist 435