fasm 1.71.13, proc32.inc and struct.inc from fasm 1.71.13

git-svn-id: svn://kolibrios.org@4039 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
heavyiron 2013-10-16 08:12:09 +00:00
parent b7c730f2b9
commit 53cca077c5
16 changed files with 10004 additions and 9659 deletions

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
assembler:
@ -12,7 +12,7 @@ assembler:
mov [actual_fixups_size],eax
assembler_loop:
mov eax,[labels_list]
mov [display_buffer],eax
mov [tagged_blocks],eax
mov eax,[additional_memory]
mov [free_additional_memory],eax
mov eax,[additional_memory_end]
@ -22,11 +22,7 @@ assembler:
xor eax,eax
mov dword [adjustment],eax
mov dword [adjustment+4],eax
mov dword [org_origin],edi
mov dword [org_origin+4],eax
mov [org_start],edi
mov [org_registers],eax
mov [org_symbol],eax
mov [addressing_space],eax
mov [error_line],eax
mov [counter],eax
mov [format_flags],eax
@ -35,18 +31,16 @@ assembler:
mov [file_extension],eax
mov [next_pass_needed],al
mov [output_format],al
mov [org_origin_sign],al
mov [adjustment_sign],al
mov [labels_type],al
mov [virtual_data],al
mov [code_type],16
call init_addressing_space
pass_loop:
call assemble_line
jnc pass_loop
mov eax,[additional_memory_end]
cmp eax,[structures_buffer]
je pass_done
sub eax,20h
sub eax,18h
mov eax,[eax+4]
mov [current_line],eax
jmp missing_end_directive
@ -141,8 +135,36 @@ assembler:
assemble_ok:
ret
create_addressing_space:
mov ebx,[addressing_space]
test ebx,ebx
jz init_addressing_space
test byte [ebx+0Ah],1
jnz illegal_instruction
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
init_addressing_space:
mov ebx,[tagged_blocks]
mov dword [ebx-4],10h
mov dword [ebx-8],20h
sub ebx,8+20h
cmp ebx,edi
jbe out_of_memory
mov [tagged_blocks],ebx
mov [addressing_space],ebx
xor eax,eax
mov [ebx],edi
mov [ebx+4],eax
mov [ebx+8],eax
mov [ebx+10h],eax
mov [ebx+14h],eax
mov [ebx+18h],edi
mov [ebx+1Ch],eax
ret
assemble_line:
mov eax,[display_buffer]
mov eax,[tagged_blocks]
sub eax,100h
cmp edi,eax
ja out_of_memory
@ -153,6 +175,8 @@ assemble_line:
cmp al,3
jb define_label
je define_constant
cmp al,4
je label_addressing_space
cmp al,0Fh
je new_line
cmp al,13h
@ -164,7 +188,7 @@ assemble_line:
code_type_setting:
lods byte [esi]
mov [code_type],al
jmp line_assembled
jmp instruction_assembled
new_line:
lods dword [esi]
mov [current_line],eax
@ -173,30 +197,19 @@ assemble_line:
je continue_line
cmp [next_pass_needed],0
jne continue_line
mov ebx,[display_buffer]
mov ebx,[tagged_blocks]
mov dword [ebx-4],1
mov dword [ebx-8],1Ch
sub ebx,8+1Ch
mov dword [ebx-8],14h
sub ebx,8+14h
cmp ebx,edi
jbe out_of_memory
mov [display_buffer],ebx
mov [tagged_blocks],ebx
mov [ebx],eax
mov [ebx+4],edi
mov eax,dword [org_origin]
mov edx,dword [org_origin+4]
mov ecx,[org_registers]
mov eax,[addressing_space]
mov [ebx+8],eax
mov [ebx+8+4],edx
mov [ebx+10h],ecx
mov edx,[org_symbol]
; mov al,[virtual_data]
; mov ah,[org_origin_sign]
; shl eax,16
; mov al,[labels_type]
; mov ah,[code_type]
mov eax,dword [labels_type]
mov [ebx+14h],edx
mov [ebx+18h],eax
mov al,[code_type]
mov [ebx+10h],al
continue_line:
cmp byte [esi],0Fh
je line_assembled
@ -215,15 +228,16 @@ assemble_line:
mov eax,edi
xor edx,edx
xor cl,cl
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
sbb cl,[org_origin_sign]
mov ebp,[addressing_space]
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb cl,[ds:ebp+8]
jp label_value_ok
call recoverable_overflow
label_value_ok:
mov [address_sign],cl
cmp [virtual_data],0
jne make_virtual_label
test byte [ds:ebp+0Ah],1
jnz make_virtual_label
or byte [ebx+9],1
xchg eax,[ebx]
xchg edx,[ebx+4]
@ -251,10 +265,11 @@ assemble_line:
setne al
or ah,al
finish_label:
mov ch,[labels_type]
mov ebp,[addressing_space]
mov ch,[ds:ebp+9]
mov cl,[label_size]
mov ebp,[org_registers]
mov edx,[org_symbol]
mov edx,[ds:ebp+14h]
mov ebp,[ds:ebp+10h]
finish_label_symbol:
mov al,[address_sign]
xor al,[ebx+9]
@ -289,6 +304,8 @@ assemble_line:
jz new_label
cmp cx,[ebx+16]
je symbol_already_defined
btr dword [ebx+8],10
jc requalified_label
inc cx
sub cx,[ebx+16]
setnz al
@ -299,6 +316,7 @@ assemble_line:
mov cx,[current_pass]
cmp cx,[ebx+18]
jne label_made
requalified_label:
or [next_pass_needed],-1
label_made:
ret
@ -320,7 +338,7 @@ assemble_line:
mov cx,[current_pass]
cmp cx,[eax+16]
je get_constant_value
and dl,not 1
or dl,4
mov [eax+8],dl
get_constant_value:
push eax
@ -331,10 +349,11 @@ assemble_line:
pop ebx
mov ch,bl
pop ebx
pop dword [ebx+8]
cmp ebx,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
pop ecx
test cl,4
jnz constant_referencing_mode_ok
and byte [ebx+8],not 4
constant_referencing_mode_ok:
xor cl,cl
mov ch,[value_type]
cmp ch,3
@ -385,8 +404,11 @@ assemble_line:
test byte [ebx+8],2
jz symbol_already_defined
or byte [ebx+8],4
and byte [ebx+9],not 4
jmp instruction_assembled
redeclare_constant:
btr dword [ebx+8],10
jc requalified_constant
inc cx
sub cx,[ebx+16]
setnz al
@ -399,11 +421,37 @@ assemble_line:
mov cx,[current_pass]
cmp cx,[ebx+18]
jne instruction_assembled
requalified_constant:
or [next_pass_needed],-1
jmp instruction_assembled
new_constant:
or byte [ebx+8],1+2
jmp instruction_assembled
label_addressing_space:
lods dword [esi]
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov cx,[current_pass]
test byte [eax+8],1
jz make_addressing_space_label
cmp cx,[eax+16]
je symbol_already_defined
test byte [eax+9],4
jnz make_addressing_space_label
or [next_pass_needed],-1
make_addressing_space_label:
mov dx,[eax+8]
and dx,not (2 or 100h)
or dx,1 or 4 or 400h
mov [eax+8],dx
mov [eax+16],cx
mov edx,[current_line]
mov [eax+28],edx
mov ebx,[addressing_space]
mov [eax],ebx
or byte [ebx+0Ah],2
jmp continue_line
assemble_instruction:
; mov [operand_size],0
; mov [size_override],0
@ -446,22 +494,31 @@ org_directive:
mov cl,[value_type]
test cl,1
jnz invalid_use_of_symbol
mov [labels_type],cl
mov dword [org_origin],edi
xor ecx,ecx
mov dword [org_origin+4],ecx
mov [org_origin_sign],cl
mov [org_registers],ecx
push eax
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
test byte [ebx+0Ah],1
jnz in_virtual
call init_addressing_space
jmp org_space_ok
in_virtual:
call close_virtual_addressing_space
call init_addressing_space
or byte [ebx+0Ah],1
org_space_ok:
pop eax
mov [ebx+9],cl
mov cl,[value_sign]
sub dword [org_origin],eax
sbb dword [org_origin+4],edx
sbb [org_origin_sign],cl
sub [ebx],eax
sbb [ebx+4],edx
sbb byte [ebx+8],cl
jp org_value_ok
call recoverable_overflow
org_value_ok:
mov [org_start],edi
mov edx,[symbol_identifier]
mov [org_symbol],edx
mov [ebx+14h],edx
cmp [output_format],1
ja instruction_assembled
cmp edi,[code_start]
@ -502,9 +559,8 @@ label_directive:
lods byte [esi]
cmp al,'('
jne invalid_argument
push dword [ebx+8]
push ebx ecx
and byte [ebx+8],not 1
or byte [ebx+8],4
cmp byte [esi],'.'
je invalid_value
call get_address_value
@ -516,14 +572,10 @@ label_directive:
xchg bl,bh
mov bp,bx
pop ecx ebx
pop dword [ebx+8]
and byte [ebx+8],not 4
mov ch,[value_type]
or ch,ch
jz make_free_label
cmp ch,4
je make_free_label
cmp ch,2
jne invalid_use_of_symbol
test ch,1
jnz invalid_use_of_symbol
make_free_label:
and byte [ebx+9],not 1
cmp eax,[ebx]
@ -558,45 +610,102 @@ load_directive:
mov [operand_size],al
and dword [value],0
and dword [value+4],0
lods word [esi]
cmp ax,82h+'(' shl 8
lods byte [esi]
cmp al,82h
jne invalid_argument
load_from_code:
cmp byte [esi],'.'
je invalid_value
or [size_override],-1
call get_address_value
call calculate_relative_offset
call get_data_point
jc value_loaded
push esi edi
cmp [next_pass_needed],0
jne load_address_type_ok
cmp [value_type],0
jne invalid_use_of_symbol
load_address_type_ok:
cmp edx,-1
jne bad_load_address
neg eax
mov esi,edi
sub esi,eax
jc bad_load_address
cmp esi,[org_start]
jb bad_load_address
mov esi,ebx
mov edi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_load_address
rep movs byte [edi],[esi]
jmp value_loaded
bad_load_address:
call recoverable_overflow
value_loaded:
pop edi esi
value_loaded:
mov [value_sign],0
mov eax,dword [value]
mov edx,dword [value+4]
pop ebx
xor cx,cx
jmp make_constant
get_data_point:
mov ebx,[addressing_space]
mov ecx,edi
sub ecx,[ebx+18h]
mov [ebx+1Ch],ecx
lods byte [esi]
cmp al,'('
jne invalid_argument
cmp byte [esi],11h
jne get_data_address
cmp word [esi+1+4],'):'
jne get_data_address
inc esi
lods dword [esi]
add esi,2
cmp byte [esi],'('
jne invalid_argument
inc esi
cmp eax,0Fh
jbe reserved_word_used_as_symbol
mov edx,undefined_symbol
test byte [eax+8],1
jz addressing_space_unavailable
mov edx,symbol_out_of_scope
mov cx,[eax+16]
cmp cx,[current_pass]
jne addressing_space_unavailable
test byte [eax+9],4
jz invalid_use_of_symbol
mov ebx,eax
mov ax,[current_pass]
mov [ebx+18],ax
or byte [ebx+8],8
cmp [symbols_file],0
je get_addressing_space
cmp [next_pass_needed],0
jne get_addressing_space
call store_label_reference
get_addressing_space:
mov ebx,[ebx]
get_data_address:
push ebx
cmp byte [esi],'.'
je invalid_value
or [size_override],-1
call get_address_value
pop ebp
call calculate_relative_offset
cmp [next_pass_needed],0
jne data_address_type_ok
cmp [value_type],0
jne invalid_use_of_symbol
data_address_type_ok:
mov ebx,edi
xor ecx,ecx
add ebx,eax
adc edx,ecx
mov eax,ebx
sub eax,[ds:ebp+18h]
sbb edx,ecx
jnz bad_data_address
mov cl,[operand_size]
add eax,ecx
cmp eax,[ds:ebp+1Ch]
ja bad_data_address
clc
ret
addressing_space_unavailable:
cmp [error_line],0
jne get_data_address
push [current_line]
pop [error_line]
mov [error],edx
mov [error_info],eax
jmp get_data_address
bad_data_address:
call recoverable_overflow
stc
ret
store_directive:
cmp byte [esi],11h
je sized_store
@ -616,44 +725,23 @@ store_directive:
jne invalid_use_of_symbol
mov dword [value],eax
mov dword [value+4],edx
lods word [esi]
cmp ax,80h+'(' shl 8
lods byte [esi]
cmp al,80h
jne invalid_argument
cmp byte [esi],'.'
je invalid_value
or [size_override],-1
call get_address_value
call calculate_relative_offset
call get_data_point
jc instruction_assembled
push esi edi
cmp [next_pass_needed],0
jne store_address_type_ok
cmp [value_type],0
jne invalid_use_of_symbol
store_address_type_ok:
cmp edx,-1
jne bad_store_address
neg eax
sub edi,eax
jc bad_store_address
cmp edi,[org_start]
jb bad_store_address
mov esi,value
movzx ecx,[operand_size]
cmp ecx,eax
ja bad_store_address
mov edi,ebx
rep movs byte [edi],[esi]
mov eax,edi
pop edi esi
cmp edi,[undefined_data_end]
jne instruction_assembled
cmp ebx,[undefined_data_end]
jae instruction_assembled
cmp eax,[undefined_data_start]
jbe instruction_assembled
mov [undefined_data_start],eax
jmp instruction_assembled
bad_store_address:
pop edi esi
call recoverable_overflow
jmp instruction_assembled
display_directive:
lods byte [esi]
@ -665,12 +753,12 @@ display_directive:
lods dword [esi]
mov ecx,eax
push edi
mov edi,[display_buffer]
mov edi,[tagged_blocks]
sub edi,8
sub edi,eax
cmp edi,[esp]
jbe out_of_memory
mov [display_buffer],edi
mov [tagged_blocks],edi
rep movs byte [edi],[esi]
stos dword [edi]
xor eax,eax
@ -681,9 +769,9 @@ display_directive:
display_byte:
call get_byte_value
push edi
mov edi,[display_buffer]
mov edi,[tagged_blocks]
sub edi,8+1
mov [display_buffer],edi
mov [tagged_blocks],edi
stos byte [edi]
mov eax,1
stos dword [edi]
@ -691,7 +779,7 @@ display_directive:
stos dword [edi]
pop edi
display_next:
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
ja out_of_memory
lods byte [esi]
cmp al,','
@ -699,7 +787,7 @@ display_directive:
dec esi
jmp instruction_assembled
show_display_buffer:
mov eax,[display_buffer]
mov eax,[tagged_blocks]
or eax,eax
jz display_done
mov esi,[labels_list]
@ -711,12 +799,12 @@ show_display_buffer:
mov ecx,[esi]
sub esi,ecx
test eax,eax
jnz skip_internal_message
jnz skip_block
push esi
call display_block
pop esi
skip_internal_message:
cmp esi,[display_buffer]
skip_block:
cmp esi,[tagged_blocks]
jne display_messages
display_done:
ret
@ -779,28 +867,41 @@ virtual_directive:
jmp set_virtual
virtual_at_current:
dec esi
mov al,[labels_type]
mov ebp,[addressing_space]
mov al,[ds:ebp+9]
mov [value_type],al
mov ebp,[org_symbol]
mov eax,edi
xor edx,edx
xor cl,cl
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
sbb cl,[org_origin_sign]
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb cl,[ds:ebp+8]
mov [address_sign],cl
mov bx,word [org_registers]
mov cx,word [org_registers+2]
mov bx,[ds:ebp+10h]
mov cx,[ds:ebp+10h+2]
xchg bh,bl
xchg ch,cl
mov ebp,[ds:ebp+14h]
set_virtual:
push [org_registers]
mov byte [org_registers],bh
mov byte [org_registers+1],bl
mov byte [org_registers+2],ch
mov byte [org_registers+3],cl
xchg bl,bh
xchg cl,ch
shl ecx,16
mov cx,bx
push ecx eax
call allocate_structure_data
mov word [ebx],virtual_directive-instruction_handler
mov ecx,[addressing_space]
mov [ebx+12],ecx
mov [ebx+8],edi
mov ecx,[current_line]
mov [ebx+4],ecx
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
call init_addressing_space
or byte [ebx+0Ah],1
pop eax
mov cl,[address_sign]
not eax
not edx
@ -811,37 +912,19 @@ virtual_directive:
add eax,edi
adc edx,0
adc cl,0
xchg dword [org_origin],eax
xchg dword [org_origin+4],edx
xchg [org_origin_sign],cl
mov [ebx+10h],eax
mov [ebx+14h],edx
pop eax
mov [ebx+18h],eax
mov al,[virtual_data]
and al,0Fh
shl cl,4
or al,cl
mov [ebx+2],al
mov al,[labels_type]
mov [ebx+3],al
mov eax,edi
xchg eax,[org_start]
mov [ebx+0Ch],eax
xchg ebp,[org_symbol]
mov [ebx+1Ch],ebp
mov [ebx+8],edi
mov eax,[current_line]
mov [ebx+4],eax
or [virtual_data],-1
mov [ebx],eax
mov [ebx+4],edx
mov [ebx+8],cl
pop dword [ebx+10h]
mov [ebx+14h],ebp
mov al,[value_type]
test al,1
jnz invalid_use_of_symbol
mov [labels_type],al
mov [ebx+9],al
jmp instruction_assembled
allocate_structure_data:
mov ebx,[structures_buffer]
sub ebx,20h
sub ebx,18h
cmp ebx,[free_additional_memory]
jb out_of_memory
mov [structures_buffer],ebx
@ -853,7 +936,7 @@ virtual_directive:
je no_such_structure
cmp ax,[ebx]
je structure_data_found
add ebx,20h
add ebx,18h
jmp scan_structures
structure_data_found:
ret
@ -863,27 +946,11 @@ virtual_directive:
end_virtual:
call find_structure_data
jc unexpected_instruction
mov al,[ebx+2]
mov ah,al
shr ah,4
and al,1
neg al
and ah,1
neg ah
mov [virtual_data],al
mov [org_origin_sign],ah
mov al,[ebx+3]
mov [labels_type],al
mov eax,[ebx+10h]
mov dword [org_origin],eax
mov eax,[ebx+14h]
mov dword [org_origin+4],eax
mov eax,[ebx+18h]
mov [org_registers],eax
mov eax,[ebx+0Ch]
mov [org_start],eax
mov eax,[ebx+1Ch]
mov [org_symbol],eax
push ebx
call close_virtual_addressing_space
pop ebx
mov eax,[ebx+12]
mov [addressing_space],eax
mov edi,[ebx+8]
remove_structure_data:
push esi edi
@ -891,13 +958,55 @@ virtual_directive:
sub ecx,[structures_buffer]
shr ecx,2
lea esi,[ebx-4]
lea edi,[esi+20h]
lea edi,[esi+18h]
std
rep movs dword [edi],[esi]
cld
add [structures_buffer],20h
add [structures_buffer],18h
pop edi esi
ret
close_virtual_addressing_space:
mov ebx,[addressing_space]
mov eax,edi
sub eax,[ebx+18h]
mov [ebx+1Ch],eax
test byte [ebx+0Ah],2
jz addressing_space_closed
push esi edi ecx edx
mov ecx,eax
mov eax,[tagged_blocks]
mov dword [eax-4],11h
mov dword [eax-8],ecx
sub eax,8
sub eax,ecx
mov [tagged_blocks],eax
lea edi,[eax+ecx-1]
xchg eax,[ebx+18h]
lea esi,[eax+ecx-1]
mov eax,edi
sub eax,esi
std
shr ecx,1
jnc virtual_byte_ok
movs byte [edi],[esi]
virtual_byte_ok:
dec esi
dec edi
shr ecx,1
jnc virtual_word_ok
movs word [edi],[esi]
virtual_word_ok:
sub esi,2
sub edi,2
rep movs dword [edi],[esi]
cld
xor edx,edx
add [ebx],eax
adc dword [ebx+4],edx
adc byte [ebx+8],dl
pop edx ecx edi esi
addressing_space_closed:
ret
repeat_directive:
cmp [prefixed_instruction],0
jne unexpected_instruction
@ -1193,7 +1302,7 @@ break_directive:
je break_while
cmp ax,if_directive-instruction_handler
je break_if
add ebx,20h
add ebx,18h
jmp find_breakable_structure
break_if:
push [current_line]
@ -1235,14 +1344,15 @@ data_bytes:
lods dword [esi]
mov ecx,eax
lea eax,[edi+ecx]
cmp eax,[display_buffer]
cmp eax,[tagged_blocks]
ja out_of_memory
rep movs byte [edi],[esi]
inc esi
ret
undefined_data:
cmp [virtual_data],0
je mark_undefined_data
mov ebp,[addressing_space]
test byte [ds:ebp+0Ah],1
jz mark_undefined_data
ret
mark_undefined_data:
cmp eax,[undefined_data_end]
@ -1252,7 +1362,7 @@ data_bytes:
mov [undefined_data_end],edi
ret
define_data:
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
cmp byte [esi],'('
jne simple_data_value
@ -1273,7 +1383,7 @@ data_bytes:
duplicate_data:
push eax esi
duplicated_values:
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
call near dword [esp+8]
lods byte [esi]
@ -1287,7 +1397,7 @@ data_bytes:
mov esi,ebx
jmp duplicate_data
duplicate_single_data_value:
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
push eax esi
call near dword [esp+8]
@ -1311,7 +1421,7 @@ data_bytes:
call skip_symbol
jmp data_defined
simple_data_value:
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
call near dword [esp]
data_defined:
@ -1354,7 +1464,7 @@ data_words:
mov ecx,eax
jecxz word_string_ok
lea eax,[edi+ecx*2]
cmp eax,[display_buffer]
cmp eax,[tagged_blocks]
ja out_of_memory
xor ah,ah
copy_word_string:
@ -1624,7 +1734,7 @@ data_file:
mov edx,edi
add edi,ecx
jc out_of_memory
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
ja out_of_memory
call read
jc error_reading_file
@ -1704,7 +1814,7 @@ reserve_bytes:
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1739,7 +1849,7 @@ reserve_words:
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1769,7 +1879,7 @@ reserve_dwords:
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1796,7 +1906,7 @@ reserve_pwords:
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1820,7 +1930,7 @@ reserve_qwords:
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1843,7 +1953,7 @@ reserve_twords:
jc out_of_memory
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0
@ -1866,14 +1976,15 @@ align_directive:
cmp eax,1
je instruction_assembled
mov ecx,edi
sub ecx,dword [org_origin]
cmp [org_registers],0
mov ebp,[addressing_space]
sub ecx,[ds:ebp]
cmp dword [ds:ebp+10h],0
jne section_not_aligned_enough
cmp [labels_type],0
cmp byte [ds:ebp+9],0
je make_alignment
cmp [output_format],3
je pe_alignment
mov ebx,[org_symbol]
mov ebx,[ds:ebp+14h]
cmp byte [ebx],0
jne section_not_aligned_enough
cmp eax,[ebx+10h]
@ -1892,7 +2003,7 @@ align_directive:
mov edx,ecx
add edx,edi
jc out_of_memory
cmp edx,[display_buffer]
cmp edx,[tagged_blocks]
ja out_of_memory
push edi
cmp [next_pass_needed],0

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
avx_single_source_pd_instruction:

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
out_of_memory:

