Subversion Repositories Kolibri OS

Rev

Rev 1242 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1242 Rev 2287
1
; flat assembler core
1
; flat assembler core
2
; Copyright (c) 1999-2009, Tomasz Grysztar.
2
; Copyright (c) 1999-2011, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
4
 
4
 
5
formatter:
5
formatter:
6
	mov	[current_offset],edi
6
	mov	[current_offset],edi
7
	cmp	[output_file],0
7
	cmp	[output_file],0
8
	jne	output_path_ok
8
	jne	output_path_ok
9
	mov	esi,[input_file]
9
	mov	esi,[input_file]
10
	mov	edi,[free_additional_memory]
10
	mov	edi,[free_additional_memory]
11
      copy_output_path:
11
      copy_output_path:
12
	lods	byte [esi]
12
	lods	byte [esi]
13
	cmp	edi,[structures_buffer]
13
	cmp	edi,[structures_buffer]
14
	jae	out_of_memory
14
	jae	out_of_memory
15
	stos	byte [edi]
15
	stos	byte [edi]
16
	or	al,al
16
	or	al,al
17
	jnz	copy_output_path
17
	jnz	copy_output_path
18
	dec	edi
18
	dec	edi
19
	mov	eax,edi
19
	mov	eax,edi
20
      find_extension:
20
      find_extension:
21
	dec	eax
21
	dec	eax
22
	cmp	eax,[free_additional_memory]
22
	cmp	eax,[free_additional_memory]
23
	jb	extension_found
23
	jb	extension_found
24
	cmp	byte [eax],'\'
24
	cmp	byte [eax],'\'
25
	je	extension_found
25
	je	extension_found
26
	cmp	byte [eax],'/'
26
	cmp	byte [eax],'/'
27
	je	extension_found
27
	je	extension_found
28
	cmp	byte [eax],'.'
28
	cmp	byte [eax],'.'
29
	jne	find_extension
29
	jne	find_extension
30
	mov	edi,eax
30
	mov	edi,eax
31
      extension_found:
31
      extension_found:
32
	lea	eax,[edi+9]
32
	lea	eax,[edi+9]
33
	cmp	eax,[structures_buffer]
33
	cmp	eax,[structures_buffer]
34
	jae	out_of_memory
34
	jae	out_of_memory
35
	cmp	[file_extension],0
35
	cmp	[file_extension],0
36
	jne	extension_specified
36
	jne	extension_specified
37
	cmp	[output_format],2
37
	cmp	[output_format],2
38
	je	exe_extension
38
	je	exe_extension
39
	jb	bin_extension
39
	jb	bin_extension
40
	cmp	[output_format],4
40
	cmp	[output_format],4
41
	je	obj_extension
41
	je	obj_extension
42
	cmp	[output_format],5
42
	cmp	[output_format],5
43
	je	o_extension
43
	je	o_extension
44
	cmp	[output_format],3
44
	cmp	[output_format],3
45
	jne	no_extension
45
	jne	no_extension
46
	cmp	[subsystem],1
46
	cmp	[subsystem],1
47
	je	sys_extension
47
	je	sys_extension
48
	cmp	[subsystem],10
48
	cmp	[subsystem],10
49
	jae	efi_extension
49
	jae	efi_extension
50
	bt	[format_flags],8
50
	bt	[format_flags],8
51
	jnc	exe_extension
51
	jnc	exe_extension
52
	mov	eax,'.dll'
52
	mov	eax,'.dll'
53
	jmp	make_extension
53
	jmp	make_extension
54
      sys_extension:
54
      sys_extension:
55
	mov	eax,'.sys'
55
	mov	eax,'.sys'
56
	jmp	make_extension
56
	jmp	make_extension
57
      efi_extension:
57
      efi_extension:
58
	mov	eax,'.efi'
58
	mov	eax,'.efi'
59
	jmp	make_extension
59
	jmp	make_extension
60
      bin_extension:
60
      bin_extension:
61
	mov	eax,'.bin'
61
	mov	eax,'.bin'
62
	bt	[format_flags],0
62
	bt	[format_flags],0
63
	jnc	make_extension
63
	jnc	make_extension
64
	mov	eax,'.com'
64
	mov	eax,'.com'
65
	jmp	make_extension
65
	jmp	make_extension
66
      obj_extension:
66
      obj_extension:
67
	mov	eax,'.obj'
67
	mov	eax,'.obj'
68
	jmp	make_extension
68
	jmp	make_extension
69
      o_extension:
69
      o_extension:
70
	mov	eax,'.o'
70
	mov	eax,'.o'
71
	bt	[format_flags],0
71
	bt	[format_flags],0
72
	jnc	make_extension
72
	jnc	make_extension
73
      no_extension:
73
      no_extension:
74
	xor	eax,eax
74
	xor	eax,eax
75
	jmp	make_extension
75
	jmp	make_extension
76
      exe_extension:
76
      exe_extension:
77
	mov	eax,'.exe'
77
	mov	eax,'.exe'
78
      make_extension:
78
      make_extension:
79
	xchg	eax,[edi]
79
	xchg	eax,[edi]
80
	scas	dword [edi]
80
	scas	dword [edi]
81
	mov	byte [edi],0
81
	mov	byte [edi],0
82
	scas	byte [edi]
82
	scas	byte [edi]
83
	mov	esi,edi
83
	mov	esi,edi
84
	stos	dword [edi]
84
	stos	dword [edi]
85
	sub	edi,9
85
	sub	edi,9
86
	xor	eax,eax
86
	xor	eax,eax
87
	mov	ebx,characters
87
	mov	ebx,characters
88
      adapt_case:
88
      adapt_case:
89
	mov	al,[esi]
89
	mov	al,[esi]
90
	or	al,al
90
	or	al,al
91
	jz	adapt_next
91
	jz	adapt_next
92
	xlat	byte [ebx]
92
	xlat	byte [ebx]
93
	cmp	al,[esi]
93
	cmp	al,[esi]
94
	je	adapt_ok
94
	je	adapt_ok
95
	sub	byte [edi],20h
95
	sub	byte [edi],20h
96
      adapt_ok:
96
      adapt_ok:
97
	inc	esi
97
	inc	esi
98
      adapt_next:
98
      adapt_next:
99
	inc	edi
99
	inc	edi
100
	cmp	byte [edi],0
100
	cmp	byte [edi],0
101
	jne	adapt_case
101
	jne	adapt_case
102
	jmp	extension_ok
102
	jmp	extension_ok
103
      extension_specified:
103
      extension_specified:
104
	mov	al,'.'
104
	mov	al,'.'
105
	stos	byte [edi]
105
	stos	byte [edi]
106
	mov	esi,[file_extension]
106
	mov	esi,[file_extension]
107
      copy_extension:
107
      copy_extension:
108
	lods	byte [esi]
108
	lods	byte [esi]
109
	stos	byte [edi]
109
	stos	byte [edi]
110
	test	al,al
110
	test	al,al
111
	jnz	copy_extension
111
	jnz	copy_extension
112
	dec	edi
112
	dec	edi
113
      extension_ok:
113
      extension_ok:
114
	mov	esi,edi
114
	mov	esi,edi
115
	lea	ecx,[esi+1]
115
	lea	ecx,[esi+1]
116
	sub	ecx,[free_additional_memory]
116
	sub	ecx,[free_additional_memory]
117
	mov	edi,[structures_buffer]
117
	mov	edi,[structures_buffer]
118
	dec	edi
118
	dec	edi
119
	std
119
	std
120
	rep	movs byte [edi],[esi]
120
	rep	movs byte [edi],[esi]
121
	cld
121
	cld
122
	inc	edi
122
	inc	edi
123
	mov	[structures_buffer],edi
123
	mov	[structures_buffer],edi
124
	mov	[output_file],edi
124
	mov	[output_file],edi
125
      output_path_ok:
125
      output_path_ok:
126
	cmp	[symbols_file],0
126
	cmp	[symbols_file],0
127
	je	labels_table_ok
127
	je	labels_table_ok
128
	mov	ecx,[memory_end]
128
	mov	ecx,[memory_end]
129
	sub	ecx,[labels_list]
129
	sub	ecx,[labels_list]
130
	mov	edi,[display_buffer]
130
	mov	edi,[display_buffer]
131
	sub	edi,8
131
	sub	edi,8
132
	mov	[edi],ecx
132
	mov	[edi],ecx
133
	or	dword [edi+4],-1
133
	or	dword [edi+4],-1
134
	sub	edi,ecx
134
	sub	edi,ecx
135
	cmp	edi,[current_offset]
135
	cmp	edi,[current_offset]
136
	jbe	out_of_memory
136
	jbe	out_of_memory
137
	mov	[display_buffer],edi
137
	mov	[display_buffer],edi
138
	mov	esi,[memory_end]
138
	mov	esi,[memory_end]
139
      copy_labels:
139
      copy_labels:
140
	sub	esi,32
140
	sub	esi,32
141
	cmp	esi,[labels_list]
141
	cmp	esi,[labels_list]
142
	jb	labels_table_ok
142
	jb	labels_table_ok
143
	mov	ecx,32 shr 2
143
	mov	ecx,32 shr 2
144
	rep	movs dword [edi],[esi]
144
	rep	movs dword [edi],[esi]
145
	sub	esi,32
145
	sub	esi,32
146
	jmp	copy_labels
146
	jmp	copy_labels
147
      labels_table_ok:
147
      labels_table_ok:
148
	mov	edi,[current_offset]
148
	mov	edi,[current_offset]
149
	cmp	[output_format],4
149
	cmp	[output_format],4
150
	je	coff_formatter
150
	je	coff_formatter
151
	cmp	[output_format],5
151
	cmp	[output_format],5
152
	jne	common_formatter
152
	jne	common_formatter
153
	bt	[format_flags],0
153
	bt	[format_flags],0
154
	jnc	elf_formatter
154
	jnc	elf_formatter
155
      common_formatter:
155
      common_formatter:
156
	mov	eax,edi
156
	mov	eax,edi
157
	sub	eax,[code_start]
157
	sub	eax,[code_start]
158
	mov	[real_code_size],eax
158
	mov	[real_code_size],eax
159
	cmp	edi,[undefined_data_end]
159
	cmp	edi,[undefined_data_end]
160
	jne	calculate_code_size
160
	jne	calculate_code_size
161
	mov	edi,[undefined_data_start]
161
	mov	edi,[undefined_data_start]
162
      calculate_code_size:
162
      calculate_code_size:
163
	mov	[current_offset],edi
163
	mov	[current_offset],edi
164
	sub	edi,[code_start]
164
	sub	edi,[code_start]
165
	mov	[code_size],edi
165
	mov	[code_size],edi
166
	mov	[written_size],0
166
	mov	[written_size],0
167
	mov	edx,[output_file]
167
	mov	edx,[output_file]
168
	call	create
168
	call	create
169
	jc	write_failed
169
	jc	write_failed
170
	cmp	[output_format],3
170
	cmp	[output_format],3
171
	jne	stub_written
171
	jne	stub_written
172
	mov	edx,[code_start]
172
	mov	edx,[code_start]
173
	mov	ecx,[stub_size]
173
	mov	ecx,[stub_size]
174
	sub	edx,ecx
174
	sub	edx,ecx
175
	add	[written_size],ecx
175
	add	[written_size],ecx
176
	call	write
176
	call	write
177
      stub_written:
177
      stub_written:
178
	cmp	[output_format],2
178
	cmp	[output_format],2
179
	jne	write_output
179
	jne	write_output
180
	call	write_mz_header
180
	call	write_mz_header
181
      write_output:
181
      write_output:
182
	call	write_code
182
	call	write_code
183
      output_written:
183
      output_written:
184
	call	close
184
	call	close
185
	cmp	[symbols_file],0
185
	cmp	[symbols_file],0
186
	jne	dump_symbols
186
	jne	dump_symbols
187
	ret
187
	ret
188
      write_code:
188
      write_code:
189
	mov	eax,[written_size]
189
	mov	eax,[written_size]
190
	mov	[headers_size],eax
190
	mov	[headers_size],eax
191
	mov	edx,[code_start]
191
	mov	edx,[code_start]
192
	mov	ecx,[code_size]
192
	mov	ecx,[code_size]
193
	add	[written_size],ecx
193
	add	[written_size],ecx
194
	lea	eax,[edx+ecx]
194
	lea	eax,[edx+ecx]
195
	call	write
195
	call	write
196
	jc	write_failed
196
	jc	write_failed
197
	ret
197
	ret
198
format_directive:
198
format_directive:
199
	cmp	edi,[code_start]
199
	cmp	edi,[code_start]
200
	jne	unexpected_instruction
200
	jne	unexpected_instruction
201
	cmp	[virtual_data],0
201
	cmp	[virtual_data],0
202
	jne	unexpected_instruction
202
	jne	unexpected_instruction
203
	cmp	[output_format],0
203
	cmp	[output_format],0
204
	jne	unexpected_instruction
204
	jne	unexpected_instruction
205
	lods	byte [esi]
205
	lods	byte [esi]
206
	cmp	al,17h
206
	cmp	al,1Ch
207
	je	format_prefix
207
	je	format_prefix
208
	cmp	al,18h
208
	cmp	al,18h
209
	jne	invalid_argument
209
	jne	invalid_argument
210
	lods	byte [esi]
210
	lods	byte [esi]
211
      select_format:
211
      select_format:
212
	mov	dl,al
212
	mov	dl,al
213
	shr	al,4
213
	shr	al,4
214
	mov	[output_format],al
214
	mov	[output_format],al
215
	and	edx,0Fh
215
	and	edx,0Fh
216
	or	[format_flags],edx
216
	or	[format_flags],edx
217
	cmp	al,2
217
	cmp	al,2
218
	je	format_mz
218
	je	format_mz
219
	cmp	al,3
219
	cmp	al,3
220
	je	format_pe
220
	je	format_pe
221
	cmp	al,4
221
	cmp	al,4
222
	je	format_coff
222
	je	format_coff
223
	cmp	al,5
223
	cmp	al,5
224
	je	format_elf
224
	je	format_elf
225
      format_defined:
225
      format_defined:
226
	cmp	byte [esi],86h
226
	cmp	byte [esi],86h
227
	jne	instruction_assembled
227
	jne	instruction_assembled
228
	cmp	word [esi+1],'('
228
	cmp	word [esi+1],'('
229
	jne	invalid_argument
229
	jne	invalid_argument
230
	mov	eax,[esi+3]
230
	mov	eax,[esi+3]
231
	add	esi,3+4
231
	add	esi,3+4
232
	mov	[file_extension],esi
232
	mov	[file_extension],esi
233
	lea	esi,[esi+eax+1]
233
	lea	esi,[esi+eax+1]
234
	jmp	instruction_assembled
234
	jmp	instruction_assembled
235
      format_prefix:
235
      format_prefix:
236
	lods	byte [esi]
236
	lods	byte [esi]
237
	mov	ah,al
237
	mov	ah,al
238
	lods	byte [esi]
238
	lods	byte [esi]
239
	cmp	al,18h
239
	cmp	al,18h
240
	jne	invalid_argument
240
	jne	invalid_argument
241
	lods	byte [esi]
241
	lods	byte [esi]
242
	mov	edx,eax
242
	mov	edx,eax
243
	shr	dl,4
243
	shr	dl,4
244
	shr	dh,4
244
	shr	dh,4
245
	cmp	dl,dh
245
	cmp	dl,dh
246
	jne	invalid_argument
246
	jne	invalid_argument
247
	or	al,ah
247
	or	al,ah
248
	jmp	select_format
248
	jmp	select_format
249
entry_directive:
249
entry_directive:
250
	bts	[format_flags],10h
250
	bts	[format_flags],10h
251
	jc	setting_already_specified
251
	jc	setting_already_specified
252
	mov	al,[output_format]
252
	mov	al,[output_format]
253
	cmp	al,2
253
	cmp	al,2
254
	je	mz_entry
254
	je	mz_entry
255
	cmp	al,3
255
	cmp	al,3
256
	je	pe_entry
256
	je	pe_entry
257
	cmp	al,5
257
	cmp	al,5
258
	jne	illegal_instruction
258
	jne	illegal_instruction
259
	bt	[format_flags],0
259
	bt	[format_flags],0
260
	jc	elf_entry
260
	jc	elf_entry
261
	jmp	illegal_instruction
261
	jmp	illegal_instruction
262
stack_directive:
262
stack_directive:
263
	bts	[format_flags],11h
263
	bts	[format_flags],11h
264
	jc	setting_already_specified
264
	jc	setting_already_specified
265
	mov	al,[output_format]
265
	mov	al,[output_format]
266
	cmp	al,2
266
	cmp	al,2
267
	je	mz_stack
267
	je	mz_stack
268
	cmp	al,3
268
	cmp	al,3
269
	je	pe_stack
269
	je	pe_stack
270
	jmp	illegal_instruction
270
	jmp	illegal_instruction
271
heap_directive:
271
heap_directive:
272
	bts	[format_flags],12h
272
	bts	[format_flags],12h
273
	jc	setting_already_specified
273
	jc	setting_already_specified
274
	mov	al,[output_format]
274
	mov	al,[output_format]
275
	cmp	al,2
275
	cmp	al,2
276
	je	mz_heap
276
	je	mz_heap
277
	cmp	al,3
277
	cmp	al,3
278
	je	pe_heap
278
	je	pe_heap
279
	jmp	illegal_instruction
279
	jmp	illegal_instruction
280
segment_directive:
280
segment_directive:
281
	cmp	[virtual_data],0
281
	cmp	[virtual_data],0
282
	jne	illegal_instruction
282
	jne	illegal_instruction
283
	mov	al,[output_format]
283
	mov	al,[output_format]
284
	cmp	al,2
284
	cmp	al,2
285
	je	mz_segment
285
	je	mz_segment
286
	cmp	al,5
286
	cmp	al,5
287
	je	elf_segment
287
	je	elf_segment
288
	jmp	illegal_instruction
288
	jmp	illegal_instruction
289
section_directive:
289
section_directive:
290
	cmp	[virtual_data],0
290
	cmp	[virtual_data],0
291
	jne	illegal_instruction
291
	jne	illegal_instruction
292
	mov	al,[output_format]
292
	mov	al,[output_format]
293
	cmp	al,3
293
	cmp	al,3
294
	je	pe_section
294
	je	pe_section
295
	cmp	al,4
295
	cmp	al,4
296
	je	coff_section
296
	je	coff_section
297
	cmp	al,5
297
	cmp	al,5
298
	je	elf_section
298
	je	elf_section
299
	jmp	illegal_instruction
299
	jmp	illegal_instruction
300
public_directive:
300
public_directive:
301
	mov	al,[output_format]
301
	mov	al,[output_format]
302
	cmp	al,4
302
	cmp	al,4
303
	je	public_allowed
303
	je	public_allowed
304
	cmp	al,5
304
	cmp	al,5
305
	jne	illegal_instruction
305
	jne	illegal_instruction
306
	bt	[format_flags],0
306
	bt	[format_flags],0
307
	jc	illegal_instruction
307
	jc	illegal_instruction
308
      public_allowed:
308
      public_allowed:
309
	mov	[base_code],0C0h
309
	mov	[base_code],0C0h
310
	lods	byte [esi]
310
	lods	byte [esi]
311
	cmp	al,2
311
	cmp	al,2
312
	je	public_label
312
	je	public_label
313
	cmp	al,1Dh
313
	cmp	al,1Dh
314
	jne	invalid_argument
314
	jne	invalid_argument
315
	lods	byte [esi]
315
	lods	byte [esi]
316
	and	al,7
316
	and	al,7
317
	add	[base_code],al
317
	add	[base_code],al
318
	lods	byte [esi]
318
	lods	byte [esi]
319
	cmp	al,2
319
	cmp	al,2
320
	jne	invalid_argument
320
	jne	invalid_argument
321
      public_label:
321
      public_label:
322
	lods	dword [esi]
322
	lods	dword [esi]
323
	cmp	eax,0Fh
323
	cmp	eax,0Fh
324
	jb	invalid_use_of_symbol
324
	jb	invalid_use_of_symbol
325
	je	reserved_word_used_as_symbol
325
	je	reserved_word_used_as_symbol
326
	mov	dx,[current_pass]
326
	mov	dx,[current_pass]
327
	mov	[eax+18],dx
327
	mov	[eax+18],dx
328
	or	byte [eax+8],8
328
	or	byte [eax+8],8
329
	inc	esi
329
	inc	esi
330
	mov	ebx,[free_additional_memory]
330
	mov	ebx,[free_additional_memory]
331
	lea	edx,[ebx+10h]
331
	lea	edx,[ebx+10h]
332
	cmp	edx,[structures_buffer]
332
	cmp	edx,[structures_buffer]
333
	jae	out_of_memory
333
	jae	out_of_memory
334
	mov	[free_additional_memory],edx
334
	mov	[free_additional_memory],edx
335
	mov	[ebx+8],eax
335
	mov	[ebx+8],eax
336
	mov	eax,[current_line]
336
	mov	eax,[current_line]
337
	mov	[ebx+0Ch],eax
337
	mov	[ebx+0Ch],eax
338
	lods	byte [esi]
338
	lods	byte [esi]
339
	cmp	al,86h
339
	cmp	al,86h
340
	jne	invalid_argument
340
	jne	invalid_argument
341
	lods	word [esi]
341
	lods	word [esi]
342
	cmp	ax,'('
342
	cmp	ax,'('
343
	jne	invalid_argument
343
	jne	invalid_argument
344
	mov	[ebx+4],esi
344
	mov	[ebx+4],esi
345
	lods	dword [esi]
345
	lods	dword [esi]
346
	lea	esi,[esi+eax+1]
346
	lea	esi,[esi+eax+1]
347
	mov	al,[base_code]
347
	mov	al,[base_code]
348
	mov	[ebx],al
348
	mov	[ebx],al
349
	jmp	instruction_assembled
349
	jmp	instruction_assembled
350
extrn_directive:
350
extrn_directive:
351
	mov	al,[output_format]
351
	mov	al,[output_format]
352
	cmp	al,4
352
	cmp	al,4
353
	je	extrn_allowed
353
	je	extrn_allowed
354
	cmp	al,5
354
	cmp	al,5
355
	jne	illegal_instruction
355
	jne	illegal_instruction
356
	bt	[format_flags],0
356
	bt	[format_flags],0
357
	jc	illegal_instruction
357
	jc	illegal_instruction
358
      extrn_allowed:
358
      extrn_allowed:
359
	lods	word [esi]
359
	lods	word [esi]
360
	cmp	ax,'('
360
	cmp	ax,'('
361
	jne	invalid_argument
361
	jne	invalid_argument
362
	mov	ebx,esi
362
	mov	ebx,esi
363
	lods	dword [esi]
363
	lods	dword [esi]
364
	lea	esi,[esi+eax+1]
364
	lea	esi,[esi+eax+1]
365
	mov	edx,[free_additional_memory]
365
	mov	edx,[free_additional_memory]
366
	lea	eax,[edx+0Ch]
366
	lea	eax,[edx+0Ch]
367
	cmp	eax,[structures_buffer]
367
	cmp	eax,[structures_buffer]
368
	jae	out_of_memory
368
	jae	out_of_memory
369
	mov	[free_additional_memory],eax
369
	mov	[free_additional_memory],eax
370
	mov	byte [edx],80h
370
	mov	byte [edx],80h
371
	mov	[edx+4],ebx
371
	mov	[edx+4],ebx
372
	lods	byte [esi]
372
	lods	byte [esi]
373
	cmp	al,86h
373
	cmp	al,86h
374
	jne	invalid_argument
374
	jne	invalid_argument
375
	lods	byte [esi]
375
	lods	byte [esi]
376
	cmp	al,2
376
	cmp	al,2
377
	jne	invalid_argument
377
	jne	invalid_argument
378
	lods	dword [esi]
378
	lods	dword [esi]
379
	cmp	eax,0Fh
379
	cmp	eax,0Fh
380
	jb	invalid_use_of_symbol
380
	jb	invalid_use_of_symbol
381
	je	reserved_word_used_as_symbol
381
	je	reserved_word_used_as_symbol
382
	inc	esi
382
	inc	esi
383
	mov	ebx,eax
383
	mov	ebx,eax
384
	xor	ah,ah
384
	xor	ah,ah
385
	lods	byte [esi]
385
	lods	byte [esi]
386
	cmp	al,':'
386
	cmp	al,':'
387
	je	get_extrn_size
387
	je	get_extrn_size
388
	dec	esi
388
	dec	esi
389
	cmp	al,11h
389
	cmp	al,11h
390
	jne	extrn_size_ok
390
	jne	extrn_size_ok
391
      get_extrn_size:
391
      get_extrn_size:
392
	lods	word [esi]
392
	lods	word [esi]
393
	cmp	al,11h
393
	cmp	al,11h
394
	jne	invalid_argument
394
	jne	invalid_argument
395
      extrn_size_ok:
395
      extrn_size_ok:
396
	mov	[address_symbol],edx
396
	mov	[address_symbol],edx
397
	movzx	ecx,ah
397
	movzx	ecx,ah
398
	mov	[edx+8],ecx
398
	mov	[edx+8],ecx
399
	xor	eax,eax
399
	xor	eax,eax
400
	xor	edx,edx
400
	xor	edx,edx
401
	xor	ebp,ebp
401
	xor	ebp,ebp
402
	mov	ch,2
402
	mov	ch,2
403
	test	[format_flags],8
403
	test	[format_flags],8
404
	jz	make_free_label
404
	jz	make_free_label
405
	mov	ch,4
405
	mov	ch,4
406
	jmp	make_free_label
406
	jmp	make_free_label
407
mark_relocation:
407
mark_relocation:
408
	cmp	[value_type],0
408
	cmp	[value_type],0
409
	je	relocation_ok
409
	je	relocation_ok
410
	cmp	[virtual_data],0
410
	cmp	[virtual_data],0
411
	jne	relocation_ok
411
	jne	relocation_ok
412
	cmp	[output_format],2
412
	cmp	[output_format],2
413
	je	mark_mz_relocation
413
	je	mark_mz_relocation
414
	cmp	[output_format],3
414
	cmp	[output_format],3
415
	je	mark_pe_relocation
415
	je	mark_pe_relocation
416
	cmp	[output_format],4
416
	cmp	[output_format],4
417
	je	mark_coff_relocation
417
	je	mark_coff_relocation
418
	cmp	[output_format],5
418
	cmp	[output_format],5
419
	je	mark_elf_relocation
419
	je	mark_elf_relocation
420
      relocation_ok:
420
      relocation_ok:
421
	ret
421
	ret
422
close_pass:
422
close_pass:
423
	mov	al,[output_format]
423
	mov	al,[output_format]
424
	cmp	al,3
424
	cmp	al,3
425
	je	close_pe
425
	je	close_pe
426
	cmp	al,4
426
	cmp	al,4
427
	je	close_coff
427
	je	close_coff
428
	cmp	al,5
428
	cmp	al,5
429
	je	close_elf
429
	je	close_elf
430
	ret
430
	ret
431
 
431
 
432
format_mz:
432
format_mz:
433
	mov	edx,[additional_memory]
433
	mov	edx,[additional_memory]
434
	push	edi
434
	push	edi
435
	mov	edi,edx
435
	mov	edi,edx
436
	mov	ecx,1Ch shr 2
436
	mov	ecx,1Ch shr 2
437
	xor	eax,eax
437
	xor	eax,eax
438
	rep	stos dword [edi]
438
	rep	stos dword [edi]
439
	mov	[free_additional_memory],edi
439
	mov	[free_additional_memory],edi
440
	pop	edi
440
	pop	edi
441
	mov	word [edx+0Ch],0FFFFh
441
	mov	word [edx+0Ch],0FFFFh
442
	mov	word [edx+10h],1000h
442
	mov	word [edx+10h],1000h
443
	mov	[code_type],16
443
	mov	[code_type],16
444
	jmp	format_defined
444
	jmp	format_defined
445
mark_mz_relocation:
445
mark_mz_relocation:
446
	push	eax ebx
446
	push	eax ebx
447
	inc	[number_of_relocations]
447
	inc	[number_of_relocations]
448
	mov	ebx,[free_additional_memory]
448
	mov	ebx,[free_additional_memory]
449
	mov	eax,edi
449
	mov	eax,edi
450
	sub	eax,[code_start]
450
	sub	eax,[code_start]
451
	mov	[ebx],ax
451
	mov	[ebx],ax
452
	shr	eax,16
452
	shr	eax,16
453
	shl	ax,12
453
	shl	ax,12
454
	mov	[ebx+2],ax
454
	mov	[ebx+2],ax
455
	cmp	word [ebx],0FFFFh
455
	cmp	word [ebx],0FFFFh
456
	jne	mz_relocation_ok
456
	jne	mz_relocation_ok
457
	inc	word [ebx+2]
457
	inc	word [ebx+2]
458
	sub	word [ebx],10h
458
	sub	word [ebx],10h
459
      mz_relocation_ok:
459
      mz_relocation_ok:
460
	add	ebx,4
460
	add	ebx,4
461
	cmp	ebx,[structures_buffer]
461
	cmp	ebx,[structures_buffer]
462
	jae	out_of_memory
462
	jae	out_of_memory
463
	mov	[free_additional_memory],ebx
463
	mov	[free_additional_memory],ebx
464
	pop	ebx eax
464
	pop	ebx eax
465
	ret
465
	ret
466
mz_segment:
466
mz_segment:
467
	lods	byte [esi]
467
	lods	byte [esi]
468
	cmp	al,2
468
	cmp	al,2
469
	jne	invalid_argument
469
	jne	invalid_argument
470
	lods	dword [esi]
470
	lods	dword [esi]
471
	cmp	eax,0Fh
471
	cmp	eax,0Fh
472
	jb	invalid_use_of_symbol
472
	jb	invalid_use_of_symbol
473
	je	reserved_word_used_as_symbol
473
	je	reserved_word_used_as_symbol
474
	inc	esi
474
	inc	esi
475
	mov	ebx,eax
475
	mov	ebx,eax
476
	mov	eax,edi
476
	mov	eax,edi
477
	sub	eax,[code_start]
477
	sub	eax,[code_start]
478
	mov	ecx,0Fh
478
	mov	ecx,0Fh
479
	add	eax,0Fh
479
	add	eax,0Fh
480
	and	eax,1111b
480
	and	eax,1111b
481
	sub	ecx,eax
481
	sub	ecx,eax
482
	mov	edx,edi
482
	mov	edx,edi
483
	xor	eax,eax
483
	xor	eax,eax
484
	rep	stos byte [edi]
484
	rep	stos byte [edi]
485
	mov	dword [org_origin],edi
485
	mov	dword [org_origin],edi
486
	mov	dword [org_origin+4],eax
486
	mov	dword [org_origin+4],eax
487
	mov	[org_registers],eax
487
	mov	[org_registers],eax
488
	mov	[org_start],edi
488
	mov	[org_start],edi
489
	mov	eax,edx
489
	mov	eax,edx
490
	call	undefined_data
490
	call	undefined_data
491
	mov	eax,edi
491
	mov	eax,edi
492
	sub	eax,[code_start]
492
	sub	eax,[code_start]
493
	shr	eax,4
493
	shr	eax,4
494
	cmp	eax,10000h
494
	cmp	eax,10000h
495
	jae	value_out_of_range
495
	jae	value_out_of_range
496
	mov	edx,eax
496
	mov	edx,eax
497
	mov	al,16
497
	mov	al,16
498
	cmp	byte [esi],13h
498
	cmp	byte [esi],13h
499
	jne	segment_type_ok
499
	jne	segment_type_ok
500
	inc	esi
500
	inc	esi
501
	lods	byte [esi]
501
	lods	byte [esi]
502
      segment_type_ok:
502
      segment_type_ok:
503
	mov	[code_type],al
503
	mov	[code_type],al
504
	mov	eax,edx
504
	mov	eax,edx
505
	mov	cx,0100h
505
	mov	cx,0100h
506
	xor	edx,edx
506
	xor	edx,edx
507
	xor	ebp,ebp
507
	xor	ebp,ebp
508
	mov	[address_symbol],edx
508
	mov	[address_symbol],edx
509
	jmp	make_free_label
509
	jmp	make_free_label
510
mz_entry:
510
mz_entry:
511
	lods	byte [esi]
511
	lods	byte [esi]
512
	cmp	al,'('
512
	cmp	al,'('
513
	jne	invalid_argument
513
	jne	invalid_argument
514
	call	get_word_value
514
	call	get_word_value
515
	cmp	[value_type],1
515
	cmp	[value_type],1
516
	je	initial_cs_ok
516
	je	initial_cs_ok
517
	cmp	[error_line],0
517
	cmp	[error_line],0
518
	jne	initial_cs_ok
518
	jne	initial_cs_ok
519
	mov	eax,[current_line]
519
	mov	eax,[current_line]
520
	mov	[error_line],eax
520
	mov	[error_line],eax
521
	mov	[error],invalid_address
521
	mov	[error],invalid_address
522
      initial_cs_ok:
522
      initial_cs_ok:
523
	mov	edx,[additional_memory]
523
	mov	edx,[additional_memory]
524
	mov	[edx+16h],ax
524
	mov	[edx+16h],ax
525
	lods	byte [esi]
525
	lods	byte [esi]
526
	cmp	al,':'
526
	cmp	al,':'
527
	jne	invalid_argument
527
	jne	invalid_argument
528
	lods	byte [esi]
528
	lods	byte [esi]
529
	cmp	al,'('
529
	cmp	al,'('
530
	jne	invalid_argument
530
	jne	invalid_argument
531
	ja	invalid_address
531
	ja	invalid_address
532
	call	get_word_value
532
	call	get_word_value
533
	cmp	[value_type],0
533
	cmp	[value_type],0
534
	jne	invalid_use_of_symbol
534
	jne	invalid_use_of_symbol
535
	mov	edx,[additional_memory]
535
	mov	edx,[additional_memory]
536
	mov	[edx+14h],ax
536
	mov	[edx+14h],ax
537
	jmp	instruction_assembled
537
	jmp	instruction_assembled
538
mz_stack:
538
mz_stack:
539
	lods	byte [esi]
539
	lods	byte [esi]
540
	cmp	al,'('
540
	cmp	al,'('
541
	jne	invalid_argument
541
	jne	invalid_argument
542
	call	get_word_value
542
	call	get_word_value
543
	cmp	byte [esi],':'
543
	cmp	byte [esi],':'
544
	je	stack_pointer
544
	je	stack_pointer
545
	cmp	ax,10h
545
	cmp	ax,10h
546
	jb	invalid_value
546
	jb	invalid_value
547
	cmp	[value_type],0
547
	cmp	[value_type],0
548
	jne	invalid_use_of_symbol
548
	jne	invalid_use_of_symbol
549
	mov	edx,[additional_memory]
549
	mov	edx,[additional_memory]
550
	mov	[edx+10h],ax
550
	mov	[edx+10h],ax
551
	jmp	instruction_assembled
551
	jmp	instruction_assembled
552
      stack_pointer:
552
      stack_pointer:
553
	cmp	[value_type],1
553
	cmp	[value_type],1
554
	je	initial_ss_ok
554
	je	initial_ss_ok
555
	cmp	[error_line],0
555
	cmp	[error_line],0
556
	jne	initial_ss_ok
556
	jne	initial_ss_ok
557
	mov	eax,[current_line]
557
	mov	eax,[current_line]
558
	mov	[error_line],eax
558
	mov	[error_line],eax
559
	mov	[error],invalid_address
559
	mov	[error],invalid_address
560
      initial_ss_ok:
560
      initial_ss_ok:
561
	mov	edx,[additional_memory]
561
	mov	edx,[additional_memory]
562
	mov	[edx+0Eh],ax
562
	mov	[edx+0Eh],ax
563
	lods	byte [esi]
563
	lods	byte [esi]
564
	cmp	al,':'
564
	cmp	al,':'
565
	jne	invalid_argument
565
	jne	invalid_argument
566
	lods	byte [esi]
566
	lods	byte [esi]
567
	cmp	al,'('
567
	cmp	al,'('
568
	jne	invalid_argument
568
	jne	invalid_argument
569
	call	get_word_value
569
	call	get_word_value
570
	cmp	[value_type],0
570
	cmp	[value_type],0
571
	jne	invalid_use_of_symbol
571
	jne	invalid_use_of_symbol
572
	mov	edx,[additional_memory]
572
	mov	edx,[additional_memory]
573
	mov	[edx+10h],ax
573
	mov	[edx+10h],ax
574
	bts	[format_flags],4
574
	bts	[format_flags],4
575
	jmp	instruction_assembled
575
	jmp	instruction_assembled
576
mz_heap:
576
mz_heap:
577
	cmp	[output_format],2
577
	cmp	[output_format],2
578
	jne	illegal_instruction
578
	jne	illegal_instruction
579
	lods	byte [esi]
579
	lods	byte [esi]
580
	call	get_size_operator
580
	call	get_size_operator
581
	cmp	ah,1
581
	cmp	ah,1
582
	je	invalid_value
582
	je	invalid_value
583
	cmp	ah,2
583
	cmp	ah,2
584
	ja	invalid_value
584
	ja	invalid_value
585
	cmp	al,'('
585
	cmp	al,'('
586
	jne	invalid_argument
586
	jne	invalid_argument
587
	call	get_word_value
587
	call	get_word_value
588
	cmp	[value_type],0
588
	cmp	[value_type],0
589
	jne	invalid_use_of_symbol
589
	jne	invalid_use_of_symbol
590
	mov	edx,[additional_memory]
590
	mov	edx,[additional_memory]
591
	mov	[edx+0Ch],ax
591
	mov	[edx+0Ch],ax
592
	jmp	instruction_assembled
592
	jmp	instruction_assembled
593
write_mz_header:
593
write_mz_header:
594
	mov	edx,[additional_memory]
594
	mov	edx,[additional_memory]
595
	bt	[format_flags],4
595
	bt	[format_flags],4
596
	jc	mz_stack_ok
