Subversion Repositories Kolibri OS

Rev

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

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