Subversion Repositories Kolibri OS

Rev

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

Rev 31 Rev 109
Line 1... Line 1...
1
; flat assembler core
1
; flat assembler core
2
; Copyright (c) 1999-2005, Tomasz Grysztar.
2
; Copyright (c) 1999-2006, Tomasz Grysztar.
3
; All rights reserved.
3
; All rights reserved.
Line 4... Line 4...
4
 
4
 
5
formatter:
5
formatter:
6
	cmp	[output_file],0
6
        cmp     [output_file],0
Line 222... Line 222...
222
	je	mz_heap
222
        je      mz_heap
223
	cmp	al,3
223
        cmp     al,3
224
	je	pe_heap
224
        je      pe_heap
225
	jmp	illegal_instruction
225
        jmp     illegal_instruction
226
section_directive:
226
segment_directive:
-
 
227
        cmp     [virtual_data],0
-
 
228
        jne     illegal_instruction
-
 
229
        mov     al,[output_format]
-
 
230
        cmp     al,2
-
 
231
        je      mz_segment
-
 
232
        cmp     al,5
-
 
233
        je      elf_segment
-
 
234
        jmp     illegal_instruction
-
 
235
section_directive:
227
	cmp	[virtual_data],0
236
        cmp     [virtual_data],0
228
	jne	illegal_instruction
237
        jne     illegal_instruction
229
	mov	al,[output_format]
238
        mov     al,[output_format]
230
	cmp	al,3
239
        cmp     al,3
231
	je	pe_section
240
        je      pe_section
Line 388... Line 397...
388
	jae	out_of_memory
397
        jae     out_of_memory
389
	mov	[free_additional_memory],ebx
398
        mov     [free_additional_memory],ebx
390
	pop	ebx eax
399
        pop     ebx eax
391
	ret
400
        ret
392
segment_directive:
401
mz_segment:
393
	cmp	[output_format],2
402
        lods    byte [esi]
394
	jne	illegal_instruction
-
 
395
	cmp	[virtual_data],0
-
 
396
	jne	illegal_instruction
-
 
397
	lods	byte [esi]
-
 
398
	cmp	al,2
403
        cmp     al,2
399
	jne	invalid_argument
404
        jne     invalid_argument
400
	lods	dword [esi]
405
        lods    dword [esi]
401
	cmp	eax,0Fh
406
        cmp     eax,0Fh
402
	jb	invalid_use_of_symbol
407
        jb      invalid_use_of_symbol
Line 637... Line 642...
637
	cmp	word [esi],'MZ'
642
        cmp     word [esi],'MZ'
638
	jne	binary_stub
643
        jne     binary_stub
639
	add	edi,1Ch
644
        add     edi,1Ch
640
	movzx	ecx,word [esi+6]
645
        movzx   ecx,word [esi+6]
641
	dec	ecx
646
        add     ecx,11b
642
	sar	ecx,3
-
 
643
	inc	ecx
647
        and     ecx,not 11b
644
	shl	ecx,2
-
 
645
	add	ecx,(40h-1Ch) shr 2
648
        add     ecx,(40h-1Ch) shr 2
646
	lea	eax,[edi+ecx*4]
649
        lea     eax,[edi+ecx*4]
647
	cmp	edi,[display_buffer]
650
        cmp     edi,[display_buffer]
648
	jae	out_of_memory
651
        jae     out_of_memory
649
	xor	eax,eax
652
        xor     eax,eax
650
	rep	stos dword [edi]
653
        rep     stos dword [edi]
Line 720... Line 723...
720
	mov	ax,cx
723
        mov     ax,cx
721
	and	ax,1FFh
724
        and     ax,1FFh
722
	mov	[esi+2],ax
725
        mov     [esi+2],ax
723
	lea	eax,[ecx+1FFh]
726
        lea     eax,[ecx+1FFh]
724
	and	eax,not 1FFh
727
        shr     eax,9
725
	mov	[esi+4],ax
728
        mov     [esi+4],ax
726
	mov	[esi+3Ch],ecx
729
        mov     [esi+3Ch],ecx
727
	sub	ecx,40h
730
        sub     ecx,40h
728
	mov	eax,10000h
731
        mov     eax,10000h
729
	sub	eax,ecx
732
        sub     eax,ecx
730
	jbe	binary_heap_ok
733
        jbe     binary_heap_ok
Line 992... Line 995...
992
	test	[format_flags],8
995
        test    [format_flags],8
993
	jnz	pe64_org
996
        jnz     pe64_org
994
	sub	eax,[edx+34h]
997
        sub     eax,[edx+34h]
995
	sbb	ecx,0
998
        sbb     ecx,0
996
	mov	[labels_type],2
999
        mov     bl,2
997
	mov	[code_type],32
1000
        mov     [code_type],32
998
	jmp	pe_org_ok
1001
        jmp     pe_org_ok
999
      pe64_org:
1002
      pe64_org:
1000
	sub	eax,[edx+30h]
1003
        sub     eax,[edx+30h]
1001
	sbb	ecx,[edx+34h]
1004
        sbb     ecx,[edx+34h]
1002
	mov	[labels_type],4
1005
        mov     bl,4
1003
	mov	[code_type],64
1006
        mov     [code_type],64
1004
      pe_org_ok:
1007
      pe_org_ok:
1005
	mov	dword [org_origin],eax
1008
        bt      [resolver_flags],0
-
 
1009
        jc      pe_labels_type_ok
-
 
1010
        xor     bl,bl
-
 
1011
      pe_labels_type_ok:
-
 
1012
        mov     [labels_type],bl
-
 
1013
        mov     dword [org_origin],eax
1006
	mov	dword [org_origin+4],ecx
1014
        mov     dword [org_origin+4],ecx
1007
	mov	[org_registers],0
1015
        mov     [org_registers],0
1008
	mov	[org_start],edi
1016
        mov     [org_start],edi
1009
	bt	[format_flags],8
1017
        bt      [format_flags],8
1010
	jnc	dll_flag_ok
1018
        jnc     dll_flag_ok
Line 1061... Line 1069...
1061
	sub	eax,[edx+34h]
1069
        sub     eax,[edx+34h]
1062
	sbb	ecx,0
1070
        sbb     ecx,0
1063
	mov	[labels_type],2
1071
        mov     [labels_type],2
1064
	mov	[code_type],32
1072
        mov     [code_type],32
1065
	jmp	pe_section_org_ok
1073
        bt      [resolver_flags],0
-
 
1074
        jc      pe_section_org_ok
-
 
1075
        mov     [labels_type],0
-
 
1076
        jmp     pe_section_org_ok
1066
      pe64_section_org:
1077
      pe64_section_org:
1067
	sub	eax,[edx+30h]
1078
        sub     eax,[edx+30h]
1068
	sbb	ecx,[edx+34h]
1079
        sbb     ecx,[edx+34h]
1069
	mov	[labels_type],4
1080
        mov     [labels_type],4
1070
	mov	[code_type],64
1081
        mov     [code_type],64
1071
      pe_section_org_ok:
1082
        bt      [resolver_flags],0
-
 
1083
        jc      pe_section_org_ok
