Subversion Repositories Kolibri OS

Rev

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

  1. ;-----------------------------------------------------------------------------
  2. proc mem.Alloc size ;/////////////////////////////////////////////////////////
  3. ;-----------------------------------------------------------------------------
  4.         push    ebx ecx
  5.         mov     eax,[size]
  6.         lea     ecx,[eax+4+4095]
  7.         and     ecx,not 4095
  8.         mcall   68,12
  9.         add     ecx,-4
  10.         mov     [eax],ecx
  11.         add     eax,4
  12.         pop     ecx ebx
  13.         ret
  14. endp
  15.  
  16. ;-----------------------------------------------------------------------------
  17. proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
  18. ;-----------------------------------------------------------------------------
  19.         push    ebx ecx esi edi eax
  20.         mov     eax,[mptr]
  21.         mov     ebx,[size]
  22.         or      eax,eax
  23.         jz      @f
  24.         lea     ecx,[ebx+4+4095]
  25.         and     ecx,not 4095
  26.         add     ecx,-4
  27.         cmp     ecx,[eax-4]
  28.         je      .exit
  29.     @@: mov     eax,ebx
  30.         call    mem.Alloc
  31.         xchg    eax,[esp]
  32.         or      eax,eax
  33.         jz      .exit
  34.         mov     esi,eax
  35.         xchg    eax,[esp]
  36.         mov     edi,eax
  37.         mov     ecx,[esi-4]
  38.         cmp     ecx,[edi-4]
  39.         jbe     @f
  40.         mov     ecx,[edi-4]
  41.     @@: add     ecx,3
  42.         shr     ecx,2
  43.         cld
  44.         rep     movsd
  45.         xchg    eax,[esp]
  46.         call    mem.Free
  47.   .exit:
  48.         pop     eax edi esi ecx ebx
  49.         ret
  50. endp
  51.  
  52. ;-----------------------------------------------------------------------------
  53. proc mem.Free mptr ;//////////////////////////////////////////////////////////
  54. ;-----------------------------------------------------------------------------
  55.         mov     eax,[mptr]
  56.         or      eax,eax
  57.         jz      @f
  58.         push    ebx ecx
  59.         lea     ecx,[eax-4]
  60.         mcall   68,13
  61.         pop     ecx ebx
  62.     @@: ret
  63. endp
  64.  
  65.  
  66. proc dll.Load, import_table:dword
  67.                 mov     esi,[import_table]
  68.   .next_lib:    mov     edx,[esi]
  69.                 or      edx,edx
  70.                 jz      .exit
  71.                 push    esi
  72.                 mov     esi,[esi+4]
  73.                 mov     edi,s_libdir.fname
  74.             @@: lodsb
  75.                 stosb
  76.                 or      al,al
  77.                 jnz     @b
  78.                 mcall   68,19,s_libdir
  79.                 or      eax,eax
  80.                 jz      .fail
  81.                 stdcall dll.Link,eax,edx
  82.                 stdcall dll.Init,[eax+4]
  83.                 pop     esi
  84.                 add     esi,8
  85.                 jmp     .next_lib
  86.   .exit:        xor     eax,eax
  87.                 ret
  88.   .fail:        add     esp,4
  89.                 xor     eax,eax
  90.                 inc     eax
  91.                 ret
  92. endp
  93.  
  94. proc dll.Link, exp:dword,imp:dword
  95.                 push    eax
  96.                 mov     esi,[imp]
  97.                 test    esi,esi
  98.                 jz      .done
  99.   .next:        lodsd
  100.                 test    eax,eax
  101.                 jz      .done
  102.                 stdcall dll.GetProcAddress,[exp],eax
  103.                 or      eax,eax
  104.                 jz      @f
  105.                 mov     [esi-4],eax
  106.                 jmp     .next
  107.             @@: mov     dword[esp],0
  108.   .done:        pop     eax
  109.                 ret
  110. endp
  111.  
  112. proc dll.Init, dllentry:dword
  113.                 pushad
  114.                 mov     eax,mem.Alloc
  115.                 mov     ebx,mem.Free
  116.                 mov     ecx,mem.ReAlloc
  117.                 mov     edx,dll.Load
  118.                 stdcall [dllentry]
  119.                 popad
  120.                 ret
  121. endp
  122.  
  123. proc dll.GetProcAddress, exp:dword,sz_name:dword
  124.                 mov     edx,[exp]
  125.                 xor     eax,eax
  126.   .next:        or      edx,edx
  127.                 jz      .end
  128.                 cmp     dword[edx],0
  129.                 jz      .end
  130.                 stdcall strcmp,[edx],[sz_name]
  131.                 test    eax,eax
  132.                 jz      .ok
  133.                 add     edx,8
  134.                 jmp     .next
  135.   .ok:          mov     eax,[edx+4]
  136.   .end:         ret
  137. endp
  138.  
  139. proc strcmp, str1:dword,str2:dword
  140.                 push    esi edi
  141.                 mov     esi,[str1]
  142.                 mov     edi,[str2]
  143.                 xor     eax,eax
  144.             @@: lodsb
  145.                 scasb
  146.                 jne     .fail
  147.                 or      al,al
  148.                 jnz     @b
  149.                 jmp     .ok
  150.   .fail:        or      eax,-1
  151.   .ok:          pop     edi esi
  152.                 ret
  153. endp
  154.  
  155. s_libdir:
  156.   db '/sys/lib/'
  157.   .fname rb 32
  158.