Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3545 hidnplayr 1
;-----------------------------------------------------------------------------
2
proc mem.Alloc size ;/////////////////////////////////////////////////////////
3
;-----------------------------------------------------------------------------
4
        push    ebx ecx
5
        mov     eax,[size]
6
        lea     ecx,[eax+4+4095]
7
        and     ecx, not 4095
8
        mcall   68,12
9
        test    eax, eax
10
        jz      @f
11
        add     ecx,-4
12
        mov     [eax],ecx
13
        add     eax,4
14
       @@:
15
        pop     ecx ebx
16
        ret
17
endp
18
 
19
;-----------------------------------------------------------------------------
20
proc mem.ReAlloc mptr,size;///////////////////////////////////////////////////
21
;-----------------------------------------------------------------------------
22
        push    ebx ecx esi edi eax
23
        mov     eax,[mptr]
24
        mov     ebx,[size]
25
        or      eax,eax
26
        jz      @f
27
        lea     ecx,[ebx+4+4095]
28
        and     ecx,not 4095
29
        add     ecx,-4
30
        cmp     ecx,[eax-4]
31
        je      .exit
32
    @@: mov     eax,ebx
33
        call    mem.Alloc
34
        xchg    eax,[esp]
35
        or      eax,eax
36
        jz      .exit
37
        mov     esi,eax
38
        xchg    eax,[esp]
39
        mov     edi,eax
40
        mov     ecx,[esi-4]
41
        cmp     ecx,[edi-4]
42
        jbe     @f
43
        mov     ecx,[edi-4]
44
    @@: add     ecx,3
45
        shr     ecx,2
46
        cld
47
        rep     movsd
48
        xchg    eax,[esp]
49
        call    mem.Free
50
  .exit:
51
        pop     eax edi esi ecx ebx
52
        ret
53
endp
54
 
55
;-----------------------------------------------------------------------------
56
proc mem.Free mptr ;//////////////////////////////////////////////////////////
57
;-----------------------------------------------------------------------------
58
        mov     eax,[mptr]
59
        or      eax,eax
60
        jz      @f
61
        push    ebx ecx
62
        lea     ecx,[eax-4]
63
        mcall   68,13
64
        pop     ecx ebx
65
    @@: ret
66
endp
67
 
68
 
69
proc dll.Load, import_table:dword
70
                mov     esi,[import_table]
71
  .next_lib:    mov     edx,[esi]
72
                or      edx,edx
73
                jz      .exit
74
                push    esi
75
                mov     esi,[esi+4]
76
                mov     edi,s_libdir.fname
77
            @@: lodsb
78
                stosb
79
                or      al,al
80
                jnz     @b
81
                mcall   68,19,s_libdir
82
                or      eax,eax
83
                jz      .fail
84
                stdcall dll.Link,eax,edx
85
                stdcall dll.Init,[eax+4]
86
                pop     esi
87
                add     esi,8
88
                jmp     .next_lib
89
  .exit:        xor     eax,eax
90
                ret
91
  .fail:        add     esp,4
92
                xor     eax,eax
93
                inc     eax
94
                ret
95
endp
96
 
97
proc dll.Link, exp:dword,imp:dword
98
                push    eax
99
                mov     esi,[imp]
100
                test    esi,esi
101
                jz      .done
102
  .next:        lodsd
103
                test    eax,eax
104
                jz      .done
105
                stdcall dll.GetProcAddress,[exp],eax
106
                or      eax,eax
107
                jz      @f
108
                mov     [esi-4],eax
109
                jmp     .next
110
            @@: mov     dword[esp],0
111
  .done:        pop     eax
112
                ret
113
endp
114
 
115
proc dll.Init, dllentry:dword
116
                pushad
117
                mov     eax,mem.Alloc
118
                mov     ebx,mem.Free
119
                mov     ecx,mem.ReAlloc
120
                mov     edx,dll.Load
121
                stdcall [dllentry]
122
                popad
123
                ret
124
endp
125
 
126
proc dll.GetProcAddress, exp:dword,sz_name:dword
127
                mov     edx,[exp]
128
                xor     eax,eax
129
  .next:        or      edx,edx
130
                jz      .end
131
                cmp     dword[edx],0
132
                jz      .end
133
                stdcall strcmp,[edx],[sz_name]
134
                test    eax,eax
135
                jz      .ok
136
                add     edx,8
137
                jmp     .next
138
  .ok:          mov     eax,[edx+4]
139
  .end:         ret
140
endp
141
 
142
proc strcmp, str1:dword,str2:dword
143
                push    esi edi
144
                mov     esi,[str1]
145
                mov     edi,[str2]
146
                xor     eax,eax
147
            @@: lodsb
148
                scasb
149
                jne     .fail
150
                or      al,al
151
                jnz     @b
152
                jmp     .ok
153
  .fail:        or      eax,-1
154
  .ok:          pop     edi esi
155
                ret
156
endp
157
 
158
s_libdir:
159
  db '/sys/lib/'
160
  .fname rb 32