-
 
1084
        mov     [labels_type],0
-
 
1085
      pe_section_org_ok:
1072
	mov	dword [org_origin],eax
1086
        mov     dword [org_origin],eax
1073
	mov	dword [org_origin+4],ecx
1087
        mov     dword [org_origin+4],ecx
1074
	mov	[org_registers],0
1088
        mov     [org_registers],0
1075
	mov	[org_start],edi
1089
        mov     [org_start],edi
1076
      get_section_flags:
1090
      get_section_flags:
Line 1101... Line 1115...
1101
	pop	edx ebx
1115
        pop     edx ebx
1102
	jmp	get_section_flags
1116
        jmp     get_section_flags
1103
      section_flag:
1117
      section_flag:
1104
	lods	byte [esi]
1118
        lods    byte [esi]
1105
	mov	cl,al
1119
        cmp     al,9
-
 
1120
        je      invalid_argument
-
 
1121
        cmp     al,11
-
 
1122
        je      invalid_argument
-
 
1123
        mov     cl,al
1106
	mov	eax,1
1124
        mov     eax,1
1107
	shl	eax,cl
1125
        shl     eax,cl
1108
	test	dword [ebx+24h],eax
1126
        test    dword [ebx+24h],eax
1109
	jnz	setting_already_specified
1127
        jnz     setting_already_specified
1110
	or	dword [ebx+24h],eax
1128
        or      dword [ebx+24h],eax
Line 1226... Line 1244...
1226
	je	invalid_value
1244
        je      invalid_value
1227
	test	[format_flags],8
1245
        test    [format_flags],8
1228
	jnz	pe64_entry
1246
        jnz     pe64_entry
1229
	call	get_dword_value
1247
        call    get_dword_value
1230
	cmp	[value_type],2
1248
        mov     bl,2
-
 
1249
        bt      [resolver_flags],0
-
 
1250
        jc      check_pe_entry_label_type
-
 
1251
        xor     bl,bl
-
 
1252
      check_pe_entry_label_type:
-
 
1253
        cmp     [value_type],bl
1231
	je	pe_entry_ok
1254
        je      pe_entry_ok
1232
	cmp	[error_line],0
1255
        cmp     [error_line],0
1233
	jne	pe_entry_ok
1256
        jne     pe_entry_ok
1234
	mov	eax,[current_line]
1257
        mov     edx,[current_line]
1235
	mov	[error_line],eax
1258
        mov     [error_line],edx
1236
	mov	[error],invalid_address
1259
        mov     [error],invalid_address
1237
      pe_entry_ok:
1260
      pe_entry_ok:
1238
	mov	edx,[code_start]
1261
        mov     edx,[code_start]
1239
	sub	eax,[edx+34h]
1262
        sub     eax,[edx+34h]
1240
	mov	[edx+28h],eax
1263
        mov     [edx+28h],eax
1241
	jmp	instruction_assembled
1264
        jmp     instruction_assembled
1242
      pe64_entry:
1265
      pe64_entry:
1243
	call	get_qword_value
1266
        call    get_qword_value
1244
	cmp	[value_type],4
1267
        mov     bl,4
-
 
1268
        bt      [resolver_flags],0
-
 
1269
        jc      check_pe64_entry_label_type
-
 
1270
        xor     bl,bl
-
 
1271
      check_pe64_entry_label_type:
-
 
1272
        cmp     [value_type],bl
1245
	je	pe64_entry_ok
1273
        je      pe64_entry_type_ok
1246
	cmp	[error_line],0
1274
        cmp     [error_line],0
1247
	jne	pe64_entry_ok
1275
        jne     pe64_entry_type_ok
1248
	mov	eax,[current_line]
1276
        mov     edx,[current_line]
1249
	mov	[error_line],eax
1277
        mov     [error_line],edx
1250
	mov	[error],invalid_address
1278
        mov     [error],invalid_address
1251
      pe64_entry_ok:
1279
      pe64_entry_type_ok:
1252
	mov	ecx,[code_start]
1280
        mov     ecx,[code_start]
1253
	sub	eax,[ecx+30h]
1281
        sub     eax,[ecx+30h]
1254
	sbb	edx,[ecx+34h]
1282
        sbb     edx,[ecx+34h]
1255
	jnz	value_out_of_range
1283
        jz      pe64_entry_range_ok
-
 
1284
        mov     edx,[current_line]
-
 
1285
        mov     [error_line],edx
-
 
1286
        mov     [error],value_out_of_range
1256
	mov	[ecx+28h],eax
1287
      pe64_entry_range_ok:
-
 
1288
        mov     [ecx+28h],eax
1257
	jmp	instruction_assembled
1289
        jmp     instruction_assembled
1258
pe_stack:
1290
pe_stack:
1259
	lods	byte [esi]
1291
        lods    byte [esi]
1260
	cmp	al,'('
1292
        cmp     al,'('
1261
	jne	invalid_argument
1293
        jne     invalid_argument
Line 1384... Line 1416...
1384
	ja	value_out_of_range
1416
        ja      value_out_of_range
1385
	jmp	instruction_assembled
1417
        jmp     instruction_assembled
1386
mark_pe_relocation:
1418
mark_pe_relocation:
1387
	push	eax ebx
1419
        push    eax ebx
1388
	mov	ebx,[current_section]
1420
        mov     al,2
-
 
1421
        test    [format_flags],8
-
 
1422
        jz      check_pe_relocation_type
-
 
1423
        mov     al,4
-
 
1424
      check_pe_relocation_type:
-
 
1425
        cmp     [value_type],al
-
 
1426
        je      pe_relocation_type_ok
-
 
1427
        cmp     [error_line],0
-
 
1428
        jne     pe_relocation_type_ok
-
 
1429
        mov     eax,[current_line]
-
 
1430
        mov     [error_line],eax
-
 
1431
        mov     [error],invalid_use_of_symbol
-
 
1432
      pe_relocation_type_ok:
-
 
1433
        mov     ebx,[current_section]
1389
	mov	eax,edi
1434
        mov     eax,edi
1390
	sub	eax,[ebx+14h]
1435
        sub     eax,[ebx+14h]
1391
	add	eax,[ebx+0Ch]
1436
        add     eax,[ebx+0Ch]
1392
	mov	ebx,[free_additional_memory]
1437
        mov     ebx,[free_additional_memory]
1393
	inc	[number_of_relocations]
1438
        inc     [number_of_relocations]
Line 1971... Line 2016...
1971
	mov	[resource_size],eax
2016
        mov     [resource_size],eax
1972
      resource_done:
2017
      resource_done:
1973
	ret
2018
        ret
1974
make_pe_fixups:
2019
make_pe_fixups:
1975
	push	esi
2020
        bts     [resolver_flags],0
-
 
2021
        jc      pe_relocatable_ok
-
 
2022
        or      [next_pass_needed],-1
-
 
2023
     pe_relocatable_ok:
-
 
2024
        push    esi
1976
	mov	ecx,[number_of_relocations]
2025
        mov     ecx,[number_of_relocations]
1977
	jecxz	fixups_done
2026
        mov     esi,[free_additional_memory]
