Rev 5350 | Rev 5363 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5350 | Rev 5356 | ||
---|---|---|---|
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: 5350 $ |
8 | $Revision: 5356 $ |
9 | 9 | ||
10 | 10 | ||
11 | GREEDY_KERNEL equ 0 |
11 | GREEDY_KERNEL equ 0 |
12 | 12 | ||
13 | struct APP_HEADER_00_ |
13 | struct APP_HEADER_00_ |
14 | banner dq ? |
14 | banner dq ? |
15 | version dd ? ;+8 |
15 | version dd ? ;+8 |
16 | start dd ? ;+12 |
16 | start dd ? ;+12 |
17 | i_end dd ? ;+16 |
17 | i_end dd ? ;+16 |
18 | mem_size dd ? ;+20 |
18 | mem_size dd ? ;+20 |
19 | i_param dd ? ;+24 |
19 | i_param dd ? ;+24 |
20 | ends |
20 | ends |
21 | 21 | ||
22 | struct APP_HEADER_01_ |
22 | struct APP_HEADER_01_ |
23 | banner dq ? |
23 | banner dq ? |
24 | version dd ? ;+8 |
24 | version dd ? ;+8 |
25 | start dd ? ;+12 |
25 | start dd ? ;+12 |
26 | i_end dd ? ;+16 |
26 | i_end dd ? ;+16 |
27 | mem_size dd ? ;+20 |
27 | mem_size dd ? ;+20 |
28 | stack_top dd ? ;+24 |
28 | stack_top dd ? ;+24 |
29 | i_param dd ? ;+28 |
29 | i_param dd ? ;+28 |
30 | i_icon dd ? ;+32 |
30 | i_icon dd ? ;+32 |
31 | ends |
31 | ends |
32 | 32 | ||
33 | 33 | ||
34 | struct APP_PARAMS |
34 | struct APP_PARAMS |
35 | app_cmdline dd ? ;0x00 |
35 | app_cmdline dd ? ;0x00 |
36 | app_path dd ? ;0x04 |
36 | app_path dd ? ;0x04 |
37 | app_eip dd ? ;0x08 |
37 | app_eip dd ? ;0x08 |
38 | app_esp dd ? ;0x0C |
38 | app_esp dd ? ;0x0C |
39 | app_mem dd ? ;0x10 |
39 | app_mem dd ? ;0x10 |
40 | ends |
40 | ends |
41 | 41 | ||
42 | macro _clear_ op |
42 | macro _clear_ op |
43 | { mov ecx, op/4 |
43 | { mov ecx, op/4 |
44 | xor eax, eax |
44 | xor eax, eax |
45 | cld |
45 | cld |
46 | rep stosd |
46 | rep stosd |
47 | } |
47 | } |
48 | 48 | ||
49 | fs_execute_from_sysdir: |
49 | fs_execute_from_sysdir: |
50 | xor ebx, ebx |
50 | xor ebx, ebx |
51 | fs_execute_from_sysdir_param: |
51 | fs_execute_from_sysdir_param: |
52 | xor edx, edx |
52 | xor edx, edx |
53 | mov esi, sysdir_path |
53 | mov esi, sysdir_path |
54 | 54 | ||
55 | align 4 |
55 | align 4 |
56 | proc fs_execute |
56 | proc fs_execute |
57 | 57 | ||
58 | ;fn_read:dword, file_size:dword, cluster:dword |
58 | ;fn_read:dword, file_size:dword, cluster:dword |
59 | 59 | ||
60 | ; ebx - cmdline |
60 | ; ebx - cmdline |
61 | ; edx - flags |
61 | ; edx - flags |
62 | ; ebp - full filename |
62 | ; ebp - full filename |
63 | ; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it |
63 | ; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it |
64 | 64 | ||
65 | locals |
65 | locals |
66 | cmdline_size dd ? ; +0 ; cmdline -12 |
66 | cmdline_size dd ? ; +0 ; cmdline -12 |
67 | cmdline_adr dd ? ; +4 ; cmdline -8 |
67 | cmdline_adr dd ? ; +4 ; cmdline -8 |
68 | cmdline_flag dd ? ; +8 ; cmdline -4 |
68 | cmdline_flag dd ? ; +8 ; cmdline -4 |
69 | cmdline rd 64 ;256/4 |
69 | cmdline rd 64 ;256/4 |
70 | filename rd 256 ;1024/4 |
70 | filename rd 256 ;1024/4 |
71 | flags dd ? |
71 | flags dd ? |
72 | 72 | ||
73 | save_proc dd ? |
73 | save_proc dd ? |
74 | slot dd ? |
74 | slot dd ? |
75 | slot_base dd ? |
75 | slot_base dd ? |
76 | file_base dd ? |
76 | file_base dd ? |
77 | file_size dd ? |
77 | file_size dd ? |
78 | handle dd ? ;temp. for default cursor handle for curr. thread |
78 | handle dd ? ;temp. for default cursor handle for curr. thread |
79 | ;app header data |
79 | ;app header data |
80 | hdr_cmdline dd ? ;0x00 |
80 | hdr_cmdline dd ? ;0x00 |
81 | hdr_path dd ? ;0x04 |
81 | hdr_path dd ? ;0x04 |
82 | hdr_eip dd ? ;0x08 |
82 | hdr_eip dd ? ;0x08 |
83 | hdr_esp dd ? ;0x0C |
83 | hdr_esp dd ? ;0x0C |
84 | hdr_mem dd ? ;0x10 |
84 | hdr_mem dd ? ;0x10 |
85 | hdr_i_end dd ? ;0x14 |
85 | hdr_i_end dd ? ;0x14 |
86 | endl |
86 | endl |
87 | 87 | ||
88 | pushad |
88 | pushad |
89 | 89 | ||
90 | cmp [SCR_MODE], word 0x13 |
90 | cmp [SCR_MODE], word 0x13 |
91 | jbe @f |
91 | jbe @f |
92 | pushad |
92 | pushad |
93 | stdcall set_cursor, [def_cursor_clock] |
93 | stdcall set_cursor, [def_cursor_clock] |
94 | mov [handle], eax |
94 | mov [handle], eax |
95 | mov [redrawmouse_unconditional], 1 |
95 | mov [redrawmouse_unconditional], 1 |
96 | call wakeup_osloop |
96 | call wakeup_osloop |
97 | popad |
97 | popad |
98 | @@: |
98 | @@: |
99 | mov [flags], edx |
99 | mov [flags], edx |
100 | 100 | ||
101 | ; [ebp] pointer to filename |
101 | ; [ebp] pointer to filename |
102 | 102 | ||
103 | lea edi, [filename] |
103 | lea edi, [filename] |
104 | lea ecx, [edi+1024] |
104 | lea ecx, [edi+1024] |
105 | mov al, '/' |
105 | mov al, '/' |
106 | stosb |
106 | stosb |
107 | @@: |
107 | @@: |
108 | cmp edi, ecx |
108 | cmp edi, ecx |
109 | jae .bigfilename |
109 | jae .bigfilename |
110 | lodsb |
110 | lodsb |
111 | stosb |
111 | stosb |
112 | test al, al |
112 | test al, al |
113 | jnz @b |
113 | jnz @b |
114 | mov esi, [ebp] |
114 | mov esi, [ebp] |
115 | test esi, esi |
115 | test esi, esi |
116 | jz .namecopied |
116 | jz .namecopied |
117 | mov byte [edi-1], '/' |
117 | mov byte [edi-1], '/' |
118 | @@: |
118 | @@: |
119 | cmp edi, ecx |
119 | cmp edi, ecx |
120 | jae .bigfilename |
120 | jae .bigfilename |
121 | lodsb |
121 | lodsb |
122 | stosb |
122 | stosb |
123 | test al, al |
123 | test al, al |
124 | jnz @b |
124 | jnz @b |
125 | jmp .namecopied |
125 | jmp .namecopied |
126 | .bigfilename: |
126 | .bigfilename: |
127 | popad |
127 | popad |
128 | mov eax, -ERROR_FILE_NOT_FOUND |
128 | mov eax, -ERROR_FILE_NOT_FOUND |
129 | 129 | ||
130 | jmp .final |
130 | jmp .final |
131 | 131 | ||
132 | .namecopied: |
132 | .namecopied: |
133 | xor eax, eax |
133 | xor eax, eax |
134 | mov [cmdline_flag], eax |
134 | mov [cmdline_flag], eax |
135 | mov [cmdline_adr], eax |
135 | mov [cmdline_adr], eax |
136 | mov [cmdline_size], eax |
136 | mov [cmdline_size], eax |
137 | 137 | ||
138 | mov [cmdline], ebx |
138 | mov [cmdline], ebx |
139 | test ebx, ebx |
139 | test ebx, ebx |
140 | jz .no_copy |
140 | jz .no_copy |
141 | ;-------------------------------------- |
141 | ;-------------------------------------- |
142 | pushad |
142 | pushad |
143 | pushfd |
143 | pushfd |
144 | mov esi, ebx |
144 | mov esi, ebx |
145 | mov ecx, 65536 ; 64 Kb max for ext.cmdline |
145 | mov ecx, 65536 ; 64 Kb max for ext.cmdline |
146 | cld |
146 | cld |
147 | @@: |
147 | @@: |
148 | dec ecx |
148 | dec ecx |
149 | jz .end_string |
149 | jz .end_string |
150 | 150 | ||
151 | lodsb |
151 | lodsb |
152 | test al, al |
152 | test al, al |
153 | jnz @b |
153 | jnz @b |
154 | 154 | ||
155 | .end_string: |
155 | .end_string: |
156 | mov eax, 65536 ; 64 Kb max for ext.cmdline |
156 | mov eax, 65536 ; 64 Kb max for ext.cmdline |
157 | sub eax, ecx |
157 | sub eax, ecx |
158 | mov [cmdline_size], eax |
158 | mov [cmdline_size], eax |
159 | cmp eax, 255 |
159 | cmp eax, 255 |
160 | ja @f |
160 | ja @f |
161 | 161 | ||
162 | popfd |
162 | popfd |
163 | popad |
163 | popad |
164 | jmp .old_copy |
164 | jmp .old_copy |
165 | 165 | ||
166 | @@: |
166 | @@: |
167 | xor eax, eax |
167 | xor eax, eax |
168 | dec eax |
168 | dec eax |
169 | mov [cmdline_flag], eax |
169 | mov [cmdline_flag], eax |
170 | popfd |
170 | popfd |
171 | popad |
171 | popad |
172 | ; get memory for the extended command line |
172 | ; get memory for the extended command line |
173 | stdcall kernel_alloc, [cmdline_size] ;eax |
173 | stdcall kernel_alloc, [cmdline_size] ;eax |
174 | test eax, eax |
174 | test eax, eax |
175 | jz .old_copy ; get memory failed |
175 | jz .old_copy ; get memory failed |
176 | 176 | ||
177 | mov [cmdline_adr], eax |
177 | mov [cmdline_adr], eax |
178 | 178 | ||
179 | pushad |
179 | pushad |
180 | pushfd |
180 | pushfd |
181 | mov esi, ebx |
181 | mov esi, ebx |
182 | mov edi, eax |
182 | mov edi, eax |
183 | mov ecx, [cmdline_size] |
183 | mov ecx, [cmdline_size] |
184 | cld |
184 | cld |
185 | rep movsb |
185 | rep movsb |
186 | popfd |
186 | popfd |
187 | popad |
187 | popad |
188 | jmp .no_copy |
188 | jmp .no_copy |
189 | 189 | ||
190 | .old_copy: |
190 | .old_copy: |
191 | ; clear flag because old method with 256 bytes |
191 | ; clear flag because old method with 256 bytes |
192 | xor eax, eax |
192 | xor eax, eax |
193 | mov [cmdline_flag], eax |
193 | mov [cmdline_flag], eax |
194 | ;-------------------------------------- |
194 | ;-------------------------------------- |
195 | lea eax, [cmdline] |
195 | lea eax, [cmdline] |
196 | mov dword [eax+252], 0 |
196 | mov dword [eax+252], 0 |
197 | .copy: |
197 | .copy: |
198 | stdcall strncpy, eax, ebx, 255 |
198 | stdcall strncpy, eax, ebx, 255 |
199 | .no_copy: |
199 | .no_copy: |
200 | lea eax, [filename] |
200 | lea eax, [filename] |
201 | stdcall load_file, eax |
201 | stdcall load_file, eax |
202 | 202 | ||
203 | mov esi, -ERROR_FILE_NOT_FOUND |
203 | mov esi, -ERROR_FILE_NOT_FOUND |
204 | test eax, eax |
204 | test eax, eax |
205 | jz .err_file |
205 | jz .err_file |
206 | 206 | ||
207 | mov [file_base], eax |
207 | mov [file_base], eax |
208 | mov [file_size], ebx |
208 | mov [file_size], ebx |
209 | 209 | ||
210 | lea ebx, [hdr_cmdline] |
210 | lea ebx, [hdr_cmdline] |
211 | call test_app_header |
211 | call test_app_header |
212 | mov esi, -0x1F |
212 | mov esi, -0x1F |
213 | test eax, eax |
213 | test eax, eax |
214 | jz .err_hdr |
214 | jz .err_hdr |
215 | 215 | ||
216 | call lock_application_table |
216 | call lock_application_table |
217 | 217 | ||
218 | call alloc_thread_slot |
218 | call alloc_thread_slot |
219 | test eax, eax |
219 | test eax, eax |
220 | mov esi, -0x20 ; too many processes |
220 | mov esi, -0x20 ; too many processes |
221 | jz .err |
221 | jz .err |
222 | 222 | ||
223 | mov [slot], eax |
223 | mov [slot], eax |
224 | shl eax, 8 |
224 | shl eax, 8 |
225 | add eax, SLOT_BASE |
225 | add eax, SLOT_BASE |
226 | mov [slot_base], eax |
226 | mov [slot_base], eax |
227 | mov edi, eax |
227 | mov edi, eax |
228 | _clear_ 256 ;clean extended information about process |
228 | _clear_ 256 ;clean extended information about process |
229 | 229 | ||
230 | ; write application name |
230 | ; write application name |
231 | lea eax, [filename] |
231 | lea eax, [filename] |
232 | stdcall strrchr, eax, '/' ; now eax points to name without path |
232 | stdcall strrchr, eax, '/' ; now eax points to name without path |
233 | 233 | ||
234 | lea esi, [eax+1] |
234 | lea esi, [eax+1] |
235 | test eax, eax |
235 | test eax, eax |
236 | jnz @F |
236 | jnz @F |
237 | lea esi, [filename] |
237 | lea esi, [filename] |
238 | @@: |
238 | @@: |
239 | mov ecx, 11 ; 11 chars for name! 8 - is old value! |
239 | mov ecx, 11 ; 11 chars for name! 8 - is old value! |
240 | mov edi, [slot_base] |
240 | mov edi, [slot_base] |
241 | .copy_process_name_loop: |
241 | .copy_process_name_loop: |
242 | lodsb |
242 | lodsb |
243 | cmp al, '.' |
243 | cmp al, '.' |
244 | jz .copy_process_name_done |
244 | jz .copy_process_name_done |
245 | test al, al |
245 | test al, al |
246 | jz .copy_process_name_done |
246 | jz .copy_process_name_done |
247 | stosb |
247 | stosb |
248 | loop .copy_process_name_loop |
248 | loop .copy_process_name_loop |
249 | .copy_process_name_done: |
249 | .copy_process_name_done: |
250 | 250 | ||
251 | mov ebx, [current_process] |
251 | mov ebx, [current_process] |
252 | mov [save_proc], ebx |
252 | mov [save_proc], ebx |
253 | 253 | ||
254 | stdcall create_process, [hdr_mem], [file_base], [file_size] |
254 | stdcall create_process, [hdr_mem], [file_base], [file_size] |
255 | mov esi, -30; no memory |
255 | mov esi, -30; no memory |
256 | test eax, eax |
256 | test eax, eax |
257 | jz .failed |
257 | jz .failed |
258 | 258 | ||
259 | mov ebx, [hdr_mem] |
259 | mov ebx, [hdr_mem] |
260 | mov [eax+PROC.mem_used], ebx |
260 | mov [eax+PROC.mem_used], ebx |
261 | 261 | ||
262 | mov ebx, [slot_base] |
262 | mov ebx, [slot_base] |
263 | mov [ebx+APPDATA.process], eax |
263 | mov [ebx+APPDATA.process], eax |
264 | 264 | ||
265 | lea edx, [ebx+APPDATA.list] |
265 | lea edx, [ebx+APPDATA.list] |
266 | lea ecx, [eax+PROC.thr_list] |
266 | lea ecx, [eax+PROC.thr_list] |
267 | list_add_tail edx, ecx |
267 | list_add_tail edx, ecx |
268 | 268 | ||
269 | xor edx, edx |
269 | xor edx, edx |
270 | cmp word [6], '02' |
270 | cmp word [6], '02' |
271 | jne @f |
271 | jne @f |
272 | 272 | ||
273 | not edx |
273 | not edx |
274 | @@: |
274 | @@: |
275 | mov [ebx+APPDATA.tls_base], edx |
275 | mov [ebx+APPDATA.tls_base], edx |
276 | 276 | ||
277 | if GREEDY_KERNEL |
277 | if GREEDY_KERNEL |
278 | else |
278 | else |
279 | mov ecx, [hdr_mem] |
279 | mov ecx, [hdr_mem] |
280 | mov edi, [file_size] |
280 | mov edi, [file_size] |
281 | add edi, 4095 |
281 | add edi, 4095 |
282 | and edi, not 4095 |
282 | and edi, not 4095 |
283 | sub ecx, edi |
283 | sub ecx, edi |
284 | jna @F |
284 | jna @F |
285 | 285 | ||
286 | xor eax, eax |
286 | xor eax, eax |
287 | cld |
287 | cld |
288 | rep stosb |
288 | rep stosb |
289 | @@: |
289 | @@: |
290 | end if |
290 | end if |
291 | 291 | ||
292 | ; release only virtual space, not phisical memory |
292 | ; release only virtual space, not phisical memory |
293 | 293 | ||
294 | stdcall free_kernel_space, [file_base] |
294 | stdcall free_kernel_space, [file_base] |
295 | lea eax, [hdr_cmdline] |
295 | lea eax, [hdr_cmdline] |
296 | lea ebx, [cmdline] |
296 | lea ebx, [cmdline] |
297 | lea ecx, [filename] |
297 | lea ecx, [filename] |
298 | stdcall set_app_params , [slot], eax, ebx, ecx, [flags] |
298 | stdcall set_app_params , [slot], eax, ebx, ecx, [flags] |
299 | 299 | ||
300 | mov eax, [save_proc] |
300 | mov eax, [save_proc] |
301 | call set_cr3 |
301 | call set_cr3 |
302 | 302 | ||
303 | mov eax, [process_number];set result |
303 | mov eax, [process_number];set result |
304 | call unlock_application_table |
304 | call unlock_application_table |
305 | 305 | ||
306 | jmp .final |
306 | jmp .final |
307 | 307 | ||
308 | .failed: |
308 | .failed: |
309 | mov eax, [save_proc] |
309 | mov eax, [save_proc] |
310 | call set_cr3 |
310 | call set_cr3 |
311 | .err: |
311 | .err: |
312 | .err_hdr: |
312 | .err_hdr: |
313 | stdcall kernel_free, [file_base] |
313 | stdcall kernel_free, [file_base] |
314 | .err_file: |
314 | .err_file: |
315 | call unlock_application_table |
315 | call unlock_application_table |
316 | mov eax, esi |
316 | mov eax, esi |
317 | .final: |
317 | .final: |
318 | cmp [SCR_MODE], word 0x13 |
318 | cmp [SCR_MODE], word 0x13 |
319 | jbe @f |
319 | jbe @f |
320 | pushad |
320 | pushad |
321 | stdcall set_cursor, [handle] |
321 | stdcall set_cursor, [handle] |
322 | mov [redrawmouse_unconditional], 1 |
322 | mov [redrawmouse_unconditional], 1 |
323 | call wakeup_osloop |
323 | call wakeup_osloop |
324 | popad |
324 | popad |
325 | @@: |
325 | @@: |
326 | ret |
326 | ret |
327 | endp |
327 | endp |
328 | 328 | ||
329 | align 4 |
329 | align 4 |
330 | test_app_header: |
330 | test_app_header: |
331 | virtual at eax |
331 | virtual at eax |
332 | APP_HEADER_00 APP_HEADER_00_ |
332 | APP_HEADER_00 APP_HEADER_00_ |
333 | end virtual |
333 | end virtual |
334 | virtual at eax |
334 | virtual at eax |
335 | APP_HEADER_01 APP_HEADER_01_ |
335 | APP_HEADER_01 APP_HEADER_01_ |
336 | end virtual |
336 | end virtual |
337 | 337 | ||
338 | cmp dword [eax], 'MENU' |
338 | cmp dword [eax], 'MENU' |
339 | jne .fail |
339 | jne .fail |
340 | cmp word [eax+4], 'ET' |
340 | cmp word [eax+4], 'ET' |
341 | jne .fail |
341 | jne .fail |
342 | 342 | ||
343 | cmp [eax+6], word '00' |
343 | cmp [eax+6], word '00' |
344 | jne .check_01_header |
344 | jne .check_01_header |
345 | 345 | ||
346 | mov ecx, [APP_HEADER_00.start] |
346 | mov ecx, [APP_HEADER_00.start] |
347 | mov [ebx+0x08], ecx ;app_eip |
347 | mov [ebx+0x08], ecx ;app_eip |
348 | mov edx, [APP_HEADER_00.mem_size] |
348 | mov edx, [APP_HEADER_00.mem_size] |
349 | mov [ebx+0x10], edx ;app_mem |
349 | mov [ebx+0x10], edx ;app_mem |
350 | shr edx, 1 |
350 | shr edx, 1 |
351 | sub edx, 0x10 |
351 | sub edx, 0x10 |
352 | mov [ebx+0x0C], edx ;app_esp |
352 | mov [ebx+0x0C], edx ;app_esp |
353 | mov ecx, [APP_HEADER_00.i_param] |
353 | mov ecx, [APP_HEADER_00.i_param] |
354 | mov [ebx], ecx ;app_cmdline |
354 | mov [ebx], ecx ;app_cmdline |
355 | mov [ebx+4], dword 0 ;app_path |
355 | mov [ebx+4], dword 0 ;app_path |
356 | mov edx, [APP_HEADER_00.i_end] |
356 | mov edx, [APP_HEADER_00.i_end] |
357 | mov [ebx+0x14], edx |
357 | mov [ebx+0x14], edx |
358 | ret |
358 | ret |
359 | 359 | ||
360 | .check_01_header: |
360 | .check_01_header: |
361 | 361 | ||
362 | cmp [eax+6], word '01' |
362 | cmp [eax+6], word '01' |
363 | je @f |
363 | je @f |
364 | cmp [eax+6], word '02' |
364 | cmp [eax+6], word '02' |
365 | jne .fail |
365 | jne .fail |
366 | @@: |
366 | @@: |
367 | mov ecx, [APP_HEADER_01.start] |
367 | mov ecx, [APP_HEADER_01.start] |
368 | mov [ebx+0x08], ecx ;app_eip |
368 | mov [ebx+0x08], ecx ;app_eip |
369 | mov edx, [APP_HEADER_01.mem_size] |
369 | mov edx, [APP_HEADER_01.mem_size] |
370 | 370 | ||
371 | ; \begin{diamond}[20.08.2006] |
371 | ; \begin{diamond}[20.08.2006] |
372 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
372 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
373 | ; fit in allocated memory to prevent kernel faults) |
373 | ; fit in allocated memory to prevent kernel faults) |
374 | cmp edx, [APP_HEADER_01.i_end] |
374 | cmp edx, [APP_HEADER_01.i_end] |
375 | jb .fail |
375 | jb .fail |
376 | ; \end{diamond}[20.08.2006] |
376 | ; \end{diamond}[20.08.2006] |
377 | 377 | ||
378 | mov [ebx+0x10], edx ;app_mem |
378 | mov [ebx+0x10], edx ;app_mem |
379 | mov ecx, [APP_HEADER_01.stack_top] |
379 | mov ecx, [APP_HEADER_01.stack_top] |
380 | mov [ebx+0x0C], ecx ;app_esp |
380 | mov [ebx+0x0C], ecx ;app_esp |
381 | mov edx, [APP_HEADER_01.i_param] |
381 | mov edx, [APP_HEADER_01.i_param] |
382 | mov [ebx], edx ;app_cmdline |
382 | mov [ebx], edx ;app_cmdline |
383 | mov ecx, [APP_HEADER_01.i_icon] |
383 | mov ecx, [APP_HEADER_01.i_icon] |
384 | mov [ebx+4], ecx ;app_path |
384 | mov [ebx+4], ecx ;app_path |
385 | mov edx, [APP_HEADER_01.i_end] |
385 | mov edx, [APP_HEADER_01.i_end] |
386 | mov [ebx+0x14], edx |
386 | mov [ebx+0x14], edx |
387 | ret |
387 | ret |
388 | .fail: |
388 | .fail: |
389 | xor eax, eax |
389 | xor eax, eax |
390 | ret |
390 | ret |
391 | 391 | ||
392 | align 4 |
392 | align 4 |
393 | alloc_thread_slot: |
393 | alloc_thread_slot: |
394 | ;input: |
394 | ;input: |
395 | ; none |
395 | ; none |
396 | ;result: |
396 | ;result: |
397 | ; eax=[new_thread_slot]<>0 - ok |
397 | ; eax=[new_thread_slot]<>0 - ok |
398 | ; 0 - failed. |
398 | ; 0 - failed. |
399 | ;This function find least empty slot. |
399 | ;This function find least empty slot. |
400 | ;It doesn't increase [TASK_COUNT]! |
400 | ;It doesn't increase [TASK_COUNT]! |
401 | 401 | ||
402 | 402 | ||
403 | mov edx, thr_slot_map |
403 | mov edx, thr_slot_map |
404 | pushfd |
404 | pushfd |
405 | cli |
405 | cli |
406 | .l1: |
406 | .l1: |
407 | bsf eax, [edx] |
407 | bsf eax, [edx] |
408 | jnz .found |
408 | jnz .found |
409 | add edx, 4 |
409 | add edx, 4 |
410 | cmp edx, thr_slot_map+32 |
410 | cmp edx, thr_slot_map+32 |
411 | jb .l1 |
411 | jb .l1 |
412 | 412 | ||
413 | popfd |
413 | popfd |
414 | xor eax, eax |
414 | xor eax, eax |
415 | ret |
415 | ret |
416 | .found: |
416 | .found: |
417 | btr [edx], eax |
417 | btr [edx], eax |
418 | sub edx, thr_slot_map |
418 | sub edx, thr_slot_map |
419 | lea eax, [eax+edx*8] |
419 | lea eax, [eax+edx*8] |
420 | popfd |
420 | popfd |
421 | ret |
421 | ret |
422 | 422 | ||
423 | 423 | ||
424 | align 4 |
424 | align 4 |
425 | proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword |
425 | proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword |
426 | locals |
426 | locals |
427 | app_pages dd ? |
427 | app_pages dd ? |
428 | img_pages dd ? |
428 | img_pages dd ? |
429 | process dd ? |
429 | process dd ? |
430 | app_tabs dd ? |
430 | app_tabs dd ? |
431 | endl |
431 | endl |
432 | 432 | ||
433 | push ebx |
433 | push ebx |
434 | push esi |
434 | push esi |
435 | push edi |
435 | push edi |
436 | 436 | ||
437 | mov ecx, pg_data.mutex |
437 | mov ecx, pg_data.mutex |
438 | call mutex_lock |
438 | call mutex_lock |
439 | 439 | ||
440 | xor eax, eax |
440 | xor eax, eax |
441 | mov [process], eax |
441 | mov [process], eax |
442 | 442 | ||
443 | mov eax, [app_size] |
443 | mov eax, [app_size] |
444 | add eax, 4095 |
444 | add eax, 4095 |
445 | and eax, NOT(4095) |
445 | and eax, NOT(4095) |
446 | mov [app_size], eax |
446 | mov [app_size], eax |
447 | mov ebx, eax |
447 | mov ebx, eax |
448 | shr eax, 12 |
448 | shr eax, 12 |
449 | mov [app_pages], eax |
449 | mov [app_pages], eax |
450 | 450 | ||
451 | add ebx, 0x3FFFFF |
451 | add ebx, 0x3FFFFF |
452 | and ebx, NOT(0x3FFFFF) |
452 | and ebx, NOT(0x3FFFFF) |
453 | shr ebx, 22 |
453 | shr ebx, 22 |
454 | mov [app_tabs], ebx |
454 | mov [app_tabs], ebx |
455 | 455 | ||
456 | mov ecx, [img_size] |
456 | mov ecx, [img_size] |
457 | add ecx, 4095 |
457 | add ecx, 4095 |
458 | and ecx, NOT(4095) |
458 | and ecx, NOT(4095) |
459 | 459 | ||
460 | mov [img_size], ecx |
460 | mov [img_size], ecx |
461 | shr ecx, 12 |
461 | shr ecx, 12 |
462 | mov [img_pages], ecx |
462 | mov [img_pages], ecx |
463 | 463 | ||
464 | lea eax, [eax+ebx+2];all requested memory |
464 | lea eax, [eax+ebx+2];all requested memory |
465 | 465 | ||
466 | cmp eax, [pg_data.pages_free] |
466 | cmp eax, [pg_data.pages_free] |
467 | ja .fail |
467 | ja .fail |
468 | 468 | ||
469 | stdcall kernel_alloc, 0x2000 |
469 | stdcall kernel_alloc, 0x2000 |
470 | test eax, eax |
470 | test eax, eax |
471 | jz .fail |
471 | jz .fail |
472 | mov [process], eax |
472 | mov [process], eax |
473 | 473 | ||
474 | lea edi, [eax+PROC.heap_lock] |
474 | lea edi, [eax+PROC.heap_lock] |
475 | mov ecx, (PROC.ht_next-PROC.heap_lock)/4 |
475 | mov ecx, (PROC.ht_next-PROC.heap_lock)/4 |
476 | 476 | ||
477 | list_init eax |
477 | list_init eax |
478 | add eax, PROC.thr_list |
478 | add eax, PROC.thr_list |
479 | list_init eax |
479 | list_init eax |
480 | 480 | ||
481 | xor eax, eax |
481 | xor eax, eax |
482 | cld |
482 | cld |
483 | rep stosd |
483 | rep stosd |
484 | 484 | ||
485 | mov ecx, (PROC.pdt_0 - PROC.htab)/4 |
485 | mov ecx, (PROC.pdt_0 - PROC.htab)/4 |
486 | @@: |
486 | @@: |
487 | stosd |
487 | stosd |
488 | inc eax |
488 | inc eax |
489 | cmp eax, ecx |
489 | cmp eax, ecx |
490 | jbe @B |
490 | jbe @B |
491 | 491 | ||
492 | mov [edi-4096+PROC.ht_next], 3 ;reserve handles for stdin stdout and stderr |
492 | mov [edi-4096+PROC.ht_next], 3 ;reserve handles for stdin stdout and stderr |
493 | mov eax, edi |
493 | mov eax, edi |
494 | call get_pg_addr |
494 | call get_pg_addr |
495 | mov [edi-4096+PROC.pdt_0_phys], eax |
495 | mov [edi-4096+PROC.pdt_0_phys], eax |
496 | 496 | ||
497 | mov ecx, (OS_BASE shr 20)/4 |
497 | mov ecx, (OS_BASE shr 20)/4 |
498 | xor eax, eax |
498 | xor eax, eax |
499 | rep stosd |
499 | rep stosd |
500 | 500 | ||
501 | mov ecx, (OS_BASE shr 20)/4 |
501 | mov ecx, (OS_BASE shr 20)/4 |
502 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
502 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
503 | rep movsd |
503 | rep movsd |
504 | 504 | ||
505 | mov eax, [edi-8192+PROC.pdt_0_phys] |
505 | mov eax, [edi-8192+PROC.pdt_0_phys] |
506 | or eax, PG_SW |
506 | or eax, PG_SWR |
507 | mov [edi-4096+(page_tabs shr 20)], eax |
507 | mov [edi-4096+(page_tabs shr 20)], eax |
508 | 508 | ||
509 | lea eax, [edi-8192] |
509 | lea eax, [edi-8192] |
510 | call set_cr3 |
510 | call set_cr3 |
511 | 511 | ||
512 | mov edx, [app_tabs] |
512 | mov edx, [app_tabs] |
513 | xor edi, edi |
513 | xor edi, edi |
514 | @@: |
514 | @@: |
515 | call alloc_page |
515 | call alloc_page |
516 | test eax, eax |
516 | test eax, eax |
517 | jz .fail |
517 | jz .fail |
518 | 518 | ||
519 | stdcall map_page_table, edi, eax |
519 | stdcall map_page_table, edi, eax |
520 | add edi, 0x00400000 |
520 | add edi, 0x00400000 |
521 | dec edx |
521 | dec edx |
522 | jnz @B |
522 | jnz @B |
523 | 523 | ||
524 | mov edi, page_tabs |
524 | mov edi, page_tabs |
525 | 525 | ||
526 | mov ecx, [app_tabs] |
526 | mov ecx, [app_tabs] |
527 | shl ecx, 10 |
527 | shl ecx, 10 |
528 | xor eax, eax |
528 | xor eax, eax |
529 | rep stosd |
529 | rep stosd |
530 | 530 | ||
531 | mov ecx, [img_pages] |
531 | mov ecx, [img_pages] |
532 | mov ebx, PG_UW |
532 | mov ebx, PG_UWR |
533 | xor edx, edx |
533 | xor edx, edx |
534 | mov esi, [img_base] |
534 | mov esi, [img_base] |
535 | shr esi, 10 |
535 | shr esi, 10 |
536 | add esi, page_tabs |
536 | add esi, page_tabs |
537 | mov edi, page_tabs |
537 | mov edi, page_tabs |
538 | .remap: |
538 | .remap: |
539 | lodsd |
539 | lodsd |
540 | and eax, 0xFFFFF000 |
540 | and eax, 0xFFFFF000 |
541 | or eax, ebx; force user level r/w access |
541 | or eax, ebx; force user level r/w access |
542 | stosd |
542 | stosd |
543 | add edx, 0x1000 |
543 | add edx, 0x1000 |
544 | dec [app_pages] |
544 | dec [app_pages] |
545 | dec ecx |
545 | dec ecx |
546 | jnz .remap |
546 | jnz .remap |
547 | 547 | ||
548 | mov ecx, [app_pages] |
548 | mov ecx, [app_pages] |
549 | test ecx, ecx |
549 | test ecx, ecx |
550 | jz .done |
550 | jz .done |
551 | 551 | ||
552 | .alloc: |
552 | .alloc: |
553 | call alloc_page |
553 | call alloc_page |
554 | test eax, eax |
554 | test eax, eax |
555 | jz .fail |
555 | jz .fail |
556 | 556 | ||
557 | stdcall map_page, edx, eax, dword PG_UW |
557 | stdcall map_page, edx, eax, dword PG_UWR |
558 | add edx, 0x1000 |
558 | add edx, 0x1000 |
559 | dec [app_pages] |
559 | dec [app_pages] |
560 | jnz .alloc |
560 | jnz .alloc |
561 | 561 | ||
562 | .done: |
562 | .done: |
563 | mov ecx, pg_data.mutex |
563 | mov ecx, pg_data.mutex |
564 | call mutex_unlock |
564 | call mutex_unlock |
565 | mov eax, [process] |
565 | mov eax, [process] |
566 | 566 | ||
567 | pop edi |
567 | pop edi |
568 | pop esi |
568 | pop esi |
569 | pop ebx |
569 | pop ebx |
570 | ret |
570 | ret |
571 | .fail: |
571 | .fail: |
572 | mov ecx, pg_data.mutex |
572 | mov ecx, pg_data.mutex |
573 | call mutex_unlock |
573 | call mutex_unlock |
574 | cmp [process], 0 |
574 | cmp [process], 0 |
575 | je @f |
575 | je @f |
576 | ;; stdcall destroy_app_space, [dir_addr], 0 |
576 | ;; stdcall destroy_app_space, [dir_addr], 0 |
577 | @@: |
577 | @@: |
578 | xor eax, eax |
578 | xor eax, eax |
579 | pop edi |
579 | pop edi |
580 | pop esi |
580 | pop esi |
581 | pop ebx |
581 | pop ebx |
582 | ret |
582 | ret |
583 | endp |
583 | endp |
584 | 584 | ||
585 | align 4 |
585 | align 4 |
586 | set_cr3: |
586 | set_cr3: |
587 | pushfd |
587 | pushfd |
588 | cli |
588 | cli |
589 | mov ebx, [current_slot] |
589 | mov ebx, [current_slot] |
590 | mov [current_process], eax |
590 | mov [current_process], eax |
591 | mov [ebx+APPDATA.process], eax |
591 | mov [ebx+APPDATA.process], eax |
592 | mov eax, [eax+PROC.pdt_0_phys] |
592 | mov eax, [eax+PROC.pdt_0_phys] |
593 | mov cr3, eax |
593 | mov cr3, eax |
594 | popfd |
594 | popfd |
595 | ret |
595 | ret |
596 | 596 | ||
597 | align 4 |
597 | align 4 |
598 | proc destroy_page_table stdcall, pg_tab:dword |
598 | proc destroy_page_table stdcall, pg_tab:dword |
599 | 599 | ||
600 | push esi |
600 | push esi |
601 | 601 | ||
602 | mov esi, [pg_tab] |
602 | mov esi, [pg_tab] |
603 | mov ecx, 1024 |
603 | mov ecx, 1024 |
604 | .free: |
604 | .free: |
605 | mov eax, [esi] |
605 | mov eax, [esi] |
606 | test eax, 1 |
606 | test eax, 1 |
607 | jz .next |
607 | jz .next |
608 | test eax, 2 |
608 | test eax, 2 |
609 | jz .next |
609 | jz .next |
610 | test eax, 1 shl 9 |
610 | test eax, 1 shl 9 |
611 | jnz .next ;skip shared pages |
611 | jnz .next ;skip shared pages |
612 | call free_page |
612 | call free_page |
613 | .next: |
613 | .next: |
614 | add esi, 4 |
614 | add esi, 4 |
615 | dec ecx |
615 | dec ecx |
616 | jnz .free |
616 | jnz .free |
617 | pop esi |
617 | pop esi |
618 | ret |
618 | ret |
619 | endp |
619 | endp |
620 | 620 | ||
621 | align 4 |
621 | align 4 |
622 | destroy_process: ;fastcall ecx= ptr to process |
622 | destroy_process: ;fastcall ecx= ptr to process |
623 | 623 | ||
624 | lea eax, [ecx+PROC.thr_list] |
624 | lea eax, [ecx+PROC.thr_list] |
625 | cmp eax, [eax+LHEAD.next] |
625 | cmp eax, [eax+LHEAD.next] |
626 | jne .exit |
626 | jne .exit |
627 | 627 | ||
628 | align 4 |
628 | align 4 |
629 | .internal: |
629 | .internal: |
630 | push ecx |
630 | push ecx |
631 | 631 | ||
632 | mov esi, [ecx+PROC.dlls_list_ptr] |
632 | mov esi, [ecx+PROC.dlls_list_ptr] |
633 | call destroy_all_hdlls |
633 | call destroy_all_hdlls |
634 | 634 | ||
635 | ; mov ecx, pg_data.mutex |
635 | ; mov ecx, pg_data.mutex |
636 | ; call mutex_lock |
636 | ; call mutex_lock |
637 | 637 | ||
638 | mov esi, [esp] |
638 | mov esi, [esp] |
639 | add esi, PROC.pdt_0 |
639 | add esi, PROC.pdt_0 |
640 | mov edi, (0x80000000 shr 20)/4 |
640 | mov edi, (0x80000000 shr 20)/4 |
641 | .destroy: |
641 | .destroy: |
642 | mov eax, [esi] |
642 | mov eax, [esi] |
643 | test eax, 1 |
643 | test eax, 1 |
644 | jz .next |
644 | jz .next |
645 | and eax, not 0xFFF |
645 | and eax, not 0xFFF |
646 | stdcall map_page, [tmp_task_ptab], eax, PG_SW |
646 | stdcall map_page, [tmp_task_ptab], eax, PG_SWR |
647 | stdcall destroy_page_table, [tmp_task_ptab] |
647 | stdcall destroy_page_table, [tmp_task_ptab] |
648 | mov eax, [esi] |
648 | mov eax, [esi] |
649 | call free_page |
649 | call free_page |
650 | .next: |
650 | .next: |
651 | add esi, 4 |
651 | add esi, 4 |
652 | dec edi |
652 | dec edi |
653 | jnz .destroy |
653 | jnz .destroy |
654 | 654 | ||
655 | call kernel_free ;ecx still in stack |
655 | call kernel_free ;ecx still in stack |
656 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
656 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
657 | ; mov ecx, pg_data.mutex |
657 | ; mov ecx, pg_data.mutex |
658 | ; call mutex_unlock |
658 | ; call mutex_unlock |
659 | 659 | ||
660 | .exit: |
660 | .exit: |
661 | ret |
661 | ret |
662 | 662 | ||
663 | align 4 |
663 | align 4 |
664 | get_pid: |
664 | get_pid: |
665 | mov eax, [TASK_BASE] |
665 | mov eax, [TASK_BASE] |
666 | mov eax, [eax+TASKDATA.pid] |
666 | mov eax, [eax+TASKDATA.pid] |
667 | ret |
667 | ret |
668 | 668 | ||
669 | pid_to_slot: |
669 | pid_to_slot: |
670 | ;Input: |
670 | ;Input: |
671 | ; eax - pid of process |
671 | ; eax - pid of process |
672 | ;Output: |
672 | ;Output: |
673 | ; eax - slot of process or 0 if process don't exists |
673 | ; eax - slot of process or 0 if process don't exists |
674 | ;Search process by PID. |
674 | ;Search process by PID. |
675 | push ebx |
675 | push ebx |
676 | push ecx |
676 | push ecx |
677 | mov ebx, [TASK_COUNT] |
677 | mov ebx, [TASK_COUNT] |
678 | shl ebx, 5 |
678 | shl ebx, 5 |
679 | mov ecx, 2*32 |
679 | mov ecx, 2*32 |
680 | 680 | ||
681 | .loop: |
681 | .loop: |
682 | ;ecx=offset of current process info entry |
682 | ;ecx=offset of current process info entry |
683 | ;ebx=maximum permitted offset |
683 | ;ebx=maximum permitted offset |
684 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
684 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
685 | jz .endloop ;skip empty slots |
685 | jz .endloop ;skip empty slots |
686 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
686 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
687 | jz .pid_found |
687 | jz .pid_found |
688 | .endloop: |
688 | .endloop: |
689 | add ecx, 32 |
689 | add ecx, 32 |
690 | cmp ecx, ebx |
690 | cmp ecx, ebx |
691 | jle .loop |
691 | jle .loop |
692 | 692 | ||
693 | pop ecx |
693 | pop ecx |
694 | pop ebx |
694 | pop ebx |
695 | xor eax, eax |
695 | xor eax, eax |
696 | ret |
696 | ret |
697 | 697 | ||
698 | .pid_found: |
698 | .pid_found: |
699 | shr ecx, 5 |
699 | shr ecx, 5 |
700 | mov eax, ecx ;convert offset to index of slot |
700 | mov eax, ecx ;convert offset to index of slot |
701 | pop ecx |
701 | pop ecx |
702 | pop ebx |
702 | pop ebx |
703 | ret |
703 | ret |
704 | 704 | ||
705 | check_region: |
705 | check_region: |
706 | ;input: |
706 | ;input: |
707 | ; esi - start of buffer |
707 | ; esi - start of buffer |
708 | ; edx - size of buffer |
708 | ; edx - size of buffer |
709 | ;result: |
709 | ;result: |
710 | ; eax = 1 region lays in app memory |
710 | ; eax = 1 region lays in app memory |
711 | ; eax = 0 region don't lays in app memory |
711 | ; eax = 0 region don't lays in app memory |
712 | 712 | ||
713 | mov eax, 1 |
713 | mov eax, 1 |
714 | ret |
714 | ret |
715 | if 0 |
715 | if 0 |
716 | mov eax, [CURRENT_TASK] |
716 | mov eax, [CURRENT_TASK] |
717 | ; jmp check_process_region |
717 | ; jmp check_process_region |
718 | ;----------------------------------------------------------------------------- |
718 | ;----------------------------------------------------------------------------- |
719 | ;check_process_region: |
719 | ;check_process_region: |
720 | ;input: |
720 | ;input: |
721 | ; eax - slot |
721 | ; eax - slot |
722 | ; esi - start of buffer |
722 | ; esi - start of buffer |
723 | ; edx - size of buffer |
723 | ; edx - size of buffer |
724 | ;result: |
724 | ;result: |
725 | ; eax = 1 region lays in app memory |
725 | ; eax = 1 region lays in app memory |
726 | ; eax = 0 region don't lays in app memory |
726 | ; eax = 0 region don't lays in app memory |
727 | 727 | ||
728 | test edx, edx |
728 | test edx, edx |
729 | jle .ok |
729 | jle .ok |
730 | shl eax, 5 |
730 | shl eax, 5 |
731 | cmp word [CURRENT_TASK+eax+0xa], 0 |
731 | cmp word [CURRENT_TASK+eax+0xa], 0 |
732 | jnz .failed |
732 | jnz .failed |
733 | shl eax, 3 |
733 | shl eax, 3 |
734 | mov eax, [SLOT_BASE+eax+0xb8] |
734 | mov eax, [SLOT_BASE+eax+0xb8] |
735 | test eax, eax |
735 | test eax, eax |
736 | jz .failed |
736 | jz .failed |
737 | 737 | ||
738 | mov eax, 1 |
738 | mov eax, 1 |
739 | ret |
739 | ret |
740 | .ok: |
740 | .ok: |
741 | mov eax, 1 |
741 | mov eax, 1 |
742 | ret |
742 | ret |
743 | .failed: |
743 | .failed: |
744 | xor eax, eax |
744 | xor eax, eax |
745 | ret |
745 | ret |
746 | end if |
746 | end if |
747 | 747 | ||
748 | align 4 |
748 | align 4 |
749 | proc read_process_memory |
749 | proc read_process_memory |
750 | ;Input: |
750 | ;Input: |
751 | ; eax - process slot |
751 | ; eax - process slot |
752 | ; ecx - buffer address |
752 | ; ecx - buffer address |
753 | ; edx - buffer size |
753 | ; edx - buffer size |
754 | ; esi - start address in other process |
754 | ; esi - start address in other process |
755 | ;Output: |
755 | ;Output: |
756 | ; eax - number of bytes read. |
756 | ; eax - number of bytes read. |
757 | locals |
757 | locals |
758 | slot dd ? |
758 | slot dd ? |
759 | buff dd ? |
759 | buff dd ? |
760 | r_count dd ? |
760 | r_count dd ? |
761 | offset dd ? |
761 | offset dd ? |
762 | tmp_r_cnt dd ? |
762 | tmp_r_cnt dd ? |
763 | endl |
763 | endl |
764 | 764 | ||
765 | mov [slot], eax |
765 | mov [slot], eax |
766 | mov [buff], ecx |
766 | mov [buff], ecx |
767 | and [r_count], 0 |
767 | and [r_count], 0 |
768 | mov [tmp_r_cnt], edx |
768 | mov [tmp_r_cnt], edx |
769 | mov [offset], esi |
769 | mov [offset], esi |
770 | 770 | ||
771 | pushad |
771 | pushad |
772 | .read_mem: |
772 | .read_mem: |
773 | mov edx, [offset] |
773 | mov edx, [offset] |
774 | mov ebx, [tmp_r_cnt] |
774 | mov ebx, [tmp_r_cnt] |
775 | 775 | ||
776 | mov ecx, 0x400000 |
776 | mov ecx, 0x400000 |
777 | and edx, 0x3FFFFF |
777 | and edx, 0x3FFFFF |
778 | sub ecx, edx |
778 | sub ecx, edx |
779 | cmp ecx, ebx |
779 | cmp ecx, ebx |
780 | jbe @f |
780 | jbe @f |
781 | mov ecx, ebx |
781 | mov ecx, ebx |
782 | @@: |
782 | @@: |
783 | cmp ecx, 0x8000 |
783 | cmp ecx, 0x8000 |
784 | jna @F |
784 | jna @F |
785 | mov ecx, 0x8000 |
785 | mov ecx, 0x8000 |
786 | @@: |
786 | @@: |
787 | mov ebx, [offset] |
787 | mov ebx, [offset] |
788 | 788 | ||
789 | push ecx |
789 | push ecx |
790 | stdcall map_memEx, [proc_mem_map], \ |
790 | stdcall map_memEx, [proc_mem_map], \ |
791 | [slot], ebx, ecx, PG_MAP |
791 | [slot], ebx, ecx, PG_READ |
792 | pop ecx |
792 | pop ecx |
793 | 793 | ||
794 | mov esi, [offset] |
794 | mov esi, [offset] |
795 | and esi, 0xfff |
795 | and esi, 0xfff |
796 | sub eax, esi |
796 | sub eax, esi |
797 | jbe .ret |
797 | jbe .ret |
798 | cmp ecx, eax |
798 | cmp ecx, eax |
799 | jbe @f |
799 | jbe @f |
800 | mov ecx, eax |
800 | mov ecx, eax |
801 | mov [tmp_r_cnt], eax |
801 | mov [tmp_r_cnt], eax |
802 | @@: |
802 | @@: |
803 | add esi, [proc_mem_map] |
803 | add esi, [proc_mem_map] |
804 | mov edi, [buff] |
804 | mov edi, [buff] |
805 | mov edx, ecx |
805 | mov edx, ecx |
806 | rep movsb |
806 | rep movsb |
807 | add [r_count], edx |
807 | add [r_count], edx |
808 | 808 | ||
809 | add [offset], edx |
809 | add [offset], edx |
810 | sub [tmp_r_cnt], edx |
810 | sub [tmp_r_cnt], edx |
811 | jnz .read_mem |
811 | jnz .read_mem |
812 | .ret: |
812 | .ret: |
813 | popad |
813 | popad |
814 | mov eax, [r_count] |
814 | mov eax, [r_count] |
815 | ret |
815 | ret |
816 | endp |
816 | endp |
817 | 817 | ||
818 | align 4 |
818 | align 4 |
819 | proc write_process_memory |
819 | proc write_process_memory |
820 | ;Input: |
820 | ;Input: |
821 | ; eax - process slot |
821 | ; eax - process slot |
822 | ; ecx - buffer address |
822 | ; ecx - buffer address |
823 | ; edx - buffer size |
823 | ; edx - buffer size |
824 | ; esi - start address in other process |
824 | ; esi - start address in other process |
825 | ;Output: |
825 | ;Output: |
826 | ; eax - number of bytes written |
826 | ; eax - number of bytes written |
827 | 827 | ||
828 | locals |
828 | locals |
829 | slot dd ? |
829 | slot dd ? |
830 | buff dd ? |
830 | buff dd ? |
831 | w_count dd ? |
831 | w_count dd ? |
832 | offset dd ? |
832 | offset dd ? |
833 | tmp_w_cnt dd ? |
833 | tmp_w_cnt dd ? |
834 | endl |
834 | endl |
835 | 835 | ||
836 | mov [slot], eax |
836 | mov [slot], eax |
837 | mov [buff], ecx |
837 | mov [buff], ecx |
838 | and [w_count], 0 |
838 | and [w_count], 0 |
839 | mov [tmp_w_cnt], edx |
839 | mov [tmp_w_cnt], edx |
840 | mov [offset], esi |
840 | mov [offset], esi |
841 | 841 | ||
842 | pushad |
842 | pushad |
843 | .read_mem: |
843 | .read_mem: |
844 | mov edx, [offset] |
844 | mov edx, [offset] |
845 | mov ebx, [tmp_w_cnt] |
845 | mov ebx, [tmp_w_cnt] |
846 | 846 | ||
847 | mov ecx, 0x400000 |
847 | mov ecx, 0x400000 |
848 | and edx, 0x3FFFFF |
848 | and edx, 0x3FFFFF |
849 | sub ecx, edx |
849 | sub ecx, edx |
850 | cmp ecx, ebx |
850 | cmp ecx, ebx |
851 | jbe @f |
851 | jbe @f |
852 | mov ecx, ebx |
852 | mov ecx, ebx |
853 | @@: |
853 | @@: |
854 | cmp ecx, 0x8000 |
854 | cmp ecx, 0x8000 |
855 | jna @F |
855 | jna @F |
856 | mov ecx, 0x8000 |
856 | mov ecx, 0x8000 |
857 | @@: |
857 | @@: |
858 | mov ebx, [offset] |
858 | mov ebx, [offset] |
859 | ; add ebx, new_app_base |
859 | ; add ebx, new_app_base |
860 | push ecx |
860 | push ecx |
861 | stdcall map_memEx, [proc_mem_map], \ |
861 | stdcall map_memEx, [proc_mem_map], \ |
862 | [slot], ebx, ecx, PG_SW |
862 | [slot], ebx, ecx, PG_SWR |
863 | pop ecx |
863 | pop ecx |
864 | 864 | ||
865 | mov edi, [offset] |
865 | mov edi, [offset] |
866 | and edi, 0xfff |
866 | and edi, 0xfff |
867 | sub eax, edi |
867 | sub eax, edi |
868 | jbe .ret |
868 | jbe .ret |
869 | cmp ecx, eax |
869 | cmp ecx, eax |
870 | jbe @f |
870 | jbe @f |
871 | mov ecx, eax |
871 | mov ecx, eax |
872 | mov [tmp_w_cnt], eax |
872 | mov [tmp_w_cnt], eax |
873 | @@: |
873 | @@: |
874 | add edi, [proc_mem_map] |
874 | add edi, [proc_mem_map] |
875 | mov esi, [buff] |
875 | mov esi, [buff] |
876 | mov edx, ecx |
876 | mov edx, ecx |
877 | rep movsb |
877 | rep movsb |
878 | 878 | ||
879 | add [w_count], edx |
879 | add [w_count], edx |
880 | add [offset], edx |
880 | add [offset], edx |
881 | sub [tmp_w_cnt], edx |
881 | sub [tmp_w_cnt], edx |
882 | jnz .read_mem |
882 | jnz .read_mem |
883 | .ret: |
883 | .ret: |
884 | popad |
884 | popad |
885 | mov eax, [w_count] |
885 | mov eax, [w_count] |
886 | ret |
886 | ret |
887 | endp |
887 | endp |
888 | 888 | ||
889 | ;ebx = 1 - kernel thread |
889 | ;ebx = 1 - kernel thread |
890 | ;ecx=thread entry point |
890 | ;ecx=thread entry point |
891 | ;edx=thread stack pointer |
891 | ;edx=thread stack pointer |
892 | ;creation flags 0x01 - debugged |
892 | ;creation flags 0x01 - debugged |
893 | ; 0x02 - kernel |
893 | ; 0x02 - kernel |
894 | 894 | ||
895 | align 4 |
895 | align 4 |
896 | proc new_sys_threads |
896 | proc new_sys_threads |
897 | locals |
897 | locals |
898 | slot dd ? |
898 | slot dd ? |
899 | flags dd ? |
899 | flags dd ? |
900 | app_cmdline dd ? ;0x00 |
900 | app_cmdline dd ? ;0x00 |
901 | app_path dd ? ;0x04 |
901 | app_path dd ? ;0x04 |
902 | app_eip dd ? ;0x08 |
902 | app_eip dd ? ;0x08 |
903 | app_esp dd ? ;0x0C |
903 | app_esp dd ? ;0x0C |
904 | app_mem dd ? ;0x10 |
904 | app_mem dd ? ;0x10 |
905 | endl |
905 | endl |
906 | 906 | ||
907 | shl ebx, 1 |
907 | shl ebx, 1 |
908 | mov [flags], ebx |
908 | mov [flags], ebx |
909 | 909 | ||
910 | xor eax, eax |
910 | xor eax, eax |
911 | mov [app_eip], ecx |
911 | mov [app_eip], ecx |
912 | mov [app_cmdline], eax |
912 | mov [app_cmdline], eax |
913 | mov [app_esp], edx |
913 | mov [app_esp], edx |
914 | mov [app_path], eax |
914 | mov [app_path], eax |
915 | 915 | ||
916 | call lock_application_table |
916 | call lock_application_table |
917 | 917 | ||
918 | call alloc_thread_slot |
918 | call alloc_thread_slot |
919 | test eax, eax |
919 | test eax, eax |
920 | jz .failed |
920 | jz .failed |
921 | 921 | ||
922 | mov [slot], eax |
922 | mov [slot], eax |
923 | 923 | ||
924 | mov esi, [current_slot] |
924 | mov esi, [current_slot] |
925 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
925 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
926 | 926 | ||
927 | mov edi, eax |
927 | mov edi, eax |
928 | shl edi, 8 |
928 | shl edi, 8 |
929 | add edi, SLOT_BASE |
929 | add edi, SLOT_BASE |
930 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
930 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
931 | mov ecx, 256/4 |
931 | mov ecx, 256/4 |
932 | xor eax, eax |
932 | xor eax, eax |
933 | cld |
933 | cld |
934 | rep stosd ;clean extended information about new thread |
934 | rep stosd ;clean extended information about new thread |
935 | mov esi, ebx |
935 | mov esi, ebx |
936 | mov edi, edx |
936 | mov edi, edx |
937 | mov ecx, 11 |
937 | mov ecx, 11 |
938 | rep movsb ;copy process name |
938 | rep movsb ;copy process name |
939 | 939 | ||
940 | mov eax, [ebx+APPDATA.process] |
940 | mov eax, [ebx+APPDATA.process] |
941 | mov [edx+APPDATA.process], eax |
941 | mov [edx+APPDATA.process], eax |
942 | 942 | ||
943 | lea ebx, [edx+APPDATA.list] |
943 | lea ebx, [edx+APPDATA.list] |
944 | lea ecx, [eax+PROC.thr_list] |
944 | lea ecx, [eax+PROC.thr_list] |
945 | list_add_tail ebx, ecx ;add thread to process child's list |
945 | list_add_tail ebx, ecx ;add thread to process child's list |
946 | 946 | ||
947 | mov eax, [ebx+APPDATA.tls_base] |
947 | mov eax, [ebx+APPDATA.tls_base] |
948 | test eax, eax |
948 | test eax, eax |
949 | jz @F |
949 | jz @F |
950 | 950 | ||
951 | push edx |
951 | push edx |
952 | stdcall user_alloc, 4096 |
952 | stdcall user_alloc, 4096 |
953 | pop edx |
953 | pop edx |
954 | test eax, eax |
954 | test eax, eax |
955 | jz .failed1;eax=0 |
955 | jz .failed1;eax=0 |
956 | @@: |
956 | @@: |
957 | mov [edx+APPDATA.tls_base], eax |
957 | mov [edx+APPDATA.tls_base], eax |
958 | 958 | ||
959 | lea eax, [app_cmdline] |
959 | lea eax, [app_cmdline] |
960 | stdcall set_app_params , [slot], eax, dword 0, \ |
960 | stdcall set_app_params , [slot], eax, dword 0, \ |
961 | dword 0, [flags] |
961 | dword 0, [flags] |
962 | 962 | ||
963 | mov eax, [process_number] ;set result |
963 | mov eax, [process_number] ;set result |
964 | call unlock_application_table |
964 | call unlock_application_table |
965 | ret |
965 | ret |
966 | .failed: |
966 | .failed: |
967 | xor eax, eax |
967 | xor eax, eax |
968 | .failed1: |
968 | .failed1: |
969 | call unlock_application_table |
969 | call unlock_application_table |
970 | dec eax ;-1 |
970 | dec eax ;-1 |
971 | ret |
971 | ret |
972 | endp |
972 | endp |
973 | 973 | ||
974 | align 4 |
974 | align 4 |
975 | tls_app_entry: |
975 | tls_app_entry: |
976 | 976 | ||
977 | call init_heap |
977 | call init_heap |
978 | stdcall user_alloc, 4096 |
978 | stdcall user_alloc, 4096 |
979 | 979 | ||
980 | mov edx, [current_slot] |
980 | mov edx, [current_slot] |
981 | mov [edx+APPDATA.tls_base], eax |
981 | mov [edx+APPDATA.tls_base], eax |
982 | mov [tls_data_l+2], ax |
982 | mov [tls_data_l+2], ax |
983 | shr eax, 16 |
983 | shr eax, 16 |
984 | mov [tls_data_l+4], al |
984 | mov [tls_data_l+4], al |
985 | mov [tls_data_l+7], ah |
985 | mov [tls_data_l+7], ah |
986 | mov dx, app_tls |
986 | mov dx, app_tls |
987 | mov fs, dx |
987 | mov fs, dx |
988 | popad |
988 | popad |
989 | iretd |
989 | iretd |
990 | 990 | ||
991 | 991 | ||
992 | EFL_IF equ 0x0200 |
992 | EFL_IF equ 0x0200 |
993 | EFL_IOPL1 equ 0x1000 |
993 | EFL_IOPL1 equ 0x1000 |
994 | EFL_IOPL2 equ 0x2000 |
994 | EFL_IOPL2 equ 0x2000 |
995 | EFL_IOPL3 equ 0x3000 |
995 | EFL_IOPL3 equ 0x3000 |
996 | 996 | ||
997 | 997 | ||
998 | align 4 |
998 | align 4 |
999 | proc set_app_params stdcall,slot:dword, params:dword,\ |
999 | proc set_app_params stdcall,slot:dword, params:dword,\ |
1000 | cmd_line:dword, app_path:dword, flags:dword |
1000 | cmd_line:dword, app_path:dword, flags:dword |
1001 | 1001 | ||
1002 | locals |
1002 | locals |
1003 | pl0_stack dd ? |
1003 | pl0_stack dd ? |
1004 | endl |
1004 | endl |
1005 | 1005 | ||
1006 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1006 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1007 | mov [pl0_stack], eax |
1007 | mov [pl0_stack], eax |
1008 | 1008 | ||
1009 | lea edi, [eax+RING0_STACK_SIZE] |
1009 | lea edi, [eax+RING0_STACK_SIZE] |
1010 | 1010 | ||
1011 | mov eax, [slot] |
1011 | mov eax, [slot] |
1012 | mov ebx, eax |
1012 | mov ebx, eax |
1013 | 1013 | ||
1014 | shl eax, 8 |
1014 | shl eax, 8 |
1015 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1015 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1016 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1016 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1017 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1017 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1018 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1018 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1019 | 1019 | ||
1020 | ;set default io permission map |
1020 | ;set default io permission map |
1021 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1021 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1022 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1022 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1023 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1023 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1024 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1024 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1025 | 1025 | ||
1026 | mov esi, fpu_data |
1026 | mov esi, fpu_data |
1027 | mov ecx, 512/4 |
1027 | mov ecx, 512/4 |
1028 | rep movsd |
1028 | rep movsd |
1029 | 1029 | ||
1030 | cmp ebx, [TASK_COUNT] |
1030 | cmp ebx, [TASK_COUNT] |
1031 | jle .noinc |
1031 | jle .noinc |
1032 | inc dword [TASK_COUNT] ;update number of processes |
1032 | inc dword [TASK_COUNT] ;update number of processes |
1033 | .noinc: |
1033 | .noinc: |
1034 | shl ebx, 8 |
1034 | shl ebx, 8 |
1035 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1035 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1036 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1036 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1037 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1037 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1038 | 1038 | ||
1039 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1039 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1040 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1040 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1041 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1041 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1042 | 1042 | ||
1043 | mov ecx, [def_cursor] |
1043 | mov ecx, [def_cursor] |
1044 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1044 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1045 | mov eax, [pl0_stack] |
1045 | mov eax, [pl0_stack] |
1046 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1046 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1047 | add eax, RING0_STACK_SIZE |
1047 | add eax, RING0_STACK_SIZE |
1048 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1048 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1049 | 1049 | ||
1050 | push ebx |
1050 | push ebx |
1051 | stdcall kernel_alloc, 0x1000 |
1051 | stdcall kernel_alloc, 0x1000 |
1052 | pop ebx |
1052 | pop ebx |
1053 | mov esi, [current_slot] |
1053 | mov esi, [current_slot] |
1054 | mov esi, [esi+APPDATA.cur_dir] |
1054 | mov esi, [esi+APPDATA.cur_dir] |
1055 | mov ecx, 0x1000/4 |
1055 | mov ecx, 0x1000/4 |
1056 | mov edi, eax |
1056 | mov edi, eax |
1057 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1057 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1058 | rep movsd |
1058 | rep movsd |
1059 | 1059 | ||
1060 | shr ebx, 3 |
1060 | shr ebx, 3 |
1061 | mov eax, new_app_base |
1061 | mov eax, new_app_base |
1062 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1062 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1063 | 1063 | ||
1064 | .add_command_line: |
1064 | .add_command_line: |
1065 | mov edx, [params] |
1065 | mov edx, [params] |
1066 | mov edx, [edx] ;app_cmdline |
1066 | mov edx, [edx] ;app_cmdline |
1067 | test edx, edx |
1067 | test edx, edx |
1068 | jz @f ;application doesn't need parameters |
1068 | jz @f ;application doesn't need parameters |
1069 | 1069 | ||
1070 | mov eax, edx |
1070 | mov eax, edx |
1071 | add eax, 256 |
1071 | add eax, 256 |
1072 | jc @f |
1072 | jc @f |
1073 | 1073 | ||
1074 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1074 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1075 | ; ja @f |
1075 | ; ja @f |
1076 | 1076 | ||
1077 | mov eax, [cmd_line] |
1077 | mov eax, [cmd_line] |
1078 | 1078 | ||
1079 | cmp [edx], dword 0xffffffff ; extended destination tag |
1079 | cmp [edx], dword 0xffffffff ; extended destination tag |
1080 | jne .no_ext_dest |
1080 | jne .no_ext_dest |
1081 | 1081 | ||
1082 | mov edx, [edx+4] ; extended destination for cmdline |
1082 | mov edx, [edx+4] ; extended destination for cmdline |
1083 | jmp .continue |
1083 | jmp .continue |
1084 | 1084 | ||
1085 | .no_ext_dest: |
1085 | .no_ext_dest: |
1086 | mov [eax-12], dword 255 |
1086 | mov [eax-12], dword 255 |
1087 | .continue: |
1087 | .continue: |
1088 | mov byte [edx], 0 ;force empty string if no cmdline given |
1088 | mov byte [edx], 0 ;force empty string if no cmdline given |
1089 | 1089 | ||
1090 | test eax, eax |
1090 | test eax, eax |
1091 | jz @f |
1091 | jz @f |
1092 | ;-------------------------------------- |
1092 | ;-------------------------------------- |
1093 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1093 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1094 | jne .old_copy |
1094 | jne .old_copy |
1095 | 1095 | ||
1096 | push eax |
1096 | push eax |
1097 | stdcall strncpy, edx, [eax-8], [eax-12] |
1097 | stdcall strncpy, edx, [eax-8], [eax-12] |
1098 | pop eax |
1098 | pop eax |
1099 | 1099 | ||
1100 | stdcall kernel_free, [eax-8] |
1100 | stdcall kernel_free, [eax-8] |
1101 | jmp @f |
1101 | jmp @f |
1102 | 1102 | ||
1103 | .old_copy: |
1103 | .old_copy: |
1104 | ;-------------------------------------- |
1104 | ;-------------------------------------- |
1105 | stdcall strncpy, edx, eax, 256 |
1105 | stdcall strncpy, edx, eax, 256 |
1106 | @@: |
1106 | @@: |
1107 | mov edx, [params] |
1107 | mov edx, [params] |
1108 | mov edx, [edx+4];app_path |
1108 | mov edx, [edx+4];app_path |
1109 | test edx, edx |
1109 | test edx, edx |
1110 | jz @F ;application don't need path of file |
1110 | jz @F ;application don't need path of file |
1111 | mov eax, edx |
1111 | mov eax, edx |
1112 | add eax, 1024 |
1112 | add eax, 1024 |
1113 | jc @f |
1113 | jc @f |
1114 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1114 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1115 | ; ja @f |
1115 | ; ja @f |
1116 | stdcall strncpy, edx, [app_path], 1024 |
1116 | stdcall strncpy, edx, [app_path], 1024 |
1117 | @@: |
1117 | @@: |
1118 | mov ebx, [slot] |
1118 | mov ebx, [slot] |
1119 | mov eax, ebx |
1119 | mov eax, ebx |
1120 | shl ebx, 5 |
1120 | shl ebx, 5 |
1121 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1121 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1122 | 1122 | ||
1123 | mov edx, irq0.return |
1123 | mov edx, irq0.return |
1124 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1124 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1125 | jne @F |
1125 | jne @F |
1126 | mov edx, tls_app_entry |
1126 | mov edx, tls_app_entry |
1127 | @@: |
1127 | @@: |
1128 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1128 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1129 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1129 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1130 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1130 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1131 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1131 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1132 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1132 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1133 | 1133 | ||
1134 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1134 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1135 | 1135 | ||
1136 | inc dword [process_number] |
1136 | inc dword [process_number] |
1137 | mov eax, [process_number] |
1137 | mov eax, [process_number] |
1138 | mov [ebx+4], eax ;set PID |
1138 | mov [ebx+4], eax ;set PID |
1139 | 1139 | ||
1140 | ;set draw data to full screen |
1140 | ;set draw data to full screen |
1141 | xor eax, eax |
1141 | xor eax, eax |
1142 | mov [ecx+0], dword eax |
1142 | mov [ecx+0], dword eax |
1143 | mov [ecx+4], dword eax |
1143 | mov [ecx+4], dword eax |
1144 | mov eax, [screen_workarea.right] |
1144 | mov eax, [screen_workarea.right] |
1145 | mov [ecx+8], eax |
1145 | mov [ecx+8], eax |
1146 | mov eax, [screen_workarea.bottom] |
1146 | mov eax, [screen_workarea.bottom] |
1147 | mov [ecx+12], eax |
1147 | mov [ecx+12], eax |
1148 | 1148 | ||
1149 | mov ebx, [pl0_stack] |
1149 | mov ebx, [pl0_stack] |
1150 | mov esi, [params] |
1150 | mov esi, [params] |
1151 | lea ecx, [ebx+REG_EIP] |
1151 | lea ecx, [ebx+REG_EIP] |
1152 | xor eax, eax |
1152 | xor eax, eax |
1153 | 1153 | ||
1154 | mov [ebx+REG_RET], edx |
1154 | mov [ebx+REG_RET], edx |
1155 | mov [ebx+REG_EDI], eax |
1155 | mov [ebx+REG_EDI], eax |
1156 | mov [ebx+REG_ESI], eax |
1156 | mov [ebx+REG_ESI], eax |
1157 | mov [ebx+REG_EBP], eax |
1157 | mov [ebx+REG_EBP], eax |
1158 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1158 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1159 | mov [ebx+REG_EBX], eax |
1159 | mov [ebx+REG_EBX], eax |
1160 | mov [ebx+REG_EDX], eax |
1160 | mov [ebx+REG_EDX], eax |
1161 | mov [ebx+REG_ECX], eax |
1161 | mov [ebx+REG_ECX], eax |
1162 | mov [ebx+REG_EAX], eax |
1162 | mov [ebx+REG_EAX], eax |
1163 | 1163 | ||
1164 | mov eax, [esi+0x08] ;app_eip |
1164 | mov eax, [esi+0x08] ;app_eip |
1165 | mov [ebx+REG_EIP], eax ;app_entry |
1165 | mov [ebx+REG_EIP], eax ;app_entry |
1166 | mov [ebx+REG_CS], dword app_code |
1166 | mov [ebx+REG_CS], dword app_code |
1167 | mov ecx, USER_PRIORITY |
1167 | mov ecx, USER_PRIORITY |
1168 | 1168 | ||
1169 | test byte [flags], 2 |
1169 | test byte [flags], 2 |
1170 | jz @F |
1170 | jz @F |
1171 | 1171 | ||
1172 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1172 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1173 | mov ecx, MAX_PRIORITY |
1173 | mov ecx, MAX_PRIORITY |
1174 | 1174 | ||
1175 | @@: |
1175 | @@: |
1176 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1176 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1177 | 1177 | ||
1178 | mov eax, [esi+0x0C] ;app_esp |
1178 | mov eax, [esi+0x0C] ;app_esp |
1179 | mov [ebx+REG_APP_ESP], eax;app_stack |
1179 | mov [ebx+REG_APP_ESP], eax;app_stack |
1180 | mov [ebx+REG_SS], dword app_data |
1180 | mov [ebx+REG_SS], dword app_data |
1181 | 1181 | ||
1182 | lea edx, [ebx+REG_RET] |
1182 | lea edx, [ebx+REG_RET] |
1183 | mov ebx, [slot] |
1183 | mov ebx, [slot] |
1184 | shl ebx, 5 |
1184 | shl ebx, 5 |
1185 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1185 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1186 | 1186 | ||
1187 | xor edx, edx; process state - running |
1187 | xor edx, edx; process state - running |
1188 | ; set if debuggee |
1188 | ; set if debuggee |
1189 | test byte [flags], 1 |
1189 | test byte [flags], 1 |
1190 | jz .no_debug |
1190 | jz .no_debug |
1191 | inc edx ; process state - suspended |
1191 | inc edx ; process state - suspended |
1192 | mov eax, [CURRENT_TASK] |
1192 | mov eax, [CURRENT_TASK] |
1193 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1193 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1194 | .no_debug: |
1194 | .no_debug: |
1195 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1195 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1196 | lea edx, [SLOT_BASE+ebx*8] |
1196 | lea edx, [SLOT_BASE+ebx*8] |
1197 | call scheduler_add_thread |
1197 | call scheduler_add_thread |
1198 | ret |
1198 | ret |
1199 | endp |
1199 | endp |
1200 | 1200 | ||
1201 | 1201 | ||
1202 | align 4 |
1202 | align 4 |
1203 | 1203 | ||
1204 | get_stack_base: |
1204 | get_stack_base: |
1205 | mov eax, [current_slot] |
1205 | mov eax, [current_slot] |
1206 | mov eax, [eax+APPDATA.pl0_stack] |
1206 | mov eax, [eax+APPDATA.pl0_stack] |
1207 | ret |
1207 | ret |
1208 | 1208 | ||
1209 | 1209 | ||
1210 | include "debug.inc"> |
1210 | include "debug.inc"> |