View File

@ -1,6 +1,7 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
calculate_expression:
@ -169,6 +170,8 @@ calculate_expression:
stos dword [edi]
mov [edi-8+13],cl
got_label:
test byte [ebx+9],4
jnz invalid_use_of_symbol
cmp [symbols_file],0
je label_reference_ok
cmp [next_pass_needed],0
@ -214,25 +217,27 @@ calculate_expression:
make_current_offset_label:
xor edx,edx
xor ch,ch
sub eax,dword [org_origin]
sbb edx,dword [org_origin+4]
sbb ch,[org_origin_sign]
mov ebp,[addressing_space]
sub eax,[ds:ebp]
sbb edx,[ds:ebp+4]
sbb ch,[ds:ebp+8]
jp current_offset_label_ok
call recoverable_overflow
current_offset_label_ok:
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[org_registers]
mov eax,[ds:ebp+10h]
stos dword [edi]
mov cl,[labels_type]
mov cl,[ds:ebp+9]
mov [edi-12+12],cx
mov eax,[org_symbol]
mov eax,[ds:ebp+14h]
mov [edi-12+16],eax
add edi,8
jmp calculation_loop
org_origin_label:
mov eax,[org_start]
mov eax,[addressing_space]
mov eax,[eax+18h]
jmp make_current_offset_label
counter_label:
mov eax,[counter]
@ -286,17 +291,27 @@ calculate_expression:
mov [error_info],ebx
jmp calculation_loop
calculate_add:
mov ecx,[ebx+16]
cmp byte [edi+12],0
je add_values
mov ecx,[edi+16]
cmp byte [ebx+12],0
je add_values
call recoverable_misuse
add_values:
xor ah,ah
mov ah,[ebx+12]
mov al,[edi+12]
or [ebx+12],al
or al,al
jz add_values
or ah,ah
jz add_relocatable
add ah,al
jnz invalid_add
mov ecx,[edi+16]
cmp ecx,[ebx+16]
je add_values
invalid_add:
call recoverable_misuse
jmp add_values
add_relocatable:
mov ah,al
mov ecx,[edi+16]
mov [ebx+16],ecx
add_values:
mov [ebx+12],ah
mov eax,[edi]
add [ebx],eax
mov eax,[edi+4]
@ -310,31 +325,29 @@ calculate_expression:
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
mov cl,[edi+10]
mov al,[edi+8]
call add_register
lea ebx,[edi+11]
mov cl,[edi+9]
mov cl,[edi+11]
mov al,[edi+9]
call add_register
pop esi
jmp calculation_loop
add_register:
or cl,cl
or al,al
jz add_register_done
add_register_start:
cmp [esi+8],cl
cmp [esi+8],al
jne add_in_second_slot
mov al,[ebx]
add [esi+10],al
add [esi+10],cl
jo value_out_of_range
jnz add_register_done
mov byte [esi+8],0
ret
add_in_second_slot:
cmp [esi+9],cl
cmp [esi+9],al
jne create_in_first_slot
mov al,[ebx]
add [esi+11],al
add [esi+11],cl
jo value_out_of_range
jnz add_register_done
mov byte [esi+9],0
@ -342,16 +355,14 @@ calculate_expression:
create_in_first_slot:
cmp byte [esi+8],0
jne create_in_second_slot
mov [esi+8],cl
mov al,[ebx]
mov [esi+10],al
mov [esi+8],al
mov [esi+10],cl
ret
create_in_second_slot:
cmp byte [esi+9],0
jne invalid_expression
mov [esi+9],cl
mov al,[ebx]
mov [esi+11],al
mov [esi+9],al
mov [esi+11],cl
add_register_done:
ret
out_of_range:
@ -362,6 +373,8 @@ calculate_expression:
mov al,[edi+12]
or al,al
jz sub_values
or ah,ah
jz negate_relocatable
cmp al,ah
jne invalid_sub
xor ah,ah
@ -370,6 +383,12 @@ calculate_expression:
je sub_values
invalid_sub:
call recoverable_misuse
jmp sub_values
negate_relocatable:
neg al
mov ah,al
mov ecx,[edi+16]
mov [ebx+16],ecx
sub_values:
mov [ebx+12],ah
mov eax,[edi]
@ -387,18 +406,18 @@ calculate_expression:
jz calculation_loop
push esi
mov esi,ebx
lea ebx,[edi+10]
mov cl,[edi+8]
mov cl,[edi+10]
mov al,[edi+8]
call sub_register
lea ebx,[edi+11]
mov cl,[edi+9]
mov cl,[edi+11]
mov al,[edi+9]
call sub_register
pop esi
jmp calculation_loop
sub_register:
or cl,cl
or al,al
jz add_register_done
neg byte [ebx]
neg cl
jo value_out_of_range
jmp add_register_start
calculate_mul:
@ -420,6 +439,7 @@ calculate_expression:
xor bl,bl
cmp byte [esi+13],0
je mul_first_sign_ok
xor bl,-1
mov eax,[esi]
mov edx,[esi+4]
not eax
@ -430,10 +450,20 @@ calculate_expression:
mov [esi+4],edx
or eax,edx
jz mul_overflow
xor bl,-1
mul_first_sign_ok:
cmp byte [edi+13],0
je mul_second_sign_ok
xor bl,-1
cmp byte [esi+8],0
je mul_first_register_sign_ok
neg byte [esi+10]
jo invalid_expression
mul_first_register_sign_ok:
cmp byte [esi+9],0
je mul_second_register_sign_ok
neg byte [esi+11]
jo invalid_expression
mul_second_register_sign_ok:
mov eax,[edi]
mov edx,[edi+4]
not eax
@ -444,7 +474,6 @@ calculate_expression:
mov [edi+4],edx
or eax,edx
jz mul_overflow
xor bl,-1
mul_second_sign_ok:
cmp dword [esi+4],0
jz mul_numbers
@ -875,12 +904,17 @@ calculate_expression:
not dword [edi]
jmp finish_not
calculate_neg:
cmp word [edi+8],0
jne invalid_expression
cmp byte [edi+12],0
je neg_ok
call recoverable_misuse
neg_ok:
cmp byte [edi+8],0
je neg_first_register_ok
neg byte [edi+10]
jo invalid_expression
neg_first_register_ok:
cmp byte [edi+9],0
je neg_second_register_ok
neg byte [edi+11]
jo invalid_expression
neg_second_register_ok:
neg byte [edi+12]
xor eax,eax
xor edx,edx
xor cl,cl
@ -1105,13 +1139,13 @@ calculate_expression:
mov [esi+13],bl
ret
store_label_reference:
mov eax,[display_buffer]
mov eax,[tagged_blocks]
mov dword [eax-4],2
mov dword [eax-8],4
sub eax,8+4
cmp eax,edi
jbe out_of_memory
mov [display_buffer],eax
mov [tagged_blocks],eax
mov [eax],ebx
ret
convert_fp:
@ -1520,18 +1554,22 @@ get_value:
get_address_word_value:
mov [address_size],2
mov [value_size],2
mov [free_address_range],0
jmp calculate_address
get_address_dword_value:
mov [address_size],4
mov [value_size],4
mov [free_address_range],0
jmp calculate_address
get_address_qword_value:
mov [address_size],8
mov [value_size],8
mov [free_address_range],0
jmp calculate_address
get_address_value:
mov [address_size],0
mov [value_size],8
or [free_address_range],-1
calculate_address:
cmp byte [esi],'.'
je invalid_address
@ -1542,17 +1580,22 @@ get_address_value:
mov [address_sign],al
mov al,[edi+12]
mov [value_type],al
cmp al,0
je address_size_ok
jg get_address_symbol_size
neg al
get_address_symbol_size:
cmp al,6
je special_address_type_32bit
cmp al,5
je special_address_type_32bit
ja invalid_use_of_symbol
ja invalid_address_type
test al,1
jnz invalid_use_of_symbol
or al,al
jz address_size_ok
jnz invalid_address_type
shl al,5
jmp address_symbol_ok
invalid_address_type:
call recoverable_misuse
special_address_type_32bit:
mov al,40h
address_symbol_ok:
@ -1621,11 +1664,11 @@ get_address_value:
je sib_allowed
cmp al,0Fh
je check_ip_relative_address
or cl,cl
jz check_word_value
cmp cl,1
je check_word_value
jmp invalid_address
ja invalid_address
cmp [free_address_range],0
jne check_qword_value
jmp check_word_value
address_sizes_do_not_match:
cmp al,0Fh
jne invalid_address
@ -1636,10 +1679,14 @@ get_address_value:
check_ip_relative_address:
or bl,bl
jnz invalid_address
cmp bh,0F4h
je check_dword_value
cmp bh,0F8h
je check_rip_relative_address
cmp bh,0F4h
jne invalid_address
cmp [free_address_range],0
jne check_qword_value
jmp check_dword_value
check_rip_relative_address:
mov eax,[edi]
cdq
cmp edx,[edi+4]
@ -1694,6 +1741,8 @@ get_address_value:
mov bh,bl
dec cl
check_immediate_address:
cmp [free_address_range],0
jne check_qword_value
mov al,[address_size]
and al,0Fh
cmp al,2
@ -1778,19 +1827,19 @@ calculate_relative_offset:
jne relative_offset_ok
test bh,bh
setne ch
cmp bx,word [org_registers]
cmp bx,[ds:ebp+10h]
je origin_registers_ok
xchg bh,bl
xchg ch,cl
cmp bx,word [org_registers]
cmp bx,[ds:ebp+10h]
jne invalid_value
origin_registers_ok:
cmp cx,word [org_registers+2]
cmp cx,[ds:ebp+10h+2]
jne invalid_value
mov bl,[address_sign]
add eax,dword [org_origin]
adc edx,dword [org_origin+4]
adc bl,[org_origin_sign]
add eax,[ds:ebp]
adc edx,[ds:ebp+4]
adc bl,[ds:ebp+8]
sub eax,edi
sbb edx,0
sbb bl,0
@ -1802,7 +1851,7 @@ calculate_relative_offset:
jnz relative_offset_unallowed
cmp bl,6
je plt_relative_offset
mov bh,[labels_type]
mov bh,[ds:ebp+9]
cmp bl,bh
je set_relative_offset_type
cmp bx,0402h
@ -1813,16 +1862,16 @@ calculate_relative_offset:
cmp [value_type],0
je relative_offset_ok
mov [value_type],0
cmp ecx,[org_symbol]
cmp ecx,[ds:ebp+14h]
je relative_offset_ok
mov [value_type],3
relative_offset_ok:
ret
plt_relative_offset:
mov [value_type],7
cmp [labels_type],2
cmp byte [ds:ebp+9],2
je relative_offset_ok
cmp [labels_type],4
cmp byte [ds:ebp+9],4
jne recoverable_misuse
ret
@ -1906,6 +1955,8 @@ calculate_logical_expression:
je given_false
cmp al,'1'
je given_true
cmp al,'('
jne invalid_value
call get_value_for_comparison
mov bh,[value_sign]
push eax edx [symbol_identifier] ebx ecx
@ -1922,6 +1973,8 @@ calculate_logical_expression:
je logical_number
inc esi
mov [compare_type],al
cmp byte [esi],'('
jne invalid_value
call get_value_for_comparison
cmp bl,[esp+4]
jne values_not_relative
@ -2173,6 +2226,8 @@ skip_symbol:
je skip_label
cmp al,3
je skip_label
cmp al,4
je skip_special_label
cmp al,20h
jb skip_assembler_symbol
cmp al,'('
@ -2189,6 +2244,9 @@ skip_symbol:
skip_assembler_symbol:
inc esi
jmp skip_done
skip_special_label:
add esi,4
jmp skip_done
skip_address:
mov al,[esi]
and al,11110000b

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
convert_expression:

View File

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

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
_out_of_memory db 'out of memory',0

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
parser:
@ -64,6 +64,8 @@ parser:
simple_label:
pop edi
call identify_label
cmp byte [esi+1],':'
je block_label
mov byte [edi],2
inc edi
stos dword [edi]
@ -71,6 +73,12 @@ parser:
xor al,al
stos byte [edi]
jmp parse_line
block_label:
mov byte [edi],4
inc edi
stos dword [edi]
add esi,2
jmp parse_line
constant_label:
pop edi
call get_label_id
@ -127,8 +135,6 @@ parser:
cmp al,':'
je invalid_name
dec esi
cmp al,3Bh
je skip_rest_of_line
mov [parenthesis_stack],0
call parse_argument
jmp parse_next_line
@ -530,6 +536,8 @@ parse_line_contents:
je unallowed_character
cmp al,'`'
je unallowed_character
cmp al,3Bh
je foreign_argument
dec esi
cmp al,1Ah
jne expression_argument
@ -550,6 +558,10 @@ parse_line_contents:
pop edi
movs byte [edi],[esi]
jmp argument_parsed
foreign_argument:
dec esi
call skip_foreign_line
jmp contents_parsed
symbol_argument:
pop edi
stos word [edi]
@ -560,7 +572,7 @@ parse_line_contents:
je ptr_argument
stos byte [edi]
cmp al,80h
je forced_expression
je forced_multipart_expression
cmp al,8Ch
je forced_expression
cmp al,81h
@ -725,7 +737,7 @@ parse_line_contents:
jmp argument_parsed
parse_from_operator:
cmp byte [esi],22h
jne forced_expression
jne forced_multipart_expression
jmp argument_parsed
parse_quoted_extrn:
inc esi
@ -771,14 +783,10 @@ parse_line_contents:
mov eax,[esi+1]
lea ebx,[esi+5+eax]
push ebx ecx esi edi
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
call parse_expression
pop eax edx ecx ebx
cmp esi,ebx
jne expression_parsed
jne expression_argument_parsed
mov edi,eax
mov esi,edx
string_argument:
@ -799,7 +807,14 @@ parse_line_contents:
rep movs dword [edi],[esi]
xor al,al
stos byte [edi]
jmp expression_parsed
jmp expression_argument_parsed
parse_expression:
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
ret
not_string:
cmp byte [esi],'('
jne expression
@ -838,24 +853,27 @@ parse_line_contents:
mov al,0F1h
jmp expression_comparator
expression:
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
jmp expression_parsed
call parse_expression
jmp expression_argument_parsed
forced_expression:
xor al,al
xchg al,[formatter_symbols_allowed]
push eax
mov al,'('
stos byte [edi]
call convert_expression
mov al,')'
stos byte [edi]
call parse_expression
forced_expression_parsed:
pop eax
mov [formatter_symbols_allowed],al
jmp argument_parsed
forced_multipart_expression:
xor al,al
xchg al,[formatter_symbols_allowed]
push eax
call parse_expression
cmp byte [esi],':'
jne forced_expression_parsed
movs byte [edi],[esi]
call parse_expression
jmp forced_expression_parsed
address_argument:
call parse_address
lods byte [esi]
@ -925,7 +943,7 @@ parse_line_contents:
dec [parenthesis_stack]
add esp,8
jmp argument_parsed
expression_parsed:
expression_argument_parsed:
cmp [parenthesis_stack],0
je parse_argument
cmp byte [esi],')'

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
preprocessor:
@ -38,7 +38,7 @@ preprocessor:
mov [labels_list],eax
xor eax,eax
mov [source_start],eax
mov [display_buffer],eax
mov [tagged_blocks],eax
mov [hash_tree],eax
mov [error],eax
mov [macro_status],al
@ -195,13 +195,13 @@ convert_line:
lods byte [esi]
stos byte [edi]
cmp al,0Ah
je missing_end_quote
je no_end_quote
cmp al,0Dh
je missing_end_quote
je no_end_quote
or al,al
jz missing_end_quote
jz no_end_quote
cmp al,1Ah
je missing_end_quote
je no_end_quote
cmp al,ah
jne copy_string
lods byte [esi]
@ -243,6 +243,9 @@ convert_line:
stos byte [edi]
inc byte [ecx]
jmp group_backslashes
no_end_quote:
mov byte [ebx-5],0
jmp missing_end_quote
backslashed_symbol:
cmp al,1Ah
je unexpected_end_of_file
@ -554,6 +557,9 @@ preprocess_line:
call get_preprocessor_symbol
jnc symbolic_constant_in_label
lea esi,[esi+ecx+1]
cmp byte [esi],':'
jne preprocess_instruction
inc esi
jmp preprocess_instruction
symbolic_constant_in_label:
mov ebx,[edx+8]
@ -571,6 +577,9 @@ preprocess_line:
cmp byte [ebx],':'
jne label_broken
inc ebx
cmp byte [ebx],':'
jne check_for_broken_label
inc ebx
jmp check_for_broken_label
label_broken:
push line_preprocessed
@ -1685,6 +1694,7 @@ do_irp:
or [default_argument_value],-1
call skip_macro_argument_value
inc esi
jmp irp_parameters_start
irps_name_ok:
cmp al,','
jne invalid_macro_arguments

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
dump_symbols:
@ -8,14 +8,14 @@ dump_symbols:
call setup_dump_header
mov esi,[input_file]
call copy_asciiz
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
mov eax,edi
sub eax,ebx
mov [ebx-40h+0Ch],eax
mov esi,[output_file]
call copy_asciiz
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
mov edx,[symbols_stream]
mov ebp,[free_additional_memory]
@ -53,7 +53,7 @@ dump_symbols:
rep movs byte [edi],[esi]
mov byte [edi],0
inc edi
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
jmp prepare_strings_table
prepare_section_string:
@ -76,7 +76,7 @@ dump_symbols:
add esi,[resource_data]
copy_elf_section_name:
lods byte [esi]
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
stos byte [edi]
test al,al
@ -87,11 +87,11 @@ dump_symbols:
stos dword [edi]
mov ax,'t'
stos word [edi]
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
jmp prepare_strings_table
strings_table_ready:
mov edx,[display_buffer]
mov edx,[tagged_blocks]
mov ebp,[memory_end]
sub ebp,[labels_list]
add ebp,edx
@ -117,7 +117,7 @@ dump_symbols:
mov [edx+24],eax
movzx ecx,byte [esi-1]
lea eax,[edi+ecx+1]
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jae out_of_memory
rep movsb
xor al,al
@ -129,6 +129,13 @@ dump_symbols:
sub eax,[memory_start]
mov [edx+28],eax
label_dump_line_ok:
test byte [edx+9],4
jz convert_base_symbol_for_label
xor eax,eax
mov [edx],eax
mov [edx+4],eax
jmp base_symbol_for_label_ok
convert_base_symbol_for_label:
mov eax,[edx+20]
test eax,eax
jz base_symbol_for_label_ok
@ -172,7 +179,7 @@ dump_symbols:
mov esi,[labels_list]
mov ebp,edi
make_lines_dump:
cmp esi,[display_buffer]
cmp esi,[tagged_blocks]
je lines_dump_ok
mov eax,[esi-4]
mov ecx,[esi-8]
@ -185,11 +192,13 @@ dump_symbols:
add dword [ebx-40h+3Ch],8
jmp make_lines_dump
process_line_dump:
push ebx
mov ebx,[esi+8]
mov eax,[esi+4]
sub eax,[code_start]
add eax,[headers_size]
cmp byte [esi+1Ah],0
je store_offset
test byte [ebx+0Ah],1
jz store_offset
xor eax,eax
store_offset:
stos dword [edi]
@ -199,15 +208,15 @@ dump_symbols:
mov eax,[esi+4]
xor edx,edx
xor cl,cl
sub eax,[esi+8]
sbb edx,[esi+8+4]
sbb cl,[esi+1Bh]
sub eax,[ebx]
sbb edx,[ebx+4]
sbb cl,[ebx+8]
stos dword [edi]
mov eax,edx
stos dword [edi]
mov eax,[esi+10h]
mov eax,[ebx+10h]
stos dword [edi]
mov eax,[esi+14h]
mov eax,[ebx+14h]
test eax,eax
jz base_symbol_for_line_ok
cmp eax,[symbols_stream]
@ -216,11 +225,17 @@ dump_symbols:
xor eax,eax
base_symbol_for_line_ok:
stos dword [edi]
mov eax,[esi+18h]
and eax,01FFFFh
stos dword [edi]
mov [edi-1],cl
cmp edi,[display_buffer]
mov al,[ebx+9]
stos byte [edi]
mov al,[esi+10h]
stos byte [edi]
mov al,[ebx+0Ah]
and al,1
stos byte [edi]
mov al,cl
stos byte [edi]
pop ebx
cmp edi,[tagged_blocks]
jae out_of_memory
mov eax,edi
sub eax,1Ch
@ -264,7 +279,7 @@ dump_symbols:
add ecx,40h
call write
jc write_failed
mov edx,[display_buffer]
mov edx,[tagged_blocks]
mov ecx,[memory_end]
sub ecx,[labels_list]
call write
@ -287,7 +302,7 @@ dump_symbols:
mov esi,[labels_list]
mov edi,[memory_start]
make_references_dump:
cmp esi,[display_buffer]
cmp esi,[tagged_blocks]
je references_dump_ok
mov eax,[esi-4]
mov ecx,[esi-8]
@ -306,7 +321,7 @@ dump_symbols:
stosd
mov eax,edx
stosd
cmp edi,[display_buffer]
cmp edi,[tagged_blocks]
jb make_references_dump
jmp out_of_memory
references_dump_ok:

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
include_variable db 'INCLUDE',0
@ -563,6 +563,10 @@ instructions_3:
db 'xor',30h
dw basic_instruction-instruction_handler
instructions_4:
db 'adcx',66h
dw adx_instruction-instruction_handler
db 'adox',0F3h
dw adx_instruction-instruction_handler
db 'andn',0F2h
dw andn_instruction-instruction_handler
db 'arpl',0
@ -581,6 +585,8 @@ instructions_4:
dw call_instruction-instruction_handler
db 'cdqe',98h
dw simple_instruction_64bit-instruction_handler
db 'clac',0CAh
dw simple_vmx_instruction-instruction_handler
db 'clgi',0DDh
dw simple_vmx_instruction-instruction_handler
db 'clts',6
@ -783,6 +789,8 @@ instructions_4:
dw pm_store_word_instruction-instruction_handler
db 'smsw',14h
dw pm_store_word_instruction-instruction_handler
db 'stac',0CBh
dw simple_vmx_instruction-instruction_handler
db 'stgi',0DCh
dw simple_vmx_instruction-instruction_handler
db 'stos',0AAh
@ -1551,6 +1559,8 @@ instructions_6:
dw simple_extended_instruction_64bit-instruction_handler
db 'rdrand',110b
dw rdrand_instruction-instruction_handler
db 'rdseed',111b
dw rdrand_instruction-instruction_handler
db 'rdtscp',1
dw rdtscp_instruction-instruction_handler
db 'repeat',0