596
	jc	mz_stack_ok
597
	mov	eax,[real_code_size]
597
	mov	eax,[real_code_size]
598
	dec	eax
598
	dec	eax
599
	shr	eax,4
599
	shr	eax,4
600
	inc	eax
600
	inc	eax
601
	mov	[edx+0Eh],ax
601
	mov	[edx+0Eh],ax
602
	shl	eax,4
602
	shl	eax,4
603
	movzx	ecx,word [edx+10h]
603
	movzx	ecx,word [edx+10h]
604
	add	eax,ecx
604
	add	eax,ecx
605
	mov	[real_code_size],eax
605
	mov	[real_code_size],eax
606
      mz_stack_ok:
606
      mz_stack_ok:
607
	mov	edi,[free_additional_memory]
607
	mov	edi,[free_additional_memory]
608
	mov	eax,[number_of_relocations]
608
	mov	eax,[number_of_relocations]
609
	shl	eax,2
609
	shl	eax,2
610
	add	eax,1Ch
610
	add	eax,1Ch
611
	sub	edi,eax
611
	sub	edi,eax
612
	xchg	edi,[free_additional_memory]
612
	xchg	edi,[free_additional_memory]
613
	mov	ecx,0Fh
613
	mov	ecx,0Fh
614
	add	eax,0Fh
614
	add	eax,0Fh
615
	and	eax,1111b
615
	and	eax,1111b
616
	sub	ecx,eax
616
	sub	ecx,eax
617
	xor	al,al
617
	xor	al,al
618
	rep	stos byte [edi]
618
	rep	stos byte [edi]
619
	sub	edi,[free_additional_memory]
619
	sub	edi,[free_additional_memory]
620
	mov	ecx,edi
620
	mov	ecx,edi
621
	shr	edi,4
621
	shr	edi,4
622
	mov	word [edx],'MZ' 	; signature
622
	mov	word [edx],'MZ' 	; signature
623
	mov	[edx+8],di		; header size in paragraphs
623
	mov	[edx+8],di		; header size in paragraphs
624
	mov	eax,[number_of_relocations]
624
	mov	eax,[number_of_relocations]
625
	mov	[edx+6],ax		; number of relocation entries
625
	mov	[edx+6],ax		; number of relocation entries
626
	mov	eax,[code_size]
626
	mov	eax,[code_size]
627
	add	eax,ecx
627
	add	eax,ecx
628
	mov	esi,eax
628
	mov	esi,eax
629
	shr	esi,9
629
	shr	esi,9
630
	and	eax,1FFh
630
	and	eax,1FFh
631
	inc	si
631
	inc	si
632
	or	ax,ax
632
	or	ax,ax
633
	jnz	mz_size_ok
633
	jnz	mz_size_ok
634
	dec	si
634
	dec	si
635
      mz_size_ok:
635
      mz_size_ok:
636
	mov	[edx+2],ax		; number of bytes in last page
636
	mov	[edx+2],ax		; number of bytes in last page
637
	mov	[edx+4],si		; number of pages
637
	mov	[edx+4],si		; number of pages
638
	mov	eax,[real_code_size]
638
	mov	eax,[real_code_size]
639
	dec	eax
639
	dec	eax
640
	shr	eax,4
640
	shr	eax,4
641
	inc	eax
641
	inc	eax
642
	mov	esi,[code_size]
642
	mov	esi,[code_size]
643
	dec	esi
643
	dec	esi
644
	shr	esi,4
644
	shr	esi,4
645
	inc	esi
645
	inc	esi
646
	sub	eax,esi
646
	sub	eax,esi
647
	mov	[edx+0Ah],ax		; minimum memory in addition to code
647
	mov	[edx+0Ah],ax		; minimum memory in addition to code
648
	add	[edx+0Ch],ax		; maximum memory in addition to code
648
	add	[edx+0Ch],ax		; maximum memory in addition to code
649
	salc
649
	salc
650
	mov	ah,al
650
	mov	ah,al
651
	or	[edx+0Ch],ax
651
	or	[edx+0Ch],ax
652
	mov	word [edx+18h],1Ch	; offset of relocation table
652
	mov	word [edx+18h],1Ch	; offset of relocation table
653
	add	[written_size],ecx
653
	add	[written_size],ecx
654
	call	write
654
	call	write
655
	jc	write_failed
655
	jc	write_failed
656
	ret
656
	ret
657
 
657
 
658
make_stub:
658
make_stub:
659
	mov	[stub_file],edx
659
	mov	[stub_file],edx
660
	or	edx,edx
660
	or	edx,edx
661
	jnz	stub_from_file
661
	jnz	stub_from_file
662
	push	esi
662
	push	esi
663
	mov	edx,edi
663
	mov	edx,edi
664
	xor	eax,eax
664
	xor	eax,eax
665
	mov	ecx,20h
665
	mov	ecx,20h
666
	rep	stos dword [edi]
666
	rep	stos dword [edi]
667
	mov	eax,40h+default_stub_end-default_stub
667
	mov	eax,40h+default_stub_end-default_stub
668
	mov	cx,100h+default_stub_end-default_stub
668
	mov	cx,100h+default_stub_end-default_stub
669
	mov	word [edx],'MZ'
669
	mov	word [edx],'MZ'
670
	mov	byte [edx+4],1
670
	mov	byte [edx+4],1
671
	mov	word [edx+2],ax
671
	mov	word [edx+2],ax
672
	mov	byte [edx+8],4
672
	mov	byte [edx+8],4
673
	mov	byte [edx+0Ah],10h
673
	mov	byte [edx+0Ah],10h
674
	mov	word [edx+0Ch],0FFFFh
674
	mov	word [edx+0Ch],0FFFFh
675
	mov	word [edx+10h],cx
675
	mov	word [edx+10h],cx
676
	mov	word [edx+3Ch],ax
676
	mov	word [edx+3Ch],ax
677
	mov	byte [edx+18h],40h
677
	mov	byte [edx+18h],40h
678
	lea	edi,[edx+40h]
678
	lea	edi,[edx+40h]
679
	mov	esi,default_stub
679
	mov	esi,default_stub
680
	mov	ecx,default_stub_end-default_stub
680
	mov	ecx,default_stub_end-default_stub
681
	rep	movs byte [edi],[esi]
681
	rep	movs byte [edi],[esi]
682
	pop	esi
682
	pop	esi
683
	jmp	stub_ok
683
	jmp	stub_ok
684
      default_stub:
684
      default_stub:
685
	use16
685
	use16
686
	push	cs
686
	push	cs
687
	pop	ds
687
	pop	ds
688
	mov	dx,stub_message-default_stub
688
	mov	dx,stub_message-default_stub
689
	mov	ah,9
689
	mov	ah,9
690
	int	21h
690
	int	21h
691
	mov	ax,4C01h
691
	mov	ax,4C01h
692
	int	21h
692
	int	21h
693
      stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h
693
      stub_message db 'This program cannot be run in DOS mode.',0Dh,0Ah,24h
694
	rq	1
694
	rq	1
695
      default_stub_end:
695
      default_stub_end:
696
	use32
696
	use32
697
      stub_from_file:
697
      stub_from_file:
698
	push	esi
698
	push	esi
699
	mov	esi,edx
699
	mov	esi,edx
700
	call	open_binary_file
700
	call	open_binary_file
701
	mov	edx,edi
701
	mov	edx,edi
702
	mov	ecx,1Ch
702
	mov	ecx,1Ch
703
	mov	esi,edx
703
	mov	esi,edx
704
	call	read
704
	call	read
705
	jc	binary_stub
705
	jc	binary_stub
706
	cmp	word [esi],'MZ'
706
	cmp	word [esi],'MZ'
707
	jne	binary_stub
707
	jne	binary_stub
708
	add	edi,1Ch
708
	add	edi,1Ch
709
	movzx	ecx,word [esi+6]
709
	movzx	ecx,word [esi+6]
710
	add	ecx,11b
710
	add	ecx,11b
711
	and	ecx,not 11b
711
	and	ecx,not 11b
712
	add	ecx,(40h-1Ch) shr 2
712
	add	ecx,(40h-1Ch) shr 2
713
	lea	eax,[edi+ecx*4]
713
	lea	eax,[edi+ecx*4]
714
	cmp	edi,[display_buffer]
714
	cmp	edi,[display_buffer]
715
	jae	out_of_memory
715
	jae	out_of_memory
716
	xor	eax,eax
716
	xor	eax,eax
717
	rep	stos dword [edi]
717
	rep	stos dword [edi]
718
	mov	edx,40h
718
	mov	edx,40h
719
	xchg	dx,[esi+18h]
719
	xchg	dx,[esi+18h]
720
	xor	al,al
720
	xor	al,al
721
	call	lseek
721
	call	lseek
722
	movzx	ecx,word [esi+6]
722
	movzx	ecx,word [esi+6]
723
	shl	ecx,2
723
	shl	ecx,2
724
	lea	edx,[esi+40h]
724
	lea	edx,[esi+40h]
725
	call	read
725
	call	read
726
	mov	edx,edi
726
	mov	edx,edi
727
	sub	edx,esi
727
	sub	edx,esi
728
	shr	edx,4
728
	shr	edx,4
729
	xchg	dx,[esi+8]
729
	xchg	dx,[esi+8]
730
	shl	edx,4
730
	shl	edx,4
731
	xor	al,al
731
	xor	al,al
732
	call	lseek
732
	call	lseek
733
	movzx	ecx,word [esi+4]
733
	movzx	ecx,word [esi+4]
734
	dec	ecx
734
	dec	ecx
735
	shl	ecx,9
735
	shl	ecx,9
736
	movzx	edx,word [esi+2]
736
	movzx	edx,word [esi+2]
737
	test	edx,edx
737
	test	edx,edx
738
	jnz	stub_header_size_ok
738
	jnz	stub_header_size_ok
739
	mov	dx,200h
739
	mov	dx,200h
740
     stub_header_size_ok:
740
     stub_header_size_ok:
741
	add	ecx,edx
741
	add	ecx,edx
742
	mov	edx,edi
742
	mov	edx,edi
743
	sub	ecx,eax
743
	sub	ecx,eax
744
	je	read_stub_code
744
	je	read_stub_code
745
	jb	stub_code_ok
745
	jb	stub_code_ok
746
	push	ecx
746
	push	ecx
747
	dec	ecx
747
	dec	ecx
748
	shr	ecx,3
748
	shr	ecx,3
749
	inc	ecx
749
	inc	ecx
750
	shl	ecx,1
750
	shl	ecx,1
751
	lea	eax,[edi+ecx*4]
751
	lea	eax,[edi+ecx*4]
752
	cmp	eax,[display_buffer]
752
	cmp	eax,[display_buffer]
753
	jae	out_of_memory
753
	jae	out_of_memory
754
	xor	eax,eax
754
	xor	eax,eax
755
	rep	stos dword [edi]
755
	rep	stos dword [edi]
756
	pop	ecx
756
	pop	ecx
757
     read_stub_code:
757
     read_stub_code:
758
	call	read
758
	call	read
759
     stub_code_ok:
759
     stub_code_ok:
760
	call	close
760
	call	close
761
	mov	edx,edi
761
	mov	edx,edi
762
	sub	edx,esi
762
	sub	edx,esi
763
	mov	ax,dx
763
	mov	ax,dx
764
	and	ax,1FFh
764
	and	ax,1FFh
765
	mov	[esi+2],ax
765
	mov	[esi+2],ax
766
	dec	edx
766
	dec	edx
767
	shr	edx,9
767
	shr	edx,9
768
	inc	edx
768
	inc	edx
769
	mov	[esi+4],dx
769
	mov	[esi+4],dx
770
	mov	eax,edi
770
	mov	eax,edi
771
	sub	eax,esi
771
	sub	eax,esi
772
	mov	[esi+3Ch],eax
772
	mov	[esi+3Ch],eax
773
	pop	esi
773
	pop	esi
774
      stub_ok:
774
      stub_ok:
775
	ret
775
	ret
776
      binary_stub:
776
      binary_stub:
777
	mov	esi,edi
777
	mov	esi,edi
778
	mov	ecx,40h shr 2
778
	mov	ecx,40h shr 2
779
	xor	eax,eax
779
	xor	eax,eax
780
	rep	stos dword [edi]
780
	rep	stos dword [edi]
781
	mov	al,2
781
	mov	al,2
782
	xor	edx,edx
782
	xor	edx,edx
783
	call	lseek
783
	call	lseek
784
	push	eax
784
	push	eax
785
	xor	al,al
785
	xor	al,al
786
	xor	edx,edx
786
	xor	edx,edx
787
	call	lseek
787
	call	lseek
788
	mov	ecx,[esp]
788
	mov	ecx,[esp]
789
	add	ecx,40h+111b
789
	add	ecx,40h+111b
790
	and	ecx,not 111b
790
	and	ecx,not 111b
791
	mov	ax,cx
791
	mov	ax,cx
792
	and	ax,1FFh
792
	and	ax,1FFh
793
	mov	[esi+2],ax
793
	mov	[esi+2],ax
794
	lea	eax,[ecx+1FFh]
794
	lea	eax,[ecx+1FFh]
795
	shr	eax,9
795
	shr	eax,9
796
	mov	[esi+4],ax
796
	mov	[esi+4],ax
797
	mov	[esi+3Ch],ecx
797
	mov	[esi+3Ch],ecx
798
	sub	ecx,40h
798
	sub	ecx,40h
799
	mov	eax,10000h
799
	mov	eax,10000h
800
	sub	eax,ecx
800
	sub	eax,ecx
801
	jbe	binary_heap_ok
801
	jbe	binary_heap_ok
802
	shr	eax,4
802
	shr	eax,4
803
	mov	[esi+0Ah],ax
803
	mov	[esi+0Ah],ax
804
      binary_heap_ok:
804
      binary_heap_ok:
805
	mov	word [esi],'MZ'
805
	mov	word [esi],'MZ'
806
	mov	byte [esi+8],4
806
	mov	byte [esi+8],4
807
	mov	ax,0FFFFh
807
	mov	ax,0FFFFh
808
	mov	[esi+0Ch],ax
808
	mov	[esi+0Ch],ax
809
	dec	ax
809
	dec	ax
810
	mov	[esi+10h],ax
810
	mov	[esi+10h],ax
811
	sub	ax,0Eh
811
	sub	ax,0Eh
812
	mov	[esi+0Eh],ax
812
	mov	[esi+0Eh],ax
813
	mov	[esi+16h],ax
813
	mov	[esi+16h],ax
814
	mov	word [esi+14h],100h
814
	mov	word [esi+14h],100h
815
	mov	byte [esi+18h],40h
815
	mov	byte [esi+18h],40h
816
	mov	eax,[display_buffer]
816
	mov	eax,[display_buffer]
817
	sub	eax,ecx
817
	sub	eax,ecx
818
	cmp	edi,eax
818
	cmp	edi,eax
819
	jae	out_of_memory
819
	jae	out_of_memory
820
	mov	edx,edi
820
	mov	edx,edi
821
	shr	ecx,2
821
	shr	ecx,2
822
	xor	eax,eax
822
	xor	eax,eax
823
	rep	stos dword [edi]
823
	rep	stos dword [edi]
824
	pop	ecx
824
	pop	ecx
825
	call	read
825
	call	read
826
	call	close
826
	call	close
827
	pop	esi
827
	pop	esi
828
	ret
828
	ret
829
 
829
 
830
format_pe:
830
format_pe:
831
	xor	edx,edx
831
	xor	edx,edx
832
	mov	[machine],14Ch
832
	mov	[machine],14Ch
833
	mov	[subsystem],3
833
	mov	[subsystem],3
834
	mov	[subsystem_version],3 + 10 shl 16
834
	mov	[subsystem_version],3 + 10 shl 16
835
	mov	[image_base],400000h
835
	mov	[image_base],400000h
836
	test	[format_flags],8
836
	mov	[image_base_high],0
-
 
837
	test	[format_flags],8
837
	jz	pe_settings
838
	jz	pe_settings
838
	mov	[machine],8664h
839
	mov	[machine],8664h
839
	mov	[subsystem_version],5 + 0 shl 16
840
	mov	[subsystem_version],5 + 0 shl 16
840
	mov	[image_base_high],0
841
      pe_settings:
841
      pe_settings:
-
 
842
	cmp	byte [esi],84h
842
	cmp	byte [esi],84h
843
	je	get_stub_name
843
	je	get_stub_name
844
	cmp	byte [esi],80h
844
	cmp	byte [esi],80h
845
	je	get_pe_base
845
	je	get_pe_base
846
	cmp	byte [esi],1Bh
846
	cmp	byte [esi],1Bh
847
	jne	pe_settings_ok
847
	jne	pe_settings_ok
848
	lods	byte [esi]
848
	lods	byte [esi]
849
	lods	byte [esi]
849
	lods	byte [esi]
850
	test	al,80h+40h
850
	test	al,80h+40h
851
	jz	subsystem_setting
851
	jz	subsystem_setting
852
	cmp	al,80h
852
	cmp	al,80h
853
	je	dll_flag
853
	je	dll_flag
854
	cmp	al,81h
854
	cmp	al,81h
855
	je	wdm_flag
855
	je	wdm_flag
856
	jmp	pe_settings
856
	cmp	al,82h
-
 
857
	je	large_flag
-
 
858
	cmp	al,83h
-
 
859
	je	nx_flag
-
 
860
	jmp	pe_settings
857
      dll_flag:
861
      dll_flag:
858
	bts	[format_flags],8
862
	bts	[format_flags],8
859
	jc	setting_already_specified
863
	jc	setting_already_specified
860
	jmp	pe_settings
864
	jmp	pe_settings
861
      wdm_flag:
865
      wdm_flag:
862
	bts	[format_flags],9
866
	bts	[format_flags],9
863
	jc	setting_already_specified
867
	jc	setting_already_specified
864
	jmp	pe_settings
868
	jmp	pe_settings
865
      subsystem_setting:
869
      large_flag:
-
 
870
	bts	[format_flags],11
-
 
871
	jc	setting_already_specified
-
 
872
	test	[format_flags],8
-
 
873
	jnz	invalid_argument
-
 
874
	jmp	pe_settings
-
 
875
      nx_flag:
-
 
876
	bts	[format_flags],12
-
 
877
	jc	setting_already_specified
-
 
878
	jmp	pe_settings
-
 
879
      subsystem_setting:
866
	bts	[format_flags],7
880
	bts	[format_flags],7
867
	jc	setting_already_specified
881
	jc	setting_already_specified
868
	and	ax,3Fh
882
	and	ax,3Fh
869
	mov	[subsystem],ax
883
	mov	[subsystem],ax
870
	cmp	ax,10
884
	cmp	ax,10
871
	jb	subsystem_type_ok
885
	jb	subsystem_type_ok
872
	or	[format_flags],8
886
	or	[format_flags],4
873
      subsystem_type_ok:
887
      subsystem_type_ok:
874
	cmp	byte [esi],'('
888
	cmp	byte [esi],'('
875
	jne	pe_settings
889
	jne	pe_settings
876
	inc	esi
890
	inc	esi
877
	cmp	byte [esi],'.'
891
	cmp	byte [esi],'.'
878
	jne	invalid_value
892
	jne	invalid_value
879
	inc	esi
893
	inc	esi
880
	push	edx
894
	push	edx
881
	cmp	byte [esi+11],0
895
	cmp	byte [esi+11],0
882
	jne	invalid_value
896
	jne	invalid_value
883
	cmp	byte [esi+10],2
897
	cmp	byte [esi+10],2
884
	ja	invalid_value
898
	ja	invalid_value
885
	mov	dx,[esi+8]
899
	mov	dx,[esi+8]
886
	cmp	dx,8000h
900
	cmp	dx,8000h
887
	je	zero_version
901
	je	zero_version
888
	mov	eax,[esi+4]
902
	mov	eax,[esi+4]
889
	cmp	dx,7
903
	cmp	dx,7
890
	jg	invalid_value
904
	jg	invalid_value
891
	mov	cx,7
905
	mov	cx,7
892
	sub	cx,dx
906
	sub	cx,dx
893
	mov	eax,[esi+4]
907
	mov	eax,[esi+4]
894
	shr	eax,cl
908
	shr	eax,cl
895
	mov	ebx,eax
909
	mov	ebx,eax
896
	shr	ebx,24
910
	shr	ebx,24
897
	cmp	bl,100
911
	cmp	bl,100
898
	jae	invalid_value
912
	jae	invalid_value
899
	and	eax,0FFFFFFh
913
	and	eax,0FFFFFFh
900
	mov	ecx,100
914
	mov	ecx,100
901
	mul	ecx
915
	mul	ecx
902
	shrd	eax,edx,24
916
	shrd	eax,edx,24
903
	jnc	version_value_ok
917
	jnc	version_value_ok
904
	inc	eax
918
	inc	eax
905
      version_value_ok:
919
      version_value_ok:
906
	shl	eax,16
920
	shl	eax,16
907
	mov	ax,bx
921
	mov	ax,bx
908
	jmp	subsystem_version_ok
922
	jmp	subsystem_version_ok
909
      zero_version:
923
      zero_version:
910
	xor	eax,eax
924
	xor	eax,eax
911
      subsystem_version_ok:
925
      subsystem_version_ok:
912
	pop	edx
926
	pop	edx
913
	add	esi,13
927
	add	esi,13
914
	mov	[subsystem_version],eax
928
	mov	[subsystem_version],eax
915
	jmp	pe_settings
929
	jmp	pe_settings
916
      get_pe_base:
930
      get_pe_base:
917
	bts	[format_flags],10
931
	bts	[format_flags],10
918
	jc	setting_already_specified
932
	jc	setting_already_specified
919
	lods	word [esi]
933
	lods	word [esi]
920
	cmp	ah,'('
934
	cmp	ah,'('
921
	jne	invalid_argument
935
	jne	invalid_argument
922
	cmp	byte [esi],'.'
936
	cmp	byte [esi],'.'
923
	je	invalid_value
937
	je	invalid_value
924
	push	edx edi
938
	push	edx edi
925
	add	edi,[stub_size]
939
	add	edi,[stub_size]
926
	test	[format_flags],8
940
	test	[format_flags],4
927
	jnz	get_peplus_base
941
	jnz	get_peplus_base
928
	call	get_dword_value
942
	call	get_dword_value
929
	mov	[image_base],eax
943
	mov	[image_base],eax
930
	jmp	pe_base_ok
944
	jmp	pe_base_ok
931
      get_peplus_base:
945
      get_peplus_base:
932
	call	get_qword_value
946
	call	get_qword_value
933
	mov	[image_base],eax
947
	mov	[image_base],eax
934
	mov	[image_base_high],edx
948
	mov	[image_base_high],edx
935
      pe_base_ok:
949
      pe_base_ok:
936
	pop	edi edx
950
	pop	edi edx
937
	cmp	[value_type],0
951
	cmp	[value_type],0
938
	jne	invalid_use_of_symbol
952
	jne	invalid_use_of_symbol
939
	cmp	byte [esi],84h
953
	cmp	byte [esi],84h
940
	jne	pe_settings_ok
954
	jne	pe_settings_ok
941
      get_stub_name:
955
      get_stub_name:
942
	lods	byte [esi]
956
	lods	byte [esi]
943
	lods	word [esi]
957
	lods	word [esi]
944
	cmp	ax,'('
958
	cmp	ax,'('
945
	jne	invalid_argument
959
	jne	invalid_argument
946
	lods	dword [esi]
960
	lods	dword [esi]
947
	mov	edx,esi
961
	mov	edx,esi
948
	add	esi,eax
962
	add	esi,eax
949
	inc	esi
963
	inc	esi
950
      pe_settings_ok:
964
      pe_settings_ok:
951
	mov	ebp,[stub_size]
965
	mov	ebp,[stub_size]
952
	or	ebp,ebp
966
	or	ebp,ebp
953
	jz	make_pe_stub
967
	jz	make_pe_stub
954
	cmp	edx,[stub_file]
968
	cmp	edx,[stub_file]
955
	je	pe_stub_ok
969
	je	pe_stub_ok
956
	sub	edi,[stub_size]
970
	sub	edi,[stub_size]
957
	mov	[code_start],edi
971
	mov	[code_start],edi
958
      make_pe_stub:
972
      make_pe_stub:
959
	call	make_stub
973
	call	make_stub
960
	mov	eax,edi
974
	mov	eax,edi
961
	sub	eax,[code_start]
975
	sub	eax,[code_start]
962
	mov	[stub_size],eax
976
	mov	[stub_size],eax
963
	mov	[code_start],edi
977
	mov	[code_start],edi
964
	mov	ebp,eax
978
	mov	ebp,eax
965
      pe_stub_ok:
979
      pe_stub_ok:
966
	mov	edx,edi
980
	mov	edx,edi
967
	mov	ecx,18h+0E0h
981
	mov	ecx,18h+0E0h
968
	test	[format_flags],8
982
	test	[format_flags],4
969
	jz	zero_pe_header
983
	jz	zero_pe_header
970
	add	ecx,10h
984
	add	ecx,10h
971
      zero_pe_header:
985
      zero_pe_header:
972
	add	ebp,ecx
986
	add	ebp,ecx
973
	shr	ecx,2
987
	shr	ecx,2
974
	xor	eax,eax
988
	xor	eax,eax
975
	rep	stos dword [edi]
989
	rep	stos dword [edi]
976
	mov	word [edx],'PE' 	; signature
990
	mov	word [edx],'PE' 	; signature
977
	mov	ax,[machine]
991
	mov	ax,[machine]
978
	mov	word [edx+4],ax
992
	mov	word [edx+4],ax
979
	mov	byte [edx+38h+1],10h	; section alignment
993
	mov	byte [edx+38h+1],10h	; section alignment
980
	mov	byte [edx+3Ch+1],2	; file alignment
994
	mov	byte [edx+3Ch+1],2	; file alignment
981
	mov	byte [edx+40h],1	; OS version
995
	mov	byte [edx+40h],1	; OS version
982
	mov	eax,[subsystem_version]
996
	mov	eax,[subsystem_version]
983
	mov	[edx+48h],eax
997
	mov	[edx+48h],eax
984
	mov	ax,[subsystem]
998
	mov	ax,[subsystem]
985
	mov	[edx+5Ch],ax
999
	mov	[edx+5Ch],ax
986
	cmp	ax,1
1000
	cmp	ax,1
987
	jne	pe_alignment_ok
1001
	jne	pe_alignment_ok
988
	mov	eax,20h
1002
	mov	eax,20h
989
	mov	dword [edx+38h],eax
1003
	mov	dword [edx+38h],eax
990
	mov	dword [edx+3Ch],eax
1004
	mov	dword [edx+3Ch],eax
991
      pe_alignment_ok:
1005
      pe_alignment_ok:
992
	mov	word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
1006
	mov	word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
993
	test	[format_flags],8
1007
	test	[format_flags],4
994
	jnz	init_peplus_specific
1008
	jnz	init_peplus_specific
995
	mov	byte [edx+14h],0E0h	; size of optional header
1009
	mov	byte [edx+14h],0E0h	; size of optional header
996
	mov	dword [edx+16h],10B010Eh; flags and magic value
1010
	mov	dword [edx+16h],10B010Fh; flags and magic value
997
	mov	eax,[image_base]
1011
	mov	eax,[image_base]
998
	mov	[edx+34h],eax
1012
	mov	[edx+34h],eax
999
	mov	byte [edx+60h+1],10h	; stack reserve
1013
	mov	byte [edx+60h+1],10h	; stack reserve
1000
	mov	byte [edx+64h+1],10h	; stack commit
1014
	mov	byte [edx+64h+1],10h	; stack commit
1001
	mov	byte [edx+68h+2],1	; heap reserve
1015
	mov	byte [edx+68h+2],1	; heap reserve
1002
	mov	byte [edx+74h],16	; number of directories
1016
	mov	byte [edx+74h],16	; number of directories
1003
	jmp	pe_header_ok
1017
	jmp	pe_header_ok
1004
      init_peplus_specific:
1018
      init_peplus_specific:
1005
	mov	byte [edx+14h],0F0h	; size of optional header
1019
	mov	byte [edx+14h],0F0h	; size of optional header
1006
	mov	dword [edx+16h],20B002Eh; flags and magic value
1020
	mov	dword [edx+16h],20B002Fh; flags and magic value
1007
	mov	eax,[image_base]
1021
	mov	eax,[image_base]
1008
	mov	[edx+30h],eax
1022
	mov	[edx+30h],eax
1009
	mov	eax,[image_base_high]
1023
	mov	eax,[image_base_high]
1010
	mov	[edx+34h],eax
1024
	mov	[edx+34h],eax
1011
	mov	byte [edx+60h+1],10h	; stack reserve
1025
	mov	byte [edx+60h+1],10h	; stack reserve
1012
	mov	byte [edx+68h+1],10h	; stack commit
1026
	mov	byte [edx+68h+1],10h	; stack commit
1013
	mov	byte [edx+70h+2],1	; heap reserve
1027
	mov	byte [edx+70h+2],1	; heap reserve
1014
	mov	byte [edx+84h],16	; number of directories
1028
	mov	byte [edx+84h],16	; number of directories
1015
      pe_header_ok:
1029
      pe_header_ok:
1016
	bsf	ecx,[edx+3Ch]
1030
	bsf	ecx,[edx+3Ch]
1017
	imul	ebx,[number_of_sections],28h
1031
	imul	ebx,[number_of_sections],28h
1018
	or	ebx,ebx
1032
	or	ebx,ebx
1019
	jnz	reserve_space_for_section_headers
1033
	jnz	reserve_space_for_section_headers
1020
	mov	ebx,28h
1034
	mov	ebx,28h
1021
      reserve_space_for_section_headers:
1035
      reserve_space_for_section_headers:
1022
	add	ebx,ebp
1036
	add	ebx,ebp
1023
	dec	ebx
1037
	dec	ebx
1024
	shr	ebx,cl
1038
	shr	ebx,cl
1025
	inc	ebx
1039
	inc	ebx
1026
	shl	ebx,cl
1040
	shl	ebx,cl
1027
	sub	ebx,ebp
1041
	sub	ebx,ebp
1028
	mov	ecx,ebx
1042
	mov	ecx,ebx
1029
	mov	eax,[display_buffer]
1043
	mov	eax,[display_buffer]
1030
	sub	eax,ecx
1044
	sub	eax,ecx
1031
	cmp	edi,eax
1045
	cmp	edi,eax
1032
	jae	out_of_memory
1046
	jae	out_of_memory
1033
	shr	ecx,2
1047
	shr	ecx,2
1034
	xor	eax,eax
1048
	xor	eax,eax
1035
	rep	stos dword [edi]
1049
	rep	stos dword [edi]
1036
	mov	eax,edi
1050
	mov	eax,edi
1037
	sub	eax,[code_start]
1051
	sub	eax,[code_start]
1038
	add	eax,[stub_size]
1052
	add	eax,[stub_size]
1039
	mov	[edx+54h],eax		; size of headers
1053
	mov	[edx+54h],eax		; size of headers
1040
	mov	ecx,[edx+38h]
1054
	mov	ecx,[edx+38h]
1041
	dec	ecx
1055
	dec	ecx
1042
	add	eax,ecx
1056
	add	eax,ecx
1043
	not	ecx
1057
	not	ecx
1044
	and	eax,ecx
1058
	and	eax,ecx
1045
	bt	[format_flags],8
1059
	bt	[format_flags],8
1046
	jc	pe_entry_init_ok
1060
	jc	pe_entry_init_ok
1047
	mov	[edx+28h],eax		; entry point rva
1061
	mov	[edx+28h],eax		; entry point rva
1048
      pe_entry_init_ok:
1062
      pe_entry_init_ok:
1049
	mov	[number_of_sections],0
1063
	mov	[number_of_sections],0
1050
	movzx	ebx,word [edx+14h]
1064
	movzx	ebx,word [edx+14h]
1051
	lea	ebx,[edx+18h+ebx]
1065
	lea	ebx,[edx+18h+ebx]
1052
	mov	[current_section],ebx
1066
	mov	[current_section],ebx
1053
	mov	dword [ebx],'.fla'
1067
	mov	dword [ebx],'.fla'
1054
	mov	dword [ebx+4],'t'
1068
	mov	dword [ebx+4],'t'
1055
	mov	[ebx+14h],edi
1069
	mov	[ebx+14h],edi
1056
	mov	[ebx+0Ch],eax
1070
	mov	[ebx+0Ch],eax
1057
	mov	dword [ebx+24h],0E0000060h
1071
	mov	dword [ebx+24h],0E0000060h
1058
	xor	ecx,ecx
1072
	xor	ecx,ecx
1059
	not	eax
1073
	not	eax
1060
	not	ecx
1074
	not	ecx
1061
	add	eax,1
1075
	add	eax,1
1062
	adc	ecx,0
1076
	adc	ecx,0
1063
	add	eax,edi
1077
	add	eax,edi
1064
	adc	ecx,0
1078
	adc	ecx,0
1065
	test	[format_flags],8
1079
	test	[format_flags],4
1066
	jnz	peplus_org
1080
	jnz	peplus_org
1067
	sub	eax,[edx+34h]
1081
	sub	eax,[edx+34h]
1068
	sbb	ecx,0
1082
	sbb	ecx,0
1069
	mov	bl,2
1083
	jmp	pe_org_ok
1070
	mov	[code_type],32
-
 
1071
	jmp	pe_org_ok
-
 
1072
      peplus_org:
1084
      peplus_org:
1073
	sub	eax,[edx+30h]
1085
	sub	eax,[edx+30h]
1074
	sbb	ecx,[edx+34h]
1086
	sbb	ecx,[edx+34h]
1075
	mov	bl,4
1087
      pe_org_ok:
-
 
1088
	test	[format_flags],8
-
 
1089
	jnz	pe64_code
-
 
1090
	mov	bl,2
-
 
1091
	mov	[code_type],32
-
 
1092
	jmp	pe_code_type_ok
-
 
1093
      pe64_code:
-
 
1094
	mov	bl,4
1076
	mov	[code_type],64
1095
	mov	[code_type],64
1077
      pe_org_ok:
1096
      pe_code_type_ok:
1078
	bt	[resolver_flags],0
1097
	bt	[resolver_flags],0
1079
	jc	pe_labels_type_ok
1098
	jc	pe_labels_type_ok
1080
	xor	bl,bl
1099
	xor	bl,bl
1081
      pe_labels_type_ok:
1100
      pe_labels_type_ok:
1082
	mov	[labels_type],bl
1101
	mov	[labels_type],bl
1083
	mov	dword [org_origin],eax
1102
	mov	dword [org_origin],eax
1084
	mov	dword [org_origin+4],ecx
1103
	mov	dword [org_origin+4],ecx
1085
	mov	[org_registers],0
1104
	mov	[org_registers],0
1086
	mov	[org_start],edi
1105
	mov	[org_start],edi
1087
	bt	[format_flags],8
1106
	bt	[format_flags],8
1088
	jnc	dll_flag_ok
1107
	jnc	dll_flag_ok
1089
	or	byte [edx+16h+1],20h
1108
	or	byte [edx+16h+1],20h
1090
      dll_flag_ok:
1109
      dll_flag_ok:
1091
	bt	[format_flags],9
1110
	bt	[format_flags],9
1092
	jnc	wdm_flag_ok
1111
	jnc	wdm_flag_ok
1093
	or	byte [edx+5Eh+1],20h
1112
	or	byte [edx+5Eh+1],20h
1094
      wdm_flag_ok:
1113
      wdm_flag_ok:
1095
	jmp	format_defined
1114
	bt	[format_flags],11
-
 
1115
	jnc	large_flag_ok
-
 
1116
	or	byte [edx+16h],20h
-
 
1117
      large_flag_ok:
-
 
1118
	bt	[format_flags],12
-
 
1119
	jnc	nx_ok
-
 
1120
	or	byte [edx+5Eh+1],1
-
 
1121
      nx_ok:
-
 
1122
	jmp	format_defined
1096
pe_section:
1123
pe_section:
1097
	call	close_pe_section
1124
	call	close_pe_section
1098
	bts	[format_flags],5
1125
	bts	[format_flags],5
1099
	lea	ecx,[ebx+28h]
1126
	lea	ecx,[ebx+28h]
1100
	add	edx,[edx+54h]
1127
	add	edx,[edx+54h]
1101
	sub	edx,[stub_size]
1128
	sub	edx,[stub_size]
1102
	cmp	ecx,edx
1129
	cmp	ecx,edx
1103
	jbe	new_section
1130
	jbe	new_section
1104
	lea	ebx,[edx-28h]
1131
	lea	ebx,[edx-28h]
1105
	or	[next_pass_needed],-1
1132
	or	[next_pass_needed],-1
1106
	push	edi
1133
	push	edi
1107
	mov	edi,ebx
1134
	mov	edi,ebx
1108
	mov	ecx,28h shr 4
1135
	mov	ecx,28h shr 4
1109
	xor	eax,eax
1136
	xor	eax,eax
1110
	rep	stos dword [edi]
1137
	rep	stos dword [edi]
1111
	pop	edi
1138
	pop	edi
1112
      new_section:
1139
      new_section:
1113
	mov	[ebx+0Ch],eax
1140
	mov	[ebx+0Ch],eax
1114
	lods	word [esi]
1141
	lods	word [esi]
1115
	cmp	ax,'('
1142
	cmp	ax,'('
1116
	jne	invalid_argument
1143
	jne	invalid_argument
1117
	lea	edx,[esi+4]
1144
	lea	edx,[esi+4]
1118
	mov	ecx,[esi]
1145
	mov	ecx,[esi]
1119
	lea	esi,[esi+4+ecx+1]
1146
	lea	esi,[esi+4+ecx+1]
1120
	cmp	ecx,8
1147
	cmp	ecx,8
1121
	ja	name_too_long
1148
	ja	name_too_long
1122
	xor	eax,eax
1149
	xor	eax,eax
1123
	mov	[ebx],eax
1150
	mov	[ebx],eax
1124
	mov	[ebx+4],eax