1978
	mov	esi,[free_additional_memory]
-
 
1979
	mov	eax,ecx
2027
        mov     eax,ecx
1980
	shl	eax,2
2028
        shl     eax,2
1981
	sub	esi,eax
2029
        sub     esi,eax
1982
	mov	[free_additional_memory],esi
2030
        mov     [free_additional_memory],esi
1983
	or	[number_of_relocations],-1
2031
        or      [number_of_relocations],-1
Line 2002... Line 2050...
2002
	mov	ebx,edi
2050
        mov     ebx,edi
2003
	mov	eax,8
2051
        mov     eax,8
2004
	stos	dword [edi]
2052
        stos    dword [edi]
2005
      store_fixup:
2053
      store_fixup:
2006
	add	dword [ebx],2
2054
        jecxz   fixups_done
-
 
2055
        add     dword [ebx],2
2007
	mov	eax,[esi]
2056
        mov     eax,[esi]
2008
	and	ax,0FFFh
2057
        and     ax,0FFFh
2009
	test	[format_flags],8
2058
        test    [format_flags],8
2010
	jnz	fixup_64bit
2059
        jnz     fixup_64bit
2011
	or	ax,3000h
2060
        or      ax,3000h
Line 2026... Line 2075...
2026
	call	make_timestamp
2075
        call    make_timestamp
2027
	mov	edx,[code_start]
2076
        mov     edx,[code_start]
2028
	mov	[edx+8],eax
2077
        mov     [edx+8],eax
2029
	mov	eax,[number_of_relocations]
2078
        mov     eax,[number_of_relocations]
2030
	cmp	eax,0
2079
        cmp     eax,-1
2031
	jle	pe_flags_ok
2080
        je      pe_relocations_ok
2032
	or	word [edx+16h],1
2081
        shl     eax,2
2033
	shl	eax,2
-
 
2034
	sub	[free_additional_memory],eax
2082
        sub     [free_additional_memory],eax
2035
      pe_flags_ok:
2083
        btr     [resolver_flags],0
-
 
2084
        jnc     pe_relocations_ok
-
 
2085
        or      [next_pass_needed],-1
-
 
2086
      pe_relocations_ok:
2036
	mov	eax,[number_of_sections]
2087
        mov     eax,[number_of_sections]
2037
	mov	[edx+6],ax
2088
        mov     [edx+6],ax
2038
	imul	eax,28h
2089
        imul    eax,28h
2039
	movzx	ecx,word [edx+14h]
2090
        movzx   ecx,word [edx+14h]
2040
	lea	eax,[eax+18h+ecx]
2091
        lea     eax,[eax+18h+ecx]
2041
	add	eax,[stub_size]
2092
        add     eax,[stub_size]
Line 2093... Line 2144...
2093
format_coff:
2144
format_coff:
2094
	mov	eax,[additional_memory]
2145
        mov     eax,[additional_memory]
2095
	mov	[symbols_stream],eax
2146
        mov     [symbols_stream],eax
2096
	mov	ebx,eax
2147
        mov     ebx,eax
2097
	add	eax,18h
2148
        add     eax,20h
2098
	cmp	eax,[structures_buffer]
2149
        cmp     eax,[structures_buffer]
2099
	jae	out_of_memory
2150
        jae     out_of_memory
2100
	mov	[free_additional_memory],eax
2151
        mov     [free_additional_memory],eax
2101
	xor	eax,eax
2152
        xor     eax,eax
2102
	mov	[ebx],al
2153
        mov     [ebx],al
Line 2126... Line 2177...
2126
	jmp	instruction_assembled
2177
        jmp     instruction_assembled
2127
coff_section:
2178
coff_section:
2128
	call	close_coff_section
2179
        call    close_coff_section
2129
	mov	ebx,[free_additional_memory]
2180
        mov     ebx,[free_additional_memory]
2130
	lea	eax,[ebx+18h]
2181
        lea     eax,[ebx+20h]
2131
	cmp	eax,[structures_buffer]
2182
        cmp     eax,[structures_buffer]
2132
	jae	out_of_memory
2183
        jae     out_of_memory
2133
	mov	[free_additional_memory],eax
2184
        mov     [free_additional_memory],eax
2134
	mov	[current_section],ebx
2185
        mov     [current_section],ebx
2135
	inc	[number_of_sections]
2186
        inc     [number_of_sections]
2136
	xor	eax,eax
2187
        xor     eax,eax
Line 2241... Line 2292...
2241
	mov	al,6
2292
        mov     al,6
2242
	jmp	coff_relocation
2293
        jmp     coff_relocation
2243
      coff_64bit_relocation:
2294
      coff_64bit_relocation:
2244
	mov	al,1
2295
        mov     al,1
2245
	jmp	coff_relocation
2296
        cmp     [value_type],4
-
 
2297
        je      coff_relocation
-
 
2298
        mov     al,2
-
 
2299
        jmp     coff_relocation
2246
      coff_relocation_relative:
2300
      coff_relocation_relative:
2247
	push	ebx
2301
        push    ebx
2248
	bt	[format_flags],0
2302
        bt      [format_flags],0
2249
	jnc	relative_ok
2303
        jnc     relative_ok
2250
	mov	ebx,[current_section]
2304
        mov     ebx,[current_section]
Line 2318... Line 2372...
2318
	mov	[ebx+4],eax
2372
        mov     [ebx+4],eax
2319
	mov	eax,[number_of_sections]
2373
        mov     eax,[number_of_sections]
2320
	mov	[ebx+2],ax
2374
        mov     [ebx+2],ax
2321
	mov	esi,[symbols_stream]
2375
        mov     esi,[symbols_stream]
2322
	xor	ecx,ecx
2376
        xor     eax,eax
-
 
2377
        xor     ecx,ecx
2323
      enumerate_symbols:
2378
      enumerate_symbols:
2324
	cmp	esi,[free_additional_memory]
2379
        cmp     esi,[free_additional_memory]
2325
	je	symbols_enumerated
2380
        je      symbols_enumerated
2326
	mov	dl,[esi]
2381
        mov     dl,[esi]
2327
	or	dl,dl
2382
        or      dl,dl
Line 2331... Line 2386...
2331
	ja	enumerate_extrn
2386
        ja      enumerate_extrn
2332
	add	esi,0Ch
2387
        add     esi,0Ch
2333
	jmp	enumerate_symbols
2388
        jmp     enumerate_symbols
2334
      enumerate_section:
2389
      enumerate_section:
2335
	mov	edx,ecx
2390
        mov     edx,eax
2336
	shl	edx,8
2391
        shl     edx,8
2337
	mov	[esi],edx
2392
        mov     [esi],edx
2338
	inc	ecx
2393
        inc     eax
-
 
2394
        inc     ecx
2339
	add	esi,18h
2395
        mov     [esi+1Eh],cx
-
 
2396
        add     esi,20h
2340
	jmp	enumerate_symbols
2397
        jmp     enumerate_symbols
2341
      enumerate_public:
2398
      enumerate_public:
2342
	mov	edx,eax
2399
        mov     edx,eax
2343
	shl	edx,8
2400
        shl     edx,8
