Subversion Repositories Kolibri OS

Rev

Rev 7984 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 7984 Rev 8490
1
#ifndef INCLUDE_DLL_H
1
#ifndef INCLUDE_DLL_H
2
#define INCLUDE_DLL_H
2
#define INCLUDE_DLL_H
3
#print "[include ]\n"
3
#print "[include ]\n"
4
 
4
 
5
#ifndef INCLUDE_FILESYSTEM_H
5
#ifndef INCLUDE_FILESYSTEM_H
6
#include "../lib/fs.h"
6
#include "../lib/fs.h"
7
#endif
7
#endif
8
 
8
 
9
#ifdef LANG_RUS
9
#ifdef LANG_RUS
10
	#define _TEXT_ERROR_ADD "'Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨\n"
10
	#define _TEXT_ERROR_ADD "'Žè¨¡ª  ¯à¨ § £à㧪¥ ¡¨¡«¨®â¥ª¨\n"
11
#elif LANG_EST
11
#elif LANG_EST
12
	#define _TEXT_ERROR_ADD "'Viga teegi laadimisel\n"
12
	#define _TEXT_ERROR_ADD "'Viga teegi laadimisel\n"
13
#else
13
#else
14
	#define _TEXT_ERROR_ADD "'Error while loading library\n"
14
	#define _TEXT_ERROR_ADD "'Error while loading library\n"
15
#endif
15
#endif
16
 
16
 
17
char a_libdir[43]  = "/sys/lib/\0";
17
char a_libdir[43]  = "/sys/lib/\0";
18
 
-
 
19
:inline void error_init(dword lirary_path)
-
 
