Subversion Repositories Kolibri OS

Rev

Rev 872 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 872 Rev 992
Line 2... Line 2...
2
; Copyright (c) 1999-2007, Tomasz Grysztar.
2
; Copyright (c) 1999-2007, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
4
 
4
 
Line 5... Line 5...
5
formatter:
5
formatter:
-
 
6
	mov	[current_offset],edi
6
	cmp	[output_file],0
7
	cmp	[output_file],0
7
	jne	output_path_ok
8
	jne	output_path_ok
8
	push	edi
-
 
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]
Line 116... Line 116...
116
	cld
116
	cld
117
	inc	edi
117
	inc	edi
118
	mov	[structures_buffer],edi
118
	mov	[structures_buffer],edi
119
	mov	[output_file],edi
119
	mov	[output_file],edi
120
	pop	edi
120
      output_path_ok:
121
      output_path_ok:
-
 
122
	cmp	[output_format],4
121
	cmp	[symbols_file],0
-
 
122
	je	labels_table_ok
-
 
123
	mov	ecx,[memory_end]
-
 
124
	sub	ecx,[labels_list]
-
 
125
	mov	edi,[display_buffer]
-
 
126
	sub	edi,8
-
 
127
	mov	[edi],ecx
-
 
128
	or	dword [edi+4],-1
-
 
129
	sub	edi,ecx
-
 
130
	cmp	edi,[esp]
-
 
131
	jbe	out_of_memory
-
 
132
	mov	[display_buffer],edi
-
 
133
	mov	esi,[memory_end]
-
 
134
      copy_labels:
-
 
135
	sub	esi,32
-
 
136
	cmp	esi,[labels_list]
-
 
137
	jb	labels_table_ok
-
 
138
	mov	ecx,32 shr 2
-
 
139
	rep	movs dword [edi],[esi]
-
 
140
	sub	esi,32
-
 
141
	jmp	copy_labels
-
 
142
      labels_table_ok:
-
 
143
	mov	edi,[current_offset]
-
 
144
	cmp	[output_format],4
123
	je	coff_formatter
145
	je	coff_formatter
124
	cmp	[output_format],5
146
	cmp	[output_format],5
125
	jne	common_formatter
147
	jne	common_formatter
126
	bt	[format_flags],0
148
	bt	[format_flags],0
127
	jnc	elf_formatter
149
	jnc	elf_formatter
Line 132... Line 154...
132
	cmp	edi,[undefined_data_end]
154
	cmp	edi,[undefined_data_end]
133
	jne	calculate_code_size
155
	jne	calculate_code_size
134
	mov	edi,[undefined_data_start]
156
	mov	edi,[undefined_data_start]
135
      calculate_code_size:
157
      calculate_code_size:
136
	sub	edi,[code_start]
158
	mov	[current_offset],edi
-
 
159
	sub	edi,[code_start]
137
	mov	[code_size],edi
160
	mov	[code_size],edi
138
	mov	[written_size],0
161
	mov	[written_size],0
139
	mov	edx,[output_file]
162
	mov	edx,[output_file]
140
	call	create
163
	call	create
141
	jc	write_failed
164
	jc	write_failed
Line 153... Line 176...
153
      write_output:
176
      write_output:
154
	call	write_code
177
	call	write_code
155
      output_written:
178
      output_written:
156
	call	close
179
	call	close
157
	ret
180
	cmp	[symbols_file],0
-
 
181
	jne	dump_symbols
-
 
182
	ret
158
      write_code:
183
      write_code:
159
	mov	eax,[written_size]
184
	mov	eax,[written_size]
160
	mov	[headers_size],eax
185
	mov	[headers_size],eax
161
	mov	edx,[code_start]
186
	mov	edx,[code_start]
162
	mov	ecx,[code_size]
187
	mov	ecx,[code_size]
163
	add	[written_size],ecx
188
	add	[written_size],ecx
164
	call	write
189
	lea	eax,[edx+ecx]
-
 
190
	call	write
165
	jc	write_failed
191
	jc	write_failed
166
	ret
192
	ret
167
format_directive:
193
format_directive:
168
	cmp	edi,[code_start]
194
	cmp	edi,[code_start]
169
	jne	unexpected_instruction
195
	jne	unexpected_instruction
Line 835... Line 861...
835
	bts	[format_flags],7
861
	bts	[format_flags],7
836
	jc	setting_already_specified
862
	jc	setting_already_specified
837
	and	ax,3Fh
863
	and	ax,3Fh
838
	mov	[subsystem],ax
864
	mov	[subsystem],ax
839
	cmp	byte [esi],'('
865
	cmp	ax,10
-
 
866
	jb	subsystem_type_ok
-
 
867
	or	[format_flags],8
-
 
868
      subsystem_type_ok:
-
 
869
	cmp	byte [esi],'('
840
	jne	pe_settings
870
	jne	pe_settings
841
	inc	esi
871
	inc	esi
842
	cmp	byte [esi],'.'
872
	cmp	byte [esi],'.'
843
	jne	invalid_value
873
	jne	invalid_value
844
	inc	esi
874
	inc	esi
Line 888... Line 918...
888
	je	invalid_value
918
	je	invalid_value
889
	push	edx edi
919
	push	edx edi
890
	add	edi,[stub_size]
920
	add	edi,[stub_size]
891
	test	[format_flags],8
921
	test	[format_flags],8
892
	jnz	get_pe64_base
922
	jnz	get_peplus_base
893
	call	get_dword_value
923
	call	get_dword_value
894
	mov	[image_base],eax