1151
	mov	[ebx+4],eax
1125
	push	esi edi
1152
	push	esi edi
1126
	mov	edi,ebx
1153
	mov	edi,ebx
1127
	mov	esi,edx
1154
	mov	esi,edx
1128
	rep	movs byte [edi],[esi]
1155
	rep	movs byte [edi],[esi]
1129
	pop	edi esi
1156
	pop	edi esi
1130
	mov	dword [ebx+24h],0
1157
	mov	dword [ebx+24h],0
1131
	mov	[ebx+14h],edi
1158
	mov	[ebx+14h],edi
1132
	mov	edx,[code_start]
1159
	mov	edx,[code_start]
1133
	mov	eax,edi
1160
	mov	eax,edi
1134
	xor	ecx,ecx
1161
	xor	ecx,ecx
1135
	sub	eax,[ebx+0Ch]
1162
	sub	eax,[ebx+0Ch]
1136
	sbb	ecx,0
1163
	sbb	ecx,0
1137
	test	[format_flags],8
1164
	mov	[labels_type],2
-
 
1165
	mov	[code_type],32
-
 
1166
	test	[format_flags],8
1138
	jnz	peplus_section_org
1167
	jz	pe_section_code_type_ok
-
 
1168
	mov	[labels_type],4
-
 
1169
	mov	[code_type],64
-
 
1170
      pe_section_code_type_ok:
-
 
1171
	test	[format_flags],4
-
 
1172
	jnz	peplus_section_org
1139
	sub	eax,[edx+34h]
1173
	sub	eax,[edx+34h]
1140
	sbb	ecx,0
1174
	sbb	ecx,0
1141
	mov	[labels_type],2
1175
	bt	[resolver_flags],0
1142
	mov	[code_type],32
-
 
1143
	bt	[resolver_flags],0
-
 
1144
	jc	pe_section_org_ok
1176
	jc	pe_section_org_ok
1145
	mov	[labels_type],0
1177
	mov	[labels_type],0
1146
	jmp	pe_section_org_ok
1178
	jmp	pe_section_org_ok
1147
      peplus_section_org:
1179
      peplus_section_org:
1148
	sub	eax,[edx+30h]
1180
	sub	eax,[edx+30h]
1149
	sbb	ecx,[edx+34h]
1181
	sbb	ecx,[edx+34h]
1150
	mov	[labels_type],4
1182
	bt	[resolver_flags],0
1151
	mov	[code_type],64
-
 
1152
	bt	[resolver_flags],0
-
 
1153
	jc	pe_section_org_ok
1183
	jc	pe_section_org_ok
1154
	mov	[labels_type],0
1184
	mov	[labels_type],0
1155
      pe_section_org_ok:
1185
      pe_section_org_ok:
1156
	mov	dword [org_origin],eax
1186
	mov	dword [org_origin],eax
1157
	mov	dword [org_origin+4],ecx
1187
	mov	dword [org_origin+4],ecx
1158
	mov	[org_registers],0
1188
	mov	[org_registers],0
1159
	mov	[org_start],edi
1189
	mov	[org_start],edi
1160
      get_section_flags:
1190
      get_section_flags:
1161
	lods	byte [esi]
1191
	lods	byte [esi]
1162
	cmp	al,1Ah
1192
	cmp	al,1Ah
1163
	je	set_directory
1193
	je	set_directory
1164
	cmp	al,19h
1194
	cmp	al,19h
1165
	je	section_flag
1195
	je	section_flag
1166
	dec	esi
1196
	dec	esi
1167
	jmp	instruction_assembled
1197
	jmp	instruction_assembled
1168
      set_directory:
1198
      set_directory:
1169
	movzx	eax,byte [esi]
1199
	movzx	eax,byte [esi]
1170
	inc	esi
1200
	inc	esi
1171
	mov	ecx,ebx
1201
	mov	ecx,ebx
1172
	test	[format_flags],8
1202
	test	[format_flags],4
1173
	jnz	peplus_directory
1203
	jnz	peplus_directory
1174
	xchg	ecx,[edx+78h+eax*8]
1204
	xchg	ecx,[edx+78h+eax*8]
1175
	mov	dword [edx+78h+eax*8+4],-1
1205
	mov	dword [edx+78h+eax*8+4],-1
1176
	jmp	pe_directory_set
1206
	jmp	pe_directory_set
1177
      peplus_directory:
1207
      peplus_directory:
1178
	xchg	ecx,[edx+88h+eax*8]
1208
	xchg	ecx,[edx+88h+eax*8]
1179
	mov	dword [edx+88h+eax*8+4],-1
1209
	mov	dword [edx+88h+eax*8+4],-1
1180
      pe_directory_set:
1210
      pe_directory_set:
1181
	or	ecx,ecx
1211
	or	ecx,ecx
1182
	jnz	data_already_defined
1212
	jnz	data_already_defined
1183
	push	ebx edx
1213
	push	ebx edx
1184
	call	generate_pe_data
1214
	call	generate_pe_data
1185
	pop	edx ebx
1215
	pop	edx ebx
1186
	jmp	get_section_flags
1216
	jmp	get_section_flags
1187
      section_flag:
1217
      section_flag:
1188
	lods	byte [esi]
1218
	lods	byte [esi]
1189
	cmp	al,9
1219
	cmp	al,9
1190
	je	invalid_argument
1220
	je	invalid_argument
1191
	cmp	al,11
1221
	cmp	al,11
1192
	je	invalid_argument
1222
	je	invalid_argument
1193
	mov	cl,al
1223
	mov	cl,al
1194
	mov	eax,1
1224
	mov	eax,1
1195
	shl	eax,cl
1225
	shl	eax,cl
1196
	test	dword [ebx+24h],eax
1226
	test	dword [ebx+24h],eax
1197
	jnz	setting_already_specified
1227
	jnz	setting_already_specified
1198
	or	dword [ebx+24h],eax
1228
	or	dword [ebx+24h],eax
1199
	jmp	get_section_flags
1229
	jmp	get_section_flags
1200
      close_pe_section:
1230
      close_pe_section:
1201
	mov	ebx,[current_section]
1231
	mov	ebx,[current_section]
1202
	mov	edx,[code_start]
1232
	mov	edx,[code_start]
1203
	mov	eax,edi
1233
	mov	eax,edi
1204
	sub	eax,[ebx+14h]
1234
	sub	eax,[ebx+14h]
1205
	jnz	finish_section
1235
	jnz	finish_section
1206
	bt	[format_flags],5
1236
	bt	[format_flags],5
1207
	jc	finish_section
1237
	jc	finish_section
1208
	mov	eax,[ebx+0Ch]
1238
	mov	eax,[ebx+0Ch]
1209
	ret
1239
	ret
1210
      finish_section:
1240
      finish_section:
1211
	mov	[ebx+8],eax
1241
	mov	[ebx+8],eax
1212
	cmp	edi,[undefined_data_end]
1242
	cmp	edi,[undefined_data_end]
1213
	jne	align_section
1243
	jne	align_section
1214
	cmp	dword [edx+38h],1000h
1244
	cmp	dword [edx+38h],1000h
1215
	jb	align_section
1245
	jb	align_section
1216
	mov	edi,[undefined_data_start]
1246
	mov	edi,[undefined_data_start]
1217
      align_section:
1247
      align_section:
1218
	mov	[undefined_data_end],0
1248
	mov	[undefined_data_end],0
1219
	mov	ebp,edi
1249
	mov	ebp,edi
1220
	sub	ebp,[ebx+14h]
1250
	sub	ebp,[ebx+14h]
1221
	mov	ecx,[edx+3Ch]
1251
	mov	ecx,[edx+3Ch]
1222
	dec	ecx
1252
	dec	ecx
1223
	lea	eax,[ebp+ecx]
1253
	lea	eax,[ebp+ecx]
1224
	not	ecx
1254
	not	ecx
1225
	and	eax,ecx
1255
	and	eax,ecx
1226
	mov	[ebx+10h],eax
1256
	mov	[ebx+10h],eax
1227
	sub	eax,ebp
1257
	sub	eax,ebp
1228
	mov	ecx,eax
1258
	mov	ecx,eax
1229
	xor	al,al
1259
	xor	al,al
1230
	rep	stos byte [edi]
1260
	rep	stos byte [edi]
1231
	mov	eax,[code_start]
1261
	mov	eax,[code_start]
1232
	sub	eax,[stub_size]
1262
	sub	eax,[stub_size]
1233
	sub	[ebx+14h],eax
1263
	sub	[ebx+14h],eax
1234
	mov	ecx,[ebx+10h]
1264
	mov	ecx,[ebx+10h]
1235
	test	byte [ebx+24h],20h
1265
	test	byte [ebx+24h],20h
1236
	jz	pe_code_sum_ok
1266
	jz	pe_code_sum_ok
1237
	add	[edx+1Ch],ecx
1267
	add	[edx+1Ch],ecx
1238
	cmp	dword [edx+2Ch],0
1268
	cmp	dword [edx+2Ch],0
1239
	jne	pe_code_sum_ok
1269
	jne	pe_code_sum_ok
1240
	mov	eax,[ebx+0Ch]
1270
	mov	eax,[ebx+0Ch]
1241
	mov	[edx+2Ch],eax
1271
	mov	[edx+2Ch],eax
1242
      pe_code_sum_ok:
1272
      pe_code_sum_ok:
1243
	test	byte [ebx+24h],40h
1273
	test	byte [ebx+24h],40h
1244
	jz	pe_data_sum_ok
1274
	jz	pe_data_sum_ok
1245
	add	[edx+20h],ecx
1275
	add	[edx+20h],ecx
1246
	test	[format_flags],8
1276
	test	[format_flags],4
1247
	jnz	pe_data_sum_ok
1277
	jnz	pe_data_sum_ok
1248
	cmp	dword [edx+30h],0
1278
	cmp	dword [edx+30h],0
1249
	jne	pe_data_sum_ok
1279
	jne	pe_data_sum_ok
1250
	mov	eax,[ebx+0Ch]
1280
	mov	eax,[ebx+0Ch]
1251
	mov	[edx+30h],eax
1281
	mov	[edx+30h],eax
1252
      pe_data_sum_ok:
1282
      pe_data_sum_ok:
1253
	mov	eax,[ebx+8]
1283
	mov	eax,[ebx+8]
1254
	or	eax,eax
1284
	or	eax,eax
1255
	jz	udata_ok
1285
	jz	udata_ok
1256
	cmp	dword [ebx+10h],0
1286
	cmp	dword [ebx+10h],0
1257
	jne	udata_ok
1287
	jne	udata_ok
1258
	or	byte [ebx+24h],80h
1288
	or	byte [ebx+24h],80h
1259
	add	[edx+24h],ecx
1289
	add	[edx+24h],ecx
1260
      udata_ok:
1290
      udata_ok:
1261
	mov	ecx,[edx+38h]
1291
	mov	ecx,[edx+38h]
1262
	dec	ecx
1292
	dec	ecx
1263
	add	eax,ecx
1293
	add	eax,ecx
1264
	not	ecx
1294
	not	ecx
1265
	and	eax,ecx
1295
	and	eax,ecx
1266
	add	eax,[ebx+0Ch]
1296
	add	eax,[ebx+0Ch]
1267
	add	ebx,28h
1297
	add	ebx,28h
1268
	mov	[current_section],ebx
1298
	mov	[current_section],ebx
1269
	inc	word [number_of_sections]
1299
	inc	word [number_of_sections]
1270
	jz	format_limitations_exceeded
1300
	jz	format_limitations_exceeded
1271
	ret
1301
	ret
1272
data_directive:
1302
data_directive:
1273
	cmp	[output_format],3
1303
	cmp	[output_format],3
1274
	jne	illegal_instruction
1304
	jne	illegal_instruction
1275
	lods	byte [esi]
1305
	lods	byte [esi]
1276
	cmp	al,1Ah
1306
	cmp	al,1Ah
1277
	je	predefined_data_type
1307
	je	predefined_data_type
1278
	cmp	al,'('
1308
	cmp	al,'('
1279
	jne	invalid_argument
1309
	jne	invalid_argument
1280
	call	get_byte_value
1310
	call	get_byte_value
1281
	cmp	al,16
1311
	cmp	al,16
1282
	jb	data_type_ok
1312
	jb	data_type_ok
1283
	jmp	invalid_value
1313
	jmp	invalid_value
1284
      predefined_data_type:
1314
      predefined_data_type:
1285
	movzx	eax,byte [esi]
1315
	movzx	eax,byte [esi]
1286
	inc	esi
1316
	inc	esi
1287
      data_type_ok:
1317
      data_type_ok:
1288
	mov	ebx,[current_section]
1318
	mov	ebx,[current_section]
1289
	mov	ecx,edi
1319
	mov	ecx,edi
1290
	sub	ecx,[ebx+14h]
1320
	sub	ecx,[ebx+14h]
1291
	add	ecx,[ebx+0Ch]
1321
	add	ecx,[ebx+0Ch]
1292
	mov	edx,[code_start]
1322
	mov	edx,[code_start]
1293
	test	[format_flags],8
1323
	test	[format_flags],4
1294
	jnz	peplus_data
1324
	jnz	peplus_data
1295
	xchg	ecx,[edx+78h+eax*8]
1325
	xchg	ecx,[edx+78h+eax*8]
1296
	jmp	init_pe_data
1326
	jmp	init_pe_data
1297
      peplus_data:
1327
      peplus_data:
1298
	xchg	ecx,[edx+88h+eax*8]
1328
	xchg	ecx,[edx+88h+eax*8]
1299
      init_pe_data:
1329
      init_pe_data:
1300
	or	ecx,ecx
1330
	or	ecx,ecx
1301
	jnz	data_already_defined
1331
	jnz	data_already_defined
1302
	call	allocate_structure_data
1332
	call	allocate_structure_data
1303
	mov	word [ebx],data_directive-instruction_handler
1333
	mov	word [ebx],data_directive-instruction_handler
1304
	mov	[ebx+2],al
1334
	mov	[ebx+2],al
1305
	mov	edx,[current_line]
1335
	mov	edx,[current_line]
1306
	mov	[ebx+4],edx
1336
	mov	[ebx+4],edx
1307
	call	generate_pe_data
1337
	call	generate_pe_data
1308
	jmp	instruction_assembled
1338
	jmp	instruction_assembled
1309
      end_data:
1339
      end_data:
1310
	cmp	[output_format],3
1340
	cmp	[output_format],3
1311
	jne	illegal_instruction
1341
	jne	illegal_instruction
1312
	call	find_structure_data
1342
	call	find_structure_data
1313
	jc	unexpected_instruction
1343
	jc	unexpected_instruction
1314
	movzx	eax,byte [ebx+2]
1344
	movzx	eax,byte [ebx+2]
1315
	mov	edx,[current_section]
1345
	mov	edx,[current_section]
1316
	mov	ecx,edi
1346
	mov	ecx,edi
1317
	sub	ecx,[edx+14h]
1347
	sub	ecx,[edx+14h]
1318
	add	ecx,[edx+0Ch]
1348
	add	ecx,[edx+0Ch]
1319
	mov	edx,[code_start]
1349
	mov	edx,[code_start]
1320
	test	[format_flags],8
1350
	test	[format_flags],4
1321
	jnz	end_peplus_data
1351
	jnz	end_peplus_data
1322
	sub	ecx,[edx+78h+eax*8]
1352
	sub	ecx,[edx+78h+eax*8]
1323
	mov	[edx+78h+eax*8+4],ecx
1353
	mov	[edx+78h+eax*8+4],ecx
1324
	jmp	remove_structure_data
1354
	jmp	remove_structure_data
1325
      end_peplus_data:
1355
      end_peplus_data:
1326
	sub	ecx,[edx+88h+eax*8]
1356
	sub	ecx,[edx+88h+eax*8]
1327
	mov	[edx+88h+eax*8+4],ecx
1357
	mov	[edx+88h+eax*8+4],ecx
1328
	jmp	remove_structure_data
1358
	jmp	remove_structure_data
1329
pe_entry:
1359
pe_entry:
1330
	lods	byte [esi]
1360
	lods	byte [esi]
1331
	cmp	al,'('
1361
	cmp	al,'('
1332
	jne	invalid_argument
1362
	jne	invalid_argument
1333
	cmp	byte [esi],'.'
1363
	cmp	byte [esi],'.'
1334
	je	invalid_value
1364
	je	invalid_value
1335
	test	[format_flags],8
1365
	test	[format_flags],8
1336
	jnz	peplus_entry
1366
	jnz	pe64_entry
1337
	call	get_dword_value
1367
	call	get_dword_value
1338
	mov	bl,2
1368
	mov	bl,2
1339
	bt	[resolver_flags],0
1369
	bt	[resolver_flags],0
1340
	jc	check_pe_entry_label_type
1370
	jc	check_pe_entry_label_type
1341
	xor	bl,bl
1371
	xor	bl,bl
1342
      check_pe_entry_label_type:
1372
      check_pe_entry_label_type:
1343
	cmp	[value_type],bl
1373
	cmp	[value_type],bl
1344
	je	pe_entry_ok
1374
	je	pe_entry_ok
1345
	cmp	[error_line],0
1375
	cmp	[error_line],0
1346
	jne	pe_entry_ok
1376
	jne	pe_entry_ok
1347
	mov	edx,[current_line]
1377
	mov	edx,[current_line]
1348
	mov	[error_line],edx
1378
	mov	[error_line],edx
1349
	mov	[error],invalid_address
1379
	mov	[error],invalid_address
1350
      pe_entry_ok:
1380
      pe_entry_ok:
1351
	mov	edx,[code_start]
1381
      cdq
-
 
1382
	test	[format_flags],4
-
 
1383
	jnz	pe64_entry_type_ok
-
 
1384
	mov	edx,[code_start]
1352
	sub	eax,[edx+34h]
1385
	sub	eax,[edx+34h]
1353
	mov	[edx+28h],eax
1386
	mov	[edx+28h],eax
1354
	jmp	instruction_assembled
1387
	jmp	instruction_assembled
1355
      peplus_entry:
1388
      pe64_entry:
1356
	call	get_qword_value
1389
	call	get_qword_value
1357
	mov	bl,4
1390
	mov	bl,4
1358
	bt	[resolver_flags],0
1391
	bt	[resolver_flags],0
1359
	jc	check_peplus_entry_label_type
1392
	jc	check_pe64_entry_label_type
1360
	xor	bl,bl
1393
	xor	bl,bl
1361
      check_peplus_entry_label_type:
1394
      check_pe64_entry_label_type:
1362
	cmp	[value_type],bl
1395
	cmp	[value_type],bl
1363
	je	peplus_entry_type_ok
1396
	je	pe64_entry_type_ok
1364
	cmp	[error_line],0
1397
	cmp	[error_line],0
1365
	jne	peplus_entry_type_ok
1398
	jne	pe64_entry_type_ok
1366
	mov	edx,[current_line]
1399
	mov	edx,[current_line]
1367
	mov	[error_line],edx
1400
	mov	[error_line],edx
1368
	mov	[error],invalid_address
1401
	mov	[error],invalid_address
1369
      peplus_entry_type_ok:
1402
      pe64_entry_type_ok:
1370
	mov	ecx,[code_start]
1403
	mov	ecx,[code_start]
1371
	sub	eax,[ecx+30h]
1404
	sub	eax,[ecx+30h]
1372
	sbb	edx,[ecx+34h]
1405
	sbb	edx,[ecx+34h]
1373
	jz	peplus_entry_range_ok
1406
	jz	pe64_entry_range_ok
1374
	mov	edx,[current_line]
1407
	mov	edx,[current_line]
1375
	mov	[error_line],edx
1408
	mov	[error_line],edx
1376
	mov	[error],value_out_of_range
1409
	mov	[error],value_out_of_range
1377
      peplus_entry_range_ok:
1410
      pe64_entry_range_ok:
1378
	mov	[ecx+28h],eax
1411
	mov	[ecx+28h],eax
1379
	jmp	instruction_assembled
1412
	jmp	instruction_assembled
1380
pe_stack:
1413
pe_stack:
1381
	lods	byte [esi]
1414
	lods	byte [esi]
1382
	cmp	al,'('
1415
	cmp	al,'('
1383
	jne	invalid_argument
1416
	jne	invalid_argument
1384
	cmp	byte [esi],'.'
1417
	cmp	byte [esi],'.'
1385
	je	invalid_value
1418
	je	invalid_value
1386
	test	[format_flags],8
1419
	test	[format_flags],4
1387
	jnz	peplus_stack
1420
	jnz	peplus_stack
1388
	call	get_dword_value
1421
	call	get_count_value
1389
	cmp	[value_type],0
1422
	mov	edx,[code_start]
1390
	jne	invalid_use_of_symbol
-
 
1391
	mov	edx,[code_start]
-
 
1392
	mov	[edx+60h],eax
1423
	mov	[edx+60h],eax
1393
	cmp	byte [esi],','
1424
	cmp	byte [esi],','
1394
	jne	default_stack_commit
1425
	jne	default_stack_commit
1395
	lods	byte [esi]
1426
	lods	byte [esi]
1396
	lods	byte [esi]
1427
	lods	byte [esi]
1397
	cmp	al,'('
1428
	cmp	al,'('
1398
	jne	invalid_argument
1429
	jne	invalid_argument
1399
	cmp	byte [esi],'.'
1430
	cmp	byte [esi],'.'
1400
	je	invalid_value
1431
	je	invalid_value
1401
	call	get_dword_value
1432
	call	get_count_value
1402
	cmp	[value_type],0
1433
	mov	edx,[code_start]
1403
	jne	invalid_use_of_symbol
-
 
1404
	mov	edx,[code_start]
-
 
1405
	mov	[edx+64h],eax
1434
	mov	[edx+64h],eax
1406
	cmp	eax,[edx+60h]
1435
	cmp	eax,[edx+60h]
1407
	ja	value_out_of_range
1436
	ja	value_out_of_range
1408
	jmp	instruction_assembled
1437
	jmp	instruction_assembled
1409
      default_stack_commit:
1438
      default_stack_commit:
1410
	mov	dword [edx+64h],1000h
1439
	mov	dword [edx+64h],1000h
1411
	mov	eax,[edx+60h]
1440
	mov	eax,[edx+60h]
1412
	cmp	eax,1000h
1441
	cmp	eax,1000h
1413
	ja	instruction_assembled
1442
	ja	instruction_assembled
1414
	mov	dword [edx+64h],eax
1443
	mov	dword [edx+64h],eax
1415
	jmp	instruction_assembled
1444
	jmp	instruction_assembled
1416
      peplus_stack:
1445
      peplus_stack:
1417
	call	get_qword_value
1446
	call	get_qword_value
1418
	cmp	[value_type],0
1447
	cmp	[value_type],0
1419
	jne	invalid_use_of_symbol
1448
	jne	invalid_use_of_symbol
1420
	mov	ecx,[code_start]
1449
	mov	ecx,[code_start]
1421
	mov	[ecx+60h],eax
1450
	mov	[ecx+60h],eax
1422
	mov	[ecx+64h],edx
1451
	mov	[ecx+64h],edx
1423
	cmp	byte [esi],','
1452
	cmp	byte [esi],','
1424
	jne	default_peplus_stack_commit
1453
	jne	default_peplus_stack_commit
1425
	lods	byte [esi]
1454
	lods	byte [esi]
1426
	lods	byte [esi]
1455
	lods	byte [esi]
1427
	cmp	al,'('
1456
	cmp	al,'('
1428
	jne	invalid_argument
1457
	jne	invalid_argument
1429
	cmp	byte [esi],'.'
1458
	cmp	byte [esi],'.'
1430
	je	invalid_value
1459
	je	invalid_value
1431
	call	get_qword_value
1460
	call	get_qword_value
1432
	cmp	[value_type],0
1461
	cmp	[value_type],0
1433
	jne	invalid_use_of_symbol
1462
	jne	invalid_use_of_symbol
1434
	mov	ecx,[code_start]
1463
	mov	ecx,[code_start]
1435
	mov	[ecx+68h],eax
1464
	mov	[ecx+68h],eax
1436
	mov	[ecx+6Ch],edx
1465
	mov	[ecx+6Ch],edx
1437
	cmp	edx,[ecx+64h]
1466
	cmp	edx,[ecx+64h]
1438
	ja	value_out_of_range
1467
	ja	value_out_of_range
1439
	jb	instruction_assembled
1468
	jb	instruction_assembled
1440
	cmp	eax,[ecx+60h]
1469
	cmp	eax,[ecx+60h]
1441
	ja	value_out_of_range
1470
	ja	value_out_of_range
1442
	jmp	instruction_assembled
1471
	jmp	instruction_assembled
1443
      default_peplus_stack_commit:
1472
      default_peplus_stack_commit:
1444
	mov	dword [ecx+68h],1000h
1473
	mov	dword [ecx+68h],1000h
1445
	cmp	dword [ecx+64h],0
1474
	cmp	dword [ecx+64h],0
1446
	jne	instruction_assembled
1475
	jne	instruction_assembled
1447
	mov	eax,[ecx+60h]
1476
	mov	eax,[ecx+60h]
1448
	cmp	eax,1000h
1477
	cmp	eax,1000h
1449
	ja	instruction_assembled
1478
	ja	instruction_assembled
1450
	mov	dword [ecx+68h],eax
1479
	mov	dword [ecx+68h],eax
1451
	jmp	instruction_assembled
1480
	jmp	instruction_assembled
1452
pe_heap:
1481
pe_heap:
1453
	lods	byte [esi]
1482
	lods	byte [esi]
1454
	cmp	al,'('
1483
	cmp	al,'('
1455
	jne	invalid_argument
1484
	jne	invalid_argument
1456
	cmp	byte [esi],'.'
1485
	cmp	byte [esi],'.'
1457
	je	invalid_value
1486
	je	invalid_value
1458
	test	[format_flags],8
1487
	test	[format_flags],4
1459
	jnz	peplus_heap
1488
	jnz	peplus_heap
1460
	call	get_dword_value
1489
	call	get_count_value
1461
	cmp	[value_type],0
1490
	mov	edx,[code_start]
1462
	jne	invalid_use_of_symbol
-
 
1463
	mov	edx,[code_start]
-
 
1464
	mov	[edx+68h],eax
1491
	mov	[edx+68h],eax
1465
	cmp	byte [esi],','
1492
	cmp	byte [esi],','
1466
	jne	instruction_assembled
1493
	jne	instruction_assembled
1467
	lods	byte [esi]
1494
	lods	byte [esi]
1468
	lods	byte [esi]
1495
	lods	byte [esi]
1469
	cmp	al,'('
1496
	cmp	al,'('
1470
	jne	invalid_argument
1497
	jne	invalid_argument
1471
	cmp	byte [esi],'.'
1498
	cmp	byte [esi],'.'
1472
	je	invalid_value
1499
	je	invalid_value
1473
	call	get_dword_value
1500
	call	get_count_value
1474
	cmp	[value_type],0
1501
	mov	edx,[code_start]
1475
	jne	invalid_use_of_symbol
-
 
1476
	mov	edx,[code_start]
-
 
1477
	mov	[edx+6Ch],eax
1502
	mov	[edx+6Ch],eax
1478
	cmp	eax,[edx+68h]
1503
	cmp	eax,[edx+68h]
1479
	ja	value_out_of_range
1504
	ja	value_out_of_range
1480
	jmp	instruction_assembled
1505
	jmp	instruction_assembled
1481
      peplus_heap:
1506
      peplus_heap:
1482
	call	get_qword_value
1507
	call	get_qword_value
1483
	cmp	[value_type],0
1508
	cmp	[value_type],0
1484
	jne	invalid_use_of_symbol
1509
	jne	invalid_use_of_symbol
1485
	mov	ecx,[code_start]
1510
	mov	ecx,[code_start]
1486
	mov	[ecx+70h],eax
1511
	mov	[ecx+70h],eax
1487
	mov	[ecx+74h],edx
1512
	mov	[ecx+74h],edx
1488
	cmp	byte [esi],','
1513
	cmp	byte [esi],','
1489
	jne	instruction_assembled
1514
	jne	instruction_assembled
1490
	lods	byte [esi]
1515
	lods	byte [esi]
1491
	lods	byte [esi]
1516
	lods	byte [esi]
1492
	cmp	al,'('
1517
	cmp	al,'('
1493
	jne	invalid_argument
1518
	jne	invalid_argument
1494
	cmp	byte [esi],'.'
1519
	cmp	byte [esi],'.'
1495
	je	invalid_value
1520
	je	invalid_value
1496
	call	get_qword_value
1521
	call	get_qword_value
1497
	cmp	[value_type],0
1522
	cmp	[value_type],0
1498
	jne	invalid_use_of_symbol
1523
	jne	invalid_use_of_symbol
1499
	mov	ecx,[code_start]
1524
	mov	ecx,[code_start]
1500
	mov	[ecx+78h],eax
1525
	mov	[ecx+78h],eax
1501
	mov	[ecx+7Ch],edx
1526
	mov	[ecx+7Ch],edx
1502
	cmp	edx,[ecx+74h]
1527
	cmp	edx,[ecx+74h]
1503
	ja	value_out_of_range
1528
	ja	value_out_of_range
1504
	jb	instruction_assembled
1529
	jb	instruction_assembled
1505
	cmp	eax,[edx+70h]
1530
	cmp	eax,[edx+70h]
1506
	ja	value_out_of_range
1531
	ja	value_out_of_range
1507
	jmp	instruction_assembled
1532
	jmp	instruction_assembled
1508
mark_pe_relocation:
1533
mark_pe_relocation:
1509
	push	eax ebx
1534
	push	eax ebx
1510
	test	[format_flags],8
1535
	test	[format_flags],4
1511
	jz	check_pe32_relocation_type
1536
	jz	check_standard_pe_relocation_type
1512
	cmp	[value_type],4
1537
	cmp	[value_type],4
1513
	je	pe_relocation_type_ok
1538
	je	pe_relocation_type_ok
1514
      check_pe32_relocation_type:
1539
      check_standard_pe_relocation_type:
1515
	cmp	[value_type],2
1540
	cmp	[value_type],2
1516
	je	pe_relocation_type_ok
1541
	je	pe_relocation_type_ok
1517
	cmp	[error_line],0
1542
	cmp	[error_line],0
1518
	jne	pe_relocation_type_ok
1543
	jne	pe_relocation_type_ok
1519
	mov	eax,[current_line]
1544
	mov	eax,[current_line]
1520
	mov	[error_line],eax
1545
	mov	[error_line],eax
1521
	mov	[error],invalid_use_of_symbol
1546
	mov	[error],invalid_use_of_symbol
1522
      pe_relocation_type_ok:
1547
      pe_relocation_type_ok:
1523
	mov	ebx,[current_section]
1548
	mov	ebx,[current_section]
1524
	mov	eax,edi
1549
	mov	eax,edi
1525
	sub	eax,[ebx+14h]
1550
	sub	eax,[ebx+14h]
1526
	add	eax,[ebx+0Ch]
1551
	add	eax,[ebx+0Ch]
1527
	mov	ebx,[free_additional_memory]
1552
	mov	ebx,[free_additional_memory]
1528
	inc	[number_of_relocations]
1553
	inc	[number_of_relocations]
1529
	jz	invalid_use_of_symbol
1554
	add	ebx,5
1530
	add	ebx,5
-
 
1531
	cmp	ebx,[structures_buffer]
1555
	cmp	ebx,[structures_buffer]
1532
	jae	out_of_memory
1556
	jae	out_of_memory
1533
	mov	[free_additional_memory],ebx
1557
	mov	[free_additional_memory],ebx
1534
	mov	[ebx-5],eax
1558
	mov	[ebx-5],eax
1535
	cmp	[value_type],2
1559
	cmp	[value_type],2
1536
	je	fixup_32bit
1560
	je	fixup_32bit
1537
	mov	byte [ebx-1],0Ah
1561
	mov	byte [ebx-1],0Ah
1538
	jmp	fixup_ok
1562
	jmp	fixup_ok
1539
      fixup_32bit:
1563
      fixup_32bit:
1540
	mov	byte [ebx-1],3
1564
	mov	byte [ebx-1],3
1541
      fixup_ok:
1565
      fixup_ok:
1542
	pop	ebx eax
1566
	pop	ebx eax
1543
	ret
1567
	ret
1544
generate_pe_data:
1568
generate_pe_data:
1545
	cmp	al,2
1569
	cmp	al,2
1546
	je	make_pe_resource
1570
	je	make_pe_resource
1547
	cmp	al,5
1571
	cmp	al,5
1548
	je	make_pe_fixups
1572
	je	make_pe_fixups
1549
	ret
1573
	ret
1550
make_pe_fixups:
1574
make_pe_fixups:
1551
	bts	[resolver_flags],0
1575
	mov	edx,[code_start]
-
 
1576
	and	byte [edx+16h],not 1
-
 
1577
	or	byte [edx+5Eh],40h
-
 
1578
	bts	[resolver_flags],0
1552
	jc	pe_relocatable_ok
1579
	jc	fixups_ready
1553
	or	[next_pass_needed],-1
1580
	or	[next_pass_needed],-1
1554
     pe_relocatable_ok:
1581
      fixups_ready:
-
 
1582
	mov	[last_fixup_base],0
-
 
1583
	call	make_fixups
-
 
1584
	xchg	eax,[actual_fixups_size]
-
 
1585
	sub	eax,[actual_fixups_size]
-
 
1586
	ja	reserve_forward_fixups
-
 
1587
	xor	eax,eax
-
 
1588
      reserve_forward_fixups:
1555
	push	esi
1589
	mov	[reserved_fixups],edi
-
 
1590
	add	edi,eax
-
 
1591
	mov	[reserved_fixups_size],eax
-
 
1592
	ret
-
 
1593
      make_fixups:
-
 
1594
	push	esi
1556
	mov	ecx,[number_of_relocations]
1595
	xor	ecx,ecx
-
 
1596
	xchg	ecx,[number_of_relocations]
1557
	mov	esi,[free_additional_memory]
1597
	mov	esi,[free_additional_memory]
1558
	lea	eax,[ecx*5]
1598
	lea	eax,[ecx*5]
1559
	sub	esi,eax
1599
	sub	esi,eax
1560
	mov	[free_additional_memory],esi
1600
	mov	[free_additional_memory],esi
1561
	or	[number_of_relocations],-1
1601
	mov	edx,[last_fixup_base]
1562
	xor	edx,edx
-
 
1563
	mov	ebp,edi
1602
	mov	ebp,edi
1564
      make_fixups:
1603
	jecxz	fixups_done
-
 
1604
      make_fixup:
1565
	cmp	[esi],edx
1605
	cmp	[esi],edx
1566
	jb	store_fixup
1606
	jb	store_fixup
1567
	mov	eax,edi
1607
	mov	eax,edi
1568
	sub	eax,ebp
1608
	sub	eax,ebp
1569
	test	eax,11b
1609
	test	eax,11b
1570
	jz	fixups_block
1610
	jz	fixups_block
1571
	xor	ax,ax
1611
	xor	ax,ax
1572
	stos	word [edi]
1612
	stos	word [edi]
1573
	add	dword [ebx],2
1613
	add	dword [ebx],2
1574
      fixups_block:
1614
      fixups_block:
1575
	mov	eax,edx
1615
	mov	eax,edx
1576
	add	edx,1000h
1616
	add	edx,1000h
1577
	cmp	[esi],edx
1617
	cmp	[esi],edx
1578
	jae	fixups_block
1618
	jae	fixups_block
1579
	stos	dword [edi]
1619
	stos	dword [edi]
1580
	mov	ebx,edi
1620
	mov	ebx,edi
1581
	mov	eax,8
1621
	mov	eax,8
1582
	stos	dword [edi]
1622
	stos	dword [edi]
1583
      store_fixup:
1623
      store_fixup:
1584
	jecxz	fixups_done
1624
	add	dword [ebx],2
1585
	add	dword [ebx],2
-
 
1586
	mov	ah,[esi+1]
1625
	mov	ah,[esi+1]
1587
	and	ah,0Fh
1626
	and	ah,0Fh
1588
	mov	al,[esi+4]
1627
	mov	al,[esi+4]
1589
	shl	al,4
1628
	shl	al,4
1590
	or	ah,al
1629
	or	ah,al
1591
	mov	al,[esi]
1630
	mov	al,[esi]
1592
	stos	word [edi]
1631
	stos	word [edi]
1593
	add	esi,5
1632
	add	esi,5
1594
	loop	make_fixups
1633
	loop	make_fixup
1595
      fixups_done:
1634
      fixups_done:
1596
	pop	esi
1635
	mov	[last_fixup_base],edx
-
 
1636
	pop	esi
1597
	ret
1637
	mov	eax,edi
-
 
1638
	sub	eax,ebp
-
 
1639
	ret
1598
make_pe_resource:
1640
make_pe_resource:
1599
	cmp	byte [esi],82h
1641
	cmp	byte [esi],82h
1600
	jne	resource_done
1642
	jne	resource_done
1601
	inc	esi
1643
	inc	esi
1602
	lods	word [esi]
1644
	lods	word [esi]
1603
	cmp	ax,'('
1645
	cmp	ax,'('
1604
	jne	invalid_argument
1646
	jne	invalid_argument
1605
	lods	dword [esi]
1647
	lods	dword [esi]
1606
	mov	edx,esi
1648
	mov	edx,esi
1607
	lea	esi,[esi+eax+1]
1649
	lea	esi,[esi+eax+1]
1608
	cmp	[next_pass_needed],0
1650
	cmp	[next_pass_needed],0
1609
	je	resource_from_file
1651
	je	resource_from_file
1610
	cmp	[current_pass],0
1652
	cmp	[current_pass],0
1611
	jne	reserve_space_for_resource
1653
	jne	reserve_space_for_resource
1612
	mov	[resource_size],0
1654
	mov	[resource_size],0
1613
      reserve_space_for_resource:
1655
      reserve_space_for_resource:
1614
	add	edi,[resource_size]
1656
	add	edi,[resource_size]
