Subversion Repositories Kolibri OS

Rev

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

  1. include '../proc32.inc'
  2.  
  3. format MS COFF
  4.  
  5. public _load_libconsole
  6.  
  7. public _con_init@20
  8. public _con_exit@4
  9. public _con_get_flags
  10. public _con_set_flags@4
  11. public _con_cls
  12. public _con_write_string@8
  13. public _con_getch2@0
  14.  
  15. section '.text' align 16
  16.  
  17.  
  18. ;void* __fastcall getprocaddr(export, name)
  19. align 4
  20. getprocaddress:
  21.         push    esi
  22.         push    edi
  23.  
  24.         xor     eax, eax
  25.         test    ecx, ecx        ; If hlib = 0 then goto .end
  26.         jz      .end
  27. .next:
  28.         cmp     [ecx], dword 0  ; If end of export table then goto .end
  29.         jz      .end
  30.  
  31.         xor     eax, eax
  32.         mov     esi, [ecx]
  33.         mov     edi, edx        ; name
  34. .next_:
  35.         lodsb
  36.         scasb
  37.         jne     .fail
  38.         or      al, al
  39.         jnz     .next_
  40.         jmp     .ok
  41. .fail:
  42.         add     ecx, 8
  43.         jmp     .next
  44. .ok:
  45.         mov eax, [ecx + 4]      ; return address
  46. .end:
  47.         pop     edi
  48.         pop     esi
  49.         ret
  50.  
  51.  
  52. ;void fastcall dll_link(export, import)
  53.  
  54. align 4
  55. dll_link:
  56.         push    esi
  57.         push    ecx
  58.         mov     esi, edx
  59.         test    esi, esi
  60.         jz      .done
  61. .next:
  62.         mov     edx, [esi]
  63.         test    edx, edx
  64.         jz      .done
  65.         mov     ecx, [esp]
  66.         call    getprocaddress
  67.         test    eax, eax
  68.         jz      .done
  69.         mov     [esi], eax
  70.         add     esi, 4
  71.         jmp     .next
  72. .done:
  73.         pop     ecx
  74.         pop     esi
  75.         ret
  76.  
  77. align 4
  78. dll_load:
  79.         push    ebp
  80.         push    ebx
  81.         push    esi
  82.         push    edi
  83.  
  84.         mov     ebp, [esp+20]
  85. .next_lib:
  86.         mov     edx, [ebp]
  87.         test    edx, edx
  88.         jz      .exit
  89.  
  90.         mov     esi, [ebp+4]
  91.         mov     edi, s_libdir.fname
  92. @@:
  93.         lodsb
  94.         stosb
  95.         test  al, al
  96.         jnz @b
  97.  
  98.         mov     eax, 68
  99.         mov     ebx, 19
  100.         mov     ecx, s_libdir
  101.         int     0x40
  102.         test    eax, eax
  103.         jz      .fail
  104.  
  105.         mov     ecx, eax
  106.         call    dll_link
  107.         mov     eax, [ecx]
  108.         cmp     dword[eax], 'lib_'
  109.         jnz     @f
  110.  
  111.         mov     esi, [ecx+4]
  112.  
  113.         pushad
  114.         mov     eax, mem.Alloc
  115.         mov     ebx, mem.Free
  116.         mov     ecx, mem.ReAlloc
  117.         mov     edx, dll_load
  118.         call    esi
  119.         popad
  120. @@:
  121.         add     ebp, 8
  122.         jmp     .next_lib
  123. .exit:
  124.         pop     edi
  125.         pop     esi
  126.         pop     ebx
  127.         pop     ebp
  128.         xor     eax, eax
  129.         ret 4
  130. .fail:
  131.         pop     edi
  132.         pop     esi
  133.         pop     ebx
  134.         pop     ebp
  135.         inc     eax
  136.         ret 4
  137.  
  138. align 4
  139. _load_libconsole:
  140.         push    ebx
  141.         mov     eax, 40
  142.         mov     ebx, 1 shl 8
  143.         int     0x40
  144.         pop     ebx
  145.  
  146.         push    @IMPORT
  147.         call    dll_load
  148.         test    eax, eax
  149.         jnz     .fail
  150.         push    1
  151.         call    [con_start]
  152.         xor     eax, eax
  153. .fail:
  154.         ret
  155.  
  156. align 4
  157. _con_init@20:
  158.         jmp     [con_init]
  159.  
  160. align 4
  161. _con_exit@4:
  162.         jmp     [con_exit]
  163.  
  164. align 4
  165. _con_write_string@8:
  166.         jmp     [con_write_string]
  167.  
  168. _con_getch2@0:
  169.         jmp     [con_getch2]
  170.  
  171. _con_get_flags:
  172. _con_set_flags@4:
  173. _con_cls:
  174.         ret
  175.  
  176.  
  177. proc mem.Alloc, size
  178.         push    ebx ecx
  179.         mov     ecx, [size]
  180.         mov     eax, 68
  181.         mov     ebx, 12
  182.         int     0x40
  183.         pop     ecx ebx
  184.         ret
  185. endp
  186. ;-----------------------------------------------------------------------------
  187. proc mem.ReAlloc, mptr, size
  188.         push    ebx ecx edx
  189.         mov     ecx, [size]
  190.         test    ecx, ecx
  191.         jz      @f
  192. @@:
  193.         mov     edx, [mptr]
  194.         test    edx, edx
  195.         jz      @f
  196. @@:
  197.         mov     eax, 68
  198.         mov     ebx, 20
  199.         int     0x40
  200.         test    eax, eax
  201.         jz  @f
  202. @@:
  203.         pop edx ecx ebx
  204.         ret
  205. endp
  206. ;-----------------------------------------------------------------------------
  207. proc mem.Free, mptr
  208.         push    ebx ecx
  209.         mov     ecx,[mptr]
  210.         test    ecx,ecx
  211.         jz  @f
  212. @@:
  213.         mov     eax, 68
  214.         mov     ebx, 13
  215.         int     0x40
  216.         pop ecx ebx
  217.         ret
  218. endp
  219.  
  220. ;section '.ctors' align 4
  221. ;align 4
  222. ;dd _load_libconsole
  223.  
  224. section '.data' align 16
  225.  
  226. ; -------------------------
  227. macro library [lname,fname]
  228. {
  229.   forward
  230.     dd __#lname#_library_table__,__#lname#_library_name__
  231.   common
  232.     dd 0
  233.   forward
  234.     align 4
  235.     __#lname#_library_name__ db fname,0
  236. }
  237.  
  238. macro import lname,[name,sname]
  239. {
  240.   common
  241.     align 4
  242.     __#lname#_library_table__:
  243.   forward
  244.     if used name
  245.       name dd __#name#_import_name__
  246.     end if
  247.   common
  248.     dd 0
  249.   forward
  250.     if used name
  251.       align 4
  252.       __#name#_import_name__ db sname,0
  253.     end if
  254. }
  255.  
  256. align   4
  257. @IMPORT:
  258.  
  259. library console,        'console.obj'
  260.  
  261. import  console,                            \
  262.         con_start,      'START',            \
  263.         con_init,       'con_init',         \
  264.         con_exit,       'con_exit',         \
  265.         con_gets,       'con_gets',         \
  266.         con_cls,        'con_cls',          \
  267.         con_getch2,     'con_getch2',       \
  268.         con_set_cursor_pos, 'con_set_cursor_pos',\
  269.         con_write_string, 'con_write_string',\
  270.         con_get_flags,  'con_get_flags',    \
  271.         con_set_flags,  'con_set_flags'
  272.  
  273. s_libdir:
  274.   db '/sys/lib/'
  275.   .fname rb 32
  276.