├── fasm ├── objconv ├── fasm_new_32.o ├── fasm_new_32_m.o ├── fasm_src ├── fasm.o ├── examples │ └── libcdemo │ │ ├── libcdemo.o │ │ ├── ccall.inc │ │ └── libcdemo.asm ├── readme.txt ├── tools │ ├── libc │ │ ├── ccall.inc │ │ ├── prepsrc.asm │ │ ├── symbols.asm │ │ ├── system.inc │ │ └── listing.asm │ ├── readme.txt │ ├── win32 │ │ ├── system.inc │ │ ├── prepsrc.asm │ │ ├── symbols.asm │ │ └── listing.asm │ ├── dos │ │ ├── loader.inc │ │ ├── prepsrc.asm │ │ ├── symbols.asm │ │ ├── system.inc │ │ └── listing.asm │ ├── prepsrc.inc │ └── symbols.inc ├── license.txt └── source │ ├── version.inc │ ├── DOS │ ├── dpmi.inc │ ├── fasm.asm │ └── system.inc │ ├── messages.inc │ ├── variable.inc │ ├── Linux │ ├── x64 │ │ ├── modes.inc │ │ ├── fasm.asm │ │ └── system.inc │ ├── fasm.asm │ └── system.inc │ ├── errors.inc │ ├── libc │ ├── fasm.asm │ └── system.inc │ ├── Win32 │ ├── fasm.asm │ └── system.inc │ └── symbdump.inc ├── objconv_src ├── extras.zip ├── objconv.exe ├── source.zip ├── source │ ├── macho.h │ ├── stdafx.cpp │ ├── build.sh │ ├── stdafx.h │ ├── error.h │ ├── maindef.h │ ├── library.h │ └── objconv.vcproj ├── objconv-instructions.pdf └── changelog.txt ├── README ├── hello32.asm ├── hello64.asm └── USAGE /fasm: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/fasm -------------------------------------------------------------------------------- /objconv: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv -------------------------------------------------------------------------------- /fasm_new_32.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/fasm_new_32.o -------------------------------------------------------------------------------- /fasm_new_32_m.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/fasm_new_32_m.o -------------------------------------------------------------------------------- /fasm_src/fasm.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/fasm_src/fasm.o -------------------------------------------------------------------------------- /objconv_src/extras.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv_src/extras.zip -------------------------------------------------------------------------------- /objconv_src/objconv.exe: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv_src/objconv.exe -------------------------------------------------------------------------------- /objconv_src/source.zip: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv_src/source.zip -------------------------------------------------------------------------------- /objconv_src/source/macho.h: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv_src/source/macho.h -------------------------------------------------------------------------------- /objconv_src/objconv-instructions.pdf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/objconv_src/objconv-instructions.pdf -------------------------------------------------------------------------------- /fasm_src/examples/libcdemo/libcdemo.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/JohnDDuncanIII/fasm/HEAD/fasm_src/examples/libcdemo/libcdemo.o -------------------------------------------------------------------------------- /objconv_src/source/stdafx.cpp: -------------------------------------------------------------------------------- 1 | // stdafx.cpp : source file that includes just the standard includes 2 | // objconv.pch will be the pre-compiled header 3 | // stdafx.obj will contain the pre-compiled type information 4 | 5 | #include "stdafx.h" 6 | -------------------------------------------------------------------------------- /fasm_src/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | The fasm.o is an object file in ELF format. To get the final executable for 3 | your system, you need to use the appropriate tool to link it with the C 4 | library available on your platform. With the GNU tools it is enough to use 5 | this command: 6 | 7 | gcc fasm.o -o fasm 8 | -------------------------------------------------------------------------------- /fasm_src/examples/libcdemo/ccall.inc: -------------------------------------------------------------------------------- 1 | 2 | macro ccall proc,[arg] 3 | { common 4 | local size 5 | size = 0 6 | mov ebp,esp 7 | if ~ arg eq 8 | forward 9 | size = size + 4 10 | common 11 | sub esp,size 12 | end if 13 | and esp,-16 14 | if ~ arg eq 15 | add esp,size 16 | reverse 17 | pushd arg 18 | common 19 | end if 20 | call proc 21 | mov esp,ebp } 22 | 23 | -------------------------------------------------------------------------------- /fasm_src/tools/libc/ccall.inc: -------------------------------------------------------------------------------- 1 | 2 | macro ccall proc,[arg] 3 | { common 4 | push ebp 5 | mov ebp,esp 6 | local size 7 | size = 0 8 | if ~ arg eq 9 | forward 10 | size = size + 4 11 | common 12 | sub esp,size 13 | end if 14 | and esp,-16 15 | if ~ arg eq 16 | add esp,size 17 | reverse 18 | pushd arg 19 | common 20 | end if 21 | call proc 22 | leave } 23 | 24 | -------------------------------------------------------------------------------- /objconv_src/source/build.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # Build script for building objconv on Linux, BSD and Mac OS X platforms. 4 | 5 | # Instructions: 6 | 7 | # You may need to change the path to bash above as required by your system 8 | 9 | # Make sure the current directory contains all the .cpp files for objconv, 10 | # and only one copy of each, and no other .cpp files 11 | 12 | # Then run ./build.sh 13 | # The compilation may take half a minute. 14 | 15 | # Alternatively, run the following line: 16 | 17 | g++ -o objconv -O2 *.cpp 18 | -------------------------------------------------------------------------------- /README: -------------------------------------------------------------------------------- 1 | # fasm-osx 2 | flat assembler - the open source assembly language compiler for x86 and x86-64 processors 3 | 4 | This repository contains a flat assembler version that will run on Macintosh OS X 10.6-10.11. 5 | 6 | the fasm version included in this repository (1.71.51) has succesfully assembled the 64-bit `rwasa' web-server fomr the [HeavyThing library](https://2ton.com.au/HeavyThing/) on OS X 10.11 El-Capitan. 7 | 8 | # Inspired/taken from: 9 | http://board.flatassembler.net/topic.php?t=13413 10 | http://board.flatassembler.net/topic.php?t=9954 -------------------------------------------------------------------------------- /fasm_src/examples/libcdemo/libcdemo.asm: -------------------------------------------------------------------------------- 1 | 2 | ; fasm example of using the C library in Unix systems 3 | 4 | ; compile the source with commands like: 5 | ; fasm libcdemo.asm libcdemo.o 6 | ; gcc libcdemo.o -o libcdemo 7 | ; strip libcdemo 8 | 9 | format ELF 10 | 11 | include 'ccall.inc' 12 | 13 | section '.text' executable 14 | 15 | public main 16 | extrn printf 17 | extrn getpid 18 | 19 | main: 20 | call getpid 21 | ccall printf, msg,eax 22 | ret 23 | 24 | section '.data' writeable 25 | 26 | msg db "Current process ID is %d.",0xA,0 27 | -------------------------------------------------------------------------------- /hello32.asm: -------------------------------------------------------------------------------- 1 | format ELF 2 | section '.text' executable 3 | public main 4 | extrn printf 5 | extrn exit 6 | struc db [data] 7 | { 8 | common 9 | . db data 10 | .size = $ - . 11 | } 12 | 13 | main: 14 | push ebp 15 | mov ebp, esp 16 | push ebx 17 | mov ebx, esp 18 | and esp, 0xfffffff0 19 | sub esp, 12 20 | push ebx 21 | add esp, 16 22 | 23 | mov dword [esp], msgHelloWorld 24 | call printf 25 | 26 | sub esp, 16 27 | pop ebx 28 | mov esp, ebx 29 | pop ebx 30 | mov esp, ebp 31 | pop ebp 32 | mov eax, 0 33 | ret 34 | section '.data' writeable 35 | msgHelloWorld db 'Hello world from FASM!',0xA,0 -------------------------------------------------------------------------------- /hello64.asm: -------------------------------------------------------------------------------- 1 | format ELF64 2 | 3 | section '.text' executable 4 | public main 5 | extrn printf 6 | extrn exit 7 | 8 | ;macro for create .size constant automatically 9 | struc db [data]{ 10 | common 11 | . db data 12 | .size = $ - . 13 | } 14 | 15 | ;testing using syscall 16 | 17 | main: 18 | mov rax, 0x2000004 ; sys_write 19 | mov rdi, 1 ; stdout 20 | mov rsi, qword msgHelloWorld ; string 21 | mov rdx, msgHelloWorld.size ; length 22 | syscall 23 | mov rax, 0x2000001 ; sys_exit 24 | xor rdi, rdi ; exit code 25 | syscall 26 | 27 | 28 | section '.data' writeable 29 | msgHelloWorld db 'Hello 64bit World from FASM!',0x0A,0 30 | -------------------------------------------------------------------------------- /USAGE: -------------------------------------------------------------------------------- 1 | COMPILE OSX 32bits "Hello World" 2 | -------------------------------- 3 | 4 | ./fasm hello32.asm hello32.o 5 | ./objconv -fmacho32 -nu hello32.o hello32_m.o 6 | ld -arch i386 -macosx_version_min 10.6 -o hello32 hello32_m.o /usr/lib/crt1.o /usr/lib/libc.dylib 7 | file hello32 8 | ./hello32 9 | 10 | COMPILE OSX 64bits "Hello World" 11 | -------------------------------- 12 | 13 | ./fasm hello64.asm hello64.o 14 | ./objconv -fmacho64 -nu hello64.o hello64_m.o 15 | ld -arch x86_64 -macosx_version_min 10.6 -o hello64 hello64_m.o /usr/lib/crt1.o /usr/lib/libc.dylib 16 | file hello64 17 | ./hello64 18 | 19 | COMPILE fasm 20 | -------------------------------- 21 | ./fasm fasm_src/source/libc/fasm.asm fasm_new_32.o 22 | ./objconv -fmac -nu fasm_new_32.o fasm_new_32_m.o 23 | ld -arch i386 -macosx_version_min 10.6 -o fasm_32_new fasm_new_32_m.o /usr/lib/crt1.o /usr/lib/libc.dylib 24 | file fasm 25 | ./fasm 26 | -------------------------------------------------------------------------------- /fasm_src/tools/readme.txt: -------------------------------------------------------------------------------- 1 | 2 | This directory contains some tools, which extract various types of information 3 | from the symbolic information file generated by flat assembler, and present 4 | them in a human-readable form. 5 | 6 | The listing tool creates a listing of assembled code - this tool needs to be 7 | executed in the exact configuration, in which the assembly was taking place. 8 | All the source files and the output file aswell must not have been moved or 9 | modified - if any of them was altered before generating the listing, it is 10 | going to contain garbage instead of useful information. For example, if you 11 | assembled the file with the command like: 12 | 13 | fasm example.asm example.exe -s example.fas 14 | 15 | you should generate listing by immediately running this command from the same 16 | directory: 17 | 18 | listing example.fas example.lst 19 | 20 | In addition, the "-a" switch is recommended to use in the case of executable 21 | formats, as it allows to get the run-time addresses for all the assembled code 22 | and data. 23 | 24 | The preprocessed source and symbols dump tools are simpler ones - they only 25 | need the symbolic information file as input and generate proper output text 26 | regardless of the availability of other files. 27 | -------------------------------------------------------------------------------- /fasm_src/tools/win32/system.inc: -------------------------------------------------------------------------------- 1 | 2 | display_string: 3 | invoke GetStdHandle,[display_handle] 4 | mov edx,eax 5 | mov edi,esi 6 | or ecx,-1 7 | xor al,al 8 | repne scasb 9 | neg ecx 10 | sub ecx,2 11 | invoke WriteFile,edx,esi,ecx,bytes_count,0 12 | retn 13 | alloc: 14 | invoke VirtualAlloc,0,eax,MEM_COMMIT,PAGE_READWRITE 15 | or eax,eax 16 | jz allocation_error 17 | clc 18 | retn 19 | allocation_error: 20 | stc 21 | retn 22 | free: 23 | invoke VirtualFree,eax,0,MEM_RELEASE 24 | retn 25 | open: 26 | invoke CreateFile,edx,GENERIC_READ,FILE_SHARE_READ,0,OPEN_EXISTING,0,0 27 | cmp eax,-1 28 | je file_error 29 | mov ebx,eax 30 | clc 31 | retn 32 | file_error: 33 | stc 34 | retn 35 | create: 36 | invoke CreateFile,edx,GENERIC_WRITE,0,0,CREATE_ALWAYS,0,0 37 | cmp eax,-1 38 | je file_error 39 | mov ebx,eax 40 | clc 41 | retn 42 | write: 43 | invoke WriteFile,ebx,edx,ecx,bytes_count,0 44 | or eax,eax 45 | jz file_error 46 | clc 47 | retn 48 | read: 49 | push ecx 50 | invoke ReadFile,ebx,edx,ecx,bytes_count,0 51 | pop edx 52 | or eax,eax 53 | jz file_error 54 | cmp edx,[bytes_count] 55 | jne file_error 56 | clc 57 | retn 58 | close: 59 | invoke CloseHandle,ebx 60 | retn 61 | lseek: 62 | movzx eax,al 63 | invoke SetFilePointer,ebx,edx,0,eax 64 | cmp eax,-1 65 | je file_error 66 | retn 67 | -------------------------------------------------------------------------------- /fasm_src/tools/libc/prepsrc.asm: -------------------------------------------------------------------------------- 1 | 2 | format ELF 3 | public main 4 | 5 | include 'ccall.inc' 6 | 7 | section '.text' executable align 16 8 | 9 | main: 10 | mov ecx,[esp+4] 11 | mov [argc],ecx 12 | mov ebx,[esp+8] 13 | mov [argv],ebx 14 | 15 | mov [display_handle],1 16 | 17 | call get_params 18 | jnc make_dump 19 | 20 | mov esi,_usage 21 | call display_string 22 | ccall exit,2 23 | 24 | make_dump: 25 | call preprocessed_source 26 | ccall exit,0 27 | 28 | error: 29 | mov [display_handle],2 30 | mov esi,_error_prefix 31 | call display_string 32 | pop esi 33 | call display_string 34 | mov esi,_error_suffix 35 | call display_string 36 | ccall exit,0 37 | 38 | get_params: 39 | mov ecx,[argc] 40 | mov ebx,[argv] 41 | add ebx,4 42 | dec ecx 43 | jz bad_params 44 | get_param: 45 | mov esi,[ebx] 46 | mov al,[esi] 47 | cmp [input_file],0 48 | jne get_output_file 49 | mov [input_file],esi 50 | jmp next_param 51 | get_output_file: 52 | cmp [output_file],0 53 | jne bad_params 54 | mov [output_file],esi 55 | jmp next_param 56 | bad_params: 57 | stc 58 | ret 59 | next_param: 60 | add ebx,4 61 | dec ecx 62 | jnz get_param 63 | cmp [input_file],0 64 | je bad_params 65 | cmp [output_file],0 66 | je bad_params 67 | clc 68 | ret 69 | 70 | include 'system.inc' 71 | 72 | include '..\prepsrc.inc' 73 | 74 | section '.data' writeable align 4 75 | 76 | input_file dd 0 77 | output_file dd 0 78 | 79 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah 80 | db 'usage: prepsrc ',0Dh,0Ah 81 | db 0 82 | _error_prefix db 'error: ',0 83 | _error_suffix db '.',0Dh,0Ah,0 84 | 85 | section '.bss' writeable align 4 86 | 87 | argc dd ? 88 | argv dd ? 89 | 90 | display_handle dd ? 91 | character db ? 92 | 93 | params rb 1000h 94 | buffer rb 1000h 95 | -------------------------------------------------------------------------------- /fasm_src/tools/libc/symbols.asm: -------------------------------------------------------------------------------- 1 | 2 | format ELF 3 | public main 4 | 5 | include 'ccall.inc' 6 | 7 | section '.text' executable align 16 8 | 9 | main: 10 | mov ecx,[esp+4] 11 | mov [argc],ecx 12 | mov ebx,[esp+8] 13 | mov [argv],ebx 14 | 15 | mov [display_handle],1 16 | 17 | call get_params 18 | jnc make_dump 19 | 20 | mov esi,_usage 21 | call display_string 22 | ccall exit,2 23 | 24 | make_dump: 25 | call symbols 26 | ccall exit,0 27 | 28 | error: 29 | mov [display_handle],2 30 | mov esi,_error_prefix 31 | call display_string 32 | pop esi 33 | call display_string 34 | mov esi,_error_suffix 35 | call display_string 36 | ccall exit,0 37 | 38 | get_params: 39 | mov ecx,[argc] 40 | mov ebx,[argv] 41 | add ebx,4 42 | dec ecx 43 | jz bad_params 44 | get_param: 45 | mov esi,[ebx] 46 | mov al,[esi] 47 | cmp [input_file],0 48 | jne get_output_file 49 | mov [input_file],esi 50 | jmp next_param 51 | get_output_file: 52 | cmp [output_file],0 53 | jne bad_params 54 | mov [output_file],esi 55 | jmp next_param 56 | bad_params: 57 | stc 58 | ret 59 | next_param: 60 | add ebx,4 61 | dec ecx 62 | jnz get_param 63 | cmp [input_file],0 64 | je bad_params 65 | cmp [output_file],0 66 | je bad_params 67 | clc 68 | ret 69 | 70 | include 'system.inc' 71 | 72 | include '..\symbols.inc' 73 | 74 | section '.data' writeable align 4 75 | 76 | input_file dd 0 77 | output_file dd 0 78 | 79 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 80 | db 'usage: symbols ',0Dh,0Ah 81 | db 0 82 | _error_prefix db 'error: ',0 83 | _error_suffix db '.',0Dh,0Ah,0 84 | 85 | section '.bss' writeable align 4 86 | 87 | input dd ? 88 | output_buffer dd ? 89 | output_handle dd ? 90 | 91 | argc dd ? 92 | argv dd ? 93 | 94 | display_handle dd ? 95 | character db ? 96 | 97 | params rb 1000h 98 | buffer rb 1000h 99 | -------------------------------------------------------------------------------- /fasm_src/license.txt: -------------------------------------------------------------------------------- 1 | 2 | flat assembler version 1.71 3 | Copyright (c) 1999-2016, Tomasz Grysztar. 4 | All rights reserved. 5 | 6 | This program is free for commercial and non-commercial use as long as 7 | the following conditions are adhered to. 8 | 9 | Copyright remains Tomasz Grysztar, and as such any Copyright notices 10 | in the code are not to be removed. 11 | 12 | Redistribution and use in source and binary forms, with or without 13 | modification, are permitted provided that the following conditions are 14 | met: 15 | 16 | 1. Redistributions of source code must retain the above copyright notice, 17 | this list of conditions and the following disclaimer. 18 | 2. Redistributions in binary form must reproduce the above copyright 19 | notice, this list of conditions and the following disclaimer in the 20 | documentation and/or other materials provided with the distribution. 21 | 22 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 23 | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 24 | TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 25 | PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 26 | CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 27 | EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 28 | PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 29 | PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 30 | LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 31 | NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 32 | SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 33 | 34 | The licence and distribution terms for any publically available 35 | version or derivative of this code cannot be changed. i.e. this code 36 | cannot simply be copied and put under another distribution licence 37 | (including the GNU Public Licence). 38 | -------------------------------------------------------------------------------- /fasm_src/source/version.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler version 1.71 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | ; 6 | ; This programs is free for commercial and non-commercial use as long as 7 | ; the following conditions are adhered to. 8 | ; 9 | ; Redistribution and use in source and binary forms, with or without 10 | ; modification, are permitted provided that the following conditions are 11 | ; met: 12 | ; 13 | ; 1. Redistributions of source code must retain the above copyright notice, 14 | ; this list of conditions and the following disclaimer. 15 | ; 2. Redistributions in binary form must reproduce the above copyright 16 | ; notice, this list of conditions and the following disclaimer in the 17 | ; documentation and/or other materials provided with the distribution. 18 | ; 19 | ; THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 20 | ; "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 21 | ; TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 22 | ; PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR 23 | ; CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 24 | ; EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 25 | ; PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 26 | ; PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 27 | ; LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 28 | ; NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 29 | ; SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 30 | ; 31 | ; The licence and distribution terms for any publically available 32 | ; version or derivative of this code cannot be changed. i.e. this code 33 | ; cannot simply be copied and put under another distribution licence 34 | ; (including the GNU Public Licence). 35 | 36 | VERSION_STRING equ "1.71.58" 37 | 38 | VERSION_MAJOR = 1 39 | VERSION_MINOR = 71 40 | -------------------------------------------------------------------------------- /fasm_src/tools/libc/system.inc: -------------------------------------------------------------------------------- 1 | 2 | extrn malloc 3 | extrn getenv 4 | extrn fopen 5 | extrn fclose 6 | extrn fread 7 | extrn fwrite 8 | extrn fseek 9 | extrn ftell 10 | extrn time 11 | extrn exit 12 | extrn 'free' as libc_free 13 | extrn 'write' as libc_write 14 | 15 | alloc: 16 | ccall malloc,eax 17 | test eax,eax 18 | jz allocation_failed 19 | clc 20 | ret 21 | allocation_failed: 22 | stc 23 | ret 24 | free: 25 | ccall libc_free,eax 26 | ret 27 | display_string: 28 | lodsb 29 | or al,al 30 | jz string_displayed 31 | mov dl,al 32 | call display_character 33 | jmp display_string 34 | string_displayed: 35 | ret 36 | display_character: 37 | mov [character],dl 38 | ccall libc_write,[display_handle],character,1 39 | ret 40 | open: 41 | push esi edi ebp 42 | call adapt_path 43 | ccall fopen,buffer,open_mode 44 | pop ebp edi esi 45 | or eax,eax 46 | jz file_error 47 | mov ebx,eax 48 | clc 49 | ret 50 | adapt_path: 51 | mov esi,edx 52 | mov edi,buffer 53 | copy_path: 54 | lods byte [esi] 55 | cmp al,'\' 56 | jne path_char_ok 57 | mov al,'/' 58 | path_char_ok: 59 | stos byte [edi] 60 | or al,al 61 | jnz copy_path 62 | cmp edi,buffer+1000h 63 | ja not_enough_memory 64 | ret 65 | create: 66 | push esi edi ebp 67 | call adapt_path 68 | ccall fopen,buffer,create_mode 69 | pop ebp edi esi 70 | or eax,eax 71 | jz file_error 72 | mov ebx,eax 73 | clc 74 | ret 75 | close: 76 | ccall fclose,ebx 77 | ret 78 | read: 79 | push ebx ecx edx esi edi 80 | ccall fread,edx,1,ecx,ebx 81 | pop edi esi edx ecx ebx 82 | cmp eax,ecx 83 | jne file_error 84 | clc 85 | ret 86 | file_error: 87 | stc 88 | ret 89 | write: 90 | push ebx ecx edx esi edi 91 | ccall fwrite,edx,1,ecx,ebx 92 | pop edi esi edx ecx ebx 93 | cmp eax,ecx 94 | jne file_error 95 | clc 96 | ret 97 | lseek: 98 | push ebx 99 | movzx eax,al 100 | ccall fseek,ebx,edx,eax 101 | mov ebx,[esp] 102 | ccall ftell,ebx 103 | pop ebx 104 | ret 105 | 106 | open_mode db 'r',0 107 | create_mode db 'w',0 108 | -------------------------------------------------------------------------------- /objconv_src/source/stdafx.h: -------------------------------------------------------------------------------- 1 | /**************************** stdafx.h ********************************** 2 | * Author: Agner Fog 3 | * Date created: 2006-07-15 4 | * Last modified: 2006-07-15 5 | * Project: objconv 6 | * Module: stdafx.h 7 | * Description: 8 | * Header file including other header files for the project. 9 | * 10 | * Copyright 2006-2008 GNU General Public License http://www.gnu.org/licenses 11 | *****************************************************************************/ 12 | 13 | #ifndef OBJCONV_STDAFX_H 14 | #define OBJCONV_STDAFX_H 15 | 16 | // System header files 17 | #include 18 | #include 19 | #include 20 | #include 21 | #ifdef _MSC_VER // For Microsoft compiler only: 22 | #include // File in/out function headers 23 | #include 24 | #include 25 | #define stricmp _stricmp // For later versions of MS compiler 26 | #define strnicmp _strnicmp // For later versions of MS compiler 27 | #define filelength _filelength // For later versions of MS compiler 28 | #else // For Gnu and other compilers: 29 | #define stricmp strcasecmp // Alternative function names 30 | #define strnicmp strncasecmp 31 | #endif 32 | 33 | // Project header files. The order of these files is not arbitrary. 34 | #include "maindef.h" // Constants, integer types, etc. 35 | #include "error.h" // Error handler 36 | #include "containers.h" // Classes for data buffers and dynamic memory allocation 37 | #include "coff.h" // COFF files structure 38 | #include "elf.h" // ELF files structure 39 | #include "omf.h" // OMF files structure 40 | #include "macho.h" // Mach-O files structure 41 | #include "disasm.h" // Structures and classes for disassembler 42 | #include "converters.h" // Classes for file converters 43 | #include "library.h" // Classes for reading and writing libraries 44 | #include "cmdline.h" // Command line interpreter class 45 | 46 | #endif // defined OBJCONV_STDAFX_H 47 | -------------------------------------------------------------------------------- /objconv_src/changelog.txt: -------------------------------------------------------------------------------- 1 | 2016-11-27 version 2.44 2 | * fixed bug when disassembling file generated by Tiny C compiler 3 | 4 | 2016-11-09 version 2.43 5 | * fixed "string table corrupt" message for ELF files 6 | * support for disassembly of AVX512_4VNNIW, AVX512_4FMAPS instructions 7 | 8 | 2016-01-16 version 2.42 9 | * fixed bugs with disassembly of some AVX512 and BMI2 instructions 10 | 11 | 2015-10-15 version 2.41 12 | * fixed bugs with disassembly of some AVX512 instructions 13 | * fixed missing "ptr" in masm syntax disassembly 14 | 15 | 2015-10-15 version 2.40 16 | * fixed bugs with disassembly of some AVX512 instructions 17 | 18 | 2015-09-14 version 2.39 19 | * fixed bugs with disassembly of some AVX512 instructions 20 | 21 | 2014-12-15 version 2.38 22 | * fixed bugs with disassembly of Knights Corner instruction set 23 | * exe file made compatible with Windows XP 24 | 25 | 2014-12-06 version 2.37 26 | * support for disassembly of AVX512BW/DQ, etc. 27 | * fixed disassembly bug of vpgatherdd on knights corner 28 | * fixed disassembly bug for FMA4 instructions 29 | * improved disassembly of switch/case tables for gcc and clang compilers 30 | 31 | 2014-07-21 version 2.36 32 | * improved execution times for disassembling very big files 33 | 34 | 2013-11-27 version 2.32 35 | * fix bug with .bss section in elf2elf.cpp and elf2coff.cpp 36 | 37 | 2013-08-23 version 2.31 38 | * support for disassembly of AVX512F 39 | * library operations were extremely slow on big libraries because of rebuilding and search for unique names. This problem is fixed. 40 | * long member names allowed in libraries 41 | * option -ls to make member names short. Perhaps good for compatibility with BSD. Member names are made unique just by adding a running hex number, not by comparing with all previous names, which was the cause of slow operations in previous versions. 42 | * option -ns to change symbol suffixes 43 | * options -ap and -as to change prefix or suffix and keep old name as alias 44 | * added missing relocation type in ELF to COFF conversion 45 | * fixed error that often occurred when disassembling .exe files 46 | * fixed minor errors 47 | 48 | 2012-08-31 version 2.16 49 | * support for disassembly of Knights Corner instruction set 50 | -------------------------------------------------------------------------------- /fasm_src/tools/dos/loader.inc: -------------------------------------------------------------------------------- 1 | 2 | segment loader use16 3 | 4 | init: 5 | 6 | mov ax,1687h 7 | int 2Fh 8 | or ax,ax ; DPMI installed? 9 | jnz short no_dpmi 10 | test bl,1 ; 32-bit programs supported? 11 | jz short no_dpmi 12 | mov word [cs:mode_switch],di 13 | mov word [cs:mode_switch+2],es 14 | mov bx,si ; allocate memory for DPMI data 15 | mov ah,48h 16 | int 21h 17 | jnc init_protected_mode 18 | init_failed: 19 | call init_error 20 | db 'error: DPMI initialization failed.',0Dh,0Ah,0 21 | no_dpmi: 22 | call init_error 23 | db 'error: 32-bit DPMI services are not available.',0Dh,0Ah,0 24 | init_error: 25 | pop si 26 | push cs 27 | pop ds 28 | display_error: 29 | lodsb 30 | test al,al 31 | jz short error_finish 32 | mov dl,al 33 | mov ah,2 34 | int 21h 35 | jmp short display_error 36 | error_finish: 37 | mov ax,4CFFh 38 | int 21h 39 | init_protected_mode: 40 | mov es,ax 41 | mov ds,[ds:2Ch] 42 | mov ax,1 43 | call far [cs:mode_switch] ; switch to protected mode 44 | jc init_failed 45 | mov cx,1 46 | xor ax,ax 47 | int 31h ; allocate descriptor for code 48 | jc init_failed 49 | mov si,ax 50 | xor ax,ax 51 | int 31h ; allocate descriptor for data 52 | jc init_failed 53 | mov di,ax 54 | mov dx,cs 55 | lar cx,dx 56 | shr cx,8 57 | or cx,0C000h 58 | mov bx,si 59 | mov ax,9 60 | int 31h ; set code descriptor access rights 61 | jc init_failed 62 | mov dx,ds 63 | lar cx,dx 64 | shr cx,8 65 | or cx,0C000h 66 | mov bx,di 67 | int 31h ; set data descriptor access rights 68 | jc init_failed 69 | mov ecx,main 70 | shl ecx,4 71 | mov dx,cx 72 | shr ecx,16 73 | mov ax,7 74 | int 31h ; set data descriptor base address 75 | jc init_failed 76 | mov bx,si 77 | int 31h ; set code descriptor base address 78 | jc init_failed 79 | mov cx,0FFFFh 80 | mov dx,0FFFFh 81 | mov ax,8 ; set segment limit to 4 GB 82 | int 31h 83 | jc init_failed 84 | mov bx,di 85 | int 31h 86 | jc init_failed 87 | mov ax,ds 88 | mov ds,di 89 | mov [psp_selector],es 90 | mov [environment_selector],ax 91 | cli 92 | mov ss,di 93 | mov esp,stack_top 94 | sti 95 | mov es,di 96 | xor eax,eax 97 | mov [memory_handles_count],eax 98 | push si 99 | push start 100 | retf 101 | 102 | mode_switch dd ? 103 | -------------------------------------------------------------------------------- /fasm_src/tools/prepsrc.inc: -------------------------------------------------------------------------------- 1 | 2 | preprocessed_source: 3 | mov edx,[input_file] 4 | call open 5 | jc input_not_found 6 | mov al,2 7 | xor edx,edx 8 | call lseek 9 | cmp eax,30h 10 | jb invalid_input 11 | push eax 12 | call alloc 13 | jc not_enough_memory 14 | push eax 15 | xor al,al 16 | xor edx,edx 17 | call lseek 18 | mov ecx,[esp+4] 19 | mov edx,[esp] 20 | call read 21 | jc reading_error 22 | pop eax ecx 23 | cmp dword [eax],1A736166h 24 | jne invalid_input 25 | mov esi,[eax+32] 26 | add esi,eax 27 | mov ebp,[eax+36] 28 | add ebp,esi 29 | mov edi,eax 30 | push eax 31 | preprocessed_to_text: 32 | cmp esi,ebp 33 | jae conversion_done 34 | add esi,16 35 | xor dl,dl 36 | convert_preprocessed_line: 37 | lodsb 38 | cmp al,1Ah 39 | je copy_symbol 40 | cmp al,22h 41 | je copy_symbol 42 | cmp al,3Bh 43 | je preprocessor_symbols 44 | or al,al 45 | jz line_converted 46 | stosb 47 | xor dl,dl 48 | jmp convert_preprocessed_line 49 | copy_symbol: 50 | or dl,dl 51 | jz space_ok 52 | mov byte [edi],20h 53 | inc edi 54 | space_ok: 55 | cmp al,22h 56 | je quoted 57 | lodsb 58 | movzx ecx,al 59 | rep movsb 60 | or dl,-1 61 | jmp convert_preprocessed_line 62 | quoted: 63 | mov al,27h 64 | stosb 65 | lodsd 66 | mov ecx,eax 67 | jecxz quoted_copied 68 | copy_quoted: 69 | lodsb 70 | stosb 71 | cmp al,27h 72 | jne quote_ok 73 | stosb 74 | quote_ok: 75 | loop copy_quoted 76 | quoted_copied: 77 | mov al,27h 78 | stosb 79 | or dl,-1 80 | jmp convert_preprocessed_line 81 | preprocessor_symbols: 82 | mov al,3Bh 83 | stosb 84 | jmp copy_symbol 85 | line_converted: 86 | mov ax,0A0Dh 87 | stosw 88 | jmp preprocessed_to_text 89 | conversion_done: 90 | mov edx,[output_file] 91 | call create 92 | jc writing_error 93 | pop edx 94 | mov ecx,edi 95 | sub ecx,edx 96 | call write 97 | jc writing_error 98 | call close 99 | ret 100 | 101 | not_enough_memory: 102 | call error 103 | db 'not enough memory to load the required data',0 104 | input_not_found: 105 | call error 106 | db 'the input file was not found',0 107 | reading_error: 108 | call error 109 | db 'some error occured while trying to read file',0 110 | writing_error: 111 | call error 112 | db 'some error occured while trying to write file',0 113 | invalid_input: 114 | call error 115 | db 'input file is not a recognized assembly information format',0 116 | -------------------------------------------------------------------------------- /fasm_src/source/DOS/dpmi.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for DOS 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | init_dpmi_memory: 7 | mov ax,500h ; get free memory information 8 | mov edi,[buffer_address] 9 | int 31h 10 | mov ebx,[edi] 11 | allocate_dpmi_memory: 12 | mov edx,[memory_setting] 13 | shl edx,10 14 | jz dpmi_memory_size_ok 15 | cmp ebx,edx 16 | jbe dpmi_memory_size_ok 17 | mov ebx,edx 18 | dpmi_memory_size_ok: 19 | mov [memory_end],ebx 20 | mov ecx,ebx 21 | shr ebx,16 22 | mov ax,501h 23 | int 31h 24 | jnc dpmi_memory_ok 25 | mov ebx,[memory_end] 26 | shr ebx,1 27 | cmp ebx,4000h 28 | jb out_of_memory 29 | jmp allocate_dpmi_memory 30 | dpmi_memory_ok: 31 | shl ebx,16 32 | mov bx,cx 33 | sub ebx,[program_base] 34 | jc out_of_memory 35 | mov [memory_start],ebx 36 | add [memory_end],ebx 37 | mov ax,100h ; get free conventional memory size 38 | mov bx,-1 39 | int 31h 40 | movzx ecx,bx 41 | shl ecx,4 42 | jecxz no_conventional_memory 43 | mov ax,100h ; allocate all conventional memory 44 | int 31h 45 | movzx edi,ax 46 | shl edi,4 47 | sub edi,[program_base] 48 | jc no_conventional_memory 49 | mov [additional_memory],edi 50 | mov [additional_memory_end],edi 51 | add [additional_memory_end],ecx 52 | mov eax,[memory_end] 53 | sub eax,[memory_start] 54 | shr eax,2 55 | cmp eax,ecx 56 | ja no_conventional_memory 57 | ret 58 | no_conventional_memory: 59 | mov eax,[memory_end] 60 | mov ebx,[memory_start] 61 | sub eax,ebx 62 | shr eax,2 63 | mov [additional_memory],ebx 64 | add ebx,eax 65 | mov [additional_memory_end],ebx 66 | mov [memory_start],ebx 67 | ret 68 | 69 | dpmi_dos_int: 70 | mov [real_mode_segment],main 71 | simulate_real_mode: 72 | push 0 ; SS:SP (DPMI will allocate stack) 73 | push 0 ; CS:IP (ignored) 74 | push 0 75 | push [real_mode_segment] ; DS 76 | push [real_mode_segment] ; ES 77 | stc 78 | pushfw 79 | push eax 80 | push ecx 81 | push edx 82 | push ebx 83 | push 0 84 | push ebp 85 | push esi 86 | push edi 87 | mov ax,300h 88 | mov bx,21h 89 | xor cx,cx 90 | mov edi,esp 91 | push es ss 92 | pop es 93 | int 31h 94 | pop es 95 | mov edi,[esp] 96 | mov esi,[esp+4] 97 | mov ebp,[esp+8] 98 | mov ebx,[esp+10h] 99 | mov edx,[esp+14h] 100 | mov ecx,[esp+18h] 101 | mov ah,[esp+20h] 102 | add esp,32h 103 | sahf 104 | mov eax,[esp-32h+1Ch] 105 | ret 106 | dpmi_dos_int_with_buffer: 107 | mov [real_mode_segment],buffer 108 | jmp simulate_real_mode 109 | -------------------------------------------------------------------------------- /objconv_src/source/error.h: -------------------------------------------------------------------------------- 1 | /**************************** error.h ************************************ 2 | * Author: Agner Fog 3 | * Date created: 2006-07-15 4 | * Last modified: 2006-07-15 5 | * Project: objconv 6 | * Module: error.h 7 | * Description: 8 | * Header file for error handler error.cpp 9 | * 10 | * Copyright 2006-2008 GNU General Public License http://www.gnu.org/licenses 11 | *****************************************************************************/ 12 | #ifndef OBJCONV_ERROR_H 13 | #define OBJCONV_ERROR_H 14 | 15 | // Structure for defining error message texts 16 | struct SErrorText { 17 | int ErrorNumber; // Error number 18 | int Status; // bit 0-3 = severity: 0 = ignore, 1 = warning, 2 = error, 9 = abort 19 | // bit 8 = error number not found 20 | char const * Text; // Error text 21 | }; 22 | 23 | // General error routine for reporting warning and error messages to STDERR output 24 | class CErrorReporter { 25 | public: 26 | CErrorReporter(); // Default constructor 27 | static SErrorText * FindError(int ErrorNumber); // Search for error in ErrorTexts 28 | void submit(int ErrorNumber); // Print error message 29 | void submit(int ErrorNumber, int extra); // Print error message with extra info 30 | void submit(int ErrorNumber, int, int); // Print error message with two extra numbers inserted 31 | void submit(int ErrorNumber, char const * extra); // Print error message with extra info 32 | void submit(int ErrorNumber, char const *, char const *); // Print error message with two extra text fields inserted 33 | void submit(int ErrorNumber, int, char const *); // Print error message with two extra text fields inserted 34 | int Number(); // Get number of errors 35 | int GetWorstError(); // Get highest warning or error number encountered 36 | void ClearError(int ErrorNumber); // Ignore further occurrences of this error 37 | protected: 38 | int NumErrors; // Number of errors detected 39 | int NumWarnings; // Number of warnings detected 40 | int WorstError; // Highest error number encountered 41 | int MaxWarnings; // Max number of warning messages to pring 42 | int MaxErrors; // Max number of error messages to print 43 | void HandleError(SErrorText * err, char const * text); // Used by submit function 44 | }; 45 | 46 | #ifndef OBJCONV_ERROR_CPP 47 | extern CErrorReporter err; // Error handling object is in error.cpp 48 | extern SErrorText ErrorTexts[]; // List of error texts 49 | #endif 50 | 51 | #endif // #ifndef OBJCONV_ERROR_H 52 | -------------------------------------------------------------------------------- /fasm_src/source/messages.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | _out_of_memory db 'out of memory',0 7 | _stack_overflow db 'out of stack space',0 8 | _main_file_not_found db 'source file not found',0 9 | _unexpected_end_of_file db 'unexpected end of file',0 10 | _code_cannot_be_generated db 'code cannot be generated',0 11 | _format_limitations_exceeded db 'format limitations exceeded',0 12 | _invalid_definition db 'invalid definition provided',0 13 | _write_failed db 'write failed',0 14 | _file_not_found db 'file not found',0 15 | _error_reading_file db 'error reading file',0 16 | _invalid_file_format db 'invalid file format',0 17 | _invalid_macro_arguments db 'invalid macro arguments',0 18 | _incomplete_macro db 'incomplete macro',0 19 | _unexpected_characters db 'unexpected characters',0 20 | _invalid_argument db 'invalid argument',0 21 | _illegal_instruction db 'illegal instruction',0 22 | _invalid_operand db 'invalid operand',0 23 | _invalid_operand_size db 'invalid size of operand',0 24 | _operand_size_not_specified db 'operand size not specified',0 25 | _operand_sizes_do_not_match db 'operand sizes do not match',0 26 | _invalid_address_size db 'invalid size of address value',0 27 | _address_sizes_do_not_agree db 'address sizes do not agree',0 28 | _disallowed_combination_of_registers db 'disallowed combination of registers',0 29 | _long_immediate_not_encodable db 'not encodable with long immediate',0 30 | _relative_jump_out_of_range db 'relative jump out of range',0 31 | _invalid_expression db 'invalid expression',0 32 | _invalid_address db 'invalid address',0 33 | _invalid_value db 'invalid value',0 34 | _value_out_of_range db 'value out of range',0 35 | _undefined_symbol db 'undefined symbol',0 36 | _symbol_out_of_scope_1 db 'symbol',0 37 | _symbol_out_of_scope_2 db 'out of scope',0 38 | _invalid_use_of_symbol db 'invalid use of symbol',0 39 | _name_too_long db 'name too long',0 40 | _invalid_name db 'invalid name',0 41 | _reserved_word_used_as_symbol db 'reserved word used as symbol',0 42 | _symbol_already_defined db 'symbol already defined',0 43 | _missing_end_quote db 'missing end quote',0 44 | _missing_end_directive db 'missing end directive',0 45 | _unexpected_instruction db 'unexpected instruction',0 46 | _extra_characters_on_line db 'extra characters on line',0 47 | _section_not_aligned_enough db 'section is not aligned enough',0 48 | _setting_already_specified db 'setting already specified',0 49 | _data_already_defined db 'data already defined',0 50 | _too_many_repeats db 'too many repeats',0 51 | _invoked_error db 'error directive encountered in source file',0 52 | _assertion_failed db 'assertion failed',0 53 | -------------------------------------------------------------------------------- /fasm_src/tools/dos/prepsrc.asm: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_dump 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_dump: 22 | call preprocessed_source 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,0Dh 46 | je all_params 47 | or al,al 48 | jz all_params 49 | cmp [es:input_file],0 50 | jne get_output_file 51 | mov [es:input_file],edi 52 | jmp process_param 53 | get_output_file: 54 | cmp [es:output_file],0 55 | jne bad_params 56 | mov [es:output_file],edi 57 | process_param: 58 | cmp al,22h 59 | je string_param 60 | copy_param: 61 | stosb 62 | lodsb 63 | cmp al,20h 64 | je param_end 65 | cmp al,0Dh 66 | je param_end 67 | or al,al 68 | jz param_end 69 | jmp copy_param 70 | string_param: 71 | lodsb 72 | cmp al,22h 73 | je string_param_end 74 | cmp al,0Dh 75 | je param_end 76 | or al,al 77 | jz param_end 78 | stosb 79 | jmp string_param 80 | bad_params_value: 81 | stc 82 | ret 83 | param_end: 84 | dec esi 85 | string_param_end: 86 | xor al,al 87 | stosb 88 | jmp find_param 89 | all_params: 90 | xor al,al 91 | stosb 92 | pop ds 93 | cmp [input_file],0 94 | je bad_params 95 | cmp [output_file],0 96 | je bad_params 97 | clc 98 | ret 99 | bad_params: 100 | stc 101 | ret 102 | 103 | include 'system.inc' 104 | 105 | include '..\prepsrc.inc' 106 | 107 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah 108 | db 'usage: prepsrc ',0Dh,0Ah 109 | db 0 110 | _error_prefix db 'error: ',0 111 | _error_suffix db '.',0Dh,0Ah,0 112 | 113 | input_file dd 0 114 | output_file dd 0 115 | 116 | psp_selector dw ? 117 | environment_selector dw ? 118 | 119 | memory_handles_count dd ? 120 | memory_handles rd 400h 121 | 122 | params rb 1000h 123 | 124 | segment buffer_segment 125 | 126 | buffer = (buffer_segment-main) shl 4 127 | 128 | db 1000h dup ? 129 | 130 | segment stack_segment 131 | 132 | stack_bottom = (stack_segment-main) shl 4 133 | 134 | db 4000h dup ? 135 | 136 | stack_top = stack_bottom + $ 137 | -------------------------------------------------------------------------------- /fasm_src/tools/dos/symbols.asm: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_dump 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_dump: 22 | call symbols 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,0Dh 46 | je all_params 47 | or al,al 48 | jz all_params 49 | cmp [es:input_file],0 50 | jne get_output_file 51 | mov [es:input_file],edi 52 | jmp process_param 53 | get_output_file: 54 | cmp [es:output_file],0 55 | jne bad_params 56 | mov [es:output_file],edi 57 | process_param: 58 | cmp al,22h 59 | je string_param 60 | copy_param: 61 | stosb 62 | lodsb 63 | cmp al,20h 64 | je param_end 65 | cmp al,0Dh 66 | je param_end 67 | or al,al 68 | jz param_end 69 | jmp copy_param 70 | string_param: 71 | lodsb 72 | cmp al,22h 73 | je string_param_end 74 | cmp al,0Dh 75 | je param_end 76 | or al,al 77 | jz param_end 78 | stosb 79 | jmp string_param 80 | bad_params_value: 81 | stc 82 | ret 83 | param_end: 84 | dec esi 85 | string_param_end: 86 | xor al,al 87 | stosb 88 | jmp find_param 89 | all_params: 90 | xor al,al 91 | stosb 92 | pop ds 93 | cmp [input_file],0 94 | je bad_params 95 | cmp [output_file],0 96 | je bad_params 97 | clc 98 | ret 99 | bad_params: 100 | stc 101 | ret 102 | 103 | include 'system.inc' 104 | 105 | include '..\symbols.inc' 106 | 107 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 108 | db 'usage: symbols ',0Dh,0Ah 109 | db 0 110 | _error_prefix db 'error: ',0 111 | _error_suffix db '.',0Dh,0Ah,0 112 | 113 | input_file dd 0 114 | output_file dd 0 115 | 116 | input dd ? 117 | output_buffer dd ? 118 | output_handle dd ? 119 | 120 | psp_selector dw ? 121 | environment_selector dw ? 122 | 123 | memory_handles_count dd ? 124 | memory_handles rd 400h 125 | 126 | params rb 1000h 127 | 128 | segment buffer_segment 129 | 130 | buffer = (buffer_segment-main) shl 4 131 | 132 | db 1000h dup ? 133 | 134 | segment stack_segment 135 | 136 | stack_bottom = (stack_segment-main) shl 4 137 | 138 | db 4000h dup ? 139 | 140 | stack_top = stack_bottom + $ 141 | -------------------------------------------------------------------------------- /fasm_src/tools/win32/prepsrc.asm: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'preprocessed source dumper for flat assembler',0Dh,0Ah 10 | db 'usage: prepsrc ',0Dh,0Ah 11 | db 0 12 | _error_prefix db 'error: ',0 13 | _error_suffix db '.',0Dh,0Ah,0 14 | 15 | input_file dd 0 16 | output_file dd 0 17 | 18 | display_handle dd ? 19 | bytes_count dd ? 20 | 21 | params rb 1000h 22 | 23 | section '.text' code readable executable 24 | 25 | start: 26 | 27 | mov [display_handle],STD_OUTPUT_HANDLE 28 | 29 | call get_params 30 | jnc make_dump 31 | 32 | mov esi,_usage 33 | call display_string 34 | invoke ExitProcess,2 35 | 36 | make_dump: 37 | call preprocessed_source 38 | invoke ExitProcess,0 39 | 40 | error: 41 | mov [display_handle],STD_ERROR_HANDLE 42 | mov esi,_error_prefix 43 | call display_string 44 | pop esi 45 | call display_string 46 | mov esi,_error_suffix 47 | call display_string 48 | invoke ExitProcess,1 49 | 50 | get_params: 51 | invoke GetCommandLine 52 | mov esi,eax 53 | mov edi,params 54 | find_command_start: 55 | lodsb 56 | cmp al,20h 57 | je find_command_start 58 | cmp al,22h 59 | je skip_quoted_name 60 | skip_name: 61 | lodsb 62 | cmp al,20h 63 | je find_param 64 | or al,al 65 | jz all_params 66 | jmp skip_name 67 | skip_quoted_name: 68 | lodsb 69 | cmp al,22h 70 | je find_param 71 | or al,al 72 | jz all_params 73 | jmp skip_quoted_name 74 | find_param: 75 | lodsb 76 | cmp al,20h 77 | je find_param 78 | cmp al,0Dh 79 | je all_params 80 | or al,al 81 | jz all_params 82 | cmp [input_file],0 83 | jne get_output_file 84 | mov [input_file],edi 85 | jmp process_param 86 | get_output_file: 87 | cmp [output_file],0 88 | jne bad_params 89 | mov [output_file],edi 90 | process_param: 91 | cmp al,22h 92 | je string_param 93 | copy_param: 94 | stosb 95 | lodsb 96 | cmp al,20h 97 | je param_end 98 | cmp al,0Dh 99 | je param_end 100 | or al,al 101 | jz param_end 102 | jmp copy_param 103 | string_param: 104 | lodsb 105 | cmp al,22h 106 | je string_param_end 107 | cmp al,0Dh 108 | je param_end 109 | or al,al 110 | jz param_end 111 | stosb 112 | jmp string_param 113 | bad_params: 114 | stc 115 | ret 116 | param_end: 117 | dec esi 118 | string_param_end: 119 | xor al,al 120 | stosb 121 | jmp find_param 122 | all_params: 123 | cmp [input_file],0 124 | je bad_params 125 | cmp [output_file],0 126 | je bad_params 127 | clc 128 | ret 129 | 130 | include 'system.inc' 131 | 132 | include '..\prepsrc.inc' 133 | 134 | section '.idata' import data readable writeable 135 | 136 | library kernel32,'KERNEL32.DLL' 137 | 138 | include 'api\kernel32.inc' 139 | -------------------------------------------------------------------------------- /fasm_src/tools/win32/symbols.asm: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'symbols dumper for flat assembler',0Dh,0Ah 10 | db 'usage: symbols ',0Dh,0Ah 11 | db 0 12 | _error_prefix db 'error: ',0 13 | _error_suffix db '.',0Dh,0Ah,0 14 | 15 | input_file dd 0 16 | output_file dd 0 17 | 18 | input dd ? 19 | output_buffer dd ? 20 | output_handle dd ? 21 | 22 | display_handle dd ? 23 | bytes_count dd ? 24 | 25 | params rb 1000h 26 | 27 | section '.text' code readable executable 28 | 29 | start: 30 | 31 | mov [display_handle],STD_OUTPUT_HANDLE 32 | 33 | call get_params 34 | jnc make_dump 35 | 36 | mov esi,_usage 37 | call display_string 38 | invoke ExitProcess,2 39 | 40 | make_dump: 41 | call symbols 42 | invoke ExitProcess,0 43 | 44 | error: 45 | mov [display_handle],STD_ERROR_HANDLE 46 | mov esi,_error_prefix 47 | call display_string 48 | pop esi 49 | call display_string 50 | mov esi,_error_suffix 51 | call display_string 52 | invoke ExitProcess,1 53 | 54 | get_params: 55 | invoke GetCommandLine 56 | mov esi,eax 57 | mov edi,params 58 | find_command_start: 59 | lodsb 60 | cmp al,20h 61 | je find_command_start 62 | cmp al,22h 63 | je skip_quoted_name 64 | skip_name: 65 | lodsb 66 | cmp al,20h 67 | je find_param 68 | or al,al 69 | jz all_params 70 | jmp skip_name 71 | skip_quoted_name: 72 | lodsb 73 | cmp al,22h 74 | je find_param 75 | or al,al 76 | jz all_params 77 | jmp skip_quoted_name 78 | find_param: 79 | lodsb 80 | cmp al,20h 81 | je find_param 82 | cmp al,0Dh 83 | je all_params 84 | or al,al 85 | jz all_params 86 | cmp [input_file],0 87 | jne get_output_file 88 | mov [input_file],edi 89 | jmp process_param 90 | get_output_file: 91 | cmp [output_file],0 92 | jne bad_params 93 | mov [output_file],edi 94 | process_param: 95 | cmp al,22h 96 | je string_param 97 | copy_param: 98 | stosb 99 | lodsb 100 | cmp al,20h 101 | je param_end 102 | cmp al,0Dh 103 | je param_end 104 | or al,al 105 | jz param_end 106 | jmp copy_param 107 | string_param: 108 | lodsb 109 | cmp al,22h 110 | je string_param_end 111 | cmp al,0Dh 112 | je param_end 113 | or al,al 114 | jz param_end 115 | stosb 116 | jmp string_param 117 | bad_params: 118 | stc 119 | ret 120 | param_end: 121 | dec esi 122 | string_param_end: 123 | xor al,al 124 | stosb 125 | jmp find_param 126 | all_params: 127 | cmp [input_file],0 128 | je bad_params 129 | cmp [output_file],0 130 | je bad_params 131 | clc 132 | ret 133 | 134 | include 'system.inc' 135 | 136 | include '..\symbols.inc' 137 | 138 | section '.idata' import data readable writeable 139 | 140 | library kernel32,'KERNEL32.DLL' 141 | 142 | include 'api\kernel32.inc' 143 | -------------------------------------------------------------------------------- /fasm_src/source/variable.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core variables 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | ; Variables which have to be set up by interface: 7 | 8 | memory_start dd ? 9 | memory_end dd ? 10 | 11 | additional_memory dd ? 12 | additional_memory_end dd ? 13 | 14 | stack_limit dd ? 15 | 16 | initial_definitions dd ? 17 | input_file dd ? 18 | output_file dd ? 19 | symbols_file dd ? 20 | 21 | passes_limit dw ? 22 | 23 | ; Internal core variables: 24 | 25 | current_pass dw ? 26 | 27 | include_paths dd ? 28 | free_additional_memory dd ? 29 | source_start dd ? 30 | code_start dd ? 31 | code_size dd ? 32 | real_code_size dd ? 33 | written_size dd ? 34 | headers_size dd ? 35 | 36 | current_line dd ? 37 | macro_line dd ? 38 | macro_block dd ? 39 | macro_block_line dd ? 40 | macro_block_line_number dd ? 41 | macro_symbols dd ? 42 | struc_name dd ? 43 | struc_label dd ? 44 | instant_macro_start dd ? 45 | parameters_end dd ? 46 | default_argument_value dd ? 47 | locals_counter rb 8 48 | current_locals_prefix dd ? 49 | anonymous_reverse dd ? 50 | anonymous_forward dd ? 51 | labels_list dd ? 52 | label_hash dd ? 53 | label_leaf dd ? 54 | hash_tree dd ? 55 | addressing_space dd ? 56 | undefined_data_start dd ? 57 | undefined_data_end dd ? 58 | counter dd ? 59 | counter_limit dd ? 60 | error_info dd ? 61 | error_line dd ? 62 | error dd ? 63 | tagged_blocks dd ? 64 | structures_buffer dd ? 65 | number_start dd ? 66 | current_offset dd ? 67 | value dq ? 68 | fp_value rd 8 69 | adjustment dq ? 70 | symbol_identifier dd ? 71 | address_symbol dd ? 72 | address_high dd ? 73 | uncompressed_displacement dd ? 74 | format_flags dd ? 75 | resolver_flags dd ? 76 | symbols_stream dd ? 77 | number_of_relocations dd ? 78 | number_of_sections dd ? 79 | stub_size dd ? 80 | stub_file dd ? 81 | current_section dd ? 82 | machine dw ? 83 | subsystem dw ? 84 | subsystem_version dd ? 85 | image_base dd ? 86 | image_base_high dd ? 87 | resource_data dd ? 88 | resource_size dd ? 89 | actual_fixups_size dd ? 90 | reserved_fixups dd ? 91 | reserved_fixups_size dd ? 92 | last_fixup_base dd ? 93 | last_fixup_header dd ? 94 | parenthesis_stack dd ? 95 | blocks_stack dd ? 96 | parsed_lines dd ? 97 | logical_value_parentheses dd ? 98 | file_extension dd ? 99 | 100 | operand_size db ? 101 | operand_flags db ? 102 | operand_prefix db ? 103 | rex_prefix db ? 104 | opcode_prefix db ? 105 | vex_required db ? 106 | vex_register db ? 107 | immediate_size db ? 108 | mask_register db ? 109 | broadcast_size db ? 110 | rounding_mode db ? 111 | 112 | base_code db ? 113 | extended_code db ? 114 | supplemental_code db ? 115 | postbyte_register db ? 116 | segment_register db ? 117 | xop_opcode_map db ? 118 | 119 | mmx_size db ? 120 | jump_type db ? 121 | push_size db ? 122 | value_size db ? 123 | address_size db ? 124 | label_size db ? 125 | size_declared db ? 126 | address_size_declared db ? 127 | displacement_compression db ? 128 | 129 | value_undefined db ? 130 | value_constant db ? 131 | value_type db ? 132 | value_sign db ? 133 | fp_sign db ? 134 | fp_format db ? 135 | address_sign db ? 136 | address_register db ? 137 | compare_type db ? 138 | logical_value_wrapping db ? 139 | next_pass_needed db ? 140 | output_format db ? 141 | code_type db ? 142 | adjustment_sign db ? 143 | evex_mode db ? 144 | 145 | macro_status db ? 146 | skip_default_argument_value db ? 147 | prefix_flags db ? 148 | formatter_symbols_allowed db ? 149 | decorator_symbols_allowed db ? 150 | free_address_range db ? 151 | 152 | 153 | characters rb 100h 154 | converted rb 100h 155 | message rb 200h 156 | -------------------------------------------------------------------------------- /fasm_src/source/Linux/x64/modes.inc: -------------------------------------------------------------------------------- 1 | 2 | esp equ +rsp 3 | 4 | macro pushD [arg] 5 | { 6 | common 7 | local offset,total 8 | offset = 0 9 | lea rsp,[rsp-total] 10 | forward 11 | offset = offset + 4 12 | if arg eqtype eax 13 | mov dword [rsp+total-offset],arg 14 | else 15 | mov r8d,dword arg 16 | mov [rsp+total-offset],r8d 17 | end if 18 | common 19 | total = offset 20 | } 21 | 22 | macro popD [arg] 23 | { 24 | common 25 | local offset 26 | offset = 0 27 | forward 28 | if arg eqtype [mem] 29 | mov r8d,[rsp+offset] 30 | mov dword arg,r8d 31 | else 32 | mov arg,dword [rsp+offset] 33 | end if 34 | offset = offset + 4 35 | common 36 | lea rsp,[rsp+offset] 37 | } 38 | 39 | macro add dest,src 40 | { 41 | if dest eq esp 42 | add rsp,src 43 | else 44 | add dest,src 45 | end if 46 | } 47 | 48 | macro mov dest,src 49 | { 50 | if src eq esp 51 | mov dest,ESP 52 | else 53 | mov dest,src 54 | end if 55 | } 56 | 57 | macro cmp dest,src 58 | { 59 | if dest eq esp 60 | cmp ESP,src 61 | else 62 | cmp dest,src 63 | end if 64 | } 65 | 66 | macro use32 67 | { 68 | 69 | macro push args 70 | \{ 71 | local list,arg,status 72 | define list 73 | define arg 74 | irps sym, args \\{ 75 | define status 76 | match =dword, sym \\\{ 77 | define status : 78 | \\\} 79 | match [any, status arg sym \\\{ 80 | define arg [any 81 | match [mem], arg \\\\{ 82 | match previous, list \\\\\{ define list previous,[mem] \\\\\} 83 | match , list \\\\\{ define list [mem] \\\\\} 84 | define arg 85 | \\\\} 86 | define status : 87 | \\\} 88 | match [, status arg sym \\\{ 89 | define arg [ 90 | define status : 91 | \\\} 92 | match , status \\\{ 93 | match previous, list \\\\{ define list previous,sym \\\\} 94 | match , list \\\\{ define list sym \\\\} 95 | \\\} 96 | \\} 97 | match arg, list \\{ pushD arg \\} 98 | \} 99 | 100 | macro pop args 101 | \{ 102 | local list,arg,status 103 | define list 104 | define arg 105 | irps sym, args \\{ 106 | define status 107 | match =dword, sym \\\{ 108 | define status : 109 | \\\} 110 | match [any, status arg sym \\\{ 111 | define arg [any 112 | match [mem], arg \\\\{ 113 | match previous, list \\\\\{ define list previous,[mem] \\\\\} 114 | match , list \\\\\{ define list [mem] \\\\\} 115 | define arg 116 | \\\\} 117 | define status : 118 | \\\} 119 | match [, status arg sym \\\{ 120 | define arg [ 121 | define status : 122 | \\\} 123 | match , status \\\{ 124 | match previous, list \\\\{ define list previous,sym \\\\} 125 | match , list \\\\{ define list sym \\\\} 126 | \\\} 127 | \\} 128 | match arg, list \\{ popD arg \\} 129 | \} 130 | 131 | macro jmp arg 132 | \{ 133 | if arg eq near eax 134 | jmp near rax 135 | else if arg eq near edx 136 | jmp near rdx 137 | else if arg eqtype [mem] 138 | mov r8d,arg 139 | jmp near r8 140 | else 141 | jmp arg 142 | end if 143 | \} 144 | 145 | macro call arg 146 | \{ 147 | if 1 148 | match =near =dword [mem], arg \\{ 149 | mov r8d,[mem] 150 | call near r8 151 | else 152 | \\} 153 | call arg 154 | end if 155 | \} 156 | 157 | macro salc ; for fasm's core it does not need to preserve flags 158 | \{ 159 | setc al 160 | neg al 161 | \} 162 | 163 | macro jcxz target ; for fasm's core it does not need to preserve flags 164 | \{ 165 | test cx,cx 166 | jz target 167 | \} 168 | 169 | use64 170 | 171 | } 172 | 173 | macro use16 174 | { 175 | 176 | purge push,pop,jmp,call,salc,jcxz 177 | 178 | use16 179 | 180 | } 181 | 182 | use32 183 | -------------------------------------------------------------------------------- /fasm_src/tools/libc/listing.asm: -------------------------------------------------------------------------------- 1 | 2 | format ELF 3 | public main 4 | 5 | include 'ccall.inc' 6 | 7 | section '.text' executable align 16 8 | 9 | main: 10 | mov ecx,[esp+4] 11 | mov [argc],ecx 12 | mov ebx,[esp+8] 13 | mov [argv],ebx 14 | 15 | mov [display_handle],1 16 | 17 | call get_params 18 | jnc make_listing 19 | 20 | mov esi,_usage 21 | call display_string 22 | ccall exit,2 23 | 24 | make_listing: 25 | call listing 26 | ccall exit,0 27 | 28 | error: 29 | mov [display_handle],2 30 | mov esi,_error_prefix 31 | call display_string 32 | pop esi 33 | call display_string 34 | mov esi,_error_suffix 35 | call display_string 36 | ccall exit,0 37 | 38 | get_params: 39 | mov ecx,[argc] 40 | mov ebx,[argv] 41 | add ebx,4 42 | dec ecx 43 | jz bad_params 44 | get_param: 45 | mov esi,[ebx] 46 | mov al,[esi] 47 | cmp al,'-' 48 | je option_param 49 | cmp [input_file],0 50 | jne get_output_file 51 | mov [input_file],esi 52 | jmp next_param 53 | get_output_file: 54 | cmp [output_file],0 55 | jne bad_params 56 | mov [output_file],esi 57 | jmp next_param 58 | option_param: 59 | inc esi 60 | lodsb 61 | cmp al,'a' 62 | je addresses_option 63 | cmp al,'A' 64 | je addresses_option 65 | cmp al,'b' 66 | je bytes_per_line_option 67 | cmp al,'B' 68 | je bytes_per_line_option 69 | bad_params: 70 | stc 71 | ret 72 | addresses_option: 73 | cmp byte [esi],0 74 | jne bad_params 75 | mov [show_addresses],1 76 | jmp next_param 77 | bytes_per_line_option: 78 | cmp byte [esi],0 79 | jne get_bytes_per_line_setting 80 | dec ecx 81 | jz bad_params 82 | add ebx,4 83 | mov esi,[ebx] 84 | get_bytes_per_line_setting: 85 | call get_option_value 86 | or edx,edx 87 | jz bad_params 88 | cmp edx,1000 89 | ja bad_params 90 | mov [code_bytes_per_line],edx 91 | next_param: 92 | add ebx,4 93 | dec ecx 94 | jnz get_param 95 | cmp [input_file],0 96 | je bad_params 97 | cmp [output_file],0 98 | je bad_params 99 | clc 100 | ret 101 | get_option_value: 102 | xor eax,eax 103 | mov edx,eax 104 | get_option_digit: 105 | lodsb 106 | cmp al,20h 107 | je option_value_ok 108 | cmp al,0Dh 109 | je option_value_ok 110 | or al,al 111 | jz option_value_ok 112 | sub al,30h 113 | jc invalid_option_value 114 | cmp al,9 115 | ja invalid_option_value 116 | imul edx,10 117 | jo invalid_option_value 118 | add edx,eax 119 | jc invalid_option_value 120 | jmp get_option_digit 121 | option_value_ok: 122 | dec esi 123 | clc 124 | ret 125 | invalid_option_value: 126 | stc 127 | ret 128 | 129 | include 'system.inc' 130 | 131 | include '..\listing.inc' 132 | 133 | section '.data' writeable align 4 134 | 135 | input_file dd 0 136 | output_file dd 0 137 | code_bytes_per_line dd 16 138 | show_addresses db 0 139 | 140 | line_break db 0Dh,0Ah 141 | 142 | _usage db 'listing generator for flat assembler',0Dh,0Ah 143 | db 'usage: listing ',0Dh,0Ah 144 | db 'optional settings:',0Dh,0Ah 145 | db ' -a show target addresses for assembled code',0Dh,0Ah 146 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 147 | db 0 148 | _error_prefix db 'error: ',0 149 | _error_suffix db '.',0Dh,0Ah,0 150 | 151 | section '.bss' writeable align 4 152 | 153 | argc dd ? 154 | argv dd ? 155 | 156 | input dd ? 157 | assembled_code dd ? 158 | assembled_code_length dd ? 159 | code_end dd ? 160 | code_offset dd ? 161 | code_length dd ? 162 | output_handle dd ? 163 | output_buffer dd ? 164 | current_source_file dd ? 165 | current_source_line dd ? 166 | source dd ? 167 | source_length dd ? 168 | maximum_address_length dd ? 169 | address_start dd ? 170 | last_listed_address dd ? 171 | 172 | display_handle dd ? 173 | character db ? 174 | 175 | params rb 1000h 176 | characters rb 100h 177 | buffer rb 1000h 178 | -------------------------------------------------------------------------------- /fasm_src/tools/dos/system.inc: -------------------------------------------------------------------------------- 1 | 2 | display_string: 3 | lods byte [esi] 4 | or al,al 5 | jz string_end 6 | mov dl,al 7 | mov ah,2 8 | int 21h 9 | jmp display_string 10 | string_end: 11 | ret 12 | alloc: 13 | push ebx esi edi 14 | mov cx,ax 15 | shr eax,16 16 | mov bx,ax 17 | mov ax,501h 18 | int 31h 19 | jc dpmi_allocation_failed 20 | mov ax,bx 21 | shl eax,16 22 | mov ax,cx 23 | mov edx,main 24 | shl edx,4 25 | sub eax,edx 26 | mov bx,si 27 | shl ebx,16 28 | mov bx,di 29 | mov ecx,[memory_handles_count] 30 | inc [memory_handles_count] 31 | shl ecx,3 32 | add ecx,memory_handles 33 | mov [ecx],eax 34 | mov [ecx+4],ebx 35 | pop edi esi ebx 36 | clc 37 | ret 38 | dpmi_allocation_failed: 39 | pop edi esi ebx 40 | stc 41 | ret 42 | free: 43 | push ebx esi edi 44 | mov esi,memory_handles 45 | mov ecx,[memory_handles_count] 46 | find_memory_handle: 47 | cmp eax,[esi] 48 | je memory_handle_found 49 | add esi,8 50 | loop find_memory_handle 51 | pop edi esi 52 | ret 53 | memory_handle_found: 54 | mov ebx,[esi+4] 55 | dec [memory_handles_count] 56 | dec ecx 57 | jz free_memory 58 | remove_memory_handle: 59 | mov edx,[esi+8] 60 | mov edi,[esi+8+4] 61 | mov [esi],edx 62 | mov [esi+4],edi 63 | add esi,8 64 | loop remove_memory_handle 65 | free_memory: 66 | mov esi,ebx 67 | shr esi,16 68 | mov di,bx 69 | mov ax,502h 70 | int 31h 71 | pop edi esi ebx 72 | ret 73 | open: 74 | push esi edi ebp 75 | call adapt_path 76 | mov ax,716Ch 77 | mov bx,100000b 78 | mov dx,1 79 | xor cx,cx 80 | xor si,si 81 | call dos_int 82 | jnc open_done 83 | cmp ax,7100h 84 | je old_open 85 | stc 86 | jmp open_done 87 | old_open: 88 | mov ax,3D00h 89 | xor dx,dx 90 | call dos_int 91 | open_done: 92 | mov bx,ax 93 | pop ebp edi esi 94 | ret 95 | adapt_path: 96 | mov esi,edx 97 | mov edi,buffer 98 | copy_path: 99 | lodsb 100 | cmp al,'/' 101 | jne path_char_ok 102 | mov al,'\' 103 | path_char_ok: 104 | stosb 105 | or al,al 106 | jnz copy_path 107 | ret 108 | dos_int: 109 | push 0 0 0 110 | pushw buffer_segment buffer_segment 111 | stc 112 | pushfw 113 | push eax 114 | push ecx 115 | push edx 116 | push ebx 117 | push 0 118 | push ebp 119 | push esi 120 | push edi 121 | mov ax,300h 122 | mov bx,21h 123 | xor cx,cx 124 | mov edi,esp 125 | push es ss 126 | pop es 127 | int 31h 128 | pop es 129 | mov edi,[esp] 130 | mov esi,[esp+4] 131 | mov ebp,[esp+8] 132 | mov ebx,[esp+10h] 133 | mov edx,[esp+14h] 134 | mov ecx,[esp+18h] 135 | mov ah,[esp+20h] 136 | add esp,32h 137 | sahf 138 | mov eax,[esp-32h+1Ch] 139 | ret 140 | create: 141 | push esi edi ebp 142 | call adapt_path 143 | mov ax,716Ch 144 | mov bx,100001b 145 | mov dx,10010b 146 | xor cx,cx 147 | xor si,si 148 | xor di,di 149 | call dos_int 150 | jnc create_done 151 | cmp ax,7100h 152 | je old_create 153 | stc 154 | jmp create_done 155 | old_create: 156 | mov ah,3Ch 157 | xor cx,cx 158 | xor dx,dx 159 | call dos_int 160 | create_done: 161 | mov bx,ax 162 | pop ebp edi esi 163 | ret 164 | write: 165 | push edx esi edi ebp 166 | mov ebp,ecx 167 | mov esi,edx 168 | write_loop: 169 | mov ecx,1000h 170 | sub ebp,1000h 171 | jnc do_write 172 | add ebp,1000h 173 | mov ecx,ebp 174 | xor ebp,ebp 175 | do_write: 176 | push ecx 177 | mov edi,buffer 178 | shr ecx,2 179 | rep movsd 180 | mov ecx,[esp] 181 | and ecx,11b 182 | rep movsb 183 | pop ecx 184 | mov ah,40h 185 | xor dx,dx 186 | call dos_int 187 | or ebp,ebp 188 | jnz write_loop 189 | pop ebp edi esi edx 190 | ret 191 | read: 192 | push edx esi edi ebp 193 | mov ebp,ecx 194 | mov edi,edx 195 | read_loop: 196 | mov ecx,1000h 197 | sub ebp,1000h 198 | jnc do_read 199 | add ebp,1000h 200 | mov ecx,ebp 201 | xor ebp,ebp 202 | do_read: 203 | push ecx 204 | mov ah,3Fh 205 | xor dx,dx 206 | call dos_int 207 | cmp ax,cx 208 | jne eof 209 | mov esi,buffer 210 | mov ecx,[esp] 211 | shr ecx,2 212 | rep movsd 213 | pop ecx 214 | and ecx,11b 215 | rep movsb 216 | or ebp,ebp 217 | jnz read_loop 218 | read_done: 219 | pop ebp edi esi edx 220 | ret 221 | eof: 222 | pop ecx 223 | stc 224 | jmp read_done 225 | close: 226 | mov ah,3Eh 227 | int 21h 228 | ret 229 | lseek: 230 | mov ah,42h 231 | mov ecx,edx 232 | shr ecx,16 233 | int 21h 234 | pushf 235 | shl edx,16 236 | popf 237 | mov dx,ax 238 | mov eax,edx 239 | ret 240 | -------------------------------------------------------------------------------- /fasm_src/tools/dos/listing.asm: -------------------------------------------------------------------------------- 1 | 2 | format MZ 3 | heap 0 4 | stack 8000h 5 | entry loader:init 6 | 7 | include 'loader.inc' 8 | 9 | segment main use32 10 | 11 | start: 12 | 13 | call get_params 14 | jnc make_listing 15 | 16 | mov esi,_usage 17 | call display_string 18 | mov ax,4C02h 19 | int 21h 20 | 21 | make_listing: 22 | call listing 23 | mov ax,4C00h 24 | int 21h 25 | 26 | error: 27 | mov esi,_error_prefix 28 | call display_string 29 | pop esi 30 | call display_string 31 | mov esi,_error_suffix 32 | call display_string 33 | mov ax,4C00h 34 | int 21h 35 | 36 | get_params: 37 | push ds 38 | mov ds,[psp_selector] 39 | mov esi,81h 40 | mov edi,params 41 | find_param: 42 | lodsb 43 | cmp al,20h 44 | je find_param 45 | cmp al,'-' 46 | je option_param 47 | cmp al,0Dh 48 | je all_params 49 | or al,al 50 | jz all_params 51 | cmp [es:input_file],0 52 | jne get_output_file 53 | mov [es:input_file],edi 54 | jmp process_param 55 | get_output_file: 56 | cmp [es:output_file],0 57 | jne bad_params 58 | mov [es:output_file],edi 59 | process_param: 60 | cmp al,22h 61 | je string_param 62 | copy_param: 63 | stosb 64 | lodsb 65 | cmp al,20h 66 | je param_end 67 | cmp al,0Dh 68 | je param_end 69 | or al,al 70 | jz param_end 71 | jmp copy_param 72 | string_param: 73 | lodsb 74 | cmp al,22h 75 | je string_param_end 76 | cmp al,0Dh 77 | je param_end 78 | or al,al 79 | jz param_end 80 | stosb 81 | jmp string_param 82 | option_param: 83 | lodsb 84 | cmp al,'a' 85 | je addresses_option 86 | cmp al,'A' 87 | je addresses_option 88 | cmp al,'b' 89 | je bytes_per_line_option 90 | cmp al,'B' 91 | je bytes_per_line_option 92 | invalid_option: 93 | pop ds 94 | stc 95 | ret 96 | get_option_value: 97 | xor eax,eax 98 | mov edx,eax 99 | get_option_digit: 100 | lodsb 101 | cmp al,20h 102 | je option_value_ok 103 | cmp al,0Dh 104 | je option_value_ok 105 | or al,al 106 | jz option_value_ok 107 | sub al,30h 108 | jc bad_params_value 109 | cmp al,9 110 | ja bad_params_value 111 | imul edx,10 112 | jo bad_params_value 113 | add edx,eax 114 | jc bad_params_value 115 | jmp get_option_digit 116 | option_value_ok: 117 | dec esi 118 | clc 119 | ret 120 | bad_params_value: 121 | stc 122 | ret 123 | bytes_per_line_option: 124 | lodsb 125 | cmp al,20h 126 | je bytes_per_line_option 127 | cmp al,0Dh 128 | je invalid_option 129 | or al,al 130 | jz invalid_option 131 | dec esi 132 | call get_option_value 133 | jc bad_params 134 | or edx,edx 135 | jz invalid_option 136 | cmp edx,1000 137 | ja invalid_option 138 | mov [es:code_bytes_per_line],edx 139 | jmp find_param 140 | addresses_option: 141 | lodsb 142 | cmp al,20h 143 | je set_addresses_option 144 | cmp al,0Dh 145 | je set_addresses_option 146 | or al,al 147 | jnz bad_params 148 | set_addresses_option: 149 | dec esi 150 | mov [es:show_addresses],1 151 | jmp find_param 152 | param_end: 153 | dec esi 154 | string_param_end: 155 | xor al,al 156 | stosb 157 | jmp find_param 158 | all_params: 159 | xor al,al 160 | stosb 161 | pop ds 162 | cmp [input_file],0 163 | je bad_params 164 | cmp [output_file],0 165 | je bad_params 166 | clc 167 | ret 168 | bad_params: 169 | stc 170 | ret 171 | 172 | include 'system.inc' 173 | 174 | include '..\listing.inc' 175 | 176 | _usage db 'listing generator for flat assembler',0Dh,0Ah 177 | db 'usage: listing ',0Dh,0Ah 178 | db 'optional settings:',0Dh,0Ah 179 | db ' -a show target addresses for assembled code',0Dh,0Ah 180 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 181 | db 0 182 | _error_prefix db 'error: ',0 183 | _error_suffix db '.',0Dh,0Ah,0 184 | 185 | input_file dd 0 186 | output_file dd 0 187 | code_bytes_per_line dd 16 188 | show_addresses db 0 189 | 190 | line_break db 0Dh,0Ah 191 | 192 | input dd ? 193 | assembled_code dd ? 194 | assembled_code_length dd ? 195 | code_end dd ? 196 | code_offset dd ? 197 | code_length dd ? 198 | output_handle dd ? 199 | output_buffer dd ? 200 | current_source_file dd ? 201 | current_source_line dd ? 202 | source dd ? 203 | source_length dd ? 204 | maximum_address_length dd ? 205 | address_start dd ? 206 | last_listed_address dd ? 207 | 208 | psp_selector dw ? 209 | environment_selector dw ? 210 | 211 | memory_handles_count dd ? 212 | memory_handles rd 400h 213 | 214 | params rb 1000h 215 | characters rb 100h 216 | 217 | segment buffer_segment 218 | 219 | buffer = (buffer_segment-main) shl 4 220 | 221 | db 1000h dup ? 222 | 223 | segment stack_segment 224 | 225 | stack_bottom = (stack_segment-main) shl 4 226 | 227 | db 4000h dup ? 228 | 229 | stack_top = stack_bottom + $ 230 | -------------------------------------------------------------------------------- /fasm_src/tools/win32/listing.asm: -------------------------------------------------------------------------------- 1 | 2 | format PE console 4.0 3 | entry start 4 | 5 | include 'win32a.inc' 6 | 7 | section '.data' data readable writeable 8 | 9 | _usage db 'listing generator for flat assembler',0Dh,0Ah 10 | db 'usage: listing ',0Dh,0Ah 11 | db 'optional settings:',0Dh,0Ah 12 | db ' -a show target addresses for assembled code',0Dh,0Ah 13 | db ' -b set the amount of bytes listed per line',0Dh,0Ah 14 | db 0 15 | _error_prefix db 'error: ',0 16 | _error_suffix db '.',0Dh,0Ah,0 17 | 18 | line_break db 0Dh,0Ah 19 | 20 | input_file dd 0 21 | output_file dd 0 22 | code_bytes_per_line dd 16 23 | show_addresses db 0 24 | 25 | input dd ? 26 | assembled_code dd ? 27 | assembled_code_length dd ? 28 | code_end dd ? 29 | code_offset dd ? 30 | code_length dd ? 31 | output_handle dd ? 32 | output_buffer dd ? 33 | current_source_file dd ? 34 | current_source_line dd ? 35 | source dd ? 36 | source_length dd ? 37 | maximum_address_length dd ? 38 | address_start dd ? 39 | last_listed_address dd ? 40 | 41 | display_handle dd ? 42 | bytes_count dd ? 43 | 44 | params rb 1000h 45 | characters rb 100h 46 | 47 | section '.text' code readable executable 48 | 49 | start: 50 | 51 | mov [display_handle],STD_OUTPUT_HANDLE 52 | 53 | call get_params 54 | jnc make_listing 55 | 56 | mov esi,_usage 57 | call display_string 58 | invoke ExitProcess,2 59 | 60 | make_listing: 61 | call listing 62 | invoke ExitProcess,0 63 | 64 | error: 65 | mov [display_handle],STD_ERROR_HANDLE 66 | mov esi,_error_prefix 67 | call display_string 68 | pop esi 69 | call display_string 70 | mov esi,_error_suffix 71 | call display_string 72 | invoke ExitProcess,1 73 | 74 | get_params: 75 | invoke GetCommandLine 76 | mov esi,eax 77 | mov edi,params 78 | find_command_start: 79 | lodsb 80 | cmp al,20h 81 | je find_command_start 82 | cmp al,22h 83 | je skip_quoted_name 84 | skip_name: 85 | lodsb 86 | cmp al,20h 87 | je find_param 88 | or al,al 89 | jz all_params 90 | jmp skip_name 91 | skip_quoted_name: 92 | lodsb 93 | cmp al,22h 94 | je find_param 95 | or al,al 96 | jz all_params 97 | jmp skip_quoted_name 98 | find_param: 99 | lodsb 100 | cmp al,20h 101 | je find_param 102 | cmp al,'-' 103 | je option_param 104 | cmp al,0Dh 105 | je all_params 106 | or al,al 107 | jz all_params 108 | cmp [input_file],0 109 | jne get_output_file 110 | mov [input_file],edi 111 | jmp process_param 112 | get_output_file: 113 | cmp [output_file],0 114 | jne bad_params 115 | mov [output_file],edi 116 | process_param: 117 | cmp al,22h 118 | je string_param 119 | copy_param: 120 | stosb 121 | lodsb 122 | cmp al,20h 123 | je param_end 124 | cmp al,0Dh 125 | je param_end 126 | or al,al 127 | jz param_end 128 | jmp copy_param 129 | string_param: 130 | lodsb 131 | cmp al,22h 132 | je string_param_end 133 | cmp al,0Dh 134 | je param_end 135 | or al,al 136 | jz param_end 137 | stosb 138 | jmp string_param 139 | option_param: 140 | lodsb 141 | cmp al,'a' 142 | je addresses_option 143 | cmp al,'A' 144 | je addresses_option 145 | cmp al,'b' 146 | je bytes_per_line_option 147 | cmp al,'B' 148 | je bytes_per_line_option 149 | bad_params: 150 | stc 151 | ret 152 | get_option_value: 153 | xor eax,eax 154 | mov edx,eax 155 | get_option_digit: 156 | lodsb 157 | cmp al,20h 158 | je option_value_ok 159 | cmp al,0Dh 160 | je option_value_ok 161 | or al,al 162 | jz option_value_ok 163 | sub al,30h 164 | jc invalid_option_value 165 | cmp al,9 166 | ja invalid_option_value 167 | imul edx,10 168 | jo invalid_option_value 169 | add edx,eax 170 | jc invalid_option_value 171 | jmp get_option_digit 172 | option_value_ok: 173 | dec esi 174 | clc 175 | ret 176 | invalid_option_value: 177 | stc 178 | ret 179 | bytes_per_line_option: 180 | lodsb 181 | cmp al,20h 182 | je bytes_per_line_option 183 | cmp al,0Dh 184 | je bad_params 185 | or al,al 186 | jz bad_params 187 | dec esi 188 | call get_option_value 189 | or edx,edx 190 | jz bad_params 191 | cmp edx,1000 192 | ja bad_params 193 | mov [code_bytes_per_line],edx 194 | jmp find_param 195 | addresses_option: 196 | lodsb 197 | cmp al,20h 198 | je set_addresses_option 199 | cmp al,0Dh 200 | je set_addresses_option 201 | or al,al 202 | jnz bad_params 203 | set_addresses_option: 204 | dec esi 205 | mov [show_addresses],1 206 | jmp find_param 207 | param_end: 208 | dec esi 209 | string_param_end: 210 | xor al,al 211 | stosb 212 | jmp find_param 213 | all_params: 214 | cmp [input_file],0 215 | je bad_params 216 | cmp [output_file],0 217 | je bad_params 218 | clc 219 | ret 220 | 221 | include 'system.inc' 222 | 223 | include '..\listing.inc' 224 | 225 | section '.idata' import data readable writeable 226 | 227 | library kernel32,'KERNEL32.DLL' 228 | 229 | include 'api\kernel32.inc' 230 | -------------------------------------------------------------------------------- /fasm_src/source/errors.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | out_of_memory: 7 | push _out_of_memory 8 | jmp fatal_error 9 | stack_overflow: 10 | push _stack_overflow 11 | jmp fatal_error 12 | main_file_not_found: 13 | push _main_file_not_found 14 | jmp fatal_error 15 | write_failed: 16 | push _write_failed 17 | jmp fatal_error 18 | 19 | unexpected_end_of_file: 20 | push _unexpected_end_of_file 21 | jmp general_error 22 | code_cannot_be_generated: 23 | push _code_cannot_be_generated 24 | jmp general_error 25 | format_limitations_exceeded: 26 | push _format_limitations_exceeded 27 | jmp general_error 28 | invalid_definition: 29 | push _invalid_definition 30 | general_error: 31 | cmp [symbols_file],0 32 | je fatal_error 33 | call dump_preprocessed_source 34 | jmp fatal_error 35 | 36 | file_not_found: 37 | push _file_not_found 38 | jmp error_with_source 39 | error_reading_file: 40 | push _error_reading_file 41 | jmp error_with_source 42 | invalid_file_format: 43 | push _invalid_file_format 44 | jmp error_with_source 45 | invalid_macro_arguments: 46 | push _invalid_macro_arguments 47 | jmp error_with_source 48 | incomplete_macro: 49 | push _incomplete_macro 50 | jmp error_with_source 51 | unexpected_characters: 52 | push _unexpected_characters 53 | jmp error_with_source 54 | invalid_argument: 55 | push _invalid_argument 56 | jmp error_with_source 57 | illegal_instruction: 58 | push _illegal_instruction 59 | jmp error_with_source 60 | invalid_operand: 61 | push _invalid_operand 62 | jmp error_with_source 63 | invalid_operand_size: 64 | push _invalid_operand_size 65 | jmp error_with_source 66 | operand_size_not_specified: 67 | push _operand_size_not_specified 68 | jmp error_with_source 69 | operand_sizes_do_not_match: 70 | push _operand_sizes_do_not_match 71 | jmp error_with_source 72 | invalid_address_size: 73 | push _invalid_address_size 74 | jmp error_with_source 75 | address_sizes_do_not_agree: 76 | push _address_sizes_do_not_agree 77 | jmp error_with_source 78 | disallowed_combination_of_registers: 79 | push _disallowed_combination_of_registers 80 | jmp error_with_source 81 | long_immediate_not_encodable: 82 | push _long_immediate_not_encodable 83 | jmp error_with_source 84 | relative_jump_out_of_range: 85 | push _relative_jump_out_of_range 86 | jmp error_with_source 87 | invalid_expression: 88 | push _invalid_expression 89 | jmp error_with_source 90 | invalid_address: 91 | push _invalid_address 92 | jmp error_with_source 93 | invalid_value: 94 | push _invalid_value 95 | jmp error_with_source 96 | value_out_of_range: 97 | push _value_out_of_range 98 | jmp error_with_source 99 | undefined_symbol: 100 | mov edi,message 101 | mov esi,_undefined_symbol 102 | call copy_asciiz 103 | push message 104 | cmp [error_info],0 105 | je error_with_source 106 | mov esi,[error_info] 107 | mov esi,[esi+24] 108 | or esi,esi 109 | jz error_with_source 110 | mov byte [edi-1],20h 111 | call write_quoted_symbol_name 112 | jmp error_with_source 113 | copy_asciiz: 114 | lods byte [esi] 115 | stos byte [edi] 116 | test al,al 117 | jnz copy_asciiz 118 | ret 119 | write_quoted_symbol_name: 120 | mov al,27h 121 | stosb 122 | movzx ecx,byte [esi-1] 123 | rep movs byte [edi],[esi] 124 | mov ax,27h 125 | stosw 126 | ret 127 | symbol_out_of_scope: 128 | mov edi,message 129 | mov esi,_symbol_out_of_scope_1 130 | call copy_asciiz 131 | cmp [error_info],0 132 | je finish_symbol_out_of_scope_message 133 | mov esi,[error_info] 134 | mov esi,[esi+24] 135 | or esi,esi 136 | jz finish_symbol_out_of_scope_message 137 | mov byte [edi-1],20h 138 | call write_quoted_symbol_name 139 | finish_symbol_out_of_scope_message: 140 | mov byte [edi-1],20h 141 | mov esi,_symbol_out_of_scope_2 142 | call copy_asciiz 143 | push message 144 | jmp error_with_source 145 | invalid_use_of_symbol: 146 | push _invalid_use_of_symbol 147 | jmp error_with_source 148 | name_too_long: 149 | push _name_too_long 150 | jmp error_with_source 151 | invalid_name: 152 | push _invalid_name 153 | jmp error_with_source 154 | reserved_word_used_as_symbol: 155 | push _reserved_word_used_as_symbol 156 | jmp error_with_source 157 | symbol_already_defined: 158 | push _symbol_already_defined 159 | jmp error_with_source 160 | missing_end_quote: 161 | push _missing_end_quote 162 | jmp error_with_source 163 | missing_end_directive: 164 | push _missing_end_directive 165 | jmp error_with_source 166 | unexpected_instruction: 167 | push _unexpected_instruction 168 | jmp error_with_source 169 | extra_characters_on_line: 170 | push _extra_characters_on_line 171 | jmp error_with_source 172 | section_not_aligned_enough: 173 | push _section_not_aligned_enough 174 | jmp error_with_source 175 | setting_already_specified: 176 | push _setting_already_specified 177 | jmp error_with_source 178 | data_already_defined: 179 | push _data_already_defined 180 | jmp error_with_source 181 | too_many_repeats: 182 | push _too_many_repeats 183 | jmp error_with_source 184 | assertion_failed: 185 | push _assertion_failed 186 | jmp error_with_source 187 | invoked_error: 188 | push _invoked_error 189 | error_with_source: 190 | cmp [symbols_file],0 191 | je assembler_error 192 | call dump_preprocessed_source 193 | call restore_preprocessed_source 194 | jmp assembler_error 195 | -------------------------------------------------------------------------------- /objconv_src/source/maindef.h: -------------------------------------------------------------------------------- 1 | /**************************** maindef.h ********************************** 2 | * Author: Agner Fog 3 | * Date created: 2006-08-26 4 | * Last modified: 2016-11-27 5 | * Project: objconv 6 | * Module: maindef.h 7 | * Description: 8 | * Header file for type definitions and other main definitions. 9 | * 10 | * Copyright 2006-2015 GNU General Public License http://www.gnu.org/licenses 11 | *****************************************************************************/ 12 | #ifndef MAINDEF_H 13 | #define MAINDEF_H 14 | 15 | // Program version 16 | #define OBJCONV_VERSION 2.44 17 | 18 | 19 | // Integer type definitions with platform-independent sizes: 20 | #include 21 | #if defined(_I64_MAX) 22 | // Microsoft compilers use __int64 etc 23 | typedef char int8; // 8 bit signed integer 24 | typedef unsigned char uint8; // 8 bit unsigned integer 25 | typedef short int int16; // 16 bit signed integer 26 | typedef unsigned short int uint16; // 16 bit unsigned integer 27 | typedef int int32; // 32 bit signed integer 28 | typedef unsigned int uint32; // 32 bit unsigned integer 29 | typedef __int64 int64; // 64 bit signed integer 30 | typedef unsigned __int64 uint64; // 64 bit unsigned integer 31 | 32 | #elif defined(INT_MAX) && defined(LLONG_MAX) && INT_MAX==2147483647L && LLONG_MAX==9223372036854775807LL 33 | // Compiler has int = 32 bit and long long = 64 bit 34 | typedef char int8; // 8 bit signed integer 35 | typedef unsigned char uint8; // 8 bit unsigned integer 36 | typedef short int int16; // 16 bit signed integer 37 | typedef unsigned short int uint16; // 16 bit unsigned integer 38 | typedef int int32; // 32 bit signed integer 39 | typedef unsigned int uint32; // 32 bit unsigned integer 40 | typedef long long int64; // 64 bit signed integer 41 | typedef unsigned long long uint64; // 64 bit unsigned integer 42 | 43 | #else 44 | // Compilers supporting C99 or C++0x or C++1x have inttypes.h defining these integer types 45 | // This is the preferred solution: 46 | #include 47 | //typedef int8_t int8; // Gnu compiler can't convert int8_t to char 48 | typedef char int8; // 8 bit signed integer 49 | typedef uint8_t uint8; // 8 bit unsigned integer 50 | typedef int16_t int16; // 16 bit signed integer 51 | typedef uint16_t uint16; // 16 bit unsigned integer 52 | typedef int32_t int32; // 32 bit signed integer 53 | typedef uint32_t uint32; // 32 bit unsigned integer 54 | typedef int64_t int64; // 64 bit signed integer 55 | typedef uint64_t uint64; // 64 bit unsigned integer 56 | #endif 57 | 58 | 59 | // Get high part of a 64-bit integer 60 | static inline uint32 HighDWord (uint64 x) { 61 | return (uint32)(x >> 32); 62 | } 63 | 64 | // Check if compiling for big-endian machine 65 | // (__BIG_ENDIAN__ may not be defined even on big endian systems, so this check is not 66 | // sufficient. A further check is done in CheckEndianness() in main.cpp) 67 | #if defined(__BIG_ENDIAN__) && (__BIG_ENDIAN__ != 4321) 68 | #error This machine has big-endian memory organization. Objconv program will not work 69 | #endif 70 | 71 | // Max file name length 72 | #define MAXFILENAMELENGTH 256 73 | 74 | 75 | // File types 76 | #define FILETYPE_COFF 1 // Windows COFF/PE file 77 | #define FILETYPE_OMF 2 // Windows OMF file 78 | #define FILETYPE_ELF 3 // Linux or BSD ELF file 79 | #define FILETYPE_MACHO_LE 4 // Mach-O file, little endian 80 | #define FILETYPE_MACHO_BE 5 // Mach-O file, big endian 81 | #define FILETYPE_DOS 6 // DOS file 82 | #define FILETYPE_WIN3X 7 // Windows 3.x file 83 | #define IMPORT_LIBRARY_MEMBER 0x10 // Member of import library, Windows 84 | #define FILETYPE_MAC_UNIVBIN 0x11 // Macintosh universal binary 85 | #define FILETYPE_MS_WPO 0x20 // Object file for whole program optimization, MS 86 | #define FILETYPE_INTEL_WPO 0x21 // Object file for whole program optimization, Intel 87 | #define FILETYPE_WIN_UNKNOWN 0x29 // Unknown subtype, Windows 88 | #define FILETYPE_ASM 0x100 // Disassembly output 89 | #define FILETYPE_LIBRARY 0x1000 // UNIX-style library/archive 90 | #define FILETYPE_OMFLIBRARY 0x2000 // OMF-style library 91 | 92 | // Library subtypes 93 | #define LIBTYPE_OMF 0x01 // OMF library 94 | #define LIBTYPE_SHORTNAMES 0x10 // Short member names only, compatible with all systems 95 | #define LIBTYPE_WINDOWS 0x11 // Long member names in "//" member, terminated by 0 96 | #define LIBTYPE_LINUX 0x12 // Long member names in "//" member, terminated by '/'+LF 97 | #define LIBTYPE_BSD_MAC 0x13 // Long member name after header. Length indicated by #1/ 98 | 99 | // Define constants for symbol scope 100 | #define S_LOCAL 0 // Local symbol. Accessed only internally 101 | #define S_PUBLIC 1 // Public symbol. Visible from other modules 102 | #define S_EXTERNAL 2 // External symbol. Defined in another module 103 | 104 | 105 | // Macro to calculate the size of an array 106 | #define TableSize(x) ((int)(sizeof(x)/sizeof(x[0]))) 107 | 108 | 109 | // Structures and functions used for lookup tables: 110 | 111 | // Structure of integers and char *, used for tables of text strings 112 | struct SIntTxt { 113 | uint32 a; 114 | const char * b; 115 | }; 116 | 117 | // Translate integer value to text string by looking up in table of SIntTxt. 118 | // Parameters: p = table, n = length of table, x = value to find in table 119 | static inline char const * LookupText(SIntTxt const * p, int n, uint32 x) { 120 | for (int i=0; ia == x) return p->b; 122 | } 123 | // Not found 124 | static char utext[32]; 125 | sprintf(utext, "unknown(0x%X)", x); 126 | return utext; 127 | } 128 | 129 | // Macro to get length of text list and call LookupText 130 | #define Lookup(list,x) LookupText(list, sizeof(list)/sizeof(list[0]), x) 131 | 132 | 133 | // Function to convert powers of 2 to index 134 | int FloorLog2(uint32 x); 135 | 136 | // Convert 32 bit time stamp to string 137 | const char * timestring(uint32 t); 138 | 139 | #endif // #ifndef MAINDEF_H 140 | -------------------------------------------------------------------------------- /objconv_src/source/library.h: -------------------------------------------------------------------------------- 1 | /**************************** library.h ******************************** 2 | * Author: Agner Fog 3 | * Date created: 2006-07-15 4 | * Last modified: 2013-08-22 5 | * Project: objconv 6 | * Module: library.h 7 | * Description: 8 | * Header file defining classes for reading and writing UNIX and OMF style 9 | * libraries. 10 | * 11 | * Copyright 2007-2013 GNU General Public License http://www.gnu.org/licenses 12 | *****************************************************************************/ 13 | 14 | #ifndef LIBRARY_H 15 | #define LIBRARY_H 16 | 17 | 18 | // Make big-endian numbers for library 19 | uint32 EndianChange(uint32); // Convert little-endian to big-endian number, or vice versa 20 | 21 | 22 | // Define UNIX library member header 23 | struct SUNIXLibraryHeader { 24 | char Name[16]; // Member name 25 | char Date[12]; // Member date, seconds, decimal ASCII 26 | char UserID[6]; // Member User ID, decimal ASCII 27 | char GroupID[6]; // Member Group ID, decimal ASCII 28 | char FileMode[8]; // Member file mode, octal 29 | char FileSize[10]; // Member file size, decimal ASCII 30 | char HeaderEnd[2]; // "`\n" 31 | }; 32 | 33 | 34 | // Class for extracting members from library or building a library 35 | class CLibrary : public CFileBuffer { 36 | public: 37 | CLibrary(); // Constructor 38 | void Go(); // Do whatever the command line says 39 | void Dump(); // Print contents of library 40 | //static char *TruncateMemberName(char const*);// Remove path and truncate object file name to 15 characters 41 | static char * ShortenMemberName(char const *name); // Truncate library member name to 15 characters and make unique. The original long name is not overwritten 42 | static char * StripMemberName(char *); // Remove path from library member name. Original long name is overwritten 43 | const char * GetModuleName(uint32 Index); // Get name of module from index or page index 44 | protected: 45 | // Properties for UNIX input libraries only 46 | uint32 LongNames; // Offset to long names member 47 | uint32 LongNamesSize; // Size of long names member 48 | uint32 AlignBy; // Member alignment 49 | 50 | // Properties for OMF input libraries only 51 | uint32 PageSize; // Alignment of members 52 | uint32 DictionaryOffset; // Offset to hash table 53 | uint32 DictionarySize; // Dictionary size, in 512 bytes blocks 54 | 55 | // Methods and properties for reading library: 56 | void DumpUNIX(); // Print contents of UNIX style library 57 | void DumpOMF(); // Print contents of OMF style library 58 | void CheckOMFHash(CMemoryBuffer &stringbuf, CSList &index);// Check if OMF library hash table has correct entries for all symbol names 59 | void StartExtracting(); // Initialize before ExtractMember() 60 | char * ExtractMember(CFileBuffer*); // Extract next library member from input library 61 | char * ExtractMemberUNIX(CFileBuffer*); // Extract member of UNIX style library 62 | char * ExtractMemberOMF(CFileBuffer*); // Extract member of OMF style library 63 | uint32 NextHeader(uint32 Offset); // Loop through library headers 64 | CConverter MemberBuffer; // Buffer containing single library member 65 | uint32 CurrentOffset; // Offset to current member 66 | uint32 CurrentNumber; // Number of current member 67 | int MemberFileType; // File type of members 68 | // Methods and properties for modifying or writing library 69 | void FixNames(); // Calls StripMemberNamesUNIX or RebuildOMF 70 | void StripMemberNamesUNIX(); // Remove path from member names 71 | void RebuildOMF(); // Rebuild OMF style library to make member names short 72 | void InsertMember(CFileBuffer*); // Add next library member to output library 73 | void InsertMemberUNIX(CFileBuffer*);// Add member to UNIX library 74 | void InsertMemberOMF(CFileBuffer*); // Add member to OMF library 75 | void MakeBinaryFile(); // Combine string index and members into binary file 76 | void MakeBinaryFileUNIX(); // Make UNIX library 77 | void MakeBinaryFileOMF(); // Make OMF library 78 | void SortStringTable(); // Sort the string table 79 | void MakeSymbolTableUnix(); // Make symbol table for COFF, ELF or MACHO library 80 | CFileBuffer OutFile; // Buffer for building output file 81 | CSList StringEntries; // String table using SStringEntry 82 | CMemoryBuffer LongNamesBuffer; // Buffer for building the "//" longnames member 83 | CMemoryBuffer StringBuffer; // Buffer containing strings 84 | CMemoryBuffer DataBuffer; // Buffer containing raw members 85 | CSList Indexes; // Buffer containing indexes into DataBuffer 86 | int RepressWarnings; // Repress warnings when rebuilding library 87 | }; 88 | 89 | 90 | // Definitions for OMF library hash table: 91 | 92 | #define OMFNumBuckets 37 // Number of buckets per block 93 | 94 | #define OMFBlockSize 512 // Size of each block 95 | 96 | // Structure of hash table block 97 | union SOMFHashBlock { 98 | struct { 99 | uint8 Buckets[OMFNumBuckets]; // Indicators for each bucket 100 | uint8 FreeSpace; // Pointer to free space 101 | uint8 Data[OMFBlockSize-OMFNumBuckets-1]; // Contains strings and module indices 102 | } b; 103 | uint8 Strings[OMFBlockSize]; // Start of each string = length 104 | }; 105 | 106 | 107 | // Hash table handler 108 | class COMFHashTable { 109 | public: 110 | void Init(SOMFHashBlock * blocks, uint32 NumBlocks); // Initialize 111 | void MakeHash(int8 * name); // Compute hash 112 | int FindString(uint32 & ModulePage, uint32 & Conflicts); // Search for string. Get number of occurrences, module, number of conflicting strings 113 | int InsertString(uint16 & ModulePage); // Insert string in hash table. Return 0 if success 114 | void MakeHashTable(CSList & StringEntries, CMemoryBuffer & StringBuffer, CMemoryBuffer & HashTable, CLibrary * Library); // Make hash table 115 | protected: 116 | uint8 * String; // String to search for or insert 117 | uint32 StringLength; // Length of string 118 | SOMFHashBlock * blocks; // Pointer to blocks 119 | uint32 NumBlocks; // Number of blocks 120 | uint16 StartBlock; // Start block for search 121 | uint16 StartBucket; // Start bucket for search 122 | uint16 BlockD; // Block step size in search 123 | uint16 BucketD; // Bucket step size in search 124 | }; 125 | 126 | #endif // #ifndef LIBRARY_H 127 | -------------------------------------------------------------------------------- /fasm_src/source/Linux/fasm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Linux 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | format ELF executable 3 7 | entry start 8 | 9 | segment readable executable 10 | 11 | start: 12 | 13 | mov [con_handle],1 14 | mov esi,_logo 15 | call display_string 16 | 17 | mov [command_line],esp 18 | mov ecx,[esp] 19 | mov ebx,[esp+4+ecx*4+4] 20 | mov [environment],ebx 21 | call get_params 22 | jc information 23 | 24 | call init_memory 25 | 26 | mov esi,_memory_prefix 27 | call display_string 28 | mov eax,[memory_end] 29 | sub eax,[memory_start] 30 | add eax,[additional_memory_end] 31 | sub eax,[additional_memory] 32 | shr eax,10 33 | call display_number 34 | mov esi,_memory_suffix 35 | call display_string 36 | 37 | mov eax,78 38 | mov ebx,buffer 39 | xor ecx,ecx 40 | int 0x80 41 | mov eax,dword [buffer] 42 | mov ecx,1000 43 | mul ecx 44 | mov ebx,eax 45 | mov eax,dword [buffer+4] 46 | div ecx 47 | add eax,ebx 48 | mov [start_time],eax 49 | 50 | and [preprocessing_done],0 51 | call preprocessor 52 | or [preprocessing_done],-1 53 | call parser 54 | call assembler 55 | call formatter 56 | 57 | call display_user_messages 58 | movzx eax,[current_pass] 59 | inc eax 60 | call display_number 61 | mov esi,_passes_suffix 62 | call display_string 63 | mov eax,78 64 | mov ebx,buffer 65 | xor ecx,ecx 66 | int 0x80 67 | mov eax,dword [buffer] 68 | mov ecx,1000 69 | mul ecx 70 | mov ebx,eax 71 | mov eax,dword [buffer+4] 72 | div ecx 73 | add eax,ebx 74 | sub eax,[start_time] 75 | jnc time_ok 76 | add eax,3600000 77 | time_ok: 78 | xor edx,edx 79 | mov ebx,100 80 | div ebx 81 | or eax,eax 82 | jz display_bytes_count 83 | xor edx,edx 84 | mov ebx,10 85 | div ebx 86 | push edx 87 | call display_number 88 | mov dl,'.' 89 | call display_character 90 | pop eax 91 | call display_number 92 | mov esi,_seconds_suffix 93 | call display_string 94 | display_bytes_count: 95 | mov eax,[written_size] 96 | call display_number 97 | mov esi,_bytes_suffix 98 | call display_string 99 | xor al,al 100 | jmp exit_program 101 | 102 | information: 103 | mov esi,_usage 104 | call display_string 105 | mov al,1 106 | jmp exit_program 107 | 108 | get_params: 109 | mov ebx,[command_line] 110 | mov [input_file],0 111 | mov [output_file],0 112 | mov [symbols_file],0 113 | mov [memory_setting],0 114 | mov [passes_limit],100 115 | mov ecx,[ebx] 116 | add ebx,8 117 | dec ecx 118 | jz bad_params 119 | mov [definitions_pointer],predefinitions 120 | get_param: 121 | mov esi,[ebx] 122 | mov al,[esi] 123 | cmp al,'-' 124 | je option_param 125 | cmp [input_file],0 126 | jne get_output_file 127 | mov [input_file],esi 128 | jmp next_param 129 | get_output_file: 130 | cmp [output_file],0 131 | jne bad_params 132 | mov [output_file],esi 133 | jmp next_param 134 | option_param: 135 | inc esi 136 | lodsb 137 | cmp al,'m' 138 | je memory_option 139 | cmp al,'M' 140 | je memory_option 141 | cmp al,'p' 142 | je passes_option 143 | cmp al,'P' 144 | je passes_option 145 | cmp al,'d' 146 | je definition_option 147 | cmp al,'D' 148 | je definition_option 149 | cmp al,'s' 150 | je symbols_option 151 | cmp al,'S' 152 | je symbols_option 153 | bad_params: 154 | stc 155 | ret 156 | memory_option: 157 | cmp byte [esi],0 158 | jne get_memory_setting 159 | dec ecx 160 | jz bad_params 161 | add ebx,4 162 | mov esi,[ebx] 163 | get_memory_setting: 164 | call get_option_value 165 | or edx,edx 166 | jz bad_params 167 | cmp edx,1 shl (32-10) 168 | jae bad_params 169 | mov [memory_setting],edx 170 | jmp next_param 171 | passes_option: 172 | cmp byte [esi],0 173 | jne get_passes_setting 174 | dec ecx 175 | jz bad_params 176 | add ebx,4 177 | mov esi,[ebx] 178 | get_passes_setting: 179 | call get_option_value 180 | or edx,edx 181 | jz bad_params 182 | cmp edx,10000h 183 | ja bad_params 184 | mov [passes_limit],dx 185 | next_param: 186 | add ebx,4 187 | dec ecx 188 | jnz get_param 189 | cmp [input_file],0 190 | je bad_params 191 | mov eax,[definitions_pointer] 192 | mov byte [eax],0 193 | mov [initial_definitions],predefinitions 194 | clc 195 | ret 196 | definition_option: 197 | cmp byte [esi],0 198 | jne get_definition 199 | dec ecx 200 | jz bad_params 201 | add ebx,4 202 | mov esi,[ebx] 203 | get_definition: 204 | push edi 205 | mov edi,[definitions_pointer] 206 | call convert_definition_option 207 | mov [definitions_pointer],edi 208 | pop edi 209 | jc bad_params 210 | jmp next_param 211 | symbols_option: 212 | cmp byte [esi],0 213 | jne get_symbols_setting 214 | dec ecx 215 | jz bad_params 216 | add ebx,4 217 | mov esi,[ebx] 218 | get_symbols_setting: 219 | mov [symbols_file],esi 220 | jmp next_param 221 | get_option_value: 222 | xor eax,eax 223 | mov edx,eax 224 | get_option_digit: 225 | lodsb 226 | cmp al,20h 227 | je option_value_ok 228 | or al,al 229 | jz option_value_ok 230 | sub al,30h 231 | jc invalid_option_value 232 | cmp al,9 233 | ja invalid_option_value 234 | imul edx,10 235 | jo invalid_option_value 236 | add edx,eax 237 | jc invalid_option_value 238 | jmp get_option_digit 239 | option_value_ok: 240 | dec esi 241 | clc 242 | ret 243 | invalid_option_value: 244 | stc 245 | ret 246 | convert_definition_option: 247 | mov edx,edi 248 | xor al,al 249 | stosb 250 | copy_definition_name: 251 | lodsb 252 | cmp al,'=' 253 | je copy_definition_value 254 | cmp al,20h 255 | je bad_definition_option 256 | or al,al 257 | jz bad_definition_option 258 | stosb 259 | inc byte [edx] 260 | jnz copy_definition_name 261 | bad_definition_option: 262 | stc 263 | ret 264 | copy_definition_value: 265 | lodsb 266 | cmp al,20h 267 | je definition_value_end 268 | or al,al 269 | jz definition_value_end 270 | stosb 271 | jmp copy_definition_value 272 | definition_value_end: 273 | dec esi 274 | xor al,al 275 | stosb 276 | clc 277 | ret 278 | 279 | include 'system.inc' 280 | 281 | include '..\version.inc' 282 | 283 | _copyright db 'Copyright (c) 1999-2016, Tomasz Grysztar',0xA,0 284 | 285 | _logo db 'flat assembler version ',VERSION_STRING,0 286 | _usage db 0xA 287 | db 'usage: fasm [output]',0xA 288 | db 'optional settings:',0xA 289 | db ' -m set the limit in kilobytes for the available memory',0xA 290 | db ' -p set the maximum allowed number of passes',0xA 291 | db ' -d = define symbolic variable',0xA 292 | db ' -s dump symbolic information for debugging',0xA 293 | db 0 294 | _memory_prefix db ' (',0 295 | _memory_suffix db ' kilobytes memory)',0xA,0 296 | _passes_suffix db ' passes, ',0 297 | _seconds_suffix db ' seconds, ',0 298 | _bytes_suffix db ' bytes.',0xA,0 299 | 300 | include '..\errors.inc' 301 | include '..\symbdump.inc' 302 | include '..\preproce.inc' 303 | include '..\parser.inc' 304 | include '..\exprpars.inc' 305 | include '..\assemble.inc' 306 | include '..\exprcalc.inc' 307 | include '..\formats.inc' 308 | include '..\x86_64.inc' 309 | include '..\avx.inc' 310 | 311 | include '..\tables.inc' 312 | include '..\messages.inc' 313 | 314 | segment readable writeable 315 | 316 | align 4 317 | 318 | include '..\variable.inc' 319 | 320 | command_line dd ? 321 | memory_setting dd ? 322 | definitions_pointer dd ? 323 | environment dd ? 324 | timestamp dq ? 325 | start_time dd ? 326 | con_handle dd ? 327 | displayed_count dd ? 328 | last_displayed db ? 329 | character db ? 330 | preprocessing_done db ? 331 | 332 | predefinitions rb 1000h 333 | buffer rb 1000h 334 | -------------------------------------------------------------------------------- /fasm_src/source/libc/fasm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Unix/libc 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | format ELF 7 | public main 8 | 9 | macro ccall proc,[arg] 10 | { common 11 | local size 12 | size = 0 13 | mov ebp,esp 14 | if ~ arg eq 15 | forward 16 | size = size + 4 17 | common 18 | sub esp,size 19 | end if 20 | and esp,-16 21 | if ~ arg eq 22 | add esp,size 23 | reverse 24 | pushd arg 25 | common 26 | end if 27 | call proc 28 | mov esp,ebp } 29 | 30 | extrn gettimeofday 31 | 32 | section '.text' executable align 16 33 | 34 | main: 35 | mov ecx,[esp+4] 36 | mov [argc],ecx 37 | mov ebx,[esp+8] 38 | mov [argv],ebx 39 | push ebp 40 | mov [stack_frame],esp 41 | 42 | mov [con_handle],1 43 | mov esi,_logo 44 | call display_string 45 | 46 | call get_params 47 | jc information 48 | 49 | call init_memory 50 | 51 | mov esi,_memory_prefix 52 | call display_string 53 | mov eax,[memory_end] 54 | sub eax,[memory_start] 55 | add eax,[additional_memory_end] 56 | sub eax,[additional_memory] 57 | shr eax,10 58 | call display_number 59 | mov esi,_memory_suffix 60 | call display_string 61 | 62 | ccall gettimeofday,buffer,0 63 | mov eax,dword [buffer] 64 | mov ecx,1000 65 | mul ecx 66 | mov ebx,eax 67 | mov eax,dword [buffer+4] 68 | div ecx 69 | add eax,ebx 70 | mov [start_time],eax 71 | 72 | and [preprocessing_done],0 73 | call preprocessor 74 | or [preprocessing_done],-1 75 | call parser 76 | call assembler 77 | call formatter 78 | 79 | call display_user_messages 80 | movzx eax,[current_pass] 81 | inc eax 82 | call display_number 83 | mov esi,_passes_suffix 84 | call display_string 85 | ccall gettimeofday,buffer,0 86 | mov eax,dword [buffer] 87 | mov ecx,1000 88 | mul ecx 89 | mov ebx,eax 90 | mov eax,dword [buffer+4] 91 | div ecx 92 | add eax,ebx 93 | sub eax,[start_time] 94 | jnc time_ok 95 | add eax,3600000 96 | time_ok: 97 | xor edx,edx 98 | mov ebx,100 99 | div ebx 100 | or eax,eax 101 | jz display_bytes_count 102 | xor edx,edx 103 | mov ebx,10 104 | div ebx 105 | push edx 106 | call display_number 107 | mov dl,'.' 108 | call display_character 109 | pop eax 110 | call display_number 111 | mov esi,_seconds_suffix 112 | call display_string 113 | display_bytes_count: 114 | mov eax,[written_size] 115 | call display_number 116 | mov esi,_bytes_suffix 117 | call display_string 118 | xor al,al 119 | jmp exit_program 120 | 121 | information: 122 | mov esi,_usage 123 | call display_string 124 | mov al,1 125 | jmp exit_program 126 | 127 | get_params: 128 | mov [input_file],0 129 | mov [output_file],0 130 | mov [symbols_file],0 131 | mov [memory_setting],0 132 | mov [passes_limit],100 133 | 134 | mov ecx,[argc] 135 | mov ebx,[argv] 136 | add ebx,4 137 | dec ecx 138 | jz bad_params 139 | mov [definitions_pointer],predefinitions 140 | get_param: 141 | mov esi,[ebx] 142 | mov al,[esi] 143 | cmp al,'-' 144 | je option_param 145 | cmp [input_file],0 146 | jne get_output_file 147 | mov [input_file],esi 148 | jmp next_param 149 | get_output_file: 150 | cmp [output_file],0 151 | jne bad_params 152 | mov [output_file],esi 153 | jmp next_param 154 | option_param: 155 | inc esi 156 | lodsb 157 | cmp al,'m' 158 | je memory_option 159 | cmp al,'M' 160 | je memory_option 161 | cmp al,'p' 162 | je passes_option 163 | cmp al,'P' 164 | je passes_option 165 | cmp al,'d' 166 | je definition_option 167 | cmp al,'D' 168 | je definition_option 169 | cmp al,'s' 170 | je symbols_option 171 | cmp al,'S' 172 | je symbols_option 173 | bad_params: 174 | stc 175 | ret 176 | memory_option: 177 | cmp byte [esi],0 178 | jne get_memory_setting 179 | dec ecx 180 | jz bad_params 181 | add ebx,4 182 | mov esi,[ebx] 183 | get_memory_setting: 184 | call get_option_value 185 | or edx,edx 186 | jz bad_params 187 | cmp edx,1 shl (32-10) 188 | jae bad_params 189 | mov [memory_setting],edx 190 | jmp next_param 191 | passes_option: 192 | cmp byte [esi],0 193 | jne get_passes_setting 194 | dec ecx 195 | jz bad_params 196 | add ebx,4 197 | mov esi,[ebx] 198 | get_passes_setting: 199 | call get_option_value 200 | or edx,edx 201 | jz bad_params 202 | cmp edx,10000h 203 | ja bad_params 204 | mov [passes_limit],dx 205 | next_param: 206 | add ebx,4 207 | dec ecx 208 | jnz get_param 209 | cmp [input_file],0 210 | je bad_params 211 | mov eax,[definitions_pointer] 212 | mov byte [eax],0 213 | mov [initial_definitions],predefinitions 214 | clc 215 | ret 216 | definition_option: 217 | cmp byte [esi],0 218 | jne get_definition 219 | dec ecx 220 | jz bad_params 221 | add ebx,4 222 | mov esi,[ebx] 223 | get_definition: 224 | push edi 225 | mov edi,[definitions_pointer] 226 | call convert_definition_option 227 | mov [definitions_pointer],edi 228 | pop edi 229 | jc bad_params 230 | jmp next_param 231 | symbols_option: 232 | cmp byte [esi],0 233 | jne get_symbols_setting 234 | dec ecx 235 | jz bad_params 236 | add ebx,4 237 | mov esi,[ebx] 238 | get_symbols_setting: 239 | mov [symbols_file],esi 240 | jmp next_param 241 | get_option_value: 242 | xor eax,eax 243 | mov edx,eax 244 | get_option_digit: 245 | lodsb 246 | cmp al,20h 247 | je option_value_ok 248 | cmp al,0Dh 249 | je option_value_ok 250 | or al,al 251 | jz option_value_ok 252 | sub al,30h 253 | jc invalid_option_value 254 | cmp al,9 255 | ja invalid_option_value 256 | imul edx,10 257 | jo invalid_option_value 258 | add edx,eax 259 | jc invalid_option_value 260 | jmp get_option_digit 261 | option_value_ok: 262 | dec esi 263 | clc 264 | ret 265 | invalid_option_value: 266 | stc 267 | ret 268 | convert_definition_option: 269 | mov edx,edi 270 | xor al,al 271 | stosb 272 | copy_definition_name: 273 | lodsb 274 | cmp al,'=' 275 | je copy_definition_value 276 | cmp al,20h 277 | je bad_definition_option 278 | or al,al 279 | jz bad_definition_option 280 | stosb 281 | inc byte [edx] 282 | jnz copy_definition_name 283 | bad_definition_option: 284 | stc 285 | ret 286 | copy_definition_value: 287 | lodsb 288 | cmp al,20h 289 | je definition_value_end 290 | or al,al 291 | jz definition_value_end 292 | stosb 293 | jmp copy_definition_value 294 | definition_value_end: 295 | dec esi 296 | xor al,al 297 | stosb 298 | clc 299 | ret 300 | 301 | include 'system.inc' 302 | 303 | include '..\version.inc' 304 | 305 | _copyright db 'Copyright (c) 1999-2016, Tomasz Grysztar',0xA,0 306 | 307 | _logo db 'flat assembler version ',VERSION_STRING,0 308 | _usage db 0xA 309 | db 'usage: fasm [output]',0xA 310 | db 'optional settings:',0xA 311 | db ' -m set the limit in kilobytes for the available memory',0xA 312 | db ' -p set the maximum allowed number of passes',0xA 313 | db ' -d = define symbolic variable',0xA 314 | db ' -s dump symbolic information for debugging',0xA 315 | db 0 316 | _memory_prefix db ' (',0 317 | _memory_suffix db ' kilobytes memory)',0xA,0 318 | _passes_suffix db ' passes, ',0 319 | _seconds_suffix db ' seconds, ',0 320 | _bytes_suffix db ' bytes.',0xA,0 321 | 322 | include '..\errors.inc' 323 | include '..\symbdump.inc' 324 | include '..\preproce.inc' 325 | include '..\parser.inc' 326 | include '..\exprpars.inc' 327 | include '..\assemble.inc' 328 | include '..\exprcalc.inc' 329 | include '..\formats.inc' 330 | include '..\x86_64.inc' 331 | include '..\avx.inc' 332 | 333 | include '..\tables.inc' 334 | include '..\messages.inc' 335 | 336 | section '.bss' writeable align 4 337 | 338 | include '..\variable.inc' 339 | 340 | argc dd ? 341 | argv dd ? 342 | stack_frame dd ? 343 | memory_setting dd ? 344 | definitions_pointer dd ? 345 | start_time dd ? 346 | timestamp dq ? 347 | con_handle dd ? 348 | displayed_count dd ? 349 | last_displayed db ? 350 | character db ? 351 | preprocessing_done db ? 352 | 353 | predefinitions rb 1000h 354 | buffer rb 1000h 355 | -------------------------------------------------------------------------------- /fasm_src/source/Linux/x64/fasm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Linux x64 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | format ELF64 executable 3 at 400000h 7 | entry start 8 | 9 | include 'modes.inc' 10 | 11 | segment readable executable 12 | 13 | start: 14 | 15 | mov [con_handle],1 16 | mov esi,_logo 17 | call display_string 18 | 19 | mov [command_line],rsp 20 | mov rcx,[rsp] 21 | mov rbx,[rsp+8+rcx*8+8] 22 | mov [environment],rbx 23 | call get_params 24 | jc information 25 | 26 | call init_memory 27 | 28 | mov esi,_memory_prefix 29 | call display_string 30 | mov eax,[memory_end] 31 | sub eax,[memory_start] 32 | add eax,[additional_memory_end] 33 | sub eax,[additional_memory] 34 | shr eax,10 35 | call display_number 36 | mov esi,_memory_suffix 37 | call display_string 38 | 39 | mov eax,96 40 | mov edi,buffer 41 | xor esi,esi 42 | syscall 43 | mov eax,dword [buffer] 44 | mov ecx,1000 45 | mul ecx 46 | mov ebx,eax 47 | mov eax,dword [buffer+4] 48 | div ecx 49 | add eax,ebx 50 | mov [start_time],eax 51 | 52 | and [preprocessing_done],0 53 | call preprocessor 54 | or [preprocessing_done],-1 55 | call parser 56 | call assembler 57 | call formatter 58 | 59 | call display_user_messages 60 | movzx eax,[current_pass] 61 | inc eax 62 | call display_number 63 | mov esi,_passes_suffix 64 | call display_string 65 | mov eax,96 66 | mov edi,buffer 67 | xor esi,esi 68 | syscall 69 | mov eax,dword [buffer] 70 | mov ecx,1000 71 | mul ecx 72 | mov ebx,eax 73 | mov eax,dword [buffer+4] 74 | div ecx 75 | add eax,ebx 76 | sub eax,[start_time] 77 | jnc time_ok 78 | add eax,3600000 79 | time_ok: 80 | xor edx,edx 81 | mov ebx,100 82 | div ebx 83 | or eax,eax 84 | jz display_bytes_count 85 | xor edx,edx 86 | mov ebx,10 87 | div ebx 88 | push edx 89 | call display_number 90 | mov dl,'.' 91 | call display_character 92 | pop eax 93 | call display_number 94 | mov esi,_seconds_suffix 95 | call display_string 96 | display_bytes_count: 97 | mov eax,[written_size] 98 | call display_number 99 | mov esi,_bytes_suffix 100 | call display_string 101 | xor al,al 102 | jmp exit_program 103 | 104 | information: 105 | mov esi,_usage 106 | call display_string 107 | mov al,1 108 | jmp exit_program 109 | 110 | get_params: 111 | mov rbx,[command_line] 112 | mov [input_file],0 113 | mov [output_file],0 114 | mov [symbols_file],0 115 | mov [memory_setting],0 116 | mov [passes_limit],100 117 | mov rcx,[rbx] 118 | add rbx,8*2 119 | dec rcx 120 | jz bad_params 121 | mov [definitions_pointer],predefinitions 122 | mov [path_pointer],paths 123 | get_param: 124 | mov rsi,[rbx] 125 | mov al,[rsi] 126 | cmp al,'-' 127 | je option_param 128 | cmp [input_file],0 129 | jne get_output_file 130 | call collect_path 131 | mov [input_file],edx 132 | jmp next_param 133 | get_output_file: 134 | cmp [output_file],0 135 | jne bad_params 136 | call collect_path 137 | mov [output_file],edx 138 | jmp next_param 139 | option_param: 140 | inc rsi 141 | lodsb 142 | cmp al,'m' 143 | je memory_option 144 | cmp al,'M' 145 | je memory_option 146 | cmp al,'p' 147 | je passes_option 148 | cmp al,'P' 149 | je passes_option 150 | cmp al,'d' 151 | je definition_option 152 | cmp al,'D' 153 | je definition_option 154 | cmp al,'s' 155 | je symbols_option 156 | cmp al,'S' 157 | je symbols_option 158 | bad_params: 159 | stc 160 | ret 161 | memory_option: 162 | cmp byte [rsi],0 163 | jne get_memory_setting 164 | dec rcx 165 | jz bad_params 166 | add rbx,8 167 | mov rsi,[rbx] 168 | get_memory_setting: 169 | call get_option_value 170 | or edx,edx 171 | jz bad_params 172 | cmp edx,1 shl (32-10) 173 | jae bad_params 174 | mov [memory_setting],edx 175 | jmp next_param 176 | passes_option: 177 | cmp byte [rsi],0 178 | jne get_passes_setting 179 | dec rcx 180 | jz bad_params 181 | add rbx,8 182 | mov rsi,[rbx] 183 | get_passes_setting: 184 | call get_option_value 185 | or edx,edx 186 | jz bad_params 187 | cmp edx,10000h 188 | ja bad_params 189 | mov [passes_limit],dx 190 | next_param: 191 | add rbx,8 192 | dec rcx 193 | jnz get_param 194 | cmp [input_file],0 195 | je bad_params 196 | mov eax,[definitions_pointer] 197 | mov byte [eax],0 198 | mov [initial_definitions],predefinitions 199 | clc 200 | ret 201 | definition_option: 202 | cmp byte [rsi],0 203 | jne get_definition 204 | dec rcx 205 | jz bad_params 206 | add rbx,8 207 | mov rsi,[rbx] 208 | get_definition: 209 | mov r12d,edi 210 | mov edi,[definitions_pointer] 211 | call convert_definition_option 212 | mov [definitions_pointer],edi 213 | mov edi,r12d 214 | jc bad_params 215 | jmp next_param 216 | symbols_option: 217 | cmp byte [rsi],0 218 | jne get_symbols_setting 219 | dec rcx 220 | jz bad_params 221 | add rbx,8 222 | mov rsi,[rbx] 223 | get_symbols_setting: 224 | call collect_path 225 | mov [symbols_file],edx 226 | jmp next_param 227 | get_option_value: 228 | xor eax,eax 229 | mov edx,eax 230 | get_option_digit: 231 | lodsb 232 | cmp al,20h 233 | je option_value_ok 234 | or al,al 235 | jz option_value_ok 236 | sub al,30h 237 | jc invalid_option_value 238 | cmp al,9 239 | ja invalid_option_value 240 | imul edx,10 241 | jo invalid_option_value 242 | add edx,eax 243 | jc invalid_option_value 244 | jmp get_option_digit 245 | option_value_ok: 246 | dec rsi 247 | clc 248 | ret 249 | invalid_option_value: 250 | stc 251 | ret 252 | convert_definition_option: 253 | mov edx,edi 254 | xor al,al 255 | stosb 256 | copy_definition_name: 257 | lodsb 258 | cmp al,'=' 259 | je copy_definition_value 260 | cmp al,20h 261 | je bad_definition_option 262 | or al,al 263 | jz bad_definition_option 264 | stosb 265 | inc byte [edx] 266 | jnz copy_definition_name 267 | bad_definition_option: 268 | stc 269 | ret 270 | copy_definition_value: 271 | lodsb 272 | cmp al,20h 273 | je definition_value_end 274 | or al,al 275 | jz definition_value_end 276 | stosb 277 | jmp copy_definition_value 278 | definition_value_end: 279 | dec rsi 280 | xor al,al 281 | stosb 282 | clc 283 | ret 284 | collect_path: 285 | mov edi,[path_pointer] 286 | mov edx,edi 287 | copy_path_to_low_memory: 288 | lodsb 289 | stosb 290 | test al,al 291 | jnz copy_path_to_low_memory 292 | mov [path_pointer],edi 293 | retn 294 | 295 | include 'system.inc' 296 | 297 | include '..\..\version.inc' 298 | 299 | _copyright db 'Copyright (c) 1999-2016, Tomasz Grysztar',0xA,0 300 | 301 | _logo db 'flat assembler version ',VERSION_STRING,0 302 | _usage db 0xA 303 | db 'usage: fasm [output]',0xA 304 | db 'optional settings:',0xA 305 | db ' -m set the limit in kilobytes for the available memory',0xA 306 | db ' -p set the maximum allowed number of passes',0xA 307 | db ' -d = define symbolic variable',0xA 308 | db ' -s dump symbolic information for debugging',0xA 309 | db 0 310 | _memory_prefix db ' (',0 311 | _memory_suffix db ' kilobytes memory, x64)',0xA,0 312 | _passes_suffix db ' passes, ',0 313 | _seconds_suffix db ' seconds, ',0 314 | _bytes_suffix db ' bytes.',0xA,0 315 | _no_low_memory db 'failed to allocate memory within 32-bit addressing range',0 316 | 317 | include '..\..\errors.inc' 318 | include '..\..\symbdump.inc' 319 | include '..\..\preproce.inc' 320 | include '..\..\parser.inc' 321 | include '..\..\exprpars.inc' 322 | include '..\..\assemble.inc' 323 | include '..\..\exprcalc.inc' 324 | include '..\..\formats.inc' 325 | include '..\..\avx.inc' 326 | include '..\..\x86_64.inc' 327 | 328 | include '..\..\tables.inc' 329 | include '..\..\messages.inc' 330 | 331 | segment readable writeable 332 | 333 | align 4 334 | 335 | include '..\..\variable.inc' 336 | 337 | command_line dq ? 338 | memory_setting dd ? 339 | path_pointer dd ? 340 | definitions_pointer dd ? 341 | environment dq ? 342 | timestamp dq ? 343 | start_time dd ? 344 | con_handle dd ? 345 | displayed_count dd ? 346 | last_displayed db ? 347 | character db ? 348 | preprocessing_done db ? 349 | 350 | buffer rb 1000h 351 | predefinitions rb 1000h 352 | paths rb 10000h 353 | -------------------------------------------------------------------------------- /fasm_src/source/libc/system.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Unix/libc 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | extrn malloc 7 | extrn free 8 | extrn getenv 9 | extrn fopen 10 | extrn fclose 11 | extrn fread 12 | extrn fwrite 13 | extrn fseek 14 | extrn ftell 15 | extrn time 16 | extrn exit 17 | 18 | extrn 'write' as libc_write 19 | 20 | init_memory: 21 | mov eax,esp 22 | and eax,not 0FFFh 23 | add eax,1000h-10000h 24 | mov [stack_limit],eax 25 | mov ecx,[memory_setting] 26 | shl ecx,10 27 | jnz allocate_memory 28 | mov ecx,1000000h 29 | allocate_memory: 30 | mov [memory_setting],ecx 31 | ccall malloc,ecx 32 | or eax,eax 33 | jz out_of_memory 34 | mov [additional_memory],eax 35 | add eax,[memory_setting] 36 | mov [memory_end],eax 37 | mov eax,[memory_setting] 38 | shr eax,2 39 | add eax,[additional_memory] 40 | mov [additional_memory_end],eax 41 | mov [memory_start],eax 42 | ret 43 | 44 | exit_program: 45 | movzx eax,al 46 | push eax 47 | ccall free,[additional_memory] 48 | pop eax 49 | ccall exit,eax 50 | mov esp,[stack_frame] 51 | pop ebp 52 | ret 53 | 54 | get_environment_variable: 55 | ccall getenv,esi 56 | mov esi,eax 57 | or eax,eax 58 | jz no_environment_variable 59 | copy_variable_value: 60 | lodsb 61 | cmp edi,[memory_end] 62 | jae out_of_memory 63 | stosb 64 | or al,al 65 | jnz copy_variable_value 66 | dec edi 67 | ret 68 | no_environment_variable: 69 | stosb 70 | dec edi 71 | ret 72 | 73 | open: 74 | push esi edi ebp 75 | call adapt_path 76 | ccall fopen,buffer,open_mode 77 | pop ebp edi esi 78 | or eax,eax 79 | jz file_error 80 | mov ebx,eax 81 | clc 82 | ret 83 | adapt_path: 84 | mov esi,edx 85 | mov edi,buffer 86 | copy_path: 87 | lods byte [esi] 88 | cmp al,'\' 89 | jne path_char_ok 90 | mov al,'/' 91 | path_char_ok: 92 | stos byte [edi] 93 | or al,al 94 | jnz copy_path 95 | mov eax,buffer 96 | add eax,1000h 97 | cmp edi,eax 98 | ja out_of_memory 99 | ret 100 | create: 101 | push esi edi ebp 102 | call adapt_path 103 | ccall fopen,buffer,create_mode 104 | pop ebp edi esi 105 | or eax,eax 106 | jz file_error 107 | mov ebx,eax 108 | clc 109 | ret 110 | close: 111 | ccall fclose,ebx 112 | ret 113 | read: 114 | push ebx ecx edx esi edi ebp 115 | ccall fread,edx,1,ecx,ebx 116 | pop ebp edi esi edx ecx ebx 117 | cmp eax,ecx 118 | jne file_error 119 | clc 120 | ret 121 | file_error: 122 | stc 123 | ret 124 | write: 125 | push ebx ecx edx esi edi ebp 126 | ccall fwrite,edx,1,ecx,ebx 127 | pop ebp edi esi edx ecx ebx 128 | cmp eax,ecx 129 | jne file_error 130 | clc 131 | ret 132 | lseek: 133 | push ebx 134 | movzx eax,al 135 | ccall fseek,ebx,edx,eax 136 | mov ebx,[esp] 137 | ccall ftell,ebx 138 | pop ebx 139 | ret 140 | 141 | display_string: 142 | lodsb 143 | or al,al 144 | jz string_displayed 145 | mov dl,al 146 | call display_character 147 | jmp display_string 148 | string_displayed: 149 | ret 150 | display_character: 151 | mov [character],dl 152 | ccall libc_write,[con_handle],character,1 153 | ret 154 | display_number: 155 | push ebx 156 | mov ecx,1000000000 157 | xor edx,edx 158 | xor bl,bl 159 | display_loop: 160 | div ecx 161 | push edx 162 | cmp ecx,1 163 | je display_digit 164 | or bl,bl 165 | jnz display_digit 166 | or al,al 167 | jz digit_ok 168 | not bl 169 | display_digit: 170 | mov dl,al 171 | add dl,30h 172 | push ebx ecx 173 | call display_character 174 | pop ecx ebx 175 | digit_ok: 176 | mov eax,ecx 177 | xor edx,edx 178 | mov ecx,10 179 | div ecx 180 | mov ecx,eax 181 | pop eax 182 | or ecx,ecx 183 | jnz display_loop 184 | pop ebx 185 | ret 186 | 187 | display_user_messages: 188 | mov [displayed_count],0 189 | call show_display_buffer 190 | cmp [displayed_count],0 191 | je line_break_ok 192 | cmp [last_displayed],0Ah 193 | je line_break_ok 194 | mov dl,0Ah 195 | call display_character 196 | line_break_ok: 197 | ret 198 | display_block: 199 | jecxz block_displayed 200 | add [displayed_count],ecx 201 | mov al,[esi+ecx-1] 202 | mov [last_displayed],al 203 | display_characters: 204 | lodsb 205 | mov dl,al 206 | push ecx esi 207 | call display_character 208 | pop esi ecx 209 | loop display_characters 210 | block_displayed: 211 | ret 212 | 213 | fatal_error: 214 | mov [con_handle],2 215 | mov esi,error_prefix 216 | call display_string 217 | pop esi 218 | call display_string 219 | mov esi,error_suffix 220 | call display_string 221 | mov al,0FFh 222 | jmp exit_program 223 | assembler_error: 224 | mov [con_handle],2 225 | call display_user_messages 226 | mov ebx,[current_line] 227 | test ebx,ebx 228 | jz display_error_message 229 | push dword 0 230 | get_error_lines: 231 | mov eax,[ebx] 232 | cmp byte [eax],0 233 | je get_next_error_line 234 | push ebx 235 | test byte [ebx+7],80h 236 | jz display_error_line 237 | mov edx,ebx 238 | find_definition_origin: 239 | mov edx,[edx+12] 240 | test byte [edx+7],80h 241 | jnz find_definition_origin 242 | push edx 243 | get_next_error_line: 244 | mov ebx,[ebx+8] 245 | jmp get_error_lines 246 | display_error_line: 247 | mov esi,[ebx] 248 | call display_string 249 | mov esi,line_number_start 250 | call display_string 251 | mov eax,[ebx+4] 252 | and eax,7FFFFFFFh 253 | call display_number 254 | mov dl,']' 255 | call display_character 256 | pop esi 257 | cmp ebx,esi 258 | je line_number_ok 259 | mov dl,20h 260 | call display_character 261 | push esi 262 | mov esi,[esi] 263 | movzx ecx,byte [esi] 264 | inc esi 265 | call display_block 266 | mov esi,line_number_start 267 | call display_string 268 | pop esi 269 | mov eax,[esi+4] 270 | and eax,7FFFFFFFh 271 | call display_number 272 | mov dl,']' 273 | call display_character 274 | line_number_ok: 275 | mov esi,line_data_start 276 | call display_string 277 | mov esi,ebx 278 | mov edx,[esi] 279 | call open 280 | mov al,2 281 | xor edx,edx 282 | call lseek 283 | mov edx,[esi+8] 284 | sub eax,edx 285 | jz line_data_displayed 286 | push eax 287 | xor al,al 288 | call lseek 289 | mov ecx,[esp] 290 | mov edx,[additional_memory] 291 | lea eax,[edx+ecx] 292 | cmp eax,[additional_memory_end] 293 | ja out_of_memory 294 | call read 295 | call close 296 | pop ecx 297 | mov esi,[additional_memory] 298 | get_line_data: 299 | mov al,[esi] 300 | cmp al,0Ah 301 | je display_line_data 302 | cmp al,0Dh 303 | je display_line_data 304 | cmp al,1Ah 305 | je display_line_data 306 | or al,al 307 | jz display_line_data 308 | inc esi 309 | loop get_line_data 310 | display_line_data: 311 | mov ecx,esi 312 | mov esi,[additional_memory] 313 | sub ecx,esi 314 | call display_block 315 | line_data_displayed: 316 | mov esi,lf 317 | call display_string 318 | pop ebx 319 | or ebx,ebx 320 | jnz display_error_line 321 | cmp [preprocessing_done],0 322 | je display_error_message 323 | mov esi,preprocessed_instruction_prefix 324 | call display_string 325 | mov esi,[current_line] 326 | add esi,16 327 | mov edi,[additional_memory] 328 | xor dl,dl 329 | convert_instruction: 330 | lodsb 331 | cmp al,1Ah 332 | je copy_symbol 333 | cmp al,22h 334 | je copy_symbol 335 | cmp al,3Bh 336 | je instruction_converted 337 | stosb 338 | or al,al 339 | jz instruction_converted 340 | xor dl,dl 341 | jmp convert_instruction 342 | copy_symbol: 343 | or dl,dl 344 | jz space_ok 345 | mov byte [edi],20h 346 | inc edi 347 | space_ok: 348 | cmp al,22h 349 | je quoted 350 | lodsb 351 | movzx ecx,al 352 | rep movsb 353 | or dl,-1 354 | jmp convert_instruction 355 | quoted: 356 | mov al,27h 357 | stosb 358 | lodsd 359 | mov ecx,eax 360 | jecxz quoted_copied 361 | copy_quoted: 362 | lodsb 363 | stosb 364 | cmp al,27h 365 | jne quote_ok 366 | stosb 367 | quote_ok: 368 | loop copy_quoted 369 | quoted_copied: 370 | mov al,27h 371 | stosb 372 | or dl,-1 373 | jmp convert_instruction 374 | instruction_converted: 375 | xor al,al 376 | stosb 377 | mov esi,[additional_memory] 378 | call display_string 379 | mov esi,lf 380 | call display_string 381 | display_error_message: 382 | mov esi,error_prefix 383 | call display_string 384 | pop esi 385 | call display_string 386 | mov esi,error_suffix 387 | call display_string 388 | mov al,2 389 | jmp exit_program 390 | 391 | make_timestamp: 392 | ccall time,timestamp 393 | mov eax,dword [timestamp] 394 | mov edx,dword [timestamp+4] 395 | ret 396 | 397 | open_mode db 'r',0 398 | create_mode db 'w',0 399 | 400 | error_prefix db 'error: ',0 401 | error_suffix db '.' 402 | lf db 0xA,0 403 | line_number_start db ' [',0 404 | line_data_start db ':',0xA,0 405 | preprocessed_instruction_prefix db 'processed: ',0 406 | -------------------------------------------------------------------------------- /objconv_src/source/objconv.vcproj: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 15 | 16 | 17 | 18 | 19 | 27 | 30 | 33 | 36 | 39 | 42 | 57 | 60 | 63 | 66 | 77 | 80 | 83 | 86 | 89 | 92 | 95 | 98 | 99 | 107 | 110 | 113 | 116 | 119 | 122 | 138 | 141 | 144 | 147 | 159 | 162 | 165 | 168 | 171 | 174 | 177 | 180 | 181 | 182 | 183 | 184 | 185 | 190 | 193 | 194 | 197 | 198 | 201 | 202 | 205 | 206 | 209 | 210 | 213 | 214 | 217 | 218 | 221 | 222 | 225 | 226 | 229 | 230 | 233 | 234 | 237 | 238 | 241 | 242 | 245 | 246 | 249 | 250 | 253 | 254 | 257 | 258 | 261 | 262 | 265 | 266 | 269 | 270 | 273 | 274 | 277 | 278 | 281 | 282 | 285 | 286 | 289 | 290 | 293 | 294 | 297 | 300 | 304 | 305 | 308 | 312 | 313 | 314 | 315 | 320 | 323 | 324 | 327 | 328 | 331 | 332 | 335 | 336 | 339 | 340 | 343 | 344 | 347 | 348 | 351 | 352 | 355 | 356 | 359 | 360 | 363 | 364 | 367 | 368 | 369 | 374 | 375 | 376 | 377 | 378 | 379 | -------------------------------------------------------------------------------- /fasm_src/source/DOS/fasm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for DOS 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | format MZ 7 | heap 0 8 | stack 8000h 9 | entry main:start 10 | 11 | include 'modes.inc' 12 | 13 | segment main use16 14 | 15 | start: 16 | 17 | mov ax,ds 18 | mov dx,[2Ch] 19 | push cs cs 20 | pop ds es 21 | mov [psp_segment],ax 22 | mov [environment_segment],dx 23 | 24 | mov dx,_logo 25 | mov ah,9 26 | int 21h 27 | 28 | cld 29 | 30 | call go32 31 | use32 32 | 33 | call get_params 34 | jc information 35 | 36 | call init_memory 37 | 38 | mov esi,_memory_prefix 39 | call display_string 40 | mov eax,[memory_end] 41 | sub eax,[memory_start] 42 | add eax,[additional_memory_end] 43 | sub eax,[additional_memory] 44 | shr eax,10 45 | call display_number 46 | mov esi,_memory_suffix 47 | call display_string 48 | 49 | xor ah,ah 50 | int 1Ah 51 | mov ax,cx 52 | shl eax,16 53 | mov ax,dx 54 | mov [start_time],eax 55 | 56 | cmp [mode],dpmi 57 | je compile 58 | jmp main+(first_segment shr 4):first_gate-first_segment 59 | 60 | compile: 61 | and [preprocessing_done],0 62 | call preprocessor 63 | or [preprocessing_done],-1 64 | call parser 65 | call assembler 66 | call formatter 67 | 68 | finish: 69 | call display_user_messages 70 | movzx eax,[current_pass] 71 | inc eax 72 | call display_number 73 | mov esi,_passes_suffix 74 | call display_string 75 | xor ah,ah 76 | int 1Ah 77 | mov ax,cx 78 | shl eax,16 79 | mov ax,dx 80 | sub eax,[start_time] 81 | mov ebx,100 82 | mul ebx 83 | mov ebx,182 84 | div ebx 85 | or eax,eax 86 | jz display_bytes_count 87 | xor edx,edx 88 | mov ebx,10 89 | div ebx 90 | push edx 91 | call display_number 92 | mov ah,2 93 | mov dl,'.' 94 | int 21h 95 | pop eax 96 | call display_number 97 | mov esi,_seconds_suffix 98 | call display_string 99 | display_bytes_count: 100 | mov eax,[written_size] 101 | call display_number 102 | mov esi,_bytes_suffix 103 | call display_string 104 | xor al,al 105 | jmp exit_program 106 | 107 | information: 108 | mov esi,_usage 109 | call display_string 110 | mov al,1 111 | jmp exit_program 112 | 113 | get_params: 114 | mov [input_file],0 115 | mov [output_file],0 116 | mov [symbols_file],0 117 | mov [memory_setting],0 118 | mov [passes_limit],100 119 | mov [definitions_pointer],predefinitions 120 | push ds 121 | mov ds,[psp_segment] 122 | mov esi,81h 123 | mov edi,params 124 | find_param: 125 | lodsb 126 | cmp al,20h 127 | je find_param 128 | cmp al,'-' 129 | je option_param 130 | cmp al,0Dh 131 | je all_params 132 | or al,al 133 | jz all_params 134 | cmp [es:input_file],0 135 | jne get_output_file 136 | mov [es:input_file],edi 137 | jmp process_param 138 | get_output_file: 139 | cmp [es:output_file],0 140 | jne bad_params 141 | mov [es:output_file],edi 142 | process_param: 143 | cmp al,22h 144 | je string_param 145 | copy_param: 146 | stosb 147 | lodsb 148 | cmp al,20h 149 | je param_end 150 | cmp al,0Dh 151 | je param_end 152 | or al,al 153 | jz param_end 154 | jmp copy_param 155 | string_param: 156 | lodsb 157 | cmp al,22h 158 | je string_param_end 159 | cmp al,0Dh 160 | je param_end 161 | or al,al 162 | jz param_end 163 | stosb 164 | jmp string_param 165 | option_param: 166 | lodsb 167 | cmp al,'m' 168 | je memory_option 169 | cmp al,'M' 170 | je memory_option 171 | cmp al,'p' 172 | je passes_option 173 | cmp al,'P' 174 | je passes_option 175 | cmp al,'d' 176 | je definition_option 177 | cmp al,'D' 178 | je definition_option 179 | cmp al,'s' 180 | je symbols_option 181 | cmp al,'S' 182 | je symbols_option 183 | invalid_option: 184 | pop ds 185 | stc 186 | ret 187 | get_option_value: 188 | xor eax,eax 189 | mov edx,eax 190 | get_option_digit: 191 | lodsb 192 | cmp al,20h 193 | je option_value_ok 194 | cmp al,0Dh 195 | je option_value_ok 196 | or al,al 197 | jz option_value_ok 198 | sub al,30h 199 | jc bad_params_value 200 | cmp al,9 201 | ja bad_params_value 202 | imul edx,10 203 | jo bad_params_value 204 | add edx,eax 205 | jc bad_params_value 206 | jmp get_option_digit 207 | option_value_ok: 208 | dec esi 209 | clc 210 | ret 211 | bad_params_value: 212 | stc 213 | ret 214 | memory_option: 215 | lodsb 216 | cmp al,20h 217 | je memory_option 218 | cmp al,0Dh 219 | je invalid_option 220 | or al,al 221 | jz invalid_option 222 | dec esi 223 | call get_option_value 224 | jc invalid_option 225 | or edx,edx 226 | jz invalid_option 227 | cmp edx,1 shl (32-10) 228 | jae invalid_option 229 | mov [es:memory_setting],edx 230 | jmp find_param 231 | passes_option: 232 | lodsb 233 | cmp al,20h 234 | je passes_option 235 | cmp al,0Dh 236 | je invalid_option 237 | or al,al 238 | jz invalid_option 239 | dec esi 240 | call get_option_value 241 | jc bad_params 242 | or edx,edx 243 | jz invalid_option 244 | cmp edx,10000h 245 | ja invalid_option 246 | mov [es:passes_limit],dx 247 | jmp find_param 248 | definition_option: 249 | lodsb 250 | cmp al,20h 251 | je definition_option 252 | cmp al,0Dh 253 | je bad_params 254 | or al,al 255 | jz bad_params 256 | dec esi 257 | push edi 258 | mov edi,[es:definitions_pointer] 259 | call convert_definition_option 260 | mov [es:definitions_pointer],edi 261 | pop edi 262 | jc invalid_option 263 | jmp find_param 264 | symbols_option: 265 | mov [es:symbols_file],edi 266 | find_symbols_file_name: 267 | lodsb 268 | cmp al,20h 269 | jne process_param 270 | jmp find_symbols_file_name 271 | param_end: 272 | dec esi 273 | string_param_end: 274 | xor al,al 275 | stosb 276 | jmp find_param 277 | all_params: 278 | xor al,al 279 | stosb 280 | pop ds 281 | cmp [input_file],0 282 | je no_input_file 283 | mov eax,[definitions_pointer] 284 | mov byte [eax],0 285 | mov [initial_definitions],predefinitions 286 | clc 287 | ret 288 | bad_params: 289 | pop ds 290 | no_input_file: 291 | stc 292 | ret 293 | convert_definition_option: 294 | mov ecx,edi 295 | xor al,al 296 | stosb 297 | copy_definition_name: 298 | lodsb 299 | cmp al,'=' 300 | je copy_definition_value 301 | cmp al,20h 302 | je bad_definition_option 303 | cmp al,0Dh 304 | je bad_definition_option 305 | or al,al 306 | jz bad_definition_option 307 | stosb 308 | inc byte [es:ecx] 309 | jnz copy_definition_name 310 | bad_definition_option: 311 | stc 312 | ret 313 | copy_definition_value: 314 | lodsb 315 | cmp al,20h 316 | je definition_value_end 317 | cmp al,0Dh 318 | je definition_value_end 319 | or al,al 320 | jz definition_value_end 321 | cmp al,'\' 322 | jne definition_value_character 323 | cmp byte [esi],20h 324 | jne definition_value_character 325 | lodsb 326 | definition_value_character: 327 | stosb 328 | jmp copy_definition_value 329 | definition_value_end: 330 | dec esi 331 | xor al,al 332 | stosb 333 | clc 334 | ret 335 | 336 | include '..\version.inc' 337 | 338 | _logo db 'flat assembler version ',VERSION_STRING,24h 339 | _copyright db 'Copyright (c) 1999-2016, Tomasz Grysztar',0Dh,0Ah,0 340 | 341 | _usage db 0Dh,0Ah 342 | db 'usage: fasm [output]',0Dh,0Ah 343 | db 'optional settings:',0Dh,0Ah 344 | db ' -m set the limit in kilobytes for the available memory',0Dh,0Ah 345 | db ' -p set the maximum allowed number of passes',0Dh,0Ah 346 | db ' -d = define symbolic variable',0Dh,0Ah 347 | db ' -s dump symbolic information for debugging',0Dh,0Ah 348 | db 0 349 | _memory_prefix db ' (',0 350 | _memory_suffix db ' kilobytes memory)',0Dh,0Ah,0 351 | _passes_suffix db ' passes, ',0 352 | _seconds_suffix db ' seconds, ',0 353 | _bytes_suffix db ' bytes.',0Dh,0Ah,0 354 | 355 | error_prefix db 'error: ',0 356 | error_suffix db '.' 357 | cr_lf db 0Dh,0Ah,0 358 | line_number_start db ' [',0 359 | line_data_start db ':',0Dh,0Ah,0 360 | preprocessed_instruction_prefix db 'processed: ',0 361 | 362 | include 'dpmi.inc' 363 | 364 | align 16 365 | first_segment: 366 | 367 | include '..\preproce.inc' 368 | include '..\parser.inc' 369 | include '..\exprpars.inc' 370 | 371 | align 16 372 | second_segment: 373 | 374 | include '..\exprcalc.inc' 375 | include '..\errors.inc' 376 | include '..\symbdump.inc' 377 | 378 | include 'system.inc' 379 | 380 | first_gate: 381 | and [preprocessing_done],0 382 | call preprocessor 383 | or [preprocessing_done],-1 384 | call parser 385 | jmp main+(second_segment shr 4):second_gate-second_segment 386 | first_segment_top = $ - first_segment 387 | 388 | include '..\assemble.inc' 389 | include '..\formats.inc' 390 | include '..\x86_64.inc' 391 | include '..\avx.inc' 392 | 393 | second_gate: 394 | call assembler 395 | call formatter 396 | jmp main:finish 397 | 398 | second_segment_top = $ - second_segment 399 | 400 | if first_segment_top>=10000h | second_segment_top>=10000h 401 | if UNREAL_ENABLED>0 402 | UNREAL_ENABLED = -1 403 | else 404 | UNREAL_ENABLED = 0 405 | end if 406 | else 407 | if UNREAL_ENABLED<0 408 | UNREAL_ENABLED = -1 409 | else 410 | UNREAL_ENABLED = 1 411 | end if 412 | end if 413 | 414 | include '..\tables.inc' 415 | include '..\messages.inc' 416 | 417 | align 4 418 | 419 | include '..\variable.inc' 420 | 421 | memory_setting dd ? 422 | start_time dd ? 423 | definitions_pointer dd ? 424 | params rb 100h 425 | predefinitions rb 100h 426 | 427 | mode dw ? 428 | real_mode_segment dw ? 429 | displayed_count dd ? 430 | last_displayed rb 2 431 | preprocessing_done db ? 432 | 433 | segment buffer 434 | 435 | rb 1000h 436 | -------------------------------------------------------------------------------- /fasm_src/source/Linux/system.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Linux 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | O_ACCMODE = 0003o 7 | O_RDONLY = 0000o 8 | O_WRONLY = 0001o 9 | O_RDWR = 0002o 10 | O_CREAT = 0100o 11 | O_EXCL = 0200o 12 | O_NOCTTY = 0400o 13 | O_TRUNC = 1000o 14 | O_APPEND = 2000o 15 | O_NONBLOCK = 4000o 16 | 17 | S_ISUID = 4000o 18 | S_ISGID = 2000o 19 | S_ISVTX = 1000o 20 | S_IRUSR = 0400o 21 | S_IWUSR = 0200o 22 | S_IXUSR = 0100o 23 | S_IRGRP = 0040o 24 | S_IWGRP = 0020o 25 | S_IXGRP = 0010o 26 | S_IROTH = 0004o 27 | S_IWOTH = 0002o 28 | S_IXOTH = 0001o 29 | 30 | init_memory: 31 | mov eax,esp 32 | and eax,not 0FFFh 33 | add eax,1000h-10000h 34 | mov [stack_limit],eax 35 | xor ebx,ebx 36 | mov eax,45 37 | int 0x80 38 | mov [additional_memory],eax 39 | mov ecx,[memory_setting] 40 | shl ecx,10 41 | jnz allocate_memory 42 | mov ecx,1000000h 43 | allocate_memory: 44 | mov ebx,[additional_memory] 45 | add ebx,ecx 46 | mov eax,45 47 | int 0x80 48 | mov [memory_end],eax 49 | sub eax,[additional_memory] 50 | shr eax,2 51 | add eax,[additional_memory] 52 | mov [additional_memory_end],eax 53 | mov [memory_start],eax 54 | ret 55 | 56 | exit_program: 57 | movzx ebx,al 58 | mov eax,1 59 | int 0x80 60 | 61 | get_environment_variable: 62 | mov ebx,esi 63 | mov esi,[environment] 64 | compare_variable_names: 65 | mov edx,ebx 66 | compare_character: 67 | lodsb 68 | mov ah,[edx] 69 | inc edx 70 | cmp al,'=' 71 | je end_of_variable_name 72 | or ah,ah 73 | jz next_variable 74 | sub ah,al 75 | jz compare_character 76 | cmp ah,20h 77 | jne next_variable 78 | cmp al,41h 79 | jb next_variable 80 | cmp al,5Ah 81 | jna compare_character 82 | next_variable: 83 | lodsb 84 | or al,al 85 | jnz next_variable 86 | cmp byte [esi],0 87 | jne compare_variable_names 88 | ret 89 | end_of_variable_name: 90 | or ah,ah 91 | jnz next_variable 92 | copy_variable_value: 93 | lodsb 94 | cmp edi,[memory_end] 95 | jae out_of_memory 96 | stosb 97 | or al,al 98 | jnz copy_variable_value 99 | dec edi 100 | ret 101 | 102 | open: 103 | push esi edi ebp 104 | call adapt_path 105 | mov eax,5 106 | mov ebx,buffer 107 | mov ecx,O_RDONLY 108 | xor edx,edx 109 | int 0x80 110 | pop ebp edi esi 111 | test eax,eax 112 | js file_error 113 | mov ebx,eax 114 | clc 115 | ret 116 | adapt_path: 117 | mov esi,edx 118 | mov edi,buffer 119 | copy_path: 120 | lods byte [esi] 121 | cmp al,'\' 122 | jne path_char_ok 123 | mov al,'/' 124 | path_char_ok: 125 | stos byte [edi] 126 | or al,al 127 | jnz copy_path 128 | cmp edi,buffer+1000h 129 | ja out_of_memory 130 | ret 131 | create: 132 | push esi edi ebp edx 133 | call adapt_path 134 | mov ebx,buffer 135 | mov ecx,O_CREAT+O_TRUNC+O_WRONLY 136 | mov edx,S_IRUSR+S_IWUSR+S_IRGRP+S_IROTH 137 | pop eax 138 | cmp eax,[output_file] 139 | jne do_create 140 | cmp [output_format],5 141 | jne do_create 142 | bt [format_flags],0 143 | jnc do_create 144 | or edx,S_IXUSR+S_IXGRP+S_IXOTH 145 | do_create: 146 | mov eax,5 147 | int 0x80 148 | pop ebp edi esi 149 | test eax,eax 150 | js file_error 151 | mov ebx,eax 152 | clc 153 | ret 154 | close: 155 | mov eax,6 156 | int 0x80 157 | ret 158 | read: 159 | push ecx edx esi edi ebp 160 | mov eax,3 161 | xchg ecx,edx 162 | int 0x80 163 | pop ebp edi esi edx ecx 164 | test eax,eax 165 | js file_error 166 | cmp eax,ecx 167 | jne file_error 168 | clc 169 | ret 170 | file_error: 171 | stc 172 | ret 173 | write: 174 | push edx esi edi ebp 175 | mov eax,4 176 | xchg ecx,edx 177 | int 0x80 178 | pop ebp edi esi edx 179 | test eax,eax 180 | js file_error 181 | clc 182 | ret 183 | lseek: 184 | mov ecx,edx 185 | xor edx,edx 186 | mov dl,al 187 | mov eax,19 188 | int 0x80 189 | ret 190 | 191 | display_string: 192 | push ebx 193 | mov edi,esi 194 | mov edx,esi 195 | or ecx,-1 196 | xor al,al 197 | repne scasb 198 | neg ecx 199 | sub ecx,2 200 | mov eax,4 201 | mov ebx,[con_handle] 202 | xchg ecx,edx 203 | int 0x80 204 | pop ebx 205 | ret 206 | display_character: 207 | push ebx 208 | mov [character],dl 209 | mov eax,4 210 | mov ebx,[con_handle] 211 | mov ecx,character 212 | mov edx,1 213 | int 0x80 214 | pop ebx 215 | ret 216 | display_number: 217 | push ebx 218 | mov ecx,1000000000 219 | xor edx,edx 220 | xor bl,bl 221 | display_loop: 222 | div ecx 223 | push edx 224 | cmp ecx,1 225 | je display_digit 226 | or bl,bl 227 | jnz display_digit 228 | or al,al 229 | jz digit_ok 230 | not bl 231 | display_digit: 232 | mov dl,al 233 | add dl,30h 234 | push ebx ecx 235 | call display_character 236 | pop ecx ebx 237 | digit_ok: 238 | mov eax,ecx 239 | xor edx,edx 240 | mov ecx,10 241 | div ecx 242 | mov ecx,eax 243 | pop eax 244 | or ecx,ecx 245 | jnz display_loop 246 | pop ebx 247 | ret 248 | 249 | display_user_messages: 250 | mov [displayed_count],0 251 | call show_display_buffer 252 | cmp [displayed_count],0 253 | je line_break_ok 254 | cmp [last_displayed],0Ah 255 | je line_break_ok 256 | mov dl,0Ah 257 | call display_character 258 | line_break_ok: 259 | ret 260 | display_block: 261 | jecxz block_displayed 262 | add [displayed_count],ecx 263 | mov al,[esi+ecx-1] 264 | mov [last_displayed],al 265 | push ebx 266 | mov eax,4 267 | mov ebx,[con_handle] 268 | mov edx,ecx 269 | mov ecx,esi 270 | int 0x80 271 | pop ebx 272 | block_displayed: 273 | ret 274 | 275 | fatal_error: 276 | mov [con_handle],2 277 | mov esi,error_prefix 278 | call display_string 279 | pop esi 280 | call display_string 281 | mov esi,error_suffix 282 | call display_string 283 | mov al,0FFh 284 | jmp exit_program 285 | assembler_error: 286 | mov [con_handle],2 287 | call display_user_messages 288 | mov ebx,[current_line] 289 | test ebx,ebx 290 | jz display_error_message 291 | push dword 0 292 | get_error_lines: 293 | mov eax,[ebx] 294 | cmp byte [eax],0 295 | je get_next_error_line 296 | push ebx 297 | test byte [ebx+7],80h 298 | jz display_error_line 299 | mov edx,ebx 300 | find_definition_origin: 301 | mov edx,[edx+12] 302 | test byte [edx+7],80h 303 | jnz find_definition_origin 304 | push edx 305 | get_next_error_line: 306 | mov ebx,[ebx+8] 307 | jmp get_error_lines 308 | display_error_line: 309 | mov esi,[ebx] 310 | call display_string 311 | mov esi,line_number_start 312 | call display_string 313 | mov eax,[ebx+4] 314 | and eax,7FFFFFFFh 315 | call display_number 316 | mov dl,']' 317 | call display_character 318 | pop esi 319 | cmp ebx,esi 320 | je line_number_ok 321 | mov dl,20h 322 | call display_character 323 | push esi 324 | mov esi,[esi] 325 | movzx ecx,byte [esi] 326 | inc esi 327 | call display_block 328 | mov esi,line_number_start 329 | call display_string 330 | pop esi 331 | mov eax,[esi+4] 332 | and eax,7FFFFFFFh 333 | call display_number 334 | mov dl,']' 335 | call display_character 336 | line_number_ok: 337 | mov esi,line_data_start 338 | call display_string 339 | mov esi,ebx 340 | mov edx,[esi] 341 | call open 342 | mov al,2 343 | xor edx,edx 344 | call lseek 345 | mov edx,[esi+8] 346 | sub eax,edx 347 | jz line_data_displayed 348 | push eax 349 | xor al,al 350 | call lseek 351 | mov ecx,[esp] 352 | mov edx,[additional_memory] 353 | lea eax,[edx+ecx] 354 | cmp eax,[additional_memory_end] 355 | ja out_of_memory 356 | call read 357 | call close 358 | pop ecx 359 | mov esi,[additional_memory] 360 | get_line_data: 361 | mov al,[esi] 362 | cmp al,0Ah 363 | je display_line_data 364 | cmp al,0Dh 365 | je display_line_data 366 | cmp al,1Ah 367 | je display_line_data 368 | or al,al 369 | jz display_line_data 370 | inc esi 371 | loop get_line_data 372 | display_line_data: 373 | mov ecx,esi 374 | mov esi,[additional_memory] 375 | sub ecx,esi 376 | call display_block 377 | line_data_displayed: 378 | mov esi,lf 379 | call display_string 380 | pop ebx 381 | or ebx,ebx 382 | jnz display_error_line 383 | cmp [preprocessing_done],0 384 | je display_error_message 385 | mov esi,preprocessed_instruction_prefix 386 | call display_string 387 | mov esi,[current_line] 388 | add esi,16 389 | mov edi,[additional_memory] 390 | xor dl,dl 391 | convert_instruction: 392 | lodsb 393 | cmp al,1Ah 394 | je copy_symbol 395 | cmp al,22h 396 | je copy_symbol 397 | cmp al,3Bh 398 | je instruction_converted 399 | stosb 400 | or al,al 401 | jz instruction_converted 402 | xor dl,dl 403 | jmp convert_instruction 404 | copy_symbol: 405 | or dl,dl 406 | jz space_ok 407 | mov byte [edi],20h 408 | inc edi 409 | space_ok: 410 | cmp al,22h 411 | je quoted 412 | lodsb 413 | movzx ecx,al 414 | rep movsb 415 | or dl,-1 416 | jmp convert_instruction 417 | quoted: 418 | mov al,27h 419 | stosb 420 | lodsd 421 | mov ecx,eax 422 | jecxz quoted_copied 423 | copy_quoted: 424 | lodsb 425 | stosb 426 | cmp al,27h 427 | jne quote_ok 428 | stosb 429 | quote_ok: 430 | loop copy_quoted 431 | quoted_copied: 432 | mov al,27h 433 | stosb 434 | or dl,-1 435 | jmp convert_instruction 436 | instruction_converted: 437 | xor al,al 438 | stosb 439 | mov esi,[additional_memory] 440 | call display_string 441 | mov esi,lf 442 | call display_string 443 | display_error_message: 444 | mov esi,error_prefix 445 | call display_string 446 | pop esi 447 | call display_string 448 | mov esi,error_suffix 449 | call display_string 450 | mov al,2 451 | jmp exit_program 452 | 453 | make_timestamp: 454 | mov eax,13 455 | mov ebx,timestamp 456 | int 0x80 457 | mov eax,dword [timestamp] 458 | mov edx,dword [timestamp+4] 459 | ret 460 | 461 | error_prefix db 'error: ',0 462 | error_suffix db '.' 463 | lf db 0xA,0 464 | line_number_start db ' [',0 465 | line_data_start db ':',0xA,0 466 | preprocessed_instruction_prefix db 'processed: ',0 467 | -------------------------------------------------------------------------------- /fasm_src/tools/symbols.inc: -------------------------------------------------------------------------------- 1 | 2 | symbols: 3 | mov edx,[input_file] 4 | call open 5 | jc input_not_found 6 | mov al,2 7 | xor edx,edx 8 | call lseek 9 | cmp eax,30h 10 | jb invalid_input 11 | push eax 12 | call alloc 13 | jc not_enough_memory 14 | push eax 15 | xor al,al 16 | xor edx,edx 17 | call lseek 18 | mov ecx,[esp+4] 19 | mov edx,[esp] 20 | call read 21 | jc reading_error 22 | pop eax ecx 23 | cmp dword [eax],1A736166h 24 | jne invalid_input 25 | mov [input],eax 26 | add [eax+16],eax 27 | add [eax+24],eax 28 | add [eax+32],eax 29 | add [eax+48],eax 30 | mov edx,[eax+16] 31 | add [eax+8],edx 32 | 33 | mov ebx,eax 34 | mov eax,[ebx+20] 35 | add eax,[ebx+36] 36 | cmp eax,1000h 37 | ja allocate_output_buffer 38 | mov eax,1000h 39 | allocate_output_buffer: 40 | call alloc 41 | jc not_enough_memory 42 | mov [output_buffer],eax 43 | 44 | mov edx,[output_file] 45 | call create 46 | jc writing_error 47 | mov [output_handle],ebx 48 | 49 | mov ebx,[input] 50 | mov edx,[ebx+24] 51 | mov ebp,[ebx+28] 52 | add ebp,edx 53 | dump_symbols: 54 | cmp edx,ebp 55 | je dump_done 56 | test byte [edx+8],1 57 | jz next_symbol 58 | test byte [edx+9],4 59 | jnz next_symbol 60 | mov edi,[output_buffer] 61 | mov esi,[edx+24] 62 | test esi,esi 63 | jz anonymous_symbol 64 | mov ebx,[input] 65 | btr esi,31 66 | jc symbol_name_in_strings_table 67 | add esi,[ebx+32] 68 | lodsb 69 | movzx ecx,al 70 | rep movsb 71 | jmp symbol_name_ok 72 | symbol_name_in_strings_table: 73 | add esi,[ebx+16] 74 | call write_string 75 | jmp symbol_name_ok 76 | anonymous_symbol: 77 | mov al,'@' 78 | stosb 79 | stosb 80 | symbol_name_ok: 81 | test byte [edx+9],2 82 | jnz negative_value 83 | mov eax,': 0x' 84 | stosd 85 | mov eax,[edx+4] 86 | call write_hex_dword 87 | mov eax,[edx] 88 | call write_hex_dword 89 | jmp write_address_registers 90 | negative_value: 91 | mov eax,': -0' 92 | stosd 93 | mov al,'x' 94 | stosb 95 | mov ecx,[edx] 96 | mov eax,[edx+4] 97 | not ecx 98 | not eax 99 | add ecx,1 100 | adc eax,0 101 | push ecx 102 | or ecx,eax 103 | jnz negative_value_ok 104 | mov byte [edi],'1' 105 | inc edi 106 | negative_value_ok: 107 | call write_hex_dword 108 | pop eax 109 | call write_hex_dword 110 | write_address_registers: 111 | mov bl,[edx+12] 112 | mov bh,[edx+14] 113 | call write_address_register 114 | mov bl,[edx+13] 115 | mov bh,[edx+15] 116 | call write_address_register 117 | mov bl,[edx+11] 118 | cmp bl,0 119 | je symbol_type_ok 120 | jl negated_symbol 121 | mov ax,', ' 122 | stosw 123 | jmp write_symbol_type 124 | negated_symbol: 125 | mov ax,', ' 126 | stosw 127 | mov esi,_negated 128 | call write_string 129 | neg bl 130 | write_symbol_type: 131 | cmp bl,1 132 | je segment_type 133 | cmp bl,5 134 | je rva_type 135 | cmp bl,6 136 | je plt_type 137 | test byte [edx+20+3],80h 138 | jnz external 139 | mov esi,_relocatable 140 | call write_string 141 | cmp dword [edx+20],0 142 | je symbol_type_ok 143 | mov esi,_in_section 144 | call write_string 145 | jmp write_symbol_base 146 | simple_relocatable: 147 | mov esi,_relocatable 148 | call write_string 149 | jmp symbol_type_ok 150 | external: 151 | mov esi,_relative_to_external 152 | call write_string 153 | jmp write_symbol_base 154 | segment_type: 155 | mov esi,_relocatable_segment 156 | call write_string 157 | jmp symbol_type_ok 158 | rva_type: 159 | mov esi,_rva 160 | call write_string 161 | jmp write_symbol_base 162 | plt_type: 163 | mov esi,_plt 164 | call write_string 165 | write_symbol_base: 166 | mov esi,[edx+20] 167 | btr esi,31 168 | jc write_external_name 169 | dec esi 170 | shl esi,2 171 | mov ebx,[input] 172 | add esi,[ebx+48] 173 | mov esi,[esi] 174 | add esi,[ebx+16] 175 | call write_string 176 | mov al,'(' 177 | stosb 178 | mov eax,[edx+20] 179 | call write_dec_number 180 | mov al,')' 181 | stosb 182 | jmp symbol_type_ok 183 | write_external_name: 184 | mov ebx,[input] 185 | add esi,[ebx+16] 186 | call write_string 187 | jmp symbol_type_ok 188 | symbol_type_ok: 189 | mov esi,_defined 190 | call write_string 191 | mov ebx,[edx+28] 192 | mov eax,[input] 193 | add ebx,[eax+32] 194 | call write_line_identifier 195 | mov ax,0A0Dh 196 | stosw 197 | push edx 198 | mov ebx,[output_handle] 199 | mov ecx,edi 200 | mov edx,[output_buffer] 201 | sub ecx,edx 202 | call write 203 | pop edx 204 | next_symbol: 205 | add edx,32 206 | jmp dump_symbols 207 | dump_done: 208 | mov ebx,[output_handle] 209 | call close 210 | ret 211 | 212 | write_string: 213 | lodsb 214 | test al,al 215 | jz string_ok 216 | stosb 217 | jmp write_string 218 | string_ok: 219 | ret 220 | write_hex_dword: 221 | mov ebx,eax 222 | mov ecx,8 223 | write_hex_digits: 224 | xor al,al 225 | shld eax,ebx,4 226 | cmp al,10 227 | sbb al,69h 228 | das 229 | stosb 230 | shl ebx,4 231 | loop write_hex_digits 232 | ret 233 | write_dec_number: 234 | push ebx edx 235 | mov ecx,1000000000 236 | xor edx,edx 237 | xor bl,bl 238 | dec_number_loop: 239 | div ecx 240 | push edx 241 | cmp ecx,1 242 | je write_dec_digit 243 | or bl,bl 244 | jnz write_dec_digit 245 | or al,al 246 | jz dec_digit_ok 247 | not bl 248 | write_dec_digit: 249 | add al,30h 250 | stosb 251 | dec_digit_ok: 252 | mov eax,ecx 253 | xor edx,edx 254 | mov ecx,10 255 | div ecx 256 | mov ecx,eax 257 | pop eax 258 | or ecx,ecx 259 | jnz dec_number_loop 260 | pop edx ebx 261 | ret 262 | write_address_register: 263 | cmp bh,0 264 | je register_ok 265 | jl negative_register 266 | mov al,'+' 267 | jmp register_sign_ok 268 | negative_register: 269 | mov al,'-' 270 | register_sign_ok: 271 | stosb 272 | push esi 273 | mov esi,address_registers 274 | find_register: 275 | lodsb 276 | test al,al 277 | jz register_not_found 278 | cmp al,bl 279 | je register_found 280 | cmp bl,[esi] 281 | je register_found 282 | lodsb 283 | movzx eax,al 284 | add esi,eax 285 | jmp find_register 286 | register_not_found: 287 | mov al,bl 288 | shr al,5 289 | cmp al,0Ch shr 1 290 | je xmm_register 291 | cmp al,0Eh shr 1 292 | je ymm_register 293 | cmp al,6 shr 1 294 | je zmm_register 295 | register_found: 296 | lodsb 297 | movzx ecx,al 298 | rep movsb 299 | write_register_scale: 300 | pop esi 301 | cmp bh,1 302 | je register_ok 303 | mov al,'*' 304 | stosb 305 | movzx eax,bh 306 | call write_dec_number 307 | register_ok: 308 | ret 309 | zmm_register: 310 | mov al,'z' 311 | jmp vector_address_register 312 | ymm_register: 313 | mov al,'y' 314 | jmp vector_address_register 315 | xmm_register: 316 | mov al,'x' 317 | vector_address_register: 318 | stosb 319 | mov ax,'mm' 320 | stosw 321 | mov al,bl 322 | and eax,11111b 323 | call write_dec_number 324 | jmp write_register_scale 325 | 326 | write_line_identifier: 327 | test dword [ebx+4],80000000h 328 | jnz identify_macro_generated_line 329 | mov esi,[ebx] 330 | mov eax,[input] 331 | test esi,esi 332 | jz main_file 333 | add esi,[eax+32] 334 | jmp file_name_ok 335 | main_file: 336 | mov esi,[eax+8] 337 | file_name_ok: 338 | call write_string 339 | mov al,'[' 340 | stosb 341 | mov eax,[ebx+4] 342 | call write_dec_number 343 | mov al,']' 344 | stosb 345 | ret 346 | identify_macro_generated_line: 347 | mov al,'{' 348 | stosb 349 | mov esi,_generated_by 350 | call write_string 351 | push ebx 352 | mov ebx,[ebx+8] 353 | mov eax,[input] 354 | add ebx,[eax+32] 355 | call write_line_identifier 356 | pop ebx 357 | mov eax,[ebx+8] 358 | cmp eax,[ebx+12] 359 | je macro_generated_line_identifier_ok 360 | mov esi,_from 361 | call write_string 362 | push ebx 363 | mov ebx,[ebx+12] 364 | mov eax,[input] 365 | add ebx,[eax+32] 366 | call write_line_identifier 367 | pop ebx 368 | macro_generated_line_identifier_ok: 369 | mov al,'}' 370 | stosb 371 | ret 372 | 373 | not_enough_memory: 374 | call error 375 | db 'not enough memory to load the required data',0 376 | input_not_found: 377 | call error 378 | db 'the input file was not found',0 379 | code_not_found: 380 | call error 381 | db 'the assembled file was not found',0 382 | source_not_found: 383 | call error 384 | db 'could not find some of the source files',0 385 | reading_error: 386 | call error 387 | db 'some error occured while trying to read file',0 388 | writing_error: 389 | call error 390 | db 'some error occured while trying to write file',0 391 | invalid_input: 392 | call error 393 | db 'input file is not a recognized assembly information format',0 394 | 395 | address_registers db 23h,2,'bx' 396 | db 25h,2,'bp' 397 | db 26h,2,'si' 398 | db 27h,2,'di' 399 | db 40h,3,'eax' 400 | db 41h,3,'ecx' 401 | db 42h,3,'edx' 402 | db 43h,3,'ebx' 403 | db 44h,3,'esp' 404 | db 45h,3,'ebp' 405 | db 46h,3,'esi' 406 | db 47h,3,'edi' 407 | db 48h,3,'r8d' 408 | db 49h,3,'r9d' 409 | db 4Ah,4,'r10d' 410 | db 4Bh,4,'r11d' 411 | db 4Ch,4,'r12d' 412 | db 4Dh,4,'r13d' 413 | db 4Eh,4,'r14d' 414 | db 4Fh,4,'r15d' 415 | db 80h,3,'rax' 416 | db 81h,3,'rcx' 417 | db 82h,3,'rdx' 418 | db 83h,3,'rbx' 419 | db 84h,3,'rsp' 420 | db 85h,3,'rbp' 421 | db 86h,3,'rsi' 422 | db 87h,3,'rdi' 423 | db 88h,2,'r8' 424 | db 89h,2,'r9' 425 | db 8Ah,3,'r10' 426 | db 8Bh,3,'r11' 427 | db 8Ch,3,'r12' 428 | db 8Dh,3,'r13' 429 | db 8Eh,3,'r14' 430 | db 8Fh,3,'r15' 431 | db 94h,3,'eip' 432 | db 98h,3,'rip' 433 | db 0,1,'?' 434 | 435 | _negated db 'negated ',0 436 | _relocatable_segment db 'relocatable segment',0 437 | _relocatable db 'relocatable',0 438 | _in_section db ' in section ',0 439 | _relative_to_external db 'relative to external ',0 440 | _rva db 'relative to RVA or GOT-based offset of ',0 441 | _plt db 'relative to address of PLT entry for ',0 442 | _defined db ', defined in ',0 443 | _generated_by db 'line generated by ',0 444 | _from db ' from ',0 445 | -------------------------------------------------------------------------------- /fasm_src/source/Win32/fasm.asm: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Win32 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | format PE console 7 | 8 | section '.text' code readable executable 9 | 10 | start: 11 | 12 | mov [con_handle],STD_OUTPUT_HANDLE 13 | mov esi,_logo 14 | call display_string 15 | 16 | call get_params 17 | jc information 18 | 19 | call init_memory 20 | 21 | mov esi,_memory_prefix 22 | call display_string 23 | mov eax,[memory_end] 24 | sub eax,[memory_start] 25 | add eax,[additional_memory_end] 26 | sub eax,[additional_memory] 27 | shr eax,10 28 | call display_number 29 | mov esi,_memory_suffix 30 | call display_string 31 | 32 | call [GetTickCount] 33 | mov [start_time],eax 34 | 35 | and [preprocessing_done],0 36 | call preprocessor 37 | or [preprocessing_done],-1 38 | call parser 39 | call assembler 40 | call formatter 41 | 42 | call display_user_messages 43 | movzx eax,[current_pass] 44 | inc eax 45 | call display_number 46 | mov esi,_passes_suffix 47 | call display_string 48 | call [GetTickCount] 49 | sub eax,[start_time] 50 | xor edx,edx 51 | mov ebx,100 52 | div ebx 53 | or eax,eax 54 | jz display_bytes_count 55 | xor edx,edx 56 | mov ebx,10 57 | div ebx 58 | push edx 59 | call display_number 60 | mov dl,'.' 61 | call display_character 62 | pop eax 63 | call display_number 64 | mov esi,_seconds_suffix 65 | call display_string 66 | display_bytes_count: 67 | mov eax,[written_size] 68 | call display_number 69 | mov esi,_bytes_suffix 70 | call display_string 71 | xor al,al 72 | jmp exit_program 73 | 74 | information: 75 | mov esi,_usage 76 | call display_string 77 | mov al,1 78 | jmp exit_program 79 | 80 | get_params: 81 | mov [input_file],0 82 | mov [output_file],0 83 | mov [symbols_file],0 84 | mov [memory_setting],0 85 | mov [passes_limit],100 86 | call [GetCommandLine] 87 | mov [definitions_pointer],predefinitions 88 | mov esi,eax 89 | mov edi,params 90 | find_command_start: 91 | lodsb 92 | cmp al,20h 93 | je find_command_start 94 | cmp al,22h 95 | je skip_quoted_name 96 | skip_name: 97 | lodsb 98 | cmp al,20h 99 | je find_param 100 | or al,al 101 | jz all_params 102 | jmp skip_name 103 | skip_quoted_name: 104 | lodsb 105 | cmp al,22h 106 | je find_param 107 | or al,al 108 | jz all_params 109 | jmp skip_quoted_name 110 | find_param: 111 | lodsb 112 | cmp al,20h 113 | je find_param 114 | cmp al,'-' 115 | je option_param 116 | cmp al,0Dh 117 | je all_params 118 | or al,al 119 | jz all_params 120 | cmp [input_file],0 121 | jne get_output_file 122 | mov [input_file],edi 123 | jmp process_param 124 | get_output_file: 125 | cmp [output_file],0 126 | jne bad_params 127 | mov [output_file],edi 128 | process_param: 129 | cmp al,22h 130 | je string_param 131 | copy_param: 132 | stosb 133 | lodsb 134 | cmp al,20h 135 | je param_end 136 | cmp al,0Dh 137 | je param_end 138 | or al,al 139 | jz param_end 140 | jmp copy_param 141 | string_param: 142 | lodsb 143 | cmp al,22h 144 | je string_param_end 145 | cmp al,0Dh 146 | je param_end 147 | or al,al 148 | jz param_end 149 | stosb 150 | jmp string_param 151 | option_param: 152 | lodsb 153 | cmp al,'m' 154 | je memory_option 155 | cmp al,'M' 156 | je memory_option 157 | cmp al,'p' 158 | je passes_option 159 | cmp al,'P' 160 | je passes_option 161 | cmp al,'d' 162 | je definition_option 163 | cmp al,'D' 164 | je definition_option 165 | cmp al,'s' 166 | je symbols_option 167 | cmp al,'S' 168 | je symbols_option 169 | bad_params: 170 | stc 171 | ret 172 | get_option_value: 173 | xor eax,eax 174 | mov edx,eax 175 | get_option_digit: 176 | lodsb 177 | cmp al,20h 178 | je option_value_ok 179 | cmp al,0Dh 180 | je option_value_ok 181 | or al,al 182 | jz option_value_ok 183 | sub al,30h 184 | jc invalid_option_value 185 | cmp al,9 186 | ja invalid_option_value 187 | imul edx,10 188 | jo invalid_option_value 189 | add edx,eax 190 | jc invalid_option_value 191 | jmp get_option_digit 192 | option_value_ok: 193 | dec esi 194 | clc 195 | ret 196 | invalid_option_value: 197 | stc 198 | ret 199 | memory_option: 200 | lodsb 201 | cmp al,20h 202 | je memory_option 203 | cmp al,0Dh 204 | je bad_params 205 | or al,al 206 | jz bad_params 207 | dec esi 208 | call get_option_value 209 | or edx,edx 210 | jz bad_params 211 | cmp edx,1 shl (32-10) 212 | jae bad_params 213 | mov [memory_setting],edx 214 | jmp find_param 215 | passes_option: 216 | lodsb 217 | cmp al,20h 218 | je passes_option 219 | cmp al,0Dh 220 | je bad_params 221 | or al,al 222 | jz bad_params 223 | dec esi 224 | call get_option_value 225 | or edx,edx 226 | jz bad_params 227 | cmp edx,10000h 228 | ja bad_params 229 | mov [passes_limit],dx 230 | jmp find_param 231 | definition_option: 232 | lodsb 233 | cmp al,20h 234 | je definition_option 235 | cmp al,0Dh 236 | je bad_params 237 | or al,al 238 | jz bad_params 239 | dec esi 240 | push edi 241 | mov edi,[definitions_pointer] 242 | call convert_definition_option 243 | mov [definitions_pointer],edi 244 | pop edi 245 | jc bad_params 246 | jmp find_param 247 | symbols_option: 248 | mov [symbols_file],edi 249 | find_symbols_file_name: 250 | lodsb 251 | cmp al,20h 252 | jne process_param 253 | jmp find_symbols_file_name 254 | param_end: 255 | dec esi 256 | string_param_end: 257 | xor al,al 258 | stosb 259 | jmp find_param 260 | all_params: 261 | cmp [input_file],0 262 | je bad_params 263 | mov eax,[definitions_pointer] 264 | mov byte [eax],0 265 | mov [initial_definitions],predefinitions 266 | clc 267 | ret 268 | convert_definition_option: 269 | mov ecx,edi 270 | xor al,al 271 | stosb 272 | copy_definition_name: 273 | lodsb 274 | cmp al,'=' 275 | je copy_definition_value 276 | cmp al,20h 277 | je bad_definition_option 278 | cmp al,0Dh 279 | je bad_definition_option 280 | or al,al 281 | jz bad_definition_option 282 | stosb 283 | inc byte [ecx] 284 | jnz copy_definition_name 285 | bad_definition_option: 286 | stc 287 | ret 288 | copy_definition_value: 289 | lodsb 290 | cmp al,20h 291 | je definition_value_end 292 | cmp al,0Dh 293 | je definition_value_end 294 | or al,al 295 | jz definition_value_end 296 | cmp al,'\' 297 | jne definition_value_character 298 | cmp byte [esi],20h 299 | jne definition_value_character 300 | lodsb 301 | definition_value_character: 302 | stosb 303 | jmp copy_definition_value 304 | definition_value_end: 305 | dec esi 306 | xor al,al 307 | stosb 308 | clc 309 | ret 310 | 311 | include 'system.inc' 312 | 313 | include '..\errors.inc' 314 | include '..\symbdump.inc' 315 | include '..\preproce.inc' 316 | include '..\parser.inc' 317 | include '..\exprpars.inc' 318 | include '..\assemble.inc' 319 | include '..\exprcalc.inc' 320 | include '..\formats.inc' 321 | include '..\x86_64.inc' 322 | include '..\avx.inc' 323 | 324 | include '..\tables.inc' 325 | include '..\messages.inc' 326 | 327 | section '.data' data readable writeable 328 | 329 | include '..\version.inc' 330 | 331 | _copyright db 'Copyright (c) 1999-2016, Tomasz Grysztar',0Dh,0Ah,0 332 | 333 | _logo db 'flat assembler version ',VERSION_STRING,0 334 | _usage db 0Dh,0Ah 335 | db 'usage: fasm [output]',0Dh,0Ah 336 | db 'optional settings:',0Dh,0Ah 337 | db ' -m set the limit in kilobytes for the available memory',0Dh,0Ah 338 | db ' -p set the maximum allowed number of passes',0Dh,0Ah 339 | db ' -d = define symbolic variable',0Dh,0Ah 340 | db ' -s dump symbolic information for debugging',0Dh,0Ah 341 | db 0 342 | _memory_prefix db ' (',0 343 | _memory_suffix db ' kilobytes memory)',0Dh,0Ah,0 344 | _passes_suffix db ' passes, ',0 345 | _seconds_suffix db ' seconds, ',0 346 | _bytes_suffix db ' bytes.',0Dh,0Ah,0 347 | 348 | align 4 349 | 350 | include '..\variable.inc' 351 | 352 | con_handle dd ? 353 | memory_setting dd ? 354 | start_time dd ? 355 | definitions_pointer dd ? 356 | bytes_count dd ? 357 | displayed_count dd ? 358 | character db ? 359 | last_displayed rb 2 360 | preprocessing_done db ? 361 | 362 | params rb 1000h 363 | options rb 1000h 364 | predefinitions rb 1000h 365 | buffer rb 4000h 366 | 367 | stack 10000h 368 | 369 | section '.idata' import data readable writeable 370 | 371 | dd 0,0,0,rva kernel_name,rva kernel_table 372 | dd 0,0,0,0,0 373 | 374 | kernel_table: 375 | ExitProcess dd rva _ExitProcess 376 | CreateFile dd rva _CreateFileA 377 | ReadFile dd rva _ReadFile 378 | WriteFile dd rva _WriteFile 379 | CloseHandle dd rva _CloseHandle 380 | SetFilePointer dd rva _SetFilePointer 381 | GetCommandLine dd rva _GetCommandLineA 382 | GetEnvironmentVariable dd rva _GetEnvironmentVariable 383 | GetStdHandle dd rva _GetStdHandle 384 | VirtualAlloc dd rva _VirtualAlloc 385 | VirtualFree dd rva _VirtualFree 386 | GetTickCount dd rva _GetTickCount 387 | GetSystemTime dd rva _GetSystemTime 388 | GlobalMemoryStatus dd rva _GlobalMemoryStatus 389 | dd 0 390 | 391 | kernel_name db 'KERNEL32.DLL',0 392 | 393 | _ExitProcess dw 0 394 | db 'ExitProcess',0 395 | _CreateFileA dw 0 396 | db 'CreateFileA',0 397 | _ReadFile dw 0 398 | db 'ReadFile',0 399 | _WriteFile dw 0 400 | db 'WriteFile',0 401 | _CloseHandle dw 0 402 | db 'CloseHandle',0 403 | _SetFilePointer dw 0 404 | db 'SetFilePointer',0 405 | _GetCommandLineA dw 0 406 | db 'GetCommandLineA',0 407 | _GetEnvironmentVariable dw 0 408 | db 'GetEnvironmentVariableA',0 409 | _GetStdHandle dw 0 410 | db 'GetStdHandle',0 411 | _VirtualAlloc dw 0 412 | db 'VirtualAlloc',0 413 | _VirtualFree dw 0 414 | db 'VirtualFree',0 415 | _GetTickCount dw 0 416 | db 'GetTickCount',0 417 | _GetSystemTime dw 0 418 | db 'GetSystemTime',0 419 | _GlobalMemoryStatus dw 0 420 | db 'GlobalMemoryStatus',0 421 | 422 | section '.reloc' fixups data readable discardable 423 | -------------------------------------------------------------------------------- /fasm_src/source/Linux/x64/system.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Linux x64 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | O_ACCMODE = 0003o 7 | O_RDONLY = 0000o 8 | O_WRONLY = 0001o 9 | O_RDWR = 0002o 10 | O_CREAT = 0100o 11 | O_EXCL = 0200o 12 | O_NOCTTY = 0400o 13 | O_TRUNC = 1000o 14 | O_APPEND = 2000o 15 | O_NONBLOCK = 4000o 16 | 17 | S_ISUID = 4000o 18 | S_ISGID = 2000o 19 | S_ISVTX = 1000o 20 | S_IRUSR = 0400o 21 | S_IWUSR = 0200o 22 | S_IXUSR = 0100o 23 | S_IRGRP = 0040o 24 | S_IWGRP = 0020o 25 | S_IXGRP = 0010o 26 | S_IROTH = 0004o 27 | S_IWOTH = 0002o 28 | S_IXOTH = 0001o 29 | 30 | init_memory: 31 | mov eax,esp 32 | and eax,not 0FFFh 33 | add eax,1000h-10000h 34 | mov [stack_limit],eax 35 | xor edi,edi 36 | mov eax,12 37 | syscall 38 | mov r9,not 0FFFFFFFFh 39 | test rax,r9 40 | jnz no_low_memory 41 | mov [additional_memory],eax 42 | mov ecx,[memory_setting] 43 | shl ecx,10 44 | jnz allocate_memory 45 | mov ecx,1000000h 46 | allocate_memory: 47 | mov edi,[additional_memory] 48 | add edi,ecx 49 | mov eax,12 50 | syscall 51 | mov r9,not 0FFFFFFFFh 52 | test rax,r9 53 | jnz no_low_memory 54 | mov [memory_end],eax 55 | sub eax,[additional_memory] 56 | shr eax,2 57 | add eax,[additional_memory] 58 | mov [additional_memory_end],eax 59 | mov [memory_start],eax 60 | ret 61 | 62 | no_low_memory: 63 | push _no_low_memory 64 | jmp fatal_error 65 | 66 | exit_program: 67 | movzx edi,al 68 | mov eax,60 69 | syscall 70 | 71 | get_environment_variable: 72 | mov ebx,esi 73 | mov rsi,[environment] 74 | compare_variable_names: 75 | mov edx,ebx 76 | compare_character: 77 | lodsb 78 | mov ah,[edx] 79 | inc edx 80 | cmp al,'=' 81 | je end_of_variable_name 82 | or ah,ah 83 | jz next_variable 84 | sub ah,al 85 | jz compare_character 86 | cmp ah,20h 87 | jne next_variable 88 | cmp al,41h 89 | jb next_variable 90 | cmp al,5Ah 91 | jna compare_character 92 | next_variable: 93 | lodsb 94 | or al,al 95 | jnz next_variable 96 | cmp byte [rsi],0 97 | jne compare_variable_names 98 | ret 99 | end_of_variable_name: 100 | or ah,ah 101 | jnz next_variable 102 | copy_variable_value: 103 | lodsb 104 | cmp edi,[memory_end] 105 | jae out_of_memory 106 | stosb 107 | or al,al 108 | jnz copy_variable_value 109 | dec edi 110 | ret 111 | 112 | open: 113 | mov r12d,esi 114 | mov r13d,edi 115 | call adapt_path 116 | mov eax,2 117 | mov edi,buffer 118 | mov esi,O_RDONLY 119 | xor edx,edx 120 | syscall 121 | mov esi,r12d 122 | mov edi,r13d 123 | test eax,eax 124 | js file_error 125 | mov ebx,eax 126 | clc 127 | ret 128 | adapt_path: 129 | mov esi,edx 130 | mov edi,buffer 131 | copy_path: 132 | lods byte [esi] 133 | cmp al,'\' 134 | jne path_char_ok 135 | mov al,'/' 136 | path_char_ok: 137 | stos byte [edi] 138 | or al,al 139 | jnz copy_path 140 | cmp edi,buffer+1000h 141 | ja out_of_memory 142 | ret 143 | create: 144 | mov r12d,esi 145 | mov r13d,edi 146 | mov r15d,edx 147 | call adapt_path 148 | mov edi,buffer 149 | mov esi,O_CREAT+O_TRUNC+O_WRONLY 150 | mov edx,S_IRUSR+S_IWUSR+S_IRGRP+S_IROTH 151 | cmp r15d,[output_file] 152 | jne do_create 153 | cmp [output_format],5 154 | jne do_create 155 | bt [format_flags],0 156 | jnc do_create 157 | or edx,S_IXUSR+S_IXGRP+S_IXOTH 158 | do_create: 159 | mov eax,2 160 | syscall 161 | mov esi,r12d 162 | mov edi,r13d 163 | test eax,eax 164 | js file_error 165 | mov ebx,eax 166 | clc 167 | ret 168 | close: 169 | mov r13d,edi 170 | mov edi,ebx 171 | mov eax,3 172 | syscall 173 | mov edi,r13d 174 | ret 175 | read: 176 | mov r12d,esi 177 | mov r13d,edi 178 | mov eax,0 179 | mov edi,ebx 180 | mov esi,edx 181 | mov edx,ecx 182 | syscall 183 | mov ecx,edx 184 | mov edx,esi 185 | mov esi,r12d 186 | mov edi,r13d 187 | test eax,eax 188 | js file_error 189 | cmp eax,ecx 190 | jne file_error 191 | clc 192 | ret 193 | file_error: 194 | stc 195 | ret 196 | write: 197 | mov r12d,esi 198 | mov r13d,edi 199 | mov eax,1 200 | mov edi,ebx 201 | mov esi,edx 202 | mov edx,ecx 203 | syscall 204 | mov ecx,edx 205 | mov edx,esi 206 | mov esi,r12d 207 | mov edi,r13d 208 | test eax,eax 209 | js file_error 210 | clc 211 | ret 212 | lseek: 213 | mov r12d,esi 214 | mov r13d,edi 215 | mov edi,ebx 216 | mov esi,edx 217 | xor edx,edx 218 | mov dl,al 219 | mov eax,8 220 | syscall 221 | mov esi,r12d 222 | mov edi,r13d 223 | ret 224 | 225 | display_string: 226 | mov edi,esi 227 | mov edx,esi 228 | or ecx,-1 229 | xor al,al 230 | repne scasb 231 | neg ecx 232 | sub ecx,2 233 | mov eax,1 234 | mov edi,[con_handle] 235 | mov esi,edx 236 | mov edx,ecx 237 | syscall 238 | ret 239 | display_character: 240 | mov r12d,esi 241 | mov r13d,edi 242 | mov [character],dl 243 | mov eax,1 244 | mov edi,[con_handle] 245 | mov esi,character 246 | mov edx,1 247 | syscall 248 | mov esi,r12d 249 | mov edi,r13d 250 | ret 251 | display_number: 252 | mov r14d,ebx 253 | mov ecx,1000000000 254 | xor edx,edx 255 | xor bl,bl 256 | display_loop: 257 | div ecx 258 | mov r15d,edx 259 | cmp ecx,1 260 | je display_digit 261 | or bl,bl 262 | jnz display_digit 263 | or al,al 264 | jz digit_ok 265 | not bl 266 | display_digit: 267 | mov dl,al 268 | add dl,30h 269 | mov r10d,ecx 270 | call display_character 271 | mov ecx,r10d 272 | digit_ok: 273 | mov eax,ecx 274 | xor edx,edx 275 | mov ecx,10 276 | div ecx 277 | mov ecx,eax 278 | mov eax,r15d 279 | or ecx,ecx 280 | jnz display_loop 281 | mov ebx,r14d 282 | ret 283 | 284 | display_user_messages: 285 | mov [displayed_count],0 286 | call show_display_buffer 287 | cmp [displayed_count],0 288 | je line_break_ok 289 | cmp [last_displayed],0Ah 290 | je line_break_ok 291 | mov dl,0Ah 292 | call display_character 293 | line_break_ok: 294 | ret 295 | display_block: 296 | jecxz block_displayed 297 | add [displayed_count],ecx 298 | mov al,[esi+ecx-1] 299 | mov [last_displayed],al 300 | mov r13d,edi 301 | mov eax,1 302 | mov edi,[con_handle] 303 | mov edx,ecx 304 | syscall 305 | mov edi,r13d 306 | block_displayed: 307 | ret 308 | 309 | fatal_error: 310 | mov [con_handle],2 311 | mov esi,error_prefix 312 | call display_string 313 | pop esi 314 | call display_string 315 | mov esi,error_suffix 316 | call display_string 317 | mov al,0FFh 318 | jmp exit_program 319 | assembler_error: 320 | mov [con_handle],2 321 | call display_user_messages 322 | mov ebx,[current_line] 323 | test ebx,ebx 324 | jz display_error_message 325 | push dword 0 326 | get_error_lines: 327 | mov eax,[ebx] 328 | cmp byte [eax],0 329 | je get_next_error_line 330 | push ebx 331 | test byte [ebx+7],80h 332 | jz display_error_line 333 | mov edx,ebx 334 | find_definition_origin: 335 | mov edx,[edx+12] 336 | test byte [edx+7],80h 337 | jnz find_definition_origin 338 | push edx 339 | get_next_error_line: 340 | mov ebx,[ebx+8] 341 | jmp get_error_lines 342 | display_error_line: 343 | mov esi,[ebx] 344 | call display_string 345 | mov esi,line_number_start 346 | call display_string 347 | mov eax,[ebx+4] 348 | and eax,7FFFFFFFh 349 | call display_number 350 | mov dl,']' 351 | call display_character 352 | pop esi 353 | cmp ebx,esi 354 | je line_number_ok 355 | mov dl,20h 356 | call display_character 357 | push esi 358 | mov esi,[esi] 359 | movzx ecx,byte [esi] 360 | inc esi 361 | call display_block 362 | mov esi,line_number_start 363 | call display_string 364 | pop esi 365 | mov eax,[esi+4] 366 | and eax,7FFFFFFFh 367 | call display_number 368 | mov dl,']' 369 | call display_character 370 | line_number_ok: 371 | mov esi,line_data_start 372 | call display_string 373 | mov esi,ebx 374 | mov edx,[esi] 375 | call open 376 | mov al,2 377 | xor edx,edx 378 | call lseek 379 | mov edx,[esi+8] 380 | sub eax,edx 381 | jz line_data_displayed 382 | push eax 383 | xor al,al 384 | call lseek 385 | mov ecx,[esp] 386 | mov edx,[additional_memory] 387 | lea eax,[edx+ecx] 388 | cmp eax,[additional_memory_end] 389 | ja out_of_memory 390 | call read 391 | call close 392 | pop ecx 393 | mov esi,[additional_memory] 394 | get_line_data: 395 | mov al,[esi] 396 | cmp al,0Ah 397 | je display_line_data 398 | cmp al,0Dh 399 | je display_line_data 400 | cmp al,1Ah 401 | je display_line_data 402 | or al,al 403 | jz display_line_data 404 | inc esi 405 | loop get_line_data 406 | display_line_data: 407 | mov ecx,esi 408 | mov esi,[additional_memory] 409 | sub ecx,esi 410 | call display_block 411 | line_data_displayed: 412 | mov esi,lf 413 | call display_string 414 | pop ebx 415 | or ebx,ebx 416 | jnz display_error_line 417 | cmp [preprocessing_done],0 418 | je display_error_message 419 | mov esi,preprocessed_instruction_prefix 420 | call display_string 421 | mov esi,[current_line] 422 | add esi,16 423 | mov edi,[additional_memory] 424 | xor dl,dl 425 | convert_instruction: 426 | lodsb 427 | cmp al,1Ah 428 | je copy_symbol 429 | cmp al,22h 430 | je copy_symbol 431 | cmp al,3Bh 432 | je instruction_converted 433 | stosb 434 | or al,al 435 | jz instruction_converted 436 | xor dl,dl 437 | jmp convert_instruction 438 | copy_symbol: 439 | or dl,dl 440 | jz space_ok 441 | mov byte [edi],20h 442 | inc edi 443 | space_ok: 444 | cmp al,22h 445 | je quoted 446 | lodsb 447 | movzx ecx,al 448 | rep movsb 449 | or dl,-1 450 | jmp convert_instruction 451 | quoted: 452 | mov al,27h 453 | stosb 454 | lodsd 455 | mov ecx,eax 456 | jecxz quoted_copied 457 | copy_quoted: 458 | lodsb 459 | stosb 460 | cmp al,27h 461 | jne quote_ok 462 | stosb 463 | quote_ok: 464 | loop copy_quoted 465 | quoted_copied: 466 | mov al,27h 467 | stosb 468 | or dl,-1 469 | jmp convert_instruction 470 | instruction_converted: 471 | xor al,al 472 | stosb 473 | mov esi,[additional_memory] 474 | call display_string 475 | mov esi,lf 476 | call display_string 477 | display_error_message: 478 | mov esi,error_prefix 479 | call display_string 480 | pop esi 481 | call display_string 482 | mov esi,error_suffix 483 | call display_string 484 | mov al,2 485 | jmp exit_program 486 | 487 | make_timestamp: 488 | mov r13d,edi 489 | mov eax,201 490 | mov edi,timestamp 491 | syscall 492 | mov eax,dword [timestamp] 493 | mov edx,dword [timestamp+4] 494 | mov edi,r13d 495 | ret 496 | 497 | error_prefix db 'error: ',0 498 | error_suffix db '.' 499 | lf db 0xA,0 500 | line_number_start db ' [',0 501 | line_data_start db ':',0xA,0 502 | preprocessed_instruction_prefix db 'processed: ',0 503 | -------------------------------------------------------------------------------- /fasm_src/source/symbdump.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler core 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | dump_symbols: 7 | mov edi,[code_start] 8 | call setup_dump_header 9 | mov esi,[input_file] 10 | call copy_asciiz 11 | cmp edi,[tagged_blocks] 12 | jae out_of_memory 13 | mov eax,edi 14 | sub eax,ebx 15 | mov [ebx-40h+0Ch],eax 16 | mov esi,[output_file] 17 | call copy_asciiz 18 | cmp edi,[tagged_blocks] 19 | jae out_of_memory 20 | mov edx,[symbols_stream] 21 | mov ebp,[free_additional_memory] 22 | and [number_of_sections],0 23 | cmp [output_format],4 24 | je prepare_strings_table 25 | cmp [output_format],5 26 | jne strings_table_ready 27 | bt [format_flags],0 28 | jc strings_table_ready 29 | prepare_strings_table: 30 | cmp edx,ebp 31 | je strings_table_ready 32 | mov al,[edx] 33 | test al,al 34 | jz prepare_string 35 | cmp al,80h 36 | je prepare_string 37 | add edx,0Ch 38 | cmp al,0C0h 39 | jb prepare_strings_table 40 | add edx,4 41 | jmp prepare_strings_table 42 | prepare_string: 43 | mov esi,edi 44 | sub esi,ebx 45 | xchg esi,[edx+4] 46 | test al,al 47 | jz prepare_section_string 48 | or dword [edx+4],1 shl 31 49 | add edx,0Ch 50 | prepare_external_string: 51 | mov ecx,[esi] 52 | add esi,4 53 | rep movs byte [edi],[esi] 54 | mov byte [edi],0 55 | inc edi 56 | cmp edi,[tagged_blocks] 57 | jae out_of_memory 58 | jmp prepare_strings_table 59 | prepare_section_string: 60 | mov ecx,[number_of_sections] 61 | mov eax,ecx 62 | inc eax 63 | mov [number_of_sections],eax 64 | xchg eax,[edx+4] 65 | shl ecx,2 66 | add ecx,[free_additional_memory] 67 | mov [ecx],eax 68 | add edx,20h 69 | test esi,esi 70 | jz prepare_default_section_string 71 | cmp [output_format],5 72 | jne prepare_external_string 73 | bt [format_flags],0 74 | jc prepare_external_string 75 | mov esi,[esi] 76 | add esi,[resource_data] 77 | copy_elf_section_name: 78 | lods byte [esi] 79 | cmp edi,[tagged_blocks] 80 | jae out_of_memory 81 | stos byte [edi] 82 | test al,al 83 | jnz copy_elf_section_name 84 | jmp prepare_strings_table 85 | prepare_default_section_string: 86 | mov eax,'.fla' 87 | stos dword [edi] 88 | mov ax,'t' 89 | stos word [edi] 90 | cmp edi,[tagged_blocks] 91 | jae out_of_memory 92 | jmp prepare_strings_table 93 | strings_table_ready: 94 | mov edx,[tagged_blocks] 95 | mov ebp,[memory_end] 96 | sub ebp,[labels_list] 97 | add ebp,edx 98 | prepare_labels_dump: 99 | cmp edx,ebp 100 | je labels_dump_ok 101 | mov eax,[edx+24] 102 | test eax,eax 103 | jz label_dump_name_ok 104 | cmp eax,[memory_start] 105 | jb label_name_outside_source 106 | cmp eax,[source_start] 107 | ja label_name_outside_source 108 | sub eax,[memory_start] 109 | dec eax 110 | mov [edx+24],eax 111 | jmp label_dump_name_ok 112 | label_name_outside_source: 113 | mov esi,eax 114 | mov eax,edi 115 | sub eax,ebx 116 | or eax,1 shl 31 117 | mov [edx+24],eax 118 | movzx ecx,byte [esi-1] 119 | lea eax,[edi+ecx+1] 120 | cmp edi,[tagged_blocks] 121 | jae out_of_memory 122 | rep movsb 123 | xor al,al 124 | stosb 125 | label_dump_name_ok: 126 | mov eax,[edx+28] 127 | test eax,eax 128 | jz label_dump_line_ok 129 | sub eax,[memory_start] 130 | mov [edx+28],eax 131 | label_dump_line_ok: 132 | test byte [edx+9],4 133 | jz convert_base_symbol_for_label 134 | xor eax,eax 135 | mov [edx],eax 136 | mov [edx+4],eax 137 | jmp base_symbol_for_label_ok 138 | convert_base_symbol_for_label: 139 | mov eax,[edx+20] 140 | test eax,eax 141 | jz base_symbol_for_label_ok 142 | cmp eax,[symbols_stream] 143 | mov eax,[eax+4] 144 | jae base_symbol_for_label_ok 145 | xor eax,eax 146 | base_symbol_for_label_ok: 147 | mov [edx+20],eax 148 | mov ax,[current_pass] 149 | cmp ax,[edx+16] 150 | je label_defined_flag_ok 151 | and byte [edx+8],not 1 152 | label_defined_flag_ok: 153 | cmp ax,[edx+18] 154 | je label_used_flag_ok 155 | and byte [edx+8],not 8 156 | label_used_flag_ok: 157 | add edx,LABEL_STRUCTURE_SIZE 158 | jmp prepare_labels_dump 159 | labels_dump_ok: 160 | mov eax,edi 161 | sub eax,ebx 162 | mov [ebx-40h+14h],eax 163 | add eax,40h 164 | mov [ebx-40h+18h],eax 165 | mov ecx,[memory_end] 166 | sub ecx,[labels_list] 167 | mov [ebx-40h+1Ch],ecx 168 | add eax,ecx 169 | mov [ebx-40h+20h],eax 170 | mov ecx,[source_start] 171 | sub ecx,[memory_start] 172 | mov [ebx-40h+24h],ecx 173 | add eax,ecx 174 | mov [ebx-40h+28h],eax 175 | mov eax,[number_of_sections] 176 | shl eax,2 177 | mov [ebx-40h+34h],eax 178 | call prepare_preprocessed_source 179 | mov esi,[labels_list] 180 | mov ebp,edi 181 | make_lines_dump: 182 | cmp esi,[tagged_blocks] 183 | je lines_dump_ok 184 | mov eax,[esi-4] 185 | mov ecx,[esi-8] 186 | sub esi,8 187 | sub esi,ecx 188 | cmp eax,1 189 | je process_line_dump 190 | cmp eax,2 191 | jne make_lines_dump 192 | add dword [ebx-40h+3Ch],8 193 | jmp make_lines_dump 194 | process_line_dump: 195 | push ebx 196 | mov ebx,[esi+8] 197 | mov eax,[esi+4] 198 | sub eax,[code_start] 199 | add eax,[headers_size] 200 | test byte [ebx+0Ah],1 201 | jz store_offset 202 | xor eax,eax 203 | store_offset: 204 | stos dword [edi] 205 | mov eax,[esi] 206 | sub eax,[memory_start] 207 | stos dword [edi] 208 | mov eax,[esi+4] 209 | xor edx,edx 210 | xor cl,cl 211 | sub eax,[ebx] 212 | sbb edx,[ebx+4] 213 | sbb cl,[ebx+8] 214 | stos dword [edi] 215 | mov eax,edx 216 | stos dword [edi] 217 | mov eax,[ebx+10h] 218 | stos dword [edi] 219 | mov eax,[ebx+14h] 220 | test eax,eax 221 | jz base_symbol_for_line_ok 222 | cmp eax,[symbols_stream] 223 | mov eax,[eax+4] 224 | jae base_symbol_for_line_ok 225 | xor eax,eax 226 | base_symbol_for_line_ok: 227 | stos dword [edi] 228 | mov al,[ebx+9] 229 | stos byte [edi] 230 | mov al,[esi+10h] 231 | stos byte [edi] 232 | mov al,[ebx+0Ah] 233 | and al,1 234 | stos byte [edi] 235 | mov al,cl 236 | stos byte [edi] 237 | pop ebx 238 | cmp edi,[tagged_blocks] 239 | jae out_of_memory 240 | mov eax,edi 241 | sub eax,1Ch 242 | sub eax,ebp 243 | mov [esi],eax 244 | jmp make_lines_dump 245 | lines_dump_ok: 246 | mov edx,edi 247 | mov eax,[current_offset] 248 | sub eax,[code_start] 249 | add eax,[headers_size] 250 | stos dword [edi] 251 | mov ecx,edi 252 | sub ecx,ebx 253 | sub ecx,[ebx-40h+14h] 254 | mov [ebx-40h+2Ch],ecx 255 | add ecx,[ebx-40h+28h] 256 | mov [ebx-40h+30h],ecx 257 | add ecx,[ebx-40h+34h] 258 | mov [ebx-40h+38h],ecx 259 | find_inexisting_offsets: 260 | sub edx,1Ch 261 | cmp edx,ebp 262 | jb write_symbols 263 | test byte [edx+1Ah],1 264 | jnz find_inexisting_offsets 265 | cmp eax,[edx] 266 | jb correct_inexisting_offset 267 | mov eax,[edx] 268 | jmp find_inexisting_offsets 269 | correct_inexisting_offset: 270 | and dword [edx],0 271 | or byte [edx+1Ah],2 272 | jmp find_inexisting_offsets 273 | write_symbols: 274 | mov edx,[symbols_file] 275 | call create 276 | jc write_failed 277 | mov edx,[code_start] 278 | mov ecx,[edx+14h] 279 | add ecx,40h 280 | call write 281 | jc write_failed 282 | mov edx,[tagged_blocks] 283 | mov ecx,[memory_end] 284 | sub ecx,[labels_list] 285 | call write 286 | jc write_failed 287 | mov edx,[memory_start] 288 | mov ecx,[source_start] 289 | sub ecx,edx 290 | call write 291 | jc write_failed 292 | mov edx,ebp 293 | mov ecx,edi 294 | sub ecx,edx 295 | call write 296 | jc write_failed 297 | mov edx,[free_additional_memory] 298 | mov ecx,[number_of_sections] 299 | shl ecx,2 300 | call write 301 | jc write_failed 302 | mov esi,[labels_list] 303 | mov edi,[memory_start] 304 | make_references_dump: 305 | cmp esi,[tagged_blocks] 306 | je references_dump_ok 307 | mov eax,[esi-4] 308 | mov ecx,[esi-8] 309 | sub esi,8 310 | sub esi,ecx 311 | cmp eax,2 312 | je dump_reference 313 | cmp eax,1 314 | jne make_references_dump 315 | mov edx,[esi] 316 | jmp make_references_dump 317 | dump_reference: 318 | mov eax,[memory_end] 319 | sub eax,[esi] 320 | sub eax,LABEL_STRUCTURE_SIZE 321 | stosd 322 | mov eax,edx 323 | stosd 324 | cmp edi,[tagged_blocks] 325 | jb make_references_dump 326 | jmp out_of_memory 327 | references_dump_ok: 328 | mov edx,[memory_start] 329 | mov ecx,edi 330 | sub ecx,edx 331 | call write 332 | jc write_failed 333 | call close 334 | ret 335 | setup_dump_header: 336 | xor eax,eax 337 | mov ecx,40h shr 2 338 | rep stos dword [edi] 339 | mov ebx,edi 340 | mov dword [ebx-40h],'fas'+1Ah shl 24 341 | mov dword [ebx-40h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 40h shl 16 342 | mov dword [ebx-40h+10h],40h 343 | ret 344 | prepare_preprocessed_source: 345 | mov esi,[memory_start] 346 | mov ebp,[source_start] 347 | test ebp,ebp 348 | jnz prepare_preprocessed_line 349 | mov ebp,[current_line] 350 | inc ebp 351 | prepare_preprocessed_line: 352 | cmp esi,ebp 353 | jae preprocessed_source_ok 354 | mov eax,[memory_start] 355 | mov edx,[input_file] 356 | cmp [esi],edx 357 | jne line_not_from_main_input 358 | mov [esi],eax 359 | line_not_from_main_input: 360 | sub [esi],eax 361 | test byte [esi+7],1 shl 7 362 | jz prepare_next_preprocessed_line 363 | sub [esi+8],eax 364 | sub [esi+12],eax 365 | prepare_next_preprocessed_line: 366 | call skip_preprocessed_line 367 | jmp prepare_preprocessed_line 368 | preprocessed_source_ok: 369 | ret 370 | skip_preprocessed_line: 371 | add esi,16 372 | skip_preprocessed_line_content: 373 | lods byte [esi] 374 | cmp al,1Ah 375 | je skip_preprocessed_symbol 376 | cmp al,3Bh 377 | je skip_preprocessed_symbol 378 | cmp al,22h 379 | je skip_preprocessed_string 380 | or al,al 381 | jnz skip_preprocessed_line_content 382 | ret 383 | skip_preprocessed_string: 384 | lods dword [esi] 385 | add esi,eax 386 | jmp skip_preprocessed_line_content 387 | skip_preprocessed_symbol: 388 | lods byte [esi] 389 | movzx eax,al 390 | add esi,eax 391 | jmp skip_preprocessed_line_content 392 | restore_preprocessed_source: 393 | mov esi,[memory_start] 394 | mov ebp,[source_start] 395 | test ebp,ebp 396 | jnz restore_preprocessed_line 397 | mov ebp,[current_line] 398 | inc ebp 399 | restore_preprocessed_line: 400 | cmp esi,ebp 401 | jae preprocessed_source_restored 402 | mov eax,[memory_start] 403 | add [esi],eax 404 | cmp [esi],eax 405 | jne preprocessed_line_source_restored 406 | mov edx,[input_file] 407 | mov [esi],edx 408 | preprocessed_line_source_restored: 409 | test byte [esi+7],1 shl 7 410 | jz restore_next_preprocessed_line 411 | add [esi+8],eax 412 | add [esi+12],eax 413 | restore_next_preprocessed_line: 414 | call skip_preprocessed_line 415 | jmp restore_preprocessed_line 416 | preprocessed_source_restored: 417 | ret 418 | dump_preprocessed_source: 419 | mov edi,[free_additional_memory] 420 | call setup_dump_header 421 | mov esi,[input_file] 422 | call copy_asciiz 423 | cmp edi,[additional_memory_end] 424 | jae out_of_memory 425 | mov eax,edi 426 | sub eax,ebx 427 | dec eax 428 | mov [ebx-40h+0Ch],eax 429 | mov eax,edi 430 | sub eax,ebx 431 | mov [ebx-40h+14h],eax 432 | add eax,40h 433 | mov [ebx-40h+20h],eax 434 | call prepare_preprocessed_source 435 | sub esi,[memory_start] 436 | mov [ebx-40h+24h],esi 437 | mov edx,[symbols_file] 438 | call create 439 | jc write_failed 440 | mov edx,[free_additional_memory] 441 | mov ecx,[edx+14h] 442 | add ecx,40h 443 | call write 444 | jc write_failed 445 | mov edx,[memory_start] 446 | mov ecx,esi 447 | call write 448 | jc write_failed 449 | call close 450 | ret -------------------------------------------------------------------------------- /fasm_src/source/DOS/system.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for DOS 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | go32: 7 | use16 8 | call modes:real32 9 | use32 10 | retw 11 | 12 | program_base dd ? 13 | buffer_address dd ? 14 | psp_segment dw ? 15 | environment_segment dw ? 16 | 17 | if UNREAL_ENABLED>0 18 | 19 | init_memory: 20 | mov [stack_limit],0 21 | cmp [mode],dpmi 22 | je init_dpmi_memory 23 | call modes:init_real32_memory 24 | ret 25 | dos_int: 26 | cmp [mode],dpmi 27 | je dpmi_dos_int 28 | stc 29 | int 21h 30 | ret 31 | dos_int_with_buffer: 32 | cmp [mode],dpmi 33 | je dpmi_dos_int_with_buffer 34 | push ds buffer 35 | pop ds 36 | stc 37 | int 21h 38 | pop ds 39 | ret 40 | exit_program: 41 | cmp [mode],dpmi 42 | je exit_state_ok 43 | push eax 44 | call modes:free_real32_memory 45 | pop eax 46 | exit_state_ok: 47 | mov ah,4Ch 48 | int 21h 49 | 50 | else 51 | 52 | init_memory: 53 | mov [stack_limit],0 54 | jmp init_dpmi_memory 55 | dos_int: 56 | jmp dpmi_dos_int 57 | dos_int_with_buffer: 58 | jmp dpmi_dos_int_with_buffer 59 | exit_program: 60 | mov ah,4Ch 61 | int 21h 62 | 63 | end if 64 | 65 | get_environment_variable: 66 | mov ebx,esi 67 | push ds 68 | mov ds,[environment_segment] 69 | xor esi,esi 70 | compare_variable_names: 71 | mov edx,ebx 72 | compare_character: 73 | lodsb 74 | mov ah,[es:edx] 75 | inc edx 76 | cmp al,'=' 77 | je end_of_variable_name 78 | or ah,ah 79 | jz next_variable 80 | sub ah,al 81 | jz compare_character 82 | cmp ah,20h 83 | jne next_variable 84 | cmp al,41h 85 | jb next_variable 86 | cmp al,5Ah 87 | jna compare_character 88 | next_variable: 89 | lodsb 90 | or al,al 91 | jnz next_variable 92 | cmp byte [esi],0 93 | jne compare_variable_names 94 | pop ds 95 | ret 96 | end_of_variable_name: 97 | or ah,ah 98 | jnz next_variable 99 | copy_variable_value: 100 | lodsb 101 | cmp edi,[es:memory_end] 102 | jae out_of_memory 103 | stosb 104 | or al,al 105 | jnz copy_variable_value 106 | dec edi 107 | pop ds 108 | ret 109 | 110 | open: 111 | push esi edi 112 | call adapt_path 113 | mov ax,716Ch 114 | mov bx,100000b 115 | mov dx,1 116 | xor cx,cx 117 | xor si,si 118 | call dos_int_with_buffer 119 | jnc open_done 120 | cmp ax,7100h 121 | je old_open 122 | stc 123 | jmp open_done 124 | old_open: 125 | mov ax,3D00h 126 | xor dx,dx 127 | call dos_int_with_buffer 128 | open_done: 129 | mov bx,ax 130 | pop edi esi 131 | ret 132 | adapt_path: 133 | mov esi,edx 134 | mov edi,[buffer_address] 135 | copy_path: 136 | lodsb 137 | cmp al,'/' 138 | jne path_char_ok 139 | mov al,'\' 140 | path_char_ok: 141 | stosb 142 | or al,al 143 | jnz copy_path 144 | ret 145 | create: 146 | push esi edi 147 | call adapt_path 148 | mov ax,716Ch 149 | mov bx,100001b 150 | mov dx,10010b 151 | xor cx,cx 152 | xor si,si 153 | xor di,di 154 | call dos_int_with_buffer 155 | jnc create_done 156 | cmp ax,7100h 157 | je old_create 158 | stc 159 | jmp create_done 160 | old_create: 161 | mov ah,3Ch 162 | xor cx,cx 163 | xor dx,dx 164 | call dos_int_with_buffer 165 | create_done: 166 | mov bx,ax 167 | pop edi esi 168 | ret 169 | write: 170 | push edx esi edi ebp 171 | mov ebp,ecx 172 | mov esi,edx 173 | .loop: 174 | mov ecx,1000h 175 | sub ebp,1000h 176 | jnc .write 177 | add ebp,1000h 178 | mov ecx,ebp 179 | xor ebp,ebp 180 | .write: 181 | push ecx 182 | mov edi,[buffer_address] 183 | shr ecx,2 184 | rep movsd 185 | mov ecx,[esp] 186 | and ecx,11b 187 | rep movsb 188 | pop ecx 189 | mov ah,40h 190 | xor dx,dx 191 | call dos_int_with_buffer 192 | or ebp,ebp 193 | jnz .loop 194 | pop ebp edi esi edx 195 | ret 196 | read: 197 | push edx esi edi ebp 198 | mov ebp,ecx 199 | mov edi,edx 200 | .loop: 201 | mov ecx,1000h 202 | sub ebp,1000h 203 | jnc .read 204 | add ebp,1000h 205 | mov ecx,ebp 206 | xor ebp,ebp 207 | .read: 208 | push ecx 209 | mov ah,3Fh 210 | xor dx,dx 211 | call dos_int_with_buffer 212 | cmp ax,cx 213 | jne .eof 214 | mov esi,[buffer_address] 215 | mov ecx,[esp] 216 | shr ecx,2 217 | rep movsd 218 | pop ecx 219 | and ecx,11b 220 | rep movsb 221 | or ebp,ebp 222 | jnz .loop 223 | .exit: 224 | pop ebp edi esi edx 225 | ret 226 | .eof: 227 | pop ecx 228 | stc 229 | jmp .exit 230 | close: 231 | mov ah,3Eh 232 | int 21h 233 | ret 234 | lseek: 235 | mov ah,42h 236 | mov ecx,edx 237 | shr ecx,16 238 | int 21h 239 | pushf 240 | shl edx,16 241 | popf 242 | mov dx,ax 243 | mov eax,edx 244 | ret 245 | 246 | display_string: 247 | lods byte [esi] 248 | or al,al 249 | jz string_end 250 | mov dl,al 251 | mov ah,2 252 | int 21h 253 | jmp display_string 254 | string_end: 255 | ret 256 | display_number: 257 | push ebx 258 | mov ecx,1000000000 259 | xor edx,edx 260 | xor bl,bl 261 | display_loop: 262 | div ecx 263 | push edx 264 | cmp ecx,1 265 | je display_digit 266 | or bl,bl 267 | jnz display_digit 268 | or al,al 269 | jz digit_ok 270 | not bl 271 | display_digit: 272 | mov dl,al 273 | add dl,30h 274 | mov ah,2 275 | int 21h 276 | digit_ok: 277 | mov eax,ecx 278 | xor edx,edx 279 | mov ecx,10 280 | div ecx 281 | mov ecx,eax 282 | pop eax 283 | or ecx,ecx 284 | jnz display_loop 285 | pop ebx 286 | ret 287 | 288 | display_user_messages: 289 | mov [displayed_count],0 290 | call show_display_buffer 291 | cmp [displayed_count],1 292 | jb line_break_ok 293 | je make_line_break 294 | mov ax,word [last_displayed] 295 | cmp ax,0A0Dh 296 | je line_break_ok 297 | cmp ax,0D0Ah 298 | je line_break_ok 299 | make_line_break: 300 | mov ah,2 301 | mov dl,0Dh 302 | int 21h 303 | mov dl,0Ah 304 | int 21h 305 | line_break_ok: 306 | ret 307 | display_block: 308 | add [displayed_count],ecx 309 | cmp ecx,1 310 | ja take_last_two_characters 311 | jb display_character 312 | mov al,[last_displayed+1] 313 | mov ah,[esi] 314 | mov word [last_displayed],ax 315 | jmp display_character 316 | take_last_two_characters: 317 | mov ax,[esi+ecx-2] 318 | mov word [last_displayed],ax 319 | display_character: 320 | lods byte [esi] 321 | mov dl,al 322 | mov ah,2 323 | int 21h 324 | loopd display_character 325 | ret 326 | 327 | fatal_error: 328 | mov esi,error_prefix 329 | call display_string 330 | pop esi 331 | call display_string 332 | mov esi,error_suffix 333 | call display_string 334 | mov al,0FFh 335 | jmp exit_program 336 | assembler_error: 337 | call display_user_messages 338 | mov ebx,[current_line] 339 | test ebx,ebx 340 | jz display_error_message 341 | pushd 0 342 | get_error_lines: 343 | mov eax,[ebx] 344 | cmp byte [eax],0 345 | je get_next_error_line 346 | push ebx 347 | test byte [ebx+7],80h 348 | jz display_error_line 349 | mov edx,ebx 350 | find_definition_origin: 351 | mov edx,[edx+12] 352 | test byte [edx+7],80h 353 | jnz find_definition_origin 354 | push edx 355 | get_next_error_line: 356 | mov ebx,[ebx+8] 357 | jmp get_error_lines 358 | display_error_line: 359 | mov esi,[ebx] 360 | call display_string 361 | mov esi,line_number_start 362 | call display_string 363 | mov eax,[ebx+4] 364 | and eax,7FFFFFFFh 365 | call display_number 366 | mov dl,']' 367 | mov ah,2 368 | int 21h 369 | pop esi 370 | cmp ebx,esi 371 | je line_number_ok 372 | mov dl,20h 373 | mov ah,2 374 | int 21h 375 | push esi 376 | mov esi,[esi] 377 | movzx ecx,byte [esi] 378 | inc esi 379 | call display_block 380 | mov esi,line_number_start 381 | call display_string 382 | pop esi 383 | mov eax,[esi+4] 384 | and eax,7FFFFFFFh 385 | call display_number 386 | mov dl,']' 387 | mov ah,2 388 | int 21h 389 | line_number_ok: 390 | mov esi,line_data_start 391 | call display_string 392 | mov esi,ebx 393 | mov edx,[esi] 394 | call open 395 | mov al,2 396 | xor edx,edx 397 | call lseek 398 | mov edx,[esi+8] 399 | sub eax,edx 400 | jz line_data_displayed 401 | mov [counter],eax 402 | xor al,al 403 | call lseek 404 | mov esi,[additional_memory] 405 | read_line_data: 406 | mov ecx,100h 407 | cmp ecx,[counter] 408 | jbe bytes_count_ok 409 | mov ecx,[counter] 410 | bytes_count_ok: 411 | sub [counter],ecx 412 | lea eax,[esi+ecx] 413 | cmp eax,[additional_memory_end] 414 | ja out_of_memory 415 | push ecx 416 | mov edx,esi 417 | call read 418 | pop ecx 419 | get_line_data: 420 | mov al,[esi] 421 | cmp al,0Ah 422 | je display_line_data 423 | cmp al,0Dh 424 | je display_line_data 425 | cmp al,1Ah 426 | je display_line_data 427 | or al,al 428 | jz display_line_data 429 | inc esi 430 | loop get_line_data 431 | cmp [counter],0 432 | ja read_line_data 433 | display_line_data: 434 | call close 435 | mov ecx,esi 436 | mov esi,[additional_memory] 437 | sub ecx,esi 438 | call display_block 439 | line_data_displayed: 440 | mov esi,cr_lf 441 | call display_string 442 | pop ebx 443 | or ebx,ebx 444 | jnz display_error_line 445 | cmp [preprocessing_done],0 446 | je display_error_message 447 | mov esi,preprocessed_instruction_prefix 448 | call display_string 449 | mov esi,[current_line] 450 | add esi,16 451 | mov edi,[additional_memory] 452 | xor dl,dl 453 | convert_instruction: 454 | lodsb 455 | cmp al,1Ah 456 | je copy_symbol 457 | cmp al,22h 458 | je copy_symbol 459 | cmp al,3Bh 460 | je instruction_converted 461 | stosb 462 | or al,al 463 | jz instruction_converted 464 | xor dl,dl 465 | jmp convert_instruction 466 | copy_symbol: 467 | or dl,dl 468 | jz space_ok 469 | mov byte [edi],20h 470 | inc edi 471 | space_ok: 472 | cmp al,22h 473 | je quoted 474 | lodsb 475 | movzx ecx,al 476 | rep movsb 477 | or dl,-1 478 | jmp convert_instruction 479 | quoted: 480 | mov al,27h 481 | stosb 482 | lodsd 483 | mov ecx,eax 484 | jecxz quoted_copied 485 | copy_quoted: 486 | lodsb 487 | stosb 488 | cmp al,27h 489 | jne quote_ok 490 | stosb 491 | quote_ok: 492 | loop copy_quoted 493 | quoted_copied: 494 | mov al,27h 495 | stosb 496 | or dl,-1 497 | jmp convert_instruction 498 | instruction_converted: 499 | xor al,al 500 | stosb 501 | mov esi,[additional_memory] 502 | call display_string 503 | mov esi,cr_lf 504 | call display_string 505 | display_error_message: 506 | mov esi,error_prefix 507 | call display_string 508 | pop esi 509 | call display_string 510 | mov esi,error_suffix 511 | call display_string 512 | mov al,2 513 | jmp exit_program 514 | 515 | make_timestamp: 516 | mov ah,2Ah 517 | int 21h 518 | push dx cx 519 | movzx ecx,cx 520 | mov eax,ecx 521 | sub eax,1970 522 | mov ebx,365 523 | mul ebx 524 | mov ebp,eax 525 | mov eax,ecx 526 | sub eax,1969 527 | shr eax,2 528 | add ebp,eax 529 | mov eax,ecx 530 | sub eax,1901 531 | mov ebx,100 532 | div ebx 533 | sub ebp,eax 534 | mov eax,ecx 535 | xor edx,edx 536 | sub eax,1601 537 | mov ebx,400 538 | div ebx 539 | add ebp,eax 540 | movzx ecx,byte [esp+3] 541 | mov eax,ecx 542 | dec eax 543 | mov ebx,30 544 | mul ebx 545 | add ebp,eax 546 | cmp ecx,8 547 | jbe months_correction 548 | mov eax,ecx 549 | sub eax,7 550 | shr eax,1 551 | add ebp,eax 552 | mov ecx,8 553 | months_correction: 554 | mov eax,ecx 555 | shr eax,1 556 | add ebp,eax 557 | cmp ecx,2 558 | pop cx 559 | jbe day_correction_ok 560 | sub ebp,2 561 | test ecx,11b 562 | jnz day_correction_ok 563 | xor edx,edx 564 | mov eax,ecx 565 | mov ebx,100 566 | div ebx 567 | or edx,edx 568 | jnz day_correction 569 | mov eax,ecx 570 | mov ebx,400 571 | div ebx 572 | or edx,edx 573 | jnz day_correction_ok 574 | day_correction: 575 | inc ebp 576 | day_correction_ok: 577 | pop dx 578 | movzx eax,dl 579 | dec eax 580 | add eax,ebp 581 | mov ebx,24 582 | mul ebx 583 | push eax 584 | mov ah,2Ch 585 | int 21h 586 | pop eax 587 | push dx 588 | movzx ebx,ch 589 | add eax,ebx 590 | mov ebx,60 591 | mul ebx 592 | movzx ebx,cl 593 | add eax,ebx 594 | mov ebx,60 595 | mul ebx 596 | pop bx 597 | movzx ebx,bh 598 | add eax,ebx 599 | adc edx,0 600 | ret 601 | -------------------------------------------------------------------------------- /fasm_src/source/Win32/system.inc: -------------------------------------------------------------------------------- 1 | 2 | ; flat assembler interface for Win32 3 | ; Copyright (c) 1999-2016, Tomasz Grysztar. 4 | ; All rights reserved. 5 | 6 | CREATE_NEW = 1 7 | CREATE_ALWAYS = 2 8 | OPEN_EXISTING = 3 9 | OPEN_ALWAYS = 4 10 | TRUNCATE_EXISTING = 5 11 | 12 | FILE_SHARE_READ = 1 13 | FILE_SHARE_WRITE = 2 14 | FILE_SHARE_DELETE = 4 15 | 16 | GENERIC_READ = 80000000h 17 | GENERIC_WRITE = 40000000h 18 | 19 | STD_INPUT_HANDLE = 0FFFFFFF6h 20 | STD_OUTPUT_HANDLE = 0FFFFFFF5h 21 | STD_ERROR_HANDLE = 0FFFFFFF4h 22 | 23 | MEM_COMMIT = 1000h 24 | MEM_RESERVE = 2000h 25 | MEM_DECOMMIT = 4000h 26 | MEM_RELEASE = 8000h 27 | MEM_FREE = 10000h 28 | MEM_PRIVATE = 20000h 29 | MEM_MAPPED = 40000h 30 | MEM_RESET = 80000h 31 | MEM_TOP_DOWN = 100000h 32 | 33 | PAGE_NOACCESS = 1 34 | PAGE_READONLY = 2 35 | PAGE_READWRITE = 4 36 | PAGE_WRITECOPY = 8 37 | PAGE_EXECUTE = 10h 38 | PAGE_EXECUTE_READ = 20h 39 | PAGE_EXECUTE_READWRITE = 40h 40 | PAGE_EXECUTE_WRITECOPY = 80h 41 | PAGE_GUARD = 100h 42 | PAGE_NOCACHE = 200h 43 | 44 | init_memory: 45 | xor eax,eax 46 | mov [memory_start],eax 47 | mov eax,esp 48 | and eax,not 0FFFh 49 | add eax,1000h-10000h 50 | mov [stack_limit],eax 51 | mov eax,[memory_setting] 52 | shl eax,10 53 | jnz allocate_memory 54 | push buffer 55 | call [GlobalMemoryStatus] 56 | mov eax,dword [buffer+20] 57 | mov edx,dword [buffer+12] 58 | cmp eax,0 59 | jl large_memory 60 | cmp edx,0 61 | jl large_memory 62 | shr eax,2 63 | add eax,edx 64 | jmp allocate_memory 65 | large_memory: 66 | mov eax,80000000h 67 | allocate_memory: 68 | mov edx,eax 69 | shr edx,2 70 | mov ecx,eax 71 | sub ecx,edx 72 | mov [memory_end],ecx 73 | mov [additional_memory_end],edx 74 | push PAGE_READWRITE 75 | push MEM_COMMIT 76 | push eax 77 | push 0 78 | call [VirtualAlloc] 79 | or eax,eax 80 | jz not_enough_memory 81 | mov [memory_start],eax 82 | add eax,[memory_end] 83 | mov [memory_end],eax 84 | mov [additional_memory],eax 85 | add [additional_memory_end],eax 86 | ret 87 | not_enough_memory: 88 | mov eax,[additional_memory_end] 89 | shl eax,1 90 | cmp eax,4000h 91 | jb out_of_memory 92 | jmp allocate_memory 93 | 94 | exit_program: 95 | movzx eax,al 96 | push eax 97 | mov eax,[memory_start] 98 | test eax,eax 99 | jz do_exit 100 | push MEM_RELEASE 101 | push 0 102 | push eax 103 | call [VirtualFree] 104 | do_exit: 105 | call [ExitProcess] 106 | 107 | get_environment_variable: 108 | mov ecx,[memory_end] 109 | sub ecx,edi 110 | cmp ecx,4000h 111 | jbe buffer_for_variable_ok 112 | mov ecx,4000h 113 | buffer_for_variable_ok: 114 | push ecx 115 | push edi 116 | push esi 117 | call [GetEnvironmentVariable] 118 | add edi,eax 119 | cmp edi,[memory_end] 120 | jae out_of_memory 121 | ret 122 | 123 | open: 124 | push 0 125 | push 0 126 | push OPEN_EXISTING 127 | push 0 128 | push FILE_SHARE_READ 129 | push GENERIC_READ 130 | push edx 131 | call [CreateFile] 132 | cmp eax,-1 133 | je file_error 134 | mov ebx,eax 135 | clc 136 | ret 137 | file_error: 138 | stc 139 | ret 140 | create: 141 | push 0 142 | push 0 143 | push CREATE_ALWAYS 144 | push 0 145 | push FILE_SHARE_READ 146 | push GENERIC_WRITE 147 | push edx 148 | call [CreateFile] 149 | cmp eax,-1 150 | je file_error 151 | mov ebx,eax 152 | clc 153 | ret 154 | write: 155 | push 0 156 | push bytes_count 157 | push ecx 158 | push edx 159 | push ebx 160 | call [WriteFile] 161 | or eax,eax 162 | jz file_error 163 | clc 164 | ret 165 | read: 166 | mov ebp,ecx 167 | push 0 168 | push bytes_count 169 | push ecx 170 | push edx 171 | push ebx 172 | call [ReadFile] 173 | or eax,eax 174 | jz file_error 175 | cmp ebp,[bytes_count] 176 | jne file_error 177 | clc 178 | ret 179 | close: 180 | push ebx 181 | call [CloseHandle] 182 | ret 183 | lseek: 184 | movzx eax,al 185 | push eax 186 | push 0 187 | push edx 188 | push ebx 189 | call [SetFilePointer] 190 | ret 191 | 192 | display_string: 193 | push [con_handle] 194 | call [GetStdHandle] 195 | mov ebp,eax 196 | mov edi,esi 197 | or ecx,-1 198 | xor al,al 199 | repne scasb 200 | neg ecx 201 | sub ecx,2 202 | push 0 203 | push bytes_count 204 | push ecx 205 | push esi 206 | push ebp 207 | call [WriteFile] 208 | ret 209 | display_character: 210 | push ebx 211 | mov [character],dl 212 | push [con_handle] 213 | call [GetStdHandle] 214 | mov ebx,eax 215 | push 0 216 | push bytes_count 217 | push 1 218 | push character 219 | push ebx 220 | call [WriteFile] 221 | pop ebx 222 | ret 223 | display_number: 224 | push ebx 225 | mov ecx,1000000000 226 | xor edx,edx 227 | xor bl,bl 228 | display_loop: 229 | div ecx 230 | push edx 231 | cmp ecx,1 232 | je display_digit 233 | or bl,bl 234 | jnz display_digit 235 | or al,al 236 | jz digit_ok 237 | not bl 238 | display_digit: 239 | mov dl,al 240 | add dl,30h 241 | push ecx 242 | call display_character 243 | pop ecx 244 | digit_ok: 245 | mov eax,ecx 246 | xor edx,edx 247 | mov ecx,10 248 | div ecx 249 | mov ecx,eax 250 | pop eax 251 | or ecx,ecx 252 | jnz display_loop 253 | pop ebx 254 | ret 255 | 256 | display_user_messages: 257 | mov [displayed_count],0 258 | call show_display_buffer 259 | cmp [displayed_count],1 260 | jb line_break_ok 261 | je make_line_break 262 | mov ax,word [last_displayed] 263 | cmp ax,0A0Dh 264 | je line_break_ok 265 | cmp ax,0D0Ah 266 | je line_break_ok 267 | make_line_break: 268 | mov word [buffer],0A0Dh 269 | push [con_handle] 270 | call [GetStdHandle] 271 | push 0 272 | push bytes_count 273 | push 2 274 | push buffer 275 | push eax 276 | call [WriteFile] 277 | line_break_ok: 278 | ret 279 | display_block: 280 | add [displayed_count],ecx 281 | cmp ecx,1 282 | ja take_last_two_characters 283 | jb block_displayed 284 | mov al,[last_displayed+1] 285 | mov ah,[esi] 286 | mov word [last_displayed],ax 287 | jmp block_ok 288 | take_last_two_characters: 289 | mov ax,[esi+ecx-2] 290 | mov word [last_displayed],ax 291 | block_ok: 292 | push ecx 293 | push [con_handle] 294 | call [GetStdHandle] 295 | pop ecx 296 | push 0 297 | push bytes_count 298 | push ecx 299 | push esi 300 | push eax 301 | call [WriteFile] 302 | block_displayed: 303 | ret 304 | 305 | fatal_error: 306 | mov [con_handle],STD_ERROR_HANDLE 307 | mov esi,error_prefix 308 | call display_string 309 | pop esi 310 | call display_string 311 | mov esi,error_suffix 312 | call display_string 313 | mov al,0FFh 314 | jmp exit_program 315 | assembler_error: 316 | mov [con_handle],STD_ERROR_HANDLE 317 | call display_user_messages 318 | mov ebx,[current_line] 319 | test ebx,ebx 320 | jz display_error_message 321 | push dword 0 322 | get_error_lines: 323 | mov eax,[ebx] 324 | cmp byte [eax],0 325 | je get_next_error_line 326 | push ebx 327 | test byte [ebx+7],80h 328 | jz display_error_line 329 | mov edx,ebx 330 | find_definition_origin: 331 | mov edx,[edx+12] 332 | test byte [edx+7],80h 333 | jnz find_definition_origin 334 | push edx 335 | get_next_error_line: 336 | mov ebx,[ebx+8] 337 | jmp get_error_lines 338 | display_error_line: 339 | mov esi,[ebx] 340 | call display_string 341 | mov esi,line_number_start 342 | call display_string 343 | mov eax,[ebx+4] 344 | and eax,7FFFFFFFh 345 | call display_number 346 | mov dl,']' 347 | call display_character 348 | pop esi 349 | cmp ebx,esi 350 | je line_number_ok 351 | mov dl,20h 352 | call display_character 353 | push esi 354 | mov esi,[esi] 355 | movzx ecx,byte [esi] 356 | inc esi 357 | call display_block 358 | mov esi,line_number_start 359 | call display_string 360 | pop esi 361 | mov eax,[esi+4] 362 | and eax,7FFFFFFFh 363 | call display_number 364 | mov dl,']' 365 | call display_character 366 | line_number_ok: 367 | mov esi,line_data_start 368 | call display_string 369 | mov esi,ebx 370 | mov edx,[esi] 371 | call open 372 | mov al,2 373 | xor edx,edx 374 | call lseek 375 | mov edx,[esi+8] 376 | sub eax,edx 377 | jz line_data_displayed 378 | push eax 379 | xor al,al 380 | call lseek 381 | mov ecx,[esp] 382 | mov edx,[additional_memory] 383 | lea eax,[edx+ecx] 384 | cmp eax,[additional_memory_end] 385 | ja out_of_memory 386 | call read 387 | call close 388 | pop ecx 389 | mov esi,[additional_memory] 390 | get_line_data: 391 | mov al,[esi] 392 | cmp al,0Ah 393 | je display_line_data 394 | cmp al,0Dh 395 | je display_line_data 396 | cmp al,1Ah 397 | je display_line_data 398 | or al,al 399 | jz display_line_data 400 | inc esi 401 | loop get_line_data 402 | display_line_data: 403 | mov ecx,esi 404 | mov esi,[additional_memory] 405 | sub ecx,esi 406 | call display_block 407 | line_data_displayed: 408 | mov esi,cr_lf 409 | call display_string 410 | pop ebx 411 | or ebx,ebx 412 | jnz display_error_line 413 | cmp [preprocessing_done],0 414 | je display_error_message 415 | mov esi,preprocessed_instruction_prefix 416 | call display_string 417 | mov esi,[current_line] 418 | add esi,16 419 | mov edi,[additional_memory] 420 | xor dl,dl 421 | convert_instruction: 422 | lodsb 423 | cmp al,1Ah 424 | je copy_symbol 425 | cmp al,22h 426 | je copy_symbol 427 | cmp al,3Bh 428 | je instruction_converted 429 | stosb 430 | or al,al 431 | jz instruction_converted 432 | xor dl,dl 433 | jmp convert_instruction 434 | copy_symbol: 435 | or dl,dl 436 | jz space_ok 437 | mov byte [edi],20h 438 | inc edi 439 | space_ok: 440 | cmp al,22h 441 | je quoted 442 | lodsb 443 | movzx ecx,al 444 | rep movsb 445 | or dl,-1 446 | jmp convert_instruction 447 | quoted: 448 | mov al,27h 449 | stosb 450 | lodsd 451 | mov ecx,eax 452 | jecxz quoted_copied 453 | copy_quoted: 454 | lodsb 455 | stosb 456 | cmp al,27h 457 | jne quote_ok 458 | stosb 459 | quote_ok: 460 | loop copy_quoted 461 | quoted_copied: 462 | mov al,27h 463 | stosb 464 | or dl,-1 465 | jmp convert_instruction 466 | instruction_converted: 467 | xor al,al 468 | stosb 469 | mov esi,[additional_memory] 470 | call display_string 471 | mov esi,cr_lf 472 | call display_string 473 | display_error_message: 474 | mov esi,error_prefix 475 | call display_string 476 | pop esi 477 | call display_string 478 | mov esi,error_suffix 479 | call display_string 480 | mov al,2 481 | jmp exit_program 482 | 483 | make_timestamp: 484 | push buffer 485 | call [GetSystemTime] 486 | movzx ecx,word [buffer] 487 | mov eax,ecx 488 | sub eax,1970 489 | mov ebx,365 490 | mul ebx 491 | mov ebp,eax 492 | mov eax,ecx 493 | sub eax,1969 494 | shr eax,2 495 | add ebp,eax 496 | mov eax,ecx 497 | sub eax,1901 498 | mov ebx,100 499 | div ebx 500 | sub ebp,eax 501 | mov eax,ecx 502 | xor edx,edx 503 | sub eax,1601 504 | mov ebx,400 505 | div ebx 506 | add ebp,eax 507 | movzx ecx,word [buffer+2] 508 | mov eax,ecx 509 | dec eax 510 | mov ebx,30 511 | mul ebx 512 | add ebp,eax 513 | cmp ecx,8 514 | jbe months_correction 515 | mov eax,ecx 516 | sub eax,7 517 | shr eax,1 518 | add ebp,eax 519 | mov ecx,8 520 | months_correction: 521 | mov eax,ecx 522 | shr eax,1 523 | add ebp,eax 524 | cmp ecx,2 525 | jbe day_correction_ok 526 | sub ebp,2 527 | movzx ecx,word [buffer] 528 | test ecx,11b 529 | jnz day_correction_ok 530 | xor edx,edx 531 | mov eax,ecx 532 | mov ebx,100 533 | div ebx 534 | or edx,edx 535 | jnz day_correction 536 | mov eax,ecx 537 | mov ebx,400 538 | div ebx 539 | or edx,edx 540 | jnz day_correction_ok 541 | day_correction: 542 | inc ebp 543 | day_correction_ok: 544 | movzx eax,word [buffer+6] 545 | dec eax 546 | add eax,ebp 547 | mov ebx,24 548 | mul ebx 549 | movzx ecx,word [buffer+8] 550 | add eax,ecx 551 | mov ebx,60 552 | mul ebx 553 | movzx ecx,word [buffer+10] 554 | add eax,ecx 555 | mov ebx,60 556 | mul ebx 557 | movzx ecx,word [buffer+12] 558 | add eax,ecx 559 | adc edx,0 560 | ret 561 | 562 | error_prefix db 'error: ',0 563 | error_suffix db '.' 564 | cr_lf db 0Dh,0Ah,0 565 | line_number_start db ' [',0 566 | line_data_start db ':',0Dh,0Ah,0 567 | preprocessed_instruction_prefix db 'processed: ',0 568 | --------------------------------------------------------------------------------