924
	mov	[image_base],eax
895
	jmp	pe_base_ok
925
	jmp	pe_base_ok
896
      get_pe64_base:
926
      get_peplus_base:
897
	call	get_qword_value
927
	call	get_qword_value
898
	mov	[image_base],eax
928
	mov	[image_base],eax
899
	mov	[image_base_high],edx
929
	mov	[image_base_high],edx
900
      pe_base_ok:
930
      pe_base_ok:
901
	pop	edi edx
931
	pop	edi edx
902
	cmp	[value_type],0
932
	cmp	[value_type],0
Line 955... Line 985...
955
	mov	dword [edx+3Ch],eax
985
	mov	dword [edx+3Ch],eax
956
      pe_alignment_ok:
986
      pe_alignment_ok:
957
	mov	word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
987
	mov	word [edx+1Ah],VERSION_MAJOR + VERSION_MINOR shl 8
958
	test	[format_flags],8
988
	test	[format_flags],8
959
	jnz	init_pe64_specific
989
	jnz	init_peplus_specific
960
	mov	dword [edx+14h],0E0h	; size of optional header
990
	mov	dword [edx+14h],0E0h	; size of optional header
961
	mov	dword [edx+16h],10B010Eh; flags and magic value
991
	mov	dword [edx+16h],10B010Eh; flags and magic value
962
	mov	eax,[image_base]
992
	mov	eax,[image_base]
963
	mov	dword [edx+34h],eax
993
	mov	dword [edx+34h],eax
964
	mov	dword [edx+60h],1000h	; stack reserve
994
	mov	dword [edx+60h],1000h	; stack reserve
965
	mov	dword [edx+64h],1000h	; stack commit
995
	mov	dword [edx+64h],1000h	; stack commit
966
	mov	dword [edx+68h],10000h	; heap reserve
996
	mov	dword [edx+68h],10000h	; heap reserve
967
	mov	dword [edx+6Ch],0	; heap commit
997
	mov	dword [edx+6Ch],0	; heap commit
968
	mov	dword [edx+74h],16	; number of directories
998
	mov	dword [edx+74h],16	; number of directories
969
	jmp	pe_header_ok
999
	jmp	pe_header_ok
970
      init_pe64_specific:
1000
      init_peplus_specific:
971
	mov	dword [edx+14h],0F0h	; size of optional header
1001
	mov	dword [edx+14h],0F0h	; size of optional header
972
	mov	dword [edx+16h],20B002Eh; flags and magic value
1002
	mov	dword [edx+16h],20B002Eh; flags and magic value
973
	mov	eax,[image_base]
1003
	mov	eax,[image_base]
974
	mov	dword [edx+30h],eax
1004
	mov	dword [edx+30h],eax
975
	mov	eax,[image_base_high]
1005
	mov	eax,[image_base_high]
976
	mov	dword [edx+34h],eax
1006
	mov	dword [edx+34h],eax
Line 1029... Line 1059...
1029
	adc	ecx,0
1059
	adc	ecx,0
1030
	add	eax,edi
1060
	add	eax,edi
1031
	adc	ecx,0
1061
	adc	ecx,0
1032
	test	[format_flags],8
1062
	test	[format_flags],8
1033
	jnz	pe64_org
1063
	jnz	peplus_org
1034
	sub	eax,[edx+34h]
1064
	sub	eax,[edx+34h]
1035
	sbb	ecx,0
1065
	sbb	ecx,0
1036
	mov	bl,2
1066
	mov	bl,2
1037
	mov	[code_type],32
1067
	mov	[code_type],32
1038
	jmp	pe_org_ok
1068
	jmp	pe_org_ok
1039
      pe64_org:
1069
      peplus_org:
1040
	sub	eax,[edx+30h]
1070
	sub	eax,[edx+30h]
1041
	sbb	ecx,[edx+34h]
1071
	sbb	ecx,[edx+34h]
1042
	mov	bl,4
1072
	mov	bl,4
1043
	mov	[code_type],64
1073
	mov	[code_type],64
1044
      pe_org_ok:
1074
      pe_org_ok:
1045
	bt	[resolver_flags],0
1075
	bt	[resolver_flags],0
Line 1101... Line 1131...
1101
	xor	ecx,ecx
1131
	xor	ecx,ecx
1102
	sub	eax,[ebx+0Ch]
1132
	sub	eax,[ebx+0Ch]
1103
	sbb	ecx,0
1133
	sbb	ecx,0
1104
	test	[format_flags],8
1134
	test	[format_flags],8
1105
	jnz	pe64_section_org
1135
	jnz	peplus_section_org
1106
	sub	eax,[edx+34h]
1136
	sub	eax,[edx+34h]
1107
	sbb	ecx,0
1137
	sbb	ecx,0
1108
	mov	[labels_type],2
1138
	mov	[labels_type],2
1109
	mov	[code_type],32
1139
	mov	[code_type],32
1110
	bt	[resolver_flags],0
1140
	bt	[resolver_flags],0
1111
	jc	pe_section_org_ok
1141
	jc	pe_section_org_ok
1112
	mov	[labels_type],0
1142
	mov	[labels_type],0
1113
	jmp	pe_section_org_ok
1143
	jmp	pe_section_org_ok
1114
      pe64_section_org:
1144
      peplus_section_org:
1115
	sub	eax,[edx+30h]
1145
	sub	eax,[edx+30h]
1116
	sbb	ecx,[edx+34h]
1146
	sbb	ecx,[edx+34h]
1117
	mov	[labels_type],4
