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