Subversion Repositories Kolibri OS

Rev

Rev 8227 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
9908 Doczom 1
;-----------------------------------------------------------------------------
2
; load one or more DLL file in COFF format and try to import functions by our list
3
; if first function in import list begins with 'lib_', call it as DLL initialization
4
; return eax = 1 as fail, if anyone of .obj file not found in /sys/lib
5
; return 0 if all fine, but 0 not garantees in succesfull import - see dll.Link comment
6
; dirties all registers! eax, ebx, ecx, edx, esi, edi
7
proc dll.Load, import_table:dword
8
        mov     esi, [import_table]
9
  .next_lib:
10
        mov     edx, [esi]
11
        or      edx, edx
12
        jz      .exit
13
        push    esi
14
        mov     esi, [esi + 4]
15
 
16
        mov     edi, esi
17
        cmp     byte[esi], '/'
18
        jz      .load_lib
19
 
20
        mov     edi, s_libdir.fname
21
    @@:
22
        lodsb
23
        stosb
24
        or      al, al
25
        jnz     @b
26
 
27
        mov     edi, s_libdir
28
  .load_lib:
29
        mcall   68, 19, edi ;s_libdir
30
        or      eax, eax
31
        jz      .fail
32
        stdcall dll.Link, eax, edx
33
        push    eax
34
        mov     eax, [eax]
35
        cmp     dword[eax], 'lib_'
36
        pop     eax
37
        jnz     @f
38
        stdcall dll.Init, [eax + 4]
39
    @@:
40
        pop     esi
41
        add     esi, 8
42
        jmp     .next_lib
43
  .exit:
44
        xor     eax, eax
45
        ret
46
  .fail:
47
        add     esp, 4
48
        xor     eax, eax
49
        inc     eax
50
        ret
51
endp
52
;-----------------------------------------------------------------------------
53
; scans dll export table for a functions we want to import
54
; break scan on first unresolved import
55
; no return value
56
proc dll.Link, exp:dword, imp:dword
57
        push    eax
58
        mov     esi, [imp]
59
        test    esi, esi
60
        jz      .done
61
  .next:
62
        lodsd
63
        test    eax, eax
64
        jz      .done
65
        stdcall dll.GetProcAddress, [exp], eax
66
        or      eax, eax
67
        jz      @f
68
        mov     [esi - 4], eax
69
        jmp     .next
70
    @@:
71
        mov     dword[esp], 0
72
  .done:
73
        pop     eax
74
        ret
75
endp
76
;-----------------------------------------------------------------------------
77
; calls lib_init with predefined parameters
78
; no return value
79
proc dll.Init, dllentry:dword
80
        pushad
81
        mov     eax, mem.Alloc
82
        mov     ebx, mem.Free
83
        mov     ecx, mem.ReAlloc
84
        mov     edx, dll.Load
85
        stdcall [dllentry]
86
        popad
87
        ret
88
endp
89
;-----------------------------------------------------------------------------
90
; scans export table for a sz_name function
91
; returns in eax function address or 0 if not found
92
proc dll.GetProcAddress, exp:dword, sz_name:dword
93
        mov     edx, [exp]
94
        xor     eax, eax
95
  .next:
96
        or      edx, edx
97
        jz      .end
98
        cmp     dword[edx], 0
99
        jz      .end
100
        stdcall strcmp, [edx], [sz_name]
101
        test    eax, eax
102
        jz      .ok
103
        add     edx, 8
104
        jmp     .next
105
  .ok:
106
        mov     eax, [edx + 4]
107
  .end:
108
        cmp eax, -1
109
        jnz @f
110
        xor eax, eax
111
  @@:
112
        ret
113
endp
114
;-----------------------------------------------------------------------------
115
; compares strings
116
; returns eax = 0 if equal, -1 otherwise
117
proc strcmp, str1:dword, str2:dword
118
        push    esi edi
119
        mov     esi, [str1]
120
        mov     edi, [str2]
121
        xor     eax, eax
122
    @@:
123
        lodsb
124
        scasb
125
        jne     .fail
126
        or      al, al
127
        jnz     @b
128
        jmp     .ok
129
  .fail:
130
        or      eax, -1
131
  .ok:
132
        pop     edi esi
133
        ret
134
endp
135
;-----------------------------------------------------------------------------
136
if defined dll.Load
137
s_libdir:
138
  db '/sys/lib/'
139
  .fname rb 32
140
end if
141
;-----------------------------------------------------------------------------
142
proc mem.Alloc, size
143
        push    ebx ecx
144
        mov     ecx, [size]
145
        mcall   68, 12
146
        pop     ecx ebx
147
        ret
148
endp
149
;-----------------------------------------------------------------------------
150
proc mem.ReAlloc, mptr, size
151
        push    ebx ecx edx
152
        mov     ecx, [size]
153
        mov     edx, [mptr]
154
        mcall   68, 20
155
        pop     edx ecx ebx
156
        ret
157
endp
158
;-----------------------------------------------------------------------------
159
proc mem.Free, mptr
160
        push    ebx ecx
161
        mov     ecx,[mptr]
162
        mcall   68, 13
163
        pop     ecx ebx
164
        ret
165
endp
166
;-----------------------------------------------------------------------------