1147
	mov	[labels_type],4
1118
	mov	[code_type],64
1148
	mov	[code_type],64
1119
	bt	[resolver_flags],0
1149
	bt	[resolver_flags],0
1120
	jc	pe_section_org_ok
1150
	jc	pe_section_org_ok
Line 1136... Line 1166...
1136
	movzx	eax,byte [esi]
1166
	movzx	eax,byte [esi]
1137
	inc	esi
1167
	inc	esi
1138
	mov	ecx,ebx
1168
	mov	ecx,ebx
1139
	test	[format_flags],8
1169
	test	[format_flags],8
1140
	jnz	pe64_directory
1170
	jnz	peplus_directory
1141
	xchg	ecx,[edx+78h+eax*8]
1171
	xchg	ecx,[edx+78h+eax*8]
1142
	mov	dword [edx+78h+eax*8+4],-1
1172
	mov	dword [edx+78h+eax*8+4],-1
1143
	jmp	pe_directory_set
1173
	jmp	pe_directory_set
1144
      pe64_directory:
1174
      peplus_directory:
1145
	xchg	ecx,[edx+88h+eax*8]
1175
	xchg	ecx,[edx+88h+eax*8]
1146
	mov	dword [edx+88h+eax*8+4],-1
1176
	mov	dword [edx+88h+eax*8+4],-1
1147
      pe_directory_set:
1177
      pe_directory_set:
1148
	or	ecx,ecx
1178
	or	ecx,ecx
1149
	jnz	data_already_defined
1179
	jnz	data_already_defined
1150
	push	ebx edx
1180
	push	ebx edx
Line 1197... Line 1227...
1197
	rep	stos byte [edi]
1227
	rep	stos byte [edi]
1198
	mov	eax,[code_start]
1228
	mov	eax,[code_start]
1199
	sub	eax,[stub_size]
1229
	sub	eax,[stub_size]
1200
	sub	[ebx+14h],eax
1230
	sub	[ebx+14h],eax
1201
	mov	eax,[ebx+8]
1231
 
-
 
1232
	mov	ecx,[ebx+10h]
-
 
1233
	test	byte [ebx+24h],20h
-
 
1234
	jz	pe_code_sum_ok
-
 
1235
	add	[edx+1Ch],ecx
-
 
1236
	cmp	dword [edx+2Ch],0
-
 
1237
	jne	pe_code_sum_ok
-
 
1238
	mov	eax,[ebx+0Ch]
-
 
1239
	mov	[edx+2Ch],eax
-
 
1240
      pe_code_sum_ok:
-
 
1241
	test	byte [ebx+24h],40h
-
 
1242
	jz	pe_data_sum_ok
-
 
1243
	add	[edx+20h],ecx
-
 
1244
	test	[format_flags],8
-
 
1245
	jnz	pe_data_sum_ok
-
 
1246
	cmp	dword [edx+30h],0
-
 
1247
	jne	pe_data_sum_ok
-
 
1248
	mov	eax,[ebx+0Ch]
-
 
1249
	mov	[edx+30h],eax
-
 
1250
      pe_data_sum_ok:
-
 
1251
 
-
 
1252
	mov	eax,[ebx+8]
1202
	or	eax,eax
1253
	or	eax,eax
1203
	jz	udata_ok
1254
	jz	udata_ok
1204
	cmp	dword [ebx+10h],0
1255
	cmp	dword [ebx+10h],0
1205
	jne	udata_ok
1256
	jne	udata_ok
1206
	or	byte [ebx+24h],80h
1257
	or	byte [ebx+24h],80h
1207
      udata_ok:
1258
	add	[edx+24h],ecx
-
 
1259
      udata_ok:
1208
	mov	ecx,[edx+38h]
1260
 
-
 
1261
	mov	ecx,[edx+38h]
1209
	dec	ecx
1262
	dec	ecx
1210
	add	eax,ecx
1263
	add	eax,ecx
1211
	not	ecx
1264
	not	ecx
1212
	and	eax,ecx
1265
	and	eax,ecx
1213
	add	eax,[ebx+0Ch]
1266
	add	eax,[ebx+0Ch]
Line 1237... Line 1290...
1237
	sub	ecx,[ebx+14h]
1290
	sub	ecx,[ebx+14h]
1238
	add	ecx,[ebx+0Ch]
1291
	add	ecx,[ebx+0Ch]
1239
	mov	edx,[code_start]
1292
	mov	edx,[code_start]
1240
	test	[format_flags],8
1293
	test	[format_flags],8
1241
	jnz	pe64_data
1294
	jnz	peplus_data
1242
	xchg	ecx,[edx+78h+eax*8]
1295
	xchg	ecx,[edx+78h+eax*8]
1243
	jmp	init_pe_data
1296
	jmp	init_pe_data
1244
      pe64_data:
1297
      peplus_data:
1245
	xchg	ecx,[edx+88h+eax*8]
1298
	xchg	ecx,[edx+88h+eax*8]
1246
      init_pe_data:
1299
      init_pe_data:
1247
	or	ecx,ecx
1300
	or	ecx,ecx
1248
	jnz	data_already_defined
1301
	jnz	data_already_defined
1249
	call	allocate_structure_data
1302
	call	allocate_structure_data
1250
	mov	word [ebx],data_directive-assembler
1303
	mov	word [ebx],data_directive-assembler
Line 1264... Line 1317...
1264
	sub	ecx,[edx+14h]
1317
	sub	ecx,[edx+14h]
1265
	add	ecx,[edx+0Ch]
