Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
2288 clevermous 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
10051 ace_dent 3
;; Copyright (C) KolibriOS team 2004-2024. All rights reserved. ;;
2288 clevermous 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
7
 
6502 pathoswith 8
; External kernel dependencies (libraries) loading.
9
; The code currently does not work, requires correcting dll.inc.
2288 clevermous 10
 
11
 
12
if 0
6502 pathoswith 13
iglobal
14
tmp_file_name_size  dd  1
15
endg
16
 
17
uglobal
18
tmp_file_name_table dd  ?
19
s_libname   rb  64
20
def_val_1   db  ?
21
endg
22
 
2288 clevermous 23
macro library [name,fname]
24
{
25
  forward
26
    dd __#name#_library_table__,__#name#_library_name__
27
  common
28
    dd 0
29
  forward
30
    __#name#_library_name__ db fname,0
31
}
32
 
33
macro import lname,[name,sname]
34
{
35
  common
36
    align 4
37
    __#lname#_library_table__:
38
  forward
39
    name dd __#name#_import_name__
40
  common
41
    dd 0
42
  forward
43
    __#name#_import_name__ db sname,0
44
}
45
 
46
macro export [name,sname]
47
{
48
align 4
49
  forward
50
    dd __#name#_export_name__,name
51
  common
52
    dd 0
53
  forward
54
    __#name#_export_name__ db sname,0
55
}
56
 
57
 
58
 
59
align 4            ; loading library (use kernel functions)
60
proc load_k_library stdcall, file_name:dword
61
           locals
62
             coff      dd ?
63
             sym       dd ?
64
             strings   dd ?
65
             img_size  dd ?
66
             img_base  dd ?
67
             exports   dd ?
68
           endl
69
 
70
        cli
71
 
72
        stdcall load_file, [file_name]
73
        test    eax, eax
74
        jz      .fail
75
 
76
        mov     [coff], eax
9715 Doczom 77
        movzx   ecx, [eax + CFH.nSections]
2288 clevermous 78
        xor     ebx, ebx
79
 
80
        lea     edx, [eax+20]
81
@@:
9715 Doczom 82
        add     ebx, [edx + CFS.SizeOfRawData]
2288 clevermous 83
        add     ebx, 15
84
        and     ebx, not 15
85
        add     edx, COFF_SECTION_SIZE
86
        dec     ecx
87
        jnz     @B
88
        mov     [img_size], ebx
89
 
90
        stdcall kernel_alloc, [img_size]
91
 
92
        test    eax, eax
93
        jz      .fail
94
        mov     [img_base], eax
95
 
96
        mov     edx, [coff]
9715 Doczom 97
        movzx   ebx, [edx + CFH.nSections]
2288 clevermous 98
        mov     edi, [img_base]
99
        lea     eax, [edx+20]
100
@@:
9715 Doczom 101
        mov     [eax + CFS.VirtualAddress], edi
102
        mov     esi, [eax + CFS.PtrRawData]
2288 clevermous 103
        test    esi, esi
104
        jnz     .copy
9715 Doczom 105
        add     edi, [eax + CFS.SizeOfRawData]
2288 clevermous 106
        jmp     .next
107
.copy:
108
        add     esi, edx
9715 Doczom 109
        mov     ecx, [eax + CFS.SizeOfRawData]
2288 clevermous 110
        cld
111
        rep movsb
112
.next:
113
        add     edi, 15
114
        and     edi, not 15
115
        add     eax, COFF_SECTION_SIZE
116
        dec     ebx
117
        jnz     @B
118
 
9715 Doczom 119
        mov     ebx, [edx + CFH.pSymTable]
2288 clevermous 120
        add     ebx, edx
121
        mov     [sym], ebx
9715 Doczom 122
        mov     ecx, [edx + CFH.nSymbols]
2288 clevermous 123
        add     ecx, ecx
9715 Doczom 124
        lea     ecx, [ecx + ecx*8];ecx*=18 = nSymbols*CSYM_SIZE
2288 clevermous 125
        add     ecx, [sym]
126
        mov     [strings], ecx
127
 
128
        lea     eax, [edx+20]
129
 
9715 Doczom 130
        stdcall fix_coff_symbols, eax, [sym], [edx + CFH.nSymbols], \
2288 clevermous 131
                [strings], dword 0
132
        test    eax, eax
133
        jnz     @F
134
 
135
@@:
136
        mov     edx, [coff]
9715 Doczom 137
        movzx   ebx, [edx + CFH.nSections]
9977 rgimad 138
        xor     edi, edi
2288 clevermous 139
        lea     eax, [edx+20]
140
@@:
9715 Doczom 141
        add     [eax + CFS.VirtualAddress], edi ;patch user space offset
2288 clevermous 142
        add     eax, COFF_SECTION_SIZE
143
        dec     ebx
144
        jnz     @B
145
 
146
        add     edx, 20
147
        stdcall fix_coff_relocs, [coff], edx, [sym]