View File

@ -1,6 +1,6 @@
; flat assembler core variables
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
; Variables which have to be set up by interface:
@ -50,10 +50,7 @@ labels_list dd ?
label_hash dd ?
label_leaf dd ?
hash_tree dd ?
org_origin dq ?
org_registers dd ?
org_symbol dd ?
org_start dd ?
addressing_space dd ?
undefined_data_start dd ?
undefined_data_end dd ?
counter dd ?
@ -61,7 +58,7 @@ counter_limit dd ?
error_info dd ?
error_line dd ?
error dd ?
display_buffer dd ?
tagged_blocks dd ?
structures_buffer dd ?
number_start dd ?
current_offset dd ?
@ -131,16 +128,15 @@ compare_type db ?
logical_value_wrapping db ?
next_pass_needed db ?
output_format db ?
labels_type db ?
code_type db ?
virtual_data db ?
org_origin_sign db ?
adjustment_sign db ?
macro_status db ?
default_argument_value db ?
prefixed_instruction db ?
formatter_symbols_allowed db ?
free_address_range db ?
characters rb 100h
converted rb 100h

View File

@ -1,6 +1,6 @@
; flat assembler version 1.70
; Copyright (c) 1999-2012, Tomasz Grysztar.
; flat assembler version 1.71
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
;
; This programs is free for commercial and non-commercial use as long as
@ -33,7 +33,7 @@
; cannot simply be copied and put under another distribution licence
; (including the GNU Public Licence).
VERSION_STRING equ "1.70.03"
VERSION_STRING equ "1.71.13"
VERSION_MAJOR = 1
VERSION_MINOR = 70
VERSION_MINOR = 71

