Rev 5577 | Rev 6240 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 5577 | Rev 5594 | ||
---|---|---|---|
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
1 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
2 | ;; ;; |
2 | ;; ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. All rights reserved. ;; |
3 | ;; Copyright (C) KolibriOS team 2004-2015. 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: 5577 $ |
8 | $Revision: 5594 $ |
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 | - | ||
473 | mov [process], eax |
472 | mov [process], eax |
474 | 473 | ||
475 | lea edi, [eax+PROC.heap_lock] |
474 | lea edi, [eax+PROC.heap_lock] |
476 | mov ecx, (PROC.ht_free-PROC.heap_lock)/4 |
475 | mov ecx, (PROC.ht_free-PROC.heap_lock)/4 |
477 | 476 | ||
478 | list_init eax |
477 | list_init eax |
479 | add eax, PROC.thr_list |
478 | add eax, PROC.thr_list |
480 | list_init eax |
479 | list_init eax |
481 | 480 | ||
482 | xor eax, eax |
481 | xor eax, eax |
483 | cld |
482 | cld |
484 | rep stosd |
483 | rep stosd |
485 | 484 | ||
486 | mov [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3 |
485 | mov [edi], dword (PROC.pdt_0 - PROC.htab)/4 - 3 |
487 | mov [edi+4], dword 3 ;reserve handles for stdin stdout and stderr |
486 | mov [edi+4], dword 3 ;reserve handles for stdin stdout and stderr |
488 | mov ecx, (PROC.pdt_0 - PROC.htab)/4 |
487 | mov ecx, (PROC.pdt_0 - PROC.htab)/4 |
489 | add edi, 8 |
488 | add edi, 8 |
490 | inc eax |
489 | inc eax |
491 | @@: |
490 | @@: |
492 | stosd |
491 | stosd |
493 | inc eax |
492 | inc eax |
494 | cmp eax, ecx |
493 | cmp eax, ecx |
495 | jbe @B |
494 | jbe @B |
496 | 495 | ||
497 | mov eax, edi |
496 | mov eax, edi |
498 | call get_pg_addr |
497 | call get_pg_addr |
499 | mov [edi-4096+PROC.pdt_0_phys], eax |
498 | mov [edi-4096+PROC.pdt_0_phys], eax |
500 | 499 | ||
501 | mov ecx, (OS_BASE shr 20)/4 |
500 | mov ecx, (OS_BASE shr 20)/4 |
502 | xor eax, eax |
501 | xor eax, eax |
503 | rep stosd |
502 | rep stosd |
504 | 503 | ||
505 | mov ecx, (OS_BASE shr 20)/4 |
504 | mov ecx, (OS_BASE shr 20)/4 |
506 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
505 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
507 | rep movsd |
506 | rep movsd |
508 | 507 | ||
509 | mov eax, [edi-8192+PROC.pdt_0_phys] |
508 | mov eax, [edi-8192+PROC.pdt_0_phys] |
510 | or eax, PG_SWR |
509 | or eax, PG_SWR |
511 | mov [edi-4096+(page_tabs shr 20)], eax |
510 | mov [edi-4096+(page_tabs shr 20)], eax |
512 | 511 | ||
513 | lea eax, [edi-8192] |
512 | lea eax, [edi-8192] |
514 | call set_cr3 |
513 | call set_cr3 |
515 | 514 | ||
516 | mov edx, [app_tabs] |
515 | mov edx, [app_tabs] |
517 | xor edi, edi |
516 | xor edi, edi |
518 | @@: |
517 | @@: |
519 | call alloc_page |
518 | call alloc_page |
520 | test eax, eax |
519 | test eax, eax |
521 | jz .fail |
520 | jz .fail |
522 | 521 | ||
523 | stdcall map_page_table, edi, eax |
522 | stdcall map_page_table, edi, eax |
524 | add edi, 0x00400000 |
523 | add edi, 0x00400000 |
525 | dec edx |
524 | dec edx |
526 | jnz @B |
525 | jnz @B |
527 | 526 | ||
528 | mov edi, page_tabs |
527 | mov edi, page_tabs |
529 | 528 | ||
530 | mov ecx, [app_tabs] |
529 | mov ecx, [app_tabs] |
531 | shl ecx, 10 |
530 | shl ecx, 10 |
532 | xor eax, eax |
531 | xor eax, eax |
533 | rep stosd |
532 | rep stosd |
534 | 533 | ||
535 | mov ecx, [img_pages] |
534 | mov ecx, [img_pages] |
536 | mov ebx, PG_UWR |
535 | mov ebx, PG_UWR |
537 | xor edx, edx |
536 | xor edx, edx |
538 | mov esi, [img_base] |
537 | mov esi, [img_base] |
539 | shr esi, 10 |
538 | shr esi, 10 |
540 | add esi, page_tabs |
539 | add esi, page_tabs |
541 | mov edi, page_tabs |
540 | mov edi, page_tabs |
542 | .remap: |
541 | .remap: |
543 | lodsd |
542 | lodsd |
544 | and eax, 0xFFFFF000 |
543 | and eax, 0xFFFFF000 |
545 | or eax, ebx; force user level r/w access |
544 | or eax, ebx; force user level r/w access |
546 | stosd |
545 | stosd |
547 | add edx, 0x1000 |
546 | add edx, 0x1000 |
548 | dec [app_pages] |
547 | dec [app_pages] |
549 | dec ecx |
548 | dec ecx |
550 | jnz .remap |
549 | jnz .remap |
551 | 550 | ||
552 | mov ecx, [app_pages] |
551 | mov ecx, [app_pages] |
553 | test ecx, ecx |
552 | test ecx, ecx |
554 | jz .done |
553 | jz .done |
555 | 554 | ||
556 | .alloc: |
555 | .alloc: |
557 | call alloc_page |
556 | call alloc_page |
558 | test eax, eax |
557 | test eax, eax |
559 | jz .fail |
558 | jz .fail |
560 | 559 | ||
561 | stdcall map_page, edx, eax, dword PG_UWR |
560 | stdcall map_page, edx, eax, dword PG_UWR |
562 | add edx, 0x1000 |
561 | add edx, 0x1000 |
563 | dec [app_pages] |
562 | dec [app_pages] |
564 | jnz .alloc |
563 | jnz .alloc |
565 | 564 | ||
566 | .done: |
565 | .done: |
567 | mov ecx, pg_data.mutex |
566 | mov ecx, pg_data.mutex |
568 | call mutex_unlock |
567 | call mutex_unlock |
569 | mov eax, [process] |
568 | mov eax, [process] |
570 | 569 | ||
571 | pop edi |
570 | pop edi |
572 | pop esi |
571 | pop esi |
573 | pop ebx |
572 | pop ebx |
574 | ret |
573 | ret |
575 | .fail: |
574 | .fail: |
576 | mov ecx, pg_data.mutex |
575 | mov ecx, pg_data.mutex |
577 | call mutex_unlock |
576 | call mutex_unlock |
578 | cmp [process], 0 |
577 | cmp [process], 0 |
579 | je @f |
578 | je @f |
580 | ;; stdcall destroy_app_space, [dir_addr], 0 |
579 | ;; stdcall destroy_app_space, [dir_addr], 0 |
581 | @@: |
580 | @@: |
582 | xor eax, eax |
581 | xor eax, eax |
583 | pop edi |
582 | pop edi |
584 | pop esi |
583 | pop esi |
585 | pop ebx |
584 | pop ebx |
586 | ret |
585 | ret |
587 | endp |
586 | endp |
588 | 587 | ||
589 | align 4 |
588 | align 4 |
590 | set_cr3: |
589 | set_cr3: |
591 | pushfd |
590 | pushfd |
592 | cli |
591 | cli |
593 | mov ebx, [current_slot] |
592 | mov ebx, [current_slot] |
594 | mov [current_process], eax |
593 | mov [current_process], eax |
595 | mov [ebx+APPDATA.process], eax |
594 | mov [ebx+APPDATA.process], eax |
596 | mov eax, [eax+PROC.pdt_0_phys] |
595 | mov eax, [eax+PROC.pdt_0_phys] |
597 | mov cr3, eax |
596 | mov cr3, eax |
598 | popfd |
597 | popfd |
599 | ret |
598 | ret |
600 | 599 | ||
601 | align 4 |
600 | align 4 |
602 | proc destroy_page_table stdcall, pg_tab:dword |
601 | proc destroy_page_table stdcall, pg_tab:dword |
603 | 602 | ||
604 | push esi |
603 | push esi |
605 | 604 | ||
606 | mov esi, [pg_tab] |
605 | mov esi, [pg_tab] |
607 | mov ecx, 1024 |
606 | mov ecx, 1024 |
608 | .free: |
607 | .free: |
609 | mov eax, [esi] |
608 | mov eax, [esi] |
610 | test eax, 1 |
609 | test eax, 1 |
611 | jz .next |
610 | jz .next |
612 | test eax, 2 |
611 | test eax, 2 |
613 | jz .next |
612 | jz .next |
614 | test eax, 1 shl 9 |
613 | test eax, 1 shl 9 |
615 | jnz .next ;skip shared pages |
614 | jnz .next ;skip shared pages |
616 | call free_page |
615 | call free_page |
617 | .next: |
616 | .next: |
618 | add esi, 4 |
617 | add esi, 4 |
619 | dec ecx |
618 | dec ecx |
620 | jnz .free |
619 | jnz .free |
621 | pop esi |
620 | pop esi |
622 | ret |
621 | ret |
623 | endp |
622 | endp |
624 | 623 | ||
625 | align 4 |
624 | align 4 |
626 | destroy_process: ;fastcall ecx= ptr to process |
625 | destroy_process: ;fastcall ecx= ptr to process |
627 | 626 | ||
628 | lea eax, [ecx+PROC.thr_list] |
627 | lea eax, [ecx+PROC.thr_list] |
629 | cmp eax, [eax+LHEAD.next] |
628 | cmp eax, [eax+LHEAD.next] |
630 | jne .exit |
629 | jne .exit |
631 | 630 | ||
632 | align 4 |
631 | align 4 |
633 | .internal: |
632 | .internal: |
634 | push ecx |
633 | push ecx |
635 | 634 | ||
636 | mov esi, [ecx+PROC.dlls_list_ptr] |
635 | mov esi, [ecx+PROC.dlls_list_ptr] |
637 | call destroy_all_hdlls |
636 | call destroy_all_hdlls |
638 | 637 | ||
639 | ; mov ecx, pg_data.mutex |
638 | ; mov ecx, pg_data.mutex |
640 | ; call mutex_lock |
639 | ; call mutex_lock |
641 | 640 | ||
642 | mov esi, [esp] |
641 | mov esi, [esp] |
643 | add esi, PROC.pdt_0 |
642 | add esi, PROC.pdt_0 |
644 | mov edi, (0x80000000 shr 20)/4 |
643 | mov edi, (0x80000000 shr 20)/4 |
645 | .destroy: |
644 | .destroy: |
646 | mov eax, [esi] |
645 | mov eax, [esi] |
647 | test eax, 1 |
646 | test eax, 1 |
648 | jz .next |
647 | jz .next |
649 | and eax, not 0xFFF |
648 | and eax, not 0xFFF |
650 | stdcall map_page, [tmp_task_ptab], eax, PG_SWR |
649 | stdcall map_page, [tmp_task_ptab], eax, PG_SWR |
651 | stdcall destroy_page_table, [tmp_task_ptab] |
650 | stdcall destroy_page_table, [tmp_task_ptab] |
652 | mov eax, [esi] |
651 | mov eax, [esi] |
653 | call free_page |
652 | call free_page |
654 | .next: |
653 | .next: |
655 | add esi, 4 |
654 | add esi, 4 |
656 | dec edi |
655 | dec edi |
657 | jnz .destroy |
656 | jnz .destroy |
658 | 657 | ||
659 | call kernel_free ;ecx still in stack |
658 | call kernel_free ;ecx still in stack |
660 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
659 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
661 | ; mov ecx, pg_data.mutex |
660 | ; mov ecx, pg_data.mutex |
662 | ; call mutex_unlock |
661 | ; call mutex_unlock |
663 | 662 | ||
664 | .exit: |
663 | .exit: |
665 | ret |
664 | ret |
666 | 665 | ||
667 | align 4 |
666 | align 4 |
668 | get_pid: |
667 | get_pid: |
669 | mov eax, [TASK_BASE] |
668 | mov eax, [TASK_BASE] |
670 | mov eax, [eax+TASKDATA.pid] |
669 | mov eax, [eax+TASKDATA.pid] |
671 | ret |
670 | ret |
672 | 671 | ||
673 | pid_to_slot: |
672 | pid_to_slot: |
674 | ;Input: |
673 | ;Input: |
675 | ; eax - pid of process |
674 | ; eax - pid of process |
676 | ;Output: |
675 | ;Output: |
677 | ; eax - slot of process or 0 if process don't exists |
676 | ; eax - slot of process or 0 if process don't exists |
678 | ;Search process by PID. |
677 | ;Search process by PID. |
679 | push ebx |
678 | push ebx |
680 | push ecx |
679 | push ecx |
681 | mov ebx, [TASK_COUNT] |
680 | mov ebx, [TASK_COUNT] |
682 | shl ebx, 5 |
681 | shl ebx, 5 |
683 | mov ecx, 2*32 |
682 | mov ecx, 2*32 |
684 | 683 | ||
685 | .loop: |
684 | .loop: |
686 | ;ecx=offset of current process info entry |
685 | ;ecx=offset of current process info entry |
687 | ;ebx=maximum permitted offset |
686 | ;ebx=maximum permitted offset |
688 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
687 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
689 | jz .endloop ;skip empty slots |
688 | jz .endloop ;skip empty slots |
690 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
689 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
691 | jz .pid_found |
690 | jz .pid_found |
692 | .endloop: |
691 | .endloop: |
693 | add ecx, 32 |
692 | add ecx, 32 |
694 | cmp ecx, ebx |
693 | cmp ecx, ebx |
695 | jle .loop |
694 | jle .loop |
696 | 695 | ||
697 | pop ecx |
696 | pop ecx |
698 | pop ebx |
697 | pop ebx |
699 | xor eax, eax |
698 | xor eax, eax |
700 | ret |
699 | ret |
701 | 700 | ||
702 | .pid_found: |
701 | .pid_found: |
703 | shr ecx, 5 |
702 | shr ecx, 5 |
704 | mov eax, ecx ;convert offset to index of slot |
703 | mov eax, ecx ;convert offset to index of slot |
705 | pop ecx |
704 | pop ecx |
706 | pop ebx |
705 | pop ebx |
707 | ret |
706 | ret |
708 | 707 | ||
709 | check_region: |
708 | check_region: |
710 | ;input: |
709 | ;input: |
711 | ; esi - start of buffer |
710 | ; esi - start of buffer |
712 | ; edx - size of buffer |
711 | ; edx - size of buffer |
713 | ;result: |
712 | ;result: |
714 | ; eax = 1 region lays in app memory |
713 | ; eax = 1 region lays in app memory |
715 | ; eax = 0 region don't lays in app memory |
714 | ; eax = 0 region don't lays in app memory |
716 | 715 | ||
717 | mov eax, 1 |
716 | mov eax, 1 |
718 | ret |
717 | ret |
719 | if 0 |
718 | if 0 |
720 | mov eax, [CURRENT_TASK] |
719 | mov eax, [CURRENT_TASK] |
721 | ; jmp check_process_region |
720 | ; jmp check_process_region |
722 | ;----------------------------------------------------------------------------- |
721 | ;----------------------------------------------------------------------------- |
723 | ;check_process_region: |
722 | ;check_process_region: |
724 | ;input: |
723 | ;input: |
725 | ; eax - slot |
724 | ; eax - slot |
726 | ; esi - start of buffer |
725 | ; esi - start of buffer |
727 | ; edx - size of buffer |
726 | ; edx - size of buffer |
728 | ;result: |
727 | ;result: |
729 | ; eax = 1 region lays in app memory |
728 | ; eax = 1 region lays in app memory |
730 | ; eax = 0 region don't lays in app memory |
729 | ; eax = 0 region don't lays in app memory |
731 | 730 | ||
732 | test edx, edx |
731 | test edx, edx |
733 | jle .ok |
732 | jle .ok |
734 | shl eax, 5 |
733 | shl eax, 5 |
735 | cmp word [CURRENT_TASK+eax+0xa], 0 |
734 | cmp word [CURRENT_TASK+eax+0xa], 0 |
736 | jnz .failed |
735 | jnz .failed |
737 | shl eax, 3 |
736 | shl eax, 3 |
738 | mov eax, [SLOT_BASE+eax+0xb8] |
737 | mov eax, [SLOT_BASE+eax+0xb8] |
739 | test eax, eax |
738 | test eax, eax |
740 | jz .failed |
739 | jz .failed |
741 | 740 | ||
742 | mov eax, 1 |
741 | mov eax, 1 |
743 | ret |
742 | ret |
744 | .ok: |
743 | .ok: |
745 | mov eax, 1 |
744 | mov eax, 1 |
746 | ret |
745 | ret |
747 | .failed: |
746 | .failed: |
748 | xor eax, eax |
747 | xor eax, eax |
749 | ret |
748 | ret |
750 | end if |
749 | end if |
751 | 750 | ||
752 | align 4 |
751 | align 4 |
753 | proc read_process_memory |
752 | proc read_process_memory |
754 | ;Input: |
753 | ;Input: |
755 | ; eax - process slot |
754 | ; eax - process slot |
756 | ; ecx - buffer address |
755 | ; ecx - buffer address |
757 | ; edx - buffer size |
756 | ; edx - buffer size |
758 | ; esi - start address in other process |
757 | ; esi - start address in other process |
759 | ;Output: |
758 | ;Output: |
760 | ; eax - number of bytes read. |
759 | ; eax - number of bytes read. |
761 | locals |
760 | locals |
762 | slot dd ? |
761 | slot dd ? |
763 | buff dd ? |
762 | buff dd ? |
764 | r_count dd ? |
763 | r_count dd ? |
765 | offset dd ? |
764 | offset dd ? |
766 | tmp_r_cnt dd ? |
765 | tmp_r_cnt dd ? |
767 | endl |
766 | endl |
768 | 767 | ||
769 | mov [slot], eax |
768 | mov [slot], eax |
770 | mov [buff], ecx |
769 | mov [buff], ecx |
771 | and [r_count], 0 |
770 | and [r_count], 0 |
772 | mov [tmp_r_cnt], edx |
771 | mov [tmp_r_cnt], edx |
773 | mov [offset], esi |
772 | mov [offset], esi |
774 | 773 | ||
775 | pushad |
774 | pushad |
776 | .read_mem: |
775 | .read_mem: |
777 | mov edx, [offset] |
776 | mov edx, [offset] |
778 | mov ebx, [tmp_r_cnt] |
777 | mov ebx, [tmp_r_cnt] |
779 | 778 | ||
780 | mov ecx, 0x400000 |
779 | mov ecx, 0x400000 |
781 | and edx, 0x3FFFFF |
780 | and edx, 0x3FFFFF |
782 | sub ecx, edx |
781 | sub ecx, edx |
783 | cmp ecx, ebx |
782 | cmp ecx, ebx |
784 | jbe @f |
783 | jbe @f |
785 | mov ecx, ebx |
784 | mov ecx, ebx |
786 | @@: |
785 | @@: |
787 | cmp ecx, 0x8000 |
786 | cmp ecx, 0x8000 |
788 | jna @F |
787 | jna @F |
789 | mov ecx, 0x8000 |
788 | mov ecx, 0x8000 |
790 | @@: |
789 | @@: |
791 | mov ebx, [offset] |
790 | mov ebx, [offset] |
792 | 791 | ||
793 | push ecx |
792 | push ecx |
794 | stdcall map_memEx, [proc_mem_map], \ |
793 | stdcall map_memEx, [proc_mem_map], \ |
795 | [slot], ebx, ecx, PG_READ |
794 | [slot], ebx, ecx, PG_READ |
796 | pop ecx |
795 | pop ecx |
797 | 796 | ||
798 | mov esi, [offset] |
797 | mov esi, [offset] |
799 | and esi, 0xfff |
798 | and esi, 0xfff |
800 | sub eax, esi |
799 | sub eax, esi |
801 | jbe .ret |
800 | jbe .ret |
802 | cmp ecx, eax |
801 | cmp ecx, eax |
803 | jbe @f |
802 | jbe @f |
804 | mov ecx, eax |
803 | mov ecx, eax |
805 | mov [tmp_r_cnt], eax |
804 | mov [tmp_r_cnt], eax |
806 | @@: |
805 | @@: |
807 | add esi, [proc_mem_map] |
806 | add esi, [proc_mem_map] |
808 | mov edi, [buff] |
807 | mov edi, [buff] |
809 | mov edx, ecx |
808 | mov edx, ecx |
810 | rep movsb |
809 | rep movsb |
811 | add [r_count], edx |
810 | add [r_count], edx |
812 | 811 | ||
813 | add [offset], edx |
812 | add [offset], edx |
814 | sub [tmp_r_cnt], edx |
813 | sub [tmp_r_cnt], edx |
815 | jnz .read_mem |
814 | jnz .read_mem |
816 | .ret: |
815 | .ret: |
817 | popad |
816 | popad |
818 | mov eax, [r_count] |
817 | mov eax, [r_count] |
819 | ret |
818 | ret |
820 | endp |
819 | endp |
821 | 820 | ||
822 | align 4 |
821 | align 4 |
823 | proc write_process_memory |
822 | proc write_process_memory |
824 | ;Input: |
823 | ;Input: |
825 | ; eax - process slot |
824 | ; eax - process slot |
826 | ; ecx - buffer address |
825 | ; ecx - buffer address |
827 | ; edx - buffer size |
826 | ; edx - buffer size |
828 | ; esi - start address in other process |
827 | ; esi - start address in other process |
829 | ;Output: |
828 | ;Output: |
830 | ; eax - number of bytes written |
829 | ; eax - number of bytes written |
831 | 830 | ||
832 | locals |
831 | locals |
833 | slot dd ? |
832 | slot dd ? |
834 | buff dd ? |
833 | buff dd ? |
835 | w_count dd ? |
834 | w_count dd ? |
836 | offset dd ? |
835 | offset dd ? |
837 | tmp_w_cnt dd ? |
836 | tmp_w_cnt dd ? |
838 | endl |
837 | endl |
839 | 838 | ||
840 | mov [slot], eax |
839 | mov [slot], eax |
841 | mov [buff], ecx |
840 | mov [buff], ecx |
842 | and [w_count], 0 |
841 | and [w_count], 0 |
843 | mov [tmp_w_cnt], edx |
842 | mov [tmp_w_cnt], edx |
844 | mov [offset], esi |
843 | mov [offset], esi |
845 | 844 | ||
846 | pushad |
845 | pushad |
847 | .read_mem: |
846 | .read_mem: |
848 | mov edx, [offset] |
847 | mov edx, [offset] |
849 | mov ebx, [tmp_w_cnt] |
848 | mov ebx, [tmp_w_cnt] |
850 | 849 | ||
851 | mov ecx, 0x400000 |
850 | mov ecx, 0x400000 |
852 | and edx, 0x3FFFFF |
851 | and edx, 0x3FFFFF |
853 | sub ecx, edx |
852 | sub ecx, edx |
854 | cmp ecx, ebx |
853 | cmp ecx, ebx |
855 | jbe @f |
854 | jbe @f |
856 | mov ecx, ebx |
855 | mov ecx, ebx |
857 | @@: |
856 | @@: |
858 | cmp ecx, 0x8000 |
857 | cmp ecx, 0x8000 |
859 | jna @F |
858 | jna @F |
860 | mov ecx, 0x8000 |
859 | mov ecx, 0x8000 |
861 | @@: |
860 | @@: |
862 | mov ebx, [offset] |
861 | mov ebx, [offset] |
863 | ; add ebx, new_app_base |
862 | ; add ebx, new_app_base |
864 | push ecx |
863 | push ecx |
865 | stdcall map_memEx, [proc_mem_map], \ |
864 | stdcall map_memEx, [proc_mem_map], \ |
866 | [slot], ebx, ecx, PG_SWR |
865 | [slot], ebx, ecx, PG_SWR |
867 | pop ecx |
866 | pop ecx |
868 | 867 | ||
869 | mov edi, [offset] |
868 | mov edi, [offset] |
870 | and edi, 0xfff |
869 | and edi, 0xfff |
871 | sub eax, edi |
870 | sub eax, edi |
872 | jbe .ret |
871 | jbe .ret |
873 | cmp ecx, eax |
872 | cmp ecx, eax |
874 | jbe @f |
873 | jbe @f |
875 | mov ecx, eax |
874 | mov ecx, eax |
876 | mov [tmp_w_cnt], eax |
875 | mov [tmp_w_cnt], eax |
877 | @@: |
876 | @@: |
878 | add edi, [proc_mem_map] |
877 | add edi, [proc_mem_map] |
879 | mov esi, [buff] |
878 | mov esi, [buff] |
880 | mov edx, ecx |
879 | mov edx, ecx |
881 | rep movsb |
880 | rep movsb |
882 | 881 | ||
883 | add [w_count], edx |
882 | add [w_count], edx |
884 | add [offset], edx |
883 | add [offset], edx |
885 | sub [tmp_w_cnt], edx |
884 | sub [tmp_w_cnt], edx |
886 | jnz .read_mem |
885 | jnz .read_mem |
887 | .ret: |
886 | .ret: |
888 | popad |
887 | popad |
889 | mov eax, [w_count] |
888 | mov eax, [w_count] |
890 | ret |
889 | ret |
891 | endp |
890 | endp |
892 | 891 | ||
893 | ;ebx = 1 - kernel thread |
892 | ;ebx = 1 - kernel thread |
894 | ;ecx=thread entry point |
893 | ;ecx=thread entry point |
895 | ;edx=thread stack pointer |
894 | ;edx=thread stack pointer |
896 | ;creation flags 0x01 - debugged |
895 | ;creation flags 0x01 - debugged |
897 | ; 0x02 - kernel |
896 | ; 0x02 - kernel |
898 | 897 | ||
899 | align 4 |
898 | align 4 |
900 | proc new_sys_threads |
899 | proc new_sys_threads |
901 | locals |
900 | locals |
902 | slot dd ? |
901 | slot dd ? |
903 | flags dd ? |
902 | flags dd ? |
904 | app_cmdline dd ? ;0x00 |
903 | app_cmdline dd ? ;0x00 |
905 | app_path dd ? ;0x04 |
904 | app_path dd ? ;0x04 |
906 | app_eip dd ? ;0x08 |
905 | app_eip dd ? ;0x08 |
907 | app_esp dd ? ;0x0C |
906 | app_esp dd ? ;0x0C |
908 | app_mem dd ? ;0x10 |
907 | app_mem dd ? ;0x10 |
909 | endl |
908 | endl |
910 | 909 | ||
911 | shl ebx, 1 |
910 | shl ebx, 1 |
912 | mov [flags], ebx |
911 | mov [flags], ebx |
913 | 912 | ||
914 | xor eax, eax |
913 | xor eax, eax |
915 | mov [app_eip], ecx |
914 | mov [app_eip], ecx |
916 | mov [app_cmdline], eax |
915 | mov [app_cmdline], eax |
917 | mov [app_esp], edx |
916 | mov [app_esp], edx |
918 | mov [app_path], eax |
917 | mov [app_path], eax |
919 | 918 | ||
920 | call lock_application_table |
919 | call lock_application_table |
921 | 920 | ||
922 | call alloc_thread_slot |
921 | call alloc_thread_slot |
923 | test eax, eax |
922 | test eax, eax |
924 | jz .failed |
923 | jz .failed |
925 | 924 | ||
926 | mov [slot], eax |
925 | mov [slot], eax |
927 | 926 | ||
928 | mov esi, [current_slot] |
927 | mov esi, [current_slot] |
929 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
928 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
930 | 929 | ||
931 | mov edi, eax |
930 | mov edi, eax |
932 | shl edi, 8 |
931 | shl edi, 8 |
933 | add edi, SLOT_BASE |
932 | add edi, SLOT_BASE |
934 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
933 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
935 | mov ecx, 256/4 |
934 | mov ecx, 256/4 |
936 | xor eax, eax |
935 | xor eax, eax |
937 | cld |
936 | cld |
938 | rep stosd ;clean extended information about new thread |
937 | rep stosd ;clean extended information about new thread |
939 | mov esi, ebx |
938 | mov esi, ebx |
940 | mov edi, edx |
939 | mov edi, edx |
941 | mov ecx, 11 |
940 | mov ecx, 11 |
942 | rep movsb ;copy process name |
941 | rep movsb ;copy process name |
943 | 942 | ||
944 | mov eax, [ebx+APPDATA.process] |
943 | mov eax, [ebx+APPDATA.process] |
945 | mov [edx+APPDATA.process], eax |
944 | mov [edx+APPDATA.process], eax |
946 | 945 | ||
947 | lea ebx, [edx+APPDATA.list] |
946 | lea ebx, [edx+APPDATA.list] |
948 | lea ecx, [eax+PROC.thr_list] |
947 | lea ecx, [eax+PROC.thr_list] |
949 | list_add_tail ebx, ecx ;add thread to process child's list |
948 | list_add_tail ebx, ecx ;add thread to process child's list |
950 | 949 | ||
951 | mov eax, [ebx+APPDATA.tls_base] |
950 | mov eax, [ebx+APPDATA.tls_base] |
952 | test eax, eax |
951 | test eax, eax |
953 | jz @F |
952 | jz @F |
954 | 953 | ||
955 | push edx |
954 | push edx |
956 | stdcall user_alloc, 4096 |
955 | stdcall user_alloc, 4096 |
957 | pop edx |
956 | pop edx |
958 | test eax, eax |
957 | test eax, eax |
959 | jz .failed1;eax=0 |
958 | jz .failed1;eax=0 |
960 | @@: |
959 | @@: |
961 | mov [edx+APPDATA.tls_base], eax |
960 | mov [edx+APPDATA.tls_base], eax |
962 | 961 | ||
963 | lea eax, [app_cmdline] |
962 | lea eax, [app_cmdline] |
964 | stdcall set_app_params , [slot], eax, dword 0, \ |
963 | stdcall set_app_params , [slot], eax, dword 0, \ |
965 | dword 0, [flags] |
964 | dword 0, [flags] |
966 | 965 | ||
967 | mov eax, [process_number] ;set result |
966 | mov eax, [process_number] ;set result |
968 | call unlock_application_table |
967 | call unlock_application_table |
969 | ret |
968 | ret |
970 | .failed: |
969 | .failed: |
971 | xor eax, eax |
970 | xor eax, eax |
972 | .failed1: |
971 | .failed1: |
973 | call unlock_application_table |
972 | call unlock_application_table |
974 | dec eax ;-1 |
973 | dec eax ;-1 |
975 | ret |
974 | ret |
976 | endp |
975 | endp |
977 | 976 | ||
978 | align 4 |
977 | align 4 |
979 | tls_app_entry: |
978 | tls_app_entry: |
980 | 979 | ||
981 | call init_heap |
980 | call init_heap |
982 | stdcall user_alloc, 4096 |
981 | stdcall user_alloc, 4096 |
983 | 982 | ||
984 | mov edx, [current_slot] |
983 | mov edx, [current_slot] |
985 | mov [edx+APPDATA.tls_base], eax |
984 | mov [edx+APPDATA.tls_base], eax |
986 | mov [tls_data_l+2], ax |
985 | mov [tls_data_l+2], ax |
987 | shr eax, 16 |
986 | shr eax, 16 |
988 | mov [tls_data_l+4], al |
987 | mov [tls_data_l+4], al |
989 | mov [tls_data_l+7], ah |
988 | mov [tls_data_l+7], ah |
990 | mov dx, app_tls |
989 | mov dx, app_tls |
991 | mov fs, dx |
990 | mov fs, dx |
992 | popad |
991 | popad |
993 | iretd |
992 | iretd |
994 | 993 | ||
995 | 994 | ||
996 | EFL_IF equ 0x0200 |
995 | EFL_IF equ 0x0200 |
997 | EFL_IOPL1 equ 0x1000 |
996 | EFL_IOPL1 equ 0x1000 |
998 | EFL_IOPL2 equ 0x2000 |
997 | EFL_IOPL2 equ 0x2000 |
999 | EFL_IOPL3 equ 0x3000 |
998 | EFL_IOPL3 equ 0x3000 |
1000 | 999 | ||
1001 | 1000 | ||
1002 | align 4 |
1001 | align 4 |
1003 | proc set_app_params stdcall,slot:dword, params:dword,\ |
1002 | proc set_app_params stdcall,slot:dword, params:dword,\ |
1004 | cmd_line:dword, app_path:dword, flags:dword |
1003 | cmd_line:dword, app_path:dword, flags:dword |
1005 | 1004 | ||
1006 | locals |
1005 | locals |
1007 | pl0_stack dd ? |
1006 | pl0_stack dd ? |
1008 | endl |
1007 | endl |
1009 | 1008 | ||
1010 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1009 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1011 | mov [pl0_stack], eax |
1010 | mov [pl0_stack], eax |
1012 | 1011 | ||
1013 | lea edi, [eax+RING0_STACK_SIZE] |
1012 | lea edi, [eax+RING0_STACK_SIZE] |
1014 | 1013 | ||
1015 | mov eax, [slot] |
1014 | mov eax, [slot] |
1016 | mov ebx, eax |
1015 | mov ebx, eax |
1017 | 1016 | ||
1018 | shl eax, 8 |
1017 | shl eax, 8 |
1019 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1018 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1020 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1019 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1021 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1020 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1022 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1021 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1023 | 1022 | ||
1024 | ;set default io permission map |
1023 | ;set default io permission map |
1025 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1024 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1026 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1025 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1027 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1026 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1028 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1027 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1029 | 1028 | ||
1030 | mov esi, fpu_data |
1029 | mov esi, fpu_data |
1031 | mov ecx, 512/4 |
1030 | mov ecx, 512/4 |
1032 | rep movsd |
1031 | rep movsd |
1033 | 1032 | ||
1034 | cmp ebx, [TASK_COUNT] |
1033 | cmp ebx, [TASK_COUNT] |
1035 | jle .noinc |
1034 | jle .noinc |
1036 | inc dword [TASK_COUNT] ;update number of processes |
1035 | inc dword [TASK_COUNT] ;update number of processes |
1037 | .noinc: |
1036 | .noinc: |
1038 | shl ebx, 8 |
1037 | shl ebx, 8 |
1039 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1038 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1040 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1039 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1041 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1040 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1042 | 1041 | ||
1043 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1042 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1044 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1043 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1045 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1044 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1046 | 1045 | ||
1047 | mov ecx, [def_cursor] |
1046 | mov ecx, [def_cursor] |
1048 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1047 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1049 | mov eax, [pl0_stack] |
1048 | mov eax, [pl0_stack] |
1050 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1049 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1051 | add eax, RING0_STACK_SIZE |
1050 | add eax, RING0_STACK_SIZE |
1052 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1051 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1053 | 1052 | ||
1054 | push ebx |
1053 | push ebx |
1055 | stdcall kernel_alloc, 0x1000 |
1054 | stdcall kernel_alloc, 0x1000 |
1056 | pop ebx |
1055 | pop ebx |
1057 | mov esi, [current_slot] |
1056 | mov esi, [current_slot] |
1058 | mov esi, [esi+APPDATA.cur_dir] |
1057 | mov esi, [esi+APPDATA.cur_dir] |
1059 | mov ecx, 0x1000/4 |
1058 | mov ecx, 0x1000/4 |
1060 | mov edi, eax |
1059 | mov edi, eax |
1061 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1060 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1062 | rep movsd |
1061 | rep movsd |
1063 | 1062 | ||
1064 | shr ebx, 3 |
1063 | shr ebx, 3 |
1065 | mov eax, new_app_base |
1064 | mov eax, new_app_base |
1066 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1065 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1067 | 1066 | ||
1068 | .add_command_line: |
1067 | .add_command_line: |
1069 | mov edx, [params] |
1068 | mov edx, [params] |
1070 | mov edx, [edx] ;app_cmdline |
1069 | mov edx, [edx] ;app_cmdline |
1071 | test edx, edx |
1070 | test edx, edx |
1072 | jz @f ;application doesn't need parameters |
1071 | jz @f ;application doesn't need parameters |
1073 | 1072 | ||
1074 | mov eax, edx |
1073 | mov eax, edx |
1075 | add eax, 256 |
1074 | add eax, 256 |
1076 | jc @f |
1075 | jc @f |
1077 | 1076 | ||
1078 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1077 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1079 | ; ja @f |
1078 | ; ja @f |
1080 | 1079 | ||
1081 | mov eax, [cmd_line] |
1080 | mov eax, [cmd_line] |
1082 | 1081 | ||
1083 | cmp [edx], dword 0xffffffff ; extended destination tag |
1082 | cmp [edx], dword 0xffffffff ; extended destination tag |
1084 | jne .no_ext_dest |
1083 | jne .no_ext_dest |
1085 | 1084 | ||
1086 | mov edx, [edx+4] ; extended destination for cmdline |
1085 | mov edx, [edx+4] ; extended destination for cmdline |
1087 | jmp .continue |
1086 | jmp .continue |
1088 | 1087 | ||
1089 | .no_ext_dest: |
1088 | .no_ext_dest: |
1090 | mov [eax-12], dword 255 |
1089 | mov [eax-12], dword 255 |
1091 | .continue: |
1090 | .continue: |
1092 | mov byte [edx], 0 ;force empty string if no cmdline given |
1091 | mov byte [edx], 0 ;force empty string if no cmdline given |
1093 | 1092 | ||
1094 | test eax, eax |
1093 | test eax, eax |
1095 | jz @f |
1094 | jz @f |
1096 | ;-------------------------------------- |
1095 | ;-------------------------------------- |
1097 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1096 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1098 | jne .old_copy |
1097 | jne .old_copy |
1099 | 1098 | ||
1100 | push eax |
1099 | push eax |
1101 | stdcall strncpy, edx, [eax-8], [eax-12] |
1100 | stdcall strncpy, edx, [eax-8], [eax-12] |
1102 | pop eax |
1101 | pop eax |
1103 | 1102 | ||
1104 | stdcall kernel_free, [eax-8] |
1103 | stdcall kernel_free, [eax-8] |
1105 | jmp @f |
1104 | jmp @f |
1106 | 1105 | ||
1107 | .old_copy: |
1106 | .old_copy: |
1108 | ;-------------------------------------- |
1107 | ;-------------------------------------- |
1109 | stdcall strncpy, edx, eax, 256 |
1108 | stdcall strncpy, edx, eax, 256 |
1110 | @@: |
1109 | @@: |
1111 | mov edx, [params] |
1110 | mov edx, [params] |
1112 | mov edx, [edx+4];app_path |
1111 | mov edx, [edx+4];app_path |
1113 | test edx, edx |
1112 | test edx, edx |
1114 | jz @F ;application don't need path of file |
1113 | jz @F ;application don't need path of file |
1115 | mov eax, edx |
1114 | mov eax, edx |
1116 | add eax, 1024 |
1115 | add eax, 1024 |
1117 | jc @f |
1116 | jc @f |
1118 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1117 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1119 | ; ja @f |
1118 | ; ja @f |
1120 | stdcall strncpy, edx, [app_path], 1024 |
1119 | stdcall strncpy, edx, [app_path], 1024 |
1121 | @@: |
1120 | @@: |
1122 | mov ebx, [slot] |
1121 | mov ebx, [slot] |
1123 | mov eax, ebx |
1122 | mov eax, ebx |
1124 | shl ebx, 5 |
1123 | shl ebx, 5 |
1125 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1124 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1126 | 1125 | ||
1127 | mov edx, irq0.return |
1126 | mov edx, irq0.return |
1128 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1127 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1129 | jne @F |
1128 | jne @F |
1130 | mov edx, tls_app_entry |
1129 | mov edx, tls_app_entry |
1131 | @@: |
1130 | @@: |
1132 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1131 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1133 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1132 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1134 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1133 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1135 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1134 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1136 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1135 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1137 | 1136 | ||
1138 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1137 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1139 | 1138 | ||
1140 | inc dword [process_number] |
1139 | inc dword [process_number] |
1141 | mov eax, [process_number] |
1140 | mov eax, [process_number] |
1142 | mov [ebx+4], eax ;set PID |
1141 | mov [ebx+4], eax ;set PID |
1143 | 1142 | ||
1144 | ;set draw data to full screen |
1143 | ;set draw data to full screen |
1145 | xor eax, eax |
1144 | xor eax, eax |
1146 | mov [ecx+0], dword eax |
1145 | mov [ecx+0], dword eax |
1147 | mov [ecx+4], dword eax |
1146 | mov [ecx+4], dword eax |
1148 | mov eax, [screen_workarea.right] |
1147 | mov eax, [screen_workarea.right] |
1149 | mov [ecx+8], eax |
1148 | mov [ecx+8], eax |
1150 | mov eax, [screen_workarea.bottom] |
1149 | mov eax, [screen_workarea.bottom] |
1151 | mov [ecx+12], eax |
1150 | mov [ecx+12], eax |
1152 | 1151 | ||
1153 | mov ebx, [pl0_stack] |
1152 | mov ebx, [pl0_stack] |
1154 | mov esi, [params] |
1153 | mov esi, [params] |
1155 | lea ecx, [ebx+REG_EIP] |
1154 | lea ecx, [ebx+REG_EIP] |
1156 | xor eax, eax |
1155 | xor eax, eax |
1157 | 1156 | ||
1158 | mov [ebx+REG_RET], edx |
1157 | mov [ebx+REG_RET], edx |
1159 | mov [ebx+REG_EDI], eax |
1158 | mov [ebx+REG_EDI], eax |
1160 | mov [ebx+REG_ESI], eax |
1159 | mov [ebx+REG_ESI], eax |
1161 | mov [ebx+REG_EBP], eax |
1160 | mov [ebx+REG_EBP], eax |
1162 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1161 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1163 | mov [ebx+REG_EBX], eax |
1162 | mov [ebx+REG_EBX], eax |
1164 | mov [ebx+REG_EDX], eax |
1163 | mov [ebx+REG_EDX], eax |
1165 | mov [ebx+REG_ECX], eax |
1164 | mov [ebx+REG_ECX], eax |
1166 | mov [ebx+REG_EAX], eax |
1165 | mov [ebx+REG_EAX], eax |
1167 | 1166 | ||
1168 | mov eax, [esi+0x08] ;app_eip |
1167 | mov eax, [esi+0x08] ;app_eip |
1169 | mov [ebx+REG_EIP], eax ;app_entry |
1168 | mov [ebx+REG_EIP], eax ;app_entry |
1170 | mov [ebx+REG_CS], dword app_code |
1169 | mov [ebx+REG_CS], dword app_code |
1171 | mov ecx, USER_PRIORITY |
1170 | mov ecx, USER_PRIORITY |
1172 | 1171 | ||
1173 | test byte [flags], 2 |
1172 | test byte [flags], 2 |
1174 | jz @F |
1173 | jz @F |
1175 | 1174 | ||
1176 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1175 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1177 | mov ecx, MAX_PRIORITY |
1176 | mov ecx, MAX_PRIORITY |
1178 | 1177 | ||
1179 | @@: |
1178 | @@: |
1180 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1179 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1181 | 1180 | ||
1182 | mov eax, [esi+0x0C] ;app_esp |
1181 | mov eax, [esi+0x0C] ;app_esp |
1183 | mov [ebx+REG_APP_ESP], eax;app_stack |
1182 | mov [ebx+REG_APP_ESP], eax;app_stack |
1184 | mov [ebx+REG_SS], dword app_data |
1183 | mov [ebx+REG_SS], dword app_data |
1185 | 1184 | ||
1186 | lea edx, [ebx+REG_RET] |
1185 | lea edx, [ebx+REG_RET] |
1187 | mov ebx, [slot] |
1186 | mov ebx, [slot] |
1188 | shl ebx, 5 |
1187 | shl ebx, 5 |
1189 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1188 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1190 | 1189 | ||
1191 | xor edx, edx; process state - running |
1190 | xor edx, edx; process state - running |
1192 | ; set if debuggee |
1191 | ; set if debuggee |
1193 | test byte [flags], 1 |
1192 | test byte [flags], 1 |
1194 | jz .no_debug |
1193 | jz .no_debug |
1195 | inc edx ; process state - suspended |
1194 | inc edx ; process state - suspended |
1196 | mov eax, [CURRENT_TASK] |
1195 | mov eax, [CURRENT_TASK] |
1197 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1196 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1198 | .no_debug: |
1197 | .no_debug: |
1199 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1198 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1200 | lea edx, [SLOT_BASE+ebx*8] |
1199 | lea edx, [SLOT_BASE+ebx*8] |
1201 | call scheduler_add_thread |
1200 | call scheduler_add_thread |
1202 | ret |
1201 | ret |
1203 | endp |
1202 | endp |
1204 | 1203 | ||
1205 | 1204 | ||
1206 | align 4 |
1205 | align 4 |
1207 | 1206 | ||
1208 | get_stack_base: |
1207 | get_stack_base: |
1209 | mov eax, [current_slot] |
1208 | mov eax, [current_slot] |
1210 | mov eax, [eax+APPDATA.pl0_stack] |
1209 | mov eax, [eax+APPDATA.pl0_stack] |
1211 | ret |
1210 | ret |
1212 | 1211 | ||
1213 | 1212 | ||
1214 | include "debug.inc"> |
1213 | include "debug.inc"> |