2344
	mov	dl,80h
2401
        mov     dl,80h
2345
	mov	[esi],edx
2402
        mov     [esi],edx
Line 2370... Line 2427...
2370
	mov	edx,ebx
2427
        mov     edx,ebx
2371
      find_references_to_default_section:
2428
      find_references_to_default_section:
2372
	cmp	ebx,[free_additional_memory]
2429
        cmp     ebx,[free_additional_memory]
2373
	jne	check_reference
2430
        jne     check_reference
2374
	add	[symbols_stream],18h
2431
        add     [symbols_stream],20h
2375
	ret
2432
        ret
2376
      check_reference:
2433
      check_reference:
2377
	mov	al,[ebx]
2434
        mov     al,[ebx]
2378
	or	al,al
2435
        or      al,al
2379
	jz	skip_other_section
2436
        jz      skip_other_section
2380
	cmp	al,80h
2437
        cmp     al,80h
Line 2396... Line 2453...
2396
	cmp	edx,[eax+20]
2453
        cmp     edx,[eax+20]
2397
	je	default_section_ok
2454
        je      default_section_ok
2398
	jmp	find_references_to_default_section
2455
        jmp     find_references_to_default_section
2399
      skip_other_section:
2456
      skip_other_section:
2400
	add	ebx,18h
2457
        add     ebx,20h
2401
	jmp	find_references_to_default_section
2458
        jmp     find_references_to_default_section
2402
      default_section_ok:
2459
      default_section_ok:
2403
	inc	[number_of_sections]
2460
        inc     [number_of_sections]
2404
	ret
2461
        ret
2405
      symbols_enumerated:
2462
      symbols_enumerated:
2406
	mov	[ebx+0Ch],eax
2463
        mov     [ebx+0Ch],eax
Line 2451... Line 2508...
2451
	mov	edx,[code_size]
2508
        mov     edx,[code_size]
2452
	add	ebx,edx
2509
        add     ebx,edx
2453
	add	edx,ebp
2510
        add     edx,ebp
2454
	xor	ecx,ecx
2511
        xor     ecx,ecx
2455
	add	esi,18h
2512
        add     esi,20h
2456
      find_relocations:
2513
      find_relocations:
2457
	cmp	esi,[free_additional_memory]
2514
        cmp     esi,[free_additional_memory]
2458
	je	section_relocations_done
2515
        je      section_relocations_done
2459
	mov	al,[esi]
2516
        mov     al,[esi]
2460
	or	al,al
2517
        or      al,al
2461
	jz	section_relocations_done
2518
        jz      section_relocations_done
Line 2533... Line 2590...
2533
	rep	stos dword [edi]
2590
        rep     stos dword [edi]
2534
	mov	edx,edi
2591
        mov     edx,edi
2535
	stos	dword [edi]
2592
        stos    dword [edi]
2536
	mov	esi,[symbols_stream]
2593
        mov     esi,[symbols_stream]
2537
      make_section_symbols:
2594
      make_symbols_table:
2538
	cmp	esi,[free_additional_memory]
2595
        cmp     esi,[free_additional_memory]
2539
	je	section_symbols_ok
2596
        je      symbols_table_ok
2540
	mov	al,[esi]
2597
        mov     al,[esi]
2541
	or	al,al
2598
        cmp     al,80h
-
 
2599
        je      add_public_symbol
-
 
2600
        ja      add_extrn_symbol
-
 
2601
        or      al,al
2542
	jz	add_section_symbol
2602
        jz      add_section_symbol
2543
	add	esi,0Ch
2603
        add     esi,0Ch
2544
	cmp	al,80h
2604
        jmp     make_symbols_table
2545
	jne	make_section_symbols
-
 
2546
	add	esi,4
-
 
2547
	jmp	make_section_symbols
-
 
2548
      add_section_symbol:
2605
      add_section_symbol:
2549
	call	store_symbol_name
2606
        call    store_symbol_name
2550
	mov	eax,[esi]
2607
        movzx   eax,word [esi+1Eh]
2551
	shr	eax,8
2608
        mov     [ebx+0Ch],ax
2552
	inc	eax
-
 
2553
	mov	[ebx+0Ch],ax
-
 
2554
	mov	byte [ebx+10h],3
2609
        mov     byte [ebx+10h],3
2555
	add	esi,18h
2610
        add     esi,20h
2556
	add	ebx,12h
2611
        add     ebx,12h
2557
	jmp	make_section_symbols
2612
        jmp     make_symbols_table
2558
      section_symbols_ok:
-
 
2559
	mov	esi,[symbols_stream]
-
 
2560
      make_symbols_table:
-
 
2561
	cmp	esi,[free_additional_memory]
-
 
2562
	je	symbols_table_ok
-
 
2563
	mov	al,[esi]
-
 
2564
	cmp	al,80h
-
 
2565
	je	add_public_symbol
-
 
2566
	ja	add_extrn_symbol
-
 
2567
	add	esi,0Ch
-
 
2568
	or	al,al
-
 
2569
	jnz	make_symbols_table
-
 
2570
	add	esi,0Ch
-
 
2571
	jmp	make_symbols_table
-
 
2572
      add_extrn_symbol:
2613
      add_extrn_symbol:
2573
	call	store_symbol_name
2614
        call    store_symbol_name
2574
	mov	byte [ebx+10h],2
2615
        mov     byte [ebx+10h],2
2575
	add	esi,0Ch
2616
        add     esi,0Ch
2576
	add	ebx,12h
2617
        add     ebx,12h
Line 2597... Line 2638...
2597
	cmp	cl,4
2638
        cmp     cl,4
2598
	jne	invalid_use_of_symbol
2639
        jne     invalid_use_of_symbol
2599
      public_symbol_type_ok:
2640
      public_symbol_type_ok:
2600
	mov	ecx,[eax+20]
2641
        mov     ecx,[eax+20]
2601
	mov	ecx,[ecx]
2642
        cmp     byte [ecx],81h
2602
	cmp	cl,81h
-
 
2603
	je	alias_symbol
2643
        je      alias_symbol
2604
	or	cl,cl
2644
        cmp     byte [ecx],0
2605
	jnz	invalid_use_of_symbol
2645
        jne     invalid_use_of_symbol
2606
	shr	ecx,8
2646
        mov     cx,[ecx+1Eh]
2607
	inc	cx
2647
        mov     [ebx+0Ch],cx
2608
	mov	[ebx+0Ch],cx
-
 
2609
      public_symbol_section_ok:
2648
      public_symbol_section_ok:
2610
	cmp	dword [eax+4],0
2649
        cmp     dword [eax+4],0
2611
	je	store_public_symbol
2650
        je      store_public_symbol
2612
	cmp	dword [eax+4],-1
2651
        cmp     dword [eax+4],-1
2613
	jne	value_out_of_range
2652
        jne     value_out_of_range
Line 2711... Line 2750...
2711
	mov	byte [edx+10h],1
2750
        mov     byte [edx+10h],1
2712
	mov	eax,[additional_memory]
2751
        mov     eax,[additional_memory]
2713
	mov	[symbols_stream],eax
2752
        mov     [symbols_stream],eax
