Subversion Repositories Kolibri OS

Rev

Rev 8227 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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