Rev 2465 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2465 | Rev 5565 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | ;============================================================================ |
8 | ;============================================================================ |
9 | ; |
9 | ; |
10 | ; External kernel dependencies (libraries) loading |
10 | ; External kernel dependencies (libraries) loading |
11 | ; |
11 | ; |
12 | ;============================================================================ |
12 | ;============================================================================ |
13 | 13 | ||
14 | $Revision: 2465 $ |
14 | $Revision: 5565 $ |
15 | 15 | ||
16 | if 0 |
16 | if 0 |
17 | ; The code currently does not work. Kill "if 0/end if" only after correcting |
17 | ; The code currently does not work. Kill "if 0/end if" only after correcting |
18 | ; to current kernel (dll.inc). |
18 | ; to current kernel (dll.inc). |
19 | macro library [name,fname] |
19 | macro library [name,fname] |
20 | { |
20 | { |
21 | forward |
21 | forward |
22 | dd __#name#_library_table__,__#name#_library_name__ |
22 | dd __#name#_library_table__,__#name#_library_name__ |
23 | common |
23 | common |
24 | dd 0 |
24 | dd 0 |
25 | forward |
25 | forward |
26 | __#name#_library_name__ db fname,0 |
26 | __#name#_library_name__ db fname,0 |
27 | } |
27 | } |
28 | 28 | ||
29 | macro import lname,[name,sname] |
29 | macro import lname,[name,sname] |
30 | { |
30 | { |
31 | common |
31 | common |
32 | align 4 |
32 | align 4 |
33 | __#lname#_library_table__: |
33 | __#lname#_library_table__: |
34 | forward |
34 | forward |
35 | name dd __#name#_import_name__ |
35 | name dd __#name#_import_name__ |
36 | common |
36 | common |
37 | dd 0 |
37 | dd 0 |
38 | forward |
38 | forward |
39 | __#name#_import_name__ db sname,0 |
39 | __#name#_import_name__ db sname,0 |
40 | } |
40 | } |
41 | 41 | ||
42 | macro export [name,sname] |
42 | macro export [name,sname] |
43 | { |
43 | { |
44 | align 4 |
44 | align 4 |
45 | forward |
45 | forward |
46 | dd __#name#_export_name__,name |
46 | dd __#name#_export_name__,name |
47 | common |
47 | common |
48 | dd 0 |
48 | dd 0 |
49 | forward |
49 | forward |
50 | __#name#_export_name__ db sname,0 |
50 | __#name#_export_name__ db sname,0 |
51 | } |
51 | } |
52 | 52 | ||
53 | 53 | ||
54 | 54 | ||
55 | align 4 ; loading library (use kernel functions) |
55 | align 4 ; loading library (use kernel functions) |
56 | proc load_k_library stdcall, file_name:dword |
56 | proc load_k_library stdcall, file_name:dword |
57 | locals |
57 | locals |
58 | coff dd ? |
58 | coff dd ? |
59 | sym dd ? |
59 | sym dd ? |
60 | strings dd ? |
60 | strings dd ? |
61 | img_size dd ? |
61 | img_size dd ? |
62 | img_base dd ? |
62 | img_base dd ? |
63 | exports dd ? |
63 | exports dd ? |
64 | endl |
64 | endl |
65 | 65 | ||
66 | cli |
66 | cli |
67 | 67 | ||
68 | stdcall load_file, [file_name] |
68 | stdcall load_file, [file_name] |
69 | test eax, eax |
69 | test eax, eax |
70 | jz .fail |
70 | jz .fail |
71 | 71 | ||
72 | mov [coff], eax |
72 | mov [coff], eax |
73 | movzx ecx, [eax+CFH.nSections] |
73 | movzx ecx, [eax+CFH.nSections] |
74 | xor ebx, ebx |
74 | xor ebx, ebx |
75 | 75 | ||
76 | lea edx, [eax+20] |
76 | lea edx, [eax+20] |
77 | @@: |
77 | @@: |
78 | add ebx, [edx+CFS.SizeOfRawData] |
78 | add ebx, [edx+CFS.SizeOfRawData] |
79 | add ebx, 15 |
79 | add ebx, 15 |
80 | and ebx, not 15 |
80 | and ebx, not 15 |
81 | add edx, COFF_SECTION_SIZE |
81 | add edx, COFF_SECTION_SIZE |
82 | dec ecx |
82 | dec ecx |
83 | jnz @B |
83 | jnz @B |
84 | mov [img_size], ebx |
84 | mov [img_size], ebx |
85 | 85 | ||
86 | stdcall kernel_alloc, [img_size] |
86 | stdcall kernel_alloc, [img_size] |
87 | 87 | ||
88 | test eax, eax |
88 | test eax, eax |
89 | jz .fail |
89 | jz .fail |
90 | mov [img_base], eax |
90 | mov [img_base], eax |
91 | 91 | ||
92 | mov edx, [coff] |
92 | mov edx, [coff] |
93 | movzx ebx, [edx+CFH.nSections] |
93 | movzx ebx, [edx+CFH.nSections] |
94 | mov edi, [img_base] |
94 | mov edi, [img_base] |
95 | lea eax, [edx+20] |
95 | lea eax, [edx+20] |
96 | @@: |
96 | @@: |
97 | mov [eax+CFS.VirtualAddress], edi |
97 | mov [eax+CFS.VirtualAddress], edi |
98 | mov esi, [eax+CFS.PtrRawData] |
98 | mov esi, [eax+CFS.PtrRawData] |
99 | test esi, esi |
99 | test esi, esi |
100 | jnz .copy |
100 | jnz .copy |
101 | add edi, [eax+CFS.SizeOfRawData] |
101 | add edi, [eax+CFS.SizeOfRawData] |
102 | jmp .next |
102 | jmp .next |
103 | .copy: |
103 | .copy: |
104 | add esi, edx |
104 | add esi, edx |
105 | mov ecx, [eax+CFS.SizeOfRawData] |
105 | mov ecx, [eax+CFS.SizeOfRawData] |
106 | cld |
106 | cld |
107 | rep movsb |
107 | rep movsb |
108 | .next: |
108 | .next: |
109 | add edi, 15 |
109 | add edi, 15 |
110 | and edi, not 15 |
110 | and edi, not 15 |
111 | add eax, COFF_SECTION_SIZE |
111 | add eax, COFF_SECTION_SIZE |
112 | dec ebx |
112 | dec ebx |
113 | jnz @B |
113 | jnz @B |
114 | 114 | ||
115 | mov ebx, [edx+CFH.pSymTable] |
115 | mov ebx, [edx+CFH.pSymTable] |
116 | add ebx, edx |
116 | add ebx, edx |
117 | mov [sym], ebx |
117 | mov [sym], ebx |
118 | mov ecx, [edx+CFH.nSymbols] |
118 | mov ecx, [edx+CFH.nSymbols] |
119 | add ecx, ecx |
119 | add ecx, ecx |
120 | lea ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
120 | lea ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
121 | add ecx, [sym] |
121 | add ecx, [sym] |
122 | mov [strings], ecx |
122 | mov [strings], ecx |
123 | 123 | ||
124 | lea eax, [edx+20] |
124 | lea eax, [edx+20] |
125 | 125 | ||
126 | stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols], \ |
126 | stdcall fix_coff_symbols, eax, [sym], [edx+CFH.nSymbols], \ |
127 | [strings], dword 0 |
127 | [strings], dword 0 |
128 | test eax, eax |
128 | test eax, eax |
129 | jnz @F |
129 | jnz @F |
130 | 130 | ||
131 | @@: |
131 | @@: |
132 | mov edx, [coff] |
132 | mov edx, [coff] |
133 | movzx ebx, [edx+CFH.nSections] |
133 | movzx ebx, [edx+CFH.nSections] |
134 | mov edi, 0 |
134 | mov edi, 0 |
135 | lea eax, [edx+20] |
135 | lea eax, [edx+20] |
136 | @@: |
136 | @@: |
137 | add [eax+CFS.VirtualAddress], edi ;patch user space offset |
137 | add [eax+CFS.VirtualAddress], edi ;patch user space offset |
138 | add eax, COFF_SECTION_SIZE |
138 | add eax, COFF_SECTION_SIZE |
139 | dec ebx |
139 | dec ebx |
140 | jnz @B |
140 | jnz @B |
141 | 141 | ||
142 | add edx, 20 |
142 | add edx, 20 |
143 | stdcall fix_coff_relocs, [coff], edx, [sym] |
143 | stdcall fix_coff_relocs, [coff], edx, [sym] |
144 | 144 | ||
145 | mov ebx, [coff] |
145 | mov ebx, [coff] |
146 | stdcall get_coff_sym, [sym], [ebx+CFH.nSymbols], szEXPORTS |
146 | stdcall get_coff_sym, [sym], [ebx+CFH.nSymbols], szEXPORTS |
147 | mov [exports], eax |
147 | mov [exports], eax |
148 | 148 | ||
149 | stdcall kernel_free, [coff] |
149 | stdcall kernel_free, [coff] |
150 | 150 | ||
151 | mov eax, [exports] |
151 | mov eax, [exports] |
152 | ret |
152 | ret |
153 | .fail: |
153 | .fail: |
154 | xor eax, eax |
154 | xor eax, eax |
155 | ret |
155 | ret |
156 | endp |
156 | endp |
157 | 157 | ||
158 | 158 | ||
159 | proc dll.Load, import_table:dword |
159 | proc dll.Load, import_table:dword |
160 | mov esi, [import_table] |
160 | mov esi, [import_table] |
161 | .next_lib: |
161 | .next_lib: |
162 | mov edx, [esi] |
162 | mov edx, [esi] |
163 | or edx, edx |
163 | or edx, edx |
164 | jz .exit |
164 | jz .exit |
165 | push esi |
165 | push esi |
166 | 166 | ||
167 | mov edi, s_libname |
167 | mov edi, s_libname |
168 | 168 | ||
169 | mov al, '/' |
169 | mov al, '/' |
170 | stosb |
170 | stosb |
171 | mov esi, sysdir_path |
171 | mov esi, sysdir_path |
172 | @@: |
172 | @@: |
173 | lodsb |
173 | lodsb |
174 | stosb |
174 | stosb |
175 | or al, al |
175 | or al, al |
176 | jnz @b |
176 | jnz @b |
177 | dec edi |
177 | dec edi |
178 | mov [edi], dword '/lib' |
178 | mov [edi], dword '/lib' |
179 | mov [edi+4], byte '/' |
179 | mov [edi+4], byte '/' |
180 | add edi, 5 |
180 | add edi, 5 |
181 | pop esi |
181 | pop esi |
182 | push esi |
182 | push esi |
183 | mov esi, [esi+4] |
183 | mov esi, [esi+4] |
184 | @@: |
184 | @@: |
185 | lodsb |
185 | lodsb |
186 | stosb |
186 | stosb |
187 | or al, al |
187 | or al, al |
188 | jnz @b |
188 | jnz @b |
189 | 189 | ||
190 | pushad |
190 | pushad |
191 | stdcall load_k_library, s_libname |
191 | stdcall load_k_library, s_libname |
192 | mov [esp+28], eax |
192 | mov [esp+28], eax |
193 | popad |
193 | popad |
194 | or eax, eax |
194 | or eax, eax |
195 | jz .fail |
195 | jz .fail |
196 | stdcall dll.Link, eax, edx |
196 | stdcall dll.Link, eax, edx |
197 | stdcall dll.Init, [eax+4] |
197 | stdcall dll.Init, [eax+4] |
198 | pop esi |
198 | pop esi |
199 | add esi, 8 |
199 | add esi, 8 |
200 | jmp .next_lib |
200 | jmp .next_lib |
201 | .exit: |
201 | .exit: |
202 | xor eax, eax |
202 | xor eax, eax |
203 | ret |
203 | ret |
204 | .fail: |
204 | .fail: |
205 | add esp, 4 |
205 | add esp, 4 |
206 | xor eax, eax |
206 | xor eax, eax |
207 | inc eax |
207 | inc eax |
208 | ret |
208 | ret |
209 | endp |
209 | endp |
210 | 210 | ||
211 | proc dll.Link, exp:dword,imp:dword |
211 | proc dll.Link, exp:dword,imp:dword |
212 | push eax |
212 | push eax |
213 | mov esi, [imp] |
213 | mov esi, [imp] |
214 | test esi, esi |
214 | test esi, esi |
215 | jz .done |
215 | jz .done |
216 | .next: |
216 | .next: |
217 | lodsd |
217 | lodsd |
218 | test eax, eax |
218 | test eax, eax |
219 | jz .done |
219 | jz .done |
220 | stdcall dll.GetProcAddress, [exp], eax |
220 | stdcall dll.GetProcAddress, [exp], eax |
221 | or eax, eax |
221 | or eax, eax |
222 | jz @f |
222 | jz @f |
223 | mov [esi-4], eax |
223 | mov [esi-4], eax |
224 | jmp .next |
224 | jmp .next |
225 | @@: |
225 | @@: |
226 | mov dword[esp], 0 |
226 | mov dword[esp], 0 |
227 | .done: |
227 | .done: |
228 | pop eax |
228 | pop eax |
229 | ret |
229 | ret |
230 | endp |
230 | endp |
231 | 231 | ||
232 | proc dll.Init, dllentry:dword |
232 | proc dll.Init, dllentry:dword |
233 | pushad |
233 | pushad |
234 | mov eax, mem.Alloc |
234 | mov eax, mem.Alloc |
235 | mov ebx, mem.Free |
235 | mov ebx, mem.Free |
236 | mov ecx, mem.ReAlloc |
236 | mov ecx, mem.ReAlloc |
237 | mov edx, dll.Load |
237 | mov edx, dll.Load |
238 | stdcall [dllentry] |
238 | stdcall [dllentry] |
239 | popad |
239 | popad |
240 | ret |
240 | ret |
241 | endp |
241 | endp |
242 | 242 | ||
243 | proc dll.GetProcAddress, exp:dword,sz_name:dword |
243 | proc dll.GetProcAddress, exp:dword,sz_name:dword |
244 | mov edx, [exp] |
244 | mov edx, [exp] |
245 | .next: |
245 | .next: |
246 | test edx, edx |
246 | test edx, edx |
247 | jz .end |
247 | jz .end |
248 | stdcall strncmp, [edx], [sz_name], dword -1 |
248 | stdcall strncmp, [edx], [sz_name], dword -1 |
249 | test eax, eax |
249 | test eax, eax |
250 | jz .ok |
250 | jz .ok |
251 | add edx, 8 |
251 | add edx, 8 |
252 | jmp .next |
252 | jmp .next |
253 | .ok: |
253 | .ok: |
254 | mov eax, [edx+4] |
254 | mov eax, [edx+4] |
255 | .end: |
255 | .end: |
256 | ret |
256 | ret |
257 | endp |
257 | endp |
258 | 258 | ||
259 | ;----------------------------------------------------------------------------- |
259 | ;----------------------------------------------------------------------------- |
260 | proc mem.Alloc size ;///////////////////////////////////////////////////////// |
260 | proc mem.Alloc size ;///////////////////////////////////////////////////////// |
261 | ;----------------------------------------------------------------------------- |
261 | ;----------------------------------------------------------------------------- |
262 | push ebx ecx |
262 | push ebx ecx |
263 | ; mov eax,[size] |
263 | ; mov eax,[size] |
264 | ; lea ecx,[eax+4+4095] |
264 | ; lea ecx,[eax+4+4095] |
265 | ; and ecx,not 4095 |
265 | ; and ecx,not 4095 |
266 | ; stdcall kernel_alloc, ecx |
266 | ; stdcall kernel_alloc, ecx |
267 | ; add ecx,-4 |
267 | ; add ecx,-4 |
268 | ; mov [eax],ecx |
268 | ; mov [eax],ecx |
269 | ; add eax,4 |
269 | ; add eax,4 |
270 | 270 | ||
271 | stdcall kernel_alloc, [size] |
271 | stdcall kernel_alloc, [size] |
272 | 272 | ||
273 | pop ecx ebx |
273 | pop ecx ebx |
274 | ret |
274 | ret |
275 | endp |
275 | endp |
276 | 276 | ||
277 | ;----------------------------------------------------------------------------- |
277 | ;----------------------------------------------------------------------------- |
278 | proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// |
278 | proc mem.ReAlloc mptr,size;/////////////////////////////////////////////////// |
279 | ;----------------------------------------------------------------------------- |
279 | ;----------------------------------------------------------------------------- |
280 | push ebx ecx esi edi eax |
280 | push ebx ecx esi edi eax |
281 | mov eax, [mptr] |
281 | mov eax, [mptr] |
282 | mov ebx, [size] |
282 | mov ebx, [size] |
283 | or eax, eax |
283 | or eax, eax |
284 | jz @f |
284 | jz @f |
285 | lea ecx, [ebx+4+4095] |
285 | lea ecx, [ebx+4+4095] |
286 | and ecx, not 4095 |
286 | and ecx, not 4095 |
287 | add ecx, -4 |
287 | add ecx, -4 |
288 | cmp ecx, [eax-4] |
288 | cmp ecx, [eax-4] |
289 | je .exit |
289 | je .exit |
290 | @@: |
290 | @@: |
291 | mov eax, ebx |
291 | mov eax, ebx |
292 | call mem.Alloc |
292 | call mem.Alloc |
293 | xchg eax, [esp] |
293 | xchg eax, [esp] |
294 | or eax, eax |
294 | or eax, eax |
295 | jz .exit |
295 | jz .exit |
296 | mov esi, eax |
296 | mov esi, eax |
297 | xchg eax, [esp] |
297 | xchg eax, [esp] |
298 | mov edi, eax |
298 | mov edi, eax |
299 | mov ecx, [esi-4] |
299 | mov ecx, [esi-4] |
300 | cmp ecx, [edi-4] |
300 | cmp ecx, [edi-4] |
301 | jbe @f |
301 | jbe @f |
302 | mov ecx, [edi-4] |
302 | mov ecx, [edi-4] |
303 | @@: |
303 | @@: |
304 | add ecx, 3 |
304 | add ecx, 3 |
305 | shr ecx, 2 |
305 | shr ecx, 2 |
306 | cld |
306 | cld |
307 | rep movsd |
307 | rep movsd |
308 | xchg eax, [esp] |
308 | xchg eax, [esp] |
309 | call mem.Free |
309 | call mem.Free |
310 | .exit: |
310 | .exit: |
311 | pop eax edi esi ecx ebx |
311 | pop eax edi esi ecx ebx |
312 | ret |
312 | ret |
313 | endp |
313 | endp |
314 | 314 | ||
315 | ;----------------------------------------------------------------------------- |
315 | ;----------------------------------------------------------------------------- |
316 | proc mem.Free mptr ;////////////////////////////////////////////////////////// |
316 | proc mem.Free mptr ;////////////////////////////////////////////////////////// |
317 | ;----------------------------------------------------------------------------- |
317 | ;----------------------------------------------------------------------------- |
318 | ; mov eax,[mptr] |
318 | ; mov eax,[mptr] |
319 | ; or eax,eax |
319 | ; or eax,eax |
320 | ; jz @f |
320 | ; jz @f |
321 | ; push ebx ecx |
321 | ; push ebx ecx |
322 | ; lea ecx,[eax-4] |
322 | ; lea ecx,[eax-4] |
323 | ; stdcall kernel_free, ecx |
323 | ; stdcall kernel_free, ecx |
324 | ; pop ecx ebx |
324 | ; pop ecx ebx |
325 | ; @@: ret |
325 | ; @@: ret |
326 | stdcall kernel_free, [mptr] |
326 | stdcall kernel_free, [mptr] |
327 | ret |
327 | ret |
328 | endp |
328 | endp |
329 | 329 | ||
330 | uglobal |
330 | uglobal |
331 | s_libname db 64 dup (0) |
331 | s_libname db 64 dup (0) |
332 | endg |
332 | endg |
333 | end if |
333 | end if |