Subversion Repositories Kolibri OS

Rev

Rev 3067 | Rev 5576 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
3067 leency 1
char a_libdir[43]  = "/sys/lib/\0";
2
 
4567 hidnplayr 3
// stdcall with 1 parameter
4
void dll_Load() {
5
asm {
6
        push    ebp
7
        mov     ebp, esp
8
        mov     esi, SSDWORD[EBP+8]
9
@next_lib:
10
        mov     edx, DSDWORD[ESI]
11
        or      edx, edx
12
        jz      exit
13
        push    esi
14
        mov     esi, DSDWORD[ESI+4]
15
        mov     edi, #a_libdir+9
3067 leency 16
 
4567 hidnplayr 17
@loc01:
18
        lodsb
19
        stosb
20
        or      al, al
21
        jnz     loc01
3067 leency 22
 
4567 hidnplayr 23
        mov     eax, 68
24
        mov     ebx, 19
25
        mov     ecx, #a_libdir
26
        int     0x40
27
        or      eax, eax
28
        jz      fail
29
 
30
        push    edx
31
        push    eax
32
        call    dll_Link
33
 
34
        push    eax
35
        mov     eax, DSDWORD[eax]
36
        cmp     DSDWORD[EAX], '_bil'    // somehow this needs to be reversed..
37
        pop     eax
38
        jnz     loc02
39
 
40
        push    DSDWORD[EAX+4]
41
        call    dll_Init
42
@loc02:
43
 
44
        pop     esi
45
        add     esi, 8
46
        jmp     next_lib
47
@exit:
48
        xor     eax, eax
49
        leave
50
        ret     4
51
 
52
@fail:
53
        add     esp, 4
54
        xor     eax, eax
55
        inc     eax
56
        leave
57
        ret     4
58
    }
3067 leency 59
}
60
 
4567 hidnplayr 61
//stdcall with 2 parameters
62
void dll_Link() {
63
asm {
64
        push    ebp
65
        mov     ebp, esp
66
        push    eax
67
        mov     esi, SSDWORD[EBP+12]
68
        test    esi, esi
69
        jz      done
70
@next:
71
        lodsd
72
        test    eax, eax
73
        jz      done
74
        push    eax
75
        push    SSDWORD[EBP+8]
76
        call    dll_GetProcAddress
77
        or      eax, eax
78
        jz      loc03
79
        mov     DSDWORD[esi-4], eax
80
        jmp     next
81
@loc03:
82
        mov     SSDWORD[esp], 0
83
@done:
84
        pop     eax
85
        leave
86
        ret     8
87
    }
88
}
3067 leency 89
 
90
 
4567 hidnplayr 91
//stdcall with 1 parameter
92
void dll_Init() {
93
asm {
94
        push    ebp
95
        mov     ebp, esp
96
        pushad
97
        mov     eax, #mem_Alloc
98
        mov     ebx, #mem_Free;
99
        mov     ecx, #mem_ReAlloc;
100
        mov     edx, #dll_Load;
101
        call    SSDWORD[EBP+8]
102
        popad
103
        leave
104
        ret     4
105
    }
3067 leency 106
}
107
 
4567 hidnplayr 108
 
109
// stdcall with 2 parameters
110
void dll_GetProcAddress(){
111
asm {
112
        push    ebp
113
        mov     ebp, esp
114
        mov     edx, CSDWORD[EBP+8]
115
        xor     eax, eax
116
 
117
@next:
118
        or      edx, edx
119
        jz      end
120
        cmp     CSDWORD[edx], 0
121
        jz      end
122
 
123
        push    CSDWORD[EBP+12]
124
        push    CSDWORD[EDX]
125
        call    dll_StrCmp
126
        test    eax, eax
127
        jz      ok
128
        add     edx, 8
129
        jmp     next
130
@ok:
131
        mov     eax, DSDWORD[EDX+4]
132
@end:
133
        leave
134
        ret     8
135
    }
3067 leency 136
}
137
 
4567 hidnplayr 138
 
139
// stdcall with 2 parameters
140
void dll_StrCmp() {
141
asm {
142
        push    ebp
143
        mov     ebp, esp
144
        push    esi
145
        push    edi
146
        mov     esi, CSDWORD[EBP+8]
147
        mov     edi, CSDWORD[EBP+12]
148
        xor     eax, eax
149
@label1:
150
        lodsb
151
        scasb
152
        jne     fail
153
        or      al, al
154
        jnz     label1
155
        jmp     label_ok
156
@fail:
157
        or      eax, -1
158
@label_ok:
159
        pop     edi
160
        pop     esi
161
        leave
162
        ret     8
163
    }
3067 leency 164
}
165
 
166
int load_dll2(dword dllname, import_table, byte need_init)
167
{
168
   //dword dllentry=0;
169
// load DLL
170
        $mov     eax, 68
171
        $mov     ebx, 19
172
        ECX=dllname;
173
        $int     0x40
174
        $test    eax, eax
175
        $jz      exit01
176
 
177
// initialize import
178
        $mov     edx,eax
179
        ESI=import_table;
180
 
181
@import_loop01:
182
        $lodsd
183
        $test    eax,eax
184
        $jz      import_done01
185
        $push    edx
186
@import_find01:
187
        $mov     ebx,DSDWORD[EDX]
188
        $test    ebx, ebx
189
        $jz      exit01
190
        $push    eax
191
@nex101:
192
        $mov     cl,DSBYTE[EAX];
193
        $cmp     cl,DSBYTE[EBX];
194
        $jnz     import_find_next01
195
        $test    cl,cl
196
        $jz      import_found01
197
        $inc     eax
198
        $inc     ebx
199
        $jmp     nex101
200
@import_find_next01:
201
        $pop     eax
202
        $add     edx, 8
203
        $jmp     import_find01
204
@import_found01:
205
        $pop     eax
206
        $mov     eax,DSDWORD[edx+4]
207
        $mov     DSDWORD[esi-4],eax
208
        $pop     edx
209
 
210
        $jmp     import_loop01
211
@import_done01:
4567 hidnplayr 212
        IF (need_init) dll_Init (DSDWORD[EDX+4]);
3067 leency 213
        return 0;
214
@exit01:
215
        return -1;
4567 hidnplayr 216
}