1615
	cmp	edi,[display_buffer]
1657
	cmp	edi,[display_buffer]
1616
	ja	out_of_memory
1658
	ja	out_of_memory
1617
	jmp	resource_done
1659
	jmp	resource_done
1618
      resource_from_file:
1660
      resource_from_file:
1619
	push	esi
1661
	push	esi
1620
	mov	esi,edx
1662
	mov	esi,edx
1621
	call	open_binary_file
1663
	call	open_binary_file
1622
	push	ebx
1664
	push	ebx
1623
	mov	esi,[free_additional_memory]
1665
	mov	esi,[free_additional_memory]
1624
	lea	eax,[esi+20h]
1666
	lea	eax,[esi+20h]
1625
	cmp	eax,[structures_buffer]
1667
	cmp	eax,[structures_buffer]
1626
	ja	out_of_memory
1668
	ja	out_of_memory
1627
	mov	edx,esi
1669
	mov	edx,esi
1628
	mov	ecx,20h
1670
	mov	ecx,20h
1629
	call	read
1671
	call	read
1630
	jc	invalid_file_format
1672
	jc	invalid_file_format
1631
	xor	eax,eax
1673
	xor	eax,eax
1632
	cmp	[esi],eax
1674
	cmp	[esi],eax
1633
	jne	invalid_file_format
1675
	jne	invalid_file_format
1634
	mov	ax,0FFFFh
1676
	mov	ax,0FFFFh
1635
	cmp	[esi+8],eax
1677
	cmp	[esi+8],eax
1636
	jne	invalid_file_format
1678
	jne	invalid_file_format
1637
	cmp	[esi+12],eax
1679
	cmp	[esi+12],eax
1638
	jne	invalid_file_format
1680
	jne	invalid_file_format
1639
	mov	eax,20h
1681
	mov	eax,20h
1640
	cmp	[esi+4],eax
1682
	cmp	[esi+4],eax
1641
	jne	invalid_file_format
1683
	jne	invalid_file_format
1642
      read_resource_headers:
1684
      read_resource_headers:
1643
	test	eax,11b
1685
	test	eax,11b
1644
	jz	resource_file_alignment_ok
1686
	jz	resource_file_alignment_ok
1645
	mov	edx,4
1687
	mov	edx,4
1646
	and	eax,11b
1688
	and	eax,11b
1647
	sub	edx,eax
1689
	sub	edx,eax
1648
	mov	al,1
1690
	mov	al,1
1649
	call	lseek
1691
	call	lseek
1650
      resource_file_alignment_ok:
1692
      resource_file_alignment_ok:
1651
	mov	[esi],eax
1693
	mov	[esi],eax
1652
	lea	edx,[esi+12]
1694
	lea	edx,[esi+12]
1653
	mov	ecx,8
1695
	mov	ecx,8
1654
	call	read
1696
	call	read
1655
	jc	resource_headers_ok
1697
	jc	resource_headers_ok
1656
	mov	ecx,[esi+16]
1698
	mov	ecx,[esi+16]
1657
	add	[esi],ecx
1699
	add	[esi],ecx
1658
	lea	edx,[esi+20]
1700
	lea	edx,[esi+20]
1659
	sub	ecx,8
1701
	sub	ecx,8
1660
	mov	[esi+16],ecx
1702
	mov	[esi+16],ecx
1661
	lea	eax,[edx+ecx]
1703
	lea	eax,[edx+ecx]
1662
	cmp	eax,[structures_buffer]
1704
	cmp	eax,[structures_buffer]
1663
	ja	out_of_memory
1705
	ja	out_of_memory
1664
	call	read
1706
	call	read
1665
	jc	invalid_file_format
1707
	jc	invalid_file_format
1666
	mov	edx,[esi]
1708
	mov	edx,[esi]
1667
	add	edx,[esi+12]
1709
	add	edx,[esi+12]
1668
	mov	eax,[esi+16]
1710
	mov	eax,[esi+16]
1669
	lea	ecx,[esi+20]
1711
	lea	ecx,[esi+20]
1670
	lea	esi,[ecx+eax]
1712
	lea	esi,[ecx+eax]
1671
	add	ecx,2
1713
	add	ecx,2
1672
	cmp	word [ecx-2],0FFFFh
1714
	cmp	word [ecx-2],0FFFFh
1673
	je	resource_header_type_ok
1715
	je	resource_header_type_ok
1674
      check_resource_header_type:
1716
      check_resource_header_type:
1675
	cmp	ecx,esi
1717
	cmp	ecx,esi
1676
	jae	invalid_file_format
1718
	jae	invalid_file_format
1677
	cmp	word [ecx],0
1719
	cmp	word [ecx],0
1678
	je	resource_header_type_ok
1720
	je	resource_header_type_ok
1679
	add	ecx,2
1721
	add	ecx,2
1680
	jmp	check_resource_header_type
1722
	jmp	check_resource_header_type
1681
      resource_header_type_ok:
1723
      resource_header_type_ok:
1682
	add	ecx,2
1724
	add	ecx,2
1683
	cmp	word [ecx],0FFFFh
1725
	cmp	word [ecx],0FFFFh
1684
	je	resource_header_name_ok
1726
	je	resource_header_name_ok
1685
      check_resource_header_name:
1727
      check_resource_header_name:
1686
	cmp	ecx,esi
1728
	cmp	ecx,esi
1687
	jae	invalid_file_format
1729
	jae	invalid_file_format
1688
	cmp	word [ecx],0
1730
	cmp	word [ecx],0
1689
	je	resource_header_name_ok
1731
	je	resource_header_name_ok
1690
	add	ecx,2
1732
	add	ecx,2
1691
	jmp	check_resource_header_name
1733
	jmp	check_resource_header_name
1692
      resource_header_name_ok:
1734
      resource_header_name_ok:
1693
	xor	al,al
1735
	xor	al,al
1694
	call	lseek
1736
	call	lseek
1695
	jmp	read_resource_headers
1737
	jmp	read_resource_headers
1696
      resource_headers_ok:
1738
      resource_headers_ok:
1697
	xor	eax,eax
1739
	xor	eax,eax
1698
	mov	[esi],eax
1740
	mov	[esi],eax
1699
	mov	[resource_data],edi
1741
	mov	[resource_data],edi
1700
	lea	eax,[edi+16]
1742
	lea	eax,[edi+16]
1701
	cmp	eax,[display_buffer]
1743
	cmp	eax,[display_buffer]
1702
	jae	out_of_memory
1744
	jae	out_of_memory
1703
	xor	eax,eax
1745
	xor	eax,eax
1704
	stos	dword [edi]
1746
	stos	dword [edi]
1705
	call	make_timestamp
1747
	call	make_timestamp
1706
	stos	dword [edi]
1748
	stos	dword [edi]
1707
	xor	eax,eax
1749
	xor	eax,eax
1708
	stos	dword [edi]
1750
	stos	dword [edi]
1709
	stos	dword [edi]
1751
	stos	dword [edi]
1710
	xor	ebx,ebx
1752
	xor	ebx,ebx
1711
      make_type_name_directory:
1753
      make_type_name_directory:
1712
	mov	esi,[free_additional_memory]
1754
	mov	esi,[free_additional_memory]
1713
	xor	edx,edx
1755
	xor	edx,edx
1714
      find_type_name:
1756
      find_type_name:
1715
	cmp	dword [esi],0
1757
	cmp	dword [esi],0
1716
	je	type_name_ok
1758
	je	type_name_ok
1717
	add	esi,20
1759
	add	esi,20
1718
	cmp	word [esi],0FFFFh
1760
	cmp	word [esi],0FFFFh
1719
	je	check_next_type_name
1761
	je	check_next_type_name
1720
	or	ebx,ebx
1762
	or	ebx,ebx
1721
	jz	check_this_type_name
1763
	jz	check_this_type_name
1722
	xor	ecx,ecx
1764
	xor	ecx,ecx
1723
      compare_with_previous_type_name:
1765
      compare_with_previous_type_name:
1724
	mov	ax,[esi+ecx]
1766
	mov	ax,[esi+ecx]
1725
	cmp	ax,[ebx+ecx]
1767
	cmp	ax,[ebx+ecx]
1726
	ja	check_this_type_name
1768
	ja	check_this_type_name
1727
	jb	check_next_type_name
1769
	jb	check_next_type_name
1728
	add	ecx,2
1770
	add	ecx,2
1729
	mov	ax,[esi+ecx]
1771
	mov	ax,[esi+ecx]
1730
	or	ax,[ebx+ecx]
1772
	or	ax,[ebx+ecx]
1731
	jnz	compare_with_previous_type_name
1773
	jnz	compare_with_previous_type_name
1732
	jmp	check_next_type_name
1774
	jmp	check_next_type_name
1733
      check_this_type_name:
1775
      check_this_type_name:
1734
	or	edx,edx
1776
	or	edx,edx
1735
	jz	type_name_found
1777
	jz	type_name_found
1736
	xor	ecx,ecx
1778
	xor	ecx,ecx
1737
      compare_with_current_type_name:
1779
      compare_with_current_type_name:
1738
	mov	ax,[esi+ecx]
1780
	mov	ax,[esi+ecx]
1739
	cmp	ax,[edx+ecx]
1781
	cmp	ax,[edx+ecx]
1740
	ja	check_next_type_name
1782
	ja	check_next_type_name
1741
	jb	type_name_found
1783
	jb	type_name_found
1742
	add	ecx,2
1784
	add	ecx,2
1743
	mov	ax,[esi+ecx]
1785
	mov	ax,[esi+ecx]
1744
	or	ax,[edx+ecx]
1786
	or	ax,[edx+ecx]
1745
	jnz	compare_with_current_type_name
1787
	jnz	compare_with_current_type_name
1746
	jmp	same_type_name
1788
	jmp	same_type_name
1747
      type_name_found:
1789
      type_name_found:
1748
	mov	edx,esi
1790
	mov	edx,esi
1749
      same_type_name:
1791
      same_type_name:
1750
	mov	[esi-16],edi
1792
	mov	[esi-16],edi
1751
      check_next_type_name:
1793
      check_next_type_name:
1752
	mov	eax,[esi-4]
1794
	mov	eax,[esi-4]
1753
	add	esi,eax
1795
	add	esi,eax
1754
	jmp	find_type_name
1796
	jmp	find_type_name
1755
      type_name_ok:
1797
      type_name_ok:
1756
	or	edx,edx
1798
	or	edx,edx
1757
	jz	type_name_directory_done
1799
	jz	type_name_directory_done
1758
	mov	ebx,edx
1800
	mov	ebx,edx
1759
      make_type_name_entry:
1801
      make_type_name_entry:
1760
	mov	eax,[resource_data]
1802
	mov	eax,[resource_data]
1761
	inc	word [eax+12]
1803
	inc	word [eax+12]
1762
	lea	eax,[edi+8]
1804
	lea	eax,[edi+8]
1763
	cmp	eax,[display_buffer]
1805
	cmp	eax,[display_buffer]
1764
	jae	out_of_memory
1806
	jae	out_of_memory
1765
	mov	eax,ebx
1807
	mov	eax,ebx
1766
	stos	dword [edi]
1808
	stos	dword [edi]
1767
	xor	eax,eax
1809
	xor	eax,eax
1768
	stos	dword [edi]
1810
	stos	dword [edi]
1769
	jmp	make_type_name_directory
1811
	jmp	make_type_name_directory
1770
      type_name_directory_done:
1812
      type_name_directory_done:
1771
	mov	ebx,-1
1813
	mov	ebx,-1
1772
      make_type_id_directory:
1814
      make_type_id_directory:
1773
	mov	esi,[free_additional_memory]
1815
	mov	esi,[free_additional_memory]
1774
	mov	edx,10000h
1816
	mov	edx,10000h
1775
      find_type_id:
1817
      find_type_id:
1776
	cmp	dword [esi],0
1818
	cmp	dword [esi],0
1777
	je	type_id_ok
1819
	je	type_id_ok
1778
	add	esi,20
1820
	add	esi,20
1779
	cmp	word [esi],0FFFFh
1821
	cmp	word [esi],0FFFFh
1780
	jne	check_next_type_id
1822
	jne	check_next_type_id
1781
	movzx	eax,word [esi+2]
1823
	movzx	eax,word [esi+2]
1782
	cmp	eax,ebx
1824
	cmp	eax,ebx
1783
	jle	check_next_type_id
1825
	jle	check_next_type_id
1784
	cmp	eax,edx
1826
	cmp	eax,edx
1785
	jg	check_next_type_id
1827
	jg	check_next_type_id
1786
	mov	edx,eax
1828
	mov	edx,eax
1787
	mov	[esi-16],edi
1829
	mov	[esi-16],edi
1788
      check_next_type_id:
1830
      check_next_type_id:
1789
	mov	eax,[esi-4]
1831
	mov	eax,[esi-4]
1790
	add	esi,eax
1832
	add	esi,eax
1791
	jmp	find_type_id
1833
	jmp	find_type_id
1792
      type_id_ok:
1834
      type_id_ok:
1793
	cmp	edx,10000h
1835
	cmp	edx,10000h
1794
	je	type_id_directory_done
1836
	je	type_id_directory_done
1795
	mov	ebx,edx
1837
	mov	ebx,edx
1796
      make_type_id_entry:
1838
      make_type_id_entry:
1797
	mov	eax,[resource_data]
1839
	mov	eax,[resource_data]
1798
	inc	word [eax+14]
1840
	inc	word [eax+14]
1799
	lea	eax,[edi+8]
1841
	lea	eax,[edi+8]
1800
	cmp	eax,[display_buffer]
1842
	cmp	eax,[display_buffer]
1801
	jae	out_of_memory
1843
	jae	out_of_memory
1802
	mov	eax,ebx
1844
	mov	eax,ebx
1803
	stos	dword [edi]
1845
	stos	dword [edi]
1804
	xor	eax,eax
1846
	xor	eax,eax
1805
	stos	dword [edi]
1847
	stos	dword [edi]
1806
	jmp	make_type_id_directory
1848
	jmp	make_type_id_directory
1807
      type_id_directory_done:
1849
      type_id_directory_done:
1808
	mov	esi,[resource_data]
1850
	mov	esi,[resource_data]
1809
	add	esi,10h
1851
	add	esi,10h
1810
	mov	ecx,[esi-4]
1852
	mov	ecx,[esi-4]
1811
	or	cx,cx
1853
	or	cx,cx
1812
	jz	resource_directories_ok
1854
	jz	resource_directories_ok
1813
      make_resource_directories:
1855
      make_resource_directories:
1814
	push	ecx
1856
	push	ecx
1815
	push	edi
1857
	push	edi
1816
	mov	edx,edi
1858
	mov	edx,edi
1817
	sub	edx,[resource_data]
1859
	sub	edx,[resource_data]
1818
	bts	edx,31
1860
	bts	edx,31
1819
	mov	[esi+4],edx
1861
	mov	[esi+4],edx
1820
	lea	eax,[edi+16]
1862
	lea	eax,[edi+16]
1821
	cmp	eax,[display_buffer]
1863
	cmp	eax,[display_buffer]
1822
	jae	out_of_memory
1864
	jae	out_of_memory
1823
	xor	eax,eax
1865
	xor	eax,eax
1824
	stos	dword [edi]
1866
	stos	dword [edi]
1825
	call	make_timestamp
1867
	call	make_timestamp
1826
	stos	dword [edi]
1868
	stos	dword [edi]
1827
	xor	eax,eax
1869
	xor	eax,eax
1828
	stos	dword [edi]
1870
	stos	dword [edi]
1829
	stos	dword [edi]
1871
	stos	dword [edi]
1830
	mov	ebp,esi
1872
	mov	ebp,esi
1831
	xor	ebx,ebx
1873
	xor	ebx,ebx
1832
      make_resource_name_directory:
1874
      make_resource_name_directory:
1833
	mov	esi,[free_additional_memory]
1875
	mov	esi,[free_additional_memory]
1834
	xor	edx,edx
1876
	xor	edx,edx
1835
      find_resource_name:
1877
      find_resource_name:
1836
	cmp	dword [esi],0
1878
	cmp	dword [esi],0
1837
	je	resource_name_ok
1879
	je	resource_name_ok
1838
	push	esi
1880
	push	esi
1839
	cmp	[esi+4],ebp
1881
	cmp	[esi+4],ebp
1840
	jne	check_next_resource_name
1882
	jne	check_next_resource_name
1841
	add	esi,20
1883
	add	esi,20
1842
	call	skip_resource_name
1884
	call	skip_resource_name
1843
	cmp	word [esi],0FFFFh
1885
	cmp	word [esi],0FFFFh
1844
	je	check_next_resource_name
1886
	je	check_next_resource_name
1845
	or	ebx,ebx
1887
	or	ebx,ebx
1846
	jz	check_this_resource_name
1888
	jz	check_this_resource_name
1847
	xor	ecx,ecx
1889
	xor	ecx,ecx
1848
      compare_with_previous_resource_name:
1890
      compare_with_previous_resource_name:
1849
	mov	ax,[esi+ecx]
1891
	mov	ax,[esi+ecx]
1850
	cmp	ax,[ebx+ecx]
1892
	cmp	ax,[ebx+ecx]
1851
	ja	check_this_resource_name
1893
	ja	check_this_resource_name
1852
	jb	check_next_resource_name
1894
	jb	check_next_resource_name
1853
	add	ecx,2
1895
	add	ecx,2
1854
	mov	ax,[esi+ecx]
1896
	mov	ax,[esi+ecx]
1855
	or	ax,[ebx+ecx]
1897
	or	ax,[ebx+ecx]
1856
	jnz	compare_with_previous_resource_name
1898
	jnz	compare_with_previous_resource_name
1857
	jmp	check_next_resource_name
1899
	jmp	check_next_resource_name
1858
      skip_resource_name:
1900
      skip_resource_name:
1859
	cmp	word [esi],0FFFFh
1901
	cmp	word [esi],0FFFFh
1860
	jne	skip_unicode_string
1902
	jne	skip_unicode_string
1861
	add	esi,4
1903
	add	esi,4
1862
	ret
1904
	ret
1863
      skip_unicode_string:
1905
      skip_unicode_string:
1864
	add	esi,2
1906
	add	esi,2
1865
	cmp	word [esi-2],0
1907
	cmp	word [esi-2],0
1866
	jne	skip_unicode_string
1908
	jne	skip_unicode_string
1867
	ret
1909
	ret
1868
      check_this_resource_name:
1910
      check_this_resource_name:
1869
	or	edx,edx
1911
	or	edx,edx
1870
	jz	resource_name_found
1912
	jz	resource_name_found
1871
	xor	ecx,ecx
1913
	xor	ecx,ecx
1872
      compare_with_current_resource_name:
1914
      compare_with_current_resource_name:
1873
	mov	ax,[esi+ecx]
1915
	mov	ax,[esi+ecx]
1874
	cmp	ax,[edx+ecx]
1916
	cmp	ax,[edx+ecx]
1875
	ja	check_next_resource_name
1917
	ja	check_next_resource_name
1876
	jb	resource_name_found
1918
	jb	resource_name_found
1877
	add	ecx,2
1919
	add	ecx,2
1878
	mov	ax,[esi+ecx]
1920
	mov	ax,[esi+ecx]
1879
	or	ax,[edx+ecx]
1921
	or	ax,[edx+ecx]
1880
	jnz	compare_with_current_resource_name
1922
	jnz	compare_with_current_resource_name
1881
	jmp	same_resource_name
1923
	jmp	same_resource_name
1882
      resource_name_found:
1924
      resource_name_found:
1883
	mov	edx,esi
1925
	mov	edx,esi
1884
      same_resource_name:
1926
      same_resource_name:
1885
	mov	eax,[esp]
1927
	mov	eax,[esp]
1886
	mov	[eax+8],edi
1928
	mov	[eax+8],edi
1887
      check_next_resource_name:
1929
      check_next_resource_name:
1888
	pop	esi
1930
	pop	esi
1889
	mov	eax,[esi+16]
1931
	mov	eax,[esi+16]
1890
	lea	esi,[esi+20+eax]
1932
	lea	esi,[esi+20+eax]
1891
	jmp	find_resource_name
1933
	jmp	find_resource_name
1892
      resource_name_ok:
1934
      resource_name_ok:
1893
	or	edx,edx
1935
	or	edx,edx
1894
	jz	resource_name_directory_done
1936
	jz	resource_name_directory_done
1895
	mov	ebx,edx
1937
	mov	ebx,edx
1896
      make_resource_name_entry:
1938
      make_resource_name_entry:
1897
	mov	eax,[esp]
1939
	mov	eax,[esp]
1898
	inc	word [eax+12]
1940
	inc	word [eax+12]
1899
	lea	eax,[edi+8]
1941
	lea	eax,[edi+8]
1900
	cmp	eax,[display_buffer]
1942
	cmp	eax,[display_buffer]
1901
	jae	out_of_memory
1943
	jae	out_of_memory
1902
	mov	eax,ebx
1944
	mov	eax,ebx
1903
	stos	dword [edi]
1945
	stos	dword [edi]
1904
	xor	eax,eax
1946
	xor	eax,eax
1905
	stos	dword [edi]
1947
	stos	dword [edi]
1906
	jmp	make_resource_name_directory
1948
	jmp	make_resource_name_directory
1907
      resource_name_directory_done:
1949
      resource_name_directory_done:
1908
	mov	ebx,-1
1950
	mov	ebx,-1
1909
      make_resource_id_directory:
1951
      make_resource_id_directory:
1910
	mov	esi,[free_additional_memory]
1952
	mov	esi,[free_additional_memory]
1911
	mov	edx,10000h
1953
	mov	edx,10000h
1912
      find_resource_id:
1954
      find_resource_id:
1913
	cmp	dword [esi],0
1955
	cmp	dword [esi],0
1914
	je	resource_id_ok
1956
	je	resource_id_ok
1915
	push	esi
1957
	push	esi
1916
	cmp	[esi+4],ebp
1958
	cmp	[esi+4],ebp
1917
	jne	check_next_resource_id
1959
	jne	check_next_resource_id
1918
	add	esi,20
1960
	add	esi,20
1919
	call	skip_resource_name
1961
	call	skip_resource_name
1920
	cmp	word [esi],0FFFFh
1962
	cmp	word [esi],0FFFFh
1921
	jne	check_next_resource_id
1963
	jne	check_next_resource_id
1922
	movzx	eax,word [esi+2]
1964
	movzx	eax,word [esi+2]
1923
	cmp	eax,ebx
1965
	cmp	eax,ebx
1924
	jle	check_next_resource_id
1966
	jle	check_next_resource_id
1925
	cmp	eax,edx
1967
	cmp	eax,edx
1926
	jg	check_next_resource_id
1968
	jg	check_next_resource_id
1927
	mov	edx,eax
1969
	mov	edx,eax
1928
	mov	eax,[esp]
1970
	mov	eax,[esp]
1929
	mov	[eax+8],edi
1971
	mov	[eax+8],edi
1930
      check_next_resource_id:
1972
      check_next_resource_id:
1931
	pop	esi
1973
	pop	esi
1932
	mov	eax,[esi+16]
1974
	mov	eax,[esi+16]
1933
	lea	esi,[esi+20+eax]
1975
	lea	esi,[esi+20+eax]
1934
	jmp	find_resource_id
1976
	jmp	find_resource_id
1935
      resource_id_ok:
1977
      resource_id_ok:
1936
	cmp	edx,10000h
1978
	cmp	edx,10000h
1937
	je	resource_id_directory_done
1979
	je	resource_id_directory_done
1938
	mov	ebx,edx
1980
	mov	ebx,edx
1939
      make_resource_id_entry:
1981
      make_resource_id_entry:
1940
	mov	eax,[esp]
1982
	mov	eax,[esp]
1941
	inc	word [eax+14]
1983
	inc	word [eax+14]
1942
	lea	eax,[edi+8]
1984
	lea	eax,[edi+8]
1943
	cmp	eax,[display_buffer]
1985
	cmp	eax,[display_buffer]
1944
	jae	out_of_memory
1986
	jae	out_of_memory
1945
	mov	eax,ebx
1987
	mov	eax,ebx
1946
	stos	dword [edi]
1988
	stos	dword [edi]
1947
	xor	eax,eax
1989
	xor	eax,eax
1948
	stos	dword [edi]
1990
	stos	dword [edi]
1949
	jmp	make_resource_id_directory
1991
	jmp	make_resource_id_directory
1950
      resource_id_directory_done:
1992
      resource_id_directory_done:
1951
	pop	eax
1993
	pop	eax
1952
	mov	esi,ebp
1994
	mov	esi,ebp
1953
	pop	ecx
1995
	pop	ecx
1954
	add	esi,8
1996
	add	esi,8
1955
	dec	cx
1997
	dec	cx
1956
	jnz	make_resource_directories
1998
	jnz	make_resource_directories
1957
      resource_directories_ok:
1999
      resource_directories_ok:
1958
	shr	ecx,16
2000
	shr	ecx,16
1959
	jnz	make_resource_directories
2001
	jnz	make_resource_directories
1960
	mov	esi,[resource_data]
2002
	mov	esi,[resource_data]
1961
	add	esi,10h
2003
	add	esi,10h
1962
	movzx	eax,word [esi-4]
2004
	movzx	eax,word [esi-4]
1963
	movzx	edx,word [esi-2]
2005
	movzx	edx,word [esi-2]
1964
	add	eax,edx
2006
	add	eax,edx
1965
	lea	esi,[esi+eax*8]
2007
	lea	esi,[esi+eax*8]
1966
	push	edi			; address of language directories
2008
	push	edi			; address of language directories
1967
      update_resource_directories:
2009
      update_resource_directories:
1968
	cmp	esi,[esp]
2010
	cmp	esi,[esp]
1969
	je	resource_directories_updated
2011
	je	resource_directories_updated
1970
	add	esi,10h
2012
	add	esi,10h
1971
	mov	ecx,[esi-4]
2013
	mov	ecx,[esi-4]
1972
	or	cx,cx
2014
	or	cx,cx
1973
	jz	language_directories_ok
2015
	jz	language_directories_ok
1974
      make_language_directories:
2016
      make_language_directories:
1975
	push	ecx
2017
	push	ecx
1976
	push	edi
2018
	push	edi
1977
	mov	edx,edi
2019
	mov	edx,edi
1978
	sub	edx,[resource_data]
2020
	sub	edx,[resource_data]
1979
	bts	edx,31
2021
	bts	edx,31
1980
	mov	[esi+4],edx
2022
	mov	[esi+4],edx
1981
	lea	eax,[edi+16]
2023
	lea	eax,[edi+16]
1982
	cmp	eax,[display_buffer]
2024
	cmp	eax,[display_buffer]
1983
	jae	out_of_memory
2025
	jae	out_of_memory
1984
	xor	eax,eax
2026
	xor	eax,eax
1985
	stos	dword [edi]
2027
	stos	dword [edi]
1986
	call	make_timestamp
2028
	call	make_timestamp
1987
	stos	dword [edi]
2029
	stos	dword [edi]
1988
	xor	eax,eax
2030
	xor	eax,eax
1989
	stos	dword [edi]
2031
	stos	dword [edi]
1990
	stos	dword [edi]
2032
	stos	dword [edi]
1991
	mov	ebp,esi
2033
	mov	ebp,esi
1992
	mov	ebx,-1
2034
	mov	ebx,-1
1993
      make_language_id_directory:
2035
      make_language_id_directory:
1994
	mov	esi,[free_additional_memory]
2036
	mov	esi,[free_additional_memory]
1995
	mov	edx,10000h
2037
	mov	edx,10000h
1996
      find_language_id:
2038
      find_language_id:
1997
	cmp	dword [esi],0
2039
	cmp	dword [esi],0
1998
	je	language_id_ok
2040
	je	language_id_ok
1999
	push	esi
2041
	push	esi
2000
	cmp	[esi+8],ebp
2042
	cmp	[esi+8],ebp
2001
	jne	check_next_language_id
2043
	jne	check_next_language_id
2002
	add	esi,20
2044
	add	esi,20
2003
	mov	eax,esi
2045
	mov	eax,esi
2004
	call	skip_resource_name
2046
	call	skip_resource_name
2005
	call	skip_resource_name
2047
	call	skip_resource_name
2006
	neg	eax
2048
	neg	eax
2007
	add	eax,esi
2049
	add	eax,esi
2008
	and	eax,11b
2050
	and	eax,11b
2009
	add	esi,eax
2051
	add	esi,eax
2010
      get_language_id:
2052
      get_language_id:
2011
	movzx	eax,word [esi+6]
2053
	movzx	eax,word [esi+6]
2012
	cmp	eax,ebx
2054
	cmp	eax,ebx
2013
	jle	check_next_language_id
2055
	jle	check_next_language_id
2014
	cmp	eax,edx
2056
	cmp	eax,edx
2015
	jge	check_next_language_id
2057
	jge	check_next_language_id
2016
	mov	edx,eax
2058
	mov	edx,eax
2017
	mov	eax,[esp]
2059
	mov	eax,[esp]
2018
	mov	dword [value],eax
2060
	mov	dword [value],eax
2019
      check_next_language_id:
2061
      check_next_language_id:
2020
	pop	esi
2062
	pop	esi
2021
	mov	eax,[esi+16]
2063
	mov	eax,[esi+16]
2022
	lea	esi,[esi+20+eax]
2064
	lea	esi,[esi+20+eax]
2023
	jmp	find_language_id
2065
	jmp	find_language_id
2024
      language_id_ok:
2066
      language_id_ok:
2025
	cmp	edx,10000h
2067
	cmp	edx,10000h
2026
	je	language_id_directory_done
2068
	je	language_id_directory_done
2027
	mov	ebx,edx
2069
	mov	ebx,edx
2028
      make_language_id_entry:
2070
      make_language_id_entry:
2029
	mov	eax,[esp]
2071
	mov	eax,[esp]
2030
	inc	word [eax+14]
2072
	inc	word [eax+14]
2031
	lea	eax,[edi+8]
2073
	lea	eax,[edi+8]
2032
	cmp	eax,[display_buffer]
2074
	cmp	eax,[display_buffer]
2033
	jae	out_of_memory
2075
	jae	out_of_memory
2034
	mov	eax,ebx
2076
	mov	eax,ebx
2035
	stos	dword [edi]
2077
	stos	dword [edi]
2036
	mov	eax,dword [value]
2078
	mov	eax,dword [value]
2037
	stos	dword [edi]
2079
	stos	dword [edi]
2038
	jmp	make_language_id_directory
2080
	jmp	make_language_id_directory
2039
      language_id_directory_done:
2081
      language_id_directory_done:
2040
	pop	eax
2082
	pop	eax
2041
	mov	esi,ebp
2083
	mov	esi,ebp
2042
	pop	ecx
2084
	pop	ecx
2043
	add	esi,8
2085
	add	esi,8
2044
	dec	cx
2086
	dec	cx
2045
	jnz	make_language_directories
2087
	jnz	make_language_directories
2046
      language_directories_ok:
2088
      language_directories_ok:
2047
	shr	ecx,16
2089
	shr	ecx,16
2048
	jnz	make_language_directories
2090
	jnz	make_language_directories
2049
	jmp	update_resource_directories
2091
	jmp	update_resource_directories
2050
      resource_directories_updated:
2092
      resource_directories_updated:
2051
	mov	esi,[resource_data]
2093
	mov	esi,[resource_data]
2052
	push	edi
2094
	push	edi
2053
      make_name_strings:
2095
      make_name_strings:
2054
	add	esi,10h
2096
	add	esi,10h
2055
	movzx	eax,word [esi-2]
2097
	movzx	eax,word [esi-2]
2056
	movzx	ecx,word [esi-4]
2098
	movzx	ecx,word [esi-4]
2057
	add	eax,ecx
2099
	add	eax,ecx
2058
	lea	eax,[esi+eax*8]
2100
	lea	eax,[esi+eax*8]
2059
	push	eax
2101
	push	eax
2060
	or	ecx,ecx
2102
	or	ecx,ecx
2061
	jz	string_entries_processed
2103
	jz	string_entries_processed
2062
      process_string_entries:
2104
      process_string_entries:
2063
	push	ecx
2105
	push	ecx
2064
	mov	edx,edi
2106
	mov	edx,edi
2065
	sub	edx,[resource_data]
2107
	sub	edx,[resource_data]
2066
	bts	edx,31
2108
	bts	edx,31
2067
	xchg	[esi],edx
2109
	xchg	[esi],edx
2068
	mov	ebx,edi
2110
	mov	ebx,edi
2069
	xor	ax,ax
2111
	xor	ax,ax
2070
	stos	word [edi]
2112
	stos	word [edi]
2071
      copy_string_data:
2113
      copy_string_data:
2072
	lea	eax,[edi+2]
2114
	lea	eax,[edi+2]
2073
	cmp	eax,[display_buffer]
2115
	cmp	eax,[display_buffer]
2074
	jae	out_of_memory
2116
	jae	out_of_memory
2075
	mov	ax,[edx]
2117
	mov	ax,[edx]
2076
	or	ax,ax
2118
	or	ax,ax
2077
	jz	string_data_copied
2119
	jz	string_data_copied
2078
	stos	word [edi]
2120
	stos	word [edi]
2079
	inc	word [ebx]
2121
	inc	word [ebx]
2080
	add	edx,2
2122
	add	edx,2
2081
	jmp	copy_string_data
2123
	jmp	copy_string_data
2082
      string_data_copied:
2124
      string_data_copied:
2083
	add	esi,8
2125
	add	esi,8
2084
	pop	ecx
2126
	pop	ecx
2085
	loop	process_string_entries
2127
	loop	process_string_entries
2086
      string_entries_processed:
2128
      string_entries_processed:
2087
	pop	esi
2129
	pop	esi
2088
	cmp	esi,[esp]
2130
	cmp	esi,[esp]
2089
	jb	make_name_strings
2131
	jb	make_name_strings
2090
	mov	eax,edi
2132
	mov	eax,edi
2091
	sub	eax,[resource_data]
2133
	sub	eax,[resource_data]
2092
	test	al,11b
2134
	test	al,11b
2093
	jz	resource_strings_alignment_ok
2135
	jz	resource_strings_alignment_ok
2094
	xor	ax,ax
2136
	xor	ax,ax
2095
	stos	word [edi]
2137
	stos	word [edi]
2096
      resource_strings_alignment_ok:
2138
      resource_strings_alignment_ok:
2097
	pop	edx
2139
	pop	edx
2098
	pop	ebx			; address of language directories
2140
	pop	ebx			; address of language directories
2099
	mov	ebp,edi
2141
	mov	ebp,edi
2100
      update_language_directories:
2142
      update_language_directories:
2101
	add	ebx,10h
2143
	add	ebx,10h
2102
	movzx	eax,word [ebx-2]
2144
	movzx	eax,word [ebx-2]
2103
	movzx	ecx,word [ebx-4]
2145
	movzx	ecx,word [ebx-4]
2104
	add	ecx,eax
2146
	add	ecx,eax
2105
      make_data_records:
2147
      make_data_records:
2106
	push	ecx
2148
	push	ecx
2107
	mov	esi,edi
2149
	mov	esi,edi
2108
	sub	esi,[resource_data]
2150
	sub	esi,[resource_data]
2109
	xchg	esi,[ebx+4]
2151
	xchg	esi,[ebx+4]
2110
	lea	eax,[edi+16]
2152
	lea	eax,[edi+16]
2111
	cmp	eax,[display_buffer]
2153
	cmp	eax,[display_buffer]
2112
	jae	out_of_memory
2154
	jae	out_of_memory
2113
	mov	eax,esi
2155
	mov	eax,esi
2114
	stos	dword [edi]
2156
	stos	dword [edi]
2115
	mov	eax,[esi+12]
2157
	mov	eax,[esi+12]
2116
	stos	dword [edi]
2158
	stos	dword [edi]
2117
	xor	eax,eax
2159
	xor	eax,eax
2118
	stos	dword [edi]
2160
	stos	dword [edi]
2119
	stos	dword [edi]
2161
	stos	dword [edi]
2120
	pop	ecx
2162
	pop	ecx
2121
	add	ebx,8
2163
	add	ebx,8
2122
	loop	make_data_records
2164
	loop	make_data_records
2123
	cmp	ebx,edx
2165
	cmp	ebx,edx
2124
	jb	update_language_directories
2166
	jb	update_language_directories
2125
	pop	ebx			; file handle
2167
	pop	ebx			; file handle
2126
	mov	esi,ebp
2168
	mov	esi,ebp
2127
	mov	ebp,edi
2169
	mov	ebp,edi
2128
      update_data_records:
2170
      update_data_records:
2129
	push	ebp
2171
	push	ebp
2130
	mov	ecx,edi
2172
	mov	ecx,edi
2131
	mov	eax,[current_section]
2173
	mov	eax,[current_section]
2132
	sub	ecx,[eax+14h]
2174
	sub	ecx,[eax+14h]
2133
	add	ecx,[eax+0Ch]
2175
	add	ecx,[eax+0Ch]
2134
	xchg	ecx,[esi]
2176
	xchg	ecx,[esi]
2135
	mov	edx,[ecx]
2177
	mov	edx,[ecx]
2136
	xor	al,al
2178
	xor	al,al
2137
	call	lseek
2179
	call	lseek
2138
	mov	edx,edi
2180
	mov	edx,edi
2139
	mov	ecx,[esi+4]
2181
	mov	ecx,[esi+4]
2140
	add	edi,ecx
2182
	add	edi,ecx
2141
	cmp	edi,[display_buffer]
2183
	cmp	edi,[display_buffer]
2142
	ja	out_of_memory
2184
	ja	out_of_memory
2143
	call	read
2185
	call	read
2144
	mov	eax,edi
2186
	mov	eax,edi
2145
	sub	eax,[resource_data]
2187
	sub	eax,[resource_data]
2146
	and	eax,11b
2188
	and	eax,11b
2147
	jz	resource_data_alignment_ok
2189
	jz	resource_data_alignment_ok
2148
	mov	ecx,4