1318
	add	ecx,[edx+0Ch]
1266
	mov	edx,[code_start]
1319
	mov	edx,[code_start]
1267
	test	[format_flags],8
1320
	test	[format_flags],8
1268
	jnz	end_pe64_data
1321
	jnz	end_peplus_data
1269
	sub	ecx,[edx+78h+eax*8]
1322
	sub	ecx,[edx+78h+eax*8]
1270
	mov	[edx+78h+eax*8+4],ecx
1323
	mov	[edx+78h+eax*8+4],ecx
1271
	jmp	remove_structure_data
1324
	jmp	remove_structure_data
1272
      end_pe64_data:
1325
      end_peplus_data:
1273
	sub	ecx,[edx+88h+eax*8]
1326
	sub	ecx,[edx+88h+eax*8]
1274
	mov	[edx+88h+eax*8+4],ecx
1327
	mov	[edx+88h+eax*8+4],ecx
1275
	jmp	remove_structure_data
1328
	jmp	remove_structure_data
1276
pe_entry:
1329
pe_entry:
1277
	lods	byte [esi]
1330
	lods	byte [esi]
1278
	cmp	al,'('
1331
	cmp	al,'('
1279
	jne	invalid_argument
1332
	jne	invalid_argument
1280
	cmp	byte [esi],'.'
1333
	cmp	byte [esi],'.'
1281
	je	invalid_value
1334
	je	invalid_value
1282
	test	[format_flags],8
1335
	test	[format_flags],8
1283
	jnz	pe64_entry
1336
	jnz	peplus_entry
1284
	call	get_dword_value
1337
	call	get_dword_value
1285
	mov	bl,2
1338
	mov	bl,2
1286
	bt	[resolver_flags],0
1339
	bt	[resolver_flags],0
1287
	jc	check_pe_entry_label_type
1340
	jc	check_pe_entry_label_type
1288
	xor	bl,bl
1341
	xor	bl,bl
1289
      check_pe_entry_label_type:
1342
      check_pe_entry_label_type:
Line 1298... Line 1351...
1298
	mov	edx,[code_start]
1351
	mov	edx,[code_start]
1299
	sub	eax,[edx+34h]
1352
	sub	eax,[edx+34h]
1300
	mov	[edx+28h],eax
1353
	mov	[edx+28h],eax
1301
	jmp	instruction_assembled
1354
	jmp	instruction_assembled
1302
      pe64_entry:
1355
      peplus_entry:
1303
	call	get_qword_value
1356
	call	get_qword_value
1304
	mov	bl,4
1357
	mov	bl,4
1305
	bt	[resolver_flags],0
1358
	bt	[resolver_flags],0
1306
	jc	check_pe64_entry_label_type
1359
	jc	check_peplus_entry_label_type
1307
	xor	bl,bl
1360
	xor	bl,bl
1308
      check_pe64_entry_label_type:
1361
      check_peplus_entry_label_type:
1309
	cmp	[value_type],bl
1362
	cmp	[value_type],bl
1310
	je	pe64_entry_type_ok
1363
	je	peplus_entry_type_ok
1311
	cmp	[error_line],0
1364
	cmp	[error_line],0
1312
	jne	pe64_entry_type_ok
1365
	jne	peplus_entry_type_ok
1313
	mov	edx,[current_line]
1366
	mov	edx,[current_line]
1314
	mov	[error_line],edx
1367
	mov	[error_line],edx
1315
	mov	[error],invalid_address
1368
	mov	[error],invalid_address
1316
      pe64_entry_type_ok:
1369
      peplus_entry_type_ok:
1317
	mov	ecx,[code_start]
1370
	mov	ecx,[code_start]
1318
	sub	eax,[ecx+30h]
1371
	sub	eax,[ecx+30h]
1319
	sbb	edx,[ecx+34h]
1372
	sbb	edx,[ecx+34h]
1320
	jz	pe64_entry_range_ok
1373
	jz	peplus_entry_range_ok
1321
	mov	edx,[current_line]
1374
	mov	edx,[current_line]
1322
	mov	[error_line],edx
1375
	mov	[error_line],edx
1323
	mov	[error],value_out_of_range
1376
	mov	[error],value_out_of_range
1324
      pe64_entry_range_ok:
1377
      peplus_entry_range_ok:
1325
	mov	[ecx+28h],eax
1378
	mov	[ecx+28h],eax
1326
	jmp	instruction_assembled
1379
	jmp	instruction_assembled
1327
pe_stack:
1380
pe_stack:
1328
	lods	byte [esi]
1381
	lods	byte [esi]
1329
	cmp	al,'('
1382
	cmp	al,'('
1330
	jne	invalid_argument
1383
	jne	invalid_argument
1331
	cmp	byte [esi],'.'
1384
	cmp	byte [esi],'.'
1332
	je	invalid_value
1385
	je	invalid_value
1333
	test	[format_flags],8
1386
	test	[format_flags],8
1334
	jnz	pe64_stack
1387
	jnz	peplus_stack
1335
	call	get_dword_value
1388
	call	get_dword_value
1336
	cmp	[value_type],0
1389
	cmp	[value_type],0
1337
	jne	invalid_use_of_symbol
1390
	jne	invalid_use_of_symbol
1338
	mov	edx,[code_start]
1391
	mov	edx,[code_start]
1339
	mov	[edx+60h],eax
1392
	mov	[edx+60h],eax
1340
	cmp	byte [esi],','
1393
	cmp	byte [esi],','
Line 1359... Line 1412...
1359
	cmp	eax,1000h
