Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. ; flat assembler core
  3. ; Copyright (c) 1999-2012, 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-40h+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.         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,[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-40h+14h],eax
  156.         add     eax,40h
  157.         mov     [ebx-40h+18h],eax
  158.         mov     ecx,[memory_end]
  159.         sub     ecx,[labels_list]
  160.         mov     [ebx-40h+1Ch],ecx
  161.         add     eax,ecx
  162.         mov     [ebx-40h+20h],eax
  163.         mov     ecx,[source_start]
  164.         sub     ecx,[memory_start]
  165.         mov     [ebx-40h+24h],ecx
  166.         add     eax,ecx
  167.         mov     [ebx-40h+28h],eax
  168.         mov     eax,[number_of_sections]
  169.         shl     eax,2
  170.         mov     [ebx-40h+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.         je      process_line_dump
  183.         cmp     eax,2
  184.         jne     make_lines_dump
  185.         add     dword [ebx-40h+3Ch],8
  186.         jmp     make_lines_dump
  187.       process_line_dump:
  188.         mov     eax,[esi+4]
  189.         sub     eax,[code_start]
  190.         add     eax,[headers_size]
  191.         cmp     byte [esi+1Ah],0
  192.         je      store_offset
  193.         xor     eax,eax
  194.       store_offset:
  195.         stos    dword [edi]
  196.         mov     eax,[esi]
  197.         sub     eax,[memory_start]
  198.         stos    dword [edi]
  199.         mov     eax,[esi+4]
  200.         xor     edx,edx
  201.         xor     cl,cl
  202.         sub     eax,[esi+8]
  203.         sbb     edx,[esi+8+4]
  204.         sbb     cl,[esi+1Bh]
  205.         stos    dword [edi]
  206.         mov     eax,edx
  207.         stos    dword [edi]
  208.         mov     eax,[esi+10h]
  209.         stos    dword [edi]
  210.         mov     eax,[esi+14h]
  211.         test    eax,eax
  212.         jz      base_symbol_for_line_ok
  213.         cmp     eax,[symbols_stream]
  214.         mov     eax,[eax+4]
  215.         jae     base_symbol_for_line_ok
  216.         xor     eax,eax
  217.       base_symbol_for_line_ok:
  218.         stos    dword [edi]
  219.         mov     eax,[esi+18h]
  220.         and     eax,01FFFFh
  221.         stos    dword [edi]
  222.         mov     [edi-1],cl
  223.         cmp     edi,[display_buffer]
  224.         jae     out_of_memory
  225.         mov     eax,edi
  226.         sub     eax,1Ch
  227.         sub     eax,ebp
  228.         mov     [esi],eax
  229.         jmp     make_lines_dump
  230.       lines_dump_ok:
  231.         mov     edx,edi
  232.         mov     eax,[current_offset]
  233.         sub     eax,[code_start]
  234.         add     eax,[headers_size]
  235.         stos    dword [edi]
  236.         mov     ecx,edi
  237.         sub     ecx,ebx
  238.         sub     ecx,[ebx-40h+14h]
  239.         mov     [ebx-40h+2Ch],ecx
  240.         add     ecx,[ebx-40h+28h]
  241.         mov     [ebx-40h+30h],ecx
  242.         add     ecx,[ebx-40h+34h]
  243.         mov     [ebx-40h+38h],ecx
  244.       find_inexisting_offsets:
  245.         sub     edx,1Ch
  246.         cmp     edx,ebp
  247.         jb      write_symbols
  248.         test    byte [edx+1Ah],1
  249.         jnz     find_inexisting_offsets
  250.         cmp     eax,[edx]
  251.         jb      correct_inexisting_offset
  252.         mov     eax,[edx]
  253.         jmp     find_inexisting_offsets
  254.       correct_inexisting_offset:
  255.         and     dword [edx],0
  256.         or      byte [edx+1Ah],2
  257.         jmp     find_inexisting_offsets
  258.       write_symbols:
  259.         mov     edx,[symbols_file]
  260.         call    create
  261.         jc      write_failed
  262.         mov     edx,[code_start]
  263.         mov     ecx,[edx+14h]
  264.         add     ecx,40h
  265.         call    write
  266.         jc      write_failed
  267.         mov     edx,[display_buffer]
  268.         mov     ecx,[memory_end]
  269.         sub     ecx,[labels_list]
  270.         call    write
  271.         jc      write_failed
  272.         mov     edx,[memory_start]
  273.         mov     ecx,[source_start]
  274.         sub     ecx,edx
  275.         call    write
  276.         jc      write_failed
  277.         mov     edx,ebp
  278.         mov     ecx,edi
  279.         sub     ecx,edx
  280.         call    write
  281.         jc      write_failed
  282.         mov     edx,[free_additional_memory]
  283.         mov     ecx,[number_of_sections]
  284.         shl     ecx,2
  285.         call    write
  286.         jc      write_failed
  287.         mov     esi,[labels_list]
  288.         mov     edi,[memory_start]
  289.       make_references_dump:
  290.         cmp     esi,[display_buffer]
  291.         je      references_dump_ok
  292.         mov     eax,[esi-4]
  293.         mov     ecx,[esi-8]
  294.         sub     esi,8
  295.         sub     esi,ecx
  296.         cmp     eax,2
  297.         je      dump_reference
  298.         cmp     eax,1
  299.         jne     make_references_dump
  300.         mov     edx,[esi]
  301.         jmp     make_references_dump
  302.       dump_reference:
  303.         mov     eax,[memory_end]
  304.         sub     eax,[esi]
  305.         sub     eax,LABEL_STRUCTURE_SIZE
  306.         stosd
  307.         mov     eax,edx
  308.         stosd
  309.         cmp     edi,[display_buffer]
  310.         jb      make_references_dump
  311.         jmp     out_of_memory
  312.       references_dump_ok:
  313.         mov     edx,[memory_start]
  314.         mov     ecx,edi
  315.         sub     ecx,edx
  316.         call    write
  317.         jc      write_failed
  318.         call    close
  319.         ret
  320.       setup_dump_header:
  321.         xor     eax,eax
  322.         mov     ecx,40h shr 2
  323.         rep     stos dword [edi]
  324.         mov     ebx,edi
  325.         mov     dword [ebx-40h],'fas'+1Ah shl 24
  326.         mov     dword [ebx-40h+4],VERSION_MAJOR + VERSION_MINOR shl 8 + 40h shl 16
  327.         mov     dword [ebx-40h+10h],40h
  328.         ret
  329. prepare_preprocessed_source:
  330.         mov     esi,[memory_start]
  331.         mov     ebp,[source_start]
  332.         test    ebp,ebp
  333.         jnz     prepare_preprocessed_line
  334.         mov     ebp,[current_line]
  335.         inc     ebp
  336.       prepare_preprocessed_line:
  337.         cmp     esi,ebp
  338.         jae     preprocessed_source_ok
  339.         mov     eax,[memory_start]
  340.         mov     edx,[input_file]
  341.         cmp     [esi],edx
  342.         jne     line_not_from_main_input
  343.         mov     [esi],eax
  344.       line_not_from_main_input:
  345.         sub     [esi],eax
  346.         test    byte [esi+7],1 shl 7
  347.         jz      prepare_next_preprocessed_line
  348.         sub     [esi+8],eax
  349.         sub     [esi+12],eax
  350.       prepare_next_preprocessed_line:
  351.         call    skip_preprocessed_line
  352.         jmp     prepare_preprocessed_line
  353.       preprocessed_source_ok:
  354.         ret
  355.       skip_preprocessed_line:
  356.         add     esi,16
  357.       skip_preprocessed_line_content:
  358.         lods    byte [esi]
  359.         cmp     al,1Ah
  360.         je      skip_preprocessed_symbol
  361.         cmp     al,3Bh
  362.         je      skip_preprocessed_symbol
  363.         cmp     al,22h
  364.         je      skip_preprocessed_string
  365.         or      al,al
  366.         jnz     skip_preprocessed_line_content
  367.         ret
  368.       skip_preprocessed_string:
  369.         lods    dword [esi]
  370.         add     esi,eax
  371.         jmp     skip_preprocessed_line_content
  372.       skip_preprocessed_symbol:
  373.         lods    byte [esi]
  374.         movzx   eax,al
  375.         add     esi,eax
  376.         jmp     skip_preprocessed_line_content
  377. restore_preprocessed_source:
  378.         mov     esi,[memory_start]
  379.         mov     ebp,[source_start]
  380.         test    ebp,ebp
  381.         jnz     restore_preprocessed_line
  382.         mov     ebp,[current_line]
  383.         inc     ebp
  384.       restore_preprocessed_line:
  385.         cmp     esi,ebp
  386.         jae     preprocessed_source_restored
  387.         mov     eax,[memory_start]
  388.         add     [esi],eax
  389.         cmp     [esi],eax
  390.         jne     preprocessed_line_source_restored
  391.         mov     edx,[input_file]
  392.         mov     [esi],edx
  393.       preprocessed_line_source_restored:
  394.         test    byte [esi+7],1 shl 7
  395.         jz      restore_next_preprocessed_line
  396.         add     [esi+8],eax
  397.         add     [esi+12],eax
  398.       restore_next_preprocessed_line:
  399.         call    skip_preprocessed_line
  400.         jmp     restore_preprocessed_line
  401.       preprocessed_source_restored:
  402.         ret
  403. dump_preprocessed_source:
  404.         mov     edi,[free_additional_memory]
  405.         call    setup_dump_header
  406.         mov     esi,[input_file]
  407.         call    copy_asciiz
  408.         cmp     edi,[additional_memory_end]
  409.         jae     out_of_memory
  410.         mov     eax,edi
  411.         sub     eax,ebx
  412.         dec     eax
  413.         mov     [ebx-40h+0Ch],eax
  414.         mov     eax,edi
  415.         sub     eax,ebx
  416.         mov     [ebx-40h+14h],eax
  417.         add     eax,40h
  418.         mov     [ebx-40h+20h],eax
  419.         call    prepare_preprocessed_source
  420.         sub     esi,[memory_start]
  421.         mov     [ebx-40h+24h],esi
  422.         mov     edx,[symbols_file]
  423.         call    create
  424.         jc      write_failed
  425.         mov     edx,[free_additional_memory]
  426.         mov     ecx,[edx+14h]
  427.         add     ecx,40h
  428.         call    write
  429.         jc      write_failed
  430.         mov     edx,[memory_start]
  431.         mov     ecx,esi
  432.         call    write
  433.         jc      write_failed
  434.         call    close
  435.         ret