Subversion Repositories Kolibri OS

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
4224 sourcerer 1
include 'proc32.inc'
2
 
3
macro __mov reg,a,b {       ; mike.dld
4
 if (~a eq)&(~b eq)
5
   mpack reg,a,b
6
 else if (~a eq)&(b eq)
7
   mov reg,a
8
 end if
9
}
10
 
11
macro mcall a,b,c,d,e,f {   ; mike.dld, updated by Ghost for Fast System Calls
12
 __mov eax,a
13
 __mov ebx,b
14
 __mov ecx,c
15
 __mov edx,d
16
 __mov esi,e
17
 __mov edi,f
18
        int     0x40
19
}
20
 
21
 
22
format ELF
23
section '.text' executable
24
 
25
public dll_load
26
public mem_Free
27
public mem_Alloc
28
public mem_ReAlloc
29
 
30
;-----------------------------------------------------------------------------
31
proc dll_load, import_table:dword
32
	mov	esi, [import_table]
33
  .next_lib:
34
	mov	edx, [esi]
35
	or	edx, edx
36
	jz	.exit
37
	push	esi
38
	mov	esi, [esi + 4]
39
	mov	edi, s_libdir.fname
40
    @@:
41
	lodsb
42
	stosb
43
	or	al, al
44
	jnz	@b
45
	mcall	68, 19, s_libdir
46
	or	eax, eax
47
	jz	.fail
48
	stdcall	dll.Link, eax, edx
49
	push	eax
50
	mov	eax, [eax]
51
	cmp	dword[eax], 'lib_'
52
	pop	eax
53
	jnz	@f
54
	stdcall	dll.Init, [eax + 4]
55
    @@:
56
	pop	esi
57
	add	esi, 8
58
	jmp	.next_lib
59
  .exit:
60
	xor	eax, eax
61
	ret
62
  .fail:
63
	add	esp, 4
64
	xor	eax, eax
65
	inc	eax
66
	ret
67
endp
68
;-----------------------------------------------------------------------------
69
proc dll.Link, exp:dword, imp:dword
70
	push	eax
71
	mov	esi, [imp]
72
	test	esi, esi
73
	jz	.done
74
  .next:
75
	lodsd
76
	test	eax, eax
77
	jz	.done
78
	stdcall	dll.GetProcAddress, [exp], eax
79
	or	eax, eax
80
	jz	@f
81
	mov	[esi - 4], eax
82
	jmp	.next
83
    @@:
84
	mov	dword[esp], 0
85
  .done:
86
	pop	eax
87
	ret
88
endp
89
;-----------------------------------------------------------------------------
90
proc dll.Init, dllentry:dword
91
	pushad
92
	mov	eax, mem_Alloc
93
	mov	ebx, mem_Free
94
	mov	ecx, mem_ReAlloc
95
	mov	edx, dll_load
96
	stdcall	[dllentry]
97
	popad
98
	ret
99
endp
100
;-----------------------------------------------------------------------------
101
proc dll.GetProcAddress, exp:dword, sz_name:dword
102
	mov	edx, [exp]
103
	xor	eax, eax
104
  .next:
105
	or	edx, edx
106
	jz	.end
107
	cmp	dword[edx], 0
108
	jz	.end
109
	stdcall	strcmp, [edx], [sz_name]
110
	test	eax, eax
111
	jz	.ok
112
	add	edx, 8
113
	jmp	.next
114
  .ok:
115
	mov	eax, [edx + 4]
116
  .end:
117
	ret
118
endp
119
;-----------------------------------------------------------------------------
120
proc strcmp, str1:dword, str2:dword
121
	push	esi edi
122
	mov	esi, [str1]
123
	mov	edi, [str2]
124
	xor	eax, eax
125
    @@:
126
	lodsb
127
	scasb
128
	jne	.fail
129
	or	al, al
130
	jnz	@b
131
	jmp	.ok
132
  .fail:
133
	or	eax, -1
134
  .ok:
135
	pop	edi esi
136
	ret
137
endp
138
;-----------------------------------------------------------------------------
139
s_libdir:
140
  db '/sys/lib/'
141
  .fname rb 32
142
;-----------------------------------------------------------------------------
143
proc mem_Alloc, size
144
	push	ebx ecx
145
	mov	ecx, [size]
146
	mcall	68, 12
147
	pop	ecx ebx
148
	ret
149
endp
150
;-----------------------------------------------------------------------------
151
proc mem_ReAlloc, mptr, size
152
	push	ebx ecx edx
153
	mov	ecx, [size]
154
	or	ecx, ecx
155
	jz	@f
156
    @@:
157
	mov	edx, [mptr]
158
	or	edx, edx
159
	jz	@f
160
    @@:
161
	mcall	68, 20
162
	or	eax, eax
163
	jz	@f
164
    @@:
165
	pop	edx ecx ebx
166
	ret
167
endp
168
;-----------------------------------------------------------------------------
169
proc mem_Free, mptr
170
	push	ebx ecx
171
	mov	ecx,[mptr]
172
	or	ecx,ecx
173
	jz	@f
174
    @@:
175
	mcall	68, 13
176
	pop	ecx ebx
177
	ret
178
endp
179
;-----------------------------------------------------------------------------