2190
	mov	ecx,4
2149
	sub	ecx,eax
2191
	sub	ecx,eax
2150
	xor	al,al
2192
	xor	al,al
2151
	rep	stos byte [edi]
2193
	rep	stos byte [edi]
2152
      resource_data_alignment_ok:
2194
      resource_data_alignment_ok:
2153
	pop	ebp
2195
	pop	ebp
2154
	add	esi,16
2196
	add	esi,16
2155
	cmp	esi,ebp
2197
	cmp	esi,ebp
2156
	jb	update_data_records
2198
	jb	update_data_records
2157
	pop	esi
2199
	pop	esi
2158
	call	close
2200
	call	close
2159
	mov	eax,edi
2201
	mov	eax,edi
2160
	sub	eax,[resource_data]
2202
	sub	eax,[resource_data]
2161
	mov	[resource_size],eax
2203
	mov	[resource_size],eax
2162
      resource_done:
2204
      resource_done:
2163
	ret
2205
	ret
2164
close_pe:
2206
close_pe:
2165
	call	close_pe_section
2207
	call	close_pe_section
2166
	mov	edx,[code_start]
2208
	mov	edx,[code_start]
2167
	mov	[edx+50h],eax
2209
	mov	[edx+50h],eax
2168
	call	make_timestamp
2210
	call	make_timestamp
2169
	mov	edx,[code_start]
2211
	mov	edx,[code_start]
2170
	mov	[edx+8],eax
2212
	mov	[edx+8],eax
2171
	mov	eax,[number_of_relocations]
2213
	mov	eax,[number_of_sections]
2172
	cmp	eax,-1
-
 
2173
	je	pe_relocations_ok
-
 
2174
	shl	eax,2
-
 
2175
	sub	[free_additional_memory],eax
-
 
2176
	btr	[resolver_flags],0
-
 
2177
	jnc	pe_relocations_ok
-
 
2178
	or	[next_pass_needed],-1
-
 
2179
      pe_relocations_ok:
-
 
2180
	mov	eax,[number_of_sections]
-
 
2181
	mov	[edx+6],ax
2214
	mov	[edx+6],ax
2182
	imul	eax,28h
2215
	imul	eax,28h
2183
	movzx	ecx,word [edx+14h]
2216
	movzx	ecx,word [edx+14h]
2184
	lea	eax,[eax+18h+ecx]
2217
	lea	eax,[eax+18h+ecx]
2185
	add	eax,[stub_size]
2218
	add	eax,[stub_size]
2186
	mov	ecx,[edx+3Ch]
2219
	mov	ecx,[edx+3Ch]
2187
	dec	ecx
2220
	dec	ecx
2188
	add	eax,ecx
2221
	add	eax,ecx
2189
	not	ecx
2222
	not	ecx
2190
	and	eax,ecx
2223
	and	eax,ecx
2191
	cmp	eax,[edx+54h]
2224
	cmp	eax,[edx+54h]
2192
	je	pe_sections_ok
2225
	je	pe_sections_ok
2193
	or	[next_pass_needed],-1
2226
	or	[next_pass_needed],-1
2194
      pe_sections_ok:
2227
      pe_sections_ok:
2195
	xor	ecx,ecx
2228
	xor	ecx,ecx
2196
	add	edx,78h
2229
	add	edx,78h
2197
	test	[format_flags],8
2230
	test	[format_flags],4
2198
	jz	process_directories
2231
	jz	process_directories
2199
	add	edx,10h
2232
	add	edx,10h
2200
      process_directories:
2233
      process_directories:
2201
	mov	eax,[edx+ecx*8]
2234
	mov	eax,[edx+ecx*8]
2202
	or	eax,eax
2235
	or	eax,eax
2203
	jz	directory_ok
2236
	jz	directory_ok
2204
	cmp	dword [edx+ecx*8+4],-1
2237
	cmp	dword [edx+ecx*8+4],-1
2205
	jne	directory_ok
2238
	jne	directory_ok
2206
      section_data:
2239
      section_data:
2207
	mov	ebx,[edx+ecx*8]
2240
	mov	ebx,[edx+ecx*8]
2208
	mov	eax,[ebx+0Ch]
2241
	mov	eax,[ebx+0Ch]
2209
	mov	[edx+ecx*8],eax 	; directory rva
2242
	mov	[edx+ecx*8],eax 	; directory rva
2210
	mov	eax,[ebx+8]
2243
	mov	eax,[ebx+8]
2211
	mov	[edx+ecx*8+4],eax	; directory size
2244
	mov	[edx+ecx*8+4],eax	; directory size
2212
      directory_ok:
2245
      directory_ok:
2213
	inc	cl
2246
	inc	cl
2214
	cmp	cl,10h
2247
	cmp	cl,10h
2215
	jb	process_directories
2248
	jb	process_directories
2216
	mov	ebx,[code_start]
2249
	cmp	dword [edx+5*8],0
-
 
2250
	jne	finish_pe_relocations
-
 
2251
	mov	eax,[number_of_relocations]
-
 
2252
	shl	eax,2
-
 
2253
	sub	[free_additional_memory],eax
-
 
2254
	btr	[resolver_flags],0
-
 
2255
	jnc	pe_relocations_ok
-
 
2256
	or	[next_pass_needed],-1
-
 
2257
	jmp	pe_relocations_ok
-
 
2258
      finish_pe_relocations:
-
 
2259
	push	edi
-
 
2260
	mov	edi,[reserved_fixups]
-
 
2261
	call	make_fixups
-
 
2262
	pop	edi
-
 
2263
	add	[actual_fixups_size],eax
-
 
2264
	cmp	eax,[reserved_fixups_size]
-
 
2265
	je	pe_relocations_ok
-
 
2266
	or	[next_pass_needed],-1
-
 
2267
      pe_relocations_ok:
-
 
2268
	mov	ebx,[code_start]
2217
	sub	ebx,[stub_size]
2269
	sub	ebx,[stub_size]
2218
	mov	ecx,edi
2270
	mov	ecx,edi
2219
	sub	ecx,ebx
2271
	sub	ecx,ebx
2220
	mov	ebp,ecx
2272
	mov	ebp,ecx
2221
	shr	ecx,1
2273
	shr	ecx,1
2222
	xor	eax,eax
2274
	xor	eax,eax
2223
	cdq
2275
	cdq
2224
      calculate_checksum:
2276
      calculate_checksum:
2225
	mov	dx,[ebx]
2277
	mov	dx,[ebx]
2226
	add	eax,edx
2278
	add	eax,edx
2227
	mov	dx,ax
2279
	mov	dx,ax
2228
	shr	eax,16
2280
	shr	eax,16
2229
	add	eax,edx
2281
	add	eax,edx
2230
	add	ebx,2
2282
	add	ebx,2
2231
	loop	calculate_checksum
2283
	loop	calculate_checksum
2232
	add	eax,ebp
2284
	add	eax,ebp
2233
	mov	ebx,[code_start]
2285
	mov	ebx,[code_start]
2234
	mov	[ebx+58h],eax
2286
	mov	[ebx+58h],eax
2235
	ret
2287
	ret
2236
 
2288
 
2237
format_coff:
2289
format_coff:
2238
	mov	eax,[additional_memory]
2290
	mov	eax,[additional_memory]
2239
	mov	[symbols_stream],eax
2291
	mov	[symbols_stream],eax
2240
	mov	ebx,eax
2292
	mov	ebx,eax
2241
	add	eax,20h
2293
	add	eax,20h
2242
	cmp	eax,[structures_buffer]
2294
	cmp	eax,[structures_buffer]
2243
	jae	out_of_memory
2295
	jae	out_of_memory
2244
	mov	[free_additional_memory],eax
2296
	mov	[free_additional_memory],eax
2245
	xor	eax,eax
2297
	xor	eax,eax
2246
	mov	[ebx],al
2298
	mov	[ebx],al
2247
	mov	[ebx+4],eax
2299
	mov	[ebx+4],eax
2248
	mov	[ebx+8],edi
2300
	mov	[ebx+8],edi
2249
	mov	al,4
2301
	mov	al,4
2250
	mov	[ebx+10h],eax
2302
	mov	[ebx+10h],eax
2251
	mov	al,60h
2303
	mov	al,60h
2252
	bt	[format_flags],0
2304
	bt	[format_flags],0
2253
	jnc	flat_section_flags_ok
2305
	jnc	flat_section_flags_ok
2254
	or	eax,0E0000000h
2306
	or	eax,0E0000000h
2255
      flat_section_flags_ok:
2307
      flat_section_flags_ok:
2256
	mov	dword [ebx+14h],eax
2308
	mov	dword [ebx+14h],eax
2257
	mov	[current_section],ebx
2309
	mov	[current_section],ebx
2258
	xor	eax,eax
2310
	xor	eax,eax
2259
	mov	[number_of_sections],eax
2311
	mov	[number_of_sections],eax
2260
	mov	dword [org_origin],edi
2312
	mov	dword [org_origin],edi
2261
	mov	dword [org_origin+4],eax
2313
	mov	dword [org_origin+4],eax
2262
	mov	[org_registers],eax
2314
	mov	[org_registers],eax
2263
	mov	[org_start],edi
2315
	mov	[org_start],edi
2264
	mov	[org_symbol],ebx
2316
	mov	[org_symbol],ebx
2265
	mov	[labels_type],2
2317
	mov	[labels_type],2
2266
	mov	[code_type],32
2318
	mov	[code_type],32
2267
	test	[format_flags],8
2319
	test	[format_flags],8
2268
	jz	format_defined
2320
	jz	format_defined
2269
	mov	[labels_type],4
2321
	mov	[labels_type],4
2270
	mov	[code_type],64
2322
	mov	[code_type],64
2271
	jmp	format_defined
2323
	jmp	format_defined
2272
coff_section:
2324
coff_section:
2273
	call	close_coff_section
2325
	call	close_coff_section
2274
	mov	ebx,[free_additional_memory]
2326
	mov	ebx,[free_additional_memory]
2275
	lea	eax,[ebx+20h]
2327
	lea	eax,[ebx+20h]
2276
	cmp	eax,[structures_buffer]
2328
	cmp	eax,[structures_buffer]
2277
	jae	out_of_memory
2329
	jae	out_of_memory
2278
	mov	[free_additional_memory],eax
2330
	mov	[free_additional_memory],eax
2279
	mov	[current_section],ebx
2331
	mov	[current_section],ebx
2280
	inc	[number_of_sections]
2332
	inc	[number_of_sections]
2281
	xor	eax,eax
2333
	xor	eax,eax
2282
	mov	[ebx],al
2334
	mov	[ebx],al
2283
	mov	[ebx+8],edi
2335
	mov	[ebx+8],edi
2284
	mov	dword [org_origin],edi
2336
	mov	dword [org_origin],edi
2285
	mov	dword [org_origin+4],eax
2337
	mov	dword [org_origin+4],eax
2286
	mov	[org_registers],eax
2338
	mov	[org_registers],eax
2287
	mov	[org_start],edi
2339
	mov	[org_start],edi
2288
	mov	[org_symbol],ebx
2340
	mov	[org_symbol],ebx
2289
	mov	[labels_type],2
2341
	mov	[labels_type],2
2290
	test	[format_flags],8
2342
	test	[format_flags],8
2291
	jz	coff_labels_type_ok
2343
	jz	coff_labels_type_ok
2292
	mov	[labels_type],4
2344
	mov	[labels_type],4
2293
      coff_labels_type_ok:
2345
      coff_labels_type_ok:
2294
	mov	[ebx+10h],eax
2346
	mov	[ebx+10h],eax
2295
	mov	[ebx+14h],eax
2347
	mov	[ebx+14h],eax
2296
	lods	word [esi]
2348
	lods	word [esi]
2297
	cmp	ax,'('
2349
	cmp	ax,'('
2298
	jne	invalid_argument
2350
	jne	invalid_argument
2299
	mov	[ebx+4],esi
2351
	mov	[ebx+4],esi
2300
	mov	ecx,[esi]
2352
	mov	ecx,[esi]
2301
	lea	esi,[esi+4+ecx+1]
2353
	lea	esi,[esi+4+ecx+1]
2302
	cmp	ecx,8
2354
	cmp	ecx,8
2303
	ja	name_too_long
2355
	ja	name_too_long
2304
      coff_section_flags:
2356
      coff_section_flags:
2305
	cmp	byte [esi],1Ch
2357
	cmp	byte [esi],8Ch
2306
	je	coff_section_alignment
2358
	je	coff_section_alignment
2307
	cmp	byte [esi],19h
2359
	cmp	byte [esi],19h
2308
	jne	coff_section_settings_ok
2360
	jne	coff_section_settings_ok
2309
	inc	esi
2361
	inc	esi
2310
	lods	byte [esi]
2362
	lods	byte [esi]
2311
	bt	[format_flags],0
2363
	bt	[format_flags],0
2312
	jc	coff_section_flag_ok
2364
	jc	coff_section_flag_ok
2313
	cmp	al,7
2365
	cmp	al,7
2314
	ja	invalid_argument
2366
	ja	invalid_argument
2315
      coff_section_flag_ok:
2367
      coff_section_flag_ok:
2316
	mov	cl,al
2368
	mov	cl,al
2317
	mov	eax,1
2369
	mov	eax,1
2318
	shl	eax,cl
2370
	shl	eax,cl
2319
	test	dword [ebx+14h],eax
2371
	test	dword [ebx+14h],eax
2320
	jnz	setting_already_specified
2372
	jnz	setting_already_specified
2321
	or	dword [ebx+14h],eax
2373
	or	dword [ebx+14h],eax
2322
	jmp	coff_section_flags
2374
	jmp	coff_section_flags
2323
      coff_section_alignment:
2375
      coff_section_alignment:
2324
	bt	[format_flags],0
2376
	bt	[format_flags],0
2325
	jnc	invalid_argument
2377
	jnc	invalid_argument
2326
	inc	esi
2378
	inc	esi
2327
	lods	byte [esi]
2379
	lods	byte [esi]
2328
	or	al,al
2380
	cmp	al,'('
2329
	jnz	invalid_argument
-
 
2330
	lods	byte [esi]
-
 
2331
	cmp	al,'('
-
 
2332
	jne	invalid_argument
2381
	jne	invalid_argument
2333
	cmp	byte [esi],'.'
2382
	cmp	byte [esi],'.'
2334
	je	invalid_value
2383
	je	invalid_value
2335
	push	ebx
2384
	push	ebx
2336
	call	get_dword_value
2385
	call	get_count_value
2337
	pop	ebx
2386
	pop	ebx
2338
	cmp	[value_type],0
2387
	mov	edx,eax
2339
	jne	invalid_use_of_symbol
-
 
2340
	mov	edx,eax
-
 
2341
	dec	edx
2388
	dec	edx
2342
	test	eax,edx
2389
	test	eax,edx
2343
	jnz	invalid_value
2390
	jnz	invalid_value
2344
	or	eax,eax
2391
	or	eax,eax
2345
	jz	invalid_value
2392
	jz	invalid_value
2346
	cmp	eax,2000h
2393
	cmp	eax,2000h
2347
	ja	invalid_value
2394
	ja	invalid_value
2348
	bsf	edx,eax
2395
	bsf	edx,eax
2349
	inc	edx
2396
	inc	edx
2350
	shl	edx,20
2397
	shl	edx,20
2351
	or	[ebx+14h],edx
2398
	or	[ebx+14h],edx
2352
	xchg	[ebx+10h],eax
2399
	xchg	[ebx+10h],eax
2353
	or	eax,eax
2400
	or	eax,eax
2354
	jnz	setting_already_specified
2401
	jnz	setting_already_specified
2355
	jmp	coff_section_flags
2402
	jmp	coff_section_flags
2356
      coff_section_settings_ok:
2403
      coff_section_settings_ok:
2357
	cmp	dword [ebx+10h],0
2404
	cmp	dword [ebx+10h],0
2358
	jne	instruction_assembled
2405
	jne	instruction_assembled
2359
	mov	dword [ebx+10h],4
2406
	mov	dword [ebx+10h],4
2360
	bt	[format_flags],0
2407
	bt	[format_flags],0
2361
	jnc	instruction_assembled
2408
	jnc	instruction_assembled
2362
	or	dword [ebx+14h],300000h
2409
	or	dword [ebx+14h],300000h
2363
	jmp	instruction_assembled
2410
	jmp	instruction_assembled
2364
      close_coff_section:
2411
      close_coff_section:
2365
	mov	ebx,[current_section]
2412
	mov	ebx,[current_section]
2366
	mov	eax,edi
2413
	mov	eax,edi
2367
	mov	edx,[ebx+8]
2414
	mov	edx,[ebx+8]
2368
	sub	eax,edx
2415
	sub	eax,edx
2369
	mov	[ebx+0Ch],eax
2416
	mov	[ebx+0Ch],eax
2370
	xor	eax,eax
2417
	xor	eax,eax
2371
	xchg	[undefined_data_end],eax
2418
	xchg	[undefined_data_end],eax
2372
	cmp	eax,edi
2419
	cmp	eax,edi
2373
	jne	coff_section_ok
2420
	jne	coff_section_ok
2374
	cmp	edx,[undefined_data_start]
2421
	cmp	edx,[undefined_data_start]
2375
	jne	coff_section_ok
2422
	jne	coff_section_ok
2376
	mov	edi,edx
2423
	mov	edi,edx
2377
	or	byte [ebx+14h],80h
2424
	or	byte [ebx+14h],80h
2378
      coff_section_ok:
2425
      coff_section_ok:
2379
	ret
2426
	ret
2380
mark_coff_relocation:
2427
mark_coff_relocation:
2381
	cmp	[value_type],3
2428
	cmp	[value_type],3
2382
	je	coff_relocation_relative
2429
	je	coff_relocation_relative
2383
	push	ebx eax
2430
	push	ebx eax
2384
	test	[format_flags],8
2431
	test	[format_flags],8
2385
	jnz	coff_64bit_relocation
2432
	jnz	coff_64bit_relocation
2386
	mov	al,6
2433
	mov	al,6
2387
	cmp	[value_type],5
2434
	cmp	[value_type],5
2388
	jne	coff_relocation
2435
	jne	coff_relocation
2389
	inc	al
2436
	inc	al
2390
	jmp	coff_relocation
2437
	jmp	coff_relocation
2391
      coff_64bit_relocation:
2438
      coff_64bit_relocation:
2392
	mov	al,1
2439
	mov	al,1
2393
	cmp	[value_type],4
2440
	cmp	[value_type],4
2394
	je	coff_relocation
2441
	je	coff_relocation
2395
	mov	al,2
2442
	mov	al,2
2396
	cmp	[value_type],5
2443
	cmp	[value_type],5
2397
	jne	coff_relocation
2444
	jne	coff_relocation
2398
	inc	al
2445
	inc	al
2399
	jmp	coff_relocation
2446
	jmp	coff_relocation
2400
      coff_relocation_relative:
2447
      coff_relocation_relative:
2401
	push	ebx
2448
	push	ebx
2402
	bt	[format_flags],0
2449
	bt	[format_flags],0
2403
	jnc	relative_ok
2450
	jnc	relative_ok
2404
	mov	ebx,[current_section]
2451
	mov	ebx,[current_section]
2405
	mov	ebx,[ebx+8]
2452
	mov	ebx,[ebx+8]
2406
	sub	ebx,edi
2453
	sub	ebx,edi
2407
	sub	eax,ebx
2454
	sub	eax,ebx
2408
	add	eax,4
2455
	add	eax,4
2409
      relative_ok:
2456
      relative_ok:
2410
	push	eax
2457
	push	eax
2411
	mov	al,20
2458
	mov	al,20
2412
	test	[format_flags],8
2459
	test	[format_flags],8
2413
	jnz	relative_coff_64bit_relocation
2460
	jnz	relative_coff_64bit_relocation
2414
	cmp	[labels_type],2
2461
	cmp	[labels_type],2
2415
	jne	invalid_use_of_symbol
2462
	jne	invalid_use_of_symbol
2416
	jmp	coff_relocation
2463
	jmp	coff_relocation
2417
      relative_coff_64bit_relocation:
2464
      relative_coff_64bit_relocation:
2418
	mov	al,4
2465
	mov	al,4
2419
	cmp	[labels_type],4
2466
	cmp	[labels_type],4
2420
	jne	invalid_use_of_symbol
2467
	jne	invalid_use_of_symbol
2421
      coff_relocation:
2468
      coff_relocation:
2422
	mov	ebx,[free_additional_memory]
2469
	mov	ebx,[free_additional_memory]
2423
	add	ebx,0Ch
2470
	add	ebx,0Ch
2424
	cmp	ebx,[structures_buffer]
2471
	cmp	ebx,[structures_buffer]
2425
	jae	out_of_memory
2472
	jae	out_of_memory
2426
	mov	[free_additional_memory],ebx
2473
	mov	[free_additional_memory],ebx
2427
	mov	byte [ebx-0Ch],al
2474
	mov	byte [ebx-0Ch],al
2428
	mov	eax,[current_section]
2475
	mov	eax,[current_section]
2429
	mov	eax,[eax+8]
2476
	mov	eax,[eax+8]
2430
	neg	eax
2477
	neg	eax
2431
	add	eax,edi
2478
	add	eax,edi
2432
	mov	[ebx-0Ch+4],eax
2479
	mov	[ebx-0Ch+4],eax
2433
	mov	eax,[symbol_identifier]
2480
	mov	eax,[symbol_identifier]
2434
	mov	[ebx-0Ch+8],eax
2481
	mov	[ebx-0Ch+8],eax
2435
	pop	eax ebx
2482
	pop	eax ebx
2436
	ret
2483
	ret
2437
close_coff:
2484
close_coff:
2438
	call	close_coff_section
2485
	call	close_coff_section
2439
	cmp	[next_pass_needed],0
2486
	cmp	[next_pass_needed],0
2440
	je	coff_closed
2487
	je	coff_closed
2441
	mov	eax,[symbols_stream]
2488
	mov	eax,[symbols_stream]
2442
	mov	[free_additional_memory],eax
2489
	mov	[free_additional_memory],eax
2443
      coff_closed:
2490
      coff_closed:
2444
	ret
2491
	ret
2445
coff_formatter:
2492
coff_formatter:
2446
	sub	edi,[code_start]
2493
	sub	edi,[code_start]
2447
	mov	[code_size],edi
2494
	mov	[code_size],edi
2448
	call	prepare_default_section
2495
	call	prepare_default_section
2449
	mov	edi,[free_additional_memory]
2496
	mov	edi,[free_additional_memory]
2450
	mov	ebx,edi
2497
	mov	ebx,edi
2451
	mov	ecx,28h shr 2
2498
	mov	ecx,28h shr 2
2452
	imul	ecx,[number_of_sections]
2499
	imul	ecx,[number_of_sections]
2453
	add	ecx,14h shr 2
2500
	add	ecx,14h shr 2
2454
	lea	eax,[edi+ecx*4]
2501
	lea	eax,[edi+ecx*4]
2455
	cmp	eax,[structures_buffer]
2502
	cmp	eax,[structures_buffer]
2456
	jae	out_of_memory
2503
	jae	out_of_memory
2457
	xor	eax,eax
2504
	xor	eax,eax
2458
	rep	stos dword [edi]
2505
	rep	stos dword [edi]
2459
	mov	word [ebx],14Ch
2506
	mov	word [ebx],14Ch
2460
	test	[format_flags],8
2507
	test	[format_flags],8
2461
	jz	coff_magic_ok
2508
	jz	coff_magic_ok
2462
	mov	word [ebx],8664h
2509
	mov	word [ebx],8664h
2463
      coff_magic_ok:
2510
      coff_magic_ok:
2464
	mov	word [ebx+12h],104h
2511
	mov	word [ebx+12h],104h
2465
	bt	[format_flags],0
2512
	bt	[format_flags],0
2466
	jnc	coff_flags_ok
2513
	jnc	coff_flags_ok
2467
	or	byte [ebx+12h],80h
2514
	or	byte [ebx+12h],80h
2468
      coff_flags_ok:
2515
      coff_flags_ok:
2469
	push	ebx
2516
	push	ebx
2470
	call	make_timestamp
2517
	call	make_timestamp
2471
	pop	ebx
2518
	pop	ebx
2472
	mov	[ebx+4],eax
2519
	mov	[ebx+4],eax
2473
	mov	eax,[number_of_sections]
2520
	mov	eax,[number_of_sections]
2474
	mov	[ebx+2],ax
2521
	mov	[ebx+2],ax
2475
	mov	esi,[symbols_stream]
2522
	mov	esi,[symbols_stream]
2476
	xor	eax,eax
2523
	xor	eax,eax
2477
	xor	ecx,ecx
2524
	xor	ecx,ecx
2478
      enumerate_symbols:
2525
      enumerate_symbols:
2479
	cmp	esi,[free_additional_memory]
2526
	cmp	esi,[free_additional_memory]
2480
	je	symbols_enumerated
2527
	je	symbols_enumerated
2481
	mov	dl,[esi]
2528
	mov	dl,[esi]
2482
	or	dl,dl
2529
	or	dl,dl
2483
	jz	enumerate_section
2530
	jz	enumerate_section
2484
	cmp	dl,0C0h
2531
	cmp	dl,0C0h
2485
	jae	enumerate_public
2532
	jae	enumerate_public
2486
	cmp	dl,80h
2533
	cmp	dl,80h
2487
	jae	enumerate_extrn
2534
	jae	enumerate_extrn
2488
	add	esi,0Ch
2535
	add	esi,0Ch
2489
	jmp	enumerate_symbols
2536
	jmp	enumerate_symbols
2490
      enumerate_section:
2537
      enumerate_section:
2491
	mov	edx,eax
2538
	mov	edx,eax
2492
	shl	edx,8
2539
	shl	edx,8
2493
	mov	[esi],edx
2540
	mov	[esi],edx
2494
	inc	eax
2541
	inc	eax
2495
	inc	ecx
2542
	inc	ecx
2496
	mov	[esi+1Eh],cx
2543
	mov	[esi+1Eh],cx
2497
	add	esi,20h
2544
	add	esi,20h
2498
	jmp	enumerate_symbols
2545
	jmp	enumerate_symbols
2499
      enumerate_public:
2546
      enumerate_public:
2500
	mov	edx,eax
2547
	mov	edx,eax
2501
	shl	edx,8
2548
	shl	edx,8
2502
	mov	dl,[esi]
2549
	mov	dl,[esi]
2503
	mov	[esi],edx
2550
	mov	[esi],edx
2504
	mov	edx,[esi+8]
2551
	mov	edx,[esi+8]
2505
	add	esi,10h
2552
	add	esi,10h
2506
	inc	eax
2553
	inc	eax
2507
	cmp	byte [edx+11],2
2554
	cmp	byte [edx+11],2
2508
	jne	enumerate_symbols
2555
	jne	enumerate_symbols
2509
	mov	edx,[edx+20]
2556
	mov	edx,[edx+20]
2510
	cmp	byte [edx],0C0h
2557
	cmp	byte [edx],0C0h
2511
	jae	enumerate_symbols
2558
	jae	enumerate_symbols
2512
	cmp	byte [edx],80h
2559
	cmp	byte [edx],80h
2513
	jb	enumerate_symbols
2560
	jb	enumerate_symbols
2514
	inc	eax
2561
	inc	eax
2515
	jmp	enumerate_symbols
2562
	jmp	enumerate_symbols
2516
      enumerate_extrn:
2563
      enumerate_extrn:
2517
	mov	edx,eax
2564
	mov	edx,eax
2518
	shl	edx,8
2565
	shl	edx,8
2519
	mov	dl,[esi]
2566
	mov	dl,[esi]
2520
	mov	[esi],edx
2567
	mov	[esi],edx
2521
	add	esi,0Ch
2568
	add	esi,0Ch
2522
	inc	eax
2569
	inc	eax
2523
	jmp	enumerate_symbols
2570
	jmp	enumerate_symbols
2524
      prepare_default_section:
2571
      prepare_default_section:
2525
	mov	ebx,[symbols_stream]
2572
	mov	ebx,[symbols_stream]
2526
	cmp	dword [ebx+0Ch],0
2573
	cmp	dword [ebx+0Ch],0
2527
	jne	default_section_ok
2574
	jne	default_section_ok
2528
	cmp	[number_of_sections],0
2575
	cmp	[number_of_sections],0
2529
	je	default_section_ok
2576
	je	default_section_ok
2530
	mov	edx,ebx
2577
	mov	edx,ebx
2531
      find_references_to_default_section:
2578
      find_references_to_default_section:
2532
	cmp	ebx,[free_additional_memory]
2579
	cmp	ebx,[free_additional_memory]
2533
	jne	check_reference
2580
	jne	check_reference
2534
	add	[symbols_stream],20h
2581
	add	[symbols_stream],20h
2535
	ret
2582
	ret
2536
      check_reference:
2583
      check_reference:
2537
	mov	al,[ebx]
2584
	mov	al,[ebx]
2538
	or	al,al
2585
	or	al,al
2539
	jz	skip_other_section
2586
	jz	skip_other_section
2540
	cmp	al,0C0h
2587
	cmp	al,0C0h
2541
	jae	check_public_reference
2588
	jae	check_public_reference
2542
	cmp	al,80h
2589
	cmp	al,80h
2543
	jae	next_reference
2590
	jae	next_reference
2544
	cmp	edx,[ebx+8]
2591
	cmp	edx,[ebx+8]
2545
	je	default_section_ok
2592
	je	default_section_ok
2546
      next_reference:
2593
      next_reference:
2547
	add	ebx,0Ch
2594
	add	ebx,0Ch
2548
	jmp	find_references_to_default_section
2595
	jmp	find_references_to_default_section
2549
      check_public_reference:
2596
      check_public_reference:
2550
	mov	eax,[ebx+8]
2597
	mov	eax,[ebx+8]
2551
	add	ebx,10h
2598
	add	ebx,10h
2552
	test	byte [eax+8],1
2599
	test	byte [eax+8],1
2553
	jz	find_references_to_default_section
2600
	jz	find_references_to_default_section
2554
	mov	cx,[current_pass]
2601
	mov	cx,[current_pass]
2555
	cmp	cx,[eax+16]
2602
	cmp	cx,[eax+16]
2556
	jne	find_references_to_default_section
2603
	jne	find_references_to_default_section
2557
	cmp	edx,[eax+20]
2604
	cmp	edx,[eax+20]
2558
	je	default_section_ok
2605
	je	default_section_ok
2559
	jmp	find_references_to_default_section
2606
	jmp	find_references_to_default_section
2560
      skip_other_section:
2607
      skip_other_section:
2561
	add	ebx,20h
2608
	add	ebx,20h
2562
	jmp	find_references_to_default_section
2609
	jmp	find_references_to_default_section
2563
      default_section_ok:
2610
      default_section_ok:
2564
	inc	[number_of_sections]
2611
	inc	[number_of_sections]
2565
	ret
2612
	ret
2566
      symbols_enumerated:
2613
      symbols_enumerated:
2567
	mov	[ebx+0Ch],eax
2614
	mov	[ebx+0Ch],eax
2568
	mov	ebp,edi
2615
	mov	ebp,edi
2569
	sub	ebp,ebx
2616
	sub	ebp,ebx
2570
	push	ebp
2617
	push	ebp
2571
	lea	edi,[ebx+14h]
2618
	lea	edi,[ebx+14h]
2572
	mov	esi,[symbols_stream]
2619
	mov	esi,[symbols_stream]
2573
      find_section:
2620
      find_section:
2574
	cmp	esi,[free_additional_memory]
2621
	cmp	esi,[free_additional_memory]
2575
	je	sections_finished
2622
	je	sections_finished
2576
	mov	al,[esi]
2623
	mov	al,[esi]
2577
	or	al,al
2624
	or	al,al
2578
	jz	section_found
2625
	jz	section_found
2579
	add	esi,0Ch
2626
	add	esi,0Ch
2580
	cmp	al,0C0h
2627
	cmp	al,0C0h
2581
	jb	find_section
2628
	jb	find_section
2582
	add	esi,4
2629
	add	esi,4
2583
	jmp	find_section
2630
	jmp	find_section
2584
      section_found:
2631
      section_found:
2585
	push	esi edi
2632
	push	esi edi
2586
	mov	esi,[esi+4]
2633
	mov	esi,[esi+4]
2587
	or	esi,esi
2634
	or	esi,esi
2588
	jz	default_section
2635
	jz	default_section
2589
	mov	ecx,[esi]
2636
	mov	ecx,[esi]
2590
	add	esi,4
2637
	add	esi,4
2591
	rep	movs byte [edi],[esi]
2638
	rep	movs byte [edi],[esi]
2592
	jmp	section_name_ok
2639
	jmp	section_name_ok
2593
      default_section:
2640
      default_section:
2594
	mov	al,'.'
2641
	mov	al,'.'
2595
	stos	byte [edi]
2642
	stos	byte [edi]
2596
	mov	eax,'flat'
2643
	mov	eax,'flat'
2597
	stos	dword [edi]
2644
	stos	dword [edi]
2598
      section_name_ok:
2645
      section_name_ok:
2599
	pop	edi esi
2646
	pop	edi esi
2600
	mov	eax,[esi+0Ch]
2647
	mov	eax,[esi+0Ch]
2601
	mov	[edi+10h],eax
2648
	mov	[edi+10h],eax
2602
	mov	eax,[esi+14h]
2649
	mov	eax,[esi+14h]
2603
	mov	[edi+24h],eax
2650
	mov	[edi+24h],eax
2604
	test	al,80h
2651
	test	al,80h
2605
	jnz	section_ptr_ok
2652
	jnz	section_ptr_ok
2606
	mov	eax,[esi+8]
2653
	mov	eax,[esi+8]
2607
	sub	eax,[code_start]
2654
	sub	eax,[code_start]
2608
	add	eax,ebp
2655
	add	eax,ebp
2609
	mov	[edi+14h],eax
2656
	mov	[edi+14h],eax
2610
      section_ptr_ok:
2657
      section_ptr_ok:
2611
	mov	ebx,[code_start]
2658
	mov	ebx,[code_start]
2612
	mov	edx,[code_size]
2659
	mov	edx,[code_size]
2613
	add	ebx,edx
2660
	add	ebx,edx
2614
	add	edx,ebp
2661
	add	edx,ebp
2615
	xor	ecx,ecx
2662
	xor	ecx,ecx
2616
	add	esi,20h
2663
	add	esi,20h
2617
      find_relocations:
2664
      find_relocations:
2618
	cmp	esi,[free_additional_memory]
2665
	cmp	esi,[free_additional_memory]
2619
	je	section_relocations_done
2666
	je	section_relocations_done
2620
	mov	al,[esi]
2667
	mov	al,[esi]
2621
	or	al,al
2668
	or	al,al
2622
	jz	section_relocations_done
2669
	jz	section_relocations_done
2623
	cmp	al,80h
2670
	cmp	al,80h
2624
	jb	add_relocation
2671
	jb	add_relocation
2625
	cmp	al,0C0h
2672
	cmp	al,0C0h
2626
	jb	next_relocation
2673
	jb	next_relocation
2627
	add	esi,10h
2674
	add	esi,10h
2628
	jmp	find_relocations
2675
	jmp	find_relocations
2629
      add_relocation:
2676
      add_relocation:
2630
	lea	eax,[ebx+0Ah]
2677
	lea	eax,[ebx+0Ah]
2631
	cmp	eax,[display_buffer]
2678
	cmp	eax,[display_buffer]
2632
	ja	out_of_memory
2679
	ja	out_of_memory
2633
	mov	eax,[esi+4]
2680
	mov	eax,[esi+4]
2634
	mov	[ebx],eax
2681
	mov	[ebx],eax
2635
	mov	eax,[esi+8]
2682
	mov	eax,[esi+8]
2636
	mov	eax,[eax]
2683
	mov	eax,[eax]
2637
	shr	eax,8
2684
	shr	eax,8
2638
	mov	[ebx+4],eax
2685
	mov	[ebx+4],eax
2639
	movzx	ax,byte [esi]
2686
	movzx	ax,byte [esi]
2640
	mov	[ebx+8],ax
2687
	mov	[ebx+8],ax
2641
	add	ebx,0Ah
2688
	add	ebx,0Ah
2642
	inc	ecx
2689
	inc	ecx
2643
      next_relocation:
2690
      next_relocation:
2644
	add	esi,0Ch
2691
	add	esi,0Ch
2645
	jmp	find_relocations
2692
	jmp	find_relocations
2646
      section_relocations_done:
2693
      section_relocations_done:
2647
	cmp	ecx,10000h
2694
	cmp	ecx,10000h
2648
	jb	section_relocations_count_16bit
2695
	jb	section_relocations_count_16bit
2649
	bt	[format_flags],0
2696
	bt	[format_flags],0
2650
	jnc	format_limitations_exceeded
2697
	jnc	format_limitations_exceeded
2651
	mov	word [edi+20h],0FFFFh
2698
	mov	word [edi+20h],0FFFFh
2652
	or	dword [edi+24h],1000000h
2699
	or	dword [edi+24h],1000000h
2653
	mov	[edi+18h],edx
2700
	mov	[edi+18h],edx
2654
	push	esi edi
2701
	push	esi edi
2655
	push	ecx
2702
	push	ecx
2656
	lea	esi,[ebx-1]
2703
	lea	esi,[ebx-1]
2657
	add	ebx,0Ah
2704
	add	ebx,0Ah
2658
	lea	edi,[ebx-1]
2705
	lea	edi,[ebx-1]
2659
	imul	ecx,0Ah
2706
	imul	ecx,0Ah
2660
	std
2707
	std
2661
	rep	movs byte [edi],[esi]
2708
	rep	movs byte [edi],[esi]
2662
	cld
2709
	cld
2663
	pop	ecx
2710
	pop	ecx
2664
	inc	esi
2711
	inc	esi
2665
	inc	ecx
2712
	inc	ecx
2666
	mov	[esi],ecx
2713
	mov	[esi],ecx
2667
	xor	eax,eax
