Subversion Repositories Kolibri OS

Rev

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

  1.  
  2. include 'proc32.inc'
  3.  
  4. DLL_ENTRY equ 1
  5. DLL_EXIT  equ -1
  6. REQ_DLL_VER equ 3
  7.  
  8. use32
  9.         db      'MENUET01'
  10.         dd      1
  11.         dd      start
  12.         dd      i_end
  13.         dd      mem
  14.         dd      mem
  15.         dd      0
  16.         dd      0
  17.  
  18. start:
  19.         stdcall load_dll_and_import, dllname, imports
  20.         test    eax, eax
  21.         jz      exit
  22.  
  23. ; check version
  24.         cmp     word [dll_ver], REQ_DLL_VER
  25.         jb      exit
  26.         cmp     word [dll_ver+2], REQ_DLL_VER
  27.         ja      exit
  28.         push    DLL_ENTRY
  29.         call    [dll_start]
  30.  
  31. ; yes! Now do some work (gets() demo in this case).
  32.  
  33.         push    caption
  34.         push    -1
  35.         push    -1
  36.         push    -1
  37.         push    -1
  38.         call    [con_init]
  39.  
  40. ; C-equivalent of the following code:
  41. ; for (;;)
  42. ; {
  43. ;   con_write_asciiz("Enter string (empty for exit): ");
  44. ;   con_gets(s,256);
  45. ;   if (s[0] == '\n') break;
  46. ;   con_write_asciiz("You entered: ");
  47. ;   con_write_asciiz(s);
  48. ; }
  49. mainloop:
  50.         push    str1
  51.         call    [con_write_asciiz]
  52.         push    256
  53.         push    s
  54.         call    [con_gets]
  55.         cmp     [s], 10
  56.         jz      done
  57.         push    str2
  58.         call    [con_write_asciiz]
  59.         push    s
  60.         call    [con_write_asciiz]
  61.         jmp     mainloop
  62. done:
  63.         push    1
  64.         call    [con_exit]
  65. exit:
  66.         or      eax, -1
  67.         int     0x40
  68.  
  69. proc load_dll_and_import stdcall, _dllname:dword, _imports:dword
  70.         pushad
  71. ; load DLL
  72.         push    68
  73.         pop     eax
  74.         push    19
  75.         pop     ebx
  76.         mov     ecx, [_dllname]
  77.         int     0x40
  78.         test    eax, eax
  79.         jz      import_fail
  80.  
  81. ; initialize import
  82.         mov     edi, eax
  83.         mov     esi, [_imports]
  84. import_loop:
  85.         lodsd
  86.         test    eax, eax
  87.         jz      import_done
  88.         mov     edx, edi
  89. import_find:
  90.         mov     ebx, [edx]
  91.         test    ebx, ebx
  92.         jz      import_not_found
  93.         push    eax
  94. @@:
  95.         mov     cl, [eax]
  96.         cmp     cl, [ebx]
  97.         jnz     import_find_next
  98.         test    cl, cl
  99.         jz      import_found
  100.         inc     eax
  101.         inc     ebx
  102.         jmp     @b
  103. import_find_next:
  104.         pop     eax
  105.         add     edx, 8
  106.         jmp     import_find
  107. import_found:
  108.         pop     eax
  109.         mov     eax, [edx+4]
  110.         mov     [esi-4], eax
  111.         jmp     import_loop
  112. import_not_found:
  113. import_fail:
  114.         popad
  115.         xor     eax, eax
  116.         ret
  117. import_done:
  118.         popad
  119.         xor     eax, eax
  120.         inc     eax
  121.         ret
  122. endp
  123.  
  124. align 4
  125.  
  126. imports:
  127. dll_start          dd szStart
  128. dll_ver            dd szVersion
  129. con_init           dd szcon_init
  130. con_write_asciiz   dd szcon_write_asciiz
  131. con_exit           dd szcon_exit
  132. con_gets           dd szcon_gets
  133.                    dd 0
  134.  
  135. szStart            db 'START',0
  136. szVersion          db 'version',0
  137. szcon_init         db 'con_init',0
  138. szcon_write_asciiz db 'con_write_asciiz',0
  139. szcon_exit         db 'con_exit',0
  140. szcon_gets         db 'con_gets',0
  141.  
  142. dllname  db '/sys/lib/console.obj',0
  143.  
  144. caption            db 'Console test - gets()',0
  145. str1               db 'Enter string (empty for exit): ',0
  146. str2               db 'You entered: ',0
  147.  
  148. i_end:
  149.  
  150. s rb 256
  151.  
  152. align 4
  153. rb 2048 ; stack
  154. mem:
  155.