View File

@ -1,6 +1,6 @@
; flat assembler core
; Copyright (c) 1999-2012, Tomasz Grysztar.
; Copyright (c) 1999-2013, Tomasz Grysztar.
; All rights reserved.
simple_instruction_except64:
@ -2989,6 +2989,7 @@ jmp_instruction:
jmp instruction_assembled
calculate_jump_offset:
add edi,2
mov ebp,[addressing_space]
call calculate_relative_offset
sub edi,2
ret
@ -5982,6 +5983,27 @@ movbe_instruction:
mov al,[operand_size]
call operand_autodetect
jmp instruction_ready
adx_instruction:
mov [base_code],0Fh
mov [extended_code],38h
mov [supplemental_code],0F6h
mov [operand_prefix],al
call get_reg_mem
jc adx_reg_reg
mov al,[operand_size]
cmp al,4
je instruction_ready
cmp al,8
jne invalid_operand_size
call operand_64bit
jmp instruction_ready
adx_reg_reg:
cmp ah,4
je nomem_instruction_ready
cmp ah,8
jne invalid_operand_size
call operand_64bit
jmp nomem_instruction_ready
simple_vmx_instruction:
mov ah,al
@ -6251,6 +6273,7 @@ xbegin_instruction:
xbegin_16bit:
call get_address_word_value
add edi,4
mov ebp,[addressing_space]
call calculate_relative_offset
sub edi,4
shl eax,16
@ -6264,6 +6287,7 @@ xbegin_instruction:
call get_address_qword_value
xbegin_address_ok:
add edi,5
mov ebp,[addressing_space]
call calculate_relative_offset
sub edi,5
mov edx,eax
@ -6383,6 +6407,7 @@ get_jump_operator:
get_address:
mov [segment_register],0
mov [address_size],0
mov [free_address_range],0
mov al,[code_type]
shr al,3
mov [value_size],al
@ -6422,6 +6447,7 @@ get_address:
mov edx,[address_symbol]
mov [symbol_identifier],edx
mov edx,[address_high]
mov ebp,[addressing_space]
call calculate_relative_offset
mov [address_high],edx
cdq