2714
	xor	eax,eax
2668
	mov	[esi+4],eax
2715
	mov	[esi+4],eax
2669
	mov	[esi+8],ax
2716
	mov	[esi+8],ax
2670
	pop	edi esi
2717
	pop	edi esi
2671
	jmp	section_relocations_ok
2718
	jmp	section_relocations_ok
2672
      section_relocations_count_16bit:
2719
      section_relocations_count_16bit:
2673
	mov	[edi+20h],cx
2720
	mov	[edi+20h],cx
2674
	jcxz	section_relocations_ok
2721
	jcxz	section_relocations_ok
2675
	mov	[edi+18h],edx
2722
	mov	[edi+18h],edx
2676
      section_relocations_ok:
2723
      section_relocations_ok:
2677
	sub	ebx,[code_start]
2724
	sub	ebx,[code_start]
2678
	mov	[code_size],ebx
2725
	mov	[code_size],ebx
2679
	add	edi,28h
2726
	add	edi,28h
2680
	jmp	find_section
2727
	jmp	find_section
2681
      sections_finished:
2728
      sections_finished:
2682
	mov	edx,[free_additional_memory]
2729
	mov	edx,[free_additional_memory]
2683
	mov	ebx,[code_size]
2730
	mov	ebx,[code_size]
2684
	add	ebp,ebx
2731
	add	ebp,ebx
2685
	mov	[edx+8],ebp
2732
	mov	[edx+8],ebp
2686
	add	ebx,[code_start]
2733
	add	ebx,[code_start]
2687
	mov	edi,ebx
2734
	mov	edi,ebx
2688
	mov	ecx,[edx+0Ch]
2735
	mov	ecx,[edx+0Ch]
2689
	imul	ecx,12h shr 1
2736
	imul	ecx,12h shr 1
2690
	xor	eax,eax
2737
	xor	eax,eax
2691
	shr	ecx,1
2738
	shr	ecx,1
2692
	jnc	zero_symbols_table
2739
	jnc	zero_symbols_table
2693
	stos	word [edi]
2740
	stos	word [edi]
2694
      zero_symbols_table:
2741
      zero_symbols_table:
2695
	rep	stos dword [edi]
2742
	rep	stos dword [edi]
2696
	mov	edx,edi
2743
	mov	edx,edi
2697
	stos	dword [edi]
2744
	stos	dword [edi]
2698
	mov	esi,[symbols_stream]
2745
	mov	esi,[symbols_stream]
2699
      make_symbols_table:
2746
      make_symbols_table:
2700
	cmp	esi,[free_additional_memory]
2747
	cmp	esi,[free_additional_memory]
2701
	je	symbols_table_ok
2748
	je	symbols_table_ok
2702
	mov	al,[esi]
2749
	mov	al,[esi]
2703
	cmp	al,0C0h
2750
	cmp	al,0C0h
2704
	jae	add_public_symbol
2751
	jae	add_public_symbol
2705
	cmp	al,80h
2752
	cmp	al,80h
2706
	jae	add_extrn_symbol
2753
	jae	add_extrn_symbol
2707
	or	al,al
2754
	or	al,al
2708
	jz	add_section_symbol
2755
	jz	add_section_symbol
2709
	add	esi,0Ch
2756
	add	esi,0Ch
2710
	jmp	make_symbols_table
2757
	jmp	make_symbols_table
2711
      add_section_symbol:
2758
      add_section_symbol:
2712
	call	store_symbol_name
2759
	call	store_symbol_name
2713
	movzx	eax,word [esi+1Eh]
2760
	movzx	eax,word [esi+1Eh]
2714
	mov	[ebx+0Ch],ax
2761
	mov	[ebx+0Ch],ax
2715
	mov	byte [ebx+10h],3
2762
	mov	byte [ebx+10h],3
2716
	add	esi,20h
2763
	add	esi,20h
2717
	add	ebx,12h
2764
	add	ebx,12h
2718
	jmp	make_symbols_table
2765
	jmp	make_symbols_table
2719
      add_extrn_symbol:
2766
      add_extrn_symbol:
2720
	call	store_symbol_name
2767
	call	store_symbol_name
2721
	mov	byte [ebx+10h],2
2768
	mov	byte [ebx+10h],2
2722
	add	esi,0Ch
2769
	add	esi,0Ch
2723
	add	ebx,12h
2770
	add	ebx,12h
2724
	jmp	make_symbols_table
2771
	jmp	make_symbols_table
2725
      add_public_symbol:
2772
      add_public_symbol:
2726
	call	store_symbol_name
2773
	call	store_symbol_name
2727
	mov	eax,[esi+0Ch]
2774
	mov	eax,[esi+0Ch]
2728
	mov	[current_line],eax
2775
	mov	[current_line],eax
2729
	mov	eax,[esi+8]
2776
	mov	eax,[esi+8]
2730
	test	byte [eax+8],1
2777
	test	byte [eax+8],1
2731
	jz	undefined_coff_public
2778
	jz	undefined_coff_public
2732
	mov	cx,[current_pass]
2779
	mov	cx,[current_pass]
2733
	cmp	cx,[eax+16]
2780
	cmp	cx,[eax+16]
2734
	jne	undefined_coff_public
2781
	jne	undefined_coff_public
2735
	mov	cl,[eax+11]
2782
	mov	cl,[eax+11]
2736
	or	cl,cl
2783
	or	cl,cl
2737
	jz	public_constant
2784
	jz	public_constant
2738
	test	[format_flags],8
2785
	test	[format_flags],8
2739
	jnz	check_64bit_public_symbol
2786
	jnz	check_64bit_public_symbol
2740
	cmp	cl,2
2787
	cmp	cl,2
2741
	je	public_symbol_type_ok
2788
	je	public_symbol_type_ok
2742
	jmp	invalid_use_of_symbol
2789
	jmp	invalid_use_of_symbol
2743
      undefined_coff_public:
2790
      undefined_coff_public:
2744
	mov	eax,[eax+24]
2791
	mov	[error_info],eax
2745
	mov	[error_info],eax
-
 
2746
	jmp	undefined_symbol
2792
	jmp	undefined_symbol
2747
      check_64bit_public_symbol:
2793
      check_64bit_public_symbol:
2748
	cmp	cl,4
2794
	cmp	cl,4
2749
	jne	invalid_use_of_symbol
2795
	jne	invalid_use_of_symbol
2750
      public_symbol_type_ok:
2796
      public_symbol_type_ok:
2751
	mov	ecx,[eax+20]
2797
	mov	ecx,[eax+20]
2752
	cmp	byte [ecx],80h
2798
	cmp	byte [ecx],80h
2753
	je	alias_symbol
2799
	je	alias_symbol
2754
	cmp	byte [ecx],0
2800
	cmp	byte [ecx],0
2755
	jne	invalid_use_of_symbol
2801
	jne	invalid_use_of_symbol
2756
	mov	cx,[ecx+1Eh]
2802
	mov	cx,[ecx+1Eh]
2757
	mov	[ebx+0Ch],cx
2803
	mov	[ebx+0Ch],cx
2758
      public_symbol_section_ok:
2804
      public_symbol_section_ok:
2759
	cmp	dword [eax+4],0
2805
	cmp	dword [eax+4],0
2760
	je	store_public_symbol
2806
	je	store_public_symbol
2761
	cmp	dword [eax+4],-1
2807
	cmp	dword [eax+4],-1
2762
	jne	value_out_of_range
2808
	jne	value_out_of_range
2763
	bt	dword [eax],31
2809
	bt	dword [eax],31
2764
	jnc	value_out_of_range
2810
	jnc	value_out_of_range
2765
      store_public_symbol:
2811
      store_public_symbol:
2766
	mov	eax,[eax]
2812
	mov	eax,[eax]
2767
	mov	[ebx+8],eax
2813
	mov	[ebx+8],eax
2768
	mov	al,2
2814
	mov	al,2
2769
	cmp	byte [esi],0C0h
2815
	cmp	byte [esi],0C0h
2770
	je	store_symbol_class
2816
	je	store_symbol_class
2771
	inc	al
2817
	inc	al
2772
	cmp	byte [esi],0C1h
2818
	cmp	byte [esi],0C1h
2773
	je	store_symbol_class
2819
	je	store_symbol_class
2774
	mov	al,105
2820
	mov	al,105
2775
      store_symbol_class:
2821
      store_symbol_class:
2776
	mov	byte [ebx+10h],al
2822
	mov	byte [ebx+10h],al
2777
	add	esi,10h
2823
	add	esi,10h
2778
	add	ebx,12h
2824
	add	ebx,12h
2779
	jmp	make_symbols_table
2825
	jmp	make_symbols_table
2780
      alias_symbol:
2826
      alias_symbol:
2781
	bt	[format_flags],0
2827
	bt	[format_flags],0
2782
	jnc	invalid_use_of_symbol
2828
	jnc	invalid_use_of_symbol
2783
	mov	ecx,[eax]
2829
	mov	ecx,[eax]
2784
	or	ecx,[eax+4]
2830
	or	ecx,[eax+4]
2785
	jnz	invalid_use_of_symbol
2831
	jnz	invalid_use_of_symbol
2786
	mov	byte [ebx+10h],69h
2832
	mov	byte [ebx+10h],69h
2787
	mov	byte [ebx+11h],1
2833
	mov	byte [ebx+11h],1
2788
	add	ebx,12h
2834
	add	ebx,12h
2789
	mov	ecx,[eax+20]
2835
	mov	ecx,[eax+20]
2790
	mov	ecx,[ecx]
2836
	mov	ecx,[ecx]
2791
	shr	ecx,8
2837
	shr	ecx,8
2792
	mov	[ebx],ecx
2838
	mov	[ebx],ecx
2793
	mov	byte [ebx+4],3
2839
	mov	byte [ebx+4],3
2794
	add	esi,10h
2840
	add	esi,10h
2795
	add	ebx,12h
2841
	add	ebx,12h
2796
	jmp	make_symbols_table
2842
	jmp	make_symbols_table
2797
      public_constant:
2843
      public_constant:
2798
	mov	word [ebx+0Ch],0FFFFh
2844
	mov	word [ebx+0Ch],0FFFFh
2799
	jmp	public_symbol_section_ok
2845
	jmp	public_symbol_section_ok
2800
      symbols_table_ok:
2846
      symbols_table_ok:
2801
	mov	eax,edi
2847
	mov	eax,edi
2802
	sub	eax,edx
2848
	sub	eax,edx
2803
	mov	[edx],eax
2849
	mov	[edx],eax
2804
	sub	edi,[code_start]
2850
	sub	edi,[code_start]
2805
	mov	[code_size],edi
2851
	mov	[code_size],edi
2806
	mov	[written_size],0
2852
	mov	[written_size],0
2807
	mov	edx,[output_file]
2853
	mov	edx,[output_file]
2808
	call	create
2854
	call	create
2809
	jc	write_failed
2855
	jc	write_failed
2810
	mov	edx,[free_additional_memory]
2856
	mov	edx,[free_additional_memory]
2811
	pop	ecx
2857
	pop	ecx
2812
	add	[written_size],ecx
2858
	add	[written_size],ecx
2813
	call	write
2859
	call	write
2814
	jc	write_failed
2860
	jc	write_failed
2815
	jmp	write_output
2861
	jmp	write_output
2816
      store_symbol_name:
2862
      store_symbol_name:
2817
	push	esi
2863
	push	esi
2818
	mov	esi,[esi+4]
2864
	mov	esi,[esi+4]
2819
	or	esi,esi
2865
	or	esi,esi
2820
	jz	default_name
2866
	jz	default_name
2821
	lods	dword [esi]
2867
	lods	dword [esi]
2822
	mov	ecx,eax
2868
	mov	ecx,eax
2823
	cmp	ecx,8
2869
	cmp	ecx,8
2824
	ja	add_string
2870
	ja	add_string
2825
	push	edi
2871
	push	edi
2826
	mov	edi,ebx
2872
	mov	edi,ebx
2827
	rep	movs byte [edi],[esi]
2873
	rep	movs byte [edi],[esi]
2828
	pop	edi esi
2874
	pop	edi esi
2829
	ret
2875
	ret
2830
      default_name:
2876
      default_name:
2831
	mov	dword [ebx],'.fla'
2877
	mov	dword [ebx],'.fla'
2832
	mov	dword [ebx+4],'t'
2878
	mov	dword [ebx+4],'t'
2833
	pop	esi
2879
	pop	esi
2834
	ret
2880
	ret
2835
      add_string:
2881
      add_string:
2836
	mov	eax,edi
2882
	mov	eax,edi
2837
	sub	eax,edx
2883
	sub	eax,edx
2838
	mov	[ebx+4],eax
2884
	mov	[ebx+4],eax
2839
	inc	ecx
2885
	inc	ecx
2840
	rep	movs byte [edi],[esi]
2886
	rep	movs byte [edi],[esi]
2841
	pop	esi
2887
	pop	esi
2842
	ret
2888
	ret
2843
 
2889
 
2844
format_elf:
2890
format_elf:
2845
	test	[format_flags],8
2891
	test	[format_flags],8
2846
	jnz	format_elf64
2892
	jnz	format_elf64
2847
	mov	edx,edi
2893
	mov	edx,edi
2848
	mov	ecx,34h shr 2
2894
	mov	ecx,34h shr 2
2849
	lea	eax,[edi+ecx*4]
2895
	lea	eax,[edi+ecx*4]
2850
	cmp	eax,[display_buffer]
2896
	cmp	eax,[display_buffer]
2851
	jae	out_of_memory
2897
	jae	out_of_memory
2852
	xor	eax,eax
2898
	xor	eax,eax
2853
	rep	stos dword [edi]
2899
	rep	stos dword [edi]
2854
	mov	dword [edx],7Fh + 'ELF' shl 8
2900
	mov	dword [edx],7Fh + 'ELF' shl 8
2855
	mov	al,1
2901
	mov	al,1
2856
	mov	[edx+4],al
2902
	mov	[edx+4],al
2857
	mov	[edx+5],al
2903
	mov	[edx+5],al
2858
	mov	[edx+6],al
2904
	mov	[edx+6],al
2859
	mov	[edx+14h],al
2905
	mov	[edx+14h],al
2860
	mov	byte [edx+12h],3
2906
	mov	byte [edx+12h],3
2861
	mov	byte [edx+28h],34h
2907
	mov	byte [edx+28h],34h
2862
	mov	byte [edx+2Eh],28h
2908
	mov	byte [edx+2Eh],28h
2863
	mov	[code_type],32
2909
	mov	[code_type],32
2864
	cmp	word [esi],1D19h
2910
	cmp	word [esi],1D19h
2865
	je	format_elf_exe
2911
	je	format_elf_exe
2866
	mov	[labels_type],2
2912
	mov	[labels_type],2
2867
      elf_header_ok:
2913
      elf_header_ok:
2868
	mov	byte [edx+10h],1
2914
	mov	byte [edx+10h],1
2869
	mov	eax,[additional_memory]
2915
	mov	eax,[additional_memory]
2870
	mov	[symbols_stream],eax
2916
	mov	[symbols_stream],eax
2871
	mov	ebx,eax
2917
	mov	ebx,eax
2872
	add	eax,20h
2918
	add	eax,20h
2873
	cmp	eax,[structures_buffer]
2919
	cmp	eax,[structures_buffer]
2874
	jae	out_of_memory
2920
	jae	out_of_memory
2875
	mov	[free_additional_memory],eax
2921
	mov	[free_additional_memory],eax
2876
	xor	eax,eax
2922
	xor	eax,eax
2877
	mov	[current_section],ebx
2923
	mov	[current_section],ebx
2878
	mov	[number_of_sections],eax
2924
	mov	[number_of_sections],eax
2879
	mov	dword [org_origin],edi
2925
	mov	dword [org_origin],edi
2880
	mov	dword [org_origin+4],eax
2926
	mov	dword [org_origin+4],eax
2881
	mov	[org_registers],eax
2927
	mov	[org_registers],eax
2882
	mov	[org_start],edi
2928
	mov	[org_start],edi
2883
	mov	[org_symbol],ebx
2929
	mov	[org_symbol],ebx
2884
	mov	[ebx],al
2930
	mov	[ebx],al
2885
	mov	[ebx+4],eax
2931
	mov	[ebx+4],eax
2886
	mov	[ebx+8],edi
2932
	mov	[ebx+8],edi
2887
	mov	al,111b
2933
	mov	al,111b
2888
	mov	[ebx+14h],eax
2934
	mov	[ebx+14h],eax
2889
	mov	al,4
2935
	mov	al,4
2890
	mov	[ebx+10h],eax
2936
	mov	[ebx+10h],eax
2891
	test	[format_flags],8
2937
	test	[format_flags],8
2892
	jz	format_defined
2938
	jz	format_defined
2893
	mov	byte [ebx+10h],8
2939
	mov	byte [ebx+10h],8
2894
	jmp	format_defined
2940
	jmp	format_defined
2895
      format_elf64:
2941
      format_elf64:
2896
	mov	edx,edi
2942
	mov	edx,edi
2897
	mov	ecx,40h shr 2
2943
	mov	ecx,40h shr 2
2898
	lea	eax,[edi+ecx*4]
2944
	lea	eax,[edi+ecx*4]
2899
	cmp	eax,[display_buffer]
2945
	cmp	eax,[display_buffer]
2900
	jae	out_of_memory
2946
	jae	out_of_memory
2901
	xor	eax,eax
2947
	xor	eax,eax
2902
	rep	stos dword [edi]
2948
	rep	stos dword [edi]
2903
	mov	dword [edx],7Fh + 'ELF' shl 8
2949
	mov	dword [edx],7Fh + 'ELF' shl 8
2904
	mov	al,1
2950
	mov	al,1
2905
	mov	[edx+5],al
2951
	mov	[edx+5],al
2906
	mov	[edx+6],al
2952
	mov	[edx+6],al
2907
	mov	[edx+14h],al
2953
	mov	[edx+14h],al
2908
	mov	byte [edx+4],2
2954
	mov	byte [edx+4],2
2909
	mov	byte [edx+12h],62
2955
	mov	byte [edx+12h],62
2910
	mov	byte [edx+34h],40h
2956
	mov	byte [edx+34h],40h
2911
	mov	byte [edx+3Ah],40h
2957
	mov	byte [edx+3Ah],40h
2912
	mov	[code_type],64
2958
	mov	[code_type],64
2913
	cmp	word [esi],1D19h
2959
	cmp	word [esi],1D19h
2914
	je	format_elf64_exe
2960
	je	format_elf64_exe
2915
	mov	[labels_type],4
2961
	mov	[labels_type],4
2916
	jmp	elf_header_ok
2962
	jmp	elf_header_ok
2917
elf_section:
2963
elf_section:
2918
	bt	[format_flags],0
2964
	bt	[format_flags],0
2919
	jc	illegal_instruction
2965
	jc	illegal_instruction
2920
	call	close_coff_section
2966
	call	close_coff_section
2921
	mov	ebx,[free_additional_memory]
2967
	mov	ebx,[free_additional_memory]
2922
	lea	eax,[ebx+20h]
2968
	lea	eax,[ebx+20h]
2923
	cmp	eax,[structures_buffer]
2969
	cmp	eax,[structures_buffer]
2924
	jae	out_of_memory
2970
	jae	out_of_memory
2925
	mov	[free_additional_memory],eax
2971
	mov	[free_additional_memory],eax
2926
	mov	[current_section],ebx
2972
	mov	[current_section],ebx
2927
	inc	word [number_of_sections]
2973
	inc	word [number_of_sections]
2928
	jz	format_limitations_exceeded
2974
	jz	format_limitations_exceeded
2929
	xor	eax,eax
2975
	xor	eax,eax
2930
	mov	[ebx],al
2976
	mov	[ebx],al
2931
	mov	[ebx+8],edi
2977
	mov	[ebx+8],edi
2932
	mov	dword [org_origin],edi
2978
	mov	dword [org_origin],edi
2933
	mov	dword [org_origin+4],eax
2979
	mov	dword [org_origin+4],eax
2934
	mov	[org_registers],eax
2980
	mov	[org_registers],eax
2935
	mov	[org_start],edi
2981
	mov	[org_start],edi
2936
	mov	[org_symbol],ebx
2982
	mov	[org_symbol],ebx
2937
	test	[format_flags],8
2983
	test	[format_flags],8
2938
	jnz	elf64_labels_type
2984
	jnz	elf64_labels_type
2939
	mov	[labels_type],2
2985
	mov	[labels_type],2
2940
	jmp	elf_labels_type_ok
2986
	jmp	elf_labels_type_ok
2941
      elf64_labels_type:
2987
      elf64_labels_type:
2942
	mov	[labels_type],4
2988
	mov	[labels_type],4
2943
      elf_labels_type_ok:
2989
      elf_labels_type_ok:
2944
	mov	[ebx+10h],eax
2990
	mov	[ebx+10h],eax
2945
	mov	al,10b
2991
	mov	al,10b
2946
	mov	[ebx+14h],eax
2992
	mov	[ebx+14h],eax
2947
	lods	word [esi]
2993
	lods	word [esi]
2948
	cmp	ax,'('
2994
	cmp	ax,'('
2949
	jne	invalid_argument
2995
	jne	invalid_argument
2950
	mov	[ebx+4],esi
2996
	mov	[ebx+4],esi
2951
	mov	ecx,[esi]
2997
	mov	ecx,[esi]
2952
	lea	esi,[esi+4+ecx+1]
2998
	lea	esi,[esi+4+ecx+1]
2953
      elf_section_flags:
2999
      elf_section_flags:
2954
	cmp	byte [esi],1Ch
3000
	cmp	byte [esi],8Ch
2955
	je	elf_section_alignment
3001
	je	elf_section_alignment
2956
	cmp	byte [esi],19h
3002
	cmp	byte [esi],19h
2957
	jne	elf_section_settings_ok
3003
	jne	elf_section_settings_ok
2958
	inc	esi
3004
	inc	esi
2959
	lods	byte [esi]
3005
	lods	byte [esi]
2960
	sub	al,28
3006
	sub	al,28
2961
	xor	al,11b
3007
	xor	al,11b
2962
	test	al,not 10b
3008
	test	al,not 10b
2963
	jnz	invalid_argument
3009
	jnz	invalid_argument
2964
	mov	cl,al
3010
	mov	cl,al
2965
	mov	al,1
3011
	mov	al,1
2966
	shl	al,cl
3012
	shl	al,cl
2967
	test	byte [ebx+14h],al
3013
	test	byte [ebx+14h],al
2968
	jnz	setting_already_specified
3014
	jnz	setting_already_specified
2969
	or	byte [ebx+14h],al
3015
	or	byte [ebx+14h],al
2970
	jmp	elf_section_flags
3016
	jmp	elf_section_flags
2971
      elf_section_alignment:
3017
      elf_section_alignment:
2972
	inc	esi
3018
	inc	esi
2973
	lods	byte [esi]
3019
	lods	byte [esi]
2974
	or	al,al
3020
	cmp	al,'('
2975
	jnz	invalid_argument
-
 
2976
	lods	byte [esi]
-
 
2977
	cmp	al,'('
-
 
2978
	jne	invalid_argument
3021
	jne	invalid_argument
2979
	cmp	byte [esi],'.'
3022
	cmp	byte [esi],'.'
2980
	je	invalid_value
3023
	je	invalid_value
2981
	push	ebx
3024
	push	ebx
2982
	call	get_dword_value
3025
	call	get_count_value
2983
	pop	ebx
3026
	pop	ebx
2984
	cmp	[value_type],0
3027
	mov	edx,eax
2985
	jne	invalid_use_of_symbol
-
 
2986
	mov	edx,eax
-
 
2987
	dec	edx
3028
	dec	edx
2988
	test	eax,edx
3029
	test	eax,edx
2989
	jnz	invalid_value
3030
	jnz	invalid_value
2990
	or	eax,eax
3031
	or	eax,eax
2991
	jz	invalid_value
3032
	jz	invalid_value
2992
	xchg	[ebx+10h],eax
3033
	xchg	[ebx+10h],eax
2993
	or	eax,eax
3034
	or	eax,eax
2994
	jnz	setting_already_specified
3035
	jnz	setting_already_specified
2995
	jmp	elf_section_flags
3036
	jmp	elf_section_flags
2996
      elf_section_settings_ok:
3037
      elf_section_settings_ok:
2997
	cmp	dword [ebx+10h],0
3038
	cmp	dword [ebx+10h],0
2998
	jne	instruction_assembled
3039
	jne	instruction_assembled
2999
	mov	dword [ebx+10h],4
3040
	mov	dword [ebx+10h],4
3000
	test	[format_flags],8
3041
	test	[format_flags],8
3001
	jz	instruction_assembled
3042
	jz	instruction_assembled
3002
	mov	byte [ebx+10h],8
3043
	mov	byte [ebx+10h],8
3003
	jmp	instruction_assembled
3044
	jmp	instruction_assembled
3004
mark_elf_relocation:
3045
mark_elf_relocation:
3005
	cmp	[value_type],3
3046
	cmp	[value_type],3
3006
	je	elf_relocation_relative
3047
	je	elf_relocation_relative
3007
	cmp	[value_type],7
3048
	cmp	[value_type],7
3008
	je	elf_relocation_relative
3049
	je	elf_relocation_relative
3009
	push	ebx eax
3050
	push	ebx eax
3010
	cmp	[value_type],5
3051
	cmp	[value_type],5
3011
	je	elf_gotoff_relocation
3052
	je	elf_gotoff_relocation
3012
	ja	invalid_use_of_symbol
3053
	ja	invalid_use_of_symbol
3013
	mov	al,1			; R_386_32 / R_AMD64_64
3054
	mov	al,1			; R_386_32 / R_AMD64_64
3014
	test	[format_flags],8
3055
	test	[format_flags],8
3015
	jz	coff_relocation
3056
	jz	coff_relocation
3016
	cmp	[value_type],4
3057
	cmp	[value_type],4
3017
	je	coff_relocation
3058
	je	coff_relocation
3018
	mov	al,11			; R_AMD64_32S
3059
	mov	al,11			; R_AMD64_32S
3019
	jmp	coff_relocation
3060
	jmp	coff_relocation
3020
      elf_gotoff_relocation:
3061
      elf_gotoff_relocation:
3021
	test	[format_flags],8
3062
	test	[format_flags],8
3022
	jnz	invalid_use_of_symbol
3063
	jnz	invalid_use_of_symbol
3023
	mov	al,9			; R_386_GOTOFF
3064
	mov	al,9			; R_386_GOTOFF
3024
	jmp	coff_relocation
3065
	jmp	coff_relocation
3025
      elf_relocation_relative:
3066
      elf_relocation_relative:
3026
	cmp	[labels_type],0
3067
	cmp	[labels_type],0
3027
	je	invalid_use_of_symbol
3068
	je	invalid_use_of_symbol
3028
	push	ebx
3069
	push	ebx
3029
	mov	ebx,[current_section]
3070
	mov	ebx,[current_section]
3030
	mov	ebx,[ebx+8]
3071
	mov	ebx,[ebx+8]
3031
	sub	ebx,edi
3072
	sub	ebx,edi
3032
	sub	eax,ebx
3073
	sub	eax,ebx
3033
	push	eax
3074
	push	eax
3034
	mov	al,2			; R_386_PC32 / R_AMD64_PC32
3075
	mov	al,2			; R_386_PC32 / R_AMD64_PC32
3035
	cmp	[value_type],3
3076
	cmp	[value_type],3
3036
	je	coff_relocation
3077
	je	coff_relocation
3037
	mov	al,4			; R_386_PLT32 / R_AMD64_PLT32
3078
	mov	al,4			; R_386_PLT32 / R_AMD64_PLT32
3038
	jmp	coff_relocation
3079
	jmp	coff_relocation
3039
close_elf:
3080
close_elf:
3040
	bt	[format_flags],0
3081
	bt	[format_flags],0
3041
	jc	close_elf_exe
3082
	jc	close_elf_exe
3042
	call	close_coff_section
3083
	call	close_coff_section
3043
	cmp	[next_pass_needed],0
3084
	cmp	[next_pass_needed],0
3044
	je	elf_closed
3085
	je	elf_closed
3045
	mov	eax,[symbols_stream]
3086
	mov	eax,[symbols_stream]
3046
	mov	[free_additional_memory],eax
3087
	mov	[free_additional_memory],eax
3047
      elf_closed:
3088
      elf_closed:
3048
	ret
3089
	ret
3049
elf_formatter:
3090
elf_formatter:
3050
	push	edi
3091
	push	edi
3051
	call	prepare_default_section
3092
	call	prepare_default_section
3052
	mov	esi,[symbols_stream]
3093
	mov	esi,[symbols_stream]
3053
	mov	edi,[free_additional_memory]
3094
	mov	edi,[free_additional_memory]
3054
	xor	eax,eax
3095
	xor	eax,eax
3055
	mov	ecx,4
3096
	mov	ecx,4
3056
	rep	stos dword [edi]
3097
	rep	stos dword [edi]
3057
	test	[format_flags],8
3098
	test	[format_flags],8
3058
	jz	find_first_section
3099
	jz	find_first_section
3059
	mov	ecx,2
3100
	mov	ecx,2
3060
	rep	stos dword [edi]
3101
	rep	stos dword [edi]
3061
      find_first_section:
3102
      find_first_section:
3062
	mov	al,[esi]
3103
	mov	al,[esi]
3063
	or	al,al
3104
	or	al,al
3064
	jz	first_section_found
3105
	jz	first_section_found
3065
	cmp	al,0C0h
3106
	cmp	al,0C0h
3066
	jb	skip_other_symbol
3107
	jb	skip_other_symbol
3067
	add	esi,4
3108
	add	esi,4
3068
      skip_other_symbol:
3109
      skip_other_symbol:
3069
	add	esi,0Ch
3110
	add	esi,0Ch
3070
	jmp	find_first_section
3111
	jmp	find_first_section
3071
      first_section_found:
3112
      first_section_found:
3072
	mov	ebx,esi
3113
	mov	ebx,esi
3073
	mov	ebp,esi
3114
	mov	ebp,esi
3074
	add	esi,20h
3115
	add	esi,20h
3075
	xor	ecx,ecx
3116
	xor	ecx,ecx
3076
	xor	edx,edx
3117
	xor	edx,edx
3077
      find_next_section:
3118
      find_next_section:
3078
	cmp	esi,[free_additional_memory]
3119
	cmp	esi,[free_additional_memory]
3079
	je	make_section_symbol
3120
	je	make_section_symbol
3080
	mov	al,[esi]
3121
	mov	al,[esi]
3081
	or	al,al
3122
	or	al,al
3082
	jz	make_section_symbol
3123
	jz	make_section_symbol
3083
	cmp	al,0C0h
3124
	cmp	al,0C0h
3084
	jae	skip_public
3125
	jae	skip_public
3085
	cmp	al,80h
3126
	cmp	al,80h
3086
	jae	skip_extrn
3127
	jae	skip_extrn
3087
	or	byte [ebx+14h],40h
3128
	or	byte [ebx+14h],40h
3088
      skip_extrn:
3129
      skip_extrn:
3089
	add	esi,0Ch
3130
	add	esi,0Ch
3090
	jmp	find_next_section
3131
	jmp	find_next_section
3091
      skip_public:
3132
      skip_public:
3092
	add	esi,10h
3133
	add	esi,10h
3093
	jmp	find_next_section
3134
	jmp	find_next_section
3094
      make_section_symbol:
3135
      make_section_symbol:
3095
	mov	eax,edi
3136
	mov	eax,edi
3096
	xchg	eax,[ebx+4]
3137
	xchg	eax,[ebx+4]
3097
	stos	dword [edi]
3138
	stos	dword [edi]
3098
	test	[format_flags],8
3139
	test	[format_flags],8
3099
	jnz	elf64_section_symbol
3140
	jnz	elf64_section_symbol
3100
	xor	eax,eax
3141
	xor	eax,eax
3101
	stos	dword [edi]
3142
	stos	dword [edi]
3102
	stos	dword [edi]
3143
	stos	dword [edi]
3103
	call	store_section_index
3144
	call	store_section_index
3104
	jmp	section_symbol_ok
3145
	jmp	section_symbol_ok
3105
      store_section_index:
3146
      store_section_index:
3106
	inc	ecx
3147
	inc	ecx
3107
	mov	eax,ecx
3148
	mov	eax,ecx
3108
	shl	eax,8
3149
	shl	eax,8
3109
	mov	[ebx],eax
3150
	mov	[ebx],eax
3110
	inc	dx
3151
	inc	dx
3111
	jz	format_limitations_exceeded
3152
	jz	format_limitations_exceeded
3112
	mov	eax,edx
3153
	mov	eax,edx
3113
	shl	eax,16
3154
	shl	eax,16
3114
	mov	al,3
3155
	mov	al,3
3115
	test	byte [ebx+14h],40h
3156
	test	byte [ebx+14h],40h
3116
	jz	section_index_ok
3157
	jz	section_index_ok
3117
	or	ah,-1
3158
	or	ah,-1
3118
	inc	dx
3159
	inc	dx
3119
	jz	format_limitations_exceeded
3160
	jz	format_limitations_exceeded
3120
      section_index_ok:
3161
      section_index_ok:
3121
	stos	dword [edi]
3162
	stos	dword [edi]
3122
	ret
3163
	ret
3123
      elf64_section_symbol:
3164
      elf64_section_symbol:
3124
	call	store_section_index
3165
	call	store_section_index
3125
	xor	eax,eax
3166
	xor	eax,eax
3126
	stos	dword [edi]
3167
	stos	dword [edi]
3127
	stos	dword [edi]
3168
	stos	dword [edi]
3128
	stos	dword [edi]
3169
	stos	dword [edi]
3129
	stos	dword [edi]
3170
	stos	dword [edi]
3130
      section_symbol_ok:
3171
      section_symbol_ok:
3131
	mov	ebx,esi
3172
	mov	ebx,esi
3132
	add	esi,20h
3173
	add	esi,20h
3133
	cmp	ebx,[free_additional_memory]
3174
	cmp	ebx,[free_additional_memory]
3134
	jne	find_next_section
3175
	jne	find_next_section
3135
	inc	dx
3176
	inc	dx
3136
	jz	format_limitations_exceeded
3177
	jz	format_limitations_exceeded
3137
	mov	[current_section],edx
3178
	mov	[current_section],edx
3138
	mov	esi,[symbols_stream]
3179
	mov	esi,[symbols_stream]
3139
      find_other_symbols:
3180
      find_other_symbols:
3140
	cmp	esi,[free_additional_memory]
3181
	cmp	esi,[free_additional_memory]
3141
	je	elf_symbol_table_ok
3182
	je	elf_symbol_table_ok
3142
	mov	al,[esi]
3183
	mov	al,[esi]
3143
	or	al,al
3184
	or	al,al
3144
	jz	skip_section
3185
	jz	skip_section
3145
	cmp	al,0C0h
3186
	cmp	al,0C0h
3146
	jae	make_public_symbol
3187
	jae	make_public_symbol
3147
	cmp	al,80h
3188
	cmp	al,80h
3148
	jae	make_extrn_symbol
3189
	jae	make_extrn_symbol
3149
	add	esi,0Ch
3190
	add	esi,0Ch
3150
	jmp	find_other_symbols
3191
	jmp	find_other_symbols
3151
      skip_section:
3192
      skip_section:
3152
	add	esi,20h
3193
	add	esi,20h
3153
	jmp	find_other_symbols
3194
	jmp	find_other_symbols
3154
      make_public_symbol:
3195
      make_public_symbol:
3155
	mov	eax,[esi+0Ch]
3196
	mov	eax,[esi+0Ch]
3156
	mov	[current_line],eax
3197
	mov	[current_line],eax
3157
	cmp	byte [esi],0C0h
3198
	cmp	byte [esi],0C0h
3158
	jne	invalid_argument
3199
	jne	invalid_argument
3159
	mov	ebx,[esi+8]
3200
	mov	ebx,[esi+8]
3160
	test	byte [ebx+8],1
3201
	test	byte [ebx+8],1
3161
	jz	undefined_public
3202
	jz	undefined_public
3162
	mov	ax,[current_pass]
3203
	mov	ax,[current_pass]
3163
	cmp	ax,[ebx+16]
3204
	cmp	ax,[ebx+16]
3164
	jne	undefined_public
3205
	jne	undefined_public
3165
	mov	dl,[ebx+11]
3206
	mov	dl,[ebx+11]
3166
	or	dl,dl
3207
	or	dl,dl
3167
	jz	public_absolute
3208
	jz	public_absolute
3168
	mov	eax,[ebx+20]
3209
	mov	eax,[ebx+20]
3169
	cmp	byte [eax],0
3210
	cmp	byte [eax],0
3170
	jne	invalid_use_of_symbol
3211
	jne	invalid_use_of_symbol
3171
	mov	eax,[eax+4]
3212
	mov	eax,[eax+4]
3172
	test	[format_flags],8
3213
	test	[format_flags],8
3173
	jnz	elf64_public
3214
	jnz	elf64_public
3174
	cmp	dl,2
3215
	cmp	dl,2
3175
	jne	invalid_use_of_symbol
3216
	jne	invalid_use_of_symbol
3176
	mov	dx,[eax+0Eh]
3217
	mov	dx,[eax+0Eh]
3177
	jmp	section_for_public_ok
3218
	jmp	section_for_public_ok
3178
      undefined_public:
3219
      undefined_public:
3179
	mov	eax,[ebx+24]
3220
	mov	eax,[ebx+24]
3180
	mov	[error_info],eax
3221
	mov	[error_info],eax
3181
	jmp	undefined_symbol
3222
	jmp	undefined_symbol
3182
      elf64_public:
3223
      elf64_public:
3183
	cmp	dl,4
3224
	cmp	dl,4
3184
	jne	invalid_use_of_symbol
3225
	jne	invalid_use_of_symbol
3185
	mov	dx,[eax+6]
3226
	mov	dx,[eax+6]
3186
	jmp	section_for_public_ok