1412
	cmp	eax,1000h
1360
	ja	instruction_assembled
1413
	ja	instruction_assembled
1361
	mov	dword [edx+64h],eax
1414
	mov	dword [edx+64h],eax
1362
	jmp	instruction_assembled
1415
	jmp	instruction_assembled
1363
      pe64_stack:
1416
      peplus_stack:
1364
	call	get_qword_value
1417
	call	get_qword_value
1365
	cmp	[value_type],0
1418
	cmp	[value_type],0
1366
	jne	invalid_use_of_symbol
1419
	jne	invalid_use_of_symbol
1367
	mov	ecx,[code_start]
1420
	mov	ecx,[code_start]
1368
	mov	[ecx+60h],eax
1421
	mov	[ecx+60h],eax
1369
	mov	[ecx+64h],edx
1422
	mov	[ecx+64h],edx
1370
	cmp	byte [esi],','
1423
	cmp	byte [esi],','
1371
	jne	default_pe64_stack_commit
1424
	jne	default_peplus_stack_commit
1372
	lods	byte [esi]
1425
	lods	byte [esi]
1373
	lods	byte [esi]
1426
	lods	byte [esi]
1374
	cmp	al,'('
1427
	cmp	al,'('
1375
	jne	invalid_argument
1428
	jne	invalid_argument
1376
	cmp	byte [esi],'.'
1429
	cmp	byte [esi],'.'
1377
	je	invalid_value
1430
	je	invalid_value
Line 1386... Line 1439...
1386
	jb	instruction_assembled
1439
	jb	instruction_assembled
1387
	cmp	eax,[ecx+60h]
1440
	cmp	eax,[ecx+60h]
1388
	ja	value_out_of_range
1441
	ja	value_out_of_range
1389
	jmp	instruction_assembled
1442
	jmp	instruction_assembled
1390
      default_pe64_stack_commit:
1443
      default_peplus_stack_commit:
1391
	mov	dword [ecx+68h],1000h
1444
	mov	dword [ecx+68h],1000h
1392
	cmp	dword [ecx+64h],0
1445
	cmp	dword [ecx+64h],0
1393
	jne	instruction_assembled
1446
	jne	instruction_assembled
1394
	mov	eax,[ecx+60h]
1447
	mov	eax,[ecx+60h]
1395
	cmp	eax,1000h
1448
	cmp	eax,1000h
1396
	ja	instruction_assembled
1449
	ja	instruction_assembled
Line 1402... Line 1455...
1402
	jne	invalid_argument
1455
	jne	invalid_argument
1403
	cmp	byte [esi],'.'
1456
	cmp	byte [esi],'.'
1404
	je	invalid_value
1457
	je	invalid_value
1405
	test	[format_flags],8
1458
	test	[format_flags],8
1406
	jnz	pe64_heap
1459
	jnz	peplus_heap
1407
	call	get_dword_value
1460
	call	get_dword_value
1408
	cmp	[value_type],0
1461
	cmp	[value_type],0
1409
	jne	invalid_use_of_symbol
1462
	jne	invalid_use_of_symbol
1410
	mov	edx,[code_start]
1463
	mov	edx,[code_start]
1411
	mov	[edx+68h],eax
1464
	mov	[edx+68h],eax
1412
	cmp	byte [esi],','
1465
	cmp	byte [esi],','
Line 1424... Line 1477...
1424
	mov	[edx+6Ch],eax
1477
	mov	[edx+6Ch],eax
1425
	cmp	eax,[edx+68h]
1478
	cmp	eax,[edx+68h]
1426
	ja	value_out_of_range
1479
	ja	value_out_of_range
1427
	jmp	instruction_assembled
1480
	jmp	instruction_assembled
1428
      pe64_heap:
1481
      peplus_heap:
1429
	call	get_qword_value
1482
	call	get_qword_value
1430
	cmp	[value_type],0
1483
	cmp	[value_type],0
1431
	jne	invalid_use_of_symbol
1484
	jne	invalid_use_of_symbol
1432
	mov	ecx,[code_start]
1485
	mov	ecx,[code_start]
1433
	mov	[ecx+70h],eax
1486
	mov	[ecx+70h],eax
1434
	mov	[ecx+74h],edx
1487
	mov	[ecx+74h],edx
Line 1961... Line 2014...
1961
	cmp	eax,edx
2014
	cmp	eax,edx
1962
	jge	check_next_language_id
2015
	jge	check_next_language_id
1963
	mov	edx,eax
2016
	mov	edx,eax
1964
	mov	eax,[esp]
2017
	mov	eax,[esp]
1965
	mov	[current_offset],eax
2018
	mov	dword [value],eax
1966
      check_next_language_id:
2019
      check_next_language_id:
1967
	pop	esi
2020
	pop	esi
1968
	mov	eax,[esi+16]
2021
	mov	eax,[esi+16]
1969
	lea	esi,[esi+20+eax]
2022
	lea	esi,[esi+20+eax]
1970
	jmp	find_language_id
2023
	jmp	find_language_id
1971
      language_id_ok:
2024
      language_id_ok:
Line 1979... Line 2032...
1979
	cmp	eax,[display_buffer]
2032
	cmp	eax,[display_buffer]
1980
	jae	out_of_memory
2033
	jae	out_of_memory
1981
	mov	eax,ebx
2034
	mov	eax,ebx
1982
	stos	dword [edi]
2035
	stos	dword [edi]
1983
	mov	eax,[current_offset]
2036
	mov	eax,dword [value]
1984
	stos	dword [edi]
2037
	stos	dword [edi]
