diff -urN fasm-vanilla/source/libc/fasm.asm fasm/source/libc/fasm.asm --- fasm-vanilla/source/libc/fasm.asm 1970-01-01 01:00:00.000000000 +0100 +++ fasm/source/libc/fasm.asm 2005-01-19 17:39:14.000000000 +0100 @@ -0,0 +1,139 @@ + +; flat assembler interface for ELF/libc +; Copyright (c) 1999-2003, Tomasz Grysztar. +; All rights reserved. + + format ELF + public main + +macro ccall proc,[arg] + { common local size + size = 0 + reverse + pushd arg + size = size+4 + common + call proc + add esp,size } + +extrn gettimeofday + +section '.flat' executable align 16 + +main: + mov ecx,[esp+4] + mov [argc],ecx + mov ebx,[esp+8] + mov [argv],ebx + push ebp + mov [stack_frame],esp + + mov esi,_logo + call display_string + + call get_params + jc information + + call init_memory + + ccall gettimeofday,buffer,0 + mov eax,dword [buffer] + mov ecx,1000 + mul ecx + mov ebx,eax + mov eax,dword [buffer+4] + div ecx + add eax,ebx + mov [start_time],eax + + call preprocessor + call parser + call assembler + call formatter + + call display_user_messages + movzx eax,[current_pass] + inc eax + call display_number + mov esi,_passes_suffix + call display_string + ccall gettimeofday,buffer,0 + mov eax,dword [buffer] + mov ecx,1000 + mul ecx + mov ebx,eax + mov eax,dword [buffer+4] + div ecx + add eax,ebx + sub eax,[start_time] + jnc time_ok + add eax,3600000 + time_ok: + xor edx,edx + mov ebx,100 + div ebx + or eax,eax + jz display_bytes_count + xor edx,edx + mov ebx,10 + div ebx + push edx + call display_number + mov dl,'.' + call display_character + pop eax + call display_number + mov esi,_seconds_suffix + call display_string + display_bytes_count: + mov eax,[written_size] + call display_number + mov esi,_bytes_suffix + call display_string + xor al,al + jmp exit_program + +information: + mov esi,_usage + call display_string + mov al,1 + jmp exit_program + +include 'system.inc' + +include '..\version.inc' +include '..\errors.inc' +include '..\expressi.inc' +include '..\preproce.inc' +include '..\parser.inc' +include '..\assemble.inc' +include '..\formats.inc' +include '..\x86.inc' + +section '.data' writeable align 16 + +_copyright db 'Copyright (c) 1999-2002, Tomasz Grysztar',0xA,0 + +_logo db 'flat assembler version ',VERSION_STRING,0xA,0 +_usage db 'usage: fasm source [output]',0xA,0 + +_passes_suffix db ' passes, ',0 +_seconds_suffix db ' seconds, ',0 +_bytes_suffix db ' bytes.',0xA,0 + +align 4 + +include '..\variable.inc' + +argc dd ? +argv dd ? +stack_frame dd ? +memory_setting dd ? +environment dd ? +start_time dd ? +timestamp dd ? +displayed_count dd ? +last_displayed db ? +character db ? + +buffer rb 1000h diff -urN fasm-vanilla/source/libc/system.inc fasm-libc/source/libc/system.inc --- fasm-vanilla/source/libc/system.inc 1970-01-01 01:00:00.000000000 +0100 +++ fasm/source/libc/system.inc 2005-01-19 17:37:10.000000000 +0100 @@ -0,0 +1,453 @@ + +; flat assembler interface for libc +; Copyright (c) 1999-2004, Tomasz Grysztar. +; All rights reserved. + +extrn malloc +extrn free +extrn getenv +extrn fopen +extrn fclose +extrn fread +extrn fwrite +extrn fseek +extrn ftell +extrn chmod +extrn putchar +extrn time +extrn exit + +S_ISUID = 4000o +S_ISGID = 2000o +S_ISVTX = 1000o +S_IRUSR = 0400o +S_IWUSR = 0200o +S_IXUSR = 0100o +S_IRGRP = 0040o +S_IWGRP = 0020o +S_IXGRP = 0010o +S_IROTH = 0004o +S_IWOTH = 0002o +S_IXOTH = 0001o + +init_memory: + mov ecx,[memory_setting] + or ecx,ecx + jnz allocate_memory + mov ecx,4000h + allocate_memory: + shl ecx,10 + mov [memory_setting],ecx + ccall malloc,ecx + or eax,eax + jz out_of_memory + mov [additional_memory],eax + add eax,[memory_setting] + mov [memory_end],eax + mov eax,[memory_setting] + shr eax,3 + imul eax,3 + add eax,[additional_memory] + mov [additional_memory_end],eax + mov [memory_start],eax + ret + +exit_program: + movzx eax,al + push eax + ccall free,[additional_memory] + call exit + mov esp,[stack_frame] + pop ebp + ret + +get_params: + mov [input_file],0 + mov [output_file],0 + mov [memory_setting],0 + mov [passes_limit],100 + mov ecx,[argc] + mov ebx,[argv] + add ebx,4 + dec ecx + jz bad_params + get_param: + mov esi,[ebx] + mov al,[esi] + cmp al,'-' + je option_param + cmp [input_file],0 + jne get_output_file + mov [input_file],esi + jmp next_param + get_output_file: + cmp [output_file],0 + jne bad_params + mov [output_file],esi + jmp next_param + option_param: + inc esi + lodsb + cmp al,'m' + je memory_option + cmp al,'M' + je memory_option + cmp al,'p' + je passes_option + cmp al,'P' + je passes_option + bad_params: + stc + ret + memory_option: + cmp byte [esi],0 + jne get_memory_setting + dec ecx + jz bad_params + add ebx,4 + mov esi,[ebx] + get_memory_setting: + call get_option_value + or edx,edx + jz bad_params + cmp edx,1 shl (32-10) + jae bad_params + mov [memory_setting],edx + jmp next_param + passes_option: + cmp byte [esi],0 + jne get_passes_setting + dec ecx + jz bad_params + add ebx,4 + mov esi,[ebx] + get_passes_setting: + call get_option_value + or edx,edx + jz bad_params + cmp edx,10000h + ja bad_params + mov [passes_limit],dx + next_param: + add ebx,4 + dec ecx + jnz get_param + cmp [input_file],0 + je bad_params + clc + ret + get_option_value: + xor eax,eax + mov edx,eax + get_option_digit: + lodsb + cmp al,20h + je option_value_ok + cmp al,0Dh + je option_value_ok + or al,al + jz option_value_ok + sub al,30h + jc invalid_option_value + cmp al,9 + ja invalid_option_value + imul edx,10 + jo invalid_option_value + add edx,eax + jc invalid_option_value + jmp get_option_digit + option_value_ok: + dec esi + clc + ret + invalid_option_value: + stc + ret + +get_environment_variable: + ccall getenv,esi + mov esi,eax + or eax,eax + jz no_environment_variable + copy_variable_value: + lodsb + cmp edi,[memory_end] + jae out_of_memory + stosb + or al,al + jnz copy_variable_value + dec edi + ret + no_environment_variable: + stosb + dec edi + ret + +open: + push esi edi ebp + call adapt_path + ccall fopen,buffer,open_mode + pop ebp edi esi + or eax,eax + jz file_error + mov ebx,eax + clc + ret + adapt_path: + mov esi,edx + mov edi,buffer + copy_path: + lods byte [esi] + cmp al,'\' + jne path_char_ok + mov al,'/' + path_char_ok: + stos byte [edi] + or al,al + jnz copy_path + cmp edi,buffer+1000h + ja out_of_memory + ret +create: + push esi edi ebp + call adapt_path + ccall fopen,buffer,create_mode + cmp [output_format],5 + jne created_ok + bt [format_flags],0 + jnc created_ok + push eax + ccall chmod,buffer,S_IRUSR+S_IWUSR+S_IRGRP+S_IROTH+S_IXUSR+S_IXGRP+S_IXOTH + pop eax + created_ok: + pop ebp edi esi + or eax,eax + jz file_error + mov ebx,eax + clc + ret +close: + ccall fclose,ebx + ret +read: + push ebx ecx edx esi edi + ccall fread,edx,1,ecx,ebx + pop edi esi edx ecx ebx + cmp eax,ecx + jne file_error + clc + ret + file_error: + stc + ret +write: + push ebx ecx edx esi edi + ccall fwrite,edx,1,ecx,ebx + pop edi esi edx ecx ebx + cmp eax,ecx + jne file_error + clc + ret +lseek: + push ebx + movzx eax,al + ccall fseek,ebx,edx,eax + mov ebx,[esp] + ccall ftell,ebx + pop ebx + ret + +display_string: + lodsb + or al,al + jz string_displayed + mov dl,al + call display_character + jmp display_string + string_displayed: + ret +display_character: + movzx edx,dl + ccall putchar,edx + ret +display_number: + push ebx + mov ecx,1000000000 + xor edx,edx + xor bl,bl + display_loop: + div ecx + push edx + cmp ecx,1 + je display_digit + or bl,bl + jnz display_digit + or al,al + jz digit_ok + not bl + display_digit: + mov dl,al + add dl,30h + push ebx ecx + call display_character + pop ecx ebx + digit_ok: + mov eax,ecx + xor edx,edx + mov ecx,10 + div ecx + mov ecx,eax + pop eax + or ecx,ecx + jnz display_loop + pop ebx + ret + +display_user_messages: + mov [displayed_count],0 + call flush_display_buffer + cmp [displayed_count],0 + je line_break_ok + cmp [last_displayed],0Ah + je line_break_ok + mov dl,0Ah + call display_character + line_break_ok: + ret +display_block: + jecxz block_displayed + add [displayed_count],ecx + mov al,[esi+ecx-1] + mov [last_displayed],al + display_characters: + lodsb + mov dl,al + push ecx esi + call display_character + pop esi ecx + loop display_characters + block_displayed: + ret + +fatal_error: + mov esi,error_prefix + call display_string + pop esi + call display_string + mov esi,error_suffix + call display_string + mov al,0FFh + jmp exit_program +assembler_error: + call display_user_messages + push dword 0 + mov ebx,[current_line] + get_error_lines: + push ebx + test byte [ebx+7],80h + jz display_error_line + mov edx,ebx + find_definition_origin: + mov edx,[edx+12] + test byte [edx+7],80h + jnz find_definition_origin + push edx + mov ebx,[ebx+8] + jmp get_error_lines + display_error_line: + mov esi,[ebx] + call display_string + mov esi,line_number_start + call display_string + mov eax,[ebx+4] + and eax,7FFFFFFFh + call display_number + mov dl,']' + call display_character + pop esi + cmp ebx,esi + je line_number_ok + mov dl,20h + call display_character + push esi + mov esi,[esi] + movzx ecx,byte [esi] + inc esi + call display_block + mov esi,line_number_start + call display_string + pop esi + mov eax,[esi+4] + and eax,7FFFFFFFh + call display_number + mov dl,']' + call display_character + line_number_ok: + mov esi,line_data_start + call display_string + mov esi,ebx + mov edx,[esi] + call open + mov al,2 + xor edx,edx + call lseek + mov edx,[esi+8] + sub eax,edx + push eax + xor al,al + call lseek + mov ecx,[esp] + mov edx,[additional_memory] + lea eax,[edx+ecx] + cmp eax,[additional_memory_end] + ja out_of_memory + call read + call close + pop ecx + mov esi,[additional_memory] + get_line_data: + mov al,[esi] + cmp al,0Ah + je display_line_data + cmp al,0Dh + je display_line_data + cmp al,1Ah + je display_line_data + or al,al + jz display_line_data + inc esi + loop get_line_data + display_line_data: + mov ecx,esi + mov esi,[additional_memory] + sub ecx,esi + call display_block + mov esi,lf + call display_string + pop ebx + or ebx,ebx + jnz display_error_line + mov esi,error_prefix + call display_string + pop esi + call display_string + mov esi,error_suffix + call display_string + mov al,2 + jmp exit_program + +make_timestamp: + ccall time,timestamp + mov eax,[timestamp] + ret + +open_mode db 'r',0 +create_mode db 'w',0 + +error_prefix db 'error: ',0 +error_suffix db '.' +lf db 0xA,0 +line_number_start db ' [',0 +line_data_start db ':',0xA,0 + +macro dm string { db string,0 }