Subversion Repositories Kolibri OS

Rev

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

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