add flat assembler toolchain
This commit is contained in:
229
toolchain/fasmw17332/TOOLS/WIN32/LISTING.ASM
Normal file
229
toolchain/fasmw17332/TOOLS/WIN32/LISTING.ASM
Normal file
@ -0,0 +1,229 @@
|
||||
|
||||
format PE console 4.0
|
||||
entry start
|
||||
|
||||
include 'win32a.inc'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
_usage db 'listing generator for flat assembler',0Dh,0Ah
|
||||
db 'usage: listing <input> <output>',0Dh,0Ah
|
||||
db 'optional settings:',0Dh,0Ah
|
||||
db ' -a show target addresses for assembled code',0Dh,0Ah
|
||||
db ' -b <number> set the amount of bytes listed per line',0Dh,0Ah
|
||||
db 0
|
||||
_error_prefix db 'error: ',0
|
||||
_error_suffix db '.',0Dh,0Ah,0
|
||||
|
||||
line_break db 0Dh,0Ah
|
||||
|
||||
input_file dd 0
|
||||
output_file dd 0
|
||||
code_bytes_per_line dd 16
|
||||
show_addresses db 0
|
||||
|
||||
input dd ?
|
||||
assembled_code dd ?
|
||||
assembled_code_length dd ?
|
||||
code_end dd ?
|
||||
code_offset dd ?
|
||||
code_length dd ?
|
||||
output_handle dd ?
|
||||
output_buffer dd ?
|
||||
current_source_file dd ?
|
||||
current_source_line dd ?
|
||||
source dd ?
|
||||
source_length dd ?
|
||||
maximum_address_length dd ?
|
||||
address_start dd ?
|
||||
last_listed_address dd ?
|
||||
|
||||
display_handle dd ?
|
||||
bytes_count dd ?
|
||||
|
||||
params rb 1000h
|
||||
characters rb 100h
|
||||
|
||||
section '.text' code readable executable
|
||||
|
||||
start:
|
||||
|
||||
mov [display_handle],STD_OUTPUT_HANDLE
|
||||
|
||||
call get_params
|
||||
jnc make_listing
|
||||
|
||||
mov esi,_usage
|
||||
call display_string
|
||||
invoke ExitProcess,2
|
||||
|
||||
make_listing:
|
||||
call listing
|
||||
invoke ExitProcess,0
|
||||
|
||||
error:
|
||||
mov [display_handle],STD_ERROR_HANDLE
|
||||
mov esi,_error_prefix
|
||||
call display_string
|
||||
pop esi
|
||||
call display_string
|
||||
mov esi,_error_suffix
|
||||
call display_string
|
||||
invoke ExitProcess,1
|
||||
|
||||
get_params:
|
||||
invoke GetCommandLine
|
||||
mov esi,eax
|
||||
mov edi,params
|
||||
find_command_start:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_command_start
|
||||
cmp al,22h
|
||||
je skip_quoted_name
|
||||
skip_name:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_name
|
||||
skip_quoted_name:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_quoted_name
|
||||
find_param:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
cmp al,'-'
|
||||
je option_param
|
||||
cmp al,0Dh
|
||||
je all_params
|
||||
or al,al
|
||||
jz all_params
|
||||
cmp [input_file],0
|
||||
jne get_output_file
|
||||
mov [input_file],edi
|
||||
jmp process_param
|
||||
get_output_file:
|
||||
cmp [output_file],0
|
||||
jne bad_params
|
||||
mov [output_file],edi
|
||||
process_param:
|
||||
cmp al,22h
|
||||
je string_param
|
||||
copy_param:
|
||||
stosb
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
jmp copy_param
|
||||
string_param:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je string_param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
stosb
|
||||
jmp string_param
|
||||
option_param:
|
||||
lodsb
|
||||
cmp al,'a'
|
||||
je addresses_option
|
||||
cmp al,'A'
|
||||
je addresses_option
|
||||
cmp al,'b'
|
||||
je bytes_per_line_option
|
||||
cmp al,'B'
|
||||
je bytes_per_line_option
|
||||
bad_params:
|
||||
stc
|
||||
ret
|
||||
get_option_value:
|
||||
xor eax,eax
|
||||
mov edx,eax
|
||||
get_option_digit:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je option_value_ok
|
||||
cmp al,0Dh
|
||||
je option_value_ok
|
||||
or al,al
|
||||
jz option_value_ok
|
||||
sub al,30h
|
||||
jc invalid_option_value
|
||||
cmp al,9
|
||||
ja invalid_option_value
|
||||
imul edx,10
|
||||
jo invalid_option_value
|
||||
add edx,eax
|
||||
jc invalid_option_value
|
||||
jmp get_option_digit
|
||||
option_value_ok:
|
||||
dec esi
|
||||
clc
|
||||
ret
|
||||
invalid_option_value:
|
||||
stc
|
||||
ret
|
||||
bytes_per_line_option:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je bytes_per_line_option
|
||||
cmp al,0Dh
|
||||
je bad_params
|
||||
or al,al
|
||||
jz bad_params
|
||||
dec esi
|
||||
call get_option_value
|
||||
or edx,edx
|
||||
jz bad_params
|
||||
cmp edx,1000
|
||||
ja bad_params
|
||||
mov [code_bytes_per_line],edx
|
||||
jmp find_param
|
||||
addresses_option:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je set_addresses_option
|
||||
cmp al,0Dh
|
||||
je set_addresses_option
|
||||
or al,al
|
||||
jnz bad_params
|
||||
set_addresses_option:
|
||||
dec esi
|
||||
mov [show_addresses],1
|
||||
jmp find_param
|
||||
param_end:
|
||||
dec esi
|
||||
string_param_end:
|
||||
xor al,al
|
||||
stosb
|
||||
jmp find_param
|
||||
all_params:
|
||||
cmp [input_file],0
|
||||
je bad_params
|
||||
cmp [output_file],0
|
||||
je bad_params
|
||||
clc
|
||||
ret
|
||||
|
||||
include 'system.inc'
|
||||
|
||||
include '..\listing.inc'
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel32,'KERNEL32.DLL'
|
||||
|
||||
include 'api\kernel32.inc'
|
138
toolchain/fasmw17332/TOOLS/WIN32/PREPSRC.ASM
Normal file
138
toolchain/fasmw17332/TOOLS/WIN32/PREPSRC.ASM
Normal file
@ -0,0 +1,138 @@
|
||||
|
||||
format PE console 4.0
|
||||
entry start
|
||||
|
||||
include 'win32a.inc'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
_usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah
|
||||
db 'usage: prepsrc <input> <output>',0Dh,0Ah
|
||||
db 0
|
||||
_error_prefix db 'error: ',0
|
||||
_error_suffix db '.',0Dh,0Ah,0
|
||||
|
||||
input_file dd 0
|
||||
output_file dd 0
|
||||
|
||||
display_handle dd ?
|
||||
bytes_count dd ?
|
||||
|
||||
params rb 1000h
|
||||
|
||||
section '.text' code readable executable
|
||||
|
||||
start:
|
||||
|
||||
mov [display_handle],STD_OUTPUT_HANDLE
|
||||
|
||||
call get_params
|
||||
jnc make_dump
|
||||
|
||||
mov esi,_usage
|
||||
call display_string
|
||||
invoke ExitProcess,2
|
||||
|
||||
make_dump:
|
||||
call preprocessed_source
|
||||
invoke ExitProcess,0
|
||||
|
||||
error:
|
||||
mov [display_handle],STD_ERROR_HANDLE
|
||||
mov esi,_error_prefix
|
||||
call display_string
|
||||
pop esi
|
||||
call display_string
|
||||
mov esi,_error_suffix
|
||||
call display_string
|
||||
invoke ExitProcess,1
|
||||
|
||||
get_params:
|
||||
invoke GetCommandLine
|
||||
mov esi,eax
|
||||
mov edi,params
|
||||
find_command_start:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_command_start
|
||||
cmp al,22h
|
||||
je skip_quoted_name
|
||||
skip_name:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_name
|
||||
skip_quoted_name:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_quoted_name
|
||||
find_param:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
cmp al,0Dh
|
||||
je all_params
|
||||
or al,al
|
||||
jz all_params
|
||||
cmp [input_file],0
|
||||
jne get_output_file
|
||||
mov [input_file],edi
|
||||
jmp process_param
|
||||
get_output_file:
|
||||
cmp [output_file],0
|
||||
jne bad_params
|
||||
mov [output_file],edi
|
||||
process_param:
|
||||
cmp al,22h
|
||||
je string_param
|
||||
copy_param:
|
||||
stosb
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
jmp copy_param
|
||||
string_param:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je string_param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
stosb
|
||||
jmp string_param
|
||||
bad_params:
|
||||
stc
|
||||
ret
|
||||
param_end:
|
||||
dec esi
|
||||
string_param_end:
|
||||
xor al,al
|
||||
stosb
|
||||
jmp find_param
|
||||
all_params:
|
||||
cmp [input_file],0
|
||||
je bad_params
|
||||
cmp [output_file],0
|
||||
je bad_params
|
||||
clc
|
||||
ret
|
||||
|
||||
include 'system.inc'
|
||||
|
||||
include '..\prepsrc.inc'
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel32,'KERNEL32.DLL'
|
||||
|
||||
include 'api\kernel32.inc'
|
142
toolchain/fasmw17332/TOOLS/WIN32/SYMBOLS.ASM
Normal file
142
toolchain/fasmw17332/TOOLS/WIN32/SYMBOLS.ASM
Normal file
@ -0,0 +1,142 @@
|
||||
|
||||
format PE console 4.0
|
||||
entry start
|
||||
|
||||
include 'win32a.inc'
|
||||
|
||||
section '.data' data readable writeable
|
||||
|
||||
_usage db 'symbols dumper for flat assembler',0Dh,0Ah
|
||||
db 'usage: symbols <input> <output>',0Dh,0Ah
|
||||
db 0
|
||||
_error_prefix db 'error: ',0
|
||||
_error_suffix db '.',0Dh,0Ah,0
|
||||
|
||||
input_file dd 0
|
||||
output_file dd 0
|
||||
|
||||
input dd ?
|
||||
output_buffer dd ?
|
||||
output_handle dd ?
|
||||
|
||||
display_handle dd ?
|
||||
bytes_count dd ?
|
||||
|
||||
params rb 1000h
|
||||
|
||||
section '.text' code readable executable
|
||||
|
||||
start:
|
||||
|
||||
mov [display_handle],STD_OUTPUT_HANDLE
|
||||
|
||||
call get_params
|
||||
jnc make_dump
|
||||
|
||||
mov esi,_usage
|
||||
call display_string
|
||||
invoke ExitProcess,2
|
||||
|
||||
make_dump:
|
||||
call symbols
|
||||
invoke ExitProcess,0
|
||||
|
||||
error:
|
||||
mov [display_handle],STD_ERROR_HANDLE
|
||||
mov esi,_error_prefix
|
||||
call display_string
|
||||
pop esi
|
||||
call display_string
|
||||
mov esi,_error_suffix
|
||||
call display_string
|
||||
invoke ExitProcess,1
|
||||
|
||||
get_params:
|
||||
invoke GetCommandLine
|
||||
mov esi,eax
|
||||
mov edi,params
|
||||
find_command_start:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_command_start
|
||||
cmp al,22h
|
||||
je skip_quoted_name
|
||||
skip_name:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_name
|
||||
skip_quoted_name:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je find_param
|
||||
or al,al
|
||||
jz all_params
|
||||
jmp skip_quoted_name
|
||||
find_param:
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je find_param
|
||||
cmp al,0Dh
|
||||
je all_params
|
||||
or al,al
|
||||
jz all_params
|
||||
cmp [input_file],0
|
||||
jne get_output_file
|
||||
mov [input_file],edi
|
||||
jmp process_param
|
||||
get_output_file:
|
||||
cmp [output_file],0
|
||||
jne bad_params
|
||||
mov [output_file],edi
|
||||
process_param:
|
||||
cmp al,22h
|
||||
je string_param
|
||||
copy_param:
|
||||
stosb
|
||||
lodsb
|
||||
cmp al,20h
|
||||
je param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
jmp copy_param
|
||||
string_param:
|
||||
lodsb
|
||||
cmp al,22h
|
||||
je string_param_end
|
||||
cmp al,0Dh
|
||||
je param_end
|
||||
or al,al
|
||||
jz param_end
|
||||
stosb
|
||||
jmp string_param
|
||||
bad_params:
|
||||
stc
|
||||
ret
|
||||
param_end:
|
||||
dec esi
|
||||
string_param_end:
|
||||
xor al,al
|
||||
stosb
|
||||
jmp find_param
|
||||
all_params:
|
||||
cmp [input_file],0
|
||||
je bad_params
|
||||
cmp [output_file],0
|
||||
je bad_params
|
||||
clc
|
||||
ret
|
||||
|
||||
include 'system.inc'
|
||||
|
||||
include '..\symbols.inc'
|
||||
|
||||
section '.idata' import data readable writeable
|
||||
|
||||
library kernel32,'KERNEL32.DLL'
|
||||
|
||||
include 'api\kernel32.inc'
|
66
toolchain/fasmw17332/TOOLS/WIN32/SYSTEM.INC
Normal file
66
toolchain/fasmw17332/TOOLS/WIN32/SYSTEM.INC
Normal file
@ -0,0 +1,66 @@
|
||||
|
||||
display_string:
|
||||
invoke GetStdHandle,[display_handle]
|
||||
mov edx,eax
|
||||
mov edi,esi
|
||||
or ecx,-1
|
||||
xor al,al
|
||||
repne scasb
|
||||
neg ecx
|
||||
sub ecx,2
|
||||
invoke WriteFile,edx,esi,ecx,bytes_count,0
|
||||
retn
|
||||
alloc:
|
||||
invoke VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE
|
||||
or eax,eax
|
||||
jz allocation_error
|
||||
clc
|
||||
retn
|
||||
allocation_error:
|
||||
stc
|
||||
retn
|
||||
free:
|
||||
invoke VirtualFree,eax,0,MEM_RELEASE
|
||||
retn
|
||||
open:
|
||||
invoke CreateFile,edx,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0
|
||||
cmp eax,-1
|
||||
je file_error
|
||||
mov ebx,eax
|
||||
clc
|
||||
retn
|
||||
file_error:
|
||||
stc
|
||||
retn
|
||||
create:
|
||||
invoke CreateFile,edx,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0
|
||||
cmp eax,-1
|
||||
je file_error
|
||||
mov ebx,eax
|
||||
clc
|
||||
retn
|
||||
write:
|
||||
invoke WriteFile,ebx,edx,ecx,bytes_count,0
|
||||
or eax,eax
|
||||
jz file_error
|
||||
clc
|
||||
retn
|
||||
read:
|
||||
push ecx
|
||||
invoke ReadFile,ebx,edx,ecx,bytes_count,0
|
||||
pop edx
|
||||
or eax,eax
|
||||
jz file_error
|
||||
cmp edx,[bytes_count]
|
||||
jne file_error
|
||||
clc
|
||||
retn
|
||||
close:
|
||||
invoke CloseHandle,ebx
|
||||
retn
|
||||
lseek:
|
||||
movzx eax,al
|
||||
invoke SetFilePointer,ebx,edx,0,eax
|
||||
cmp eax,-1
|
||||
je file_error
|
||||
retn
|
Reference in New Issue
Block a user