148
 
149
        mov     ebx, [coff]
150
        stdcall get_coff_sym, [sym], [ebx+CFH.nSymbols], szEXPORTS
151
        mov     [exports], eax
152
 
153
        stdcall kernel_free, [coff]
154
 
155
        mov     eax, [exports]
156
        ret
157
.fail:
158
        xor     eax, eax
159
        ret
160
endp
161
 
162
 
163
proc dll.Load, import_table:dword
164
        mov     esi, [import_table]
165
  .next_lib:
166
        mov     edx, [esi]
167
        or      edx, edx
168
        jz      .exit
169
        push    esi
170
 
171
        mov     edi, s_libname
172
 
173
        mov     al, '/'
174
        stosb
175
        mov     esi, sysdir_path
176
            @@:
177
        lodsb
178
        stosb
179
        or      al, al
180
        jnz     @b
181
        dec     edi
182
        mov     [edi], dword '/lib'
183
        mov     [edi+4], byte '/'
184
        add     edi, 5
185
        pop     esi
186
        push    esi
187
        mov     esi, [esi+4]
188
            @@:
189
        lodsb
190
        stosb
191
        or      al, al
192
        jnz     @b
193
 
194
        pushad
195
        stdcall load_k_library, s_libname
196
        mov     [esp+28], eax
197
        popad
198
        or      eax, eax
199
        jz      .fail
200
        stdcall dll.Link, eax, edx
201
        stdcall dll.Init, [eax+4]
202
        pop     esi
203
        add     esi, 8
204
        jmp     .next_lib
205
  .exit:
206
        xor     eax, eax
207
        ret
208
  .fail:
209
        add     esp, 4
210
        xor     eax, eax
211
        inc     eax
212
        ret
213
endp
214
 
215
proc dll.Link, exp:dword,imp:dword
216
        push    eax
217
        mov     esi, [imp]
218
        test    esi, esi
219
        jz      .done
220
  .next:
221
        lodsd
222
        test    eax, eax
223
        jz      .done
224
        stdcall dll.GetProcAddress, [exp], eax
225
        or      eax, eax
226
        jz      @f
227
        mov     [esi-4], eax
228
        jmp     .next
229
            @@:
230
        mov     dword[esp], 0
231
  .done:
232
        pop     eax
233
        ret
234
endp
235
 
236
proc dll.Init, dllentry:dword
237
        pushad
238
        mov     eax, mem.Alloc
239
        mov     ebx, mem.Free
240
        mov     ecx, mem.ReAlloc
241
        mov     edx, dll.Load
242
        stdcall [dllentry]
243
        popad
244
        ret
245
endp
246
 
247
proc dll.GetProcAddress, exp:dword,sz_name:dword
248
        mov     edx, [exp]
249
  .next:
250
        test    edx, edx
251
        jz      .end
252
        stdcall strncmp, [edx], [sz_name], dword -1
253
        test    eax, eax
254
        jz      .ok
255
        add     edx, 8
256
        jmp     .next
257
  .ok:
258
        mov     eax, [edx+4]
259
  .end:
260
        ret
261
endp
262
 
263
;-----------------------------------------------------------------------------
264
proc mem.Alloc size ;/////////////////////////////////////////////////////////
265
;-----------------------------------------------------------------------------
266
        push    ebx ecx
267
;       mov     eax,[size]
268
;       lea     ecx,[eax+4+4095]
269
;       and     ecx,not 4095
270
;       stdcall kernel_alloc, ecx
271
;       add     ecx,-4
272
;       mov     [eax],ecx
273
;       add     eax,4
274
 
275
        stdcall kernel_alloc, [size]
276
 
277
        pop     ecx ebx
278
        ret
279
endp
280
 
281
;-----------------------------------------------------------------------------
282
proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
283
;-----------------------------------------------------------------------------
284
        push    ebx ecx esi edi eax
285
        mov     eax, [mptr]
286
        mov     ebx, [size]
287
        or      eax, eax
288
        jz      @f
289
        lea     ecx, [ebx+4+4095]
290
        and     ecx, not 4095
291
        add     ecx, -4
292
        cmp     ecx, [eax-4]
293
        je      .exit
294
    @@:
295
        mov     eax, ebx
296
        call    mem.Alloc
297
        xchg    eax, [esp]
298
        or      eax, eax
299
        jz      .exit
300
        mov     esi, eax
301
        xchg    eax, [esp]
302
        mov     edi, eax
303
        mov     ecx, [esi-4]
304
        cmp     ecx, [edi-4]
305
        jbe     @f
306
        mov     ecx, [edi-4]
307
    @@:
308
        add     ecx, 3
309
        shr     ecx, 2
310
        cld
311
        rep movsd
312
        xchg    eax, [esp]
313
        call    mem.Free
314
  .exit:
315
        pop     eax edi esi ecx ebx
316
        ret
317
endp
318
 
