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