20
{
-
 
21
	char error_text[1024];
-
 
22
    strcpy(#error_text, _TEXT_ERROR_ADD);
-
 
23
    strcat(#error_text, lirary_path);
-
 
24
    strcat(#error_text, "' -E");
-
 
25
	notify(#error_text);
-
 
26
}
-
 
27
 
18
 
28
// stdcall with 1 parameter
19
// stdcall with 1 parameter
29
:void dll_Load() {
20
:void dll_Load() {
30
asm {
21
asm {
31
        push    ebp
22
        push    ebp
32
        mov     ebp, esp
23
        mov     ebp, esp
33
        mov     esi, SSDWORD[EBP+8]
24
        mov     esi, SSDWORD[EBP+8]
34
		@next_lib:    
25
		@next_lib:    
35
        mov     edx, DSDWORD[ESI]
26
        mov     edx, DSDWORD[ESI]
36
        or      edx, edx
27
        or      edx, edx
37
        jz      exit
28
        jz      exit
38
        push    esi
29
        push    esi
39
        mov     esi, DSDWORD[ESI+4]
30
        mov     esi, DSDWORD[ESI+4]
40
        mov     edi, #a_libdir+9
31
        mov     edi, #a_libdir+9
41
 
32
 
42
@loc01: 
33
@loc01: 
43
        lodsb
34
        lodsb
44
        stosb
35
        stosb
45
        or      al, al
36
        or      al, al
46
        jnz     loc01
37
        jnz     loc01
47
 
38
 
48
        mov     eax, 68
39
        mov     eax, 68
49
        mov     ebx, 19
40
        mov     ebx, 19
50
        mov     ecx, #a_libdir
41
        mov     ecx, #a_libdir
51
        int     0x40
42
        int     0x40
52
        or      eax, eax
43
        or      eax, eax
53
        jz      fail
44
        jz      fail
54
 
45
 
55
        push    edx
46
        push    edx
56
        push    eax
47
        push    eax
57
        call    dll_Link
48
        call    dll_Link
58
 
49
 
59
        push    eax
50
        push    eax
60
        mov     eax, DSDWORD[eax]
51
        mov     eax, DSDWORD[eax]
61
        cmp     DSDWORD[EAX], '_bil'    // somehow this needs to be reversed..
52
        cmp     DSDWORD[EAX], '_bil'    // somehow this needs to be reversed..
62
        pop     eax
53
        pop     eax
63
        jnz     loc02
54
        jnz     loc02
64
 
55
 
65
        push    DSDWORD[EAX+4]
56
        push    DSDWORD[EAX+4]
66
        call    dll_Init
57
        call    dll_Init
67
@loc02:
58
@loc02:
68
 
59
 
69
        pop     esi
60
        pop     esi
70
        add     esi, 8
61
        add     esi, 8
71
        jmp     next_lib
62
        jmp     next_lib
72
@exit:
63
@exit:
73
	xor     eax, eax
64
	xor     eax, eax
74
        leave
65
        leave
75
        ret     4
66
        ret     4
76
        
67
        
77
@fail:        
68
@fail:        
78
        add     esp, 4
69
        add     esp, 4
79
        xor     eax, eax
70
        xor     eax, eax
80
        inc     eax
71
        inc     eax
81
        leave
72
        leave
82
        ret     4
73
        ret     4
83
    }
74
    }
84
}
75
}
85
 
76
 
86
//stdcall with 2 parameters
77
//stdcall with 2 parameters
87
:void dll_Link() {
78
:void dll_Link() {
88
asm {
79
asm {
89
        push    ebp
80
        push    ebp
90
        mov     ebp, esp
81
        mov     ebp, esp
91
        push    eax
82
        push    eax
92
        mov     esi, SSDWORD[EBP+12]
83
        mov     esi, SSDWORD[EBP+12]
93
        test    esi, esi
84
        test    esi, esi
94
        jz      done
85
        jz      done
95
@next:        
86
@next:        
96
        lodsd
87
        lodsd
97
        test    eax, eax
88
        test    eax, eax
98
        jz      done
89
        jz      done
99
        push    eax
90
        push    eax
100
        push    SSDWORD[EBP+8]
91
        push    SSDWORD[EBP+8]
101
        call    dll_GetProcAddress
92
        call    dll_GetProcAddress
102
        or      eax, eax
93
        or      eax, eax
103
        jz      loc03
94
        jz      loc03
104
        mov     DSDWORD[esi-4], eax
95
        mov     DSDWORD[esi-4], eax
105
        jmp     next
96
        jmp     next
106
@loc03: 
97
@loc03: 
107
        mov     SSDWORD[esp], 0
98
        mov     SSDWORD[esp], 0
108
@done:
99
@done:
109
        pop     eax
100
        pop     eax
110
        leave
101
        leave
111
        ret     8
102
        ret     8
112
    }
103
    }
113
}
104
}
114
 
105
 
115
 
106
 
116
//stdcall with 1 parameter
107
//stdcall with 1 parameter
117
:void dll_Init() {
108
:void dll_Init() {
118
asm {
109
asm {
119
        push    ebp
110
        push    ebp
120
        mov     ebp, esp
111
        mov     ebp, esp
121
        pushad
112
        pushad
122
        mov     eax, #malloc
113
        mov     eax, #malloc
123
        mov     ebx, #free;
114
        mov     ebx, #free;
124
        mov     ecx, #realloc;
115
        mov     ecx, #realloc;
125
        mov     edx, #dll_Load;
116
        mov     edx, #dll_Load;
126
        call    SSDWORD[EBP+8]
117
        call    SSDWORD[EBP+8]
127
        popad
118
        popad
128
        leave
119
        leave
129
        ret     4
120
        ret     4
130
    }
121
    }
131
}
122
}
132
 
123
 
133
 
124
 
134
// stdcall with 2 parameters
125
// stdcall with 2 parameters
135
:void dll_GetProcAddress(){
126
:void dll_GetProcAddress(){
136
asm {
127
asm {
137
        push    ebp
128
        push    ebp
138
        mov     ebp, esp
129
        mov     ebp, esp
139
        mov     edx, CSDWORD[EBP+8]
130
        mov     edx, CSDWORD[EBP+8]
140
        xor     eax, eax
131
        xor     eax, eax
141
 
132
 
142
@next:        
133
@next:        
143
        or      edx, edx
134
        or      edx, edx
144
        jz      end
135
        jz      end
145
        cmp     CSDWORD[edx], 0
136
        cmp     CSDWORD[edx], 0
146
        jz      end
137
        jz      end
147
 
138
 
148
        push    CSDWORD[EBP+12]
139
        push    CSDWORD[EBP+12]
149
        push    CSDWORD[EDX]
140
        push    CSDWORD[EDX]
150
        call    dll_StrCmp
141
        call    dll_StrCmp
151
        test    eax, eax
142
        test    eax, eax
152
        jz      ok
143
        jz      ok
153
        add     edx, 8
144
        add     edx, 8
154
        jmp     next
145
        jmp     next
155
@ok:
146
@ok:
156
        mov     eax, DSDWORD[EDX+4]
147
        mov     eax, DSDWORD[EDX+4]
157
@end:
148
@end:
158
        leave
149
        leave
159
        ret     8
150
        ret     8
160
    }
151
    }
161
}
152
}
162
 
153
 
163
 
154
 
164
// stdcall with 2 parameters
155
// stdcall with 2 parameters
165
:void dll_StrCmp() {
156
:void dll_StrCmp() {
166
asm {
157
asm {
167
        push    ebp
158
        push    ebp
168
        mov     ebp, esp
159
        mov     ebp, esp
169
        push    esi
160
        push    esi
170
        push    edi
161
        push    edi
171
        mov     esi, CSDWORD[EBP+8]
162
        mov     esi, CSDWORD[EBP+8]
172
        mov     edi, CSDWORD[EBP+12]
163
        mov     edi, CSDWORD[EBP+12]
173
        xor     eax, eax
164
        xor     eax, eax
174
@label1:
165
@label1:
175
        lodsb
166
        lodsb
176
        scasb
167
        scasb
177
        jne     fail
168
        jne     fail
178
        or      al, al
169
        or      al, al
179
        jnz     label1
170
        jnz     label1
180
        jmp     label_ok
171
        jmp     label_ok
181
@fail:
172
@fail:
182
        or      eax, -1
173
        or      eax, -1
183
@label_ok:
174
@label_ok:
184
        pop     edi
175
        pop     edi
185
        pop     esi
176
        pop     esi
186
        leave
177
        leave
187
        ret     8
178
        ret     8
188
    }
179
    }
189
}
180
}
190
 
181
 
191
:int load_dll2(dword dllname, import_table, byte need_init)
182
:void load_dll(dword dllname, import_table, byte need_init)
192
{
-
 
193
   //dword dllentry=0;
183
{
194
// load DLL
184
// load DLL
195
        $mov     eax, 68
185
        $mov     eax, 68
196
        $mov     ebx, 19
186
        $mov     ebx, 19
197
        ECX=dllname;
187
        ECX=dllname;
198
        $int     0x40
188
        $int     0x40
199
        $test    eax, eax
189
        $test    eax, eax
200
        $jz      exit01
190
        $jz      exit01
201
 
191
 
202
// initialize import
192
// initialize import
203
        $mov     edx,eax
193
        $mov     edx,eax
204
        ESI=import_table;
194
        ESI=import_table;
205
 
195
 
206
@import_loop01:
196
@import_loop01:
207
        $lodsd
197
        $lodsd
208
        $test    eax,eax
198
        $test    eax,eax
209
        $jz      import_done01
199
        $jz      import_done01
210
        $push    edx
200
        $push    edx
211
@import_find01:
201
@import_find01:
212
        $mov     ebx,DSDWORD[EDX]
202
        $mov     ebx,DSDWORD[EDX]
213
        $test    ebx, ebx
203
        $test    ebx, ebx
214
        $jz      exit01
204
        $jz      exit01
215
        $push    eax
205
        $push    eax
216
@nex101:
206
@nex101:
217
        $mov     cl,DSBYTE[EAX];
207
        $mov     cl,DSBYTE[EAX];
218
        $cmp     cl,DSBYTE[EBX];
208
        $cmp     cl,DSBYTE[EBX];
219
        $jnz     import_find_next01
209
        $jnz     import_find_next01
220
        $test    cl,cl
210
        $test    cl,cl
221
        $jz      import_found01
211
        $jz      import_found01
222
        $inc     eax
212
        $inc     eax
223
        $inc     ebx
213
        $inc     ebx
224
        $jmp     nex101
214
        $jmp     nex101
225
@import_find_next01:
215
@import_find_next01:
226
        $pop     eax
216
        $pop     eax
227
        $add     edx, 8
217
        $add     edx, 8
228
        $jmp     import_find01
218
        $jmp     import_find01
229
@import_found01:
219
@import_found01:
230
        $pop     eax
220
        $pop     eax
231
        $mov     eax,DSDWORD[edx+4]
221
        $mov     eax,DSDWORD[edx+4]
232
        $mov     DSDWORD[esi-4],eax
222
        $mov     DSDWORD[esi-4],eax
233
        $pop     edx
223
        $pop     edx
234
       
224
       
235
        $jmp     import_loop01
225
        $jmp     import_loop01
236
@import_done01:
226
@import_done01:
237
        #ifndef NO_DLL_INIT
227
        #ifndef NO_DLL_INIT
238
        IF (need_init) dll_Init (DSDWORD[EDX+4]);
228
        IF (need_init) dll_Init (DSDWORD[EDX+4]);
239
        #endif
229
        #endif
240
        return 0;
230
        return;
241
@exit01:
231
@exit01:
242
        return -1;
232
        error_init(dllname);
243
}
233
}
244
 
-
 
245
:byte load_dll(dword dllname, import_table, byte need_init)
-
 
246
{
234
 
247
	if (load_dll2(dllname, import_table, need_init))
235
:inline void error_init(dword lirary_path)
248
	{
236
{
-
 
237
    char error_text[1024];
-
 
238
    strcpy(#error_text, _TEXT_ERROR_ADD);
249
		error_init(dllname);
239
    strcat(#error_text, lirary_path);
250
		return false;
-
 
251
	}
240
    strcat(#error_text, "' -E");
252
	return true;
241
    notify(#error_text);
253
}
242
}
254
 
243
 
255
 
244
 
256
#endif
245
#endif