"Fossies" - the Fresh Open Source Software Archive

Member "fasm/source/Win32/system.inc" (21 Feb 2022, 9297 Bytes) of package /linux/misc/fasm-1.73.30.tgz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) fasm source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "system.inc": 1.73.29_vs_1.73.30.

    1 
    2 ; flat assembler interface for Win32
    3 ; Copyright (c) 1999-2022, 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     cmp eax,-1
  191     je  file_error
  192     clc
  193     ret
  194 
  195 display_string:
  196     push    [con_handle]
  197     call    [GetStdHandle]
  198     mov ebp,eax
  199     mov edi,esi
  200     or  ecx,-1
  201     xor al,al
  202     repne   scasb
  203     neg ecx
  204     sub ecx,2
  205     push    0
  206     push    bytes_count
  207     push    ecx
  208     push    esi
  209     push    ebp
  210     call    [WriteFile]
  211     ret
  212 display_character:
  213     push    ebx
  214     mov [character],dl
  215     push    [con_handle]
  216     call    [GetStdHandle]
  217     mov ebx,eax
  218     push    0
  219     push    bytes_count
  220     push    1
  221     push    character
  222     push    ebx
  223     call    [WriteFile]
  224     pop ebx
  225     ret
  226 display_number:
  227     push    ebx
  228     mov ecx,1000000000
  229     xor edx,edx
  230     xor bl,bl
  231       display_loop:
  232     div ecx
  233     push    edx
  234     cmp ecx,1
  235     je  display_digit
  236     or  bl,bl
  237     jnz display_digit
  238     or  al,al
  239     jz  digit_ok
  240     not bl
  241       display_digit:
  242     mov dl,al
  243     add dl,30h
  244     push    ecx
  245     call    display_character
  246     pop ecx
  247       digit_ok:
  248     mov eax,ecx
  249     xor edx,edx
  250     mov ecx,10
  251     div ecx
  252     mov ecx,eax
  253     pop eax
  254     or  ecx,ecx
  255     jnz display_loop
  256     pop ebx
  257     ret
  258 
  259 display_user_messages:
  260     mov [displayed_count],0
  261     call    show_display_buffer
  262     cmp [displayed_count],1
  263     jb  line_break_ok
  264     je  make_line_break
  265     mov ax,word [last_displayed]
  266     cmp ax,0A0Dh
  267     je  line_break_ok
  268     cmp ax,0D0Ah
  269     je  line_break_ok
  270       make_line_break:
  271     mov word [buffer],0A0Dh
  272     push    [con_handle]
  273     call    [GetStdHandle]
  274     push    0
  275     push    bytes_count
  276     push    2
  277     push    buffer
  278     push    eax
  279     call    [WriteFile]
  280       line_break_ok:
  281     ret
  282 display_block:
  283     add [displayed_count],ecx
  284     cmp ecx,1
  285     ja  take_last_two_characters
  286     jb  block_displayed
  287     mov al,[last_displayed+1]
  288     mov ah,[esi]
  289     mov word [last_displayed],ax
  290     jmp block_ok
  291       take_last_two_characters:
  292     mov ax,[esi+ecx-2]
  293     mov word [last_displayed],ax
  294       block_ok:
  295     push    ecx
  296     push    [con_handle]
  297     call    [GetStdHandle]
  298     pop ecx
  299     push    0
  300     push    bytes_count
  301     push    ecx
  302     push    esi
  303     push    eax
  304     call    [WriteFile]
  305       block_displayed:
  306     ret
  307 
  308 fatal_error:
  309     mov [con_handle],STD_ERROR_HANDLE
  310     mov esi,error_prefix
  311     call    display_string
  312     pop esi
  313     call    display_string
  314     mov esi,error_suffix
  315     call    display_string
  316     mov al,0FFh
  317     jmp exit_program
  318 assembler_error:
  319     mov [con_handle],STD_ERROR_HANDLE
  320     call    display_user_messages
  321     mov ebx,[current_line]
  322     test    ebx,ebx
  323     jz  display_error_message
  324     push    dword 0
  325       get_error_lines:
  326     mov eax,[ebx]
  327     cmp byte [eax],0
  328     je  get_next_error_line
  329     push    ebx
  330     test    byte [ebx+7],80h
  331     jz  display_error_line
  332     mov edx,ebx
  333       find_definition_origin:
  334     mov edx,[edx+12]
  335     test    byte [edx+7],80h
  336     jnz find_definition_origin
  337     push    edx
  338       get_next_error_line:
  339     mov ebx,[ebx+8]
  340     jmp get_error_lines
  341       display_error_line:
  342     mov esi,[ebx]
  343     call    display_string
  344     mov esi,line_number_start
  345     call    display_string
  346     mov eax,[ebx+4]
  347     and eax,7FFFFFFFh
  348     call    display_number
  349     mov dl,']'
  350     call    display_character
  351     pop esi
  352     cmp ebx,esi
  353     je  line_number_ok
  354     mov dl,20h
  355     call    display_character
  356     push    esi
  357     mov esi,[esi]
  358     movzx   ecx,byte [esi]
  359     inc esi
  360     call    display_block
  361     mov esi,line_number_start
  362     call    display_string
  363     pop esi
  364     mov eax,[esi+4]
  365     and eax,7FFFFFFFh
  366     call    display_number
  367     mov dl,']'
  368     call    display_character
  369       line_number_ok:
  370     mov esi,line_data_start
  371     call    display_string
  372     mov esi,ebx
  373     mov edx,[esi]
  374     call    open
  375     mov al,2
  376     xor edx,edx
  377     call    lseek
  378     mov edx,[esi+8]
  379     sub eax,edx
  380     jz  line_data_displayed
  381     push    eax
  382     xor al,al
  383     call    lseek
  384     mov ecx,[esp]
  385     mov edx,[additional_memory]
  386     lea eax,[edx+ecx]
  387     cmp eax,[additional_memory_end]
  388     ja  out_of_memory
  389     call    read
  390     call    close
  391     pop ecx
  392     mov esi,[additional_memory]
  393       get_line_data:
  394     mov al,[esi]
  395     cmp al,0Ah
  396     je  display_line_data
  397     cmp al,0Dh
  398     je  display_line_data
  399     cmp al,1Ah
  400     je  display_line_data
  401     or  al,al
  402     jz  display_line_data
  403     inc esi
  404     loop    get_line_data
  405       display_line_data:
  406     mov ecx,esi
  407     mov esi,[additional_memory]
  408     sub ecx,esi
  409     call    display_block
  410       line_data_displayed:
  411     mov esi,cr_lf
  412     call    display_string
  413     pop ebx
  414     or  ebx,ebx
  415     jnz display_error_line
  416     cmp [preprocessing_done],0
  417     je  display_error_message
  418     mov esi,preprocessed_instruction_prefix
  419     call    display_string
  420     mov esi,[current_line]
  421     add esi,16
  422     mov edi,[additional_memory]
  423     xor dl,dl
  424       convert_instruction:
  425     lodsb
  426     cmp al,1Ah
  427     je  copy_symbol
  428     cmp al,22h
  429     je  copy_symbol
  430     cmp al,3Bh
  431     je  instruction_converted
  432     stosb
  433     or  al,al
  434     jz  instruction_converted
  435     xor dl,dl
  436     jmp convert_instruction
  437       copy_symbol:
  438     or  dl,dl
  439     jz  space_ok
  440     mov byte [edi],20h
  441     inc edi
  442       space_ok:
  443     cmp al,22h
  444     je  quoted
  445     lodsb
  446     movzx   ecx,al
  447     rep movsb
  448     or  dl,-1
  449     jmp convert_instruction
  450       quoted:
  451     mov al,27h
  452     stosb
  453     lodsd
  454     mov ecx,eax
  455     jecxz   quoted_copied
  456       copy_quoted:
  457     lodsb
  458     stosb
  459     cmp al,27h
  460     jne quote_ok
  461     stosb
  462       quote_ok:
  463     loop    copy_quoted
  464       quoted_copied:
  465     mov al,27h
  466     stosb
  467     or  dl,-1
  468     jmp convert_instruction
  469       instruction_converted:
  470     xor al,al
  471     stosb
  472     mov esi,[additional_memory]
  473     call    display_string
  474     mov esi,cr_lf
  475     call    display_string
  476       display_error_message:
  477     mov esi,error_prefix
  478     call    display_string
  479     pop esi
  480     call    display_string
  481     mov esi,error_suffix
  482     call    display_string
  483     mov al,2
  484     jmp exit_program
  485 
  486 make_timestamp:
  487     push    buffer
  488     call    [GetSystemTime]
  489     movzx   ecx,word [buffer]
  490     mov eax,ecx
  491     sub eax,1970
  492     mov ebx,365
  493     mul ebx
  494     mov ebp,eax
  495     mov eax,ecx
  496     sub eax,1969
  497     shr eax,2
  498     add ebp,eax
  499     mov eax,ecx
  500     sub eax,1901
  501     mov ebx,100
  502     div ebx
  503     sub ebp,eax
  504     mov eax,ecx
  505     xor edx,edx
  506     sub eax,1601
  507     mov ebx,400
  508     div ebx
  509     add ebp,eax
  510     movzx   ecx,word [buffer+2]
  511     mov eax,ecx
  512     dec eax
  513     mov ebx,30
  514     mul ebx
  515     add ebp,eax
  516     cmp ecx,8
  517     jbe months_correction
  518     mov eax,ecx
  519     sub eax,7
  520     shr eax,1
  521     add ebp,eax
  522     mov ecx,8
  523       months_correction:
  524     mov eax,ecx
  525     shr eax,1
  526     add ebp,eax
  527     cmp ecx,2
  528     jbe day_correction_ok
  529     sub ebp,2
  530     movzx   ecx,word [buffer]
  531     test    ecx,11b
  532     jnz day_correction_ok
  533     xor edx,edx
  534     mov eax,ecx
  535     mov ebx,100
  536     div ebx
  537     or  edx,edx
  538     jnz day_correction
  539     mov eax,ecx
  540     mov ebx,400
  541     div ebx
  542     or  edx,edx
  543     jnz day_correction_ok
  544       day_correction:
  545     inc ebp
  546       day_correction_ok:
  547     movzx   eax,word [buffer+6]
  548     dec eax
  549     add eax,ebp
  550     mov ebx,24
  551     mul ebx
  552     movzx   ecx,word [buffer+8]
  553     add eax,ecx
  554     mov ebx,60
  555     mul ebx
  556     movzx   ecx,word [buffer+10]
  557     add eax,ecx
  558     mov ebx,60
  559     mul ebx
  560     movzx   ecx,word [buffer+12]
  561     add eax,ecx
  562     adc edx,0
  563     ret
  564 
  565 error_prefix db 'error: ',0
  566 error_suffix db '.'
  567 cr_lf db 0Dh,0Ah,0
  568 line_number_start db ' [',0
  569 line_data_start db ':',0Dh,0Ah,0
  570 preprocessed_instruction_prefix db 'processed: ',0