Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
5725 serge 1
include 'proc32.inc'
2
 
3
format MS COFF
4
 
5
public _http_init
6
public _http_get@16
7
public _http_receive@4
8
public _http_free@4
9
 
10
section '.text' align 16
11
 
12
 
13
;void* __fastcall getprocaddr(export, name)
14
align 4
15
getprocaddress:
16
        push    esi
17
        push    edi
18
 
19
        xor     eax, eax
20
        test    ecx, ecx        ; If hlib = 0 then goto .end
21
        jz      .end
22
.next:
23
        cmp     [ecx], dword 0  ; If end of export table then goto .end
24
        jz      .end
25
 
26
        xor     eax, eax
27
        mov     esi, [ecx]
28
        mov     edi, edx        ; name
29
.next_:
30
        lodsb
31
        scasb
32
        jne     .fail
33
        or      al, al
34
        jnz     .next_
35
        jmp     .ok
36
.fail:
37
        add     ecx, 8
38
        jmp     .next
39
.ok:
40
        mov eax, [ecx + 4]      ; return address
41
.end:
42
        pop     edi
43
        pop     esi
44
        ret
45
 
46
 
47
;void fastcall dll_link(export, import)
48
 
49
align 4
50
dll_link:
51
        push    esi
52
        push    ecx
53
        mov     esi, edx
54
        test    esi, esi
55
        jz      .done
56
.next:
57
        mov     edx, [esi]
58
        test    edx, edx
59
        jz      .done
60
        mov     ecx, [esp]
61
        call    getprocaddress
62
        test    eax, eax
63
        jz      .done
64
        mov     [esi], eax
65
        add     esi, 4
66
        jmp     .next
67
.done:
68
        pop     ecx
69
        pop     esi
70
        ret
71
 
72
align 4
73
dll_load:
74
        push    ebp
75
        push    esi
76
        push    edi
77
 
78
        mov     ebp, [esp+16]
79
.next_lib:
80
        mov     edx, [ebp]
81
        test    edx, edx
82
        jz      .exit
83
 
84
        mov     esi, [ebp+4]
85
        mov     edi, s_libdir.fname
86
@@:
87
        lodsb
88
        stosb
89
        test  al, al
90
        jnz @b
91
 
92
        mov     eax, 68
93
        mov     ebx, 19
94
        mov     ecx, s_libdir
95
        int     0x40
96
        test    eax, eax
97
        jz      .fail
98
 
99
        mov     ecx, eax
100
        call    dll_link
101
        mov     eax, [ecx]
102
        cmp     dword[eax], 'lib_'
103
        jnz     @f
104
 
105
        mov     esi, [ecx+4]
106
 
107
        pushad
108
        mov     eax, mem.Alloc
109
        mov     ebx, mem.Free
110
        mov     ecx, mem.ReAlloc
111
        mov     edx, dll_load
112
        call    esi
113
        popad
114
@@:
115
        add     ebp, 8
116
        jmp     .next_lib
117
.exit:
118
        pop     edi
119
        pop     esi
120
        pop     ebp
121
        xor     eax, eax
122
        ret 4
123
.fail:
124
        pop     edi
125
        pop     esi
126
        pop     ebx
127
        inc     eax
128
        ret 4
129
 
130
align 4
131
_http_init:
132
 
133
        push    @IMPORT
134
        call    dll_load
135
        ret
136
 
137
align 4
138
_http_get@16:
139
        jmp     [HTTP_get]
140
 
141
align 4
142
_http_receive@4:
143
        jmp    [HTTP_receive]
144
 
145
align 4
146
_http_free@4:
147
        jmp    [HTTP_free]
148
 
149
proc mem.Alloc, size
150
        push    ebx ecx
151
        mov     ecx, [size]
152
        mov     eax, 68
153
        mov     ebx, 12
154
        int     0x40
155
        pop     ecx ebx
156
        ret
157
endp
158
;-----------------------------------------------------------------------------
159
proc mem.ReAlloc, mptr, size
160
        push    ebx ecx edx
161
        mov     ecx, [size]
162
        test    ecx, ecx
163
        jz      @f
164
@@:
165
        mov     edx, [mptr]
166
        test    edx, edx
167
        jz      @f
168
@@:
169
        mov     eax, 68
170
        mov     ebx, 20
171
        int     0x40
172
        test    eax, eax
173
        jz  @f
174
@@:
175
        pop edx ecx ebx
176
        ret
177
endp
178
;-----------------------------------------------------------------------------
179
proc mem.Free, mptr
180
        push    ebx ecx
181
        mov     ecx,[mptr]
182
        test    ecx,ecx
183
        jz  @f
184
@@:
185
        mov     eax, 68
186
        mov     ebx, 13
187
        int     0x40
188
        pop ecx ebx
189
        ret
190
endp
191
 
192
section '.data' align 16
193
 
194
; -------------------------
195
macro library [lname,fname]
196
{
197
  forward
198
    dd __#lname#_library_table__,__#lname#_library_name__
199
  common
200
    dd 0
201
  forward
202
    align 4
203
    __#lname#_library_name__ db fname,0
204
}
205
 
206
macro import lname,[name,sname]
207
{
208
  common
209
    align 4
210
    __#lname#_library_table__:
211
  forward
212
    if used name
213
      name dd __#name#_import_name__
214
    end if
215
  common
216
    dd 0
217
  forward
218
    if used name
219
      align 4
220
      __#name#_import_name__ db sname,0
221
    end if
222
}
223
 
224
align   4
225
@IMPORT:
226
 
227
library lib_http,       'http.obj'
228
 
229
import  lib_http, \
230
        HTTP_get,       'get', \
231
        HTTP_receive,   'receive', \
232
        HTTP_free,      'free'
233
 
234
s_libdir:
235
  db '/sys/lib/'
236
  .fname rb 32