Subversion Repositories Kolibri OS

Compare Revisions

Regard whitespace Rev 4039 → Rev 2665

/programs/develop/fasm/trunk/formats.inc
1,6 → 1,6
 
; flat assembler core
; Copyright (c) 1999-2013, Tomasz Grysztar.
; Copyright (c) 1999-2012, Tomasz Grysztar.
; All rights reserved.
 
formatter:
129,7 → 129,7
je labels_table_ok
mov ecx,[memory_end]
sub ecx,[labels_list]
mov edi,[tagged_blocks]
mov edi,[display_buffer]
sub edi,8
mov [edi],ecx
or dword [edi+4],-1
136,7 → 136,7
sub edi,ecx
cmp edi,[current_offset]
jbe out_of_memory
mov [tagged_blocks],edi
mov [display_buffer],edi
mov esi,[memory_end]
copy_labels:
sub esi,32
200,9 → 200,8
format_directive:
cmp edi,[code_start]
jne unexpected_instruction
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jnz unexpected_instruction
cmp [virtual_data],0
jne unexpected_instruction
cmp [output_format],0
jne unexpected_instruction
lods byte [esi]
281,6 → 280,8
je pe_heap
jmp illegal_instruction
segment_directive:
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,2
je mz_segment
288,6 → 289,8
je elf_segment
jmp illegal_instruction
section_directive:
cmp [virtual_data],0
jne illegal_instruction
mov al,[output_format]
cmp al,3
je pe_section
407,7 → 410,6
xor eax,eax
xor edx,edx
xor ebp,ebp
mov [address_sign],0
mov ch,2
test [format_flags],8
jz make_free_label
416,9 → 418,8
mark_relocation:
cmp [value_type],0
je relocation_ok
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jnz relocation_ok
cmp [virtual_data],0
jne relocation_ok
cmp [output_format],2
je mark_mz_relocation
cmp [output_format],3
492,11 → 493,13
mov edx,edi
xor eax,eax
rep stos byte [edi]
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_origin_sign],al
mov [org_registers],eax
mov [org_start],edi
mov eax,edx
call undefined_data
push ebx
call create_addressing_space
pop ebx
mov eax,edi
sub eax,[code_start]
shr eax,4
512,10 → 515,9
mov [code_type],al
mov eax,edx
mov ch,1
mov [address_sign],0
mov [label_size],0
xor edx,edx
xor ebp,ebp
mov [label_size],0
mov [address_symbol],edx
jmp make_free_label
mz_entry:
722,7 → 724,7
and ecx,not 11b
add ecx,(40h-1Ch) shr 2
lea eax,[edi+ecx*4]
cmp edi,[tagged_blocks]
cmp edi,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
760,7 → 762,7
inc ecx
shl ecx,1
lea eax,[edi+ecx*4]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
824,7 → 826,7
mov [esi+16h],ax
mov word [esi+14h],100h
mov byte [esi+18h],40h
mov eax,[tagged_blocks]
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
1051,7 → 1053,7
shl ebx,cl
sub ebx,ebp
mov ecx,ebx
mov eax,[tagged_blocks]
mov eax,[display_buffer]
sub eax,ecx
cmp edi,eax
jae out_of_memory
1115,14 → 1117,12
jc pe_labels_type_ok
xor bh,bh
pe_labels_type_ok:
push eax ebx
call init_addressing_space
mov ebp,ebx
pop ebx eax
mov [ds:ebp],eax
mov [ds:ebp+4],ecx
mov [ds:ebp+8],bx
mov [ds:ebp+18h],edi
mov [labels_type],bh
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
mov [org_origin_sign],bl
and [org_registers],0
mov [org_start],edi
bt [format_flags],8
jnc dll_flag_ok
or byte [edx+16h+1],20h
1142,10 → 1142,6
jmp format_defined
pe_section:
call close_pe_section
push eax ebx
call create_addressing_space
mov ebp,ebx
pop ebx eax
bts [format_flags],5
lea ecx,[ebx+28h]
add edx,[edx+54h]
1183,14 → 1179,15
mov edx,[code_start]
mov eax,edi
xor ecx,ecx
mov [org_origin_sign],0
sub eax,[ebx+0Ch]
sbb ecx,0
sbb byte [ds:ebp+8],0
mov byte [ds:ebp+9],2
sbb [org_origin_sign],0
mov [labels_type],2
mov [code_type],32
test [format_flags],8
jz pe_section_code_type_ok
mov byte [ds:ebp+9],4
mov [labels_type],4
mov [code_type],64
pe_section_code_type_ok:
test [format_flags],4
1197,22 → 1194,23
jnz peplus_section_org
sub eax,[edx+34h]
sbb ecx,0
sbb byte [ds:ebp+8],0
sbb [org_origin_sign],0
bt [resolver_flags],0
jc pe_section_org_ok
mov byte [ds:ebp+9],0
mov [labels_type],0
jmp pe_section_org_ok
peplus_section_org:
sub eax,[edx+30h]
sbb ecx,[edx+34h]
sbb byte [ds:ebp+8],0
sbb [org_origin_sign],0
bt [resolver_flags],0
jc pe_section_org_ok
mov byte [ds:ebp+9],0
mov [labels_type],0
pe_section_org_ok:
mov [ds:ebp],eax
mov [ds:ebp+4],ecx
mov [ds:ebp+18h],edi
mov dword [org_origin],eax
mov dword [org_origin+4],ecx
and [org_registers],0
mov [org_start],edi
get_section_flags:
lods byte [esi]
cmp al,1Ah
1543,7 → 1541,7
cmp edx,[ecx+74h]
ja value_out_of_range
jb instruction_assembled
cmp eax,[ecx+70h]
cmp eax,[edx+70h]
ja value_out_of_range
jmp instruction_assembled
mark_pe_relocation:
1666,7 → 1664,7
and [resource_size],0
reserve_space_for_resource:
add edi,[resource_size]
cmp edi,[tagged_blocks]
cmp edi,[display_buffer]
ja out_of_memory
jmp resource_done
resource_from_file:
1752,7 → 1750,7
mov [esi],eax
mov [resource_data],edi
lea eax,[edi+16]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
1814,7 → 1812,7
mov eax,[resource_data]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
1851,7 → 1849,7
mov eax,[resource_data]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
1872,7 → 1870,7
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
1951,7 → 1949,7
mov eax,[esp]
inc word [eax+12]
lea eax,[edi+8]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
1994,7 → 1992,7
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
2033,7 → 2031,7
bts edx,31
mov [esi+4],edx
lea eax,[edi+16]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
stos dword [edi]
2083,7 → 2081,7
mov eax,[esp]
inc word [eax+14]
lea eax,[edi+8]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,ebx
stos dword [edi]
2124,7 → 2122,7
stos word [edi]
copy_string_data:
lea eax,[edi+2]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov ax,[edx]
or ax,ax
2162,7 → 2160,7
sub esi,[resource_data]
xchg esi,[ebx+4]
lea eax,[edi+16]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
mov eax,esi
stos dword [edi]
2192,7 → 2190,7
mov edx,edi
mov ecx,[esi+4]
add edi,ecx
cmp edi,[tagged_blocks]
cmp edi,[display_buffer]
ja out_of_memory
call read
mov eax,edi
2321,16 → 2319,28
mov [current_section],ebx
xor eax,eax
mov [number_of_sections],eax
mov edx,ebx
call init_addressing_space
mov [ebx+14h],edx
mov byte [ebx+9],2
call setup_coff_section_org
mov [code_type],32
test [format_flags],8
jz format_defined
mov byte [ebx+9],4
mov [code_type],64
jmp format_defined
setup_coff_section_org:
xor eax,eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_origin_sign],al
mov [org_registers],eax
mov [org_start],edi
mov [org_symbol],ebx
test [format_flags],8
jnz coff_64bit_labels
mov [labels_type],2
ret
coff_64bit_labels:
mov [labels_type],4
ret
 