1985
	jmp	make_language_id_directory
2038
	jmp	make_language_id_directory
1986
      language_id_directory_done:
2039
      language_id_directory_done:
1987
	pop	eax
2040
	pop	eax
1988
	mov	esi,ebp
2041
	mov	esi,ebp
1989
	pop	ecx
2042
	pop	ecx
Line 2329... Line 2382...
2329
	push	ebx eax
2382
	push	ebx eax
2330
	test	[format_flags],8
2383
	test	[format_flags],8
2331
	jnz	coff_64bit_relocation
2384
	jnz	coff_64bit_relocation
2332
	mov	al,6
2385
	mov	al,6
2333
	jmp	coff_relocation
2386
	cmp	[value_type],5
-
 
2387
	jne	coff_relocation
-
 
2388
	inc	al
-
 
2389
	jmp	coff_relocation
2334
      coff_64bit_relocation:
2390
      coff_64bit_relocation:
2335
	mov	al,1
2391
	mov	al,1
2336
	cmp	[value_type],4
2392
	cmp	[value_type],4
2337
	je	coff_relocation
2393
	je	coff_relocation
2338
	mov	al,2
2394
	mov	al,2
2339
	jmp	coff_relocation
2395
	cmp	[value_type],5
-
 
2396
	jne	coff_relocation
-
 
2397
	inc	al
-
 
2398
	jmp	coff_relocation
2340
      coff_relocation_relative:
2399
      coff_relocation_relative:
2341
	push	ebx
2400
	push	ebx
2342
	bt	[format_flags],0
2401
	bt	[format_flags],0
2343
	jnc	relative_ok
2402
	jnc	relative_ok
2344
	mov	ebx,[current_section]
2403
	mov	ebx,[current_section]
Line 3512... Line 3571...
3512
	mov	dword [edx+1],'.sym'
3571
	mov	dword [edx+1],'.sym'
3513
	mov	[edx+1+4],eax
3572
	mov	[edx+1+4],eax
3514
	mov	dword [edx+1+8],'.str'
3573
	mov	dword [edx+1+8],'.str'
3515
	mov	[edx+1+8+4],eax
3574
	mov	[edx+1+8+4],eax
3516
	mov	[written_size],0
3575
	mov	[resource_data],edx
-
 
3576
	mov	[written_size],0
3517
	mov	edx,[output_file]
3577
	mov	edx,[output_file]
3518
	call	create
3578
	call	create
3519
	jc	write_failed
3579
	jc	write_failed
3520
	call	write_code
3580
	call	write_code
3521
	mov	ecx,edi
3581
	mov	ecx,edi
Line 3907... Line 3967...
3907
	je	elf64_exe_ok
3967
	je	elf64_exe_ok
3908
	or	[next_pass_needed],-1
3968
	or	[next_pass_needed],-1
3909
      elf64_exe_ok:
3969
      elf64_exe_ok:
3910
	ret
3970
	ret
3911
3971
 
-
 
3972
dump_symbols:
-
 
3973
	mov	ebx,[code_start]
-
 
3974
	mov	dword [ebx],'fas'+27 shl 24
-
 
