Subversion Repositories Kolibri OS

Rev

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

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