Subversion Repositories Kolibri OS

Rev

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

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