3227
	jmp	section_for_public_ok
3187
      public_absolute:
3228
      public_absolute:
3188
	mov	dx,0FFF1h
3229
	mov	dx,0FFF1h
3189
      section_for_public_ok:
3230
      section_for_public_ok:
3190
	mov	eax,[esi+4]
3231
	mov	eax,[esi+4]
3191
	stos	dword [edi]
3232
	stos	dword [edi]
3192
	test	[format_flags],8
3233
	test	[format_flags],8
3193
	jnz	elf64_public_symbol
3234
	jnz	elf64_public_symbol
3194
	call	get_public_value
3235
	call	get_public_value
3195
	stos	dword [edi]
3236
	stos	dword [edi]
3196
	xor	eax,eax
3237
	xor	eax,eax
3197
	mov	al,[ebx+10]
3238
	mov	al,[ebx+10]
3198
	stos	dword [edi]
3239
	stos	dword [edi]
3199
	mov	eax,edx
3240
	mov	eax,edx
3200
	shl	eax,16
3241
	shl	eax,16
3201
	mov	al,10h
3242
	mov	al,10h
3202
	cmp	byte [ebx+10],0
3243
	cmp	byte [ebx+10],0
3203
	je	elf_public_function
3244
	je	elf_public_function
3204
	or	al,1
3245
	or	al,1
3205
	jmp	store_elf_public_info
3246
	jmp	store_elf_public_info
3206
      elf_public_function:
3247
      elf_public_function:
3207
	or	al,2
3248
	or	al,2
3208
      store_elf_public_info:
3249
      store_elf_public_info:
3209
	stos	dword [edi]
3250
	stos	dword [edi]
3210
	jmp	public_symbol_ok
3251
	jmp	public_symbol_ok
3211
      elf64_public_symbol:
3252
      elf64_public_symbol:
3212
	mov	eax,edx
3253
	mov	eax,edx
3213
	shl	eax,16
3254
	shl	eax,16
3214
	mov	al,10h
3255
	mov	al,10h
3215
	cmp	byte [ebx+10],0
3256
	cmp	byte [ebx+10],0
3216
	je	elf64_public_function
3257
	je	elf64_public_function
3217
	or	al,1
3258
	or	al,1
3218
	jmp	store_elf64_public_info
3259
	jmp	store_elf64_public_info
3219
      elf64_public_function:
3260
      elf64_public_function:
3220
	or	al,2
3261
	or	al,2
3221
      store_elf64_public_info:
3262
      store_elf64_public_info:
3222
	stos	dword [edi]
3263
	stos	dword [edi]
3223
	call	get_public_value
3264
	call	get_public_value
3224
	stos	dword [edi]
3265
	stos	dword [edi]
3225
	xor	eax,eax
3266
	xor	eax,eax
3226
	stos	dword [edi]
3267
	stos	dword [edi]
3227
	mov	al,[ebx+10]
3268
	mov	al,[ebx+10]
3228
	stos	dword [edi]
3269
	stos	dword [edi]
3229
	xor	al,al
3270
	xor	al,al
3230
	stos	dword [edi]
3271
	stos	dword [edi]
3231
      public_symbol_ok:
3272
      public_symbol_ok:
3232
	inc	ecx
3273
	inc	ecx
3233
	mov	eax,ecx
3274
	mov	eax,ecx
3234
	shl	eax,8
3275
	shl	eax,8
3235
	mov	al,0C0h
3276
	mov	al,0C0h
3236
	mov	[esi],eax
3277
	mov	[esi],eax
3237
	add	esi,10h
3278
	add	esi,10h
3238
	jmp	find_other_symbols
3279
	jmp	find_other_symbols
3239
      get_public_value:
3280
      get_public_value:
3240
	mov	eax,[ebx]
3281
	mov	eax,[ebx]
3241
	cmp	dword [ebx+4],0
3282
	cmp	dword [ebx+4],0
3242
	je	public_value_ok
3283
	je	public_value_ok
3243
	cmp	dword [ebx+4],-1
3284
	cmp	dword [ebx+4],-1
3244
	jne	value_out_of_range
3285
	jne	value_out_of_range
3245
	bt	eax,31
3286
	bt	eax,31
3246
	jnc	value_out_of_range
3287
	jnc	value_out_of_range
3247
      public_value_ok:
3288
      public_value_ok:
3248
	ret
3289
	ret
3249
      make_extrn_symbol:
3290
      make_extrn_symbol:
3250
	mov	eax,[esi+4]
3291
	mov	eax,[esi+4]
3251
	stos	dword [edi]
3292
	stos	dword [edi]
3252
	test	[format_flags],8
3293
	test	[format_flags],8
3253
	jnz	elf64_extrn_symbol
3294
	jnz	elf64_extrn_symbol
3254
	xor	eax,eax
3295
	xor	eax,eax
3255
	stos	dword [edi]
3296
	stos	dword [edi]
3256
	mov	eax,[esi+8]
3297
	mov	eax,[esi+8]
3257
	stos	dword [edi]
3298
	stos	dword [edi]
3258
	mov	eax,10h
3299
	mov	eax,10h
3259
	stos	dword [edi]
3300
	stos	dword [edi]
3260
	jmp	extrn_symbol_ok
3301
	jmp	extrn_symbol_ok
3261
      elf64_extrn_symbol:
3302
      elf64_extrn_symbol:
3262
	mov	eax,10h
3303
	mov	eax,10h
3263
	stos	dword [edi]
3304
	stos	dword [edi]
3264
	xor	al,al
3305
	xor	al,al
3265
	stos	dword [edi]
3306
	stos	dword [edi]
3266
	stos	dword [edi]
3307
	stos	dword [edi]
3267
	mov	eax,[esi+8]
3308
	mov	eax,[esi+8]
3268
	stos	dword [edi]
3309
	stos	dword [edi]
3269
	xor	eax,eax
3310
	xor	eax,eax
3270
	stos	dword [edi]
3311
	stos	dword [edi]
3271
      extrn_symbol_ok:
3312
      extrn_symbol_ok:
3272
	inc	ecx
3313
	inc	ecx
3273
	mov	eax,ecx
3314
	mov	eax,ecx
3274
	shl	eax,8
3315
	shl	eax,8
3275
	mov	al,80h
3316
	mov	al,80h
3276
	mov	[esi],eax
3317
	mov	[esi],eax
3277
	add	esi,0Ch
3318
	add	esi,0Ch
3278
	jmp	find_other_symbols
3319
	jmp	find_other_symbols
3279
      elf_symbol_table_ok:
3320
      elf_symbol_table_ok:
3280
	mov	edx,edi
3321
	mov	edx,edi
3281
	mov	ebx,[free_additional_memory]
3322
	mov	ebx,[free_additional_memory]
3282
	xor	al,al
3323
	xor	al,al
3283
	stos	byte [edi]
3324
	stos	byte [edi]
3284
	add	edi,16
3325
	add	edi,16
3285
	mov	[edx+1],edx
3326
	mov	[edx+1],edx
3286
	add	ebx,10h
3327
	add	ebx,10h
3287
	test	[format_flags],8
3328
	test	[format_flags],8
3288
	jz	make_string_table
3329
	jz	make_string_table
3289
	add	ebx,8
3330
	add	ebx,8
3290
      make_string_table:
3331
      make_string_table:
3291
	cmp	ebx,edx
3332
	cmp	ebx,edx
3292
	je	elf_string_table_ok
3333
	je	elf_string_table_ok
3293
	test	[format_flags],8
3334
	test	[format_flags],8
3294
	jnz	make_elf64_string
3335
	jnz	make_elf64_string
3295
	cmp	byte [ebx+0Dh],0
3336
	cmp	byte [ebx+0Dh],0
3296
	je	rel_prefix_ok
3337
	je	rel_prefix_ok
3297
	mov	byte [ebx+0Dh],0
3338
	mov	byte [ebx+0Dh],0
3298
	mov	eax,'.rel'
3339
	mov	eax,'.rel'
3299
	stos	dword [edi]
3340
	stos	dword [edi]
3300
      rel_prefix_ok:
3341
      rel_prefix_ok:
3301
	mov	esi,edi
3342
	mov	esi,edi
3302
	sub	esi,edx
3343
	sub	esi,edx
3303
	xchg	esi,[ebx]
3344
	xchg	esi,[ebx]
3304
	add	ebx,10h
3345
	add	ebx,10h
3305
      make_elf_string:
3346
      make_elf_string:
3306
	or	esi,esi
3347
	or	esi,esi
3307
	jz	default_string
3348
	jz	default_string
3308
	lods	dword [esi]
3349
	lods	dword [esi]
3309
	mov	ecx,eax
3350
	mov	ecx,eax
3310
	rep	movs byte [edi],[esi]
3351
	rep	movs byte [edi],[esi]
3311
	xor	al,al
3352
	xor	al,al
3312
	stos	byte [edi]
3353
	stos	byte [edi]
3313
	jmp	make_string_table
3354
	jmp	make_string_table
3314
      make_elf64_string:
3355
      make_elf64_string:
3315
	cmp	byte [ebx+5],0
3356
	cmp	byte [ebx+5],0
3316
	je	elf64_rel_prefix_ok
3357
	je	elf64_rel_prefix_ok
3317
	mov	byte [ebx+5],0
3358
	mov	byte [ebx+5],0
3318
	mov	eax,'.rel'
3359
	mov	eax,'.rel'
3319
	stos	dword [edi]
3360
	stos	dword [edi]
3320
	mov	al,'a'
3361
	mov	al,'a'
3321
	stos	byte [edi]
3362
	stos	byte [edi]
3322
      elf64_rel_prefix_ok:
3363
      elf64_rel_prefix_ok:
3323
	mov	esi,edi
3364
	mov	esi,edi
3324
	sub	esi,edx
3365
	sub	esi,edx
3325
	xchg	esi,[ebx]
3366
	xchg	esi,[ebx]
3326
	add	ebx,18h
3367
	add	ebx,18h
3327
	jmp	make_elf_string
3368
	jmp	make_elf_string
3328
      default_string:
3369
      default_string:
3329
	mov	eax,'.fla'
3370
	mov	eax,'.fla'
3330
	stos	dword [edi]
3371
	stos	dword [edi]
3331
	mov	ax,'t'
3372
	mov	ax,'t'
3332
	stos	word [edi]
3373
	stos	word [edi]
3333
	jmp	make_string_table
3374
	jmp	make_string_table
3334
      elf_string_table_ok:
3375
      elf_string_table_ok:
3335
	mov	[edx+1+8],edi
3376
	mov	[edx+1+8],edi
3336
	mov	ebx,[code_start]
3377
	mov	ebx,[code_start]
3337
	mov	eax,edi
3378
	mov	eax,edi
3338
	sub	eax,[free_additional_memory]
3379
	sub	eax,[free_additional_memory]
3339
	test	[format_flags],8
3380
	test	[format_flags],8
3340
	jnz	finish_elf64_header
3381
	jnz	finish_elf64_header
3341
	mov	[ebx+20h],eax
3382
	mov	[ebx+20h],eax
3342
	mov	eax,[current_section]
3383
	mov	eax,[current_section]
3343
	inc	ax
3384
	inc	ax
3344
	jz	format_limitations_exceeded
3385
	jz	format_limitations_exceeded
3345
	mov	[ebx+32h],ax
3386
	mov	[ebx+32h],ax
3346
	inc	ax
3387
	inc	ax
3347
	jz	format_limitations_exceeded
3388
	jz	format_limitations_exceeded
3348
	mov	[ebx+30h],ax
3389
	mov	[ebx+30h],ax
3349
	jmp	elf_header_finished
3390
	jmp	elf_header_finished
3350
      finish_elf64_header:
3391
      finish_elf64_header:
3351
	mov	[ebx+28h],eax
3392
	mov	[ebx+28h],eax
3352
	mov	eax,[current_section]
3393
	mov	eax,[current_section]
3353
	inc	ax
3394
	inc	ax
3354
	jz	format_limitations_exceeded
3395
	jz	format_limitations_exceeded
3355
	mov	[ebx+3Eh],ax
3396
	mov	[ebx+3Eh],ax
3356
	inc	ax
3397
	inc	ax
3357
	jz	format_limitations_exceeded
3398
	jz	format_limitations_exceeded
3358
	mov	[ebx+3Ch],ax
3399
	mov	[ebx+3Ch],ax
3359
      elf_header_finished:
3400
      elf_header_finished:
3360
	xor	eax,eax
3401
	xor	eax,eax
3361
	mov	ecx,10
3402
	mov	ecx,10
3362
	rep	stos dword [edi]
3403
	rep	stos dword [edi]
3363
	test	[format_flags],8
3404
	test	[format_flags],8
3364
	jz	elf_null_section_ok
3405
	jz	elf_null_section_ok
3365
	mov	ecx,6
3406
	mov	ecx,6
3366
	rep	stos dword [edi]
3407
	rep	stos dword [edi]
3367
      elf_null_section_ok:
3408
      elf_null_section_ok:
3368
	mov	esi,ebp
3409
	mov	esi,ebp
3369
	xor	ecx,ecx
3410
	xor	ecx,ecx
3370
      make_section_entry:
3411
      make_section_entry:
3371
	mov	ebx,edi
3412
	mov	ebx,edi
3372
	mov	eax,[esi+4]
3413
	mov	eax,[esi+4]
3373
	mov	eax,[eax]
3414
	mov	eax,[eax]
3374
	stos	dword [edi]
3415
	stos	dword [edi]
3375
	mov	eax,1
3416
	mov	eax,1
3376
	cmp	dword [esi+0Ch],0
3417
	cmp	dword [esi+0Ch],0
3377
	je	bss_section
3418
	je	bss_section
3378
	test	byte [esi+14h],80h
3419
	test	byte [esi+14h],80h
3379
	jz	section_type_ok
3420
	jz	section_type_ok
3380
      bss_section:
3421
      bss_section:
3381
	mov	al,8
3422
	mov	al,8
3382
      section_type_ok:
3423
      section_type_ok:
3383
	stos	dword [edi]
3424
	stos	dword [edi]
3384
	mov	eax,[esi+14h]
3425
	mov	eax,[esi+14h]
3385
	and	al,3Fh
3426
	and	al,3Fh
3386
	call	store_elf_machine_word
3427
	call	store_elf_machine_word
3387
	xor	eax,eax
3428
	xor	eax,eax
3388
	call	store_elf_machine_word
3429
	call	store_elf_machine_word
3389
	mov	eax,[esi+8]
3430
	mov	eax,[esi+8]
3390
	mov	[image_base],eax
3431
	mov	[image_base],eax
3391
	sub	eax,[code_start]
3432
	sub	eax,[code_start]
3392
	call	store_elf_machine_word
3433
	call	store_elf_machine_word
3393
	mov	eax,[esi+0Ch]
3434
	mov	eax,[esi+0Ch]
3394
	call	store_elf_machine_word
3435
	call	store_elf_machine_word
3395
	xor	eax,eax
3436
	xor	eax,eax
3396
	stos	dword [edi]
3437
	stos	dword [edi]
3397
	stos	dword [edi]
3438
	stos	dword [edi]
3398
	mov	eax,[esi+10h]
3439
	mov	eax,[esi+10h]
3399
	call	store_elf_machine_word
3440
	call	store_elf_machine_word
3400
	xor	eax,eax
3441
	xor	eax,eax
3401
	call	store_elf_machine_word
3442
	call	store_elf_machine_word
3402
	inc	ecx
3443
	inc	ecx
3403
	add	esi,20h
3444
	add	esi,20h
3404
	xchg	edi,[esp]
3445
	xchg	edi,[esp]
3405
	mov	ebp,edi
3446
	mov	ebp,edi
3406
      convert_relocations:
3447
      convert_relocations:
3407
	cmp	esi,[free_additional_memory]
3448
	cmp	esi,[free_additional_memory]
3408
	je	relocations_converted
3449
	je	relocations_converted
3409
	mov	al,[esi]
3450
	mov	al,[esi]
3410
	or	al,al
3451
	or	al,al
3411
	jz	relocations_converted
3452
	jz	relocations_converted
3412
	cmp	al,80h
3453
	cmp	al,80h
3413
	jb	make_relocation_entry
3454
	jb	make_relocation_entry
3414
	cmp	al,0C0h
3455
	cmp	al,0C0h
3415
	jb	relocation_entry_ok
3456
	jb	relocation_entry_ok
3416
	add	esi,10h
3457
	add	esi,10h
3417
	jmp	convert_relocations
3458
	jmp	convert_relocations
3418
      make_relocation_entry:
3459
      make_relocation_entry:
3419
	test	[format_flags],8
3460
	test	[format_flags],8
3420
	jnz	make_elf64_relocation_entry
3461
	jnz	make_elf64_relocation_entry
3421
	mov	eax,[esi+4]
3462
	mov	eax,[esi+4]
3422
	stos	dword [edi]
3463
	stos	dword [edi]
3423
	mov	eax,[esi+8]
3464
	mov	eax,[esi+8]
3424
	mov	eax,[eax]
3465
	mov	eax,[eax]
3425
	mov	al,[esi]
3466
	mov	al,[esi]
3426
	stos	dword [edi]
3467
	stos	dword [edi]
3427
	jmp	relocation_entry_ok
3468
	jmp	relocation_entry_ok
3428
      make_elf64_relocation_entry:
3469
      make_elf64_relocation_entry:
3429
	mov	eax,[esi+4]
3470
	mov	eax,[esi+4]
3430
	stos	dword [edi]
3471
	stos	dword [edi]
3431
	xor	eax,eax
3472
	xor	eax,eax
3432
	stos	dword [edi]
3473
	stos	dword [edi]
3433
	movzx	eax,byte [esi]
3474
	movzx	eax,byte [esi]
3434
	stos	dword [edi]
3475
	stos	dword [edi]
3435
	mov	eax,[esi+8]
3476
	mov	eax,[esi+8]
3436
	mov	eax,[eax]
3477
	mov	eax,[eax]
3437
	shr	eax,8
3478
	shr	eax,8
3438
	stos	dword [edi]
3479
	stos	dword [edi]
3439
	xor	eax,eax
3480
	xor	eax,eax
3440
	stos	dword [edi]
3481
	stos	dword [edi]
3441
	stos	dword [edi]
3482
	stos	dword [edi]
3442
      relocation_entry_ok:
3483
      relocation_entry_ok:
3443
	add	esi,0Ch
3484
	add	esi,0Ch
3444
	jmp	convert_relocations
3485
	jmp	convert_relocations
3445
      store_elf_machine_word:
3486
      store_elf_machine_word:
3446
	stos	dword [edi]
3487
	stos	dword [edi]
3447
	test	[format_flags],8
3488
	test	[format_flags],8
3448
	jz	elf_machine_word_ok
3489
	jz	elf_machine_word_ok
3449
	mov	dword [edi],0
3490
	mov	dword [edi],0
3450
	add	edi,4
3491
	add	edi,4
3451
      elf_machine_word_ok:
3492
      elf_machine_word_ok:
3452
	ret
3493
	ret
3453
      relocations_converted:
3494
      relocations_converted:
3454
	cmp	edi,ebp
3495
	cmp	edi,ebp
3455
	xchg	edi,[esp]
3496
	xchg	edi,[esp]
3456
	je	rel_section_ok
3497
	je	rel_section_ok
3457
	mov	eax,[ebx]
3498
	mov	eax,[ebx]
3458
	sub	eax,4
3499
	sub	eax,4
3459
	test	[format_flags],8
3500
	test	[format_flags],8
3460
	jz	store_relocations_name_offset
3501
	jz	store_relocations_name_offset
3461
	dec	eax
3502
	dec	eax
3462
      store_relocations_name_offset:
3503
      store_relocations_name_offset:
3463
	stos	dword [edi]
3504
	stos	dword [edi]
3464
	test	[format_flags],8
3505
	test	[format_flags],8
3465
	jnz	rela_section
3506
	jnz	rela_section
3466
	mov	eax,9
3507
	mov	eax,9
3467
	jmp	store_relocations_type
3508
	jmp	store_relocations_type
3468
      rela_section:
3509
      rela_section:
3469
	mov	eax,4
3510
	mov	eax,4
3470
      store_relocations_type:
3511
      store_relocations_type:
3471
	stos	dword [edi]
3512
	stos	dword [edi]
3472
	xor	al,al
3513
	xor	al,al
3473
	call	store_elf_machine_word
3514
	call	store_elf_machine_word
3474
	call	store_elf_machine_word
3515
	call	store_elf_machine_word
3475
	mov	eax,ebp
3516
	mov	eax,ebp
3476
	sub	eax,[code_start]
3517
	sub	eax,[code_start]
3477
	call	store_elf_machine_word
3518
	call	store_elf_machine_word
3478
	mov	eax,[esp]
3519
	mov	eax,[esp]
3479
	sub	eax,ebp
3520
	sub	eax,ebp
3480
	call	store_elf_machine_word
3521
	call	store_elf_machine_word
3481
	mov	eax,[current_section]
3522
	mov	eax,[current_section]
3482
	stos	dword [edi]
3523
	stos	dword [edi]
3483
	mov	eax,ecx
3524
	mov	eax,ecx
3484
	stos	dword [edi]
3525
	stos	dword [edi]
3485
	inc	ecx
3526
	inc	ecx
3486
	test	[format_flags],8
3527
	test	[format_flags],8
3487
	jnz	finish_elf64_rela_section
3528
	jnz	finish_elf64_rela_section
3488
	mov	eax,4
3529
	mov	eax,4
3489
	stos	dword [edi]
3530
	stos	dword [edi]
3490
	mov	al,8
3531
	mov	al,8
3491
	stos	dword [edi]
3532
	stos	dword [edi]
3492
	jmp	rel_section_ok
3533
	jmp	rel_section_ok
3493
      finish_elf64_rela_section:
3534
      finish_elf64_rela_section:
3494
	mov	eax,8
3535
	mov	eax,8
3495
	stos	dword [edi]
3536
	stos	dword [edi]
3496
	xor	al,al
3537
	xor	al,al
3497
	stos	dword [edi]
3538
	stos	dword [edi]
3498
	mov	al,24
3539
	mov	al,24
3499
	stos	dword [edi]
3540
	stos	dword [edi]
3500
	xor	al,al
3541
	xor	al,al
3501
	stos	dword [edi]
3542
	stos	dword [edi]
3502
      rel_section_ok:
3543
      rel_section_ok:
3503
	cmp	esi,[free_additional_memory]
3544
	cmp	esi,[free_additional_memory]
3504
	jne	make_section_entry
3545
	jne	make_section_entry
3505
	pop	eax
3546
	pop	eax
3506
	mov	ebx,[code_start]
3547
	mov	ebx,[code_start]
3507
	sub	eax,ebx
3548
	sub	eax,ebx
3508
	mov	[code_size],eax
3549
	mov	[code_size],eax
3509
	mov	ecx,20h
3550
	mov	ecx,20h
3510
	test	[format_flags],8
3551
	test	[format_flags],8
3511
	jz	adjust_elf_section_headers_offset
3552
	jz	adjust_elf_section_headers_offset
3512
	mov	ecx,28h
3553
	mov	ecx,28h
3513
      adjust_elf_section_headers_offset:
3554
      adjust_elf_section_headers_offset:
3514
	add	[ebx+ecx],eax
3555
	add	[ebx+ecx],eax
3515
	mov	eax,1
3556
	mov	eax,1
3516
	stos	dword [edi]
3557
	stos	dword [edi]
3517
	mov	al,2
3558
	mov	al,2
3518
	stos	dword [edi]
3559
	stos	dword [edi]
3519
	xor	al,al
3560
	xor	al,al
3520
	call	store_elf_machine_word
3561
	call	store_elf_machine_word
3521
	call	store_elf_machine_word
3562
	call	store_elf_machine_word
3522
	mov	eax,[code_size]
3563
	mov	eax,[code_size]
3523
	call	store_elf_machine_word
3564
	call	store_elf_machine_word
3524
	mov	eax,[edx+1]
3565
	mov	eax,[edx+1]
3525
	sub	eax,[free_additional_memory]
3566
	sub	eax,[free_additional_memory]
3526
	call	store_elf_machine_word
3567
	call	store_elf_machine_word
3527
	mov	eax,[current_section]
3568
	mov	eax,[current_section]
3528
	inc	eax
3569
	inc	eax
3529
	stos	dword [edi]
3570
	stos	dword [edi]
3530
	mov	eax,[number_of_sections]
3571
	mov	eax,[number_of_sections]
3531
	inc	eax
3572
	inc	eax
3532
	stos	dword [edi]
3573
	stos	dword [edi]
3533
	test	[format_flags],8
3574
	test	[format_flags],8
3534
	jnz	finish_elf64_sym_section
3575
	jnz	finish_elf64_sym_section
3535
	mov	eax,4
3576
	mov	eax,4
3536
	stos	dword [edi]
3577
	stos	dword [edi]
3537
	mov	al,10h
3578
	mov	al,10h
3538
	stos	dword [edi]
3579
	stos	dword [edi]
3539
	jmp	sym_section_ok
3580
	jmp	sym_section_ok
3540
      finish_elf64_sym_section:
3581
      finish_elf64_sym_section:
3541
	mov	eax,8
3582
	mov	eax,8
3542
	stos	dword [edi]
3583
	stos	dword [edi]
3543
	xor	al,al
3584
	xor	al,al
3544
	stos	dword [edi]
3585
	stos	dword [edi]
3545
	mov	al,18h
3586
	mov	al,18h
3546
	stos	dword [edi]
3587
	stos	dword [edi]
3547
	xor	al,al
3588
	xor	al,al
3548
	stos	dword [edi]
3589
	stos	dword [edi]
3549
      sym_section_ok:
3590
      sym_section_ok:
3550
	mov	al,1+8
3591
	mov	al,1+8
3551
	stos	dword [edi]
3592
	stos	dword [edi]
3552
	mov	al,3
3593
	mov	al,3
3553
	stos	dword [edi]
3594
	stos	dword [edi]
3554
	xor	al,al
3595
	xor	al,al
3555
	call	store_elf_machine_word
3596
	call	store_elf_machine_word
3556
	call	store_elf_machine_word
3597
	call	store_elf_machine_word
3557
	mov	eax,[edx+1]
3598
	mov	eax,[edx+1]
3558
	sub	eax,[free_additional_memory]
3599
	sub	eax,[free_additional_memory]
3559
	add	eax,[code_size]
3600
	add	eax,[code_size]
3560
	call	store_elf_machine_word
3601
	call	store_elf_machine_word
3561
	mov	eax,[edx+1+8]
3602
	mov	eax,[edx+1+8]
3562
	sub	eax,[edx+1]
3603
	sub	eax,[edx+1]
3563
	call	store_elf_machine_word
3604
	call	store_elf_machine_word
3564
	xor	eax,eax
3605
	xor	eax,eax
3565
	stos	dword [edi]
3606
	stos	dword [edi]
3566
	stos	dword [edi]
3607
	stos	dword [edi]
3567
	mov	al,1
3608
	mov	al,1
3568
	call	store_elf_machine_word
3609
	call	store_elf_machine_word
3569
	xor	eax,eax
3610
	xor	eax,eax
3570
	call	store_elf_machine_word
3611
	call	store_elf_machine_word
3571
	mov	eax,'tab'
3612
	mov	eax,'tab'
3572
	mov	dword [edx+1],'.sym'
3613
	mov	dword [edx+1],'.sym'
3573
	mov	[edx+1+4],eax
3614
	mov	[edx+1+4],eax
3574
	mov	dword [edx+1+8],'.str'
3615
	mov	dword [edx+1+8],'.str'
3575
	mov	[edx+1+8+4],eax
3616
	mov	[edx+1+8+4],eax
3576
	mov	[resource_data],edx
3617
	mov	[resource_data],edx
3577
	mov	[written_size],0
3618
	mov	[written_size],0
3578
	mov	edx,[output_file]
3619
	mov	edx,[output_file]
3579
	call	create
3620
	call	create
3580
	jc	write_failed
3621
	jc	write_failed
3581
	call	write_code
3622
	call	write_code
3582
	mov	ecx,edi
3623
	mov	ecx,edi
3583
	mov	edx,[free_additional_memory]
3624
	mov	edx,[free_additional_memory]
3584
	sub	ecx,edx
3625
	sub	ecx,edx
3585
	add	[written_size],ecx
3626
	add	[written_size],ecx
3586
	call	write
3627
	call	write
3587
	jc	write_failed
3628
	jc	write_failed
3588
	jmp	output_written
3629
	jmp	output_written
3589
 
3630
 
3590
format_elf_exe:
3631
format_elf_exe:
3591
	add	esi,2
3632
	add	esi,2
3592
	or	[format_flags],1
3633
	or	[format_flags],1
3593
	cmp	byte [esi],'('
3634
	cmp	byte [esi],'('
3594
	jne	elf_exe_brand_ok
3635
	jne	elf_exe_brand_ok
3595
	inc	esi
3636
	inc	esi
3596
	cmp	byte [esi],'.'
3637
	cmp	byte [esi],'.'
3597
	je	invalid_value
3638
	je	invalid_value
3598
	push	edx
3639
	push	edx
3599
	call	get_byte_value
3640
	call	get_byte_value
3600
	cmp	[value_type],0
3641
	cmp	[value_type],0
3601
	jne	invalid_use_of_symbol
3642
	jne	invalid_use_of_symbol
3602
	pop	edx
3643
	pop	edx
3603
	mov	[edx+7],al
3644
	mov	[edx+7],al
3604
      elf_exe_brand_ok:
3645
      elf_exe_brand_ok:
3605
	mov	[image_base],8048000h
3646
	mov	[image_base],8048000h
3606
	cmp	byte [esi],80h
3647
	cmp	byte [esi],80h
3607
	jne	elf_exe_base_ok
3648
	jne	elf_exe_base_ok
3608
	lods	word [esi]
3649
	lods	word [esi]
3609
	cmp	ah,'('
3650
	cmp	ah,'('
3610
	jne	invalid_argument
3651
	jne	invalid_argument
3611
	cmp	byte [esi],'.'
3652
	cmp	byte [esi],'.'
3612
	je	invalid_value
3653
	je	invalid_value
3613
	push	edx
3654
	push	edx
3614
	call	get_dword_value
3655
	call	get_dword_value
3615
	cmp	[value_type],0
3656
	cmp	[value_type],0
3616
	jne	invalid_use_of_symbol
3657
	jne	invalid_use_of_symbol
3617
	mov	[image_base],eax
3658
	mov	[image_base],eax
3618
	pop	edx
3659
	pop	edx
3619
      elf_exe_base_ok:
3660
      elf_exe_base_ok:
3620
	mov	byte [edx+10h],2
3661
	mov	byte [edx+10h],2
3621
	mov	byte [edx+2Ah],20h
3662
	mov	byte [edx+2Ah],20h
3622
	mov	ebx,edi
3663
	mov	ebx,edi
3623
	mov	ecx,20h shr 2
3664
	mov	ecx,20h shr 2
3624
	cmp	[current_pass],0
3665
	cmp	[current_pass],0
3625
	je	init_elf_segments
3666
	je	init_elf_segments
3626
	imul	ecx,[number_of_sections]
3667
	imul	ecx,[number_of_sections]
3627
      init_elf_segments:
3668
      init_elf_segments:
3628
	xor	eax,eax
3669
	xor	eax,eax
3629
	rep	stos dword [edi]
3670
	rep	stos dword [edi]
3630
	mov	[number_of_sections],0
3671
	mov	[number_of_sections],0
3631
	mov	byte [ebx],1
3672
	mov	byte [ebx],1
3632
	mov	word [ebx+1Ch],1000h
3673
	mov	word [ebx+1Ch],1000h
3633
	mov	byte [ebx+18h],111b
3674
	mov	byte [ebx+18h],111b
3634
	mov	eax,edi
3675
	mov	eax,edi
3635
	sub	eax,[code_start]
3676
	sub	eax,[code_start]
3636
	mov	[ebx+4],eax
3677
	mov	[ebx+4],eax
3637
	add	eax,[image_base]
3678
	add	eax,[image_base]
3638
	mov	[ebx+8],eax
3679
	mov	[ebx+8],eax
3639
	mov	[ebx+0Ch],eax
3680
	mov	[ebx+0Ch],eax
3640
	mov	[edx+18h],eax
3681
	mov	[edx+18h],eax
3641
	xor	edx,edx
3682
	xor	edx,edx
3642
	not	eax
3683
	not	eax
3643
	not	edx
3684
	not	edx
3644
	add	eax,1
3685
	add	eax,1
3645
	adc	edx,0
3686
	adc	edx,0
3646
	add	eax,edi
3687
	add	eax,edi
3647
	adc	edx,0
3688
	adc	edx,0
3648
	mov	dword [org_origin],eax
3689
	mov	dword [org_origin],eax
3649
	mov	dword [org_origin+4],edx
3690
	mov	dword [org_origin+4],edx
3650
	mov	[org_registers],0
3691
	mov	[org_registers],0
3651
	mov	[org_start],edi
3692
	mov	[org_start],edi
3652
	mov	[symbols_stream],edi
3693
	mov	[symbols_stream],edi
3653
	jmp	format_defined
3694
	jmp	format_defined
3654
      format_elf64_exe:
3695
      format_elf64_exe:
3655
	add	esi,2
3696
	add	esi,2
3656
	or	[format_flags],1
3697
	or	[format_flags],1
3657
	cmp	byte [esi],'('
3698
	cmp	byte [esi],'('
3658
	jne	elf64_exe_brand_ok
3699
	jne	elf64_exe_brand_ok
3659
	inc	esi
3700
	inc	esi
3660
	cmp	byte [esi],'.'
3701
	cmp	byte [esi],'.'
3661
	je	invalid_value
3702
	je	invalid_value
3662
	push	edx
3703
	push	edx
3663
	call	get_byte_value
3704
	call	get_byte_value
3664
	cmp	[value_type],0
3705
	cmp	[value_type],0
3665
	jne	invalid_use_of_symbol
3706
	jne	invalid_use_of_symbol
3666
	pop	edx
3707
	pop	edx
3667
	mov	[edx+7],al
3708
	mov	[edx+7],al
3668
      elf64_exe_brand_ok:
3709
      elf64_exe_brand_ok:
3669
	mov	[image_base],400000h
3710
	mov	[image_base],400000h
3670
	mov	[image_base_high],0
3711
	mov	[image_base_high],0
3671
	cmp	byte [esi],80h
3712
	cmp	byte [esi],80h
3672
	jne	elf64_exe_base_ok
3713
	jne	elf64_exe_base_ok
3673
	lods	word [esi]
3714
	lods	word [esi]
3674
	cmp	ah,'('
3715
	cmp	ah,'('
3675
	jne	invalid_argument
3716
	jne	invalid_argument
3676
	cmp	byte [esi],'.'
3717
	cmp	byte [esi],'.'
3677
	je	invalid_value
3718
	je	invalid_value
3678
	push	edx
3719
	push	edx
3679
	call	get_qword_value
3720
	call	get_qword_value
3680
	cmp	[value_type],0
3721
	cmp	[value_type],0
3681
	jne	invalid_use_of_symbol
3722
	jne	invalid_use_of_symbol
3682
	mov	[image_base],eax
3723
	mov	[image_base],eax
3683
	mov	[image_base_high],edx
3724
	mov	[image_base_high],edx
3684
	pop	edx
3725
	pop	edx
3685
      elf64_exe_base_ok:
3726
      elf64_exe_base_ok:
3686
	mov	byte [edx+10h],2
3727
	mov	byte [edx+10h],2
3687
	mov	byte [edx+36h],38h
3728
	mov	byte [edx+36h],38h
3688
	mov	ebx,edi
3729
	mov	ebx,edi
3689
	mov	ecx,38h shr 2
3730
	mov	ecx,38h shr 2
3690
	cmp	[current_pass],0
3731
	cmp	[current_pass],0
3691
	je	init_elf64_segments
3732
	je	init_elf64_segments
3692
	imul	ecx,[number_of_sections]
3733
	imul	ecx,[number_of_sections]
3693
      init_elf64_segments:
3734
      init_elf64_segments:
3694
	xor	eax,eax
3735
	xor	eax,eax
3695
	rep	stos dword [edi]
3736
	rep	stos dword [edi]
3696
	mov	[number_of_sections],0
3737
	mov	[number_of_sections],0
3697
	mov	byte [ebx],1
3738
	mov	byte [ebx],1
3698
	mov	word [ebx+30h],1000h
3739
	mov	word [ebx+30h],1000h
3699
	mov	byte [ebx+4],111b
3740
	mov	byte [ebx+4],111b
3700
	push	edx
3741
	push	edx
3701
	mov	eax,edi
3742
	mov	eax,edi
3702
	sub	eax,[code_start]
3743
	sub	eax,[code_start]
3703
	mov	[ebx+8],eax
3744
	mov	[ebx+8],eax
3704
	xor	edx,edx
3745
	xor	edx,edx
3705
	add	eax,[image_base]
3746
	add	eax,[image_base]
3706
	adc	edx,[image_base_high]
3747
	adc	edx,[image_base_high]
3707
	mov	[ebx+10h],eax
3748
	mov	[ebx+10h],eax
3708
	mov	[ebx+10h+4],edx
3749
	mov	[ebx+10h+4],edx
3709
	mov	[ebx+18h],eax
3750
	mov	[ebx+18h],eax
3710
	mov	[ebx+18h+4],edx
3751
	mov	[ebx+18h+4],edx
3711
	pop	ebx
3752
	pop	ebx
3712
	mov	[ebx+18h],eax
3753
	mov	[ebx+18h],eax
3713
	mov	[ebx+18h+4],edx
3754
	mov	[ebx+18h+4],edx
3714
	not	eax
3755
	not	eax
3715
	not	edx
3756
	not	edx
3716
	add	eax,1
3757
	add	eax,1
3717
	adc	edx,0
3758
	adc	edx,0
3718
	add	eax,edi
3759
	add	eax,edi
3719
	adc	edx,0