2714
	mov	ebx,eax
2753
        mov     ebx,eax
2715
	add	eax,18h
2754
        add     eax,20h
2716
	cmp	eax,[structures_buffer]
2755
        cmp     eax,[structures_buffer]
2717
	jae	out_of_memory
2756
        jae     out_of_memory
2718
	mov	[free_additional_memory],eax
2757
        mov     [free_additional_memory],eax
2719
	xor	eax,eax
2758
        xor     eax,eax
2720
	mov	[current_section],ebx
2759
        mov     [current_section],ebx
2721
	mov	[number_of_sections],eax
2760
        mov     [number_of_sections],eax
Line 2758... Line 2797...
2758
	mov	[labels_type],4
2797
        mov     [labels_type],4
2759
	jmp	elf_header_ok
2798
        jmp     elf_header_ok
2760
elf_section:
2799
elf_section:
2761
	bt	[format_flags],0
2800
        bt      [format_flags],0
2762
	jc	elf_exe_section
2801
        jc      illegal_instruction
2763
	call	close_coff_section
2802
        call    close_coff_section
2764
	mov	ebx,[free_additional_memory]
2803
        mov     ebx,[free_additional_memory]
2765
	lea	eax,[ebx+18h]
2804
        lea     eax,[ebx+20h]
2766
	cmp	eax,[structures_buffer]
2805
        cmp     eax,[structures_buffer]
2767
	jae	out_of_memory
2806
        jae     out_of_memory
2768
	mov	[free_additional_memory],eax
2807
        mov     [free_additional_memory],eax
2769
	mov	[current_section],ebx
2808
        mov     [current_section],ebx
2770
	inc	word [number_of_sections]
2809
        inc     word [number_of_sections]
2771
	jz	format_limitations_exceeded
2810
        jz      format_limitations_exceeded
Line 2847... Line 2886...
2847
mark_elf_relocation:
2886
mark_elf_relocation:
2848
	cmp	[value_type],3
2887
        cmp     [value_type],3
2849
	je	elf_relocation_relative
2888
        je      elf_relocation_relative
2850
	push	ebx eax
2889
        push    ebx eax
2851
	mov	al,1
2890
        cmp     [value_type],3
-
 
2891
        je      elf_gotoff_relocation
-
 
2892
        mov     al,1
2852
	jmp	coff_relocation
2893
        test    [format_flags],8
-
 
2894
        jz      coff_relocation
-
 
2895
        cmp     [value_type],4
-
 
2896
        je      coff_relocation
-
 
2897
        mov     al,11
-
 
2898
        jmp     coff_relocation
-
 
2899
      elf_gotoff_relocation:
-
 
2900
        mov     al,9
-
 
2901
        jmp     coff_relocation
2853
      elf_relocation_relative:
2902
      elf_relocation_relative:
2854
	cmp	[labels_type],0
2903
        cmp     [labels_type],0
2855
	je	invalid_use_of_symbol
2904
        je      invalid_use_of_symbol
2856
	push	ebx
2905
        push    ebx
2857
	mov	ebx,[current_section]
2906
        mov     ebx,[current_section]
Line 2895... Line 2944...
2895
	jmp	find_first_section
2944
        jmp     find_first_section
2896
      first_section_found:
2945
      first_section_found:
2897
	mov	ebx,esi
2946
        mov     ebx,esi
2898
	mov	ebp,esi
2947
        mov     ebp,esi
2899
	add	esi,18h
2948
        add     esi,20h
2900
	xor	ecx,ecx
2949
        xor     ecx,ecx
2901
	xor	edx,edx
2950
        xor     edx,edx
2902
      find_next_section:
2951
      find_next_section:
2903
	cmp	esi,[free_additional_memory]
2952
        cmp     esi,[free_additional_memory]
2904
	je	make_section_symbol
2953
        je      make_section_symbol
2905
	mov	al,[esi]
2954
        mov     al,[esi]
Line 2952... Line 3001...
2952
	stos	dword [edi]
3001
        stos    dword [edi]
2953
	stos	dword [edi]
3002
        stos    dword [edi]
2954
      section_symbol_ok:
3003
      section_symbol_ok:
2955
	mov	ebx,esi
3004
        mov     ebx,esi
2956
	add	esi,18h
3005
        add     esi,20h
2957
	cmp	ebx,[free_additional_memory]
3006
        cmp     ebx,[free_additional_memory]
2958
	jne	find_next_section
3007
        jne     find_next_section
2959
	inc	dx
3008
        inc     dx
2960
	jz	format_limitations_exceeded
3009
        jz      format_limitations_exceeded
2961
	mov	[current_section],edx
3010
        mov     [current_section],edx
2962
	mov	esi,[symbols_stream]
3011
        mov     esi,[symbols_stream]
Line 2971... Line 3020...
2971
	ja	make_extrn_symbol
3020
        ja      make_extrn_symbol
2972
	add	esi,0Ch
3021
        add     esi,0Ch
2973
	jmp	find_other_symbols
3022
        jmp     find_other_symbols
2974
      skip_section:
3023
      skip_section:
2975
	add	esi,18h
3024
        add     esi,20h
2976
	jmp	find_other_symbols
3025
        jmp     find_other_symbols
2977
      make_public_symbol:
3026
      make_public_symbol:
2978
	mov	eax,[esi+0Ch]
3027
        mov     eax,[esi+0Ch]
2979
	mov	[current_line],eax
3028
        mov     [current_line],eax
2980
	mov	ebx,[esi+8]
3029
        mov     ebx,[esi+8]
2981
	test	byte [ebx+8],1
3030
        test    byte [ebx+8],1
Line 3015... Line 3064...
3015
	stos	dword [edi]
3064
        stos    dword [edi]
3016
	mov	eax,edx
3065
        mov     eax,edx
3017
	shl	eax,16
3066
        shl     eax,16
3018
	mov	al,10h
3067
        mov     al,10h
3019
	stos	dword [edi]
3068
        cmp     byte [ebx+10],0
-
 
3069
        je      elf_public_function
-
 
3070
        or      al,1
-
 
3071
        jmp     store_elf_public_info
-
 
3072
      elf_public_function:
-
 
3073
        or      al,2
-
 
3074
      store_elf_public_info:
-
 
3075
        stos    dword [edi]
3020
	jmp	public_symbol_ok
3076
        jmp     public_symbol_ok
3021
      elf64_public_symbol:
3077
      elf64_public_symbol:
3022
	mov	eax,edx
3078
        mov     eax,edx
3023
	shl	eax,16
3079
        shl     eax,16
3024
	mov	al,10h
3080
        mov     al,10h
3025
	stos	dword [edi]
3081
        cmp     byte [ebx+10],0
-
 
3082
        je      elf64_public_function
-
 
3083
        or      al,1
-
 
3084
        jmp     store_elf64_public_info
-
 
3085
      elf64_public_function:
-
 
3086
        or      al,2
-
 
3087
      store_elf64_public_info:
-
 
3088
        stos    dword [edi]
3026
	call	get_public_value
3089
        call    get_public_value
3027
	stos	dword [edi]
3090
        stos    dword [edi]
