Rev 4429 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 4429 | Rev 4430 | ||
---|---|---|---|
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: 4424 $ |
8 | $Revision: 4424 $ |
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_slot] |
251 | mov ebx, [current_slot] |
252 | mov ebx, [ebx+APPDATA.process] |
252 | mov ebx, [ebx+APPDATA.process] |
253 | mov [save_proc], ebx |
253 | mov [save_proc], ebx |
254 | 254 | ||
255 | stdcall create_process, [hdr_mem], [file_base], [file_size] |
255 | stdcall create_process, [hdr_mem], [file_base], [file_size] |
256 | mov esi, -30; no memory |
256 | mov esi, -30; no memory |
257 | test eax, eax |
257 | test eax, eax |
258 | jz .failed |
258 | jz .failed |
- | 259 | ||
- | 260 | mov ebx, [hdr_mem] |
|
- | 261 | mov [eax+PROC.mem_used], ebx |
|
259 | 262 | ||
260 | mov ebx, [slot_base] |
263 | mov ebx, [slot_base] |
261 | mov [ebx+APPDATA.process], eax |
- | |
262 | mov eax, [hdr_mem] |
- | |
263 | mov [ebx+APPDATA.mem_size], eax |
264 | mov [ebx+APPDATA.process], eax |
264 | 265 | ||
265 | xor edx, edx |
266 | xor edx, edx |
266 | cmp word [6], '02' |
267 | cmp word [6], '02' |
267 | jne @f |
268 | jne @f |
268 | 269 | ||
269 | not edx |
270 | not edx |
270 | @@: |
271 | @@: |
271 | mov [ebx+APPDATA.tls_base], edx |
272 | mov [ebx+APPDATA.tls_base], edx |
272 | 273 | ||
273 | if GREEDY_KERNEL |
274 | if GREEDY_KERNEL |
274 | else |
275 | else |
275 | mov ecx, [hdr_mem] |
276 | mov ecx, [hdr_mem] |
276 | mov edi, [file_size] |
277 | mov edi, [file_size] |
277 | add edi, 4095 |
278 | add edi, 4095 |
278 | and edi, not 4095 |
279 | and edi, not 4095 |
279 | sub ecx, edi |
280 | sub ecx, edi |
280 | jna @F |
281 | jna @F |
281 | 282 | ||
282 | xor eax, eax |
283 | xor eax, eax |
283 | cld |
284 | cld |
284 | rep stosb |
285 | rep stosb |
285 | @@: |
286 | @@: |
286 | end if |
287 | end if |
287 | 288 | ||
288 | ; release only virtual space, not phisical memory |
289 | ; release only virtual space, not phisical memory |
289 | 290 | ||
290 | stdcall free_kernel_space, [file_base] |
291 | stdcall free_kernel_space, [file_base] |
291 | lea eax, [hdr_cmdline] |
292 | lea eax, [hdr_cmdline] |
292 | lea ebx, [cmdline] |
293 | lea ebx, [cmdline] |
293 | lea ecx, [filename] |
294 | lea ecx, [filename] |
294 | stdcall set_app_params , [slot], eax, ebx, ecx, [flags] |
295 | stdcall set_app_params , [slot], eax, ebx, ecx, [flags] |
295 | 296 | ||
296 | mov eax, [save_proc] |
297 | mov eax, [save_proc] |
297 | call set_cr3 |
298 | call set_cr3 |
298 | 299 | ||
299 | mov eax, [process_number];set result |
300 | mov eax, [process_number];set result |
300 | call unlock_application_table |
301 | call unlock_application_table |
301 | 302 | ||
302 | jmp .final |
303 | jmp .final |
303 | 304 | ||
304 | .failed: |
305 | .failed: |
305 | mov eax, [save_proc] |
306 | mov eax, [save_proc] |
306 | call set_cr3 |
307 | call set_cr3 |
307 | .err: |
308 | .err: |
308 | .err_hdr: |
309 | .err_hdr: |
309 | stdcall kernel_free, [file_base] |
310 | stdcall kernel_free, [file_base] |
310 | .err_file: |
311 | .err_file: |
311 | call unlock_application_table |
312 | call unlock_application_table |
312 | mov eax, esi |
313 | mov eax, esi |
313 | .final: |
314 | .final: |
314 | cmp [SCR_MODE], word 0x13 |
315 | cmp [SCR_MODE], word 0x13 |
315 | jbe @f |
316 | jbe @f |
316 | pushad |
317 | pushad |
317 | stdcall set_cursor, [handle] |
318 | stdcall set_cursor, [handle] |
318 | mov [redrawmouse_unconditional], 1 |
319 | mov [redrawmouse_unconditional], 1 |
319 | call wakeup_osloop |
320 | call wakeup_osloop |
320 | popad |
321 | popad |
321 | @@: |
322 | @@: |
322 | ret |
323 | ret |
323 | endp |
324 | endp |
324 | 325 | ||
325 | align 4 |
326 | align 4 |
326 | test_app_header: |
327 | test_app_header: |
327 | virtual at eax |
328 | virtual at eax |
328 | APP_HEADER_00 APP_HEADER_00_ |
329 | APP_HEADER_00 APP_HEADER_00_ |
329 | end virtual |
330 | end virtual |
330 | virtual at eax |
331 | virtual at eax |
331 | APP_HEADER_01 APP_HEADER_01_ |
332 | APP_HEADER_01 APP_HEADER_01_ |
332 | end virtual |
333 | end virtual |
333 | 334 | ||
334 | cmp dword [eax], 'MENU' |
335 | cmp dword [eax], 'MENU' |
335 | jne .fail |
336 | jne .fail |
336 | cmp word [eax+4], 'ET' |
337 | cmp word [eax+4], 'ET' |
337 | jne .fail |
338 | jne .fail |
338 | 339 | ||
339 | cmp [eax+6], word '00' |
340 | cmp [eax+6], word '00' |
340 | jne .check_01_header |
341 | jne .check_01_header |
341 | 342 | ||
342 | mov ecx, [APP_HEADER_00.start] |
343 | mov ecx, [APP_HEADER_00.start] |
343 | mov [ebx+0x08], ecx ;app_eip |
344 | mov [ebx+0x08], ecx ;app_eip |
344 | mov edx, [APP_HEADER_00.mem_size] |
345 | mov edx, [APP_HEADER_00.mem_size] |
345 | mov [ebx+0x10], edx ;app_mem |
346 | mov [ebx+0x10], edx ;app_mem |
346 | shr edx, 1 |
347 | shr edx, 1 |
347 | sub edx, 0x10 |
348 | sub edx, 0x10 |
348 | mov [ebx+0x0C], edx ;app_esp |
349 | mov [ebx+0x0C], edx ;app_esp |
349 | mov ecx, [APP_HEADER_00.i_param] |
350 | mov ecx, [APP_HEADER_00.i_param] |
350 | mov [ebx], ecx ;app_cmdline |
351 | mov [ebx], ecx ;app_cmdline |
351 | mov [ebx+4], dword 0 ;app_path |
352 | mov [ebx+4], dword 0 ;app_path |
352 | mov edx, [APP_HEADER_00.i_end] |
353 | mov edx, [APP_HEADER_00.i_end] |
353 | mov [ebx+0x14], edx |
354 | mov [ebx+0x14], edx |
354 | ret |
355 | ret |
355 | 356 | ||
356 | .check_01_header: |
357 | .check_01_header: |
357 | 358 | ||
358 | cmp [eax+6], word '01' |
359 | cmp [eax+6], word '01' |
359 | je @f |
360 | je @f |
360 | cmp [eax+6], word '02' |
361 | cmp [eax+6], word '02' |
361 | jne .fail |
362 | jne .fail |
362 | @@: |
363 | @@: |
363 | mov ecx, [APP_HEADER_01.start] |
364 | mov ecx, [APP_HEADER_01.start] |
364 | mov [ebx+0x08], ecx ;app_eip |
365 | mov [ebx+0x08], ecx ;app_eip |
365 | mov edx, [APP_HEADER_01.mem_size] |
366 | mov edx, [APP_HEADER_01.mem_size] |
366 | 367 | ||
367 | ; \begin{diamond}[20.08.2006] |
368 | ; \begin{diamond}[20.08.2006] |
368 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
369 | ; sanity check (functions 19,58 load app_i_end bytes and that must |
369 | ; fit in allocated memory to prevent kernel faults) |
370 | ; fit in allocated memory to prevent kernel faults) |
370 | cmp edx, [APP_HEADER_01.i_end] |
371 | cmp edx, [APP_HEADER_01.i_end] |
371 | jb .fail |
372 | jb .fail |
372 | ; \end{diamond}[20.08.2006] |
373 | ; \end{diamond}[20.08.2006] |
373 | 374 | ||
374 | mov [ebx+0x10], edx ;app_mem |
375 | mov [ebx+0x10], edx ;app_mem |
375 | mov ecx, [APP_HEADER_01.stack_top] |
376 | mov ecx, [APP_HEADER_01.stack_top] |
376 | mov [ebx+0x0C], ecx ;app_esp |
377 | mov [ebx+0x0C], ecx ;app_esp |
377 | mov edx, [APP_HEADER_01.i_param] |
378 | mov edx, [APP_HEADER_01.i_param] |
378 | mov [ebx], edx ;app_cmdline |
379 | mov [ebx], edx ;app_cmdline |
379 | mov ecx, [APP_HEADER_01.i_icon] |
380 | mov ecx, [APP_HEADER_01.i_icon] |
380 | mov [ebx+4], ecx ;app_path |
381 | mov [ebx+4], ecx ;app_path |
381 | mov edx, [APP_HEADER_01.i_end] |
382 | mov edx, [APP_HEADER_01.i_end] |
382 | mov [ebx+0x14], edx |
383 | mov [ebx+0x14], edx |
383 | ret |
384 | ret |
384 | .fail: |
385 | .fail: |
385 | xor eax, eax |
386 | xor eax, eax |
386 | ret |
387 | ret |
387 | 388 | ||
388 | 389 | ||
389 | align 4 |
390 | align 4 |
390 | alloc_thread_slot: |
391 | alloc_thread_slot: |
391 | ;input: |
392 | ;input: |
392 | ; none |
393 | ; none |
393 | ;result: |
394 | ;result: |
394 | ; eax=[new_thread_slot]<>0 - ok |
395 | ; eax=[new_thread_slot]<>0 - ok |
395 | ; 0 - failed. |
396 | ; 0 - failed. |
396 | ;This function find least empty slot. |
397 | ;This function find least empty slot. |
397 | ;It doesn't increase [TASK_COUNT]! |
398 | ;It doesn't increase [TASK_COUNT]! |
398 | 399 | ||
399 | 400 | ||
400 | mov edx, thr_slot_map |
401 | mov edx, thr_slot_map |
401 | pushfd |
402 | pushfd |
402 | cli |
403 | cli |
403 | .l1: |
404 | .l1: |
404 | bsf eax, [edx] |
405 | bsf eax, [edx] |
405 | jnz .found |
406 | jnz .found |
406 | add edx, 4 |
407 | add edx, 4 |
407 | cmp edx, thr_slot_map+32 |
408 | cmp edx, thr_slot_map+32 |
408 | jb .l1 |
409 | jb .l1 |
409 | 410 | ||
410 | popfd |
411 | popfd |
411 | xor eax, eax |
412 | xor eax, eax |
412 | ret |
413 | ret |
413 | .found: |
414 | .found: |
414 | btr [edx], eax |
415 | btr [edx], eax |
415 | sub edx, thr_slot_map |
416 | sub edx, thr_slot_map |
416 | lea eax, [eax+edx*8] |
417 | lea eax, [eax+edx*8] |
417 | popfd |
418 | popfd |
418 | ret |
419 | ret |
419 | 420 | ||
420 | 421 | ||
421 | align 4 |
422 | align 4 |
422 | proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword |
423 | proc create_process stdcall, app_size:dword,img_base:dword,img_size:dword |
423 | locals |
424 | locals |
424 | app_pages dd ? |
425 | app_pages dd ? |
425 | img_pages dd ? |
426 | img_pages dd ? |
426 | process dd ? |
427 | process dd ? |
427 | app_tabs dd ? |
428 | app_tabs dd ? |
428 | endl |
429 | endl |
429 | 430 | ||
430 | mov ecx, pg_data.mutex |
431 | mov ecx, pg_data.mutex |
431 | call mutex_lock |
432 | call mutex_lock |
432 | 433 | ||
433 | xchg bx, bx |
434 | xchg bx, bx |
434 | 435 | ||
435 | xor eax, eax |
436 | xor eax, eax |
436 | mov [process], eax |
437 | mov [process], eax |
437 | 438 | ||
438 | mov eax, [app_size] |
439 | mov eax, [app_size] |
439 | add eax, 4095 |
440 | add eax, 4095 |
440 | and eax, NOT(4095) |
441 | and eax, NOT(4095) |
441 | mov [app_size], eax |
442 | mov [app_size], eax |
442 | mov ebx, eax |
443 | mov ebx, eax |
443 | shr eax, 12 |
444 | shr eax, 12 |
444 | mov [app_pages], eax |
445 | mov [app_pages], eax |
445 | 446 | ||
446 | add ebx, 0x3FFFFF |
447 | add ebx, 0x3FFFFF |
447 | and ebx, NOT(0x3FFFFF) |
448 | and ebx, NOT(0x3FFFFF) |
448 | shr ebx, 22 |
449 | shr ebx, 22 |
449 | mov [app_tabs], ebx |
450 | mov [app_tabs], ebx |
450 | 451 | ||
451 | mov ecx, [img_size] |
452 | mov ecx, [img_size] |
452 | add ecx, 4095 |
453 | add ecx, 4095 |
453 | and ecx, NOT(4095) |
454 | and ecx, NOT(4095) |
454 | 455 | ||
455 | mov [img_size], ecx |
456 | mov [img_size], ecx |
456 | shr ecx, 12 |
457 | shr ecx, 12 |
457 | mov [img_pages], ecx |
458 | mov [img_pages], ecx |
458 | 459 | ||
459 | lea eax, [eax+ebx+2];all requested memory |
460 | lea eax, [eax+ebx+2];all requested memory |
460 | 461 | ||
461 | cmp eax, [pg_data.pages_free] |
462 | cmp eax, [pg_data.pages_free] |
462 | ja .fail |
463 | ja .fail |
463 | 464 | ||
464 | stdcall kernel_alloc, 0x2000 |
465 | stdcall kernel_alloc, 0x2000 |
465 | test eax, eax |
466 | test eax, eax |
466 | jz .fail |
467 | jz .fail |
467 | mov [process], eax |
468 | mov [process], eax |
468 | 469 | ||
469 | lea edi, [eax+PROC.heap_lock] |
470 | lea edi, [eax+PROC.heap_lock] |
470 | mov ecx, (4096-PROC.heap_lock)/4 |
471 | mov ecx, (4096-PROC.heap_lock)/4 |
471 | 472 | ||
472 | list_init eax |
473 | list_init eax |
473 | add eax, PROC.thr_list |
474 | add eax, PROC.thr_list |
474 | list_init eax |
475 | list_init eax |
475 | 476 | ||
476 | xor eax, eax |
477 | xor eax, eax |
477 | cld |
478 | cld |
478 | rep stosd |
479 | rep stosd |
479 | 480 | ||
480 | mov eax, edi |
481 | mov eax, edi |
481 | call get_pg_addr |
482 | call get_pg_addr |
482 | mov [edi-4096+PROC.pdt_0_phys], eax |
483 | mov [edi-4096+PROC.pdt_0_phys], eax |
483 | 484 | ||
484 | mov ecx, (OS_BASE shr 20)/4 |
485 | mov ecx, (OS_BASE shr 20)/4 |
485 | xor eax, eax |
486 | xor eax, eax |
486 | rep stosd |
487 | rep stosd |
487 | 488 | ||
488 | mov ecx, (OS_BASE shr 20)/4 |
489 | mov ecx, (OS_BASE shr 20)/4 |
489 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
490 | mov esi, sys_proc+PROC.pdt_0+(OS_BASE shr 20) |
490 | rep movsd |
491 | rep movsd |
491 | 492 | ||
492 | mov eax, [edi-8192+PROC.pdt_0_phys] |
493 | mov eax, [edi-8192+PROC.pdt_0_phys] |
493 | or eax, PG_SW |
494 | or eax, PG_SW |
494 | mov [edi-4096+(page_tabs shr 20)], eax |
495 | mov [edi-4096+(page_tabs shr 20)], eax |
495 | 496 | ||
496 | lea eax, [edi-8192] |
497 | lea eax, [edi-8192] |
497 | call set_cr3 |
498 | call set_cr3 |
498 | 499 | ||
499 | mov edx, [app_tabs] |
500 | mov edx, [app_tabs] |
500 | xor edi, edi |
501 | xor edi, edi |
501 | @@: |
502 | @@: |
502 | call alloc_page |
503 | call alloc_page |
503 | test eax, eax |
504 | test eax, eax |
504 | jz .fail |
505 | jz .fail |
505 | 506 | ||
506 | stdcall map_page_table, edi, eax |
507 | stdcall map_page_table, edi, eax |
507 | add edi, 0x00400000 |
508 | add edi, 0x00400000 |
508 | dec edx |
509 | dec edx |
509 | jnz @B |
510 | jnz @B |
510 | 511 | ||
511 | mov edi, page_tabs |
512 | mov edi, page_tabs |
512 | 513 | ||
513 | mov ecx, [app_tabs] |
514 | mov ecx, [app_tabs] |
514 | shl ecx, 10 |
515 | shl ecx, 10 |
515 | xor eax, eax |
516 | xor eax, eax |
516 | rep stosd |
517 | rep stosd |
517 | 518 | ||
518 | mov ecx, [img_pages] |
519 | mov ecx, [img_pages] |
519 | mov ebx, PG_UW |
520 | mov ebx, PG_UW |
520 | xor edx, edx |
521 | xor edx, edx |
521 | mov esi, [img_base] |
522 | mov esi, [img_base] |
522 | shr esi, 10 |
523 | shr esi, 10 |
523 | add esi, page_tabs |
524 | add esi, page_tabs |
524 | mov edi, page_tabs |
525 | mov edi, page_tabs |
525 | .remap: |
526 | .remap: |
526 | lodsd |
527 | lodsd |
527 | and eax, 0xFFFFF000 |
528 | and eax, 0xFFFFF000 |
528 | or eax, ebx; force user level r/w access |
529 | or eax, ebx; force user level r/w access |
529 | stosd |
530 | stosd |
530 | add edx, 0x1000 |
531 | add edx, 0x1000 |
531 | dec [app_pages] |
532 | dec [app_pages] |
532 | dec ecx |
533 | dec ecx |
533 | jnz .remap |
534 | jnz .remap |
534 | 535 | ||
535 | mov ecx, [app_pages] |
536 | mov ecx, [app_pages] |
536 | test ecx, ecx |
537 | test ecx, ecx |
537 | jz .done |
538 | jz .done |
538 | 539 | ||
539 | .alloc: |
540 | .alloc: |
540 | call alloc_page |
541 | call alloc_page |
541 | test eax, eax |
542 | test eax, eax |
542 | jz .fail |
543 | jz .fail |
543 | 544 | ||
544 | stdcall map_page, edx, eax, dword PG_UW |
545 | stdcall map_page, edx, eax, dword PG_UW |
545 | add edx, 0x1000 |
546 | add edx, 0x1000 |
546 | dec [app_pages] |
547 | dec [app_pages] |
547 | jnz .alloc |
548 | jnz .alloc |
548 | 549 | ||
549 | .done: |
550 | .done: |
550 | mov ecx, pg_data.mutex |
551 | mov ecx, pg_data.mutex |
551 | call mutex_unlock |
552 | call mutex_unlock |
552 | mov eax, [process] |
553 | mov eax, [process] |
553 | ret |
554 | ret |
554 | .fail: |
555 | .fail: |
555 | mov ecx, pg_data.mutex |
556 | mov ecx, pg_data.mutex |
556 | call mutex_unlock |
557 | call mutex_unlock |
557 | cmp [process], 0 |
558 | cmp [process], 0 |
558 | je @f |
559 | je @f |
559 | ;; stdcall destroy_app_space, [dir_addr], 0 |
560 | ;; stdcall destroy_app_space, [dir_addr], 0 |
560 | @@: |
561 | @@: |
561 | xor eax, eax |
562 | xor eax, eax |
562 | ret |
563 | ret |
563 | endp |
564 | endp |
564 | 565 | ||
565 | align 4 |
566 | align 4 |
566 | set_cr3: |
567 | set_cr3: |
567 | 568 | ||
568 | mov ebx, [current_slot] |
569 | mov ebx, [current_slot] |
569 | mov [ebx+APPDATA.process], eax |
570 | mov [ebx+APPDATA.process], eax |
570 | mov eax, [eax+PROC.pdt_0_phys] |
571 | mov eax, [eax+PROC.pdt_0_phys] |
571 | mov cr3, eax |
572 | mov cr3, eax |
572 | ret |
573 | ret |
573 | 574 | ||
574 | align 4 |
575 | align 4 |
575 | proc destroy_page_table stdcall, pg_tab:dword |
576 | proc destroy_page_table stdcall, pg_tab:dword |
576 | 577 | ||
577 | push esi |
578 | push esi |
578 | 579 | ||
579 | mov esi, [pg_tab] |
580 | mov esi, [pg_tab] |
580 | mov ecx, 1024 |
581 | mov ecx, 1024 |
581 | .free: |
582 | .free: |
582 | mov eax, [esi] |
583 | mov eax, [esi] |
583 | test eax, 1 |
584 | test eax, 1 |
584 | jz .next |
585 | jz .next |
585 | test eax, 1 shl 9 |
586 | test eax, 1 shl 9 |
586 | jnz .next ;skip shared pages |
587 | jnz .next ;skip shared pages |
587 | call free_page |
588 | call free_page |
588 | .next: |
589 | .next: |
589 | add esi, 4 |
590 | add esi, 4 |
590 | dec ecx |
591 | dec ecx |
591 | jnz .free |
592 | jnz .free |
592 | pop esi |
593 | pop esi |
593 | ret |
594 | ret |
594 | endp |
595 | endp |
595 | 596 | ||
596 | align 4 |
597 | align 4 |
597 | proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword |
598 | proc destroy_app_space stdcall, pg_dir:dword, dlls_list:dword |
598 | 599 | ||
599 | xor edx, edx |
600 | xor edx, edx |
600 | push edx |
601 | push edx |
601 | mov eax, 0x1 |
602 | mov eax, 0x1 |
602 | mov ebx, [pg_dir] |
603 | mov ebx, [pg_dir] |
603 | .loop: |
604 | .loop: |
604 | ;eax = current slot of process |
605 | ;eax = current slot of process |
605 | mov ecx, eax |
606 | mov ecx, eax |
606 | shl ecx, 5 |
607 | shl ecx, 5 |
607 | cmp byte [CURRENT_TASK+ecx+0xa], 9;if process running? |
608 | cmp byte [CURRENT_TASK+ecx+0xa], 9;if process running? |
608 | jz @f ;skip empty slots |
609 | jz @f ;skip empty slots |
609 | shl ecx, 3 |
610 | shl ecx, 3 |
610 | add ecx, SLOT_BASE |
611 | add ecx, SLOT_BASE |
611 | cmp [ecx+APPDATA.process], ebx;compare page directory addresses |
612 | cmp [ecx+APPDATA.process], ebx;compare page directory addresses |
612 | jnz @f |
613 | jnz @f |
613 | mov [ebp-4], ecx |
614 | mov [ebp-4], ecx |
614 | inc edx ;thread found |
615 | inc edx ;thread found |
615 | @@: |
616 | @@: |
616 | inc eax |
617 | inc eax |
617 | cmp eax, [TASK_COUNT] ;exit loop if we look through all processes |
618 | cmp eax, [TASK_COUNT] ;exit loop if we look through all processes |
618 | jle .loop |
619 | jle .loop |
619 | 620 | ||
620 | ;edx = number of threads |
621 | ;edx = number of threads |
621 | ;our process is zombi so it isn't counted |
622 | ;our process is zombi so it isn't counted |
622 | pop ecx |
623 | pop ecx |
623 | cmp edx, 1 |
624 | cmp edx, 1 |
624 | jg .ret |
625 | jg .ret |
625 | ;if there isn't threads then clear memory. |
626 | ;if there isn't threads then clear memory. |
626 | mov esi, [dlls_list] |
627 | mov esi, [dlls_list] |
627 | call destroy_all_hdlls;ecx=APPDATA |
628 | call destroy_all_hdlls;ecx=APPDATA |
628 | 629 | ||
629 | mov ecx, pg_data.mutex |
630 | mov ecx, pg_data.mutex |
630 | call mutex_lock |
631 | call mutex_lock |
631 | 632 | ||
632 | mov eax, [pg_dir] |
633 | mov eax, [pg_dir] |
633 | and eax, not 0xFFF |
634 | and eax, not 0xFFF |
634 | ; stdcall map_page, [tmp_task_pdir], eax, PG_SW |
635 | ; stdcall map_page, [tmp_task_pdir], eax, PG_SW |
635 | ; mov esi, [tmp_task_pdir] |
636 | ; mov esi, [tmp_task_pdir] |
636 | mov edi, (OS_BASE shr 20)/4 |
637 | mov edi, (OS_BASE shr 20)/4 |
637 | .destroy: |
638 | .destroy: |
638 | mov eax, [esi] |
639 | mov eax, [esi] |
639 | test eax, 1 |
640 | test eax, 1 |
640 | jz .next |
641 | jz .next |
641 | and eax, not 0xFFF |
642 | and eax, not 0xFFF |
642 | stdcall map_page, [tmp_task_ptab], eax, PG_SW |
643 | stdcall map_page, [tmp_task_ptab], eax, PG_SW |
643 | stdcall destroy_page_table, [tmp_task_ptab] |
644 | stdcall destroy_page_table, [tmp_task_ptab] |
644 | mov eax, [esi] |
645 | mov eax, [esi] |
645 | call free_page |
646 | call free_page |
646 | .next: |
647 | .next: |
647 | add esi, 4 |
648 | add esi, 4 |
648 | dec edi |
649 | dec edi |
649 | jnz .destroy |
650 | jnz .destroy |
650 | 651 | ||
651 | mov eax, [pg_dir] |
652 | mov eax, [pg_dir] |
652 | call free_page |
653 | call free_page |
653 | .exit: |
654 | .exit: |
654 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
655 | stdcall map_page, [tmp_task_ptab], 0, PG_UNMAP |
655 | ; stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP |
656 | ; stdcall map_page, [tmp_task_pdir], 0, PG_UNMAP |
656 | mov ecx, pg_data.mutex |
657 | mov ecx, pg_data.mutex |
657 | call mutex_unlock |
658 | call mutex_unlock |
658 | .ret: |
659 | .ret: |
659 | ret |
660 | ret |
660 | endp |
661 | endp |
661 | 662 | ||
662 | align 4 |
663 | align 4 |
663 | get_pid: |
664 | get_pid: |
664 | mov eax, [TASK_BASE] |
665 | mov eax, [TASK_BASE] |
665 | mov eax, [eax+TASKDATA.pid] |
666 | mov eax, [eax+TASKDATA.pid] |
666 | ret |
667 | ret |
667 | 668 | ||
668 | pid_to_slot: |
669 | pid_to_slot: |
669 | ;Input: |
670 | ;Input: |
670 | ; eax - pid of process |
671 | ; eax - pid of process |
671 | ;Output: |
672 | ;Output: |
672 | ; eax - slot of process or 0 if process don't exists |
673 | ; eax - slot of process or 0 if process don't exists |
673 | ;Search process by PID. |
674 | ;Search process by PID. |
674 | push ebx |
675 | push ebx |
675 | push ecx |
676 | push ecx |
676 | mov ebx, [TASK_COUNT] |
677 | mov ebx, [TASK_COUNT] |
677 | shl ebx, 5 |
678 | shl ebx, 5 |
678 | mov ecx, 2*32 |
679 | mov ecx, 2*32 |
679 | 680 | ||
680 | .loop: |
681 | .loop: |
681 | ;ecx=offset of current process info entry |
682 | ;ecx=offset of current process info entry |
682 | ;ebx=maximum permitted offset |
683 | ;ebx=maximum permitted offset |
683 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
684 | cmp byte [CURRENT_TASK+ecx+0xa], 9 |
684 | jz .endloop ;skip empty slots |
685 | jz .endloop ;skip empty slots |
685 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
686 | cmp [CURRENT_TASK+ecx+0x4], eax;check PID |
686 | jz .pid_found |
687 | jz .pid_found |
687 | .endloop: |
688 | .endloop: |
688 | add ecx, 32 |
689 | add ecx, 32 |
689 | cmp ecx, ebx |
690 | cmp ecx, ebx |
690 | jle .loop |
691 | jle .loop |
691 | 692 | ||
692 | pop ecx |
693 | pop ecx |
693 | pop ebx |
694 | pop ebx |
694 | xor eax, eax |
695 | xor eax, eax |
695 | ret |
696 | ret |
696 | 697 | ||
697 | .pid_found: |
698 | .pid_found: |
698 | shr ecx, 5 |
699 | shr ecx, 5 |
699 | mov eax, ecx ;convert offset to index of slot |
700 | mov eax, ecx ;convert offset to index of slot |
700 | pop ecx |
701 | pop ecx |
701 | pop ebx |
702 | pop ebx |
702 | ret |
703 | ret |
703 | 704 | ||
704 | check_region: |
705 | check_region: |
705 | ;input: |
706 | ;input: |
706 | ; esi - start of buffer |
707 | ; esi - start of buffer |
707 | ; edx - size of buffer |
708 | ; edx - size of buffer |
708 | ;result: |
709 | ;result: |
709 | ; eax = 1 region lays in app memory |
710 | ; eax = 1 region lays in app memory |
710 | ; eax = 0 region don't lays in app memory |
711 | ; eax = 0 region don't lays in app memory |
711 | mov eax, [CURRENT_TASK] |
712 | mov eax, [CURRENT_TASK] |
712 | ; jmp check_process_region |
713 | ; jmp check_process_region |
713 | ;----------------------------------------------------------------------------- |
714 | ;----------------------------------------------------------------------------- |
714 | ;check_process_region: |
715 | ;check_process_region: |
715 | ;input: |
716 | ;input: |
716 | ; eax - slot |
717 | ; eax - slot |
717 | ; esi - start of buffer |
718 | ; esi - start of buffer |
718 | ; edx - size of buffer |
719 | ; edx - size of buffer |
719 | ;result: |
720 | ;result: |
720 | ; eax = 1 region lays in app memory |
721 | ; eax = 1 region lays in app memory |
721 | ; eax = 0 region don't lays in app memory |
722 | ; eax = 0 region don't lays in app memory |
722 | 723 | ||
723 | test edx, edx |
724 | test edx, edx |
724 | jle .ok |
725 | jle .ok |
725 | shl eax, 5 |
726 | shl eax, 5 |
726 | cmp word [CURRENT_TASK+eax+0xa], 0 |
727 | cmp word [CURRENT_TASK+eax+0xa], 0 |
727 | jnz .failed |
728 | jnz .failed |
728 | shl eax, 3 |
729 | shl eax, 3 |
729 | mov eax, [SLOT_BASE+eax+0xb8] |
730 | mov eax, [SLOT_BASE+eax+0xb8] |
730 | test eax, eax |
731 | test eax, eax |
731 | jz .failed |
732 | jz .failed |
732 | 733 | ||
733 | mov eax, 1 |
734 | mov eax, 1 |
734 | ret |
735 | ret |
735 | 736 | ||
736 | 737 | ||
737 | ; call MEM_Get_Linear_Address |
738 | ; call MEM_Get_Linear_Address |
738 | ; push ebx |
739 | ; push ebx |
739 | ; push ecx |
740 | ; push ecx |
740 | ; push edx |
741 | ; push edx |
741 | ; mov edx,ebx |
742 | ; mov edx,ebx |
742 | ; and edx,not (4096-1) |
743 | ; and edx,not (4096-1) |
743 | ; sub ebx,edx |
744 | ; sub ebx,edx |
744 | ; add ecx,ebx |
745 | ; add ecx,ebx |
745 | ; mov ebx,edx |
746 | ; mov ebx,edx |
746 | ; add ecx,(4096-1) |
747 | ; add ecx,(4096-1) |
747 | ; and ecx,not (4096-1) |
748 | ; and ecx,not (4096-1) |
748 | ;.loop: |
749 | ;.loop: |
749 | ;;eax - linear address of page directory |
750 | ;;eax - linear address of page directory |
750 | ;;ebx - current page |
751 | ;;ebx - current page |
751 | ;;ecx - current size |
752 | ;;ecx - current size |
752 | ; mov edx,ebx |
753 | ; mov edx,ebx |
753 | ; shr edx,22 |
754 | ; shr edx,22 |
754 | ; mov edx,[eax+4*edx] |
755 | ; mov edx,[eax+4*edx] |
755 | ; and edx,not (4096-1) |
756 | ; and edx,not (4096-1) |
756 | ; test edx,edx |
757 | ; test edx,edx |
757 | ; jz .failed1 |
758 | ; jz .failed1 |
758 | ; push eax |
759 | ; push eax |
759 | ; mov eax,edx |
760 | ; mov eax,edx |
760 | ; call MEM_Get_Linear_Address |
761 | ; call MEM_Get_Linear_Address |
761 | ; mov edx,ebx |
762 | ; mov edx,ebx |
762 | ; shr edx,12 |
763 | ; shr edx,12 |
763 | ; and edx,(1024-1) |
764 | ; and edx,(1024-1) |
764 | ; mov eax,[eax+4*edx] |
765 | ; mov eax,[eax+4*edx] |
765 | ; and eax,not (4096-1) |
766 | ; and eax,not (4096-1) |
766 | ; test eax,eax |
767 | ; test eax,eax |
767 | ; pop eax |
768 | ; pop eax |
768 | ; jz .failed1 |
769 | ; jz .failed1 |
769 | ; add ebx,4096 |
770 | ; add ebx,4096 |
770 | ; sub ecx,4096 |
771 | ; sub ecx,4096 |
771 | ; jg .loop |
772 | ; jg .loop |
772 | ; pop edx |
773 | ; pop edx |
773 | ; pop ecx |
774 | ; pop ecx |
774 | ; pop ebx |
775 | ; pop ebx |
775 | .ok: |
776 | .ok: |
776 | mov eax, 1 |
777 | mov eax, 1 |
777 | ret |
778 | ret |
778 | ; |
779 | ; |
779 | ;.failed1: |
780 | ;.failed1: |
780 | ; pop edx |
781 | ; pop edx |
781 | ; pop ecx |
782 | ; pop ecx |
782 | ; pop ebx |
783 | ; pop ebx |
783 | .failed: |
784 | .failed: |
784 | xor eax, eax |
785 | xor eax, eax |
785 | ret |
786 | ret |
786 | 787 | ||
787 | align 4 |
788 | align 4 |
788 | proc read_process_memory |
789 | proc read_process_memory |
789 | ;Input: |
790 | ;Input: |
790 | ; eax - process slot |
791 | ; eax - process slot |
791 | ; ecx - buffer address |
792 | ; ecx - buffer address |
792 | ; edx - buffer size |
793 | ; edx - buffer size |
793 | ; esi - start address in other process |
794 | ; esi - start address in other process |
794 | ;Output: |
795 | ;Output: |
795 | ; eax - number of bytes read. |
796 | ; eax - number of bytes read. |
796 | locals |
797 | locals |
797 | slot dd ? |
798 | slot dd ? |
798 | buff dd ? |
799 | buff dd ? |
799 | r_count dd ? |
800 | r_count dd ? |
800 | offset dd ? |
801 | offset dd ? |
801 | tmp_r_cnt dd ? |
802 | tmp_r_cnt dd ? |
802 | endl |
803 | endl |
803 | 804 | ||
804 | mov [slot], eax |
805 | mov [slot], eax |
805 | mov [buff], ecx |
806 | mov [buff], ecx |
806 | and [r_count], 0 |
807 | and [r_count], 0 |
807 | mov [tmp_r_cnt], edx |
808 | mov [tmp_r_cnt], edx |
808 | mov [offset], esi |
809 | mov [offset], esi |
809 | 810 | ||
810 | pushad |
811 | pushad |
811 | .read_mem: |
812 | .read_mem: |
812 | mov edx, [offset] |
813 | mov edx, [offset] |
813 | mov ebx, [tmp_r_cnt] |
814 | mov ebx, [tmp_r_cnt] |
814 | 815 | ||
815 | mov ecx, 0x400000 |
816 | mov ecx, 0x400000 |
816 | and edx, 0x3FFFFF |
817 | and edx, 0x3FFFFF |
817 | sub ecx, edx |
818 | sub ecx, edx |
818 | cmp ecx, ebx |
819 | cmp ecx, ebx |
819 | jbe @f |
820 | jbe @f |
820 | mov ecx, ebx |
821 | mov ecx, ebx |
821 | @@: |
822 | @@: |
822 | cmp ecx, 0x8000 |
823 | cmp ecx, 0x8000 |
823 | jna @F |
824 | jna @F |
824 | mov ecx, 0x8000 |
825 | mov ecx, 0x8000 |
825 | @@: |
826 | @@: |
826 | mov ebx, [offset] |
827 | mov ebx, [offset] |
827 | 828 | ||
828 | push ecx |
829 | push ecx |
829 | stdcall map_memEx, [proc_mem_map], \ |
830 | stdcall map_memEx, [proc_mem_map], \ |
830 | [slot], ebx, ecx, PG_MAP |
831 | [slot], ebx, ecx, PG_MAP |
831 | pop ecx |
832 | pop ecx |
832 | 833 | ||
833 | mov esi, [offset] |
834 | mov esi, [offset] |
834 | and esi, 0xfff |
835 | and esi, 0xfff |
835 | sub eax, esi |
836 | sub eax, esi |
836 | jbe .ret |
837 | jbe .ret |
837 | cmp ecx, eax |
838 | cmp ecx, eax |
838 | jbe @f |
839 | jbe @f |
839 | mov ecx, eax |
840 | mov ecx, eax |
840 | mov [tmp_r_cnt], eax |
841 | mov [tmp_r_cnt], eax |
841 | @@: |
842 | @@: |
842 | add esi, [proc_mem_map] |
843 | add esi, [proc_mem_map] |
843 | mov edi, [buff] |
844 | mov edi, [buff] |
844 | mov edx, ecx |
845 | mov edx, ecx |
845 | rep movsb |
846 | rep movsb |
846 | add [r_count], edx |
847 | add [r_count], edx |
847 | 848 | ||
848 | add [offset], edx |
849 | add [offset], edx |
849 | sub [tmp_r_cnt], edx |
850 | sub [tmp_r_cnt], edx |
850 | jnz .read_mem |
851 | jnz .read_mem |
851 | .ret: |
852 | .ret: |
852 | popad |
853 | popad |
853 | mov eax, [r_count] |
854 | mov eax, [r_count] |
854 | ret |
855 | ret |
855 | endp |
856 | endp |
856 | 857 | ||
857 | align 4 |
858 | align 4 |
858 | proc write_process_memory |
859 | proc write_process_memory |
859 | ;Input: |
860 | ;Input: |
860 | ; eax - process slot |
861 | ; eax - process slot |
861 | ; ecx - buffer address |
862 | ; ecx - buffer address |
862 | ; edx - buffer size |
863 | ; edx - buffer size |
863 | ; esi - start address in other process |
864 | ; esi - start address in other process |
864 | ;Output: |
865 | ;Output: |
865 | ; eax - number of bytes written |
866 | ; eax - number of bytes written |
866 | 867 | ||
867 | locals |
868 | locals |
868 | slot dd ? |
869 | slot dd ? |
869 | buff dd ? |
870 | buff dd ? |
870 | w_count dd ? |
871 | w_count dd ? |
871 | offset dd ? |
872 | offset dd ? |
872 | tmp_w_cnt dd ? |
873 | tmp_w_cnt dd ? |
873 | endl |
874 | endl |
874 | 875 | ||
875 | mov [slot], eax |
876 | mov [slot], eax |
876 | mov [buff], ecx |
877 | mov [buff], ecx |
877 | and [w_count], 0 |
878 | and [w_count], 0 |
878 | mov [tmp_w_cnt], edx |
879 | mov [tmp_w_cnt], edx |
879 | mov [offset], esi |
880 | mov [offset], esi |
880 | 881 | ||
881 | pushad |
882 | pushad |
882 | .read_mem: |
883 | .read_mem: |
883 | mov edx, [offset] |
884 | mov edx, [offset] |
884 | mov ebx, [tmp_w_cnt] |
885 | mov ebx, [tmp_w_cnt] |
885 | 886 | ||
886 | mov ecx, 0x400000 |
887 | mov ecx, 0x400000 |
887 | and edx, 0x3FFFFF |
888 | and edx, 0x3FFFFF |
888 | sub ecx, edx |
889 | sub ecx, edx |
889 | cmp ecx, ebx |
890 | cmp ecx, ebx |
890 | jbe @f |
891 | jbe @f |
891 | mov ecx, ebx |
892 | mov ecx, ebx |
892 | @@: |
893 | @@: |
893 | cmp ecx, 0x8000 |
894 | cmp ecx, 0x8000 |
894 | jna @F |
895 | jna @F |
895 | mov ecx, 0x8000 |
896 | mov ecx, 0x8000 |
896 | @@: |
897 | @@: |
897 | mov ebx, [offset] |
898 | mov ebx, [offset] |
898 | ; add ebx, new_app_base |
899 | ; add ebx, new_app_base |
899 | push ecx |
900 | push ecx |
900 | stdcall map_memEx, [proc_mem_map], \ |
901 | stdcall map_memEx, [proc_mem_map], \ |
901 | [slot], ebx, ecx, PG_SW |
902 | [slot], ebx, ecx, PG_SW |
902 | pop ecx |
903 | pop ecx |
903 | 904 | ||
904 | mov edi, [offset] |
905 | mov edi, [offset] |
905 | and edi, 0xfff |
906 | and edi, 0xfff |
906 | sub eax, edi |
907 | sub eax, edi |
907 | jbe .ret |
908 | jbe .ret |
908 | cmp ecx, eax |
909 | cmp ecx, eax |
909 | jbe @f |
910 | jbe @f |
910 | mov ecx, eax |
911 | mov ecx, eax |
911 | mov [tmp_w_cnt], eax |
912 | mov [tmp_w_cnt], eax |
912 | @@: |
913 | @@: |
913 | add edi, [proc_mem_map] |
914 | add edi, [proc_mem_map] |
914 | mov esi, [buff] |
915 | mov esi, [buff] |
915 | mov edx, ecx |
916 | mov edx, ecx |
916 | rep movsb |
917 | rep movsb |
917 | 918 | ||
918 | add [w_count], edx |
919 | add [w_count], edx |
919 | add [offset], edx |
920 | add [offset], edx |
920 | sub [tmp_w_cnt], edx |
921 | sub [tmp_w_cnt], edx |
921 | jnz .read_mem |
922 | jnz .read_mem |
922 | .ret: |
923 | .ret: |
923 | popad |
924 | popad |
924 | mov eax, [w_count] |
925 | mov eax, [w_count] |
925 | ret |
926 | ret |
926 | endp |
927 | endp |
927 | 928 | ||
928 | ;ebx = 1 - kernel thread |
929 | ;ebx = 1 - kernel thread |
929 | ;ecx=thread entry point |
930 | ;ecx=thread entry point |
930 | ;edx=thread stack pointer |
931 | ;edx=thread stack pointer |
931 | ;creation flags 0x01 - debugged |
932 | ;creation flags 0x01 - debugged |
932 | ; 0x02 - kernel |
933 | ; 0x02 - kernel |
933 | 934 | ||
934 | align 4 |
935 | align 4 |
935 | proc new_sys_threads |
936 | proc new_sys_threads |
936 | locals |
937 | locals |
937 | slot dd ? |
938 | slot dd ? |
938 | flags dd ? |
939 | flags dd ? |
939 | app_cmdline dd ? ;0x00 |
940 | app_cmdline dd ? ;0x00 |
940 | app_path dd ? ;0x04 |
941 | app_path dd ? ;0x04 |
941 | app_eip dd ? ;0x08 |
942 | app_eip dd ? ;0x08 |
942 | app_esp dd ? ;0x0C |
943 | app_esp dd ? ;0x0C |
943 | app_mem dd ? ;0x10 |
944 | app_mem dd ? ;0x10 |
944 | endl |
945 | endl |
945 | 946 | ||
946 | shl ebx, 1 |
947 | shl ebx, 1 |
947 | mov [flags], ebx |
948 | mov [flags], ebx |
948 | 949 | ||
949 | xor eax, eax |
950 | xor eax, eax |
950 | mov [app_eip], ecx |
951 | mov [app_eip], ecx |
951 | mov [app_cmdline], eax |
952 | mov [app_cmdline], eax |
952 | mov [app_esp], edx |
953 | mov [app_esp], edx |
953 | mov [app_path], eax |
954 | mov [app_path], eax |
954 | 955 | ||
955 | call lock_application_table |
956 | call lock_application_table |
956 | 957 | ||
957 | call alloc_thread_slot |
958 | call alloc_thread_slot |
958 | test eax, eax |
959 | test eax, eax |
959 | jz .failed |
960 | jz .failed |
960 | 961 | ||
961 | mov [slot], eax |
962 | mov [slot], eax |
962 | 963 | ||
963 | mov esi, [current_slot] |
964 | mov esi, [current_slot] |
964 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
965 | mov ebx, esi ;ebx=esi - pointer to extended information about current thread |
965 | 966 | ||
966 | mov edi, eax |
967 | mov edi, eax |
967 | shl edi, 8 |
968 | shl edi, 8 |
968 | add edi, SLOT_BASE |
969 | add edi, SLOT_BASE |
969 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
970 | mov edx, edi ;edx=edi - pointer to extended infomation about new thread |
970 | mov ecx, 256/4 |
971 | mov ecx, 256/4 |
971 | xor eax, eax |
972 | xor eax, eax |
972 | cld |
973 | cld |
973 | rep stosd ;clean extended information about new thread |
974 | rep stosd ;clean extended information about new thread |
974 | mov esi, ebx |
975 | mov esi, ebx |
975 | mov edi, edx |
976 | mov edi, edx |
976 | mov ecx, 11 |
977 | mov ecx, 11 |
977 | rep movsb ;copy process name |
978 | rep movsb ;copy process name |
978 | 979 | ||
979 | mov eax, [ebx+APPDATA.heap_base] |
980 | mov eax, [ebx+APPDATA.process] |
980 | mov [edx+APPDATA.heap_base], eax |
- | |
981 | - | ||
982 | mov ecx, [ebx+APPDATA.heap_top] |
- | |
983 | mov [edx+APPDATA.heap_top], ecx |
- | |
984 | - | ||
985 | mov eax, [ebx+APPDATA.mem_size] |
- | |
986 | mov [edx+APPDATA.mem_size], eax |
- | |
987 | - | ||
988 | mov ecx, [ebx+APPDATA.process] |
- | |
989 | mov [edx+APPDATA.process], ecx;copy page directory |
981 | mov [edx+APPDATA.process], eax |
990 | 982 | ||
991 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
983 | mov eax, [ebx+APPDATA.dlls_list_ptr] |
992 | mov [edx+APPDATA.dlls_list_ptr], eax |
984 | mov [edx+APPDATA.dlls_list_ptr], eax |
993 | 985 | ||
994 | mov eax, [ebx+APPDATA.tls_base] |
986 | mov eax, [ebx+APPDATA.tls_base] |
995 | test eax, eax |
987 | test eax, eax |
996 | jz @F |
988 | jz @F |
997 | 989 | ||
998 | push edx |
990 | push edx |
999 | stdcall user_alloc, 4096 |
991 | stdcall user_alloc, 4096 |
1000 | pop edx |
992 | pop edx |
1001 | test eax, eax |
993 | test eax, eax |
1002 | jz .failed1;eax=0 |
994 | jz .failed1;eax=0 |
1003 | @@: |
995 | @@: |
1004 | mov [edx+APPDATA.tls_base], eax |
996 | mov [edx+APPDATA.tls_base], eax |
1005 | 997 | ||
1006 | lea eax, [app_cmdline] |
998 | lea eax, [app_cmdline] |
1007 | stdcall set_app_params , [slot], eax, dword 0, \ |
999 | stdcall set_app_params , [slot], eax, dword 0, \ |
1008 | dword 0, [flags] |
1000 | dword 0, [flags] |
1009 | 1001 | ||
1010 | mov eax, [process_number] ;set result |
1002 | mov eax, [process_number] ;set result |
1011 | call unlock_application_table |
1003 | call unlock_application_table |
1012 | ret |
1004 | ret |
1013 | .failed: |
1005 | .failed: |
1014 | xor eax, eax |
1006 | xor eax, eax |
1015 | .failed1: |
1007 | .failed1: |
1016 | call unlock_application_table |
1008 | call unlock_application_table |
1017 | dec eax ;-1 |
1009 | dec eax ;-1 |
1018 | ret |
1010 | ret |
1019 | endp |
1011 | endp |
1020 | 1012 | ||
1021 | align 4 |
1013 | align 4 |
1022 | tls_app_entry: |
1014 | tls_app_entry: |
1023 | 1015 | ||
1024 | call init_heap |
1016 | call init_heap |
1025 | stdcall user_alloc, 4096 |
1017 | stdcall user_alloc, 4096 |
1026 | 1018 | ||
1027 | mov edx, [current_slot] |
1019 | mov edx, [current_slot] |
1028 | mov [edx+APPDATA.tls_base], eax |
1020 | mov [edx+APPDATA.tls_base], eax |
1029 | mov [tls_data_l+2], ax |
1021 | mov [tls_data_l+2], ax |
1030 | shr eax, 16 |
1022 | shr eax, 16 |
1031 | mov [tls_data_l+4], al |
1023 | mov [tls_data_l+4], al |
1032 | mov [tls_data_l+7], ah |
1024 | mov [tls_data_l+7], ah |
1033 | mov dx, app_tls |
1025 | mov dx, app_tls |
1034 | mov fs, dx |
1026 | mov fs, dx |
1035 | popad |
1027 | popad |
1036 | iretd |
1028 | iretd |
1037 | 1029 | ||
1038 | 1030 | ||
1039 | EFL_IF equ 0x0200 |
1031 | EFL_IF equ 0x0200 |
1040 | EFL_IOPL1 equ 0x1000 |
1032 | EFL_IOPL1 equ 0x1000 |
1041 | EFL_IOPL2 equ 0x2000 |
1033 | EFL_IOPL2 equ 0x2000 |
1042 | EFL_IOPL3 equ 0x3000 |
1034 | EFL_IOPL3 equ 0x3000 |
1043 | 1035 | ||
1044 | 1036 | ||
1045 | align 4 |
1037 | align 4 |
1046 | proc set_app_params stdcall,slot:dword, params:dword,\ |
1038 | proc set_app_params stdcall,slot:dword, params:dword,\ |
1047 | cmd_line:dword, app_path:dword, flags:dword |
1039 | cmd_line:dword, app_path:dword, flags:dword |
1048 | 1040 | ||
1049 | locals |
1041 | locals |
1050 | pl0_stack dd ? |
1042 | pl0_stack dd ? |
1051 | endl |
1043 | endl |
1052 | 1044 | ||
1053 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1045 | stdcall kernel_alloc, RING0_STACK_SIZE+512 |
1054 | mov [pl0_stack], eax |
1046 | mov [pl0_stack], eax |
1055 | 1047 | ||
1056 | lea edi, [eax+RING0_STACK_SIZE] |
1048 | lea edi, [eax+RING0_STACK_SIZE] |
1057 | 1049 | ||
1058 | mov eax, [slot] |
1050 | mov eax, [slot] |
1059 | mov ebx, eax |
1051 | mov ebx, eax |
1060 | 1052 | ||
1061 | shl eax, 8 |
1053 | shl eax, 8 |
1062 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1054 | mov [eax+SLOT_BASE+APPDATA.fpu_state], edi |
1063 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1055 | mov [eax+SLOT_BASE+APPDATA.exc_handler], 0 |
1064 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1056 | mov [eax+SLOT_BASE+APPDATA.except_mask], 0 |
1065 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1057 | mov [eax+SLOT_BASE+APPDATA.terminate_protection], 80000001h |
1066 | 1058 | ||
1067 | ;set default io permission map |
1059 | ;set default io permission map |
1068 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1060 | mov ecx, [SLOT_BASE+256+APPDATA.io_map] |
1069 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1061 | mov [eax+SLOT_BASE+APPDATA.io_map], ecx |
1070 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1062 | mov ecx, [SLOT_BASE+256+APPDATA.io_map+4] |
1071 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1063 | mov [eax+SLOT_BASE+APPDATA.io_map+4], ecx |
1072 | 1064 | ||
1073 | mov esi, fpu_data |
1065 | mov esi, fpu_data |
1074 | mov ecx, 512/4 |
1066 | mov ecx, 512/4 |
1075 | rep movsd |
1067 | rep movsd |
1076 | 1068 | ||
1077 | cmp ebx, [TASK_COUNT] |
1069 | cmp ebx, [TASK_COUNT] |
1078 | jle .noinc |
1070 | jle .noinc |
1079 | inc dword [TASK_COUNT] ;update number of processes |
1071 | inc dword [TASK_COUNT] ;update number of processes |
1080 | .noinc: |
1072 | .noinc: |
1081 | shl ebx, 8 |
1073 | shl ebx, 8 |
1082 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1074 | lea edx, [ebx+SLOT_BASE+APP_EV_OFFSET] |
1083 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1075 | mov [SLOT_BASE+APPDATA.fd_ev+ebx], edx |
1084 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1076 | mov [SLOT_BASE+APPDATA.bk_ev+ebx], edx |
1085 | 1077 | ||
1086 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1078 | add edx, APP_OBJ_OFFSET-APP_EV_OFFSET |
1087 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1079 | mov [SLOT_BASE+APPDATA.fd_obj+ebx], edx |
1088 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1080 | mov [SLOT_BASE+APPDATA.bk_obj+ebx], edx |
1089 | 1081 | ||
1090 | mov ecx, [def_cursor] |
1082 | mov ecx, [def_cursor] |
1091 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1083 | mov [SLOT_BASE+APPDATA.cursor+ebx], ecx |
1092 | mov eax, [pl0_stack] |
1084 | mov eax, [pl0_stack] |
1093 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1085 | mov [SLOT_BASE+APPDATA.pl0_stack+ebx], eax |
1094 | add eax, RING0_STACK_SIZE |
1086 | add eax, RING0_STACK_SIZE |
1095 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1087 | mov [SLOT_BASE+APPDATA.saved_esp0+ebx], eax |
1096 | 1088 | ||
1097 | push ebx |
1089 | push ebx |
1098 | stdcall kernel_alloc, 0x1000 |
1090 | stdcall kernel_alloc, 0x1000 |
1099 | pop ebx |
1091 | pop ebx |
1100 | mov esi, [current_slot] |
1092 | mov esi, [current_slot] |
1101 | mov esi, [esi+APPDATA.cur_dir] |
1093 | mov esi, [esi+APPDATA.cur_dir] |
1102 | mov ecx, 0x1000/4 |
1094 | mov ecx, 0x1000/4 |
1103 | mov edi, eax |
1095 | mov edi, eax |
1104 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1096 | mov [ebx+SLOT_BASE+APPDATA.cur_dir], eax |
1105 | rep movsd |
1097 | rep movsd |
1106 | 1098 | ||
1107 | shr ebx, 3 |
1099 | shr ebx, 3 |
1108 | mov eax, new_app_base |
1100 | mov eax, new_app_base |
1109 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1101 | mov dword [CURRENT_TASK+ebx+0x10], eax |
1110 | 1102 | ||
1111 | .add_command_line: |
1103 | .add_command_line: |
1112 | mov edx, [params] |
1104 | mov edx, [params] |
1113 | mov edx, [edx] ;app_cmdline |
1105 | mov edx, [edx] ;app_cmdline |
1114 | test edx, edx |
1106 | test edx, edx |
1115 | jz @f ;application doesn't need parameters |
1107 | jz @f ;application doesn't need parameters |
1116 | 1108 | ||
1117 | mov eax, edx |
1109 | mov eax, edx |
1118 | add eax, 256 |
1110 | add eax, 256 |
1119 | jc @f |
1111 | jc @f |
1120 | 1112 | ||
1121 | cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1113 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1122 | ja @f |
1114 | ; ja @f |
1123 | 1115 | ||
1124 | mov eax, [cmd_line] |
1116 | mov eax, [cmd_line] |
1125 | 1117 | ||
1126 | cmp [edx], dword 0xffffffff ; extended destination tag |
1118 | cmp [edx], dword 0xffffffff ; extended destination tag |
1127 | jne .no_ext_dest |
1119 | jne .no_ext_dest |
1128 | 1120 | ||
1129 | mov edx, [edx+4] ; extended destination for cmdline |
1121 | mov edx, [edx+4] ; extended destination for cmdline |
1130 | jmp .continue |
1122 | jmp .continue |
1131 | 1123 | ||
1132 | .no_ext_dest: |
1124 | .no_ext_dest: |
1133 | mov [eax-12], dword 255 |
1125 | mov [eax-12], dword 255 |
1134 | .continue: |
1126 | .continue: |
1135 | mov byte [edx], 0 ;force empty string if no cmdline given |
1127 | mov byte [edx], 0 ;force empty string if no cmdline given |
1136 | 1128 | ||
1137 | test eax, eax |
1129 | test eax, eax |
1138 | jz @f |
1130 | jz @f |
1139 | ;-------------------------------------- |
1131 | ;-------------------------------------- |
1140 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1132 | cmp [eax-4], dword 0xffffffff ; cmdline_flag |
1141 | jne .old_copy |
1133 | jne .old_copy |
1142 | 1134 | ||
1143 | push eax |
1135 | push eax |
1144 | stdcall strncpy, edx, [eax-8], [eax-12] |
1136 | stdcall strncpy, edx, [eax-8], [eax-12] |
1145 | pop eax |
1137 | pop eax |
1146 | 1138 | ||
1147 | stdcall kernel_free, [eax-8] |
1139 | stdcall kernel_free, [eax-8] |
1148 | jmp @f |
1140 | jmp @f |
1149 | 1141 | ||
1150 | .old_copy: |
1142 | .old_copy: |
1151 | ;-------------------------------------- |
1143 | ;-------------------------------------- |
1152 | stdcall strncpy, edx, eax, 256 |
1144 | stdcall strncpy, edx, eax, 256 |
1153 | @@: |
1145 | @@: |
1154 | mov edx, [params] |
1146 | mov edx, [params] |
1155 | mov edx, [edx+4];app_path |
1147 | mov edx, [edx+4];app_path |
1156 | test edx, edx |
1148 | test edx, edx |
1157 | jz @F ;application don't need path of file |
1149 | jz @F ;application don't need path of file |
1158 | mov eax, edx |
1150 | mov eax, edx |
1159 | add eax, 1024 |
1151 | add eax, 1024 |
1160 | jc @f |
1152 | jc @f |
1161 | cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1153 | ; cmp eax, [SLOT_BASE+APPDATA.mem_size+ebx*8] |
1162 | ja @f |
1154 | ; ja @f |
1163 | stdcall strncpy, edx, [app_path], 1024 |
1155 | stdcall strncpy, edx, [app_path], 1024 |
1164 | @@: |
1156 | @@: |
1165 | mov ebx, [slot] |
1157 | mov ebx, [slot] |
1166 | mov eax, ebx |
1158 | mov eax, ebx |
1167 | shl ebx, 5 |
1159 | shl ebx, 5 |
1168 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1160 | lea ecx, [draw_data+ebx];ecx - pointer to draw data |
1169 | 1161 | ||
1170 | mov edx, irq0.return |
1162 | mov edx, irq0.return |
1171 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1163 | cmp [ebx*8+SLOT_BASE+APPDATA.tls_base], -1 |
1172 | jne @F |
1164 | jne @F |
1173 | mov edx, tls_app_entry |
1165 | mov edx, tls_app_entry |
1174 | @@: |
1166 | @@: |
1175 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1167 | ; set window state to 'normal' (non-minimized/maximized/rolled-up) state |
1176 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1168 | mov [ebx+window_data+WDATA.fl_wstate], WSTATE_NORMAL |
1177 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1169 | mov [ebx+window_data+WDATA.fl_redraw], 1 |
1178 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1170 | add ebx, CURRENT_TASK ;ebx - pointer to information about process |
1179 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1171 | mov [ebx+TASKDATA.wnd_number], al;set window number on screen = process slot |
1180 | 1172 | ||
1181 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1173 | mov [ebx+TASKDATA.event_mask], dword 1+2+4;set default event flags (see 40 function) |
1182 | 1174 | ||
1183 | inc dword [process_number] |
1175 | inc dword [process_number] |
1184 | mov eax, [process_number] |
1176 | mov eax, [process_number] |
1185 | mov [ebx+4], eax ;set PID |
1177 | mov [ebx+4], eax ;set PID |
1186 | 1178 | ||
1187 | ;set draw data to full screen |
1179 | ;set draw data to full screen |
1188 | xor eax, eax |
1180 | xor eax, eax |
1189 | mov [ecx+0], dword eax |
1181 | mov [ecx+0], dword eax |
1190 | mov [ecx+4], dword eax |
1182 | mov [ecx+4], dword eax |
1191 | mov eax, [Screen_Max_X] |
1183 | mov eax, [Screen_Max_X] |
1192 | mov [ecx+8], eax |
1184 | mov [ecx+8], eax |
1193 | mov eax, [Screen_Max_Y] |
1185 | mov eax, [Screen_Max_Y] |
1194 | mov [ecx+12], eax |
1186 | mov [ecx+12], eax |
1195 | 1187 | ||
1196 | mov ebx, [pl0_stack] |
1188 | mov ebx, [pl0_stack] |
1197 | mov esi, [params] |
1189 | mov esi, [params] |
1198 | lea ecx, [ebx+REG_EIP] |
1190 | lea ecx, [ebx+REG_EIP] |
1199 | xor eax, eax |
1191 | xor eax, eax |
1200 | 1192 | ||
1201 | mov [ebx+REG_RET], edx |
1193 | mov [ebx+REG_RET], edx |
1202 | mov [ebx+REG_EDI], eax |
1194 | mov [ebx+REG_EDI], eax |
1203 | mov [ebx+REG_ESI], eax |
1195 | mov [ebx+REG_ESI], eax |
1204 | mov [ebx+REG_EBP], eax |
1196 | mov [ebx+REG_EBP], eax |
1205 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1197 | mov [ebx+REG_ESP], ecx;ebx+REG_EIP |
1206 | mov [ebx+REG_EBX], eax |
1198 | mov [ebx+REG_EBX], eax |
1207 | mov [ebx+REG_EDX], eax |
1199 | mov [ebx+REG_EDX], eax |
1208 | mov [ebx+REG_ECX], eax |
1200 | mov [ebx+REG_ECX], eax |
1209 | mov [ebx+REG_EAX], eax |
1201 | mov [ebx+REG_EAX], eax |
1210 | 1202 | ||
1211 | mov eax, [esi+0x08] ;app_eip |
1203 | mov eax, [esi+0x08] ;app_eip |
1212 | mov [ebx+REG_EIP], eax ;app_entry |
1204 | mov [ebx+REG_EIP], eax ;app_entry |
1213 | mov [ebx+REG_CS], dword app_code |
1205 | mov [ebx+REG_CS], dword app_code |
1214 | mov ecx, USER_PRIORITY |
1206 | mov ecx, USER_PRIORITY |
1215 | 1207 | ||
1216 | test byte [flags], 2 |
1208 | test byte [flags], 2 |
1217 | jz @F |
1209 | jz @F |
1218 | 1210 | ||
1219 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1211 | mov [ebx+REG_CS], dword os_code ; kernel thread |
1220 | mov ecx, MAX_PRIORITY |
1212 | mov ecx, MAX_PRIORITY |
1221 | 1213 | ||
1222 | @@: |
1214 | @@: |
1223 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1215 | mov [ebx+REG_EFLAGS], dword EFL_IOPL1+EFL_IF |
1224 | 1216 | ||
1225 | mov eax, [esi+0x0C] ;app_esp |
1217 | mov eax, [esi+0x0C] ;app_esp |
1226 | mov [ebx+REG_APP_ESP], eax;app_stack |
1218 | mov [ebx+REG_APP_ESP], eax;app_stack |
1227 | mov [ebx+REG_SS], dword app_data |
1219 | mov [ebx+REG_SS], dword app_data |
1228 | 1220 | ||
1229 | lea edx, [ebx+REG_RET] |
1221 | lea edx, [ebx+REG_RET] |
1230 | mov ebx, [slot] |
1222 | mov ebx, [slot] |
1231 | shl ebx, 5 |
1223 | shl ebx, 5 |
1232 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1224 | mov [ebx*8+SLOT_BASE+APPDATA.saved_esp], edx |
1233 | 1225 | ||
1234 | xor edx, edx; process state - running |
1226 | xor edx, edx; process state - running |
1235 | ; set if debuggee |
1227 | ; set if debuggee |
1236 | test byte [flags], 1 |
1228 | test byte [flags], 1 |
1237 | jz .no_debug |
1229 | jz .no_debug |
1238 | inc edx ; process state - suspended |
1230 | inc edx ; process state - suspended |
1239 | mov eax, [CURRENT_TASK] |
1231 | mov eax, [CURRENT_TASK] |
1240 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1232 | mov [SLOT_BASE+ebx*8+APPDATA.debugger_slot], eax |
1241 | .no_debug: |
1233 | .no_debug: |
1242 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1234 | mov [CURRENT_TASK+ebx+TASKDATA.state], dl |
1243 | lea edx, [SLOT_BASE+ebx*8] |
1235 | lea edx, [SLOT_BASE+ebx*8] |
1244 | call scheduler_add_thread |
1236 | call scheduler_add_thread |
1245 | ret |
1237 | ret |
1246 | endp |
1238 | endp |
1247 | 1239 | ||
1248 | 1240 | ||
1249 | align 4 |
1241 | align 4 |
1250 | 1242 | ||
1251 | get_stack_base: |
1243 | get_stack_base: |
1252 | mov eax, [current_slot] |
1244 | mov eax, [current_slot] |
1253 | mov eax, [eax+APPDATA.pl0_stack] |
1245 | mov eax, [eax+APPDATA.pl0_stack] |
1254 | ret |
1246 | ret |
1255 | 1247 | ||
1256 | 1248 | ||
1257 | include "debug.inc"> |
1249 | include "debug.inc"> |