Commit 308fb0f8 authored by Tomasz Buchert's avatar Tomasz Buchert

Imported Upstream version 1.71.39

parent f77805ff
No preview for this file type
......@@ -414,20 +414,16 @@ with their priority values are listed in table 1.4. The operations with higher
priority value will be calculated first, you can of course change this
behavior by putting some parts of expression into parenthesis. The "+", "-",
"*" and "/" are standard arithmetical operations, "mod" calculates the
remainder from division. The "and", "or", "xor", "shl", "shr" and "not"
perform the same logical operations as assembly instructions of those names.
The "rva" and "plt" are special unary operators that perform conversions
between different kinds of addresses, they can be used only with few of the
output formats and their meaning may vary (see 2.4).
The arithmetical and logical calculations are usually processed as if they
remainder from division. The "and", "or", "xor", "shl", "shr", "bsf", "bsr"
and "not" perform the same bit-logical operations as assembly instructions of
those names. The "rva" and "plt" are special unary operators that perform
conversions between different kinds of addresses, they can be used only with
few of the output formats and their meaning may vary (see 2.4).
The arithmetical and bit-logical calculations are processed as if they
operated on infinite precision 2-adic numbers, and assembler signalizes an
overflow error if because of its limitations it is not table to perform the
required calculation, or if the result is too large number to fit in either
signed or unsigned range for the destination unit size. However "not", "xor"
and "shr" operators are exceptions from this rule - if the value specified
by numerical expression has to fit in a unit of specified size, and the
arguments for operation fit into that size, the operation will be performed
with precision limited to that size.
signed or unsigned range for the destination unit size.
The numbers in the expression are by default treated as a decimal, binary
numbers should have the "b" letter attached at the end, octal number should
end with "o" letter, hexadecimal numbers should begin with "0x" characters
......@@ -454,7 +450,7 @@ recognized, otherwise they should contain at least one of the "." or "E"
characters. So "1.0", "1E0" and "1f" define the same floating point value,
while simple "1" defines an integer value.
Table 1.4 Arithmetical and logical operators by priority
Table 1.4 Arithmetical and bit-logical operators by priority
/-------------------------\
| Priority | Operators |
|==========|==============|
......@@ -470,7 +466,9 @@ while simple "1" defines an integer value.
|----------|--------------|
| 5 | not |
|----------|--------------|
| 6 | rva plt |
| 6 | bsf bsr |
|----------|--------------|
| 7 | rva plt |
\-------------------------/
......@@ -3945,6 +3943,9 @@ has an empty value provided, the default value will be used instead.
some commas, such argument should be enclosed between "<" and ">" characters.
If it contains more than one "<" character, the same number of ">" should be
used to tell that the value of argument ends.
When the name of the last argument of macroinstruction is followed by "&"
character, this argument consumes everything up to the end of line, including
commas.
"purge" directive allows removing the last definition of specified
macroinstruction. It should be followed by one or more names of
macroinstructions, separated with commas. If such macroinstruction has not
......@@ -4642,8 +4643,9 @@ for Windows drivers, "EFI", "EFIboot" or "EFIruntime" for the UEFI, it may be
followed by the minimum version of system that the executable is targeted to
(specified in form of floating-point value). Optional "DLL" and "WDM" keywords
mark the output file as a dynamic link library and WDM driver respectively,
and the "large" keyword marks the executable as able to handle addresses
larger than 2 GB.
the "large" keyword marks the executable as able to handle addresses larger
than 2 GB and the "NX" keyword signalizes that the executable conforms to the
restriction of not executing code residing in non-executable sections.
After those settings can follow the "at" operator and a numerical expression
specifying the base of PE image and then optionally "on" operator followed by
the quoted string containing file name selects custom MZ stub for PE program
......
; flat assembler interface for DOS
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
format MZ
......@@ -114,6 +114,7 @@ get_params:
mov [symbols_file],0
mov [memory_setting],0
mov [passes_limit],100
mov [definitions_pointer],predefinitions
push ds
mov ds,[psp_segment]
mov esi,81h
......@@ -169,6 +170,10 @@ get_params:
je passes_option
cmp al,'P'
je passes_option
cmp al,'d'
je definition_option
cmp al,'D'
je definition_option
cmp al,'s'
je symbols_option
cmp al,'S'
......@@ -238,6 +243,22 @@ get_params:
ja invalid_option
mov [es:passes_limit],dx
jmp find_param
definition_option:
lodsb
cmp al,20h
je definition_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
push edi
mov edi,[es:definitions_pointer]
call convert_definition_option
mov [es:definitions_pointer],edi
pop edi
jc invalid_option
jmp find_param
symbols_option:
mov [es:symbols_file],edi
find_symbols_file_name:
......@@ -257,6 +278,9 @@ get_params:
pop ds
cmp [input_file],0
je no_input_file
mov eax,[definitions_pointer]
mov byte [eax],0
mov [initial_definitions],predefinitions
clc
ret
bad_params:
......@@ -264,18 +288,61 @@ get_params:
no_input_file:
stc
ret
convert_definition_option:
mov ecx,edi
xor al,al
stosb
copy_definition_name:
lodsb
cmp al,'='
je copy_definition_value
cmp al,20h
je bad_definition_option
cmp al,0Dh
je bad_definition_option
or al,al
jz bad_definition_option
stosb
inc byte [es:ecx]
jnz copy_definition_name
bad_definition_option:
stc
ret
copy_definition_value:
lodsb
cmp al,20h
je definition_value_end
cmp al,0Dh
je definition_value_end
or al,al
jz definition_value_end
cmp al,'\'
jne definition_value_character
cmp byte [esi],20h
jne definition_value_character
lodsb
definition_value_character:
stosb
jmp copy_definition_value
definition_value_end:
dec esi
xor al,al
stosb
clc
ret
include '..\version.inc'
_logo db 'flat assembler version ',VERSION_STRING,24h
_copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0Dh,0Ah,0
_copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0Dh,0Ah,0
_usage db 0Dh,0Ah
db 'usage: fasm <source> [output]',0Dh,0Ah
db 'optional settings:',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -d <name>=<value> define symbolic variable',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db 0
_memory_prefix db ' (',0
_memory_suffix db ' kilobytes memory)',0Dh,0Ah,0
......@@ -346,7 +413,9 @@ include '..\variable.inc'
memory_setting dd ?
start_time dd ?
definitions_pointer dd ?
params rb 100h
predefinitions rb 100h
mode dw ?
real_mode_segment dw ?
......
; flat assembler interface for DOS
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
segment modes use16
......
; flat assembler interface for DOS
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
go32:
......@@ -439,8 +439,10 @@ fatal_error:
jmp exit_program
assembler_error:
call display_user_messages
push dword 0
mov ebx,[current_line]
test ebx,ebx
jz display_error_message
push dword 0
get_error_lines:
mov eax,[ebx]
cmp byte [eax],0
......@@ -544,6 +546,7 @@ assembler_error:
pop ebx
or ebx,ebx
jnz display_error_line
display_error_message:
mov esi,error_prefix
call display_string
pop esi
......
; flat assembler interface for Linux
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
format ELF executable 3
......@@ -115,6 +115,7 @@ get_params:
add ebx,8
dec ecx
jz bad_params
mov [definitions_pointer],predefinitions
get_param:
mov esi,[ebx]
mov al,[esi]
......@@ -140,6 +141,10 @@ get_params:
je passes_option
cmp al,'P'
je passes_option
cmp al,'d'
je definition_option
cmp al,'D'
je definition_option
cmp al,'s'
je symbols_option
cmp al,'S'
......@@ -182,8 +187,26 @@ get_params:
jnz get_param
cmp [input_file],0
je bad_params
mov eax,[definitions_pointer]
mov byte [eax],0
mov [initial_definitions],predefinitions
clc
ret
definition_option:
cmp byte [esi],0
jne get_definition
dec ecx
jz bad_params
add ebx,4
mov esi,[ebx]
get_definition:
push edi
mov edi,[definitions_pointer]
call convert_definition_option
mov [definitions_pointer],edi
pop edi
jc bad_params
jmp next_param
symbols_option:
cmp byte [esi],0
jne get_symbols_setting
......@@ -219,20 +242,53 @@ get_params:
invalid_option_value:
stc
ret
convert_definition_option:
mov edx,edi
xor al,al
stosb
copy_definition_name:
lodsb
cmp al,'='
je copy_definition_value
cmp al,20h
je bad_definition_option
or al,al
jz bad_definition_option
stosb
inc byte [edx]
jnz copy_definition_name
bad_definition_option:
stc
ret
copy_definition_value:
lodsb
cmp al,20h
je definition_value_end
or al,al
jz definition_value_end
stosb
jmp copy_definition_value
definition_value_end:
dec esi
xor al,al
stosb
clc
ret
include 'system.inc'
include '..\version.inc'
_copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0xA,0
_copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0xA,0
_logo db 'flat assembler version ',VERSION_STRING,0
_usage db 0xA
db 'usage: fasm <source> [output]',0xA
db 'optional settings:',0xA
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -d <name>=<value> define symbolic variable',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db 0
_memory_prefix db ' (',0
_memory_suffix db ' kilobytes memory)',0xA,0
......@@ -262,6 +318,7 @@ include '..\variable.inc'
command_line dd ?
memory_setting dd ?
definitions_pointer dd ?
environment dd ?
timestamp dq ?
start_time dd ?
......@@ -270,4 +327,5 @@ displayed_count dd ?
last_displayed db ?
character db ?
predefinitions rb 1000h
buffer rb 1000h
; flat assembler interface for Linux
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
O_ACCMODE = 0003o
......@@ -285,8 +285,10 @@ fatal_error:
assembler_error:
mov [con_handle],2
call display_user_messages
push dword 0
mov ebx,[current_line]
test ebx,ebx
jz display_error_message
push dword 0
get_error_lines:
mov eax,[ebx]
cmp byte [eax],0
......@@ -378,6 +380,7 @@ assembler_error:
pop ebx
or ebx,ebx
jnz display_error_line
display_error_message:
mov esi,error_prefix
call display_string
pop esi
......
; flat assembler interface for Win32
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
format PE console
......@@ -82,6 +82,7 @@ get_params:
mov [memory_setting],0
mov [passes_limit],100
call [GetCommandLine]
mov [definitions_pointer],predefinitions
mov esi,eax
mov edi,params
find_command_start:
......@@ -155,6 +156,10 @@ get_params:
je passes_option
cmp al,'P'
je passes_option
cmp al,'d'
je definition_option
cmp al,'D'
je definition_option
cmp al,'s'
je symbols_option
cmp al,'S'
......@@ -221,6 +226,22 @@ get_params:
ja bad_params
mov [passes_limit],dx
jmp find_param
definition_option:
lodsb
cmp al,20h
je definition_option
cmp al,0Dh
je bad_params
or al,al
jz bad_params
dec esi
push edi
mov edi,[definitions_pointer]
call convert_definition_option
mov [definitions_pointer],edi
pop edi
jc bad_params
jmp find_param
symbols_option:
mov [symbols_file],edi
find_symbols_file_name:
......@@ -237,6 +258,51 @@ get_params:
all_params:
cmp [input_file],0
je bad_params
mov eax,[definitions_pointer]
mov byte [eax],0
mov [initial_definitions],predefinitions
clc
ret
convert_definition_option:
mov ecx,edi
xor al,al
stosb
copy_definition_name:
lodsb
cmp al,'='
je copy_definition_value
cmp al,20h
je bad_definition_option
cmp al,0Dh
je bad_definition_option
or al,al
jz bad_definition_option
stosb
inc byte [ecx]
jnz copy_definition_name
bad_definition_option:
stc
ret
copy_definition_value:
lodsb
cmp al,20h
je definition_value_end
cmp al,0Dh
je definition_value_end
or al,al
jz definition_value_end
cmp al,'\'
jne definition_value_character
cmp byte [esi],20h
jne definition_value_character
lodsb
definition_value_character:
stosb
jmp copy_definition_value
definition_value_end:
dec esi
xor al,al
stosb
clc
ret
......@@ -260,15 +326,16 @@ section '.data' data readable writeable
include '..\version.inc'
_copyright db 'Copyright (c) 1999-2014, Tomasz Grysztar',0Dh,0Ah,0
_copyright db 'Copyright (c) 1999-2015, Tomasz Grysztar',0Dh,0Ah,0
_logo db 'flat assembler version ',VERSION_STRING,0
_usage db 0Dh,0Ah
db 'usage: fasm <source> [output]',0Dh,0Ah
db 'optional settings:',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db ' -m <limit> set the limit in kilobytes for the available memory',0Dh,0Ah
db ' -p <limit> set the maximum allowed number of passes',0Dh,0Ah
db ' -d <name>=<value> define symbolic variable',0Dh,0Ah
db ' -s <file> dump symbolic information for debugging',0Dh,0Ah
db 0
_memory_prefix db ' (',0
_memory_suffix db ' kilobytes memory)',0Dh,0Ah,0
......@@ -283,6 +350,7 @@ include '..\variable.inc'
con_handle dd ?
memory_setting dd ?
start_time dd ?
definitions_pointer dd ?
bytes_count dd ?
displayed_count dd ?
character db ?
......@@ -290,6 +358,7 @@ last_displayed rb 2
params rb 1000h
options rb 1000h
predefinitions rb 1000h
buffer rb 4000h
stack 10000h
......
; flat assembler interface for Win32
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
CREATE_NEW = 1
......@@ -315,8 +315,10 @@ fatal_error:
assembler_error:
mov [con_handle],STD_ERROR_HANDLE
call display_user_messages
push dword 0
mov ebx,[current_line]
test ebx,ebx
jz display_error_message
push dword 0
get_error_lines:
mov eax,[ebx]
cmp byte [eax],0
......@@ -408,6 +410,7 @@ assembler_error:
pop ebx
or ebx,ebx
jnz display_error_line
display_error_message:
mov esi,error_prefix
call display_string
pop esi
......
; flat assembler core
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
assembler:
......@@ -329,31 +329,10 @@ assemble_line:
cmp eax,0Fh
jb invalid_use_of_symbol
je reserved_word_used_as_symbol
mov edx,[eax+8]
push edx
cmp [current_pass],0
je get_constant_value
test dl,4
jnz get_constant_value
mov cx,[current_pass]
cmp cx,[eax+16]
je get_constant_value
or dl,4
mov [eax+8],dl
get_constant_value:
push eax
mov al,byte [esi-1]
push eax
or [size_override],-1
call get_value
pop ebx
mov ch,bl
pop ebx
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
......@@ -453,15 +432,15 @@ assemble_line:
or byte [ebx+0Ah],2
jmp continue_line
assemble_instruction:
; mov [operand_size],0
; mov [size_override],0
; mov [operand_prefix],0
; mov [opcode_prefix],0
; mov [operand_size],0
; mov [size_override],0
; mov [operand_prefix],0
; mov [opcode_prefix],0
and dword [operand_size],0
; mov [rex_prefix],0
; mov [vex_required],0
; mov [vex_register],0
; mov [immediate_size],0
; mov [rex_prefix],0
; mov [vex_required],0
; mov [vex_register],0
; mov [immediate_size],0
and dword [rex_prefix],0
call instruction_handler
instruction_handler:
......
; flat assembler core
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
avx_single_source_pd_instruction:
......
; flat assembler core
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
out_of_memory:
......@@ -24,6 +24,9 @@ code_cannot_be_generated:
jmp general_error
format_limitations_exceeded:
push _format_limitations_exceeded
jmp general_error
invalid_definition:
push _invalid_definition
general_error:
cmp [symbols_file],0
je fatal_error
......
; flat assembler core
; Copyright (c) 1999-2014, Tomasz Grysztar.
; Copyright (c) 1999-2015, Tomasz Grysztar.
; All rights reserved.
calculate_expression:
......@@ -11,6 +11,10 @@ calculate_expression:
cmp byte [esi],'.'
je convert_fp
calculation_loop:
mov eax,[tagged_blocks]
sub eax,0Ch
cmp eax,edi
jbe out_of_memory
lods byte [esi]
cmp al,1
je get_byte_number
......@@ -35,12 +39,16 @@ calculate_expression:
sub edi,14h
mov ebx,edi
sub ebx,14h
cmp al,0E0h
cmp al,0F0h
je calculate_rva
cmp al,0E1h
cmp al,0F1h
je calculate_plt
cmp al,0D0h
je calculate_not
cmp al,0E0h
je calculate_bsf
cmp al,0E1h
je calculate_bsr
cmp al,083h
je calculate_neg
mov dx,[ebx+8]
......@@ -622,76 +630,6 @@ calculate_expression:
xor [ebx],eax
xor [ebx+4],edx
xor [ebx+13],cl
jz calculation_loop
or cl,cl
jz xor_size_check
xor eax,[ebx]
xor edx,[ebx+4]
xor_size_check:
mov cl,[value_size]
cmp cl,1
je xor_byte_result
cmp cl,2
je xor_word_result
cmp cl,4
je xor_dword_result
cmp cl,6
je xor_pword_result
cmp cl,8
jne calculation_loop
xor edx,[ebx+4]
js xor_result_truncated
jmp calculation_loop
xor_pword_result:
test edx,0FFFF0000h
jnz calculation_loop
cmp word [ebx+6],-1
jne calculation_loop
xor dx,[ebx+4]
jns calculation_loop
not word [ebx+6]
jmp xor_result_truncated
xor_dword_result:
test edx,edx
jnz calculation_loop
cmp dword [ebx+4],-1
jne calculation_loop
xor eax,[ebx]
jns calculation_loop
not dword [ebx+4]
jmp xor_result_truncated
xor_word_result:
test edx,edx
jnz calculation_loop
test eax,0FFFF0000h
jnz calculation_loop
cmp dword [ebx+4],-1
jne calculation_loop
cmp word [ebx+2],-1
jne calculation_loop
xor ax,[ebx]
jns calculation_loop
not dword [ebx+4]
not word [ebx+2]
jmp xor_result_truncated
xor_byte_result:
test edx,edx
jnz calculation_loop
test eax,0FFFFFF00h
jnz calculation_loop
cmp dword [ebx+4],-1
jne calculation_loop
cmp word [ebx+2],-1
jne calculation_loop
cmp byte [ebx+1],-1
jne calculation_loop
xor al,[ebx]
jns calculation_loop
not dword [ebx+4]
not word [ebx+2]
not byte [ebx+1]