Subversion Repositories Kolibri OS

Rev

Rev 5725 | Details | Compare with Previous | 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
 
5731 serge 10
public _con_init@20
11
public _con_exit@4
12
public _con_get_flags
13
public _con_set_flags@4
14
public _con_cls
15
public _con_write_asciiz@4
16
 
5725 serge 17
section '.text' align 16
18
 
19
 
20
;void* __fastcall getprocaddr(export, name)
21
align 4
22
getprocaddress:
23
        push    esi
24
        push    edi
25
 
26
        xor     eax, eax
27
        test    ecx, ecx        ; If hlib = 0 then goto .end
28
        jz      .end
29
.next:
30
        cmp     [ecx], dword 0  ; If end of export table then goto .end
31
        jz      .end
32
 
33
        xor     eax, eax
34
        mov     esi, [ecx]
35
        mov     edi, edx        ; name
36
.next_:
37
        lodsb
38
        scasb
39
        jne     .fail
40
        or      al, al
41
        jnz     .next_
42
        jmp     .ok
43
.fail:
44
        add     ecx, 8
45
        jmp     .next
46
.ok:
47
        mov eax, [ecx + 4]      ; return address
48
.end:
49
        pop     edi
50
        pop     esi
51
        ret
52
 
53
 
54
;void fastcall dll_link(export, import)
55
 
56
align 4
57
dll_link:
58
        push    esi
59
        push    ecx
60
        mov     esi, edx
61
        test    esi, esi
62
        jz      .done
63
.next:
64
        mov     edx, [esi]
65
        test    edx, edx
66
        jz      .done
67
        mov     ecx, [esp]
68
        call    getprocaddress
69
        test    eax, eax
70
        jz      .done
71
        mov     [esi], eax
72
        add     esi, 4
73
        jmp     .next
74
.done:
75
        pop     ecx
76
        pop     esi
77
        ret
78
 
79
align 4
80
dll_load:
81
        push    ebp
82
        push    esi
83
        push    edi
84
 
85
        mov     ebp, [esp+16]
86
.next_lib:
87
        mov     edx, [ebp]
88
        test    edx, edx
89
        jz      .exit
90
 
91
        mov     esi, [ebp+4]
92
        mov     edi, s_libdir.fname
93
@@:
94
        lodsb
95
        stosb
96
        test  al, al
97
        jnz @b
98
 
99
        mov     eax, 68
100
        mov     ebx, 19
101
        mov     ecx, s_libdir
102
        int     0x40
103
        test    eax, eax
104
        jz      .fail
105
 
106
        mov     ecx, eax
107
        call    dll_link
108
        mov     eax, [ecx]
109
        cmp     dword[eax], 'lib_'
110
        jnz     @f
111
 
112
        mov     esi, [ecx+4]
113
 
114
        pushad
115
        mov     eax, mem.Alloc
116
        mov     ebx, mem.Free
117
        mov     ecx, mem.ReAlloc
118
        mov     edx, dll_load
119
        call    esi
120
        popad
121
@@:
122
        add     ebp, 8
123
        jmp     .next_lib
124
.exit:
125
        pop     edi
126
        pop     esi
127
        pop     ebp
128
        xor     eax, eax
129
        ret 4
130
.fail:
131
        pop     edi
132
        pop     esi
133
        pop     ebx
134
        inc     eax
135
        ret 4
136
 
137
align 4
138
_http_init:
5731 serge 139
        push    ebx
140
        mov     eax, 40
141
        mov     ebx, 1 shl 8
142
        int     0x40
143
        pop     ebx
5725 serge 144
 
145
        push    @IMPORT
146
        call    dll_load
5731 serge 147
        test    eax, eax
148
        jnz     .fail
149
        push    1
150
        call    [con_start]
151
        xor     eax, eax
152
.fail:
5725 serge 153
        ret
154
 
155
align 4
156
_http_get@16:
157
        jmp     [HTTP_get]
158
 
159
align 4
160
_http_receive@4:
5731 serge 161
        jmp     [HTTP_receive]
5725 serge 162
 
163
align 4
164
_http_free@4:
5731 serge 165
        jmp     [HTTP_free]
5725 serge 166
 
5731 serge 167
align 4
168
_con_init@20:
169
        jmp     [con_init]
170
 
171
align 4
172
_con_exit@4:
173
        jmp     [con_exit]
174
 
175
align 4
176
_con_write_asciiz@4:
177
        jmp     [con_write_asciiz]
178
 
179
_con_get_flags:
180
_con_set_flags@4:
181
_con_cls:
182
        ret
183
 
184
 
5725 serge 185
proc mem.Alloc, size
186
        push    ebx ecx
187
        mov     ecx, [size]
188
        mov     eax, 68
189
        mov     ebx, 12
190
        int     0x40
191
        pop     ecx ebx
192
        ret
193
endp
194
;-----------------------------------------------------------------------------
195
proc mem.ReAlloc, mptr, size
196
        push    ebx ecx edx
197
        mov     ecx, [size]
198
        test    ecx, ecx
199
        jz      @f
200
@@:
201
        mov     edx, [mptr]
202
        test    edx, edx
203
        jz      @f
204
@@:
205
        mov     eax, 68
206
        mov     ebx, 20
207
        int     0x40
208
        test    eax, eax
209
        jz  @f
210
@@:
211
        pop edx ecx ebx
212
        ret
213
endp
214
;-----------------------------------------------------------------------------
215
proc mem.Free, mptr
216
        push    ebx ecx
217
        mov     ecx,[mptr]
218
        test    ecx,ecx
219
        jz  @f
220
@@:
221
        mov     eax, 68
222
        mov     ebx, 13
223
        int     0x40
224
        pop ecx ebx
225
        ret
226
endp
227
 
228
section '.data' align 16
229
 
230
; -------------------------
231
macro library [lname,fname]
232
{
233
  forward
234
    dd __#lname#_library_table__,__#lname#_library_name__
235
  common
236
    dd 0
237
  forward
238
    align 4
239
    __#lname#_library_name__ db fname,0
240
}
241
 
242
macro import lname,[name,sname]
243
{
244
  common
245
    align 4
246
    __#lname#_library_table__:
247
  forward
248
    if used name
249
      name dd __#name#_import_name__
250
    end if
251
  common
252
    dd 0
253
  forward
254
    if used name
255
      align 4
256
      __#name#_import_name__ db sname,0
257
    end if
258
}
259
 
260
align   4
261
@IMPORT:
262
 
5731 serge 263
library lib_http,       'http.obj', \
264
        console,        'console.obj'
5725 serge 265
 
5731 serge 266
import  lib_http,                   \
267
        HTTP_get,       'get',      \
268
        HTTP_receive,   'receive',  \
5725 serge 269
        HTTP_free,      'free'
270
 
5731 serge 271
import  console,                            \
272
        con_start,      'START',            \
273
        con_init,       'con_init',         \
274
        con_write_asciiz,'con_write_asciiz',\
275
        con_exit,       'con_exit',         \
276
        con_gets,       'con_gets',         \
277
        con_cls,        'con_cls',          \
278
        con_getch2,     'con_getch2',       \
279
        con_set_cursor_pos, 'con_set_cursor_pos',\
280
        con_write_string, 'con_write_string',\
281
        con_get_flags,  'con_get_flags',    \
282
        con_set_flags,  'con_set_flags'
283
 
5725 serge 284
s_libdir:
285
  db '/sys/lib/'
286
  .fname rb 32