Subversion Repositories Kolibri OS

Rev

Rev 3011 | Blame | Last modification | View Log | Download | RSS feed

  1.  
  2. ; flat assembler core
  3. ; Copyright (c) 1999-2013, 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