Rev 8777 | Rev 9716 | Go to most recent revision | Details | Compare with Previous | 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 |
||
6536 | serge | 13 | public _con_getch2@0 |
8777 | turbocat | 14 | public _con_gets |
9354 | turbocat | 15 | public con_set_title as '_con_set_title_ptr' |
6068 | serge | 16 | |
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 ebx |
||
83 | push esi |
||
84 | push edi |
||
85 | |||
86 | mov ebp, [esp+20] |
||
87 | .next_lib: |
||
88 | mov edx, [ebp] |
||
89 | test edx, edx |
||
90 | jz .exit |
||
91 | |||
92 | mov esi, [ebp+4] |
||
93 | mov edi, s_libdir.fname |
||
94 | @@: |
||
95 | lodsb |
||
96 | stosb |
||
97 | test al, al |
||
98 | jnz @b |
||
99 | |||
100 | mov eax, 68 |
||
101 | mov ebx, 19 |
||
102 | mov ecx, s_libdir |
||
103 | int 0x40 |
||
104 | test eax, eax |
||
105 | jz .fail |
||
106 | |||
107 | mov ecx, eax |
||
108 | call dll_link |
||
109 | mov eax, [ecx] |
||
110 | cmp dword[eax], 'lib_' |
||
111 | jnz @f |
||
112 | |||
113 | mov esi, [ecx+4] |
||
114 | |||
115 | pushad |
||
116 | mov eax, mem.Alloc |
||
117 | mov ebx, mem.Free |
||
118 | mov ecx, mem.ReAlloc |
||
119 | mov edx, dll_load |
||
120 | call esi |
||
121 | popad |
||
122 | @@: |
||
123 | add ebp, 8 |
||
124 | jmp .next_lib |
||
125 | .exit: |
||
126 | pop edi |
||
127 | pop esi |
||
128 | pop ebx |
||
129 | pop ebp |
||
130 | xor eax, eax |
||
131 | ret 4 |
||
132 | .fail: |
||
133 | pop edi |
||
134 | pop esi |
||
135 | pop ebx |
||
136 | pop ebp |
||
137 | inc eax |
||
138 | ret 4 |
||
139 | |||
140 | align 4 |
||
141 | _load_libconsole: |
||
142 | push ebx |
||
143 | mov eax, 40 |
||
144 | mov ebx, 1 shl 8 |
||
145 | int 0x40 |
||
146 | pop ebx |
||
147 | |||
148 | push @IMPORT |
||
149 | call dll_load |
||
150 | test eax, eax |
||
151 | jnz .fail |
||
152 | push 1 |
||
153 | call [con_start] |
||
154 | xor eax, eax |
||
155 | .fail: |
||
156 | ret |
||
157 | |||
158 | align 4 |
||
159 | _con_init@20: |
||
160 | jmp [con_init] |
||
161 | |||
162 | align 4 |
||
163 | _con_exit@4: |
||
164 | jmp [con_exit] |
||
165 | |||
166 | align 4 |
||
167 | _con_write_string@8: |
||
168 | jmp [con_write_string] |
||
169 | |||
6536 | serge | 170 | _con_getch2@0: |
171 | jmp [con_getch2] |
||
172 | |||
8777 | turbocat | 173 | _con_gets: |
174 | jmp [con_gets] |
||
175 | |||
6068 | serge | 176 | _con_get_flags: |
177 | _con_set_flags@4: |
||
178 | _con_cls: |
||
179 | ret |
||
180 | |||
181 | |||
182 | proc mem.Alloc, size |
||
183 | push ebx ecx |
||
184 | mov ecx, [size] |
||
185 | mov eax, 68 |
||
186 | mov ebx, 12 |
||
187 | int 0x40 |
||
188 | pop ecx ebx |
||
189 | ret |
||
190 | endp |
||
191 | ;----------------------------------------------------------------------------- |
||
192 | proc mem.ReAlloc, mptr, size |
||
193 | push ebx ecx edx |
||
194 | mov ecx, [size] |
||
195 | test ecx, ecx |
||
196 | jz @f |
||
197 | @@: |
||
198 | mov edx, [mptr] |
||
199 | test edx, edx |
||
200 | jz @f |
||
201 | @@: |
||
202 | mov eax, 68 |
||
203 | mov ebx, 20 |
||
204 | int 0x40 |
||
205 | test eax, eax |
||
206 | jz @f |
||
207 | @@: |
||
208 | pop edx ecx ebx |
||
209 | ret |
||
210 | endp |
||
211 | ;----------------------------------------------------------------------------- |
||
212 | proc mem.Free, mptr |
||
213 | push ebx ecx |
||
214 | mov ecx,[mptr] |
||
215 | test ecx,ecx |
||
216 | jz @f |
||
217 | @@: |
||
218 | mov eax, 68 |
||
219 | mov ebx, 13 |
||
220 | int 0x40 |
||
221 | pop ecx ebx |
||
222 | ret |
||
223 | endp |
||
224 | |||
225 | ;section '.ctors' align 4 |
||
226 | ;align 4 |
||
227 | ;dd _load_libconsole |
||
228 | |||
229 | section '.data' align 16 |
||
230 | |||
231 | ; ------------------------- |
||
232 | macro library [lname,fname] |
||
233 | { |
||
234 | forward |
||
235 | dd __#lname#_library_table__,__#lname#_library_name__ |
||
236 | common |
||
237 | dd 0 |
||
238 | forward |
||
239 | align 4 |
||
240 | __#lname#_library_name__ db fname,0 |
||
241 | } |
||
242 | |||
243 | macro import lname,[name,sname] |
||
244 | { |
||
245 | common |
||
246 | align 4 |
||
247 | __#lname#_library_table__: |
||
248 | forward |
||
249 | if used name |
||
250 | name dd __#name#_import_name__ |
||
251 | end if |
||
252 | common |
||
253 | dd 0 |
||
254 | forward |
||
255 | if used name |
||
256 | align 4 |
||
257 | __#name#_import_name__ db sname,0 |
||
258 | end if |
||
259 | } |
||
260 | |||
261 | align 4 |
||
262 | @IMPORT: |
||
263 | |||
264 | library console, 'console.obj' |
||
265 | |||
266 | import console, \ |
||
267 | con_start, 'START', \ |
||
268 | con_init, 'con_init', \ |
||
269 | con_exit, 'con_exit', \ |
||
270 | con_gets, 'con_gets', \ |
||
271 | con_cls, 'con_cls', \ |
||
272 | con_getch2, 'con_getch2', \ |
||
273 | con_set_cursor_pos, 'con_set_cursor_pos',\ |
||
274 | con_write_string, 'con_write_string',\ |
||
275 | con_get_flags, 'con_get_flags', \ |
||
9354 | turbocat | 276 | con_set_flags, 'con_set_flags', \ |
277 | con_set_title, 'con_set_title' |
||
6068 | serge | 278 | |
279 | s_libdir: |
||
280 | db '/sys/lib/' |
||
281 | .fname rb 32 |