3028
	xor	eax,eax
3091
        xor     eax,eax
3029
	stos	dword [edi]
3092
        stos    dword [edi]
3030
	mov	al,[ebx+10]
3093
        mov     al,[ebx+10]
Line 3202... Line 3265...
3202
	call	store_elf_machine_word
3265
        call    store_elf_machine_word
3203
	xor	eax,eax
3266
        xor     eax,eax
3204
	call	store_elf_machine_word
3267
        call    store_elf_machine_word
3205
	inc	ecx
3268
        inc     ecx
3206
	add	esi,18h
3269
        add     esi,20h
3207
	xchg	edi,[esp]
3270
        xchg    edi,[esp]
3208
	mov	ebp,edi
3271
        mov     ebp,edi
3209
      convert_relocations:
3272
      convert_relocations:
3210
	cmp	esi,[free_additional_memory]
3273
        cmp     esi,[free_additional_memory]
3211
	je	relocations_converted
3274
        je      relocations_converted
3212
	mov	al,[esi]
3275
        mov     al,[esi]
Line 3410... Line 3473...
3410
	mov	byte [edx+2Ah],20h
3473
        mov     byte [edx+2Ah],20h
3411
	mov	ebx,edi
3474
        mov     ebx,edi
3412
	mov	ecx,20h shr 2
3475
        mov     ecx,20h shr 2
3413
	cmp	[current_pass],0
3476
        cmp     [current_pass],0
3414
	je	init_elf_exe_sections
3477
        je      init_elf_segments
3415
	imul	ecx,[number_of_sections]
3478
        imul    ecx,[number_of_sections]
3416
      init_elf_exe_sections:
3479
      init_elf_segments:
3417
	xor	eax,eax
3480
        xor     eax,eax
3418
	rep	stos dword [edi]
3481
        rep     stos dword [edi]
3419
	mov	[number_of_sections],0
3482
        mov     [number_of_sections],0
3420
	mov	byte [ebx],1
3483
        mov     byte [ebx],1
3421
	mov	word [ebx+1Ch],1000h
3484
        mov     word [ebx+1Ch],1000h
3422
	mov	byte [ebx+18h],111b
3485
        mov     byte [ebx+18h],111b
Line 3464... Line 3527...
3464
	mov	byte [edx+36h],38h
3527
        mov     byte [edx+36h],38h
3465
	mov	ebx,edi
3528
        mov     ebx,edi
3466
	mov	ecx,38h shr 2
3529
        mov     ecx,38h shr 2
3467
	cmp	[current_pass],0
3530
        cmp     [current_pass],0
3468
	je	init_elf64_exe_sections
3531
        je      init_elf64_segments
3469
	imul	ecx,[number_of_sections]
3532
        imul    ecx,[number_of_sections]
3470
      init_elf64_exe_sections:
3533
      init_elf64_segments:
3471
	xor	eax,eax
3534
        xor     eax,eax
3472
	rep	stos dword [edi]
3535
        rep     stos dword [edi]
3473
	mov	[number_of_sections],0
3536
        mov     [number_of_sections],0
3474
	mov	byte [ebx],1
3537
        mov     byte [ebx],1
3475
	mov	word [ebx+30h],1000h
3538
        mov     word [ebx+30h],1000h
3476
	mov	byte [ebx+4],111b
3539
        mov     byte [ebx+4],111b
Line 3521... Line 3584...
3521
	mov	ebx,[code_start]
3584
        mov     ebx,[code_start]
3522
	mov	[ebx+18h],eax
3585
        mov     [ebx+18h],eax
3523
	mov	[ebx+1Ch],edx
3586
        mov     [ebx+1Ch],edx
3524
	jmp	instruction_assembled
3587
        jmp     instruction_assembled
3525
elf_exe_section:
3588
elf_segment:
3526
	test	[format_flags],8
3589
        bt      [format_flags],0
-
 
3590
        jnc     illegal_instruction
-
 
3591
        test    [format_flags],8
3527
	jnz	elf64_exe_section
3592
        jnz     elf64_segment
3528
	call	close_elf_exe_section
3593
        call    close_elf_segment
3529
	push	eax
3594
        push    eax
3530
	mov	ebx,[number_of_sections]
3595
        mov     ebx,[number_of_sections]
3531
	shl	ebx,5
3596
        shl     ebx,5
3532
	add	ebx,[code_start]
3597
        add     ebx,[code_start]
3533
	add	ebx,34h
3598
        add     ebx,34h
3534
	cmp	ebx,[symbols_stream]
3599
        cmp     ebx,[symbols_stream]
3535
	jb	new_elf_exe_section
3600
        jb      new_elf_segment
3536
	mov	ebx,[symbols_stream]
3601
        mov     ebx,[symbols_stream]
3537
	sub	ebx,20h
3602
        sub     ebx,20h
3538
	push	edi
3603
        push    edi
3539
	mov	edi,ebx
3604
        mov     edi,ebx
3540
	mov	ecx,20h shr 2
3605
        mov     ecx,20h shr 2
3541
	xor	eax,eax
3606
        xor     eax,eax
3542
	rep	stos dword [edi]
3607
        rep     stos dword [edi]
3543
	pop	edi
3608
        pop     edi
3544
	or	[next_pass_needed],-1
3609
        or      [next_pass_needed],-1
3545
      new_elf_exe_section:
3610
      new_elf_segment:
3546
	mov	byte [ebx],1
3611
        mov     byte [ebx],1
3547
	mov	word [ebx+1Ch],1000h
3612
        mov     word [ebx+1Ch],1000h
3548
      elf_exe_section_flags:
3613
      elf_segment_flags:
3549
	cmp	byte [esi],19h
3614
        cmp     byte [esi],19h
3550
	jne	elf_exe_section_flags_ok
3615
        jne     elf_segment_flags_ok
3551
	lods	word [esi]
3616
        lods    word [esi]
3552
	sub	ah,28
3617
        sub     ah,28
3553
	jbe	invalid_argument
3618
        jbe     invalid_argument
3554
	cmp	ah,1
3619
        cmp     ah,1
3555
	je	mark_elf_exe_section_flag
3620
        je      mark_elf_segment_flag
3556
	cmp	ah,3
3621
        cmp     ah,3
3557
	ja	invalid_argument
3622
        ja      invalid_argument
3558
	xor	ah,1
3623
        xor     ah,1
3559
	cmp	ah,2
3624
        cmp     ah,2
3560
	je	mark_elf_exe_section_flag
3625
        je      mark_elf_segment_flag
3561
	inc	ah
3626
        inc     ah
3562
      mark_elf_exe_section_flag:
3627
      mark_elf_segment_flag:
3563
	test	[ebx+18h],ah
3628
        test    [ebx+18h],ah
3564
	jnz	setting_already_specified
3629
        jnz     setting_already_specified
3565
	or	[ebx+18h],ah
3630
        or      [ebx+18h],ah
3566
	jmp	elf_exe_section_flags
3631
        jmp     elf_segment_flags
3567
      elf_exe_section_flags_ok:
3632
      elf_segment_flags_ok:
3568
	mov	eax,edi
3633
        mov     eax,edi
