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