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