Subversion Repositories Kolibri OS

Rev

Rev 992 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ; flat assembler core
  3. ; Copyright (c) 1999-2011, 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,[display_buffer]
  12.         jae     out_of_memory
  13.         mov     eax,edi
  14.         sub     eax,ebx
  15.         mov     [ebx-38h+0Ch],eax
  16.         mov     esi,[output_file]
  17.         call    copy_asciiz
  18.         cmp     edi,[display_buffer]
  19.         jae     out_of_memory
  20.         mov     edx,[symbols_stream]
  21.         mov     ebp,[free_additional_memory]
  22.         mov     [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,[display_buffer]
  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,[display_buffer]
  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,[display_buffer]
  91.         jae     out_of_memory
  92.         jmp     prepare_strings_table
  93.       strings_table_ready:
  94.         mov     edx,[display_buffer]
  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,[display_buffer]
  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.         mov     eax,[edx+20]
  133.         test    eax,eax
  134.         jz      base_symbol_for_label_ok
  135.         cmp     eax,[symbols_stream]
  136.         mov     eax,[eax+4]
  137.         jae     base_symbol_for_label_ok
  138.         xor     eax,eax
  139.       base_symbol_for_label_ok:
  140.         mov     [edx+20],eax
  141.         mov     ax,[current_pass]
  142.         cmp     ax,[edx+16]
  143.         je      label_defined_flag_ok
  144.         and     byte [edx+8],not 1
  145.       label_defined_flag_ok:
  146.         cmp     ax,[edx+18]
  147.         je      label_used_flag_ok
  148.         and     byte [edx+8],not 8
  149.       label_used_flag_ok:
  150.         add     edx,LABEL_STRUCTURE_SIZE
  151.         jmp     prepare_labels_dump
  152.       labels_dump_ok:
  153.         mov     eax,edi
  154.         sub     eax,ebx
  155.         mov     [ebx-38h+14h],eax
  156.         add     eax,38h
  157.         mov     [ebx-38h+18h],eax
  158.         mov     ecx,[memory_end]
  159.         sub     ecx,[labels_list]
  160.         mov     [ebx-38h+1Ch],ecx
  161.         add     eax,ecx
  162.         mov     [ebx-38h+20h],eax
  163.         mov     ecx,[source_start]
  164.         sub     ecx,[memory_start]
  165.         mov     [ebx-38h+24h],ecx
  166.         add     eax,ecx
  167.         mov     [ebx-38h+28h],eax
  168.         mov     eax,[number_of_sections]
  169.         shl     eax,2
  170.         mov     [ebx-38h+34h],eax
  171.         call    prepare_preprocessed_source
  172.         mov     esi,[labels_list]
  173.         mov     ebp,edi
  174.       make_lines_dump:
  175.         cmp     esi,[display_buffer]
  176.         je      lines_dump_ok
  177.         mov     eax,[esi-4]
  178.         mov     ecx,[esi-8]
  179.         sub     esi,8
  180.         sub     esi,ecx
  181.         cmp     eax,1
  182.         jne     make_lines_dump
  183.         mov     eax,[esi+4]
  184.         sub     eax,[code_start]
  185.         add     eax,[headers_size]
  186.         cmp     byte [esi+1Ah],0
  187.         je      store_offset
  188.         xor     eax,eax
  189.       store_offset:
  190.         stos    dword [edi]
  191.         mov     eax,[esi]
  192.         sub     eax,[memory_start]
  193.         stos    dword [edi]
  194.         mov     eax,[esi+4]
  195.         xor     edx,edx
  196.         sub     eax,[esi+8]
  197.         sbb     edx,[esi+8+4]
  198.         stos    dword [edi]
  199.         mov     eax,edx
  200.         stos    dword [edi]
  201.         mov     eax,[esi+10h]
  202.         stos    dword [edi]
  203.         mov     eax,[esi+14h]
  204.         test    eax,eax
  205.         jz      base_symbol_for_line_ok
  206.         cmp     eax,[symbols_stream]
  207.         mov     eax,[eax+4]
  208.         jae     base_symbol_for_line_ok
  209.         xor     eax,eax
  210.       base_symbol_for_line_ok:
  211.         stos    dword [edi]
  212.         mov     eax,[esi+18h]
  213.         and     eax,001FFFFh
  214.         stos    dword [edi]
  215.         cmp     edi,[display_buffer]
  216.         jae     out_of_memory
  217.         jmp     make_lines_dump
  218.       lines_dump_ok:
  219.         mov     edx,edi
  220.         mov     eax,[current_offset]
  221.         sub     eax,[code_start]
  222.         add     eax,[headers_size]
  223.         stos    dword [edi]
  224.         mov     ecx,edi
  225.         sub     ecx,ebx
  226.         sub     ecx,[ebx-38h+14h]
  227.         mov     [ebx-38h+2Ch],ecx
  228.         add     ecx,[ebx-38h+28h]
  229.         mov     [ebx-38h+30h],ecx
  230.       find_inexisting_offsets:
  231.         sub     edx,1Ch
  232.         cmp     edx,ebp
  233.         jb      write_symbols
  234.         test    byte [edx+1Ah],1
  235.         jnz     find_inexisting_offsets
  236.         cmp     eax,[edx]
  237.         jb      correct_inexisting_offset
  238.         mov     eax,[edx]
  239.         jmp     find_inexisting_offsets
  240.       correct_inexisting_offset:
  241.         mov     dword [edx],0
  242.         or      byte [edx+1Ah],2
  243.         jmp     find_inexisting_offsets
  244.       write_symbols:
  245.         mov     edx,[symbols_file]
  246.         call    create
  247.         jc      write_failed
  248.         mov     edx,[code_start]
  249.         mov     ecx,[edx+14h]
  250.         add     ecx,38h
  251.         call    write
  252.         jc      write_failed
  253.         mov     edx,[display_buffer]
  254.         mov     ecx,[memory_end]
  255.         sub     ecx,[labels_list]
  256.         call    write
  257.         jc      write_failed
  258.         mov     edx,[memory_start]
  259.         mov     ecx,[source_start]
  260.         sub     ecx,edx
  261.         call    write
  262.         jc      write_failed
  263.         mov     edx,ebp
  264.         mov     ecx,edi
  265.         sub     ecx,edx
  266.         call    write
  267.         jc      write_failed
  268.         mov     edx,[free_additional_memory]
  269.         mov     ecx,[number_of_sections]
  270.         shl     ecx,2
  271.         call    write
  272.         jc      write_failed
  273.         call    close
  274.         ret
  275.       setup_dump_header:
  276.         xor     eax,eax
  277.         mov     ecx,38h shr 2
  278.         rep     stos dword [edi]
  279.         mov     ebx,edi
  280.         mov     dword [ebx-38h],'fas'+1Ah shl 24
  281.         mov     dword [ebx-38h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 38h shl 16
  282.         mov     dword [ebx-38h+10h],38h
  283.         ret
  284. prepare_preprocessed_source:
  285.         mov     esi,[memory_start]
  286.         mov     ebp,[source_start]
  287.         test    ebp,ebp
  288.         jnz     prepare_preprocessed_line
  289.         mov     ebp,[current_line]
  290.         inc     ebp
  291.       prepare_preprocessed_line:
  292.         cmp     esi,ebp
  293.         jae     preprocessed_source_ok
  294.         mov     eax,[memory_start]
  295.         mov     edx,[input_file]
  296.         cmp     [esi],edx
  297.         jne     line_not_from_main_input
  298.         mov     [esi],eax
  299.       line_not_from_main_input:
  300.         sub     [esi],eax
  301.         test    byte [esi+7],1 shl 7
  302.         jz      prepare_next_preprocessed_line
  303.         sub     [esi+8],eax
  304.         sub     [esi+12],eax
  305.       prepare_next_preprocessed_line:
  306.         call    skip_preprocessed_line
  307.         jmp     prepare_preprocessed_line
  308.       preprocessed_source_ok:
  309.         ret
  310.       skip_preprocessed_line:
  311.         add     esi,16
  312.       skip_preprocessed_line_content:
  313.         lods    byte [esi]
  314.         cmp     al,1Ah
  315.         je      skip_preprocessed_symbol
  316.         cmp     al,3Bh
  317.         je      skip_preprocessed_symbol
  318.         cmp     al,22h
  319.         je      skip_preprocessed_string
  320.         or      al,al
  321.         jnz     skip_preprocessed_line_content
  322.         ret
  323.       skip_preprocessed_string:
  324.         lods    dword [esi]
  325.         add     esi,eax
  326.         jmp     skip_preprocessed_line_content
  327.       skip_preprocessed_symbol:
  328.         lods    byte [esi]
  329.         movzx   eax,al
  330.         add     esi,eax
  331.         jmp     skip_preprocessed_line_content
  332. restore_preprocessed_source:
  333.         mov     esi,[memory_start]
  334.         mov     ebp,[source_start]
  335.         test    ebp,ebp
  336.         jnz     restore_preprocessed_line
  337.         mov     ebp,[current_line]
  338.         inc     ebp
  339.       restore_preprocessed_line:
  340.         cmp     esi,ebp
  341.         jae     preprocessed_source_restored
  342.         mov     eax,[memory_start]
  343.         add     [esi],eax
  344.         cmp     [esi],eax
  345.         jne     preprocessed_line_source_restored
  346.         mov     edx,[input_file]
  347.         mov     [esi],edx
  348.       preprocessed_line_source_restored:
  349.         test    byte [esi+7],1 shl 7
  350.         jz      restore_next_preprocessed_line
  351.         add     [esi+8],eax
  352.         add     [esi+12],eax
  353.       restore_next_preprocessed_line:
  354.         call    skip_preprocessed_line
  355.         jmp     restore_preprocessed_line
  356.       preprocessed_source_restored:
  357.         ret
  358. dump_preprocessed_source:
  359.         mov     edi,[free_additional_memory]
  360.         call    setup_dump_header
  361.         mov     esi,[input_file]
  362.         call    copy_asciiz
  363.         cmp     edi,[additional_memory_end]
  364.         jae     out_of_memory
  365.         mov     eax,edi
  366.         sub     eax,ebx
  367.         dec     eax
  368.         mov     [ebx-38h+0Ch],eax
  369.         mov     eax,edi
  370.         sub     eax,ebx
  371.         mov     [ebx-38h+14h],eax
  372.         add     eax,38h
  373.         mov     [ebx-38h+20h],eax
  374.         call    prepare_preprocessed_source
  375.         sub     esi,[memory_start]
  376.         mov     [ebx-38h+24h],esi
  377.         mov     edx,[symbols_file]
  378.         call    create
  379.         jc      write_failed
  380.         mov     edx,[free_additional_memory]
  381.         mov     ecx,[edx+14h]
  382.         add     ecx,38h
  383.         call    write
  384.         jc      write_failed
  385.         mov     edx,[memory_start]
  386.         mov     ecx,esi
  387.         call    write
  388.         jc      write_failed
  389.         call    close
  390.         ret