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