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