coff_section:
call close_coff_section
mov ebx,[free_additional_memory]
2345,15 → 2355,7
mov [ebx+8],edi
mov [ebx+10h],eax
mov [ebx+14h],eax
mov edx,ebx
call create_addressing_space
xchg edx,ebx
mov [edx+14h],ebx
mov byte [edx+9],2
test [format_flags],8
jz coff_labels_type_ok
mov byte [edx+9],4
coff_labels_type_ok:
call setup_coff_section_org
lods word [esi]
cmp ax,'('
jne invalid_argument
2440,10 → 2442,8
test [format_flags],8
jnz coff_64bit_relocation
mov al,6
cmp [value_type],2
je coff_relocation
cmp [value_type],5
jne invalid_use_of_symbol
jne coff_relocation
inc al
jmp coff_relocation
coff_64bit_relocation:
2451,10 → 2451,8
cmp [value_type],4
je coff_relocation
mov al,2
cmp [value_type],2
je coff_relocation
cmp [value_type],5
jne invalid_use_of_symbol
jne coff_relocation
inc al
jmp coff_relocation
coff_relocation_relative:
2467,17 → 2465,16
sub eax,ebx
add eax,4
relative_ok:
mov ebx,[addressing_space]
push eax
mov al,20
test [format_flags],8
jnz relative_coff_64bit_relocation
cmp byte [ebx+9],2
cmp [labels_type],2
jne invalid_use_of_symbol
jmp coff_relocation
relative_coff_64bit_relocation:
mov al,4
cmp byte [ebx+9],4
cmp [labels_type],4
jne invalid_use_of_symbol
coff_relocation:
mov ebx,[free_additional_memory]
2689,7 → 2686,7
jmp find_relocations
add_relocation:
lea eax,[ebx+0Ah]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
ja out_of_memory
mov eax,[esi+4]
mov [ebx],eax
2908,7 → 2905,7
mov edx,edi
mov ecx,34h shr 2
lea eax,[edi+ecx*4]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
2943,14 → 2940,9
mov [ebx+14h],eax
mov al,4
mov [ebx+10h],eax
mov edx,ebx
call init_addressing_space
xchg edx,ebx
mov [edx+14h],ebx
mov byte [edx+9],2
call setup_coff_section_org
test [format_flags],8
jz format_defined
mov byte [edx+9],4
mov byte [ebx+10h],8
jmp format_defined
format_elf64:
2957,7 → 2949,7
mov edx,edi
mov ecx,40h shr 2
lea eax,[edi+ecx*4]
cmp eax,[tagged_blocks]
cmp eax,[display_buffer]
jae out_of_memory
xor eax,eax
rep stos dword [edi]
2992,15 → 2984,7
mov [ebx+10h],eax
mov al,10b
mov [ebx+14h],eax
mov edx,ebx
call create_addressing_space
xchg edx,ebx
mov [edx+14h],ebx
mov byte [edx+9],2
test [format_flags],8
jz elf_labels_type_ok
mov byte [edx+9],4
elf_labels_type_ok:
call setup_coff_section_org
lods word [esi]
cmp ax,'('
jne invalid_argument
3054,13 → 3038,11
mov byte [ebx+10h],8
jmp instruction_assembled
mark_elf_relocation:
push ebx
mov ebx,[addressing_space]
cmp [value_type],3
je elf_relocation_relative
cmp [value_type],7
je elf_relocation_relative
push eax
push ebx eax
cmp [value_type],5
je elf_gotoff_relocation
ja invalid_use_of_symbol
3077,8 → 3059,9
mov al,9 ; R_386_GOTOFF
jmp coff_relocation
elf_relocation_relative:
cmp byte [ebx+9],0
cmp [labels_type],0
je invalid_use_of_symbol
push ebx
mov ebx,[current_section]
mov ebx,[ebx+8]
sub ebx,edi
3707,13 → 3690,11
add eax,edi
adc ebp,0
adc cl,0
elf_exe_addressing_setup:
push eax
call init_addressing_space
pop eax
mov [ebx],eax
mov [ebx+4],edx
mov [ebx+8],cl
mov dword [org_origin],eax
mov dword [org_origin+4],edx
mov [org_origin_sign],cl
and [org_registers],0
mov [org_start],edi
mov [symbols_stream],edi
jmp format_defined
format_elf64_exe:
3787,7 → 3768,13
add eax,edi
adc edx,0
adc cl,0
jmp elf_exe_addressing_setup
mov dword [org_origin],eax
mov dword [org_origin+4],edx
mov [org_origin_sign],cl
and [org_registers],0
mov [org_start],edi
mov [symbols_stream],edi
jmp format_defined
elf_entry:
lods byte [esi]
cmp al,'('
3817,8 → 3804,6
jnz elf64_segment
call close_elf_segment
push eax
call create_addressing_space
mov ebp,ebx
mov ebx,[number_of_sections]
shl ebx,5
add ebx,[code_start]
3898,10 → 3883,11
add eax,edi
adc edx,0
adc cl,0
elf_segment_addressing_setup:
mov [ds:ebp],eax
mov [ds:ebp+4],edx
mov [ds:ebp+8],cl
mov dword [org_origin],eax
mov dword [org_origin+4],edx
mov [org_origin_sign],cl
and [org_registers],0
mov [org_start],edi
inc [number_of_sections]
jmp instruction_assembled
close_elf_segment:
3949,8 → 3935,6
elf64_segment:
call close_elf64_segment
push eax edx
call create_addressing_space
mov ebp,ebx
mov ebx,[number_of_sections]
imul ebx,38h
add ebx,[code_start]
4031,7 → 4015,13
add eax,edi
adc edx,0
adc cl,0
jmp elf_segment_addressing_setup
mov dword [org_origin],eax
mov dword [org_origin+4],edx
mov [org_origin_sign],cl
and [org_registers],0
mov [org_start],edi
inc [number_of_sections]
jmp instruction_assembled
close_elf64_segment:
cmp [number_of_sections],0
jne finish_elf64_segment