3760
	adc	edx,0
3720
	mov	dword [org_origin],eax
3761
	mov	dword [org_origin],eax
3721
	mov	dword [org_origin+4],edx
3762
	mov	dword [org_origin+4],edx
3722
	mov	[org_registers],0
3763
	mov	[org_registers],0
3723
	mov	[org_start],edi
3764
	mov	[org_start],edi
3724
	mov	[symbols_stream],edi
3765
	mov	[symbols_stream],edi
3725
	jmp	format_defined
3766
	jmp	format_defined
3726
elf_entry:
3767
elf_entry:
3727
	lods	byte [esi]
3768
	lods	byte [esi]
3728
	cmp	al,'('
3769
	cmp	al,'('
3729
	jne	invalid_argument
3770
	jne	invalid_argument
3730
	cmp	byte [esi],'.'
3771
	cmp	byte [esi],'.'
3731
	je	invalid_value
3772
	je	invalid_value
3732
	test	[format_flags],8
3773
	test	[format_flags],8
3733
	jnz	elf64_entry
3774
	jnz	elf64_entry
3734
	call	get_dword_value
3775
	call	get_dword_value
3735
	cmp	[value_type],0
3776
	cmp	[value_type],0
3736
	jne	invalid_use_of_symbol
3777
	jne	invalid_use_of_symbol
3737
	mov	edx,[code_start]
3778
	mov	edx,[code_start]
3738
	mov	[edx+18h],eax
3779
	mov	[edx+18h],eax
3739
	jmp	instruction_assembled
3780
	jmp	instruction_assembled
3740
      elf64_entry:
3781
      elf64_entry:
3741
	call	get_qword_value
3782
	call	get_qword_value
3742
	cmp	[value_type],0
3783
	cmp	[value_type],0
3743
	jne	invalid_use_of_symbol
3784
	jne	invalid_use_of_symbol
3744
	mov	ebx,[code_start]
3785
	mov	ebx,[code_start]
3745
	mov	[ebx+18h],eax
3786
	mov	[ebx+18h],eax
3746
	mov	[ebx+1Ch],edx
3787
	mov	[ebx+1Ch],edx
3747
	jmp	instruction_assembled
3788
	jmp	instruction_assembled
3748
elf_segment:
3789
elf_segment:
3749
	bt	[format_flags],0
3790
	bt	[format_flags],0
3750
	jnc	illegal_instruction
3791
	jnc	illegal_instruction
3751
	test	[format_flags],8
3792
	test	[format_flags],8
3752
	jnz	elf64_segment
3793
	jnz	elf64_segment
3753
	call	close_elf_segment
3794
	call	close_elf_segment
3754
	push	eax
3795
	push	eax
3755
	mov	ebx,[number_of_sections]
3796
	mov	ebx,[number_of_sections]
3756
	shl	ebx,5
3797
	shl	ebx,5
3757
	add	ebx,[code_start]
3798
	add	ebx,[code_start]
3758
	add	ebx,34h
3799
	add	ebx,34h
3759
	cmp	ebx,[symbols_stream]
3800
	cmp	ebx,[symbols_stream]
3760
	jb	new_elf_segment
3801
	jb	new_elf_segment
3761
	mov	ebx,[symbols_stream]
3802
	mov	ebx,[symbols_stream]
3762
	sub	ebx,20h
3803
	sub	ebx,20h
3763
	push	edi
3804
	push	edi
3764
	mov	edi,ebx
3805
	mov	edi,ebx
3765
	mov	ecx,20h shr 2
3806
	mov	ecx,20h shr 2
3766
	xor	eax,eax
3807
	xor	eax,eax
3767
	rep	stos dword [edi]
3808
	rep	stos dword [edi]
3768
	pop	edi
3809
	pop	edi
3769
	or	[next_pass_needed],-1
3810
	or	[next_pass_needed],-1
3770
      new_elf_segment:
3811
      new_elf_segment:
3771
	mov	byte [ebx],1
3812
	mov	byte [ebx],1
3772
	mov	word [ebx+1Ch],1000h
3813
	mov	word [ebx+1Ch],1000h
3773
      elf_segment_flags:
3814
      elf_segment_flags:
3774
	cmp	byte [esi],1Eh
3815
	cmp	byte [esi],1Eh
3775
	je	elf_segment_type
3816
	je	elf_segment_type
3776
	cmp	byte [esi],19h
3817
	cmp	byte [esi],19h
3777
	jne	elf_segment_flags_ok
3818
	jne	elf_segment_flags_ok
3778
	lods	word [esi]
3819
	lods	word [esi]
3779
	sub	ah,28
3820
	sub	ah,28
3780
	jbe	invalid_argument
3821
	jbe	invalid_argument
3781
	cmp	ah,1
3822
	cmp	ah,1
3782
	je	mark_elf_segment_flag
3823
	je	mark_elf_segment_flag
3783
	cmp	ah,3
3824
	cmp	ah,3
3784
	ja	invalid_argument
3825
	ja	invalid_argument
3785
	xor	ah,1
3826
	xor	ah,1
3786
	cmp	ah,2
3827
	cmp	ah,2
3787
	je	mark_elf_segment_flag
3828
	je	mark_elf_segment_flag
3788
	inc	ah
3829
	inc	ah
3789
      mark_elf_segment_flag:
3830
      mark_elf_segment_flag:
3790
	test	[ebx+18h],ah
3831
	test	[ebx+18h],ah
3791
	jnz	setting_already_specified
3832
	jnz	setting_already_specified
3792
	or	[ebx+18h],ah
3833
	or	[ebx+18h],ah
3793
	jmp	elf_segment_flags
3834
	jmp	elf_segment_flags
3794
      elf_segment_type:
3835
      elf_segment_type:
3795
	cmp	byte [ebx],1
3836
	cmp	byte [ebx],1
3796
	jne	setting_already_specified
3837
	jne	setting_already_specified
3797
	lods	word [esi]
3838
	lods	word [esi]
3798
	mov	ecx,[number_of_sections]
3839
	mov	ecx,[number_of_sections]
3799
	jecxz	elf_segment_type_ok
3840
	jecxz	elf_segment_type_ok
3800
	mov	edx,[code_start]
3841
	mov	edx,[code_start]
3801
	add	edx,34h
3842
	add	edx,34h
3802
      scan_elf_segment_types:
3843
      scan_elf_segment_types:
3803
	cmp	edx,[symbols_stream]
3844
	cmp	edx,[symbols_stream]
3804
	jae	elf_segment_type_ok
3845
	jae	elf_segment_type_ok
3805
	cmp	[edx],ah
3846
	cmp	[edx],ah
3806
	je	data_already_defined
3847
	je	data_already_defined
3807
	add	edx,20h
3848
	add	edx,20h
3808
	loop	scan_elf_segment_types
3849
	loop	scan_elf_segment_types
3809
      elf_segment_type_ok:
3850
      elf_segment_type_ok:
3810
	mov	[ebx],ah
3851
	mov	[ebx],ah
3811
	mov	word [ebx+1Ch],1
3852
	mov	word [ebx+1Ch],1
3812
	jmp	elf_segment_flags
3853
	jmp	elf_segment_flags
3813
      elf_segment_flags_ok:
3854
      elf_segment_flags_ok:
3814
	mov	eax,edi
3855
	mov	eax,edi
3815
	sub	eax,[code_start]
3856
	sub	eax,[code_start]
3816
	mov	[ebx+4],eax
3857
	mov	[ebx+4],eax
3817
	pop	edx
3858
	pop	edx
3818
	and	eax,0FFFh
3859
	and	eax,0FFFh
3819
	add	edx,eax
3860
	add	edx,eax
3820
	mov	[ebx+8],edx
3861
	mov	[ebx+8],edx
3821
	mov	[ebx+0Ch],edx
3862
	mov	[ebx+0Ch],edx
3822
	mov	eax,edx
3863
	mov	eax,edx
3823
	xor	edx,edx
3864
	xor	edx,edx
3824
	not	eax
3865
	not	eax
3825
	not	edx
3866
	not	edx
3826
	add	eax,1
3867
	add	eax,1
3827
	adc	edx,0
3868
	adc	edx,0
3828
	add	eax,edi
3869
	add	eax,edi
3829
	adc	edx,0
3870
	adc	edx,0
3830
	mov	dword [org_origin],eax
3871
	mov	dword [org_origin],eax
3831
	mov	dword [org_origin+4],edx
3872
	mov	dword [org_origin+4],edx
3832
	mov	[org_registers],0
3873
	mov	[org_registers],0
3833
	mov	[org_start],edi
3874
	mov	[org_start],edi
3834
	inc	[number_of_sections]
3875
	inc	[number_of_sections]
3835
	jmp	instruction_assembled
3876
	jmp	instruction_assembled
3836
      close_elf_segment:
3877
      close_elf_segment:
3837
	cmp	[number_of_sections],0
3878
	cmp	[number_of_sections],0
3838
	jne	finish_elf_segment
3879
	jne	finish_elf_segment
3839
	cmp	edi,[symbols_stream]
3880
	cmp	edi,[symbols_stream]
3840
	jne	first_elf_segment_ok
3881
	jne	first_elf_segment_ok
3841
	push	edi
3882
	push	edi
3842
	mov	edi,[code_start]
3883
	mov	edi,[code_start]
3843
	add	edi,34h
3884
	add	edi,34h
3844
	mov	ecx,20h shr 2
3885
	mov	ecx,20h shr 2
3845
	xor	eax,eax
3886
	xor	eax,eax
3846
	rep	stos dword [edi]
3887
	rep	stos dword [edi]
3847
	pop	edi
3888
	pop	edi
3848
	mov	eax,[image_base]
3889
	mov	eax,[image_base]
3849
	ret
3890
	ret
3850
      first_elf_segment_ok:
3891
      first_elf_segment_ok:
3851
	inc	[number_of_sections]
3892
	inc	[number_of_sections]
3852
      finish_elf_segment:
3893
      finish_elf_segment:
3853
	mov	ebx,[number_of_sections]
3894
	mov	ebx,[number_of_sections]
3854
	dec	ebx
3895
	dec	ebx
3855
	shl	ebx,5
3896
	shl	ebx,5
3856
	add	ebx,[code_start]
3897
	add	ebx,[code_start]
3857
	add	ebx,34h
3898
	add	ebx,34h
3858
	mov	eax,edi
3899
	mov	eax,edi
3859
	sub	eax,[code_start]
3900
	sub	eax,[code_start]
3860
	sub	eax,[ebx+4]
3901
	sub	eax,[ebx+4]
3861
	mov	edx,edi
3902
	mov	edx,edi
3862
	cmp	edi,[undefined_data_end]
3903
	cmp	edi,[undefined_data_end]
3863
	jne	elf_segment_size_ok
3904
	jne	elf_segment_size_ok
3864
	mov	edi,[undefined_data_start]
3905
	mov	edi,[undefined_data_start]
3865
      elf_segment_size_ok:
3906
      elf_segment_size_ok:
3866
	mov	[ebx+14h],eax
3907
	mov	[ebx+14h],eax
3867
	add	eax,edi
3908
	add	eax,edi
3868
	sub	eax,edx
3909
	sub	eax,edx
3869
	mov	[ebx+10h],eax
3910
	mov	[ebx+10h],eax
3870
	mov	eax,[ebx+8]
3911
	mov	eax,[ebx+8]
3871
	cmp	byte [ebx],1
3912
	cmp	byte [ebx],1
3872
	jne	elf_segment_position_ok
3913
	jne	elf_segment_position_ok
3873
	add	eax,[ebx+14h]
3914
	add	eax,[ebx+14h]
3874
	add	eax,0FFFh
3915
	add	eax,0FFFh
3875
      elf_segment_position_ok:
3916
      elf_segment_position_ok:
3876
	and	eax,not 0FFFh
3917
	and	eax,not 0FFFh
3877
	ret
3918
	ret
3878
      elf64_segment:
3919
      elf64_segment:
3879
	call	close_elf64_segment
3920
	call	close_elf64_segment
3880
	push	eax edx
3921
	push	eax edx
3881
	mov	ebx,[number_of_sections]
3922
	mov	ebx,[number_of_sections]
3882
	imul	ebx,38h
3923
	imul	ebx,38h
3883
	add	ebx,[code_start]
3924
	add	ebx,[code_start]
3884
	add	ebx,40h
3925
	add	ebx,40h
3885
	cmp	ebx,[symbols_stream]
3926
	cmp	ebx,[symbols_stream]
3886
	jb	new_elf64_segment
3927
	jb	new_elf64_segment
3887
	mov	ebx,[symbols_stream]
3928
	mov	ebx,[symbols_stream]
3888
	sub	ebx,38h
3929
	sub	ebx,38h
3889
	push	edi
3930
	push	edi
3890
	mov	edi,ebx
3931
	mov	edi,ebx
3891
	mov	ecx,38h shr 2
3932
	mov	ecx,38h shr 2
3892
	xor	eax,eax
3933
	xor	eax,eax
3893
	rep	stos dword [edi]
3934
	rep	stos dword [edi]
3894
	pop	edi
3935
	pop	edi
3895
	or	[next_pass_needed],-1
3936
	or	[next_pass_needed],-1
3896
      new_elf64_segment:
3937
      new_elf64_segment:
3897
	mov	byte [ebx],1
3938
	mov	byte [ebx],1
3898
	mov	word [ebx+30h],1000h
3939
	mov	word [ebx+30h],1000h
3899
      elf64_segment_flags:
3940
      elf64_segment_flags:
3900
	cmp	byte [esi],1Eh
3941
	cmp	byte [esi],1Eh
3901
	je	elf64_segment_type
3942
	je	elf64_segment_type
3902
	cmp	byte [esi],19h
3943
	cmp	byte [esi],19h
3903
	jne	elf64_segment_flags_ok
3944
	jne	elf64_segment_flags_ok
3904
	lods	word [esi]
3945
	lods	word [esi]
3905
	sub	ah,28
3946
	sub	ah,28
3906
	jbe	invalid_argument
3947
	jbe	invalid_argument
3907
	cmp	ah,1
3948
	cmp	ah,1
3908
	je	mark_elf64_segment_flag
3949
	je	mark_elf64_segment_flag
3909
	cmp	ah,3
3950
	cmp	ah,3
3910
	ja	invalid_argument
3951
	ja	invalid_argument
3911
	xor	ah,1
3952
	xor	ah,1
3912
	cmp	ah,2
3953
	cmp	ah,2
3913
	je	mark_elf64_segment_flag
3954
	je	mark_elf64_segment_flag
3914
	inc	ah
3955
	inc	ah
3915
      mark_elf64_segment_flag:
3956
      mark_elf64_segment_flag:
3916
	test	[ebx+4],ah
3957
	test	[ebx+4],ah
3917
	jnz	setting_already_specified
3958
	jnz	setting_already_specified
3918
	or	[ebx+4],ah
3959
	or	[ebx+4],ah
3919
	jmp	elf64_segment_flags
3960
	jmp	elf64_segment_flags
3920
      elf64_segment_type:
3961
      elf64_segment_type:
3921
	cmp	byte [ebx],1
3962
	cmp	byte [ebx],1
3922
	jne	setting_already_specified
3963
	jne	setting_already_specified
3923
	lods	word [esi]
3964
	lods	word [esi]
3924
	mov	ecx,[number_of_sections]
3965
	mov	ecx,[number_of_sections]
3925
	jecxz	elf64_segment_type_ok
3966
	jecxz	elf64_segment_type_ok
3926
	mov	edx,[code_start]
3967
	mov	edx,[code_start]
3927
	add	edx,40h
3968
	add	edx,40h
3928
      scan_elf64_segment_types:
3969
      scan_elf64_segment_types:
3929
	cmp	edx,[symbols_stream]
3970
	cmp	edx,[symbols_stream]
3930
	jae	elf64_segment_type_ok
3971
	jae	elf64_segment_type_ok
3931
	cmp	[edx],ah
3972
	cmp	[edx],ah
3932
	je	data_already_defined
3973
	je	data_already_defined
3933
	add	edx,38h
3974
	add	edx,38h
3934
	loop	scan_elf64_segment_types
3975
	loop	scan_elf64_segment_types
3935
      elf64_segment_type_ok:
3976
      elf64_segment_type_ok:
3936
	mov	[ebx],ah
3977
	mov	[ebx],ah
3937
	mov	word [ebx+30h],1
3978
	mov	word [ebx+30h],1
3938
	jmp	elf64_segment_flags
3979
	jmp	elf64_segment_flags
3939
      elf64_segment_flags_ok:
3980
      elf64_segment_flags_ok:
3940
	mov	ecx,edi
3981
	mov	ecx,edi
3941
	sub	ecx,[code_start]
3982
	sub	ecx,[code_start]
3942
	mov	[ebx+8],ecx
3983
	mov	[ebx+8],ecx
3943
	pop	edx eax
3984
	pop	edx eax
3944
	and	ecx,0FFFh
3985
	and	ecx,0FFFh
3945
	add	eax,ecx
3986
	add	eax,ecx
3946
	adc	edx,0
3987
	adc	edx,0
3947
	mov	[ebx+10h],eax
3988
	mov	[ebx+10h],eax
3948
	mov	[ebx+10h+4],edx
3989
	mov	[ebx+10h+4],edx
3949
	mov	[ebx+18h],eax
3990
	mov	[ebx+18h],eax
3950
	mov	[ebx+18h+4],edx
3991
	mov	[ebx+18h+4],edx
3951
	not	eax
3992
	not	eax
3952
	not	edx
3993
	not	edx
3953
	add	eax,1
3994
	add	eax,1
3954
	adc	edx,0
3995
	adc	edx,0
3955
	add	eax,edi
3996
	add	eax,edi
3956
	adc	edx,0
3997
	adc	edx,0
3957
	mov	dword [org_origin],eax
3998
	mov	dword [org_origin],eax
3958
	mov	dword [org_origin+4],edx
3999
	mov	dword [org_origin+4],edx
3959
	mov	[org_registers],0
4000
	mov	[org_registers],0
3960
	mov	[org_start],edi
4001
	mov	[org_start],edi
3961
	inc	[number_of_sections]
4002
	inc	[number_of_sections]
3962
	jmp	instruction_assembled
4003
	jmp	instruction_assembled
3963
      close_elf64_segment:
4004
      close_elf64_segment:
3964
	cmp	[number_of_sections],0
4005
	cmp	[number_of_sections],0
3965
	jne	finish_elf64_segment
4006
	jne	finish_elf64_segment
3966
	cmp	edi,[symbols_stream]
4007
	cmp	edi,[symbols_stream]
3967
	jne	first_elf64_segment_ok
4008
	jne	first_elf64_segment_ok
3968
	push	edi
4009
	push	edi
3969
	mov	edi,[code_start]
4010
	mov	edi,[code_start]
3970
	add	edi,40h
4011
	add	edi,40h
3971
	mov	ecx,38h shr 2
4012
	mov	ecx,38h shr 2
3972
	xor	eax,eax
4013
	xor	eax,eax
3973
	rep	stos dword [edi]
4014
	rep	stos dword [edi]
3974
	pop	edi
4015
	pop	edi
3975
	mov	eax,[image_base]
4016
	mov	eax,[image_base]
3976
	mov	edx,[image_base_high]
4017
	mov	edx,[image_base_high]
3977
	ret
4018
	ret
3978
      first_elf64_segment_ok:
4019
      first_elf64_segment_ok:
3979
	inc	[number_of_sections]
4020
	inc	[number_of_sections]
3980
      finish_elf64_segment:
4021
      finish_elf64_segment:
3981
	mov	ebx,[number_of_sections]
4022
	mov	ebx,[number_of_sections]
3982
	dec	ebx
4023
	dec	ebx
3983
	imul	ebx,38h
4024
	imul	ebx,38h
3984
	add	ebx,[code_start]
4025
	add	ebx,[code_start]
3985
	add	ebx,40h
4026
	add	ebx,40h
3986
	mov	eax,edi
4027
	mov	eax,edi
3987
	sub	eax,[code_start]
4028
	sub	eax,[code_start]
3988
	sub	eax,[ebx+8]
4029
	sub	eax,[ebx+8]
3989
	mov	edx,edi
4030
	mov	edx,edi
3990
	cmp	edi,[undefined_data_end]
4031
	cmp	edi,[undefined_data_end]
3991
	jne	elf64_segment_size_ok
4032
	jne	elf64_segment_size_ok
3992
	mov	edi,[undefined_data_start]
4033
	mov	edi,[undefined_data_start]
3993
      elf64_segment_size_ok:
4034
      elf64_segment_size_ok:
3994
	mov	[ebx+28h],eax
4035
	mov	[ebx+28h],eax
3995
	add	eax,edi
4036
	add	eax,edi
3996
	sub	eax,edx
4037
	sub	eax,edx
3997
	mov	[ebx+20h],eax
4038
	mov	[ebx+20h],eax
3998
	mov	eax,[ebx+10h]
4039
	mov	eax,[ebx+10h]
3999
	mov	edx,[ebx+10h+4]
4040
	mov	edx,[ebx+10h+4]
4000
	cmp	byte [ebx],1
4041
	cmp	byte [ebx],1
4001
	jne	elf64_segment_position_ok
4042
	jne	elf64_segment_position_ok
4002
	add	eax,[ebx+28h]
4043
	add	eax,[ebx+28h]
4003
	adc	edx,0
4044
	adc	edx,0
4004
	add	eax,0FFFh
4045
	add	eax,0FFFh
4005
	adc	edx,0
4046
	adc	edx,0
4006
      elf64_segment_position_ok:
4047
      elf64_segment_position_ok:
4007
	and	eax,not 0FFFh
4048
	and	eax,not 0FFFh
4008
	ret
4049
	ret
4009
 
4050
close_elf_exe:
4010
close_elf_exe:
-
 
4011
	test	[format_flags],8
4051
	test	[format_flags],8
4012
	jnz	close_elf64_exe
4052
	jnz	close_elf64_exe
4013
	call	close_elf_segment
4053
	call	close_elf_segment
4014
	mov	edx,[code_start]
4054
	mov	edx,[code_start]
4015
	mov	eax,[number_of_sections]
4055
	mov	eax,[number_of_sections]
4016
	mov	byte [edx+1Ch],34h
4056
	mov	byte [edx+1Ch],34h
4017
	mov	[edx+2Ch],ax
4057
	mov	[edx+2Ch],ax
4018
	shl	eax,5
4058
	shl	eax,5
4019
	add	eax,edx
4059
	add	eax,edx
4020
	add	eax,34h
4060
	add	eax,34h
4021
	cmp	eax,[symbols_stream]
4061
	cmp	eax,[symbols_stream]
4022
	je	elf_exe_ok
4062
	je	elf_exe_ok
4023
	or	[next_pass_needed],-1
4063
	or	[next_pass_needed],-1
4024
      elf_exe_ok:
4064
      elf_exe_ok:
4025
	ret
4065
	ret
4026
      close_elf64_exe:
4066
      close_elf64_exe:
4027
	call	close_elf64_segment
4067
	call	close_elf64_segment
4028
	mov	edx,[code_start]
4068
	mov	edx,[code_start]
4029
	mov	eax,[number_of_sections]
4069
	mov	eax,[number_of_sections]
4030
	mov	byte [edx+20h],40h
4070
	mov	byte [edx+20h],40h
4031
	mov	[edx+38h],ax
4071
	mov	[edx+38h],ax
4032
	imul	eax,38h
4072
	imul	eax,38h
4033
	add	eax,edx
4073
	add	eax,edx
4034
	add	eax,40h
4074
	add	eax,40h
4035
	cmp	eax,[symbols_stream]
4075
	cmp	eax,[symbols_stream]
4036
	je	elf64_exe_ok
4076
	je	elf64_exe_ok
4037
	or	[next_pass_needed],-1
4077
	or	[next_pass_needed],-1
4038
      elf64_exe_ok:
4078
      elf64_exe_ok:
4039
	ret
4079
	ret
4040
 
4080
4041
dump_symbols:
-
 
4042
	mov	ebx,[code_start]
-
 
4043
	mov	dword [ebx],'fas'+1Ah shl 24
-
 
4044
	mov	dword [ebx+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16
-
 
4045
	add	ebx,38h
-
 
4046
	mov	edi,ebx
-
 
4047
	mov	dword [ebx-38h+10h],38h
-
 
4048
	mov	dword [ebx-38h+8],0
-
 
4049
	mov	esi,[input_file]
-
 
4050
	call	copy_asciiz
-
 
4051
	cmp	edi,[display_buffer]
-
 
4052
	jae	out_of_memory
-
 
4053
	mov	eax,edi
-
 
4054
	sub	eax,ebx
-
 
4055
	mov	[ebx-38h+0Ch],eax
-
 
4056
	mov	esi,[output_file]
-
 
4057
	call	copy_asciiz
-
 
4058
	cmp	edi,[display_buffer]
-
 
4059
	jae	out_of_memory
-
 
4060
	mov	edx,[symbols_stream]
-
 
4061
	mov	ebp,[free_additional_memory]
-
 
4062
	mov	[number_of_sections],0
-
 
4063
	cmp	[output_format],4
-
 
4064
	je	prepare_strings_table
-
 
4065
	cmp	[output_format],5
-
 
4066
	jne	strings_table_ready
-
 
4067
	bt	[format_flags],0
-
 
4068
	jc	strings_table_ready
-
 
4069
      prepare_strings_table:
-
 
4070
	cmp	edx,ebp
-
 
4071
	je	strings_table_ready
-
 
4072
	mov	al,[edx]
-
 
4073
	test	al,al
-
 
4074
	jz	prepare_string
-
 
4075
	cmp	al,80h
-
 
4076
	je	prepare_string
-
 
4077
	add	edx,0Ch
-
 
4078
	cmp	al,0C0h
-
 
4079
	jb	prepare_strings_table
-
 
4080
	add	edx,4
-
 
4081
	jmp	prepare_strings_table
-
 
4082
      prepare_string:
-
 
4083
	mov	esi,edi
-
 
4084
	sub	esi,ebx
-
 
4085
	xchg	esi,[edx+4]
-
 
4086
	test	al,al
-
 
4087
	jz	prepare_section_string
-
 
4088
	or	dword [edx+4],1 shl 31
-
 
4089
	add	edx,0Ch
-
 
4090
      prepare_external_string:
-
 
4091
	mov	ecx,[esi]
-
 
4092
	add	esi,4
-
 
4093
	rep	movs byte [edi],[esi]
-
 
4094
	mov	byte [edi],0
-
 
4095
	inc	edi
-
 
4096
	cmp	edi,[display_buffer]
-
 
4097
	jae	out_of_memory
-
 
4098
	jmp	prepare_strings_table
-
 
4099
      prepare_section_string:
-
 
4100
	mov	ecx,[number_of_sections]
-
 
4101
	mov	eax,ecx
-
 
4102
	inc	eax
-
 
4103
	mov	[number_of_sections],eax
-
 
4104
	xchg	eax,[edx+4]
-
 
4105
	shl	ecx,2
-
 
4106
	add	ecx,[free_additional_memory]
-
 
4107
	mov	[ecx],eax
-
 
4108
	add	edx,20h
-
 
4109
	test	esi,esi
-
 
4110
	jz	prepare_default_section_string
-
 
4111
	cmp	[output_format],5
-
 
4112
	jne	prepare_external_string
-
 
4113
	bt	[format_flags],0
-
 
4114
	jc	prepare_external_string
-
 
4115
	mov	esi,[esi]
-
 
4116
	add	esi,[resource_data]
-
 
4117
      copy_elf_section_name:
-
 
4118
	lods	byte [esi]
-
 
4119
	cmp	edi,[display_buffer]
-
 
4120
	jae	out_of_memory
-
 
4121
	stos	byte [edi]
-
 
4122
	test	al,al
-
 
4123
	jnz	copy_elf_section_name
-
 
4124
	jmp	prepare_strings_table
-
 
4125
      prepare_default_section_string:
-
 
4126
	mov	eax,'.fla'
-
 
4127
	stos	dword [edi]
-
 
4128
	mov	ax,'t'
-
 
4129
	stos	word [edi]
-
 
4130
	cmp	edi,[display_buffer]
-
 
4131
	jae	out_of_memory
-
 
4132
	jmp	prepare_strings_table
-
 
4133
      strings_table_ready:
-
 
4134
	mov	edx,[display_buffer]
-
 
4135
	mov	ebp,[memory_end]
-
 
4136
	sub	ebp,[labels_list]
-
 
4137
	add	ebp,edx
-
 
4138
      prepare_labels_dump:
-
 
4139
	cmp	edx,ebp
-
 
4140
	je	labels_dump_ok
-
 
4141
	mov	eax,[edx+24]
-
 
4142
	test	eax,eax
-
 
4143
	jz	label_dump_name_ok
-
 
4144
	cmp	eax,[memory_start]
-
 
4145
	jb	label_name_outside_source
-
 
4146
	cmp	eax,[source_start]
-
 
4147
	ja	label_name_outside_source
-
 
4148
	sub	eax,[memory_start]
-
 
4149
	dec	eax
-
 
4150
	mov	[edx+24],eax
-
 
4151
	jmp	label_dump_name_ok
-
 
4152
      label_name_outside_source:
-
 
4153
	mov	esi,eax
-
 
4154
	mov	eax,edi
-
 
4155
	sub	eax,ebx
-
 
4156
	or	eax,1 shl 31
-
 
4157
	mov	[edx+24],eax
-
 
4158
	movzx	ecx,byte [esi-1]
-
 
4159
	lea	eax,[edi+ecx+1]
-
 
4160
	cmp	edi,[display_buffer]
-
 
4161
	jae	out_of_memory
-
 
4162
	rep	movsb
-
 
4163
	xor	al,al
-
 
4164
	stosb
-
 
4165
      label_dump_name_ok:
-
 
4166
	mov	eax,[edx+28]
-
 
4167
	test	eax,eax
-
 
4168
	jz	label_dump_line_ok
-
 
4169
	sub	eax,[memory_start]
-
 
4170
	mov	[edx+28],eax
-
 
4171
      label_dump_line_ok:
-
 
4172
	mov	eax,[edx+20]
-
 
4173
	test	eax,eax
-
 
4174
	jz	base_symbol_for_label_ok
-
 
4175
	cmp	eax,[symbols_stream]
-
 
4176
	mov	eax,[eax+4]
-
 
4177
	jae	base_symbol_for_label_ok
-
 
4178
	xor	eax,eax
-
 
4179
      base_symbol_for_label_ok:
-
 
4180
	mov	[edx+20],eax
-
 
4181
	add	edx,LABEL_STRUCTURE_SIZE
-
 
4182
	jmp	prepare_labels_dump
-
 
4183
      labels_dump_ok:
-
 
4184
	mov	eax,edi
-
 
4185
	sub	eax,ebx
-
 
4186
	mov	[ebx-38h+14h],eax
-
 
4187
	add	eax,38h
-
 
4188
	mov	[ebx-38h+18h],eax
-
 
4189
	mov	ecx,[memory_end]
-
 
4190
	sub	ecx,[labels_list]
-
 
4191
	mov	[ebx-38h+1Ch],ecx
-
 
4192
	add	eax,ecx
-
 
4193
	mov	[ebx-38h+20h],eax
-
 
4194
	mov	ecx,[source_start]
-
 
4195
	sub	ecx,[memory_start]
-
 
4196
	mov	[ebx-38h+24h],ecx
-
 
4197
	add	eax,ecx
-
 
4198
	mov	[ebx-38h+28h],eax
-
 
4199
	mov	eax,[number_of_sections]
-
 
4200
	shl	eax,2
-
 
4201
	mov	[ebx-38h+34h],eax
-
 
4202
	mov	esi,[memory_start]
-
 
4203
      prepare_preprocessed_source:
-
 
4204
	cmp	esi,[source_start]
-
 
4205
	jae	preprocessed_source_ok
-
 
4206
	mov	eax,[memory_start]
-
 
4207
	mov	edx,[input_file]
-
 
4208
	cmp	[esi],edx
-
 
4209
	jne	line_not_from_main_input
-
 
4210
	mov	[esi],eax
-
 
4211
      line_not_from_main_input:
-
 
4212
	sub	[esi],eax
-
 
4213
	test	byte [esi+7],1 shl 7
-
 
4214
	jz	prepare_next_preprocessed_line
-
 
4215
	sub	[esi+8],eax
-
 
4216
	sub	[esi+12],eax
-
 
4217
      prepare_next_preprocessed_line:
-
 
4218
	add	esi,16
-
 
4219
      skip_preprocessed_line:
-
 
4220
	lods	byte [esi]
-
 
4221
	cmp	al,1Ah
-
 
4222
	je	skip_preprocessed_symbol
-
 
4223
	cmp	al,3Bh
-
 
4224
	je	skip_preprocessed_symbol
-
 
4225
	cmp	al,22h
-
 
4226
	je	skip_preprocessed_string
-
 
4227
	or	al,al
-
 
4228
	jnz	skip_preprocessed_line
-
 
4229
	jmp	prepare_preprocessed_source
-
 
4230
      skip_preprocessed_string:
-
 
4231
	lods	dword [esi]
-
 
4232
	add	esi,eax
-
 
4233
	jmp	skip_preprocessed_line
-
 
4234
      skip_preprocessed_symbol:
-
 
4235
	lods	byte [esi]
-
 
4236
	movzx	eax,al
-
 
4237
	add	esi,eax
-
 
4238
	jmp	skip_preprocessed_line
-
 
4239
      preprocessed_source_ok:
-
 
4240
	mov	esi,[labels_list]
-
 
4241
	mov	ebp,edi
-
 
4242
      make_lines_dump:
-
 
4243
	cmp	esi,[display_buffer]
-
 
4244
	je	lines_dump_ok
-
 
4245
	mov	eax,[esi-4]
-
 
4246
	mov	ecx,[esi-8]
-
 
4247
	sub	esi,8
-
 
4248
	sub	esi,ecx
-
 
4249
	cmp	eax,1
-
 
4250
	jne	make_lines_dump
-
 
4251
	mov	eax,[esi+4]
-
 
4252
	sub	eax,[code_start]
-
 
4253
	add	eax,[headers_size]
-
 
4254
	cmp	byte [esi+1Ah],0
-
 
4255
	je	store_offset
-
 
4256
	xor	eax,eax
-
 
4257
      store_offset:
-
 
4258
	stos	dword [edi]
-
 
4259
	mov	eax,[esi]
-
 
4260
	sub	eax,[memory_start]
-
 
4261
	stos	dword [edi]
-
 
4262
	mov	eax,[esi+4]
-
 
4263
	xor	edx,edx
-
 
4264
	sub	eax,[esi+8]
-
 
4265
	sbb	edx,[esi+8+4]
-
 
4266
	stos	dword [edi]
-
 
4267
	mov	eax,edx
-
 
4268
	stos	dword [edi]
-
 
4269
	mov	eax,[esi+10h]
-
 
4270
	stos	dword [edi]
-
 
4271
	mov	eax,[esi+14h]
-
 
4272
	test	eax,eax
-
 
4273
	jz	base_symbol_for_line_ok
-
 
4274
	cmp	eax,[symbols_stream]
-
 
4275
	mov	eax,[eax+4]
-
 
4276
	jae	base_symbol_for_line_ok
-
 
4277
	xor	eax,eax
-
 
4278
      base_symbol_for_line_ok:
-
 
4279
	stos	dword [edi]
-
 
4280
	mov	eax,[esi+18h]
-
 
4281
	and	eax,001FFFFh
-
 
4282
	stos	dword [edi]
-
 
4283
	jmp	make_lines_dump
-
 
4284
      lines_dump_ok:
-
 
4285
	mov	edx,edi
-
 
4286
	mov	eax,[current_offset]
-
 
4287
	sub	eax,[code_start]
-
 
4288
	add	eax,[headers_size]
-
 
4289
	stos	dword [edi]
-
 
4290
	mov	ecx,edi
-
 
4291
	sub	ecx,ebx
-
 
4292
	sub	ecx,[ebx-38h+14h]
-
 
4293
	mov	[ebx-38h+2Ch],ecx
-
 
4294
	add	ecx,[ebx-38h+28h]
-
 
4295
	mov	[ebx-38h+30h],ecx
-
 
4296
      find_inexisting_offsets:
-
 
4297
	sub	edx,1Ch
-
 
4298
	cmp	edx,ebp
-
 
4299
	jb	write_symbols
-
 
4300
	test	byte [edx+1Ah],1
-
 
4301
	jnz	find_inexisting_offsets
-
 
4302
	cmp	eax,[edx]
-
 
4303
	jb	correct_inexisting_offset
-
 
4304
	mov	eax,[edx]
-
 
4305
	jmp	find_inexisting_offsets
-
 
4306
      correct_inexisting_offset:
-
 
4307
	mov	dword [edx],0
-
 
4308
	or	byte [edx+1Ah],2
-
 
4309
	jmp	find_inexisting_offsets
-
 
4310
      write_symbols:
-
 
4311
	mov	edx,[symbols_file]
-
 
4312
	call	create
-
 
4313
	jc	write_failed
-
 
4314
	mov	edx,[code_start]
-
 
4315
	mov	ecx,[edx+14h]
-
 
4316
	add	ecx,38h
-
 
4317
	call	write
-
 
4318
	mov	edx,[display_buffer]
-
 
4319
	mov	ecx,[memory_end]
-
 
4320
	sub	ecx,[labels_list]
-
 
4321
	call	write
-
 
4322
	mov	edx,[memory_start]
-
 
4323
	mov	ecx,[source_start]
-
 
4324
	sub	ecx,edx
-
 
4325
	call	write
-
 
4326
	mov	edx,ebp
-
 
4327
	mov	ecx,edi
-
 
4328
	sub	ecx,edx
-
 
4329
	call	write
-
 
4330
	mov	edx,[free_additional_memory]
-
 
4331
	mov	ecx,[number_of_sections]
-
 
4332
	shl	ecx,2
-
 
4333
	call	write
-
 
4334
	call	close
-
 
4335
	ret
-
 
4336
-