319
;-----------------------------------------------------------------------------
320
proc mem.Free mptr ;//////////////////////////////////////////////////////////
321
;-----------------------------------------------------------------------------
322
;       mov     eax,[mptr]
323
;       or      eax,eax
324
;       jz      @f
325
;       push    ebx ecx
326
;       lea     ecx,[eax-4]
327
;       stdcall kernel_free, ecx
328
;       pop     ecx ebx
329
;    @@: ret
330
        stdcall kernel_free, [mptr]
331
        ret
332
endp
333
 
6502 pathoswith 334
proc load_file_parse_table
335
        stdcall kernel_alloc, 0x1000
336
        mov     [tmp_file_name_table], eax
337
        mov     edi, eax
338
        mov     esi, sysdir_name
339
        mov     ecx, 128/4
340
        rep movsd
341
        invoke  ini.enum_keys, conf_fname, conf_path_sect, get_every_key
342
        mov     eax, [tmp_file_name_table]
343
        mov     [full_file_name_table], eax
344
        mov     eax, [tmp_file_name_size]
345
        mov     [full_file_name_table.size], eax
346
        ret
347
endp
348
 
349
proc get_every_key stdcall, f_name, sec_name, key_name
350
        mov     esi, [key_name]
351
        mov     ecx, esi
352
        cmp     byte [esi], '/'
353
        jnz     @f
354
        inc     esi
355
@@:
356
        mov     edi, [tmp_file_name_size]
357
        shl     edi, 7
358
        cmp     edi, 0x1000
359
        jae     .stop_parse
360
        add     edi, [tmp_file_name_table]
361
        lea     ebx, [edi+64]
362
@@:
363
        cmp     edi, ebx
364
        jae     .skip_this_key
365
        lodsb
366
        test    al, al
367
        jz      @f
368
        or      al, 20h
369
        stosb
370
        jmp     @b
371
 
372
.stop_parse:
373
        xor     eax, eax
374
        ret
375
 
376
@@:
377
        stosb
378
        invoke  ini.get_str, [f_name], [sec_name], ecx, ebx, 64, def_val_1
379
        cmp     byte [ebx], '/'
380
        jnz     @f
381
        lea     esi, [ebx+1]
382
        mov     edi, ebx
383
        mov     ecx, 63
384
        rep movsb
385
@@:
386
        push    ebp
387
        mov     ebp, [tmp_file_name_table]
388
        mov     ecx, [tmp_file_name_size]
389
        jecxz   .noreplace
390
        mov     eax, ecx
391
        dec     eax
392
        shl     eax, 7
393
        add     ebp, eax
394
.replace_loop:
395
        mov     edi, ebx
396
        mov     esi, ebp
397
@@:
398
        lodsb
399
        test    al, al
400
        jz      .doreplace
401
        mov     dl, [edi]
402
        inc     edi
403
        test    dl, dl
404
        jz      .replace_loop_cont
405
        or      dl, 20h
406
        cmp     al, dl
407
        jz      @b
408
        jmp     .replace_loop_cont
409
 
410
.doreplace:
411
        cmp     byte [edi], 0
412
        jz      @f
413
        cmp     byte [edi], '/'
414
        jnz     .replace_loop_cont
415
@@:
416
        lea     esi, [ebp+64]
417
        call    .replace
418
        jc      .skip_this_key2
419
.replace_loop_cont:
420
        sub     ebp, 128
421
        loop    .replace_loop
422
.noreplace:
423
        pop     ebp
424
        inc     [tmp_file_name_size]
425
.skip_this_key:
426
        xor     eax, eax
427
        inc     eax
428
        ret
429
 
430
.skip_this_key2:
431
        pop     ebp
432
        jmp     .skip_this_key
433
endp
434
 
435
proc get_every_key.replace
436
; in: ebx->destination, esi->first part of name, edi->second part of name
437
; maximum length is 64 bytes
438
; out: CF=1 <=> overflow
439
        sub     esp, 64 ; allocate temporary buffer in stack
440
        push    esi
441
        lea     esi, [esp+4]    ; esi->tmp buffer
442
        xchg    esi, edi        ; edi->tmp buffer, esi->source
443
@@: ; save second part of name to temporary buffer
444
        lodsb
445
        stosb
446
        test    al, al
447
        jnz     @b
448
        pop     esi
449
        mov     edi, ebx
450
@@: ; copy first part of name to destination
451
        lodsb
452
        test    al, al
453
        jz      @f
454
        stosb
455
        jmp     @b
456
 
457
@@: ; restore second part of name from temporary buffer to destination
458
        lea     edx, [ebx+64]   ; limit of destination
459
        mov     esi, esp
460
@@:
461
        cmp     edi, edx
462
        jae     .overflow
463
        lodsb
464
        stosb
465
        test    al, al
466
        jnz     @b
467
        add     esp, 64 ; CF is cleared
468
        ret
469
 
470
.overflow:  ; name is too long
471
        add     esp, 64
472
        stc
473
        ret
474
endp
2288 clevermous 475
end if