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