3569
	sub	eax,[code_start]
3634
        sub     eax,[code_start]
3570
	mov	[ebx+4],eax
3635
        mov     [ebx+4],eax
3571
	pop	edx
3636
        pop     edx
3572
	and	eax,0FFFh
3637
        and     eax,0FFFh
3573
	add	edx,eax
3638
        add     edx,eax
Line 3586... Line 3651...
3586
	mov	[org_registers],0
3651
        mov     [org_registers],0
3587
	mov	[org_start],edi
3652
        mov     [org_start],edi
3588
	inc	[number_of_sections]
3653
        inc     [number_of_sections]
3589
	jmp	instruction_assembled
3654
        jmp     instruction_assembled
3590
      close_elf_exe_section:
3655
      close_elf_segment:
3591
	cmp	[number_of_sections],0
3656
        cmp     [number_of_sections],0
3592
	jne	finish_elf_exe_section
3657
        jne     finish_elf_segment
3593
	cmp	edi,[symbols_stream]
3658
        cmp     edi,[symbols_stream]
3594
	jne	first_elf_exe_section_ok
3659
        jne     first_elf_segment_ok
3595
	push	edi
3660
        push    edi
3596
	mov	edi,[code_start]
3661
        mov     edi,[code_start]
3597
	add	edi,34h
3662
        add     edi,34h
3598
	mov	ecx,20h shr 2
3663
        mov     ecx,20h shr 2
3599
	xor	eax,eax
3664
        xor     eax,eax
3600
	rep	stos dword [edi]
3665
        rep     stos dword [edi]
3601
	pop	edi
3666
        pop     edi
3602
	mov	eax,[image_base]
3667
        mov     eax,[image_base]
3603
	ret
3668
        ret
3604
      first_elf_exe_section_ok:
3669
      first_elf_segment_ok:
3605
	inc	[number_of_sections]
3670
        inc     [number_of_sections]
3606
      finish_elf_exe_section:
3671
      finish_elf_segment:
3607
	mov	ebx,[number_of_sections]
3672
        mov     ebx,[number_of_sections]
3608
	dec	ebx
3673
        dec     ebx
3609
	shl	ebx,5
3674
        shl     ebx,5
3610
	add	ebx,[code_start]
3675
        add     ebx,[code_start]
3611
	add	ebx,34h
3676
        add     ebx,34h
3612
	mov	eax,edi
3677
        mov     eax,edi
3613
	sub	eax,[code_start]
3678
        sub     eax,[code_start]
3614
	sub	eax,[ebx+4]
3679
        sub     eax,[ebx+4]
3615
	mov	edx,edi
3680
        mov     edx,edi
3616
	cmp	edi,[undefined_data_end]
3681
        cmp     edi,[undefined_data_end]
3617
	jne	elf_exe_section_size_ok
3682
        jne     elf_segment_size_ok
3618
	mov	edi,[undefined_data_start]
3683
        mov     edi,[undefined_data_start]
3619
      elf_exe_section_size_ok:
3684
      elf_segment_size_ok:
3620
	mov	[ebx+14h],eax
3685
        mov     [ebx+14h],eax
3621
	add	eax,edi
3686
        add     eax,edi
3622
	sub	eax,edx
3687
        sub     eax,edx
3623
	mov	[ebx+10h],eax
3688
        mov     [ebx+10h],eax
3624
	mov	eax,[ebx+8]
3689
        mov     eax,[ebx+8]
3625
	add	eax,[ebx+14h]
3690
        add     eax,[ebx+14h]
3626
	add	eax,0FFFh
3691
        add     eax,0FFFh
3627
	and	eax,not 0FFFh
3692
        and     eax,not 0FFFh
3628
	ret
3693
        ret
3629
      elf64_exe_section:
3694
      elf64_segment:
3630
	call	close_elf64_exe_section
3695
        call    close_elf64_segment
3631
	push	eax edx
3696
        push    eax edx
3632
	mov	ebx,[number_of_sections]
3697
        mov     ebx,[number_of_sections]
3633
	imul	ebx,38h
3698
        imul    ebx,38h
3634
	add	ebx,[code_start]
3699
        add     ebx,[code_start]
3635
	add	ebx,40h
3700
        add     ebx,40h
3636
	cmp	ebx,[symbols_stream]
3701
        cmp     ebx,[symbols_stream]
3637
	jb	new_elf64_exe_section
3702
        jb      new_elf64_segment
3638
	mov	ebx,[symbols_stream]
3703
        mov     ebx,[symbols_stream]
3639
	sub	ebx,38h
3704
        sub     ebx,38h
3640
	push	edi
3705
        push    edi
3641
	mov	edi,ebx
3706
        mov     edi,ebx
3642
	mov	ecx,38h shr 2
3707
        mov     ecx,38h shr 2
3643
	xor	eax,eax
3708
        xor     eax,eax
3644
	rep	stos dword [edi]
3709
        rep     stos dword [edi]
3645
	pop	edi
3710
        pop     edi
3646
	or	[next_pass_needed],-1
3711
        or      [next_pass_needed],-1
3647
      new_elf64_exe_section:
3712
      new_elf64_segment:
3648
	mov	byte [ebx],1
3713
        mov     byte [ebx],1
3649
	mov	word [ebx+30h],1000h
3714
        mov     word [ebx+30h],1000h
3650
      elf64_exe_section_flags:
3715
      elf64_segment_flags:
3651
	cmp	byte [esi],19h
3716
        cmp     byte [esi],19h
3652
	jne	elf64_exe_section_flags_ok
3717
        jne     elf64_segment_flags_ok
3653
	lods	word [esi]
3718
        lods    word [esi]
3654
	sub	ah,28
3719
        sub     ah,28
3655
	jbe	invalid_argument
3720
        jbe     invalid_argument
3656
	cmp	ah,1
3721
        cmp     ah,1
3657
	je	mark_elf64_exe_section_flag
3722
        je      mark_elf64_segment_flag
3658
	cmp	ah,3
3723
        cmp     ah,3
3659
	ja	invalid_argument
3724
        ja      invalid_argument
3660
	xor	ah,1
3725
        xor     ah,1
3661
	cmp	ah,2
3726
        cmp     ah,2
3662
	je	mark_elf64_exe_section_flag
3727
        je      mark_elf64_segment_flag
3663
	inc	ah
3728
        inc     ah
3664
      mark_elf64_exe_section_flag:
3729
      mark_elf64_segment_flag:
3665
	test	[ebx+4],ah
3730
        test    [ebx+4],ah
3666
	jnz	setting_already_specified
3731
        jnz     setting_already_specified
3667
	or	[ebx+4],ah
3732
        or      [ebx+4],ah
3668
	jmp	elf64_exe_section_flags
3733
        jmp     elf64_segment_flags
3669
      elf64_exe_section_flags_ok:
3734
      elf64_segment_flags_ok:
3670
	mov	ecx,edi
3735
        mov     ecx,edi
3671
	sub	ecx,[code_start]
3736
        sub     ecx,[code_start]
3672
	mov	[ebx+8],ecx
3737
        mov     [ebx+8],ecx
3673
	pop	edx eax
