Subversion Repositories Kolibri OS

Rev

Rev 4888 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;;;;;;;;;;;;;;;;;;;;;;;; Working with program symbols ;;;;;;;;;;;;;;;;;;;;;;;;
  3. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  4.  
  5. include 'sort.inc'
  6.  
  7. ; compare proc for sorter
  8. compare:
  9.         cmpsd
  10.         jnz     @f
  11.         cmp     esi, edi
  12.  
  13.   @@:
  14.         ret
  15.  
  16. ; compare proc for sorter 2
  17. compare2:
  18.         cmpsd
  19.  
  20.   @@:
  21.         cmpsb
  22.         jnz     @f
  23.         cmp     byte [esi-1], 0
  24.         jnz     @b
  25.         cmp     esi, edi
  26.  
  27.   @@:
  28.         ret
  29.  
  30. free_symbols:
  31.         mov     ecx, [symbols]
  32.         jecxz   @f
  33.         mcall   68, 13
  34.         and     [symbols], 0
  35.         and     [num_symbols], 0
  36.  
  37.   @@:
  38.         ret
  39.  
  40.  
  41. ;-----------------------------------------------------------------------------
  42. ;                        Load symbols event
  43.  
  44. OnLoadSymbols.fileerr:
  45.         test    ebp, ebp
  46.         jz      @f
  47.         mcall   68, 13, edi
  48.         ret
  49.  
  50.   @@:
  51.         push    eax
  52.         mcall   68, 13, edi
  53.         mov     esi, aCannotLoadFile
  54.         call    put_message_nodraw
  55.         pop     eax
  56.         cmp     eax, 0x20
  57.         jae     .unk
  58.         mov     esi, [load_err_msgs + eax*4]
  59.         test    esi, esi
  60.         jnz     put_message
  61.  
  62.   .unk:
  63.         mov     esi, unk_err_msg2
  64.         jmp     put_message
  65.  
  66.  
  67. OnLoadSymbols:
  68.         xor     ebp, ebp
  69. ; load input file
  70.         mov     esi, [curarg]
  71.         call    free_symbols
  72.  
  73.   .silent:
  74. ; esi = ptr to symbols filename
  75.         xor     edi, edi
  76.         cmp     [num_symbols], edi              ; Any previously loaded symbols?
  77.         je      .loadfile
  78.         call    free_symbols                    ; Yep, free them
  79.  
  80.   .loadfile:
  81.         mov     ebx, fn70_attr_block            ; Get file attributes
  82.         mov     [ebx+21], esi
  83.         mcall   70
  84.         test    eax, eax
  85.         jnz     .fileerr
  86.         cmp     dword [fileattr+36], edi        ; Is upper dword of filesize larger then 0?
  87.         jnz     .memerr
  88.         mov     ecx, dword [fileattr+32]        ; Lower dword of filesize
  89.         mcall   68, 12                          ; allocate the memory
  90.         test    eax, eax
  91.         jz      .memerr
  92.         mov     edi, eax
  93.         mov     ebx, fn70_read_block
  94.         mov     [ebx+12], ecx
  95.         mov     [ebx+16], edi
  96.         mov     [ebx+21], esi
  97.         mcall   70                              ; Read the file into the allocated buffer
  98.         test    eax, eax
  99.         jnz     .fileerr
  100.  
  101.  
  102. ; calculate memory requirements to load debug symbols
  103.  
  104.         lea     edx, [ecx+edi-1]                ; edx = EOF-1
  105.         mov     esi, edi
  106.         xor     ecx, ecx
  107.  
  108.         mov     [symbol_section], 1    ;;;;;
  109.  
  110.   .calcloop:
  111.         cmp     esi, edx
  112.         jae     .calcdone
  113.         cmp     byte[esi], ' '          ; skip spaces at the beginning of a line
  114.         jne     .not_space
  115.         inc     esi
  116.         jmp     .calcloop
  117.   .not_space:
  118.         cmp     byte[esi], '.'
  119.         jne     .not_section
  120.         inc     esi
  121.         mov     [symbol_section], 0
  122.         cmp     dword[esi], 'text'
  123.         jne     .skipline
  124.         inc     [symbol_section]
  125.         jmp     .skipline
  126.   .not_section:
  127.         cmp     [symbol_section], 0
  128.         je      .skipline
  129.  
  130.         cmp     word[esi], '0x'
  131.         jne     .skipline
  132.         inc     esi
  133.         inc     esi
  134.  
  135.   @@:
  136.         cmp     esi, edx
  137.         jae     .calcdone
  138.         lodsb
  139.         or      al, 20h
  140.         sub     al, '0'
  141.         cmp     al, 9
  142.         jbe     @b
  143.         sub     al, 'a'-'0'-10
  144.         cmp     al, 15
  145.         jbe     @b
  146.         dec     esi
  147.  
  148.   @@:
  149.         cmp     esi, edx
  150.         ja      .calcdone
  151.         lodsb
  152.         cmp     al, 20h
  153.         je      @b
  154.         jb      .calcloop
  155.         cmp     al, 9
  156.         jz      @b
  157.         add     ecx, 12+1
  158.         inc     [num_symbols]
  159.  
  160.   @@:
  161.         inc     ecx
  162.         cmp     esi, edx
  163.         ja      .calcdone
  164.         lodsb
  165.         cmp     al, 0xD
  166.         jz      .calcloop
  167.         cmp     al, 0xA
  168.         jz      .calcloop
  169.         jmp     @b
  170.  
  171.   .skipline:
  172.         cmp     esi, edx
  173.         jae     .calcdone
  174.         lodsb
  175.         cmp     al, 0xD
  176.         jz      .calcloop
  177.         cmp     al, 0xA
  178.         jz      .calcloop
  179.         jmp     .skipline
  180.  
  181.   .calcdone:
  182.  
  183. ; Allocate memory to place the debug symbols in
  184.  
  185.         mcall   68, 12
  186.         test    eax, eax
  187.         jnz     .memok
  188.         inc     ebx
  189.         mov     ecx, edi
  190.         mov     al, 68
  191.         mcall
  192.  
  193.   .memerr:
  194.         mov     esi, aNoMemory
  195.         jmp     put_message
  196.  
  197.   .memok:
  198.         mov     [symbols], eax
  199.         mov     ebx, eax
  200.         push    edi
  201.         mov     esi, edi
  202.         mov     edi, [num_symbols]
  203.         lea     ebp, [eax+edi*4]
  204.         lea     edi, [eax+edi*8]
  205.  
  206. ; Actual loading of the debug symbols
  207. ; esi->input, edx->EOF, ebx->ptrs, edi->names
  208.  
  209.         mov     [symbol_section], 1    ;;;;;
  210.  
  211.   .readloop:
  212.         cmp     esi, edx
  213.         jae     .readdone
  214.         cmp     byte[esi], ' '
  215.         jne     .not_space2
  216.         inc     esi
  217.         jmp     .readloop
  218.   .not_space2:
  219.         cmp     byte[esi], '.'
  220.         jne     .not_section2
  221.         inc     esi
  222.         mov     [symbol_section], 0
  223.         cmp     dword[esi], 'text'
  224.         jne     .readline
  225.         inc     [symbol_section]
  226.         jmp     .readline
  227.   .not_section2:
  228.         cmp     [symbol_section], 0
  229.         je      .readline
  230.  
  231.         cmp     word[esi], '0x'
  232.         jnz     .readline
  233.         inc     esi
  234.         inc     esi
  235.         xor     eax, eax
  236.         xor     ecx, ecx
  237.  
  238.   @@:
  239.         shl     ecx, 4
  240.         add     ecx, eax
  241.         cmp     esi, edx
  242.         jae     .readdone
  243.         lodsb
  244.         or      al, 20h
  245.         sub     al, '0'
  246.         cmp     al, 9
  247.         jbe     @b
  248.         sub     al, 'a'-'0'-10
  249.         cmp     al, 15
  250.         jbe     @b
  251.         dec     esi
  252.  
  253.   @@:
  254.         cmp     esi, edx
  255.         ja      .readdone
  256.         lodsb
  257.         cmp     al, 20h
  258.         jz      @b
  259.         jb      .readloop
  260.         cmp     al, 9
  261.         jz      @b
  262.         mov     dword [ebx], edi
  263.         add     ebx, 4
  264.         mov     dword [ebp], edi
  265.         add     ebp, 4
  266.         mov     dword [edi], ecx
  267.         add     edi, 4
  268.         stosb
  269.  
  270.   @@:
  271.         xor     eax, eax
  272.         stosb
  273.         cmp     esi, edx
  274.         ja      .readdone
  275.         lodsb
  276.         cmp     al, 0xD
  277.         jz      .readloop
  278.         cmp     al, 0xA
  279.         jz      .readloop
  280.         mov     byte [edi-1], al
  281.         jmp     @b
  282.  
  283.   .readline:
  284.         cmp     esi, edx
  285.         jae     .readdone
  286.         lodsb
  287.         cmp     al, 0xD
  288.         jz      .readloop
  289.         cmp     al, 0xA
  290.         jz      .readloop
  291.         jmp     .readline
  292.  
  293.   .readdone:
  294.         pop     ecx
  295.         mcall   68, 13
  296.         mov     ecx, [num_symbols]
  297.         mov     edx, [symbols]
  298.         mov     ebx, compare
  299.         call    sort
  300.         mov     ecx, [num_symbols]
  301.         lea     edx, [edx+ecx*4]
  302.         mov     ebx, compare2
  303.         call    sort
  304.         mov     esi, aSymbolsLoaded
  305.         call    put_message
  306.         jmp     draw_disasm.redraw
  307.  
  308. ;-----------------------------------------------------------------------------
  309. ;
  310. ; in: EAX = address
  311. ; out: ESI, CF
  312.  
  313. find_symbol:
  314.         cmp     [num_symbols], 0
  315.         jnz     @f
  316.  
  317.   .ret0:
  318.         xor     esi, esi
  319.         stc
  320.         ret
  321.  
  322.   @@:
  323.         push    ebx ecx edx
  324.         xor     edx, edx
  325.         mov     esi, [symbols]
  326.         mov     ecx, [num_symbols]
  327.         mov     ebx, [esi]
  328.         cmp     [ebx], eax
  329.         jz      .donez
  330.         jb      @f
  331.         pop     edx ecx ebx
  332.         jmp     .ret0
  333.  
  334.   @@:
  335.     ; invariant: symbols_addr[edx] < eax < symbols_addr[ecx]
  336.     ; TODO: add meaningful label names
  337.   .0:
  338.         push    edx
  339.  
  340.   .1:
  341.         add     edx, ecx
  342.         sar     edx, 1
  343.         cmp     edx, [esp]
  344.         jz      .done2
  345.         mov     ebx, [esi+edx*4]
  346.         cmp     [ebx], eax
  347.         jz      .done
  348.         ja      .2
  349.         mov     [esp], edx
  350.         jmp     .1
  351.  
  352.   .2:
  353.         mov     ecx, edx
  354.         pop     edx
  355.         jmp     .0
  356.  
  357.   .donecont:
  358.         dec     edx
  359.  
  360.   .done:
  361.         test    edx, edx
  362.         jz      @f
  363.         mov     ebx, [esi+edx*4-4]
  364.         cmp     [ebx], eax
  365.         jz      .donecont
  366.  
  367.   @@:
  368.         pop     ecx
  369.  
  370.   .donez:
  371.         mov     esi, [esi+edx*4]
  372.         add     esi, 4
  373.         pop     edx ecx ebx
  374.         clc
  375.         ret
  376.  
  377.   .done2:
  378.         lea     esi, [esi+edx*4]
  379.         pop     ecx edx ecx ebx
  380.         stc
  381.         ret
  382.  
  383. ;-----------------------------------------------------------------------------
  384. ;
  385. ; in: esi->name
  386. ; out: if found: CF = 0, EAX = value
  387. ;      otherwise CF = 1
  388. find_symbol_name:
  389.         cmp     [num_symbols], 0
  390.         jnz     @f
  391.  
  392.   .stc_ret:
  393.         stc
  394.         ret
  395.  
  396.   @@:
  397.         push    ebx ecx edx edi
  398.         push    -1
  399.         pop     edx
  400.         mov     ebx, [symbols]
  401.         mov     ecx, [num_symbols]
  402.         lea     ebx, [ebx+ecx*4]
  403.    
  404.     ; invariant: symbols_name[edx] < name < symbols_name[ecx]
  405.   .0:
  406.         push    edx
  407.  
  408.   .1:
  409.         add     edx, ecx
  410.         sar     edx, 1
  411.         cmp     edx, [esp]
  412.         jz      .done2
  413.         call    .cmp
  414.         jz      .done
  415.         jb      .2
  416.         mov     [esp], edx
  417.         jmp     .1
  418.  
  419.   .2:
  420.         mov     ecx, edx
  421.         pop     edx
  422.         jmp     .0
  423.  
  424.   .done:
  425.         pop     ecx
  426.  
  427.   .donez:
  428.         mov     eax, [ebx+edx*4]
  429.         mov     eax, [eax]
  430.         pop     edi edx ecx ebx
  431.         clc
  432.         ret
  433.  
  434.   .done2:
  435.         pop     edx edi edx ecx ebx
  436.         stc
  437.         ret
  438.  
  439.   .cmp:
  440.         mov     edi, [ebx+edx*4]
  441.         push    esi
  442.         add     edi, 4
  443.  
  444.   @@:
  445.         cmpsb
  446.         jnz     @f
  447.         cmp     byte [esi-1], 0
  448.         jnz     @b
  449.  
  450.   @@:
  451.         pop     esi
  452.         ret