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