Subversion Repositories Kolibri OS

Rev

Rev 6536 | Rev 9354 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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