3738
        pop     edx eax
3674
	and	ecx,0FFFh
3739
        and     ecx,0FFFh
3675
	add	eax,ecx
3740
        add     eax,ecx
Line 3689... Line 3754...
3689
	mov	[org_registers],0
3754
        mov     [org_registers],0
3690
	mov	[org_start],edi
3755
        mov     [org_start],edi
3691
	inc	[number_of_sections]
3756
        inc     [number_of_sections]
3692
	jmp	instruction_assembled
3757
        jmp     instruction_assembled
3693
      close_elf64_exe_section:
3758
      close_elf64_segment:
3694
	cmp	[number_of_sections],0
3759
        cmp     [number_of_sections],0
3695
	jne	finish_elf64_exe_section
3760
        jne     finish_elf64_segment
3696
	cmp	edi,[symbols_stream]
3761
        cmp     edi,[symbols_stream]
3697
	jne	first_elf64_exe_section_ok
3762
        jne     first_elf64_segment_ok
3698
	push	edi
3763
        push    edi
3699
	mov	edi,[code_start]
3764
        mov     edi,[code_start]
3700
	add	edi,40h
3765
        add     edi,40h
3701
	mov	ecx,38h shr 2
3766
        mov     ecx,38h shr 2
3702
	xor	eax,eax
3767
        xor     eax,eax
3703
	rep	stos dword [edi]
3768
        rep     stos dword [edi]
3704
	pop	edi
3769
        pop     edi
3705
	mov	eax,[image_base]
3770
        mov     eax,[image_base]
3706
	mov	edx,[image_base_high]
3771
        mov     edx,[image_base_high]
3707
	ret
3772
        ret
3708
      first_elf64_exe_section_ok:
3773
      first_elf64_segment_ok:
3709
	inc	[number_of_sections]
3774
        inc     [number_of_sections]
3710
      finish_elf64_exe_section:
3775
      finish_elf64_segment:
3711
	mov	ebx,[number_of_sections]
3776
        mov     ebx,[number_of_sections]
3712
	dec	ebx
3777
        dec     ebx
3713
	imul	ebx,38h
3778
        imul    ebx,38h
3714
	add	ebx,[code_start]
3779
        add     ebx,[code_start]
3715
	add	ebx,40h
3780
        add     ebx,40h
3716
	mov	eax,edi
3781
        mov     eax,edi
3717
	sub	eax,[code_start]
3782
        sub     eax,[code_start]
3718
	sub	eax,[ebx+8]
3783
        sub     eax,[ebx+8]
3719
	mov	edx,edi
3784
        mov     edx,edi
3720
	cmp	edi,[undefined_data_end]
3785
        cmp     edi,[undefined_data_end]
3721
	jne	elf64_exe_section_size_ok
3786
        jne     elf64_segment_size_ok
3722
	mov	edi,[undefined_data_start]
3787
        mov     edi,[undefined_data_start]
3723
      elf64_exe_section_size_ok:
3788
      elf64_segment_size_ok:
3724
	mov	[ebx+28h],eax
3789
        mov     [ebx+28h],eax
3725
	add	eax,edi
3790
        add     eax,edi
3726
	sub	eax,edx
3791
        sub     eax,edx
3727
	mov	[ebx+20h],eax
3792
        mov     [ebx+20h],eax
3728
	mov	eax,[ebx+10h]
3793
        mov     eax,[ebx+10h]
3729
	mov	edx,[ebx+10h+4]
3794
        mov     edx,[ebx+10h+4]
Line 3740... Line 3805...
3740
	ret
3805
        ret
3741
close_elf_exe:
3806
close_elf_exe:
3742
	test	[format_flags],8
3807
        test    [format_flags],8
3743
	jnz	close_elf64_exe
3808
        jnz     close_elf64_exe
3744
	call	close_elf_exe_section
3809
        call    close_elf_segment
3745
	mov	edx,[code_start]
3810
        mov     edx,[code_start]
3746
	mov	eax,[number_of_sections]
3811
        mov     eax,[number_of_sections]
3747
	mov	byte [edx+1Ch],34h
3812
        mov     byte [edx+1Ch],34h
3748
	mov	[edx+2Ch],ax
3813
        mov     [edx+2Ch],ax
3749
	shl	eax,5
3814
        shl     eax,5
3750
	add	eax,edx
3815
        add     eax,edx
Line 3754... Line 3819...
3754
	or	[next_pass_needed],-1
3819
        or      [next_pass_needed],-1
3755
      elf_exe_ok:
3820
      elf_exe_ok:
3756
	ret
3821
        ret
3757
      close_elf64_exe:
3822
      close_elf64_exe:
3758
	call	close_elf64_exe_section
3823
        call    close_elf64_segment
3759
	mov	edx,[code_start]
3824
        mov     edx,[code_start]
3760
	mov	eax,[number_of_sections]
3825
        mov     eax,[number_of_sections]
3761
	mov	byte [edx+20h],40h
3826
        mov     byte [edx+20h],40h
3762
	mov	[edx+38h],ax
3827
        mov     [edx+38h],ax
3763
	imul	eax,38h
3828
        imul    eax,38h
3764
	add	eax,edx
3829
        add     eax,edx
Line 3767... Line 3832...
3767
	je	elf64_exe_ok
3832
        je      elf64_exe_ok
3768
	or	[next_pass_needed],-1
3833
        or      [next_pass_needed],-1
3769
      elf64_exe_ok:
3834
      elf64_exe_ok:
3770
	ret
3835
        ret
3771
 
3836
3772
formatter_symbols:
-
 
3773
 db 5,'align',1Ch,0
-
 
3774
 db 6,'binary',18h,10h
-
 
3775
 db 4,'code',19h,5
-
 
3776
 db 4,'coff',18h,40h
-
 
3777
 db 7,'console',1Bh,3
-
 
3778
 db 4,'data',19h,6
-
 
3779
 db 11,'discardable',19h,25
-
 
3780
 db 3,'dll',1Bh,80h
-
 
3781
 db 3,'elf',18h,50h
-
 
3782
 db 5,'elf64',18h,58h
-
 
3783
 db 10,'executable',19h,29
-
 
3784
 db 6,'export',1Ah,0
-
 
3785
 db 6,'fixups',1Ah,5
-
 
3786
 db 3,'gui',1Bh,2
-
 
3787
 db 6,'import',1Ah,1
-
 
3788
 db 2,'ms',17h,41h
-
 
3789
 db 4,'ms64',17h,49h
-
 
3790
 db 2,'mz',18h,20h
-
 
3791
 db 6,'native',1Bh,1
-
 
3792
 db 11,'notpageable',19h,27
-
 
3793
 db 2,'pe',18h,30h
-
 
3794
 db 4,'pe64',18h,38h
-
 
3795
 db 8,'readable',19h,30
-
 
3796
 db 8,'resource',1Ah,2
-
 
3797
 db 9,'shareable',19h,28
-
 
3798
 db 3,'wdm',1Bh,81h
-
 
3799
 db 8,'writable',19h,31
-
 
3800
 db 9,'writeable',19h,31
-
 
3801
 db 0
-
 
3802
-