Rev 2987 | Rev 3500 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2987 | Rev 3232 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2012. All rights reserved. ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
4 | ;; Distributed under terms of the GNU General Public License ;; |
5 | ;; ;; |
5 | ;; ;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | 7 | ||
8 | $Revision: 2987 $ |
8 | $Revision: 3232 $ |
9 | 9 | ||
10 | 10 | ||
11 | DRV_COMPAT equ 5 ;minimal required drivers version |
11 | DRV_COMPAT equ 5 ;minimal required drivers version |
12 | DRV_CURRENT equ 6 ;current drivers model version |
12 | DRV_CURRENT equ 6 ;current drivers model version |
13 | 13 | ||
14 | DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT |
14 | DRV_VERSION equ (DRV_COMPAT shl 16) or DRV_CURRENT |
15 | PID_KERNEL equ 1 ;os_idle thread |
15 | PID_KERNEL equ 1 ;os_idle thread |
16 | 16 | ||
17 | 17 | ||
18 | 18 | ||
19 | align 4 |
19 | align 4 |
20 | proc get_notify stdcall, p_ev:dword |
20 | proc get_notify stdcall, p_ev:dword |
21 | 21 | ||
22 | .wait: |
22 | .wait: |
23 | mov ebx, [current_slot] |
23 | mov ebx, [current_slot] |
24 | test dword [ebx+APPDATA.event_mask], EVENT_NOTIFY |
24 | test dword [ebx+APPDATA.event_mask], EVENT_NOTIFY |
25 | jz @f |
25 | jz @f |
26 | and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY |
26 | and dword [ebx+APPDATA.event_mask], not EVENT_NOTIFY |
27 | mov edi, [p_ev] |
27 | mov edi, [p_ev] |
28 | mov dword [edi], EV_INTR |
28 | mov dword [edi], EV_INTR |
29 | mov eax, [ebx+APPDATA.event] |
29 | mov eax, [ebx+APPDATA.event] |
30 | mov dword [edi+4], eax |
30 | mov dword [edi+4], eax |
31 | ret |
31 | ret |
32 | @@: |
32 | @@: |
33 | call change_task |
33 | call change_task |
34 | jmp .wait |
34 | jmp .wait |
35 | endp |
35 | endp |
36 | 36 | ||
37 | align 4 |
37 | align 4 |
38 | proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword |
38 | proc pci_read32 stdcall, bus:dword, devfn:dword, reg:dword |
39 | push ebx |
39 | push ebx |
40 | xor eax, eax |
40 | xor eax, eax |
41 | xor ebx, ebx |
41 | xor ebx, ebx |
42 | mov ah, byte [bus] |
42 | mov ah, byte [bus] |
43 | mov al, 6 |
43 | mov al, 6 |
44 | mov bh, byte [devfn] |
44 | mov bh, byte [devfn] |
45 | mov bl, byte [reg] |
45 | mov bl, byte [reg] |
46 | call pci_read_reg |
46 | call pci_read_reg |
47 | pop ebx |
47 | pop ebx |
48 | ret |
48 | ret |
49 | endp |
49 | endp |
50 | 50 | ||
51 | align 4 |
51 | align 4 |
52 | proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword |
52 | proc pci_read16 stdcall, bus:dword, devfn:dword, reg:dword |
53 | push ebx |
53 | push ebx |
54 | xor eax, eax |
54 | xor eax, eax |
55 | xor ebx, ebx |
55 | xor ebx, ebx |
56 | mov ah, byte [bus] |
56 | mov ah, byte [bus] |
57 | mov al, 5 |
57 | mov al, 5 |
58 | mov bh, byte [devfn] |
58 | mov bh, byte [devfn] |
59 | mov bl, byte [reg] |
59 | mov bl, byte [reg] |
60 | call pci_read_reg |
60 | call pci_read_reg |
61 | pop ebx |
61 | pop ebx |
62 | ret |
62 | ret |
63 | endp |
63 | endp |
64 | 64 | ||
65 | align 4 |
65 | align 4 |
66 | proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword |
66 | proc pci_read8 stdcall, bus:dword, devfn:dword, reg:dword |
67 | push ebx |
67 | push ebx |
68 | xor eax, eax |
68 | xor eax, eax |
69 | xor ebx, ebx |
69 | xor ebx, ebx |
70 | mov ah, byte [bus] |
70 | mov ah, byte [bus] |
71 | mov al, 4 |
71 | mov al, 4 |
72 | mov bh, byte [devfn] |
72 | mov bh, byte [devfn] |
73 | mov bl, byte [reg] |
73 | mov bl, byte [reg] |
74 | call pci_read_reg |
74 | call pci_read_reg |
75 | pop ebx |
75 | pop ebx |
76 | ret |
76 | ret |
77 | endp |
77 | endp |
78 | 78 | ||
79 | align 4 |
79 | align 4 |
80 | proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
80 | proc pci_write8 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
81 | push ebx |
81 | push ebx |
82 | xor eax, eax |
82 | xor eax, eax |
83 | xor ebx, ebx |
83 | xor ebx, ebx |
84 | mov ah, byte [bus] |
84 | mov ah, byte [bus] |
85 | mov al, 8 |
85 | mov al, 8 |
86 | mov bh, byte [devfn] |
86 | mov bh, byte [devfn] |
87 | mov bl, byte [reg] |
87 | mov bl, byte [reg] |
88 | mov ecx, [val] |
88 | mov ecx, [val] |
89 | call pci_write_reg |
89 | call pci_write_reg |
90 | pop ebx |
90 | pop ebx |
91 | ret |
91 | ret |
92 | endp |
92 | endp |
93 | 93 | ||
94 | align 4 |
94 | align 4 |
95 | proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
95 | proc pci_write16 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
96 | push ebx |
96 | push ebx |
97 | xor eax, eax |
97 | xor eax, eax |
98 | xor ebx, ebx |
98 | xor ebx, ebx |
99 | mov ah, byte [bus] |
99 | mov ah, byte [bus] |
100 | mov al, 9 |
100 | mov al, 9 |
101 | mov bh, byte [devfn] |
101 | mov bh, byte [devfn] |
102 | mov bl, byte [reg] |
102 | mov bl, byte [reg] |
103 | mov ecx, [val] |
103 | mov ecx, [val] |
104 | call pci_write_reg |
104 | call pci_write_reg |
105 | pop ebx |
105 | pop ebx |
106 | ret |
106 | ret |
107 | endp |
107 | endp |
108 | 108 | ||
109 | align 4 |
109 | align 4 |
110 | proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
110 | proc pci_write32 stdcall, bus:dword, devfn:dword, reg:dword, val:dword |
111 | push ebx |
111 | push ebx |
112 | xor eax, eax |
112 | xor eax, eax |
113 | xor ebx, ebx |
113 | xor ebx, ebx |
114 | mov ah, byte [bus] |
114 | mov ah, byte [bus] |
115 | mov al, 10 |
115 | mov al, 10 |
116 | mov bh, byte [devfn] |
116 | mov bh, byte [devfn] |
117 | mov bl, byte [reg] |
117 | mov bl, byte [reg] |
118 | mov ecx, [val] |
118 | mov ecx, [val] |
119 | call pci_write_reg |
119 | call pci_write_reg |
120 | pop ebx |
120 | pop ebx |
121 | ret |
121 | ret |
122 | endp |
122 | endp |
123 | 123 | ||
124 | handle equ IOCTL.handle |
124 | handle equ IOCTL.handle |
125 | io_code equ IOCTL.io_code |
125 | io_code equ IOCTL.io_code |
126 | input equ IOCTL.input |
126 | input equ IOCTL.input |
127 | inp_size equ IOCTL.inp_size |
127 | inp_size equ IOCTL.inp_size |
128 | output equ IOCTL.output |
128 | output equ IOCTL.output |
129 | out_size equ IOCTL.out_size |
129 | out_size equ IOCTL.out_size |
130 | 130 | ||
131 | 131 | ||
132 | align 4 |
132 | align 4 |
133 | proc srv_handler stdcall, ioctl:dword |
133 | proc srv_handler stdcall, ioctl:dword |
134 | mov esi, [ioctl] |
134 | mov esi, [ioctl] |
135 | test esi, esi |
135 | test esi, esi |
136 | jz .err |
136 | jz .err |
137 | 137 | ||
138 | mov edi, [esi+handle] |
138 | mov edi, [esi+handle] |
139 | cmp [edi+SRV.magic], ' SRV' |
139 | cmp [edi+SRV.magic], ' SRV' |
140 | jne .fail |
140 | jne .fail |
141 | 141 | ||
142 | cmp [edi+SRV.size], sizeof.SRV |
142 | cmp [edi+SRV.size], sizeof.SRV |
143 | jne .fail |
143 | jne .fail |
144 | 144 | ||
145 | stdcall [edi+SRV.srv_proc], esi |
145 | stdcall [edi+SRV.srv_proc], esi |
146 | ret |
146 | ret |
147 | .fail: |
147 | .fail: |
148 | xor eax, eax |
148 | xor eax, eax |
149 | not eax |
149 | not eax |
150 | mov [esi+output], eax |
150 | mov [esi+output], eax |
151 | mov [esi+out_size], 4 |
151 | mov [esi+out_size], 4 |
152 | ret |
152 | ret |
153 | .err: |
153 | .err: |
154 | xor eax, eax |
154 | xor eax, eax |
155 | not eax |
155 | not eax |
156 | ret |
156 | ret |
157 | endp |
157 | endp |
158 | 158 | ||
159 | ; param |
159 | ; param |
160 | ; ecx= io_control |
160 | ; ecx= io_control |
161 | ; |
161 | ; |
162 | ; retval |
162 | ; retval |
163 | ; eax= error code |
163 | ; eax= error code |
164 | 164 | ||
165 | align 4 |
165 | align 4 |
166 | srv_handlerEx: |
166 | srv_handlerEx: |
167 | cmp ecx, OS_BASE |
167 | cmp ecx, OS_BASE |
168 | jae .fail |
168 | jae .fail |
169 | 169 | ||
170 | mov eax, [ecx+handle] |
170 | mov eax, [ecx+handle] |
171 | cmp [eax+SRV.magic], ' SRV' |
171 | cmp [eax+SRV.magic], ' SRV' |
172 | jne .fail |
172 | jne .fail |
173 | 173 | ||
174 | cmp [eax+SRV.size], sizeof.SRV |
174 | cmp [eax+SRV.size], sizeof.SRV |
175 | jne .fail |
175 | jne .fail |
176 | 176 | ||
177 | stdcall [eax+SRV.srv_proc], ecx |
177 | stdcall [eax+SRV.srv_proc], ecx |
178 | ret |
178 | ret |
179 | .fail: |
179 | .fail: |
180 | or eax, -1 |
180 | or eax, -1 |
181 | ret |
181 | ret |
182 | 182 | ||
183 | restore handle |
183 | restore handle |
184 | restore io_code |
184 | restore io_code |
185 | restore input |
185 | restore input |
186 | restore inp_size |
186 | restore inp_size |
187 | restore output |
187 | restore output |
188 | restore out_size |
188 | restore out_size |
189 | 189 | ||
190 | align 4 |
190 | align 4 |
191 | proc get_service stdcall, sz_name:dword |
191 | proc get_service stdcall, sz_name:dword |
192 | mov eax, [sz_name] |
192 | mov eax, [sz_name] |
193 | test eax, eax |
193 | test eax, eax |
194 | jnz @F |
194 | jnz @F |
195 | ret |
195 | ret |
196 | @@: |
196 | @@: |
197 | mov edx, [srv.fd] |
197 | mov edx, [srv.fd] |
198 | @@: |
198 | @@: |
199 | cmp edx, srv.fd-SRV.fd |
199 | cmp edx, srv.fd-SRV.fd |
200 | je .not_load |
200 | je .not_load |
201 | 201 | ||
202 | stdcall strncmp, edx, [sz_name], 16 |
202 | stdcall strncmp, edx, [sz_name], 16 |
203 | test eax, eax |
203 | test eax, eax |
204 | je .ok |
204 | je .ok |
205 | 205 | ||
206 | mov edx, [edx+SRV.fd] |
206 | mov edx, [edx+SRV.fd] |
207 | jmp @B |
207 | jmp @B |
208 | .not_load: |
208 | .not_load: |
209 | pop ebp |
209 | pop ebp |
210 | jmp load_driver |
210 | jmp load_driver |
211 | .ok: |
211 | .ok: |
212 | mov eax, edx |
212 | mov eax, edx |
213 | ret |
213 | ret |
214 | endp |
214 | endp |
215 | 215 | ||
216 | align 4 |
216 | align 4 |
217 | proc reg_service stdcall, name:dword, handler:dword |
217 | proc reg_service stdcall, name:dword, handler:dword |
218 | 218 | ||
219 | push ebx |
219 | push ebx |
220 | 220 | ||
221 | xor eax, eax |
221 | xor eax, eax |
222 | 222 | ||
223 | cmp [name], eax |
223 | cmp [name], eax |
224 | je .fail |
224 | je .fail |
225 | 225 | ||
226 | cmp [handler], eax |
226 | cmp [handler], eax |
227 | je .fail |
227 | je .fail |
228 | 228 | ||
229 | mov eax, sizeof.SRV |
229 | mov eax, sizeof.SRV |
230 | call malloc |
230 | call malloc |
231 | test eax, eax |
231 | test eax, eax |
232 | jz .fail |
232 | jz .fail |
233 | 233 | ||
234 | push esi |
234 | push esi |
235 | push edi |
235 | push edi |
236 | mov edi, eax |
236 | mov edi, eax |
237 | mov esi, [name] |
237 | mov esi, [name] |
238 | movsd |
238 | movsd |
239 | movsd |
239 | movsd |
240 | movsd |
240 | movsd |
241 | movsd |
241 | movsd |
242 | pop edi |
242 | pop edi |
243 | pop esi |
243 | pop esi |
244 | 244 | ||
245 | mov [eax+SRV.magic], ' SRV' |
245 | mov [eax+SRV.magic], ' SRV' |
246 | mov [eax+SRV.size], sizeof.SRV |
246 | mov [eax+SRV.size], sizeof.SRV |
247 | 247 | ||
248 | mov ebx, srv.fd-SRV.fd |
248 | mov ebx, srv.fd-SRV.fd |
249 | mov edx, [ebx+SRV.fd] |
249 | mov edx, [ebx+SRV.fd] |
250 | mov [eax+SRV.fd], edx |
250 | mov [eax+SRV.fd], edx |
251 | mov [eax+SRV.bk], ebx |
251 | mov [eax+SRV.bk], ebx |
252 | mov [ebx+SRV.fd], eax |
252 | mov [ebx+SRV.fd], eax |
253 | mov [edx+SRV.bk], eax |
253 | mov [edx+SRV.bk], eax |
254 | 254 | ||
255 | mov ecx, [handler] |
255 | mov ecx, [handler] |
256 | mov [eax+SRV.srv_proc], ecx |
256 | mov [eax+SRV.srv_proc], ecx |
257 | pop ebx |
257 | pop ebx |
258 | ret |
258 | ret |
259 | .fail: |
259 | .fail: |
260 | xor eax, eax |
260 | xor eax, eax |
261 | pop ebx |
261 | pop ebx |
262 | ret |
262 | ret |
263 | endp |
263 | endp |
264 | 264 | ||
265 | align 4 |
265 | align 4 |
266 | proc get_proc stdcall, exp:dword, sz_name:dword |
266 | proc get_proc stdcall, exp:dword, sz_name:dword |
267 | 267 | ||
268 | mov edx, [exp] |
268 | mov edx, [exp] |
269 | .next: |
269 | .next: |
270 | mov eax, [edx] |
270 | mov eax, [edx] |
271 | test eax, eax |
271 | test eax, eax |
272 | jz .end |
272 | jz .end |
273 | 273 | ||
274 | push edx |
274 | push edx |
275 | stdcall strncmp, eax, [sz_name], 16 |
275 | stdcall strncmp, eax, [sz_name], 16 |
276 | pop edx |
276 | pop edx |
277 | test eax, eax |
277 | test eax, eax |
278 | jz .ok |
278 | jz .ok |
279 | 279 | ||
280 | add edx, 8 |
280 | add edx, 8 |
281 | jmp .next |
281 | jmp .next |
282 | .ok: |
282 | .ok: |
283 | mov eax, [edx+4] |
283 | mov eax, [edx+4] |
284 | .end: |
284 | .end: |
285 | ret |
285 | ret |
286 | endp |
286 | endp |
287 | 287 | ||
288 | align 4 |
288 | align 4 |
289 | proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword |
289 | proc get_coff_sym stdcall, pSym:dword,count:dword, sz_sym:dword |
290 | 290 | ||
291 | @@: |
291 | @@: |
292 | stdcall strncmp, [pSym], [sz_sym], 8 |
292 | stdcall strncmp, [pSym], [sz_sym], 8 |
293 | test eax, eax |
293 | test eax, eax |
294 | jz .ok |
294 | jz .ok |
295 | add [pSym], 18 |
295 | add [pSym], 18 |
296 | dec [count] |
296 | dec [count] |
297 | jnz @b |
297 | jnz @b |
298 | xor eax, eax |
298 | xor eax, eax |
299 | ret |
299 | ret |
300 | .ok: |
300 | .ok: |
301 | mov eax, [pSym] |
301 | mov eax, [pSym] |
302 | mov eax, [eax+8] |
302 | mov eax, [eax+8] |
303 | ret |
303 | ret |
304 | endp |
304 | endp |
305 | 305 | ||
306 | align 4 |
306 | align 4 |
307 | proc get_curr_task |
307 | proc get_curr_task |
308 | mov eax, [CURRENT_TASK] |
308 | mov eax, [CURRENT_TASK] |
309 | shl eax, 8 |
309 | shl eax, 8 |
310 | ret |
310 | ret |
311 | endp |
311 | endp |
312 | 312 | ||
313 | align 4 |
313 | align 4 |
314 | proc get_fileinfo stdcall, file_name:dword, info:dword |
314 | proc get_fileinfo stdcall, file_name:dword, info:dword |
315 | locals |
315 | locals |
316 | cmd dd ? |
316 | cmd dd ? |
317 | offset dd ? |
317 | offset dd ? |
318 | dd ? |
318 | dd ? |
319 | count dd ? |
319 | count dd ? |
320 | buff dd ? |
320 | buff dd ? |
321 | db ? |
321 | db ? |
322 | name dd ? |
322 | name dd ? |
323 | endl |
323 | endl |
324 | 324 | ||
325 | xor eax, eax |
325 | xor eax, eax |
326 | mov ebx, [file_name] |
326 | mov ebx, [file_name] |
327 | mov ecx, [info] |
327 | mov ecx, [info] |
328 | 328 | ||
329 | mov [cmd], 5 |
329 | mov [cmd], 5 |
330 | mov [offset], eax |
330 | mov [offset], eax |
331 | mov [offset+4], eax |
331 | mov [offset+4], eax |
332 | mov [count], eax |
332 | mov [count], eax |
333 | mov [buff], ecx |
333 | mov [buff], ecx |
334 | mov byte [buff+4], al |
334 | mov byte [buff+4], al |
335 | mov [name], ebx |
335 | mov [name], ebx |
336 | 336 | ||
337 | mov eax, 70 |
337 | mov eax, 70 |
338 | lea ebx, [cmd] |
338 | lea ebx, [cmd] |
339 | int 0x40 |
339 | int 0x40 |
340 | ret |
340 | ret |
341 | endp |
341 | endp |
342 | 342 | ||
343 | align 4 |
343 | align 4 |
344 | proc read_file stdcall,file_name:dword, buffer:dword, off:dword,\ |
344 | proc read_file stdcall,file_name:dword, buffer:dword, off:dword,\ |
345 | bytes:dword |
345 | bytes:dword |
346 | locals |
346 | locals |
347 | cmd dd ? |
347 | cmd dd ? |
348 | offset dd ? |
348 | offset dd ? |
349 | dd ? |
349 | dd ? |
350 | count dd ? |
350 | count dd ? |
351 | buff dd ? |
351 | buff dd ? |
352 | db ? |
352 | db ? |
353 | name dd ? |
353 | name dd ? |
354 | endl |
354 | endl |
355 | 355 | ||
356 | xor eax, eax |
356 | xor eax, eax |
357 | mov ebx, [file_name] |
357 | mov ebx, [file_name] |
358 | mov ecx, [off] |
358 | mov ecx, [off] |
359 | mov edx, [bytes] |
359 | mov edx, [bytes] |
360 | mov esi, [buffer] |
360 | mov esi, [buffer] |
361 | 361 | ||
362 | mov [cmd], eax |
362 | mov [cmd], eax |
363 | mov [offset], ecx |
363 | mov [offset], ecx |
364 | mov [offset+4], eax |
364 | mov [offset+4], eax |
365 | mov [count], edx |
365 | mov [count], edx |
366 | mov [buff], esi |
366 | mov [buff], esi |
367 | mov byte [buff+4], al |
367 | mov byte [buff+4], al |
368 | mov [name], ebx |
368 | mov [name], ebx |
369 | 369 | ||
370 | pushad |
370 | pushad |
371 | lea ebx, [cmd] |
371 | lea ebx, [cmd] |
372 | call file_system_lfn |
372 | call file_system_lfn |
373 | popad |
373 | popad |
374 | ret |
374 | ret |
375 | endp |
375 | endp |
376 | 376 | ||
377 | ; description |
377 | ; description |
378 | ; allocate kernel memory and loads the specified file |
378 | ; allocate kernel memory and loads the specified file |
379 | ; |
379 | ; |
380 | ; param |
380 | ; param |
381 | ; file_name= full path to file |
381 | ; file_name= full path to file |
382 | ; |
382 | ; |
383 | ; retval |
383 | ; retval |
384 | ; eax= file image in kernel memory |
384 | ; eax= file image in kernel memory |
385 | ; ebx= size of file |
385 | ; ebx= size of file |
386 | ; |
386 | ; |
387 | ; warging |
387 | ; warging |
388 | ; You mast call kernel_free() to delete each file |
388 | ; You mast call kernel_free() to delete each file |
389 | ; loaded by the load_file() function |
389 | ; loaded by the load_file() function |
390 | 390 | ||
391 | align 4 |
391 | align 4 |
392 | proc load_file stdcall, file_name:dword |
392 | proc load_file stdcall, file_name:dword |
393 | locals |
393 | locals |
394 | attr dd ? |
394 | attr dd ? |
395 | flags dd ? |
395 | flags dd ? |
396 | cr_time dd ? |
396 | cr_time dd ? |
397 | cr_date dd ? |
397 | cr_date dd ? |
398 | acc_time dd ? |
398 | acc_time dd ? |
399 | acc_date dd ? |
399 | acc_date dd ? |
400 | mod_time dd ? |
400 | mod_time dd ? |
401 | mod_date dd ? |
401 | mod_date dd ? |
402 | file_size dd ? |
402 | file_size dd ? |
403 | 403 | ||
404 | file dd ? |
404 | file dd ? |
405 | file2 dd ? |
405 | file2 dd ? |
406 | endl |
406 | endl |
407 | 407 | ||
408 | push esi |
408 | push esi |
409 | push edi |
409 | push edi |
410 | 410 | ||
411 | lea eax, [attr] |
411 | lea eax, [attr] |
412 | stdcall get_fileinfo, [file_name], eax |
412 | stdcall get_fileinfo, [file_name], eax |
413 | test eax, eax |
413 | test eax, eax |
414 | jnz .fail |
414 | jnz .fail |
415 | 415 | ||
416 | mov eax, [file_size] |
416 | mov eax, [file_size] |
417 | cmp eax, 1024*1024*16 |
417 | cmp eax, 1024*1024*16 |
418 | ja .fail |
418 | ja .fail |
419 | 419 | ||
420 | stdcall kernel_alloc, [file_size] |
420 | stdcall kernel_alloc, [file_size] |
421 | mov [file], eax |
421 | mov [file], eax |
422 | test eax, eax |
422 | test eax, eax |
423 | jz .fail |
423 | jz .fail |
424 | 424 | ||
425 | stdcall read_file, [file_name], eax, dword 0, [file_size] |
425 | stdcall read_file, [file_name], eax, dword 0, [file_size] |
426 | cmp ebx, [file_size] |
426 | cmp ebx, [file_size] |
427 | jne .cleanup |
427 | jne .cleanup |
428 | 428 | ||
429 | mov eax, [file] |
429 | mov eax, [file] |
430 | cmp dword [eax], 0x4B43504B |
430 | cmp dword [eax], 0x4B43504B |
431 | jne .exit |
431 | jne .exit |
432 | mov ebx, [eax+4] |
432 | mov ebx, [eax+4] |
433 | mov [file_size], ebx |
433 | mov [file_size], ebx |
434 | stdcall kernel_alloc, ebx |
434 | stdcall kernel_alloc, ebx |
435 | 435 | ||
436 | test eax, eax |
436 | test eax, eax |
437 | jz .cleanup |
437 | jz .cleanup |
438 | 438 | ||
439 | mov [file2], eax |
439 | mov [file2], eax |
440 | 440 | ||
441 | pushad |
441 | pushad |
442 | mov ecx, unpack_mutex |
442 | mov ecx, unpack_mutex |
443 | call mutex_lock |
443 | call mutex_lock |
444 | popad |
444 | popad |
445 | 445 | ||
446 | stdcall unpack, [file], eax |
446 | stdcall unpack, [file], eax |
447 | 447 | ||
448 | pushad |
448 | pushad |
449 | mov ecx, unpack_mutex |
449 | mov ecx, unpack_mutex |
450 | call mutex_unlock |
450 | call mutex_unlock |
451 | popad |
451 | popad |
452 | 452 | ||
453 | stdcall kernel_free, [file] |
453 | stdcall kernel_free, [file] |
454 | mov eax, [file2] |
454 | mov eax, [file2] |
455 | mov ebx, [file_size] |
455 | mov ebx, [file_size] |
456 | .exit: |
456 | .exit: |
457 | push eax |
457 | push eax |
458 | lea edi, [eax+ebx] ;cleanup remain space |
458 | lea edi, [eax+ebx] ;cleanup remain space |
459 | mov ecx, 4096 ;from file end |
459 | mov ecx, 4096 ;from file end |
460 | and ebx, 4095 |
460 | and ebx, 4095 |
461 | jz @f |
461 | jz @f |
462 | sub ecx, ebx |
462 | sub ecx, ebx |
463 | xor eax, eax |
463 | xor eax, eax |
464 | cld |
464 | cld |
465 | rep stosb |
465 | rep stosb |
466 | @@: |
466 | @@: |
467 | mov ebx, [file_size] |
467 | mov ebx, [file_size] |
468 | pop eax |
468 | pop eax |
469 | pop edi |
469 | pop edi |
470 | pop esi |
470 | pop esi |
471 | ret |
471 | ret |
472 | .cleanup: |
472 | .cleanup: |
473 | stdcall kernel_free, [file] |
473 | stdcall kernel_free, [file] |
474 | .fail: |
474 | .fail: |
475 | xor eax, eax |
475 | xor eax, eax |
476 | xor ebx, ebx |
476 | xor ebx, ebx |
477 | pop edi |
477 | pop edi |
478 | pop esi |
478 | pop esi |
479 | ret |
479 | ret |
480 | endp |
480 | endp |
481 | 481 | ||
482 | uglobal |
482 | uglobal |
483 | align 4 |
483 | align 4 |
484 | unpack_mutex MUTEX |
484 | unpack_mutex MUTEX |
485 | endg |
485 | endg |
486 | 486 | ||
487 | align 4 |
487 | align 4 |
488 | proc get_proc_ex stdcall, proc_name:dword, imports:dword |
488 | proc get_proc_ex stdcall, proc_name:dword, imports:dword |
489 | 489 | ||
490 | .look_up: |
490 | .look_up: |
491 | mov edx, [imports] |
491 | mov edx, [imports] |
492 | test edx, edx |
492 | test edx, edx |
493 | jz .end |
493 | jz .end |
494 | mov edx, [edx] |
494 | mov edx, [edx] |
495 | test edx, edx |
495 | test edx, edx |
496 | jz .end |
496 | jz .end |
497 | .next: |
497 | .next: |
498 | mov eax, [edx] |
498 | mov eax, [edx] |
499 | test eax, eax |
499 | test eax, eax |
500 | jz .next_table |
500 | jz .next_table |
501 | 501 | ||
502 | push edx |
502 | push edx |
503 | stdcall strncmp, eax, [proc_name], 256 |
503 | stdcall strncmp, eax, [proc_name], 256 |
504 | pop edx |
504 | pop edx |
505 | test eax, eax |
505 | test eax, eax |
506 | jz .ok |
506 | jz .ok |
507 | 507 | ||
508 | add edx, 8 |
508 | add edx, 8 |
509 | jmp .next |
509 | jmp .next |
510 | .next_table: |
510 | .next_table: |
511 | add [imports], 4 |
511 | add [imports], 4 |
512 | jmp .look_up |
512 | jmp .look_up |
513 | .ok: |
513 | .ok: |
514 | mov eax, [edx+4] |
514 | mov eax, [edx+4] |
515 | ret |
515 | ret |
516 | .end: |
516 | .end: |
517 | xor eax, eax |
517 | xor eax, eax |
518 | ret |
518 | ret |
519 | endp |
519 | endp |
520 | 520 | ||
521 | align 4 |
521 | align 4 |
522 | proc fix_coff_symbols stdcall uses ebx esi, sec:dword, symbols:dword,\ |
522 | proc fix_coff_symbols stdcall uses ebx esi, sec:dword, symbols:dword,\ |
523 | sym_count:dword, strings:dword, imports:dword |
523 | sym_count:dword, strings:dword, imports:dword |
524 | locals |
524 | locals |
525 | retval dd ? |
525 | retval dd ? |
526 | endl |
526 | endl |
527 | 527 | ||
528 | mov edi, [symbols] |
528 | mov edi, [symbols] |
529 | mov [retval], 1 |
529 | mov [retval], 1 |
530 | .fix: |
530 | .fix: |
531 | movzx ebx, [edi+COFF_SYM.SectionNumber] |
531 | movzx ebx, [edi+COFF_SYM.SectionNumber] |
532 | test ebx, ebx |
532 | test ebx, ebx |
533 | jnz .internal |
533 | jnz .internal |
534 | mov eax, dword [edi+COFF_SYM.Name] |
534 | mov eax, dword [edi+COFF_SYM.Name] |
535 | test eax, eax |
535 | test eax, eax |
536 | jnz @F |
536 | jnz @F |
537 | 537 | ||
538 | mov edi, [edi+4] |
538 | mov edi, [edi+4] |
539 | add edi, [strings] |
539 | add edi, [strings] |
540 | @@: |
540 | @@: |
541 | push edi |
541 | push edi |
542 | stdcall get_proc_ex, edi, [imports] |
542 | stdcall get_proc_ex, edi, [imports] |
543 | pop edi |
543 | pop edi |
544 | 544 | ||
545 | xor ebx, ebx |
545 | xor ebx, ebx |
546 | test eax, eax |
546 | test eax, eax |
547 | jnz @F |
547 | jnz @F |
548 | 548 | ||
549 | mov esi, msg_unresolved |
549 | mov esi, msg_unresolved |
550 | call sys_msg_board_str |
550 | call sys_msg_board_str |
551 | mov esi, edi |
551 | mov esi, edi |
552 | call sys_msg_board_str |
552 | call sys_msg_board_str |
553 | mov esi, msg_CR |
553 | mov esi, msg_CR |
554 | call sys_msg_board_str |
554 | call sys_msg_board_str |
555 | 555 | ||
556 | mov [retval], 0 |
556 | mov [retval], 0 |
557 | @@: |
557 | @@: |
558 | mov edi, [symbols] |
558 | mov edi, [symbols] |
559 | mov [edi+COFF_SYM.Value], eax |
559 | mov [edi+COFF_SYM.Value], eax |
560 | jmp .next |
560 | jmp .next |
561 | .internal: |
561 | .internal: |
562 | cmp bx, -1 |
562 | cmp bx, -1 |
563 | je .next |
563 | je .next |
564 | cmp bx, -2 |
564 | cmp bx, -2 |
565 | je .next |
565 | je .next |
566 | 566 | ||
567 | dec ebx |
567 | dec ebx |
568 | shl ebx, 3 |
568 | shl ebx, 3 |
569 | lea ebx, [ebx+ebx*4] |
569 | lea ebx, [ebx+ebx*4] |
570 | add ebx, [sec] |
570 | add ebx, [sec] |
571 | 571 | ||
572 | mov eax, [ebx+COFF_SECTION.VirtualAddress] |
572 | mov eax, [ebx+COFF_SECTION.VirtualAddress] |
573 | add [edi+COFF_SYM.Value], eax |
573 | add [edi+COFF_SYM.Value], eax |
574 | .next: |
574 | .next: |
575 | add edi, sizeof.COFF_SYM |
575 | add edi, sizeof.COFF_SYM |
576 | mov [symbols], edi |
576 | mov [symbols], edi |
577 | dec [sym_count] |
577 | dec [sym_count] |
578 | jnz .fix |
578 | jnz .fix |
579 | mov eax, [retval] |
579 | mov eax, [retval] |
580 | ret |
580 | ret |
581 | endp |
581 | endp |
582 | 582 | ||
583 | align 4 |
583 | align 4 |
584 | proc fix_coff_relocs stdcall uses ebx esi, coff:dword, sym:dword, \ |
584 | proc fix_coff_relocs stdcall uses ebx esi, coff:dword, sym:dword, \ |
585 | delta:dword |
585 | delta:dword |
586 | locals |
586 | locals |
587 | n_sec dd ? |
587 | n_sec dd ? |
588 | endl |
588 | endl |
589 | 589 | ||
590 | mov eax, [coff] |
590 | mov eax, [coff] |
591 | movzx ebx, [eax+COFF_HEADER.nSections] |
591 | movzx ebx, [eax+COFF_HEADER.nSections] |
592 | mov [n_sec], ebx |
592 | mov [n_sec], ebx |
593 | lea esi, [eax+20] |
593 | lea esi, [eax+20] |
594 | .fix_sec: |
594 | .fix_sec: |
595 | mov edi, [esi+COFF_SECTION.PtrReloc] |
595 | mov edi, [esi+COFF_SECTION.PtrReloc] |
596 | add edi, [coff] |
596 | add edi, [coff] |
597 | 597 | ||
598 | movzx ecx, [esi+COFF_SECTION.NumReloc] |
598 | movzx ecx, [esi+COFF_SECTION.NumReloc] |
599 | test ecx, ecx |
599 | test ecx, ecx |
600 | jz .next |
600 | jz .next |
601 | .reloc_loop: |
601 | .reloc_loop: |
602 | mov ebx, [edi+COFF_RELOC.SymIndex] |
602 | mov ebx, [edi+COFF_RELOC.SymIndex] |
603 | add ebx, ebx |
603 | add ebx, ebx |
604 | lea ebx, [ebx+ebx*8] |
604 | lea ebx, [ebx+ebx*8] |
605 | add ebx, [sym] |
605 | add ebx, [sym] |
606 | 606 | ||
607 | mov edx, [ebx+COFF_SYM.Value] |
607 | mov edx, [ebx+COFF_SYM.Value] |
608 | 608 | ||
609 | cmp [edi+COFF_RELOC.Type], 6 |
609 | cmp [edi+COFF_RELOC.Type], 6 |
610 | je .dir_32 |
610 | je .dir_32 |
611 | 611 | ||
612 | cmp [edi+COFF_RELOC.Type], 20 |
612 | cmp [edi+COFF_RELOC.Type], 20 |
613 | jne .next_reloc |
613 | jne .next_reloc |
614 | .rel_32: |
614 | .rel_32: |
615 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
615 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
616 | add eax, [esi+COFF_SECTION.VirtualAddress] |
616 | add eax, [esi+COFF_SECTION.VirtualAddress] |
617 | sub edx, eax |
617 | sub edx, eax |
618 | sub edx, 4 |
618 | sub edx, 4 |
619 | jmp .fix |
619 | jmp .fix |
620 | .dir_32: |
620 | .dir_32: |
621 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
621 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
622 | add eax, [esi+COFF_SECTION.VirtualAddress] |
622 | add eax, [esi+COFF_SECTION.VirtualAddress] |
623 | .fix: |
623 | .fix: |
624 | add eax, [delta] |
624 | add eax, [delta] |
625 | add [eax], edx |
625 | add [eax], edx |
626 | .next_reloc: |
626 | .next_reloc: |
627 | add edi, 10 |
627 | add edi, 10 |
628 | dec ecx |
628 | dec ecx |
629 | jnz .reloc_loop |
629 | jnz .reloc_loop |
630 | .next: |
630 | .next: |
631 | add esi, sizeof.COFF_SECTION |
631 | add esi, sizeof.COFF_SECTION |
632 | dec [n_sec] |
632 | dec [n_sec] |
633 | jnz .fix_sec |
633 | jnz .fix_sec |
634 | .exit: |
634 | .exit: |
635 | ret |
635 | ret |
636 | endp |
636 | endp |
637 | 637 | ||
638 | align 4 |
638 | align 4 |
639 | proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \ |
639 | proc rebase_coff stdcall uses ebx esi, coff:dword, sym:dword, \ |
640 | delta:dword |
640 | delta:dword |
641 | locals |
641 | locals |
642 | n_sec dd ? |
642 | n_sec dd ? |
643 | endl |
643 | endl |
644 | 644 | ||
645 | mov eax, [coff] |
645 | mov eax, [coff] |
646 | movzx ebx, [eax+COFF_HEADER.nSections] |
646 | movzx ebx, [eax+COFF_HEADER.nSections] |
647 | mov [n_sec], ebx |
647 | mov [n_sec], ebx |
648 | lea esi, [eax+20] |
648 | lea esi, [eax+20] |
649 | mov edx, [delta] |
649 | mov edx, [delta] |
650 | .fix_sec: |
650 | .fix_sec: |
651 | mov edi, [esi+COFF_SECTION.PtrReloc] |
651 | mov edi, [esi+COFF_SECTION.PtrReloc] |
652 | add edi, [coff] |
652 | add edi, [coff] |
653 | 653 | ||
654 | movzx ecx, [esi+COFF_SECTION.NumReloc] |
654 | movzx ecx, [esi+COFF_SECTION.NumReloc] |
655 | test ecx, ecx |
655 | test ecx, ecx |
656 | jz .next |
656 | jz .next |
657 | .reloc_loop: |
657 | .reloc_loop: |
658 | cmp [edi+COFF_RELOC.Type], 6 |
658 | cmp [edi+COFF_RELOC.Type], 6 |
659 | jne .next_reloc |
659 | jne .next_reloc |
660 | .dir_32: |
660 | .dir_32: |
661 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
661 | mov eax, [edi+COFF_RELOC.VirtualAddress] |
662 | add eax, [esi+COFF_SECTION.VirtualAddress] |
662 | add eax, [esi+COFF_SECTION.VirtualAddress] |
663 | add [eax+edx], edx |
663 | add [eax+edx], edx |
664 | .next_reloc: |
664 | .next_reloc: |
665 | add edi, 10 |
665 | add edi, 10 |
666 | dec ecx |
666 | dec ecx |
667 | jnz .reloc_loop |
667 | jnz .reloc_loop |
668 | .next: |
668 | .next: |
669 | add esi, sizeof.COFF_SECTION |
669 | add esi, sizeof.COFF_SECTION |
670 | dec [n_sec] |
670 | dec [n_sec] |
671 | jnz .fix_sec |
671 | jnz .fix_sec |
672 | .exit: |
672 | .exit: |
673 | ret |
673 | ret |
674 | endp |
674 | endp |
675 | 675 | ||
676 | align 4 |
676 | align 4 |
677 | proc load_driver stdcall, driver_name:dword |
677 | proc load_driver stdcall, driver_name:dword |
678 | locals |
678 | locals |
679 | coff dd ? |
679 | coff dd ? |
680 | sym dd ? |
680 | sym dd ? |
681 | strings dd ? |
681 | strings dd ? |
682 | img_size dd ? |
682 | img_size dd ? |
683 | img_base dd ? |
683 | img_base dd ? |
684 | start dd ? |
684 | start dd ? |
685 | 685 | ||
686 | exports dd ? ;fake exports table |
686 | exports dd ? ;fake exports table |
687 | dd ? |
687 | dd ? |
688 | file_name rb 13+16+4+1 ; '/sys/drivers/ |
688 | file_name rb 13+16+4+1 ; '/sys/drivers/ |
689 | endl |
689 | endl |
690 | 690 | ||
691 | lea edx, [file_name] |
691 | lea edx, [file_name] |
692 | mov dword [edx], '/sys' |
692 | mov dword [edx], '/sys' |
693 | mov dword [edx+4], '/dri' |
693 | mov dword [edx+4], '/dri' |
694 | mov dword [edx+8], 'vers' |
694 | mov dword [edx+8], 'vers' |
695 | mov byte [edx+12], '/' |
695 | mov byte [edx+12], '/' |
696 | mov esi, [driver_name] |
696 | mov esi, [driver_name] |
697 | .redo: |
697 | .redo: |
698 | lea edx, [file_name] |
698 | lea edx, [file_name] |
699 | lea edi, [edx+13] |
699 | lea edi, [edx+13] |
700 | mov ecx, 16 |
700 | mov ecx, 16 |
701 | @@: |
701 | @@: |
702 | lodsb |
702 | lodsb |
703 | test al, al |
703 | test al, al |
704 | jz @f |
704 | jz @f |
705 | stosb |
705 | stosb |
706 | loop @b |
706 | loop @b |
707 | @@: |
707 | @@: |
708 | mov dword [edi], '.obj' |
708 | mov dword [edi], '.obj' |
709 | mov byte [edi+4], 0 |
709 | mov byte [edi+4], 0 |
710 | stdcall load_file, edx |
710 | stdcall load_file, edx |
711 | 711 | ||
712 | test eax, eax |
712 | test eax, eax |
713 | jz .exit |
713 | jz .exit |
714 | 714 | ||
715 | mov [coff], eax |
715 | mov [coff], eax |
716 | 716 | ||
717 | movzx ecx, [eax+COFF_HEADER.nSections] |
717 | movzx ecx, [eax+COFF_HEADER.nSections] |
718 | xor ebx, ebx |
718 | xor ebx, ebx |
719 | 719 | ||
720 | lea edx, [eax+20] |
720 | lea edx, [eax+20] |
721 | @@: |
721 | @@: |
722 | add ebx, [edx+COFF_SECTION.SizeOfRawData] |
722 | add ebx, [edx+COFF_SECTION.SizeOfRawData] |
723 | add ebx, 15 |
723 | add ebx, 15 |
724 | and ebx, not 15 |
724 | and ebx, not 15 |
725 | add edx, sizeof.COFF_SECTION |
725 | add edx, sizeof.COFF_SECTION |
726 | dec ecx |
726 | dec ecx |
727 | jnz @B |
727 | jnz @B |
728 | mov [img_size], ebx |
728 | mov [img_size], ebx |
729 | 729 | ||
730 | stdcall kernel_alloc, ebx |
730 | stdcall kernel_alloc, ebx |
731 | test eax, eax |
731 | test eax, eax |
732 | jz .fail |
732 | jz .fail |
733 | mov [img_base], eax |
733 | mov [img_base], eax |
734 | 734 | ||
735 | mov edi, eax |
735 | mov edi, eax |
736 | xor eax, eax |
736 | xor eax, eax |
737 | mov ecx, [img_size] |
737 | mov ecx, [img_size] |
738 | add ecx, 4095 |
738 | add ecx, 4095 |
739 | and ecx, not 4095 |
739 | and ecx, not 4095 |
740 | shr ecx, 2 |
740 | shr ecx, 2 |
741 | cld |
741 | cld |
742 | rep stosd |
742 | rep stosd |
743 | 743 | ||
744 | mov edx, [coff] |
744 | mov edx, [coff] |
745 | movzx ebx, [edx+COFF_HEADER.nSections] |
745 | movzx ebx, [edx+COFF_HEADER.nSections] |
746 | mov edi, [img_base] |
746 | mov edi, [img_base] |
747 | lea eax, [edx+20] |
747 | lea eax, [edx+20] |
748 | @@: |
748 | @@: |
749 | mov [eax+COFF_SECTION.VirtualAddress], edi |
749 | mov [eax+COFF_SECTION.VirtualAddress], edi |
750 | mov esi, [eax+COFF_SECTION.PtrRawData] |
750 | mov esi, [eax+COFF_SECTION.PtrRawData] |
751 | test esi, esi |
751 | test esi, esi |
752 | jnz .copy |
752 | jnz .copy |
753 | add edi, [eax+COFF_SECTION.SizeOfRawData] |
753 | add edi, [eax+COFF_SECTION.SizeOfRawData] |
754 | jmp .next |
754 | jmp .next |
755 | .copy: |
755 | .copy: |
756 | add esi, edx |
756 | add esi, edx |
757 | mov ecx, [eax+COFF_SECTION.SizeOfRawData] |
757 | mov ecx, [eax+COFF_SECTION.SizeOfRawData] |
758 | cld |
758 | cld |
759 | rep movsb |
759 | rep movsb |
760 | .next: |
760 | .next: |
761 | add edi, 15 |
761 | add edi, 15 |
762 | and edi, not 15 |
762 | and edi, not 15 |
763 | add eax, sizeof.COFF_SECTION |
763 | add eax, sizeof.COFF_SECTION |
764 | dec ebx |
764 | dec ebx |
765 | jnz @B |
765 | jnz @B |
766 | 766 | ||
767 | mov ebx, [edx+COFF_HEADER.pSymTable] |
767 | mov ebx, [edx+COFF_HEADER.pSymTable] |
768 | add ebx, edx |
768 | add ebx, edx |
769 | mov [sym], ebx |
769 | mov [sym], ebx |
770 | mov ecx, [edx+COFF_HEADER.nSymbols] |
770 | mov ecx, [edx+COFF_HEADER.nSymbols] |
771 | add ecx, ecx |
771 | add ecx, ecx |
772 | lea ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
772 | lea ecx, [ecx+ecx*8];ecx*=18 = nSymbols*CSYM_SIZE |
773 | add ecx, [sym] |
773 | add ecx, [sym] |
774 | mov [strings], ecx |
774 | mov [strings], ecx |
775 | 775 | ||
776 | lea ebx, [exports] |
776 | lea ebx, [exports] |
777 | mov dword [ebx], kernel_export |
777 | mov dword [ebx], kernel_export |
778 | mov dword [ebx+4], 0 |
778 | mov dword [ebx+4], 0 |
779 | lea eax, [edx+20] |
779 | lea eax, [edx+20] |
780 | 780 | ||
781 | stdcall fix_coff_symbols, eax, [sym], [edx+COFF_HEADER.nSymbols], \ |
781 | stdcall fix_coff_symbols, eax, [sym], [edx+COFF_HEADER.nSymbols], \ |
782 | [strings], ebx |
782 | [strings], ebx |
783 | test eax, eax |
783 | test eax, eax |
784 | jz .link_fail |
784 | jz .link_fail |
785 | 785 | ||
786 | mov ebx, [coff] |
786 | mov ebx, [coff] |
787 | stdcall fix_coff_relocs, ebx, [sym], 0 |
787 | stdcall fix_coff_relocs, ebx, [sym], 0 |
788 | 788 | ||
789 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szVersion |
789 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szVersion |
790 | test eax, eax |
790 | test eax, eax |
791 | jz .link_fail |
791 | jz .link_fail |
792 | 792 | ||
793 | mov eax, [eax] |
793 | mov eax, [eax] |
794 | shr eax, 16 |
794 | shr eax, 16 |
795 | cmp eax, DRV_COMPAT |
795 | cmp eax, DRV_COMPAT |
796 | jb .ver_fail |
796 | jb .ver_fail |
797 | 797 | ||
798 | cmp eax, DRV_CURRENT |
798 | cmp eax, DRV_CURRENT |
799 | ja .ver_fail |
799 | ja .ver_fail |
800 | 800 | ||
801 | mov ebx, [coff] |
801 | mov ebx, [coff] |
802 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szSTART |
802 | stdcall get_coff_sym, [sym], [ebx+COFF_HEADER.nSymbols], szSTART |
803 | mov [start], eax |
803 | mov [start], eax |
804 | 804 | ||
805 | stdcall kernel_free, [coff] |
805 | stdcall kernel_free, [coff] |
806 | 806 | ||
807 | mov ebx, [start] |
807 | mov ebx, [start] |
808 | stdcall ebx, DRV_ENTRY |
808 | stdcall ebx, DRV_ENTRY |
809 | test eax, eax |
809 | test eax, eax |
810 | jnz .ok |
810 | jnz .ok |
811 | 811 | ||
812 | stdcall kernel_free, [img_base] |
812 | stdcall kernel_free, [img_base] |
813 | cmp dword [file_name+13], 'SOUN' |
- | |
814 | jnz @f |
- | |
815 | cmp dword [file_name+17], 'D.ob' |
- | |
816 | jnz @f |
- | |
817 | cmp word [file_name+21], 'j' |
- | |
818 | jnz @f |
- | |
819 | mov esi, aHDA |
- | |
820 | jmp .redo |
- | |
821 | @@: |
813 | |
822 | xor eax, eax |
814 | xor eax, eax |
823 | ret |
815 | ret |
824 | .ok: |
816 | .ok: |
825 | mov ebx, [img_base] |
817 | mov ebx, [img_base] |
826 | mov [eax+SRV.base], ebx |
818 | mov [eax+SRV.base], ebx |
827 | mov ecx, [start] |
819 | mov ecx, [start] |
828 | mov [eax+SRV.entry], ecx |
820 | mov [eax+SRV.entry], ecx |
829 | ret |
821 | ret |
830 | 822 | ||
831 | .ver_fail: |
823 | .ver_fail: |
832 | mov esi, msg_CR |
824 | mov esi, msg_CR |
833 | call sys_msg_board_str |
825 | call sys_msg_board_str |
834 | mov esi, [driver_name] |
826 | mov esi, [driver_name] |
835 | call sys_msg_board_str |
827 | call sys_msg_board_str |
836 | mov esi, msg_CR |
828 | mov esi, msg_CR |
837 | call sys_msg_board_str |
829 | call sys_msg_board_str |
838 | mov esi, msg_version |
830 | mov esi, msg_version |
839 | call sys_msg_board_str |
831 | call sys_msg_board_str |
840 | mov esi, msg_www |
832 | mov esi, msg_www |
841 | call sys_msg_board_str |
833 | call sys_msg_board_str |
842 | jmp .cleanup |
834 | jmp .cleanup |
843 | 835 | ||
844 | .link_fail: |
836 | .link_fail: |
845 | mov esi, msg_module |
837 | mov esi, msg_module |
846 | call sys_msg_board_str |
838 | call sys_msg_board_str |
847 | mov esi, [driver_name] |
839 | mov esi, [driver_name] |
848 | call sys_msg_board_str |
840 | call sys_msg_board_str |
849 | mov esi, msg_CR |
841 | mov esi, msg_CR |
850 | call sys_msg_board_str |
842 | call sys_msg_board_str |
851 | .cleanup: |
843 | .cleanup: |
852 | stdcall kernel_free, [img_base] |
844 | stdcall kernel_free, [img_base] |
853 | .fail: |
845 | .fail: |
854 | stdcall kernel_free, [coff] |
846 | stdcall kernel_free, [coff] |
855 | .exit: |
847 | .exit: |
856 | xor eax, eax |
848 | xor eax, eax |
857 | ret |
849 | ret |
858 | endp |
850 | endp |
859 | 851 | ||
860 | ; in: edx -> COFF_SECTION struct |
852 | ; in: edx -> COFF_SECTION struct |
861 | ; out: eax = alignment as mask for bits to drop |
853 | ; out: eax = alignment as mask for bits to drop |
862 | coff_get_align: |
854 | coff_get_align: |
863 | ; Rules: |
855 | ; Rules: |
864 | ; - if alignment is not given, use default = 4K; |
856 | ; - if alignment is not given, use default = 4K; |
865 | ; - if alignment is given and is no more than 4K, use it; |
857 | ; - if alignment is given and is no more than 4K, use it; |
866 | ; - if alignment is more than 4K, revert to 4K. |
858 | ; - if alignment is more than 4K, revert to 4K. |
867 | push ecx |
859 | push ecx |
868 | mov cl, byte [edx+COFF_SECTION.Characteristics+2] |
860 | mov cl, byte [edx+COFF_SECTION.Characteristics+2] |
869 | mov eax, 1 |
861 | mov eax, 1 |
870 | shr cl, 4 |
862 | shr cl, 4 |
871 | dec cl |
863 | dec cl |
872 | js .default |
864 | js .default |
873 | cmp cl, 12 |
865 | cmp cl, 12 |
874 | jbe @f |
866 | jbe @f |
875 | .default: |
867 | .default: |
876 | mov cl, 12 |
868 | mov cl, 12 |
877 | @@: |
869 | @@: |
878 | shl eax, cl |
870 | shl eax, cl |
879 | pop ecx |
871 | pop ecx |
880 | dec eax |
872 | dec eax |
881 | ret |
873 | ret |
882 | 874 | ||
883 | align 4 |
875 | align 4 |
884 | proc load_library stdcall, file_name:dword |
876 | proc load_library stdcall, file_name:dword |
885 | locals |
877 | locals |
886 | fullname rb 260 |
878 | fullname rb 260 |
887 | fileinfo rb 40 |
879 | fileinfo rb 40 |
888 | coff dd ? |
880 | coff dd ? |
889 | img_base dd ? |
881 | img_base dd ? |
890 | endl |
882 | endl |
891 | 883 | ||
892 | cli |
884 | cli |
893 | 885 | ||
894 | ; resolve file name |
886 | ; resolve file name |
895 | mov ebx, [file_name] |
887 | mov ebx, [file_name] |
896 | lea edi, [fullname+1] |
888 | lea edi, [fullname+1] |
897 | mov byte [edi-1], '/' |
889 | mov byte [edi-1], '/' |
898 | stdcall get_full_file_name, edi, 259 |
890 | stdcall get_full_file_name, edi, 259 |
899 | test al, al |
891 | test al, al |
900 | jz .fail |
892 | jz .fail |
901 | 893 | ||
902 | ; scan for required DLL in list of already loaded for this process, |
894 | ; scan for required DLL in list of already loaded for this process, |
903 | ; ignore timestamp |
895 | ; ignore timestamp |
904 | mov esi, [CURRENT_TASK] |
896 | mov esi, [CURRENT_TASK] |
905 | shl esi, 8 |
897 | shl esi, 8 |
906 | lea edi, [fullname] |
898 | lea edi, [fullname] |
907 | mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr] |
899 | mov ebx, [esi+SLOT_BASE+APPDATA.dlls_list_ptr] |
908 | test ebx, ebx |
900 | test ebx, ebx |
909 | jz .not_in_process |
901 | jz .not_in_process |
910 | mov esi, [ebx+HDLL.fd] |
902 | mov esi, [ebx+HDLL.fd] |
911 | .scan_in_process: |
903 | .scan_in_process: |
912 | cmp esi, ebx |
904 | cmp esi, ebx |
913 | jz .not_in_process |
905 | jz .not_in_process |
914 | mov eax, [esi+HDLL.parent] |
906 | mov eax, [esi+HDLL.parent] |
915 | add eax, DLLDESCR.name |
907 | add eax, DLLDESCR.name |
916 | stdcall strncmp, eax, edi, -1 |
908 | stdcall strncmp, eax, edi, -1 |
917 | test eax, eax |
909 | test eax, eax |
918 | jnz .next_in_process |
910 | jnz .next_in_process |
919 | ; simple variant: load DLL which is already loaded in this process |
911 | ; simple variant: load DLL which is already loaded in this process |
920 | ; just increment reference counters and return address of exports table |
912 | ; just increment reference counters and return address of exports table |
921 | inc [esi+HDLL.refcount] |
913 | inc [esi+HDLL.refcount] |
922 | mov ecx, [esi+HDLL.parent] |
914 | mov ecx, [esi+HDLL.parent] |
923 | inc [ecx+DLLDESCR.refcount] |
915 | inc [ecx+DLLDESCR.refcount] |
924 | mov eax, [ecx+DLLDESCR.exports] |
916 | mov eax, [ecx+DLLDESCR.exports] |
925 | sub eax, [ecx+DLLDESCR.defaultbase] |
917 | sub eax, [ecx+DLLDESCR.defaultbase] |
926 | add eax, [esi+HDLL.base] |
918 | add eax, [esi+HDLL.base] |
927 | ret |
919 | ret |
928 | .next_in_process: |
920 | .next_in_process: |
929 | mov esi, [esi+HDLL.fd] |
921 | mov esi, [esi+HDLL.fd] |
930 | jmp .scan_in_process |
922 | jmp .scan_in_process |
931 | .not_in_process: |
923 | .not_in_process: |
932 | 924 | ||
933 | ; scan in full list, compare timestamp |
925 | ; scan in full list, compare timestamp |
934 | lea eax, [fileinfo] |
926 | lea eax, [fileinfo] |
935 | stdcall get_fileinfo, edi, eax |
927 | stdcall get_fileinfo, edi, eax |
936 | test eax, eax |
928 | test eax, eax |
937 | jnz .fail |
929 | jnz .fail |
938 | mov esi, [dll_list.fd] |
930 | mov esi, [dll_list.fd] |
939 | .scan_for_dlls: |
931 | .scan_for_dlls: |
940 | cmp esi, dll_list |
932 | cmp esi, dll_list |
941 | jz .load_new |
933 | jz .load_new |
942 | lea eax, [esi+DLLDESCR.name] |
934 | lea eax, [esi+DLLDESCR.name] |
943 | stdcall strncmp, eax, edi, -1 |
935 | stdcall strncmp, eax, edi, -1 |
944 | test eax, eax |
936 | test eax, eax |
945 | jnz .continue_scan |
937 | jnz .continue_scan |
946 | .test_prev_dll: |
938 | .test_prev_dll: |
947 | mov eax, dword [fileinfo+24]; last modified time |
939 | mov eax, dword [fileinfo+24]; last modified time |
948 | mov edx, dword [fileinfo+28]; last modified date |
940 | mov edx, dword [fileinfo+28]; last modified date |
949 | cmp dword [esi+DLLDESCR.timestamp], eax |
941 | cmp dword [esi+DLLDESCR.timestamp], eax |
950 | jnz .continue_scan |
942 | jnz .continue_scan |
951 | cmp dword [esi+DLLDESCR.timestamp+4], edx |
943 | cmp dword [esi+DLLDESCR.timestamp+4], edx |
952 | jz .dll_already_loaded |
944 | jz .dll_already_loaded |
953 | .continue_scan: |
945 | .continue_scan: |
954 | mov esi, [esi+DLLDESCR.fd] |
946 | mov esi, [esi+DLLDESCR.fd] |
955 | jmp .scan_for_dlls |
947 | jmp .scan_for_dlls |
956 | 948 | ||
957 | ; new DLL |
949 | ; new DLL |
958 | .load_new: |
950 | .load_new: |
959 | ; load file |
951 | ; load file |
960 | stdcall load_file, edi |
952 | stdcall load_file, edi |
961 | test eax, eax |
953 | test eax, eax |
962 | jz .fail |
954 | jz .fail |
963 | mov [coff], eax |
955 | mov [coff], eax |
964 | mov dword [fileinfo+32], ebx |
956 | mov dword [fileinfo+32], ebx |
965 | 957 | ||
966 | ; allocate DLLDESCR struct; size is DLLDESCR.sizeof plus size of DLL name |
958 | ; allocate DLLDESCR struct; size is DLLDESCR.sizeof plus size of DLL name |
967 | mov esi, edi |
959 | mov esi, edi |
968 | mov ecx, -1 |
960 | mov ecx, -1 |
969 | xor eax, eax |
961 | xor eax, eax |
970 | repnz scasb |
962 | repnz scasb |
971 | not ecx |
963 | not ecx |
972 | lea eax, [ecx+sizeof.DLLDESCR] |
964 | lea eax, [ecx+sizeof.DLLDESCR] |
973 | push ecx |
965 | push ecx |
974 | call malloc |
966 | call malloc |
975 | pop ecx |
967 | pop ecx |
976 | test eax, eax |
968 | test eax, eax |
977 | jz .fail_and_free_coff |
969 | jz .fail_and_free_coff |
978 | ; save timestamp |
970 | ; save timestamp |
979 | lea edi, [eax+DLLDESCR.name] |
971 | lea edi, [eax+DLLDESCR.name] |
980 | rep movsb |
972 | rep movsb |
981 | mov esi, eax |
973 | mov esi, eax |
982 | mov eax, dword [fileinfo+24] |
974 | mov eax, dword [fileinfo+24] |
983 | mov dword [esi+DLLDESCR.timestamp], eax |
975 | mov dword [esi+DLLDESCR.timestamp], eax |
984 | mov eax, dword [fileinfo+28] |
976 | mov eax, dword [fileinfo+28] |
985 | mov dword [esi+DLLDESCR.timestamp+4], eax |
977 | mov dword [esi+DLLDESCR.timestamp+4], eax |
986 | ; initialize DLLDESCR struct |
978 | ; initialize DLLDESCR struct |
987 | and dword [esi+DLLDESCR.refcount], 0; no HDLLs yet; later it will be incremented |
979 | and dword [esi+DLLDESCR.refcount], 0; no HDLLs yet; later it will be incremented |
988 | mov [esi+DLLDESCR.fd], dll_list |
980 | mov [esi+DLLDESCR.fd], dll_list |
989 | mov eax, [dll_list.bk] |
981 | mov eax, [dll_list.bk] |
990 | mov [dll_list.bk], esi |
982 | mov [dll_list.bk], esi |
991 | mov [esi+DLLDESCR.bk], eax |
983 | mov [esi+DLLDESCR.bk], eax |
992 | mov [eax+DLLDESCR.fd], esi |
984 | mov [eax+DLLDESCR.fd], esi |
993 | 985 | ||
994 | ; calculate size of loaded DLL |
986 | ; calculate size of loaded DLL |
995 | mov edx, [coff] |
987 | mov edx, [coff] |
996 | movzx ecx, [edx+COFF_HEADER.nSections] |
988 | movzx ecx, [edx+COFF_HEADER.nSections] |
997 | xor ebx, ebx |
989 | xor ebx, ebx |
998 | 990 | ||
999 | add edx, 20 |
991 | add edx, 20 |
1000 | @@: |
992 | @@: |
1001 | call coff_get_align |
993 | call coff_get_align |
1002 | add ebx, eax |
994 | add ebx, eax |
1003 | not eax |
995 | not eax |
1004 | and ebx, eax |
996 | and ebx, eax |
1005 | add ebx, [edx+COFF_SECTION.SizeOfRawData] |
997 | add ebx, [edx+COFF_SECTION.SizeOfRawData] |
1006 | add edx, sizeof.COFF_SECTION |
998 | add edx, sizeof.COFF_SECTION |
1007 | dec ecx |
999 | dec ecx |
1008 | jnz @B |
1000 | jnz @B |
1009 | ; it must be nonzero and not too big |
1001 | ; it must be nonzero and not too big |
1010 | mov [esi+DLLDESCR.size], ebx |
1002 | mov [esi+DLLDESCR.size], ebx |
1011 | test ebx, ebx |
1003 | test ebx, ebx |
1012 | jz .fail_and_free_dll |
1004 | jz .fail_and_free_dll |
1013 | cmp ebx, MAX_DEFAULT_DLL_ADDR-MIN_DEFAULT_DLL_ADDR |
1005 | cmp ebx, MAX_DEFAULT_DLL_ADDR-MIN_DEFAULT_DLL_ADDR |
1014 | ja .fail_and_free_dll |
1006 | ja .fail_and_free_dll |
1015 | ; allocate memory for kernel-side image |
1007 | ; allocate memory for kernel-side image |
1016 | stdcall kernel_alloc, ebx |
1008 | stdcall kernel_alloc, ebx |
1017 | test eax, eax |
1009 | test eax, eax |
1018 | jz .fail_and_free_dll |
1010 | jz .fail_and_free_dll |
1019 | mov [esi+DLLDESCR.data], eax |
1011 | mov [esi+DLLDESCR.data], eax |
1020 | ; calculate preferred base address |
1012 | ; calculate preferred base address |
1021 | add ebx, 0x1FFF |
1013 | add ebx, 0x1FFF |
1022 | and ebx, not 0xFFF |
1014 | and ebx, not 0xFFF |
1023 | mov ecx, [dll_cur_addr] |
1015 | mov ecx, [dll_cur_addr] |
1024 | lea edx, [ecx+ebx] |
1016 | lea edx, [ecx+ebx] |
1025 | cmp edx, MAX_DEFAULT_DLL_ADDR |
1017 | cmp edx, MAX_DEFAULT_DLL_ADDR |
1026 | jb @f |
1018 | jb @f |
1027 | mov ecx, MIN_DEFAULT_DLL_ADDR |
1019 | mov ecx, MIN_DEFAULT_DLL_ADDR |
1028 | lea edx, [ecx+ebx] |
1020 | lea edx, [ecx+ebx] |
1029 | @@: |
1021 | @@: |
1030 | mov [esi+DLLDESCR.defaultbase], ecx |
1022 | mov [esi+DLLDESCR.defaultbase], ecx |
1031 | mov [dll_cur_addr], edx |
1023 | mov [dll_cur_addr], edx |
1032 | 1024 | ||
1033 | ; copy sections and set correct values for VirtualAddress'es in headers |
1025 | ; copy sections and set correct values for VirtualAddress'es in headers |
1034 | push esi |
1026 | push esi |
1035 | mov edx, [coff] |
1027 | mov edx, [coff] |
1036 | movzx ebx, [edx+COFF_HEADER.nSections] |
1028 | movzx ebx, [edx+COFF_HEADER.nSections] |
1037 | mov edi, eax |
1029 | mov edi, eax |
1038 | add edx, 20 |
1030 | add edx, 20 |
1039 | cld |
1031 | cld |
1040 | @@: |
1032 | @@: |
1041 | call coff_get_align |
1033 | call coff_get_align |
1042 | add ecx, eax |
1034 | add ecx, eax |
1043 | add edi, eax |
1035 | add edi, eax |
1044 | not eax |
1036 | not eax |
1045 | and ecx, eax |
1037 | and ecx, eax |
1046 | and edi, eax |
1038 | and edi, eax |
1047 | mov [edx+COFF_SECTION.VirtualAddress], ecx |
1039 | mov [edx+COFF_SECTION.VirtualAddress], ecx |
1048 | add ecx, [edx+COFF_SECTION.SizeOfRawData] |
1040 | add ecx, [edx+COFF_SECTION.SizeOfRawData] |
1049 | mov esi, [edx+COFF_SECTION.PtrRawData] |
1041 | mov esi, [edx+COFF_SECTION.PtrRawData] |
1050 | push ecx |
1042 | push ecx |
1051 | mov ecx, [edx+COFF_SECTION.SizeOfRawData] |
1043 | mov ecx, [edx+COFF_SECTION.SizeOfRawData] |
1052 | test esi, esi |
1044 | test esi, esi |
1053 | jnz .copy |
1045 | jnz .copy |
1054 | xor eax, eax |
1046 | xor eax, eax |
1055 | rep stosb |
1047 | rep stosb |
1056 | jmp .next |
1048 | jmp .next |
1057 | .copy: |
1049 | .copy: |
1058 | add esi, [coff] |
1050 | add esi, [coff] |
1059 | rep movsb |
1051 | rep movsb |
1060 | .next: |
1052 | .next: |
1061 | pop ecx |
1053 | pop ecx |
1062 | add edx, sizeof.COFF_SECTION |
1054 | add edx, sizeof.COFF_SECTION |
1063 | dec ebx |
1055 | dec ebx |
1064 | jnz @B |
1056 | jnz @B |
1065 | pop esi |
1057 | pop esi |
1066 | 1058 | ||
1067 | ; save some additional data from COFF file |
1059 | ; save some additional data from COFF file |
1068 | ; later we will use COFF header, headers for sections and symbol table |
1060 | ; later we will use COFF header, headers for sections and symbol table |
1069 | ; and also relocations table for all sections |
1061 | ; and also relocations table for all sections |
1070 | mov edx, [coff] |
1062 | mov edx, [coff] |
1071 | mov ebx, [edx+COFF_HEADER.pSymTable] |
1063 | mov ebx, [edx+COFF_HEADER.pSymTable] |
1072 | mov edi, dword [fileinfo+32] |
1064 | mov edi, dword [fileinfo+32] |
1073 | sub edi, ebx |
1065 | sub edi, ebx |
1074 | jc .fail_and_free_data |
1066 | jc .fail_and_free_data |
1075 | mov [esi+DLLDESCR.symbols_lim], edi |
1067 | mov [esi+DLLDESCR.symbols_lim], edi |
1076 | add ebx, edx |
1068 | add ebx, edx |
1077 | movzx ecx, [edx+COFF_HEADER.nSections] |
1069 | movzx ecx, [edx+COFF_HEADER.nSections] |
1078 | lea ecx, [ecx*5] |
1070 | lea ecx, [ecx*5] |
1079 | lea edi, [edi+ecx*8+20] |
1071 | lea edi, [edi+ecx*8+20] |
1080 | add edx, 20 |
1072 | add edx, 20 |
1081 | @@: |
1073 | @@: |
1082 | movzx eax, [edx+COFF_SECTION.NumReloc] |
1074 | movzx eax, [edx+COFF_SECTION.NumReloc] |
1083 | lea eax, [eax*5] |
1075 | lea eax, [eax*5] |
1084 | lea edi, [edi+eax*2] |
1076 | lea edi, [edi+eax*2] |
1085 | add edx, sizeof.COFF_SECTION |
1077 | add edx, sizeof.COFF_SECTION |
1086 | sub ecx, 5 |
1078 | sub ecx, 5 |
1087 | jnz @b |
1079 | jnz @b |
1088 | stdcall kernel_alloc, edi |
1080 | stdcall kernel_alloc, edi |
1089 | test eax, eax |
1081 | test eax, eax |
1090 | jz .fail_and_free_data |
1082 | jz .fail_and_free_data |
1091 | mov edx, [coff] |
1083 | mov edx, [coff] |
1092 | movzx ecx, [edx+COFF_HEADER.nSections] |
1084 | movzx ecx, [edx+COFF_HEADER.nSections] |
1093 | lea ecx, [ecx*5] |
1085 | lea ecx, [ecx*5] |
1094 | lea ecx, [ecx*2+5] |
1086 | lea ecx, [ecx*2+5] |
1095 | mov [esi+DLLDESCR.coff_hdr], eax |
1087 | mov [esi+DLLDESCR.coff_hdr], eax |
1096 | push esi |
1088 | push esi |
1097 | mov esi, edx |
1089 | mov esi, edx |
1098 | mov edi, eax |
1090 | mov edi, eax |
1099 | rep movsd |
1091 | rep movsd |
1100 | pop esi |
1092 | pop esi |
1101 | mov [esi+DLLDESCR.symbols_ptr], edi |
1093 | mov [esi+DLLDESCR.symbols_ptr], edi |
1102 | push esi |
1094 | push esi |
1103 | mov ecx, [edx+COFF_HEADER.nSymbols] |
1095 | mov ecx, [edx+COFF_HEADER.nSymbols] |
1104 | mov [esi+DLLDESCR.symbols_num], ecx |
1096 | mov [esi+DLLDESCR.symbols_num], ecx |
1105 | mov ecx, [esi+DLLDESCR.symbols_lim] |
1097 | mov ecx, [esi+DLLDESCR.symbols_lim] |
1106 | mov esi, ebx |
1098 | mov esi, ebx |
1107 | rep movsb |
1099 | rep movsb |
1108 | pop esi |
1100 | pop esi |
1109 | mov ebx, [esi+DLLDESCR.coff_hdr] |
1101 | mov ebx, [esi+DLLDESCR.coff_hdr] |
1110 | push esi |
1102 | push esi |
1111 | movzx eax, [edx+COFF_HEADER.nSections] |
1103 | movzx eax, [edx+COFF_HEADER.nSections] |
1112 | lea edx, [ebx+20] |
1104 | lea edx, [ebx+20] |
1113 | @@: |
1105 | @@: |
1114 | movzx ecx, [edx+COFF_SECTION.NumReloc] |
1106 | movzx ecx, [edx+COFF_SECTION.NumReloc] |
1115 | lea ecx, [ecx*5] |
1107 | lea ecx, [ecx*5] |
1116 | mov esi, [edx+COFF_SECTION.PtrReloc] |
1108 | mov esi, [edx+COFF_SECTION.PtrReloc] |
1117 | mov [edx+COFF_SECTION.PtrReloc], edi |
1109 | mov [edx+COFF_SECTION.PtrReloc], edi |
1118 | sub [edx+COFF_SECTION.PtrReloc], ebx |
1110 | sub [edx+COFF_SECTION.PtrReloc], ebx |
1119 | add esi, [coff] |
1111 | add esi, [coff] |
1120 | shr ecx, 1 |
1112 | shr ecx, 1 |
1121 | rep movsd |
1113 | rep movsd |
1122 | adc ecx, ecx |
1114 | adc ecx, ecx |
1123 | rep movsw |
1115 | rep movsw |
1124 | add edx, sizeof.COFF_SECTION |
1116 | add edx, sizeof.COFF_SECTION |
1125 | dec eax |
1117 | dec eax |
1126 | jnz @b |
1118 | jnz @b |
1127 | pop esi |
1119 | pop esi |
1128 | 1120 | ||
1129 | ; fixup symbols |
1121 | ; fixup symbols |
1130 | mov edx, ebx |
1122 | mov edx, ebx |
1131 | mov eax, [ebx+COFF_HEADER.nSymbols] |
1123 | mov eax, [ebx+COFF_HEADER.nSymbols] |
1132 | add edx, 20 |
1124 | add edx, 20 |
1133 | mov ecx, [esi+DLLDESCR.symbols_num] |
1125 | mov ecx, [esi+DLLDESCR.symbols_num] |
1134 | lea ecx, [ecx*9] |
1126 | lea ecx, [ecx*9] |
1135 | add ecx, ecx |
1127 | add ecx, ecx |
1136 | add ecx, [esi+DLLDESCR.symbols_ptr] |
1128 | add ecx, [esi+DLLDESCR.symbols_ptr] |
1137 | 1129 | ||
1138 | stdcall fix_coff_symbols, edx, [esi+DLLDESCR.symbols_ptr], eax, \ |
1130 | stdcall fix_coff_symbols, edx, [esi+DLLDESCR.symbols_ptr], eax, \ |
1139 | ecx, 0 |
1131 | ecx, 0 |
1140 | ; test eax, eax |
1132 | ; test eax, eax |
1141 | ; jnz @F |
1133 | ; jnz @F |
1142 | ; |
1134 | ; |
1143 | ;@@: |
1135 | ;@@: |
1144 | 1136 | ||
1145 | stdcall get_coff_sym, [esi+DLLDESCR.symbols_ptr], [ebx+COFF_HEADER.nSymbols], szEXPORTS |
1137 | stdcall get_coff_sym, [esi+DLLDESCR.symbols_ptr], [ebx+COFF_HEADER.nSymbols], szEXPORTS |
1146 | test eax, eax |
1138 | test eax, eax |
1147 | jnz @F |
1139 | jnz @F |
1148 | 1140 | ||
1149 | stdcall get_coff_sym, [esi+DLLDESCR.symbols_ptr], [ebx+COFF_HEADER.nSymbols], sz_EXPORTS |
1141 | stdcall get_coff_sym, [esi+DLLDESCR.symbols_ptr], [ebx+COFF_HEADER.nSymbols], sz_EXPORTS |
1150 | @@: |
1142 | @@: |
1151 | mov [esi+DLLDESCR.exports], eax |
1143 | mov [esi+DLLDESCR.exports], eax |
1152 | 1144 | ||
1153 | ; fix relocs in the hidden copy in kernel memory to default address |
1145 | ; fix relocs in the hidden copy in kernel memory to default address |
1154 | ; it is first fix; usually this will be enough, but second fix |
1146 | ; it is first fix; usually this will be enough, but second fix |
1155 | ; can be necessary if real load address will not equal assumption |
1147 | ; can be necessary if real load address will not equal assumption |
1156 | mov eax, [esi+DLLDESCR.data] |
1148 | mov eax, [esi+DLLDESCR.data] |
1157 | sub eax, [esi+DLLDESCR.defaultbase] |
1149 | sub eax, [esi+DLLDESCR.defaultbase] |
1158 | stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax |
1150 | stdcall fix_coff_relocs, ebx, [esi+DLLDESCR.symbols_ptr], eax |
1159 | 1151 | ||
1160 | stdcall kernel_free, [coff] |
1152 | stdcall kernel_free, [coff] |
1161 | 1153 | ||
1162 | .dll_already_loaded: |
1154 | .dll_already_loaded: |
1163 | inc [esi+DLLDESCR.refcount] |
1155 | inc [esi+DLLDESCR.refcount] |
1164 | push esi |
1156 | push esi |
1165 | call init_heap |
1157 | call init_heap |
1166 | pop esi |
1158 | pop esi |
1167 | 1159 | ||
1168 | mov edi, [esi+DLLDESCR.size] |
1160 | mov edi, [esi+DLLDESCR.size] |
1169 | stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi |
1161 | stdcall user_alloc_at, [esi+DLLDESCR.defaultbase], edi |
1170 | test eax, eax |
1162 | test eax, eax |
1171 | jnz @f |
1163 | jnz @f |
1172 | stdcall user_alloc, edi |
1164 | stdcall user_alloc, edi |
1173 | test eax, eax |
1165 | test eax, eax |
1174 | jz .fail_and_dereference |
1166 | jz .fail_and_dereference |
1175 | @@: |
1167 | @@: |
1176 | mov [img_base], eax |
1168 | mov [img_base], eax |
1177 | mov eax, sizeof.HDLL |
1169 | mov eax, sizeof.HDLL |
1178 | call malloc |
1170 | call malloc |
1179 | test eax, eax |
1171 | test eax, eax |
1180 | jz .fail_and_free_user |
1172 | jz .fail_and_free_user |
1181 | mov ebx, [CURRENT_TASK] |
1173 | mov ebx, [CURRENT_TASK] |
1182 | shl ebx, 5 |
1174 | shl ebx, 5 |
1183 | mov edx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1175 | mov edx, [CURRENT_TASK+ebx+TASKDATA.pid] |
1184 | mov [eax+HDLL.pid], edx |
1176 | mov [eax+HDLL.pid], edx |
1185 | push eax |
1177 | push eax |
1186 | call init_dlls_in_thread |
1178 | call init_dlls_in_thread |
1187 | pop ebx |
1179 | pop ebx |
1188 | test eax, eax |
1180 | test eax, eax |
1189 | jz .fail_and_free_user |
1181 | jz .fail_and_free_user |
1190 | mov edx, [eax+HDLL.fd] |
1182 | mov edx, [eax+HDLL.fd] |
1191 | mov [ebx+HDLL.fd], edx |
1183 | mov [ebx+HDLL.fd], edx |
1192 | mov [ebx+HDLL.bk], eax |
1184 | mov [ebx+HDLL.bk], eax |
1193 | mov [eax+HDLL.fd], ebx |
1185 | mov [eax+HDLL.fd], ebx |
1194 | mov [edx+HDLL.bk], ebx |
1186 | mov [edx+HDLL.bk], ebx |
1195 | mov eax, ebx |
1187 | mov eax, ebx |
1196 | mov ebx, [img_base] |
1188 | mov ebx, [img_base] |
1197 | mov [eax+HDLL.base], ebx |
1189 | mov [eax+HDLL.base], ebx |
1198 | mov [eax+HDLL.size], edi |
1190 | mov [eax+HDLL.size], edi |
1199 | mov [eax+HDLL.refcount], 1 |
1191 | mov [eax+HDLL.refcount], 1 |
1200 | mov [eax+HDLL.parent], esi |
1192 | mov [eax+HDLL.parent], esi |
1201 | mov edx, ebx |
1193 | mov edx, ebx |
1202 | shr edx, 12 |
1194 | shr edx, 12 |
1203 | or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK |
1195 | or dword [page_tabs+(edx-1)*4], DONT_FREE_BLOCK |
1204 | ; copy entries of page table from kernel-side image to usermode |
1196 | ; copy entries of page table from kernel-side image to usermode |
1205 | ; use copy-on-write for user-mode image, so map as readonly |
1197 | ; use copy-on-write for user-mode image, so map as readonly |
1206 | xor edi, edi |
1198 | xor edi, edi |
1207 | mov ecx, [esi+DLLDESCR.data] |
1199 | mov ecx, [esi+DLLDESCR.data] |
1208 | shr ecx, 12 |
1200 | shr ecx, 12 |
1209 | .map_pages_loop: |
1201 | .map_pages_loop: |
1210 | mov eax, [page_tabs+ecx*4] |
1202 | mov eax, [page_tabs+ecx*4] |
1211 | and eax, not 0xFFF |
1203 | and eax, not 0xFFF |
1212 | or al, PG_USER |
1204 | or al, PG_USER |
1213 | xchg eax, [page_tabs+edx*4] |
1205 | xchg eax, [page_tabs+edx*4] |
1214 | test al, 1 |
1206 | test al, 1 |
1215 | jz @f |
1207 | jz @f |
1216 | call free_page |
1208 | call free_page |
1217 | @@: |
1209 | @@: |
1218 | invlpg [ebx+edi] |
1210 | invlpg [ebx+edi] |
1219 | inc ecx |
1211 | inc ecx |
1220 | inc edx |
1212 | inc edx |
1221 | add edi, 0x1000 |
1213 | add edi, 0x1000 |
1222 | cmp edi, [esi+DLLDESCR.size] |
1214 | cmp edi, [esi+DLLDESCR.size] |
1223 | jb .map_pages_loop |
1215 | jb .map_pages_loop |
1224 | 1216 | ||
1225 | ; if real user-mode base is not equal to preferred base, relocate image |
1217 | ; if real user-mode base is not equal to preferred base, relocate image |
1226 | sub ebx, [esi+DLLDESCR.defaultbase] |
1218 | sub ebx, [esi+DLLDESCR.defaultbase] |
1227 | jz @f |
1219 | jz @f |
1228 | stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx |
1220 | stdcall rebase_coff, [esi+DLLDESCR.coff_hdr], [esi+DLLDESCR.symbols_ptr], ebx |
1229 | @@: |
1221 | @@: |
1230 | 1222 | ||
1231 | mov eax, [esi+DLLDESCR.exports] |
1223 | mov eax, [esi+DLLDESCR.exports] |
1232 | sub eax, [esi+DLLDESCR.defaultbase] |
1224 | sub eax, [esi+DLLDESCR.defaultbase] |
1233 | add eax, [img_base] |
1225 | add eax, [img_base] |
1234 | ret |
1226 | ret |
1235 | .fail_and_free_data: |
1227 | .fail_and_free_data: |
1236 | stdcall kernel_free, [esi+DLLDESCR.data] |
1228 | stdcall kernel_free, [esi+DLLDESCR.data] |
1237 | .fail_and_free_dll: |
1229 | .fail_and_free_dll: |
1238 | mov eax, esi |
1230 | mov eax, esi |
1239 | call free |
1231 | call free |
1240 | .fail_and_free_coff: |
1232 | .fail_and_free_coff: |
1241 | stdcall kernel_free, [coff] |
1233 | stdcall kernel_free, [coff] |
1242 | .fail: |
1234 | .fail: |
1243 | xor eax, eax |
1235 | xor eax, eax |
1244 | ret |
1236 | ret |
1245 | .fail_and_free_user: |
1237 | .fail_and_free_user: |
1246 | stdcall user_free, [img_base] |
1238 | stdcall user_free, [img_base] |
1247 | .fail_and_dereference: |
1239 | .fail_and_dereference: |
1248 | mov eax, 1 ; delete 1 reference |
1240 | mov eax, 1 ; delete 1 reference |
1249 | call dereference_dll |
1241 | call dereference_dll |
1250 | xor eax, eax |
1242 | xor eax, eax |
1251 | ret |
1243 | ret |
1252 | endp |
1244 | endp |
1253 | 1245 | ||
1254 | ; initialize [APPDATA.dlls_list_ptr] for given thread |
1246 | ; initialize [APPDATA.dlls_list_ptr] for given thread |
1255 | ; DLL is per-process object, so APPDATA.dlls_list_ptr must be |
1247 | ; DLL is per-process object, so APPDATA.dlls_list_ptr must be |
1256 | ; kept in sync for all threads of one process. |
1248 | ; kept in sync for all threads of one process. |
1257 | ; out: eax = APPDATA.dlls_list_ptr if all is OK, |
1249 | ; out: eax = APPDATA.dlls_list_ptr if all is OK, |
1258 | ; NULL if memory allocation failed |
1250 | ; NULL if memory allocation failed |
1259 | init_dlls_in_thread: |
1251 | init_dlls_in_thread: |
1260 | mov ebx, [current_slot] |
1252 | mov ebx, [current_slot] |
1261 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
1253 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
1262 | test eax, eax |
1254 | test eax, eax |
1263 | jnz .ret |
1255 | jnz .ret |
1264 | push [ebx+APPDATA.dir_table] |
1256 | push [ebx+APPDATA.dir_table] |
1265 | mov eax, 8 |
1257 | mov eax, 8 |
1266 | call malloc |
1258 | call malloc |
1267 | pop edx |
1259 | pop edx |
1268 | test eax, eax |
1260 | test eax, eax |
1269 | jz .ret |
1261 | jz .ret |
1270 | mov [eax], eax |
1262 | mov [eax], eax |
1271 | mov [eax+4], eax |
1263 | mov [eax+4], eax |
1272 | mov ecx, [TASK_COUNT] |
1264 | mov ecx, [TASK_COUNT] |
1273 | mov ebx, SLOT_BASE+256 |
1265 | mov ebx, SLOT_BASE+256 |
1274 | .set: |
1266 | .set: |
1275 | cmp [ebx+APPDATA.dir_table], edx |
1267 | cmp [ebx+APPDATA.dir_table], edx |
1276 | jnz @f |
1268 | jnz @f |
1277 | mov [ebx+APPDATA.dlls_list_ptr], eax |
1269 | mov [ebx+APPDATA.dlls_list_ptr], eax |
1278 | @@: |
1270 | @@: |
1279 | add ebx, 256 |
1271 | add ebx, 256 |
1280 | dec ecx |
1272 | dec ecx |
1281 | jnz .set |
1273 | jnz .set |
1282 | .ret: |
1274 | .ret: |
1283 | ret |
1275 | ret |
1284 | 1276 | ||
1285 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
1277 | ; in: eax = number of references to delete, esi -> DLLDESCR struc |
1286 | dereference_dll: |
1278 | dereference_dll: |
1287 | sub [esi+DLLDESCR.refcount], eax |
1279 | sub [esi+DLLDESCR.refcount], eax |
1288 | jnz .ret |
1280 | jnz .ret |
1289 | mov eax, [esi+DLLDESCR.fd] |
1281 | mov eax, [esi+DLLDESCR.fd] |
1290 | mov edx, [esi+DLLDESCR.bk] |
1282 | mov edx, [esi+DLLDESCR.bk] |
1291 | mov [eax+DLLDESCR.bk], edx |
1283 | mov [eax+DLLDESCR.bk], edx |
1292 | mov [edx+DLLDESCR.fd], eax |
1284 | mov [edx+DLLDESCR.fd], eax |
1293 | stdcall kernel_free, [esi+DLLDESCR.coff_hdr] |
1285 | stdcall kernel_free, [esi+DLLDESCR.coff_hdr] |
1294 | stdcall kernel_free, [esi+DLLDESCR.data] |
1286 | stdcall kernel_free, [esi+DLLDESCR.data] |
1295 | mov eax, esi |
1287 | mov eax, esi |
1296 | call free |
1288 | call free |
1297 | .ret: |
1289 | .ret: |
1298 | ret |
1290 | ret |
1299 | 1291 | ||
1300 | destroy_hdll: |
1292 | destroy_hdll: |
1301 | push ebx ecx esi edi |
1293 | push ebx ecx esi edi |
1302 | push eax |
1294 | push eax |
1303 | mov ebx, [eax+HDLL.base] |
1295 | mov ebx, [eax+HDLL.base] |
1304 | mov esi, [eax+HDLL.parent] |
1296 | mov esi, [eax+HDLL.parent] |
1305 | mov edx, [esi+DLLDESCR.size] |
1297 | mov edx, [esi+DLLDESCR.size] |
1306 | ; The following actions require the context of application where HDLL is mapped. |
1298 | ; The following actions require the context of application where HDLL is mapped. |
1307 | ; However, destroy_hdll can be called in the context of OS thread when |
1299 | ; However, destroy_hdll can be called in the context of OS thread when |
1308 | ; cleaning up objects created by the application which is destroyed. |
1300 | ; cleaning up objects created by the application which is destroyed. |
1309 | ; So remember current cr3 and set it to page table of target. |
1301 | ; So remember current cr3 and set it to page table of target. |
1310 | mov eax, [ecx+APPDATA.dir_table] |
1302 | mov eax, [ecx+APPDATA.dir_table] |
1311 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
1303 | ; Because we cheat with cr3, disable interrupts: task switch would restore |
1312 | ; page table from APPDATA of current thread. |
1304 | ; page table from APPDATA of current thread. |
1313 | ; Also set [current_slot] because it is used by user_free. |
1305 | ; Also set [current_slot] because it is used by user_free. |
1314 | pushf |
1306 | pushf |
1315 | cli |
1307 | cli |
1316 | push [current_slot] |
1308 | push [current_slot] |
1317 | mov [current_slot], ecx |
1309 | mov [current_slot], ecx |
1318 | mov ecx, cr3 |
1310 | mov ecx, cr3 |
1319 | push ecx |
1311 | push ecx |
1320 | mov cr3, eax |
1312 | mov cr3, eax |
1321 | push ebx ; argument for user_free |
1313 | push ebx ; argument for user_free |
1322 | mov eax, ebx |
1314 | mov eax, ebx |
1323 | shr ebx, 12 |
1315 | shr ebx, 12 |
1324 | push ebx |
1316 | push ebx |
1325 | mov esi, [esi+DLLDESCR.data] |
1317 | mov esi, [esi+DLLDESCR.data] |
1326 | shr esi, 12 |
1318 | shr esi, 12 |
1327 | .unmap_loop: |
1319 | .unmap_loop: |
1328 | push eax |
1320 | push eax |
1329 | mov eax, 2 |
1321 | mov eax, 2 |
1330 | xchg eax, [page_tabs+ebx*4] |
1322 | xchg eax, [page_tabs+ebx*4] |
1331 | mov ecx, [page_tabs+esi*4] |
1323 | mov ecx, [page_tabs+esi*4] |
1332 | and eax, not 0xFFF |
1324 | and eax, not 0xFFF |
1333 | and ecx, not 0xFFF |
1325 | and ecx, not 0xFFF |
1334 | cmp eax, ecx |
1326 | cmp eax, ecx |
1335 | jz @f |
1327 | jz @f |
1336 | call free_page |
1328 | call free_page |
1337 | @@: |
1329 | @@: |
1338 | pop eax |
1330 | pop eax |
1339 | invlpg [eax] |
1331 | invlpg [eax] |
1340 | add eax, 0x1000 |
1332 | add eax, 0x1000 |
1341 | inc ebx |
1333 | inc ebx |
1342 | inc esi |
1334 | inc esi |
1343 | sub edx, 0x1000 |
1335 | sub edx, 0x1000 |
1344 | ja .unmap_loop |
1336 | ja .unmap_loop |
1345 | pop ebx |
1337 | pop ebx |
1346 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |
1338 | and dword [page_tabs+(ebx-1)*4], not DONT_FREE_BLOCK |
1347 | call user_free |
1339 | call user_free |
1348 | ; Restore context. |
1340 | ; Restore context. |
1349 | pop eax |
1341 | pop eax |
1350 | mov cr3, eax |
1342 | mov cr3, eax |
1351 | pop [current_slot] |
1343 | pop [current_slot] |
1352 | popf |
1344 | popf |
1353 | ; Ok, cheating is done. |
1345 | ; Ok, cheating is done. |
1354 | pop eax |
1346 | pop eax |
1355 | push eax |
1347 | push eax |
1356 | mov esi, [eax+HDLL.parent] |
1348 | mov esi, [eax+HDLL.parent] |
1357 | mov eax, [eax+HDLL.refcount] |
1349 | mov eax, [eax+HDLL.refcount] |
1358 | call dereference_dll |
1350 | call dereference_dll |
1359 | pop eax |
1351 | pop eax |
1360 | mov edx, [eax+HDLL.bk] |
1352 | mov edx, [eax+HDLL.bk] |
1361 | mov ebx, [eax+HDLL.fd] |
1353 | mov ebx, [eax+HDLL.fd] |
1362 | mov [ebx+HDLL.bk], edx |
1354 | mov [ebx+HDLL.bk], edx |
1363 | mov [edx+HDLL.fd], ebx |
1355 | mov [edx+HDLL.fd], ebx |
1364 | call free |
1356 | call free |
1365 | pop edi esi ecx ebx |
1357 | pop edi esi ecx ebx |
1366 | ret |
1358 | ret |
1367 | 1359 | ||
1368 | ; ecx -> APPDATA for slot, esi = dlls_list_ptr |
1360 | ; ecx -> APPDATA for slot, esi = dlls_list_ptr |
1369 | destroy_all_hdlls: |
1361 | destroy_all_hdlls: |
1370 | test esi, esi |
1362 | test esi, esi |
1371 | jz .ret |
1363 | jz .ret |
1372 | .loop: |
1364 | .loop: |
1373 | mov eax, [esi+HDLL.fd] |
1365 | mov eax, [esi+HDLL.fd] |
1374 | cmp eax, esi |
1366 | cmp eax, esi |
1375 | jz free |
1367 | jz free |
1376 | call destroy_hdll |
1368 | call destroy_hdll |
1377 | jmp .loop |
1369 | jmp .loop |
1378 | .ret: |
1370 | .ret: |
1379 | ret |
1371 | ret |
1380 | 1372 | ||
1381 | align 4 |
1373 | align 4 |
1382 | stop_all_services: |
1374 | stop_all_services: |
1383 | push ebp |
1375 | push ebp |
1384 | mov edx, [srv.fd] |
1376 | mov edx, [srv.fd] |
1385 | .next: |
1377 | .next: |
1386 | cmp edx, srv.fd-SRV.fd |
1378 | cmp edx, srv.fd-SRV.fd |
1387 | je .done |
1379 | je .done |
1388 | cmp [edx+SRV.magic], ' SRV' |
1380 | cmp [edx+SRV.magic], ' SRV' |
1389 | jne .next |
1381 | jne .next |
1390 | cmp [edx+SRV.size], sizeof.SRV |
1382 | cmp [edx+SRV.size], sizeof.SRV |
1391 | jne .next |
1383 | jne .next |
1392 | 1384 | ||
1393 | mov ebx, [edx+SRV.entry] |
1385 | mov ebx, [edx+SRV.entry] |
1394 | mov edx, [edx+SRV.fd] |
1386 | mov edx, [edx+SRV.fd] |
1395 | test ebx, ebx |
1387 | test ebx, ebx |
1396 | jz .next |
1388 | jz .next |
1397 | 1389 | ||
1398 | push edx |
1390 | push edx |
1399 | mov ebp, esp |
1391 | mov ebp, esp |
1400 | push 0 |
1392 | push 0 |
1401 | push -1 |
1393 | push -1 |
1402 | call ebx |
1394 | call ebx |
1403 | mov esp, ebp |
1395 | mov esp, ebp |
1404 | pop edx |
1396 | pop edx |
1405 | jmp .next |
1397 | jmp .next |
1406 | .done: |
1398 | .done: |
1407 | pop ebp |
1399 | pop ebp |
1408 | ret |
1400 | ret |
1409 | 1401 | ||
1410 | ; param |
1402 | ; param |
1411 | ; eax= size |
1403 | ; eax= size |
1412 | ; ebx= pid |
1404 | ; ebx= pid |
1413 | 1405 | ||
1414 | align 4 |
1406 | align 4 |
1415 | create_kernel_object: |
1407 | create_kernel_object: |
1416 | 1408 | ||
1417 | push ebx |
1409 | push ebx |
1418 | call malloc |
1410 | call malloc |
1419 | pop ebx |
1411 | pop ebx |
1420 | test eax, eax |
1412 | test eax, eax |
1421 | jz .fail |
1413 | jz .fail |
1422 | 1414 | ||
1423 | mov ecx, [current_slot] |
1415 | mov ecx, [current_slot] |
1424 | add ecx, APP_OBJ_OFFSET |
1416 | add ecx, APP_OBJ_OFFSET |
1425 | 1417 | ||
1426 | pushfd |
1418 | pushfd |
1427 | cli |
1419 | cli |
1428 | mov edx, [ecx+APPOBJ.fd] |
1420 | mov edx, [ecx+APPOBJ.fd] |
1429 | mov [eax+APPOBJ.fd], edx |
1421 | mov [eax+APPOBJ.fd], edx |
1430 | mov [eax+APPOBJ.bk], ecx |
1422 | mov [eax+APPOBJ.bk], ecx |
1431 | mov [eax+APPOBJ.pid], ebx |
1423 | mov [eax+APPOBJ.pid], ebx |
1432 | 1424 | ||
1433 | mov [ecx+APPOBJ.fd], eax |
1425 | mov [ecx+APPOBJ.fd], eax |
1434 | mov [edx+APPOBJ.bk], eax |
1426 | mov [edx+APPOBJ.bk], eax |
1435 | popfd |
1427 | popfd |
1436 | .fail: |
1428 | .fail: |
1437 | ret |
1429 | ret |
1438 | 1430 | ||
1439 | ; param |
1431 | ; param |
1440 | ; eax= object |
1432 | ; eax= object |
1441 | 1433 | ||
1442 | align 4 |
1434 | align 4 |
1443 | destroy_kernel_object: |
1435 | destroy_kernel_object: |
1444 | 1436 | ||
1445 | pushfd |
1437 | pushfd |
1446 | cli |
1438 | cli |
1447 | mov ebx, [eax+APPOBJ.fd] |
1439 | mov ebx, [eax+APPOBJ.fd] |
1448 | mov ecx, [eax+APPOBJ.bk] |
1440 | mov ecx, [eax+APPOBJ.bk] |
1449 | mov [ebx+APPOBJ.bk], ecx |
1441 | mov [ebx+APPOBJ.bk], ecx |
1450 | mov [ecx+APPOBJ.fd], ebx |
1442 | mov [ecx+APPOBJ.fd], ebx |
1451 | popfd |
1443 | popfd |
1452 | 1444 | ||
1453 | xor edx, edx ;clear common header |
1445 | xor edx, edx ;clear common header |
1454 | mov [eax], edx |
1446 | mov [eax], edx |
1455 | mov [eax+4], edx |
1447 | mov [eax+4], edx |
1456 | mov [eax+8], edx |
1448 | mov [eax+8], edx |
1457 | mov [eax+12], edx |
1449 | mov [eax+12], edx |
1458 | mov [eax+16], edx |
1450 | mov [eax+16], edx |
1459 | 1451 | ||
1460 | call free ;release object memory |
1452 | call free ;release object memory |
1461 | ret |
1453 | ret |