3975
	mov	dword [ebx+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16
-
 
3976
	add	ebx,38h
-
 
3977
	mov	edi,ebx
-
 
3978
	mov	dword [ebx-38h+10h],38h
-
 
3979
	mov	dword [ebx-38h+8],0
-
 
3980
	mov	esi,[input_file]
-
 
3981
	call	copy_asciiz
-
 
3982
	cmp	edi,[display_buffer]
-
 
3983
	jae	out_of_memory
-
 
3984
	mov	eax,edi
-
 
3985
	sub	eax,ebx
-
 
3986
	mov	[ebx-38h+0Ch],eax
-
 
3987
	mov	esi,[output_file]
-
 
3988
	call	copy_asciiz
-
 
3989
	cmp	edi,[display_buffer]
-
 
3990
	jae	out_of_memory
-
 
3991
	mov	edx,[symbols_stream]
-
 
3992
	mov	ebp,[free_additional_memory]
-
 
3993
	mov	[number_of_sections],0
-
 
3994
	cmp	[output_format],4
-
 
3995
	je	prepare_strings_table
-
 
3996
	cmp	[output_format],5
-
 
3997
	jne	strings_table_ready
-
 
3998
	bt	[format_flags],0
-
 
3999
	jc	strings_table_ready
-
 
4000
      prepare_strings_table:
-
 
4001
	cmp	edx,ebp
-
 
4002
	je	strings_table_ready
-
 
4003
	mov	al,[edx]
-
 
4004
	test	al,al
-
 
4005
	jz	prepare_string
-
 
4006
	cmp	al,80h
-
 
4007
	je	prepare_string
-
 
4008
	add	edx,0Ch
-
 
4009
	cmp	al,0C0h
-
 
4010
	jne	prepare_strings_table
-
 
4011
	add	edx,4
-
 
4012
	jmp	prepare_strings_table
-
 
4013
      prepare_string:
-
 
4014
	mov	esi,edi
-
 
4015
	sub	esi,ebx
-
 
4016
	xchg	esi,[edx+4]
-
 
4017
	test	al,al
-
 
4018
	jz	prepare_section_string
-
 
4019
	or	dword [edx+4],1 shl 31
-
 
4020
	add	edx,0Ch
-
 
4021
      prepare_external_string:
-
 
4022
	mov	ecx,[esi]
-
 
4023
	add	esi,4
-
 
4024
	rep	movs byte [edi],[esi]
-
 
4025
	mov	byte [edi],0
-
 
4026
	inc	edi
-
 
4027
	cmp	edi,[display_buffer]
-
 
4028
	jae	out_of_memory
-
 
4029
	jmp	prepare_strings_table
-
 
4030
      prepare_section_string:
-
 
4031
	mov	ecx,[number_of_sections]
-
 
4032
	mov	eax,ecx
-
 
4033
	inc	eax
-
 
4034
	mov	[number_of_sections],eax
-
 
4035
	xchg	eax,[edx+4]
-
 
4036
	shl	ecx,2
-
 
4037
	add	ecx,[free_additional_memory]
-
 
4038
	mov	[ecx],eax
-
 
4039
	add	edx,20h
-
 
4040
	test	esi,esi
-
 
4041
	jz	prepare_default_section_string
-
 
4042
	cmp	[output_format],5
-
 
4043
	jne	prepare_external_string
-
 
4044
	bt	[format_flags],0
-
 
4045
	jc	prepare_external_string
-
 
4046
	mov	esi,[esi]
-
 
4047
	add	esi,[resource_data]
-
 
4048
      copy_elf_section_name:
-
 
4049
	lods	byte [esi]
-
 
4050
	cmp	edi,[display_buffer]
-
 
4051
	jae	out_of_memory
-
 
4052
	stos	byte [edi]
-
 
4053
	test	al,al
-
 
4054
	jnz	copy_elf_section_name
-
 
4055
	jmp	prepare_strings_table
-
 
4056
      prepare_default_section_string:
-
 
4057
	mov	eax,'.fla'
-
 
4058
	stos	dword [edi]
-
 
4059
	mov	ax,'t'
-
 
4060
	stos	word [edi]
-
 
4061
	cmp	edi,[display_buffer]
-
 
4062
	jae	out_of_memory
-
 
4063
	jmp	prepare_strings_table
-
 
4064
      strings_table_ready:
-
 
4065
	mov	edx,[display_buffer]
-
 
4066
	mov	ebp,[memory_end]
-
 
4067
	sub	ebp,[labels_list]
-
 
4068
	add	ebp,edx
-
 
4069
      prepare_labels_dump:
-
 
4070
	cmp	edx,ebp
-
 
4071
	je	labels_dump_ok
-
 
4072
	mov	eax,[edx+24]
-
 
4073
	test	eax,eax
-
 
4074
	jz	label_dump_name_ok
-
 
4075
	cmp	eax,[memory_start]
-
 
4076
	jb	label_name_outside_source
-
 
4077
	cmp	eax,[source_start]
-
 
4078
	ja	label_name_outside_source
-
 
4079
	sub	eax,[memory_start]
-
 
4080
	dec	eax
-
 
4081
	mov	[edx+24],eax
-
 
4082
	jmp	label_dump_name_ok
-
 
4083
      label_name_outside_source:
-
 
4084
	mov	esi,eax
-
 
4085
	mov	eax,edi
-
 
4086
	sub	eax,ebx
-
 
4087
	or	eax,1 shl 31
-
 
4088
	mov	[edx+24],eax
-
 
4089
	movzx	ecx,byte [esi-1]
-
 
4090
	lea	eax,[edi+ecx+1]
-
 
4091
	cmp	edi,[display_buffer]
-
 
4092
	jae	out_of_memory
-
 
4093
	rep	movsb
-
 
4094
	xor	al,al
-
 
4095
	stosb
-
 
4096
      label_dump_name_ok:
-
 
4097
	mov	eax,[edx+28]
-
 
4098
	test	eax,eax
-
 
4099
	jz	label_dump_line_ok
-
 
4100
	sub	eax,[memory_start]
-
 
4101
	mov	[edx+28],eax
-
 
4102
      label_dump_line_ok:
-
 
4103
	mov	eax,[edx+20]
-
 
4104
	test	eax,eax
-
 
4105
	jz	base_symbol_for_label_ok
-
 
4106
	cmp	eax,[symbols_stream]
-
 
4107
	mov	eax,[eax+4]
-
 
4108
	jae	base_symbol_for_label_ok
-
 
4109
	xor	eax,eax
-
 
4110
      base_symbol_for_label_ok:
-
 
4111
	mov	[edx+20],eax
-
 
4112
	add	edx,32
-
 
4113
	jmp	prepare_labels_dump
-
 
4114
      labels_dump_ok:
-
 
4115
	mov	eax,edi
-
 
4116
	sub	eax,ebx
-
 
4117
	mov	[ebx-38h+14h],eax
-
 
4118
	add	eax,38h
-
 
4119
	mov	[ebx-38h+18h],eax
-
 
4120
	mov	ecx,[memory_end]
-
 
4121
	sub	ecx,[labels_list]
-
 
4122
	mov	[ebx-38h+1Ch],ecx
-
 
4123
	add	eax,ecx
-
 
4124
	mov	[ebx-38h+20h],eax
-
 
4125
	mov	ecx,[source_start]
-
 
4126
	sub	ecx,[memory_start]
-
 
4127
	mov	[ebx-38h+24h],ecx
-
 
4128
	add	eax,ecx
-
 
4129
	mov	[ebx-38h+28h],eax
-
 
4130
	mov	eax,[number_of_sections]
-
 
4131
	shl	eax,3
-
 
4132
	mov	[ebx-38h+34h],eax
-
 
4133
	mov	esi,[memory_start]
-
 
4134
      prepare_preprocessed_source:
-
 
4135
	cmp	esi,[source_start]
-
 
4136
	jae	preprocessed_source_ok
-
 
4137
	mov	eax,[memory_start]
-
 
4138
	mov	edx,[input_file]
-
 
4139
	cmp	[esi],edx
-
 
4140
	jne	line_not_from_main_input
-
 
4141
	mov	[esi],eax
-
 
4142
      line_not_from_main_input:
-
 
4143
	sub	[esi],eax
-
 
4144
	test	byte [esi+7],1 shl 7
-
 
4145
	jz	prepare_next_preprocessed_line
-
 
4146
	sub	[esi+8],eax
-
 
4147
	sub	[esi+12],eax
-
 
4148
      prepare_next_preprocessed_line:
-
 
4149
	add	esi,16
-
 
4150
	call	skip_foreign_line
-
 
4151
	jmp	prepare_preprocessed_source
-
 
4152
      preprocessed_source_ok:
-
 
4153
	mov	esi,[labels_list]
-
 
4154
	mov	ebp,edi
-
 
4155
      make_lines_dump:
-
 
4156
	cmp	esi,[display_buffer]
-
 
4157
	je	lines_dump_ok
-
 
4158
	mov	eax,[esi-4]
-
 
4159
	mov	ecx,[esi-8]
-
 
4160
	sub	esi,8
-
 
4161
	sub	esi,ecx
-
 
4162
	cmp	eax,1
-
 
4163
	jne	make_lines_dump
-
 
4164
	mov	eax,[esi+4]
-
 
4165
	sub	eax,[code_start]
-
 
4166
	add	eax,[headers_size]
-
 
4167
	cmp	byte [esi+1Ah],0
-
 
4168
	je	store_offset
-
 
4169
	xor	eax,eax
-
 
4170
      store_offset:
-
 
4171
	stos	dword [edi]
-
 
4172
	mov	eax,[esi]
-
 
4173
	sub	eax,[memory_start]
-
 
4174
	stos	dword [edi]
-
 
4175
	mov	eax,[esi+4]
-
 
4176
	xor	edx,edx
-
 
4177
	sub	eax,[esi+8]
-
 
4178
	sbb	edx,[esi+8+4]
-
 
4179
	stos	dword [edi]
-
 
4180
	mov	eax,edx
-
 
4181
	stos	dword [edi]
-
 
4182
	mov	eax,[esi+10h]
-
 
4183
	stos	dword [edi]
-
 
4184
	mov	eax,[esi+14h]
-
 
4185
	test	eax,eax
-
 
4186
	jz	base_symbol_for_line_ok
-
 
4187
	cmp	eax,[symbols_stream]
-
 
4188
	mov	eax,[eax+4]
-
 
4189
	jae	base_symbol_for_line_ok
-
 
4190
	xor	eax,eax
-
 
4191
      base_symbol_for_line_ok:
-
 
4192
	stos	dword [edi]
-
 
4193
	mov	eax,[esi+18h]
-
 
4194
	and	eax,001FFFFh
-
 
4195
	stos	dword [edi]
-
 
4196
	jmp	make_lines_dump
-
 
4197
      lines_dump_ok:
-
 
4198
	mov	edx,edi
-
 
4199
	mov	eax,[current_offset]
-
 
4200
	sub	eax,[code_start]
-
 
4201
	add	eax,[headers_size]
-
 
4202
	stos	dword [edi]
-
 
4203
	mov	ecx,edi
-
 
4204
	sub	ecx,ebx
-
 
4205
	sub	ecx,[ebx-38h+14h]
-
 
4206
	mov	[ebx-38h+2Ch],ecx
-
 
4207
	add	ecx,[ebx-38h+28h]
-
 
4208
	mov	[ebx-38h+30h],ecx
-
 
4209
      find_inexisting_offsets:
-
 
4210
	sub	edx,1Ch
-
 
4211
	cmp	edx,ebp
-
 
4212
	jb	write_symbols
-
 
4213
	test	byte [edx+1Ah],1
-
 
4214
	jnz	find_inexisting_offsets
-
 
4215
	cmp	eax,[edx]
-
 
4216
	jb	correct_inexisting_offset
-
 
4217
	mov	eax,[edx]
-
 
4218
	jmp	find_inexisting_offsets
-
 
4219
      correct_inexisting_offset:
-
 
4220
	mov	dword [edx],0
-
 
4221
	or	byte [edx+1Ah],2
-
 
4222
	jmp	find_inexisting_offsets
-
 
4223
      write_symbols:
-
 
4224
	mov	edx,[symbols_file]
-
 
4225
	call	create
-
 
4226
	jc	write_failed
-
 
4227
	mov	edx,[code_start]
-
 
4228
	mov	ecx,[edx+14h]
-
 
4229
	add	ecx,38h
-
 
4230
	call	write
-
 
4231
	mov	edx,[display_buffer]
-
 
4232
	mov	ecx,[memory_end]
-
 
4233
	sub	ecx,[labels_list]
-
 
4234
	call	write
-
 
4235
	mov	edx,[memory_start]
-
 
4236
	mov	ecx,[source_start]
-
 
4237
	sub	ecx,edx
-
 
4238
	call	write
-
 
4239
	mov	edx,ebp
-
 
4240
	mov	ecx,edi
-
 
4241
	sub	ecx,edx
-
 
4242
	call	write
-
 
4243
	mov	edx,[free_additional_memory]
-
 
4244
	mov	ecx,[number_of_sections]
-
 
4245
	shl	ecx,2
-
 
4246
	call	write
-
 
4247
	call	close
-
 
4248
	ret
-
 
4249