View File

@ -55,11 +55,15 @@ macro proc [args] ; define procedure
prologue@proc equ prologuedef
macro prologuedef procname,flag,parmbytes,localbytes,reglist
{ if parmbytes | localbytes
{ local loc
loc = (localbytes+3) and (not 3)
parmbase@proc equ ebp+8
localbase@proc equ ebp-loc
if parmbytes | localbytes
push ebp
mov ebp,esp
if localbytes
sub esp,localbytes
sub esp,loc
end if
end if
irps reg, reglist \{ push reg \} }
@ -77,6 +81,8 @@ macro epiloguedef procname,flag,parmbytes,localbytes,reglist
retn parmbytes
end if }
close@proc equ
macro define@proc name,statement
{ local params,flag,regs,parmbytes,localbytes,current
if used name
@ -91,22 +97,22 @@ macro define@proc name,statement
flag = 10001b \}
match =params, params \{ params equ statement
flag = 0 \}
virtual at ebp+8
match =uses reglist=,args, params \{ regs equ reglist
params equ args \}
match =regs =uses reglist, regs params \{ regs equ reglist
params equ \}
match =regs, regs \{ regs equ \}
match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \}
virtual at parmbase@proc
match =,args, params \{ defargs@proc args \}
match =args@proc args, args@proc params \{ defargs@proc args \}
parmbytes = $ - (ebp+8)
parmbytes = $-(parmbase@proc)
end virtual
name # % = parmbytes/4
all@vars equ
current = 0
match prologue:reglist, prologue@proc:<regs> \{ prologue name,flag,parmbytes,localbytes,reglist \}
macro locals
\{ virtual at ebp-localbytes+current
\{ virtual at localbase@proc+current
macro label def \\{ match . type,def> \\\{ deflocal@proc .,label,<type \\\} \\}
struc db [val] \\{ \common deflocal@proc .,db,val \\}
struc du [val] \\{ \common deflocal@proc .,du,val \\}
@ -125,13 +131,14 @@ macro define@proc name,statement
\{ purge label
restruc db,du,dw,dp,dd,dt,dq
restruc rb,rw,rp,rd,rt,rq
current = $-(ebp-localbytes)
current = $-(localbase@proc)
end virtual \}
macro ret operand
\{ match any, operand \\{ retn operand \\}
match , operand \\{ match epilogue:reglist, epilogue@proc:<regs>
\\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \}
macro finish@proc \{ localbytes = (((current-1) shr 2)+1) shl 2
match , operand \\{ match epilogue:reglist, epilogue@proc:<regs> \\\{ epilogue name,flag,parmbytes,localbytes,reglist \\\} \\} \}
macro finish@proc
\{ localbytes = current
match close:reglist, close@proc:<regs> \\{ close name,flag,parmbytes,localbytes,reglist \\}
end if \} }
macro defargs@proc [arg]
@ -143,7 +150,9 @@ macro defargs@proc [arg]
\{ current@arg equ argname
label ..arg type
argname equ ..arg
if dqword eq type
if qqword eq type
dd ?,?,?,?,?,?,?,?
else if dqword eq type
dd ?,?,?,?
else if tbyte eq type
dd ?,?,?
@ -163,17 +172,19 @@ macro defargs@proc [arg]
common
end if }
macro deflocal@proc name,def,[val] { name def val }
macro deflocal@proc name,def,[val]
{ common
match vars, all@vars \{ all@vars equ all@vars, \}
all@vars equ all@vars name
forward
local ..var,..tmp
match =label,def \{ ..tmp equ \}
match tmp,..tmp \{ ..var def val \}
match ,..tmp \{ label ..var val \}
..var def val
match =?, val \{ ..tmp equ \}
match any =dup (=?), val \{ ..tmp equ \}
match any =?, val \{ ..tmp equ \}
match any (=?), val \{ ..tmp equ \}
match =label, def \{ ..tmp equ \}
match tmp : value, ..tmp : val
\{ tmp: end virtual
initlocal@proc ..var,def value
@ -181,6 +192,8 @@ macro deflocal@proc name,def,[val]
common
match first rest, ..var, \{ name equ first \} }
struc label type { label . type }
macro initlocal@proc name,def
{ virtual at name
def
@ -238,7 +251,16 @@ macro local [var]
match =TBYTE, vartype \\{ varname rt count
restore done@local \\}
match =DQWORD, vartype \\{ label varname dqword
rq count+count
rq count*2
restore done@local \\}
match =QQWORD, vartype \\{ label varname qqword
rq count*4
restore done@local \\}
match =XWORD, vartype \\{ label varname xword
rq count*2
restore done@local \\}
match =YWORD, vartype \\{ label varname yword
rq count*4
restore done@local \\}
match , done@local \\{ virtual
varname vartype
@ -261,6 +283,15 @@ macro local [var]
match =DQWORD, vartype \\{ label varname dqword
dq ?,?
restore done@local \\}
match =QQWORD, vartype \\{ label varname qqword
dq ?,?,?,?
restore done@local \\}
match =XWORD, vartype \\{ label varname xword
dq ?,?
restore done@local \\}
match =YWORD, vartype \\{ label varname yword
dq ?,?,?,?
restore done@local \\}
match , done@local \\{ varname vartype
restore done@local \\} \}
match ,done@local

View File

@ -2,53 +2,79 @@
; Macroinstructions for defining data structures
macro struct name
{ fields@struct equ name
{ virtual at 0
fields@struct equ name
match child parent, name \{ fields@struct equ child,fields@\#parent \}
sub@struct equ
struc db [val] \{ \common fields@struct equ fields@struct,.,db,<val> \}
struc dw [val] \{ \common fields@struct equ fields@struct,.,dw,<val> \}
struc du [val] \{ \common fields@struct equ fields@struct,.,du,<val> \}
struc dd [val] \{ \common fields@struct equ fields@struct,.,dd,<val> \}
struc dp [val] \{ \common fields@struct equ fields@struct,.,dp,<val> \}
struc dq [val] \{ \common fields@struct equ fields@struct,.,dq,<val> \}
struc dt [val] \{ \common fields@struct equ fields@struct,.,dt,<val> \}
struc rb count \{ fields@struct equ fields@struct,.,db,count dup (?) \}
struc rw count \{ fields@struct equ fields@struct,.,dw,count dup (?) \}
struc rd count \{ fields@struct equ fields@struct,.,dd,count dup (?) \}
struc rp count \{ fields@struct equ fields@struct,.,dp,count dup (?) \}
struc rq count \{ fields@struct equ fields@struct,.,dq,count dup (?) \}
struc rt count \{ fields@struct equ fields@struct,.,dt,count dup (?) \}
struc db [val] \{ \common define field@struct .,db,<val>
fields@struct equ fields@struct,field@struct \}
struc dw [val] \{ \common define field@struct .,dw,<val>
fields@struct equ fields@struct,field@struct \}
struc du [val] \{ \common define field@struct .,du,<val>
fields@struct equ fields@struct,field@struct \}
struc dd [val] \{ \common define field@struct .,dd,<val>
fields@struct equ fields@struct,field@struct \}
struc dp [val] \{ \common define field@struct .,dp,<val>
fields@struct equ fields@struct,field@struct \}
struc dq [val] \{ \common define field@struct .,dq,<val>
fields@struct equ fields@struct,field@struct \}
struc dt [val] \{ \common define field@struct .,dt,<val>
fields@struct equ fields@struct,field@struct \}
struc rb count \{ define field@struct .,db,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rw count \{ define field@struct .,dw,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rd count \{ define field@struct .,dd,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rp count \{ define field@struct .,dp,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rq count \{ define field@struct .,dq,count dup (?)
fields@struct equ fields@struct,field@struct \}
struc rt count \{ define field@struct .,dt,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro db [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,db,<val> \}
define field@struct anonymous,db,<val>
fields@struct equ fields@struct,field@struct \}
macro dw [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,dw,<val> \}
define field@struct anonymous,dw,<val>
fields@struct equ fields@struct,field@struct \}
macro du [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,du,<val> \}
define field@struct anonymous,du,<val>
fields@struct equ fields@struct,field@struct \}
macro dd [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,dd,<val> \}
define field@struct anonymous,dd,<val>
fields@struct equ fields@struct,field@struct \}
macro dp [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,dp,<val> \}
define field@struct anonymous,dp,<val>
fields@struct equ fields@struct,field@struct \}
macro dq [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,dq,<val> \}
define field@struct anonymous,dq,<val>
fields@struct equ fields@struct,field@struct \}
macro dt [val] \{ \common \local anonymous
fields@struct equ fields@struct,anonymous,dt,<val> \}
define field@struct anonymous,dt,<val>
fields@struct equ fields@struct,field@struct \}
macro rb count \{ \local anonymous
fields@struct equ fields@struct,anonymous,db,count dup (?) \}
define field@struct anonymous,db,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro rw count \{ \local anonymous
fields@struct equ fields@struct,anonymous,dw,count dup (?) \}
define field@struct anonymous,dw,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro rd count \{ \local anonymous
fields@struct equ fields@struct,anonymous,dd,count dup (?) \}
define field@struct anonymous,dd,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro rp count \{ \local anonymous
fields@struct equ fields@struct,anonymous,dp,count dup (?) \}
define field@struct anonymous,dp,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro rq count \{ \local anonymous
fields@struct equ fields@struct,anonymous,dq,count dup (?) \}
define field@struct anonymous,dq,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro rt count \{ \local anonymous
fields@struct equ fields@struct,anonymous,dt,count dup (?) \}
define field@struct anonymous,dt,count dup (?)
fields@struct equ fields@struct,field@struct \}
macro union \{ fields@struct equ fields@struct,,union,<
sub@struct equ union \}
macro struct \{ fields@struct equ fields@struct,,substruct,<
sub@struct equ substruct \}
virtual at 0 }
sub@struct equ substruct \} }
macro ends
{ match , sub@struct \{ restruc db,dw,du,dd,dp,dq,dt
@ -56,19 +82,19 @@ macro ends
purge db,dw,du,dd,dp,dq,dt
purge rb,rw,rd,rp,rq,rt
purge union,struct
match name tail,fields@struct, \\{ if $
display 'Error: definition of ',\\`name,' contains illegal instructions.',0Dh,0Ah
err
end if \\}
match name=,fields,fields@struct \\{ fields@struct equ
make@struct name,fields
fields@\\#name equ fields \\}
define fields@\\#name fields \\}
end virtual \}
match any, sub@struct \{ fields@struct equ fields@struct> \}
restore sub@struct }
macro make@struct name,[field,type,def]
{ common
if $
display 'Error: definition of ',`name,' contains illegal instructions.',0Dh,0Ah
err
end if
local define
define equ name
forward
@ -81,6 +107,14 @@ macro make@struct name,[field,type,def]
macro define@struct name,[field,type,def]
{ common
virtual
db `name
load initial@struct byte from 0
if initial@struct = '.'
display 'Error: name of structure should not begin with a dot.',0Dh,0Ah
err
end if
end virtual
local list
list equ
forward
@ -88,6 +122,7 @@ macro define@struct name,[field,type,def]
name#field type def
sizeof.#name#field = $ - name#field
else
label name#.#type
rb sizeof.#type
end if
local value
@ -97,15 +132,29 @@ macro define@struct name,[field,type,def]
sizeof.#name = $
restruc name
match values, list \{
struc name value \\{
struc name value \\{ \\local \\..base
match any, fields@struct \\\{ fields@struct equ fields@struct,.,name,<values> \\\}
match , fields@struct \\\{ label .
match , fields@struct \\\{ label \\..base
forward
match , value \\\\{ field type def \\\\}
match any, value \\\\{ field type value
if ~ field eq .
rb sizeof.#name#field - ($-field)
end if \\\\}
common label . at \\..base \\\}
\\}
macro name value \\{
match any, fields@struct \\\{ \\\local anonymous
fields@struct equ fields@struct,anonymous,name,<values> \\\}
match , fields@struct \\\{
forward
match , value \\\\{ type def \\\\}
match any, value \\\\{ \\\\local ..field
..field = $
type value
if ~ field eq .
rb sizeof.#name#field - ($-..field)
end if \\\\}
common \\\} \\} \} }
macro enable@substruct
@ -116,7 +165,7 @@ macro enable@substruct
\forward
\local sub
match , field \\{ match any, type \\\{ enable@substruct
make@substruct type,name,sub def
make@substruct type,parent,sub def
purge make@substruct
define equ define,.,sub, \\\} \\}
match any, field \\{ define equ define,.\#field,type,<def> \\}
@ -127,21 +176,28 @@ enable@substruct
macro define@union parent,name,[field,type,def]
{ common
virtual at 0
virtual at parent#.#name
forward
if ~ field eq .
virtual at 0
virtual at parent#.#name
parent#field type def
sizeof.#parent#field = $ - parent#field
end virtual
if sizeof.#parent#field > $
rb sizeof.#parent#field - $
if sizeof.#parent#field > $ - parent#.#name
rb sizeof.#parent#field - ($ - parent#.#name)
end if
else
virtual at parent#.#name
label parent#.#type
type def
end virtual
label name#.#type at parent#.#name
if sizeof.#type > $ - parent#.#name
rb sizeof.#type - ($ - parent#.#name)
end if
else if sizeof.#type > $
rb sizeof.#type - $
end if
common
sizeof.#name = $
sizeof.#name = $ - parent#.#name
end virtual
struc name [value] \{ \common
label .\#name
@ -153,21 +209,23 @@ macro define@union parent,name,[field,type,def]
match , last@union \\{ match , value \\\{ field type def \\\}
match any, value \\\{ field type value \\\} \\}
last@union equ field
common rb sizeof.#name - ($ - .\#name) \} }
common rb sizeof.#name - ($ - .\#name) \}
macro name [value] \{ \common \local ..anonymous
..anonymous name value \} }
macro define@substruct parent,name,[field,type,def]
{ common
virtual at 0
virtual at parent#.#name
forward
if ~ field eq .
parent#field type def
sizeof.#parent#field = $ - parent#field
else
label parent#.#type
rb sizeof.#type
end if
local value
common
sizeof.#name = $
sizeof.#name = $ - parent#.#name
end virtual
struc name value \{
label .\#name
@ -177,4 +235,6 @@ macro define@substruct parent,name,[field,type,def]
if ~ field eq .
rb sizeof.#parent#field - ($-field)
end if \\}
common \} }
common \}
macro name value \{ \local ..anonymous
..anonymous name \} }