Rev 61 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 61 | Rev 91 | ||
---|---|---|---|
1 | if ~defined newprocess_inc |
1 | if ~defined newprocess_inc |
2 | newprocess_inc_fix: |
2 | newprocess_inc_fix: |
3 | newprocess_inc fix newprocess_inc_fix |
3 | newprocess_inc fix newprocess_inc_fix |
4 | include "mem.inc" |
4 | include "mem.inc" |
5 | include "memmanag.inc" |
5 | include "memmanag.inc" |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
6 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
7 | ;;Working with new types of processes. |
7 | ;;Working with new types of processes. |
8 | ;;Author: Khalyavin Andrey halyavin@land.ru |
8 | ;;Author: Khalyavin Andrey halyavin@land.ru |
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
9 | ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; |
10 | iglobal |
10 | iglobal |
11 | new_process_loading db 'K : New Process - loading',13,10,0 |
11 | new_process_loading db 'K : New Process - loading',13,10,0 |
12 | new_process_running db 'K : New Process - done',13,10,0 |
12 | new_process_running db 'K : New Process - done',13,10,0 |
13 | start_not_enough_memory db 'K : New Process - not enough memory',13,10,0 |
13 | start_not_enough_memory db 'K : New Process - not enough memory',13,10,0 |
14 | endg |
14 | endg |
15 | ;----------------------------------------------------------------------------- |
15 | ;----------------------------------------------------------------------------- |
16 | 16 | ||
17 | find_new_process_place: |
17 | find_new_process_place: |
18 | ;input: |
18 | ;input: |
19 | ; none |
19 | ; none |
20 | ;result: |
20 | ;result: |
21 | ; eax=[new_process_place]<>0 - ok |
21 | ; eax=[new_process_place]<>0 - ok |
22 | ; 0 - failed. |
22 | ; 0 - failed. |
23 | ;This function find least empty slot. |
23 | ;This function find least empty slot. |
24 | ;It doesn't increase [0x3004]! |
24 | ;It doesn't increase [0x3004]! |
25 | mov eax,0x3000+second_base_address |
25 | mov eax,0x3000+second_base_address |
26 | push ebx |
26 | push ebx |
27 | mov ebx,[0x3004] |
27 | mov ebx,[0x3004] |
28 | inc ebx |
28 | inc ebx |
29 | shl ebx,5 |
29 | shl ebx,5 |
30 | add ebx,eax ;ebx - address of process information for (last+1) slot |
30 | add ebx,eax ;ebx - address of process information for (last+1) slot |
31 | .newprocessplace: |
31 | .newprocessplace: |
32 | ;eax = address of process information for current slot |
32 | ;eax = address of process information for current slot |
33 | cmp eax,ebx |
33 | cmp eax,ebx |
34 | jz .endnewprocessplace ;empty slot after high boundary |
34 | jz .endnewprocessplace ;empty slot after high boundary |
35 | add eax,0x20 |
35 | add eax,0x20 |
36 | cmp word [eax+0xa],9 ;check process state, 9 means that process slot is empty |
36 | cmp word [eax+0xa],9 ;check process state, 9 means that process slot is empty |
37 | jnz .newprocessplace |
37 | jnz .newprocessplace |
38 | .endnewprocessplace: |
38 | .endnewprocessplace: |
39 | mov ebx,eax |
39 | mov ebx,eax |
40 | sub eax,0x3000+second_base_address |
40 | sub eax,0x3000+second_base_address |
41 | shr eax,5 ;calculate slot index |
41 | shr eax,5 ;calculate slot index |
42 | cmp eax,256 |
42 | cmp eax,256 |
43 | jge .failed ;it should be <256 |
43 | jge .failed ;it should be <256 |
44 | mov word [ebx+0xa],9 ;set process state to 9 (for slot after hight boundary) |
44 | mov word [ebx+0xa],9 ;set process state to 9 (for slot after hight boundary) |
45 | mov [new_process_place],eax ;save process slot |
45 | mov [new_process_place],eax ;save process slot |
46 | pop ebx |
46 | pop ebx |
47 | ret |
47 | ret |
48 | .failed: |
48 | .failed: |
49 | xor eax,eax |
49 | xor eax,eax |
50 | pop ebx |
50 | pop ebx |
51 | ret |
51 | ret |
52 | ;----------------------------------------------------------------------------- |
52 | ;----------------------------------------------------------------------------- |
53 | safe_sti: |
53 | safe_sti: |
54 | cmp byte [0xe000], 1 |
54 | cmp byte [0xe000], 1 |
55 | jne @f |
55 | jne @f |
56 | sti |
56 | sti |
57 | @@:ret |
57 | @@:ret |
58 | 58 | ||
59 | new_start_application_floppy: |
59 | new_start_application_floppy: |
60 | ;input: |
60 | ;input: |
61 | ; eax - pointer to filename |
61 | ; eax - pointer to filename |
62 | ; ebx - parameters to pass |
62 | ; ebx - parameters to pass |
63 | ; edx - flags |
63 | ; edx - flags |
64 | ;result: |
64 | ;result: |
65 | ; eax - pid of new process |
65 | ; eax - pid of new process |
66 | ; or 0 if call fails. |
66 | ; or 0 if call fails. |
67 | mov [appl_path],edi |
67 | mov [appl_path],edi |
68 | pushad |
68 | pushad |
69 | mov esi,new_process_loading |
69 | mov esi,new_process_loading |
70 | call sys_msg_board_str ;write to debug board |
70 | call sys_msg_board_str ;write to debug board |
71 | 71 | ||
72 | ;wait application_table_status mutex |
72 | ;wait application_table_status mutex |
73 | .table_status: |
73 | .table_status: |
74 | cli |
74 | cli |
75 | cmp [application_table_status],0 |
75 | cmp [application_table_status],0 |
76 | jz .stf |
76 | jz .stf |
77 | sti |
77 | sti |
78 | call change_task |
78 | call change_task |
79 | jmp .table_status |
79 | jmp .table_status |
80 | .stf: |
80 | .stf: |
81 | call set_application_table_status |
81 | call set_application_table_status |
82 | ;we can change system tables now |
82 | ;we can change system tables now |
83 | push edi |
83 | push edi |
84 | push ebx |
84 | push ebx |
85 | push eax |
85 | push eax |
86 | call find_new_process_place ;find empty process slot |
86 | call find_new_process_place ;find empty process slot |
87 | sti |
87 | sti |
88 | test eax,eax |
88 | test eax,eax |
89 | mov ecx, -0x20 ; too many processes |
89 | mov ecx, -0x20 ; too many processes |
90 | jz .failed |
90 | jz .failed |
91 | 91 | ||
92 | mov edi,eax |
92 | mov edi,eax |
93 | shl edi,8 |
93 | shl edi,8 |
94 | add edi,0x80000 |
94 | add edi,0x80000 |
95 | mov ecx,256/4 |
95 | mov ecx,256/4 |
96 | xor eax,eax |
96 | xor eax,eax |
97 | cld |
97 | cld |
98 | rep stosd ;clean extended information about process |
98 | rep stosd ;clean extended information about process |
99 | 99 | ||
100 | ;set new process name |
100 | ;set new process name |
101 | mov [appl_path_size],eax |
101 | mov [appl_path_size],eax |
102 | pop eax |
102 | pop eax |
103 | push eax |
103 | push eax |
104 | .find_last_byte: |
104 | .find_last_byte: |
105 | cmp byte [eax],0 |
105 | cmp byte [eax],0 |
106 | jz .find_last_byte_end |
106 | jz .find_last_byte_end |
107 | inc eax |
107 | inc eax |
108 | inc [appl_path_size] |
108 | inc [appl_path_size] |
109 | jmp .find_last_byte |
109 | jmp .find_last_byte |
110 | .find_last_byte_end: |
110 | .find_last_byte_end: |
111 | add [appl_path_size],24 |
111 | add [appl_path_size],24 |
112 | sub eax,11 ;last 11 bytes = application name |
112 | sub eax,11 ;last 11 bytes = application name |
113 | ; mov eax,[esp] ;eax - pointer to file name |
113 | ; mov eax,[esp] ;eax - pointer to file name |
114 | mov ebx,[new_process_place] |
114 | mov ebx,[new_process_place] |
115 | shl ebx,8 |
115 | shl ebx,8 |
116 | add ebx,0x80000 |
116 | add ebx,0x80000 |
117 | mov ecx,11 |
117 | mov ecx,11 |
118 | call memmove |
118 | call memmove |
119 | 119 | ||
120 | ;read header of file |
120 | ;read header of file |
121 | mov eax,[esp] |
121 | mov eax,[esp] |
122 | mov ebx,1 ;index of first block |
122 | mov ebx,1 ;index of first block |
123 | mov ecx,2 ;number of blocks |
123 | mov ecx,2 ;number of blocks |
124 | mov edx,0x90000 ;temp area |
124 | mov edx,0x90000 ;temp area |
125 | mov esi,12 ;file name length |
125 | mov esi,12 ;file name length |
126 | mov edi,[esp+8] |
126 | mov edi,[esp+8] |
127 | ; cli |
127 | ; cli |
128 | call floppy_fileread ;read file from FD |
128 | call floppy_fileread ;read file from FD |
129 | ; sti |
129 | ; sti |
130 | mov ecx, eax |
130 | mov ecx, eax |
131 | neg ecx |
131 | neg ecx |
132 | jnz .cleanfailed |
132 | jnz .cleanfailed |
133 | ;check MENUET signature |
133 | ;check MENUET signature |
134 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
134 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
135 | cmp [0x90000],dword 'MENU' |
135 | cmp [0x90000],dword 'MENU' |
136 | jnz .cleanfailed |
136 | jnz .cleanfailed |
137 | cmp [0x90004],word 'ET' |
137 | cmp [0x90004],word 'ET' |
138 | jnz .cleanfailed |
138 | jnz .cleanfailed |
139 | 139 | ||
140 | call get_app_params ;parse header fields |
140 | call get_app_params ;parse header fields |
141 | test esi, esi |
141 | test esi, esi |
142 | jz .cleanfailed |
142 | jz .cleanfailed |
143 | 143 | ||
144 | mov eax,[new_process_place] |
144 | mov eax,[new_process_place] |
145 | inc ecx ; -0x1E = no memory |
145 | inc ecx ; -0x1E = no memory |
146 | call create_app_cr3_table ;create page directory for new process |
146 | call create_app_cr3_table ;create page directory for new process |
147 | test eax,eax |
147 | test eax,eax |
148 | jz .cleanfailed_mem |
148 | jz .cleanfailed_mem |
149 | 149 | ||
150 | call MEM_Get_Linear_Address ;calculate linear address of it |
150 | call MEM_Get_Linear_Address ;calculate linear address of it |
151 | 151 | ||
152 | mov ebx,std_application_base_address |
152 | mov ebx,std_application_base_address |
153 | mov ecx,[app_mem] |
153 | mov ecx,[app_mem] |
154 | add ecx,4095 |
154 | add ecx,4095 |
155 | shr ecx,12 |
155 | shr ecx,12 |
156 | mov edx,eax |
156 | mov edx,eax |
157 | call mem_alloc_specified_region ;allocate memory for application |
157 | call mem_alloc_specified_region ;allocate memory for application |
158 | test eax,eax |
158 | test eax,eax |
159 | mov ecx, -0x1E |
159 | mov ecx, -0x1E |
160 | jz .cleanfailed_mem1 |
160 | jz .cleanfailed_mem1 |
161 | 161 | ||
162 | mov eax,[edx+(std_application_base_address shr 20)] |
162 | mov eax,[edx+(std_application_base_address shr 20)] |
163 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
163 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
164 | call MEM_Get_Linear_Address |
164 | call MEM_Get_Linear_Address |
165 | mov edx,eax |
165 | mov edx,eax |
166 | 166 | ||
167 | ;read file |
167 | ;read file |
168 | mov ebx,1 |
168 | mov ebx,1 |
169 | mov esi,12 ;length of file name |
169 | mov esi,12 ;length of file name |
170 | .loop1: |
170 | .loop1: |
171 | ;edx = linear address of current page table entry |
171 | ;edx = linear address of current page table entry |
172 | ;ebx = index of current block in file |
172 | ;ebx = index of current block in file |
173 | push edx |
173 | push edx |
174 | mov eax,[edx] |
174 | mov eax,[edx] |
175 | and eax,not (4096-1) |
175 | and eax,not (4096-1) |
176 | call MEM_Get_Linear_Address |
176 | call MEM_Get_Linear_Address |
177 | mov edx,eax ;read file block to current page |
177 | mov edx,eax ;read file block to current page |
178 | mov eax,[esp+4] ;restore pointer to file name |
178 | mov eax,[esp+4] ;restore pointer to file name |
179 | mov ecx,8 ;number of blocks read |
179 | mov ecx,8 ;number of blocks read |
180 | push ebx |
180 | push ebx |
181 | mov edi,[esp+16] |
181 | mov edi,[esp+16] |
182 | ; cli |
182 | ; cli |
183 | call floppy_fileread |
183 | call floppy_fileread |
184 | ;ebx=file size |
184 | ;ebx=file size |
185 | ; sti |
185 | ; sti |
186 | pop ecx |
186 | pop ecx |
187 | shr ebx,9 |
187 | shr ebx,9 |
188 | cmp ecx,ebx |
188 | cmp ecx,ebx |
189 | jg .endloop1 ;if end of file? |
189 | jg .endloop1 ;if end of file? |
190 | mov ebx,ecx |
190 | mov ebx,ecx |
191 | test eax,eax |
191 | test eax,eax |
192 | jnz .endloop1 ;check io errors |
192 | jnz .endloop1 ;check io errors |
193 | pop edx |
193 | pop edx |
194 | add ebx,8 ;go to next page |
194 | add ebx,8 ;go to next page |
195 | add edx,4 |
195 | add edx,4 |
196 | jmp .loop1 |
196 | jmp .loop1 |
197 | 197 | ||
198 | .endloop1: |
198 | .endloop1: |
199 | add esp,8+4 ;pop linear address of page table entry and pointer to file name |
199 | add esp,8+4 ;pop linear address of page table entry and pointer to file name |
200 | call new_start_application_fl.add_app_parameters |
200 | call new_start_application_fl.add_app_parameters |
201 | mov [esp+28],eax |
201 | mov [esp+28],eax |
202 | popad |
202 | popad |
203 | ret |
203 | ret |
204 | 204 | ||
205 | .cleanfailed_mem1: |
205 | .cleanfailed_mem1: |
206 | ;there is mem for directory entry, but there is no mem for pages |
206 | ;there is mem for directory entry, but there is no mem for pages |
207 | ;so free directory entry |
207 | ;so free directory entry |
208 | mov eax,[new_process_place] |
208 | mov eax,[new_process_place] |
209 | shl eax,8 |
209 | shl eax,8 |
210 | mov eax,[0x80000+eax+0xB8] |
210 | mov eax,[0x80000+eax+0xB8] |
211 | call MEM_Free_Page |
211 | call MEM_Free_Page |
212 | .cleanfailed_mem: |
212 | .cleanfailed_mem: |
213 | ;there is no mem for directory entry, display message. |
213 | ;there is no mem for directory entry, display message. |
214 | mov esi,start_not_enough_memory |
214 | mov esi,start_not_enough_memory |
215 | call sys_msg_board_str |
215 | call sys_msg_board_str |
216 | .cleanfailed: ;clean process name |
216 | .cleanfailed: ;clean process name |
217 | push ecx ; save error code |
217 | push ecx ; save error code |
218 | ;can't read file, clean process name. |
218 | ;can't read file, clean process name. |
219 | ;this avoid problems with panel application. |
219 | ;this avoid problems with panel application. |
220 | mov edi,[new_process_place] |
220 | mov edi,[new_process_place] |
221 | shl edi,8 |
221 | shl edi,8 |
222 | add edi,0x80000 |
222 | add edi,0x80000 |
223 | mov ecx,11 |
223 | mov ecx,11 |
224 | mov eax,' ' |
224 | mov eax,' ' |
225 | cld |
225 | cld |
226 | rep stosb |
226 | rep stosb |
227 | pop eax |
227 | pop eax |
228 | .failed: |
228 | .failed: |
229 | ;no more slots |
229 | ;no more slots |
230 | add esp,8+4 |
230 | add esp,8+4 |
231 | mov [application_table_status],0 |
231 | mov [application_table_status],0 |
232 | mov [esp+1Ch], eax |
232 | mov [esp+1Ch], eax |
233 | popad |
233 | popad |
234 | sti |
234 | sti |
235 | ret |
235 | ret |
236 | 236 | ||
237 | ;----------------------------------------------------------------------------- |
237 | ;----------------------------------------------------------------------------- |
238 | new_start_application_fl: |
238 | new_start_application_fl: |
239 | ;input: |
239 | ;input: |
240 | ; eax - pointer to filename |
240 | ; eax - pointer to filename |
241 | ; ebx - parameters to pass |
241 | ; ebx - parameters to pass |
242 | ; edx - flags |
242 | ; edx - flags |
243 | ;result: |
243 | ;result: |
244 | ; eax - pid of new process |
244 | ; eax - pid of new process |
245 | ; or 0 if call fails. |
245 | ; or 0 if call fails. |
246 | mov [appl_path],edi |
246 | mov [appl_path],edi |
247 | mov [appl_path_size],36 |
247 | mov [appl_path_size],36 |
248 | pushad |
248 | pushad |
249 | mov esi,new_process_loading |
249 | mov esi,new_process_loading |
250 | call sys_msg_board_str ;write to debug board |
250 | call sys_msg_board_str ;write to debug board |
251 | 251 | ||
252 | ;wait application_table_status mutex |
252 | ;wait application_table_status mutex |
253 | .table_status: |
253 | .table_status: |
254 | cli |
254 | cli |
255 | cmp [application_table_status],0 |
255 | cmp [application_table_status],0 |
256 | jz .stf |
256 | jz .stf |
257 | sti |
257 | sti |
258 | call change_task |
258 | call change_task |
259 | jmp .table_status |
259 | jmp .table_status |
260 | .stf: |
260 | .stf: |
261 | call set_application_table_status |
261 | call set_application_table_status |
262 | ;we can change system tables now |
262 | ;we can change system tables now |
263 | push ebx |
263 | push ebx |
264 | push eax |
264 | push eax |
265 | call find_new_process_place ;find empty process slot |
265 | call find_new_process_place ;find empty process slot |
266 | call safe_sti |
266 | call safe_sti |
267 | test eax,eax |
267 | test eax,eax |
268 | mov ecx, -0x20 ; too many processes |
268 | mov ecx, -0x20 ; too many processes |
269 | jz .failed |
269 | jz .failed |
270 | 270 | ||
271 | mov edi,eax |
271 | mov edi,eax |
272 | shl edi,8 |
272 | shl edi,8 |
273 | add edi,0x80000 |
273 | add edi,0x80000 |
274 | mov ecx,256/4 |
274 | mov ecx,256/4 |
275 | xor eax,eax |
275 | xor eax,eax |
276 | cld |
276 | cld |
277 | rep stosd ;clean extended information about process |
277 | rep stosd ;clean extended information about process |
278 | 278 | ||
279 | ;set new process name |
279 | ;set new process name |
280 | mov eax,[esp] ;eax - pointer to file name |
280 | mov eax,[esp] ;eax - pointer to file name |
281 | mov ebx,[new_process_place] |
281 | mov ebx,[new_process_place] |
282 | shl ebx,8 |
282 | shl ebx,8 |
283 | add ebx,0x80000 |
283 | add ebx,0x80000 |
284 | mov ecx,11 |
284 | mov ecx,11 |
285 | call memmove |
285 | call memmove |
286 | 286 | ||
287 | ;read header of file |
287 | ;read header of file |
288 | mov ebx,1 ;index of first block |
288 | mov ebx,1 ;index of first block |
289 | mov ecx,2 ;number of blocks |
289 | mov ecx,2 ;number of blocks |
290 | mov edx,0x90000 ;temp area |
290 | mov edx,0x90000 ;temp area |
291 | mov esi,12 ;file name length |
291 | mov esi,12 ;file name length |
292 | cli |
292 | cli |
293 | call fileread ;read file from RD |
293 | call fileread ;read file from RD |
294 | call safe_sti |
294 | call safe_sti |
295 | mov ecx, eax |
295 | mov ecx, eax |
296 | neg ecx |
296 | neg ecx |
297 | jnz .cleanfailed |
297 | jnz .cleanfailed |
298 | ;check MENUET signature |
298 | ;check MENUET signature |
299 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
299 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
300 | cmp [0x90000],dword 'MENU' |
300 | cmp [0x90000],dword 'MENU' |
301 | jnz .cleanfailed |
301 | jnz .cleanfailed |
302 | cmp [0x90004],word 'ET' |
302 | cmp [0x90004],word 'ET' |
303 | jnz .cleanfailed |
303 | jnz .cleanfailed |
304 | 304 | ||
305 | call get_app_params ;parse header fields |
305 | call get_app_params ;parse header fields |
306 | test esi,esi |
306 | test esi,esi |
307 | jz .cleanfailed |
307 | jz .cleanfailed |
308 | 308 | ||
309 | mov eax,[new_process_place] |
309 | mov eax,[new_process_place] |
310 | call create_app_cr3_table ;create page directory for new process |
- | |
311 | inc ecx ; -0x1E = no memory |
310 | inc ecx ; -0x1E = no memory |
- | 311 | call create_app_cr3_table ;create page directory for new process |
|
312 | test eax,eax |
312 | test eax,eax |
313 | jz .cleanfailed_mem |
313 | jz .cleanfailed_mem |
314 | 314 | ||
315 | call MEM_Get_Linear_Address ;calculate linear address of it |
315 | call MEM_Get_Linear_Address ;calculate linear address of it |
316 | 316 | ||
317 | mov ebx,std_application_base_address |
317 | mov ebx,std_application_base_address |
318 | mov ecx,[app_mem] |
318 | mov ecx,[app_mem] |
319 | add ecx,4095 |
319 | add ecx,4095 |
320 | shr ecx,12 |
320 | shr ecx,12 |
321 | mov edx,eax |
321 | mov edx,eax |
322 | call mem_alloc_specified_region ;allocate memory for application |
322 | call mem_alloc_specified_region ;allocate memory for application |
323 | test eax,eax |
323 | test eax,eax |
324 | mov ecx, -0x1E |
324 | mov ecx, -0x1E |
325 | jz .cleanfailed_mem1 |
325 | jz .cleanfailed_mem1 |
326 | 326 | ||
327 | mov eax,[edx+(std_application_base_address shr 20)] |
327 | mov eax,[edx+(std_application_base_address shr 20)] |
328 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
328 | and eax,not (4096-1) ;eax - physical address of first (for application memory) page table |
329 | call MEM_Get_Linear_Address |
329 | call MEM_Get_Linear_Address |
330 | mov edx,eax |
330 | mov edx,eax |
331 | 331 | ||
332 | ;read file |
332 | ;read file |
333 | mov ebx,1 |
333 | mov ebx,1 |
334 | mov esi,12 ;length of file name |
334 | mov esi,12 ;length of file name |
335 | .loop1: |
335 | .loop1: |
336 | ;edx = linear address of current page table entry |
336 | ;edx = linear address of current page table entry |
337 | ;ebx = index of current block in file |
337 | ;ebx = index of current block in file |
338 | push edx |
338 | push edx |
339 | mov eax,[edx] |
339 | mov eax,[edx] |
340 | and eax,not (4096-1) |
340 | and eax,not (4096-1) |
341 | call MEM_Get_Linear_Address |
341 | call MEM_Get_Linear_Address |
342 | mov edx,eax ;read file block to current page |
342 | mov edx,eax ;read file block to current page |
343 | mov eax,[esp+4] ;restore pointer to file name |
343 | mov eax,[esp+4] ;restore pointer to file name |
344 | mov ecx,8 ;number of blocks read |
344 | mov ecx,8 ;number of blocks read |
345 | push ebx |
345 | push ebx |
346 | cli |
346 | cli |
347 | call fileread |
347 | call fileread |
348 | ;ebx=file size |
348 | ;ebx=file size |
349 | call safe_sti |
349 | call safe_sti |
350 | pop ecx |
350 | pop ecx |
351 | shr ebx,9 |
351 | shr ebx,9 |
352 | cmp ecx,ebx |
352 | cmp ecx,ebx |
353 | jg .endloop1 ;if end of file? |
353 | jg .endloop1 ;if end of file? |
354 | mov ebx,ecx |
354 | mov ebx,ecx |
355 | test eax,eax |
355 | test eax,eax |
356 | jnz .endloop1 ;check io errors |
356 | jnz .endloop1 ;check io errors |
357 | pop edx |
357 | pop edx |
358 | add ebx,8 ;go to next page |
358 | add ebx,8 ;go to next page |
359 | add edx,4 |
359 | add edx,4 |
360 | jmp .loop1 |
360 | jmp .loop1 |
361 | 361 | ||
362 | .endloop1: |
362 | .endloop1: |
363 | add esp,8 ;pop linear address of page table entry and pointer to file name |
363 | add esp,8 ;pop linear address of page table entry and pointer to file name |
364 | call .add_app_parameters |
364 | call .add_app_parameters |
365 | mov [esp+28],eax |
365 | mov [esp+28],eax |
366 | popad |
366 | popad |
367 | ret |
367 | ret |
368 | 368 | ||
369 | .cleanfailed_mem1: |
369 | .cleanfailed_mem1: |
370 | ;there is mem for directory entry, but there is no mem for pages |
370 | ;there is mem for directory entry, but there is no mem for pages |
371 | ;so free directory entry |
371 | ;so free directory entry |
372 | mov eax,[new_process_place] |
372 | mov eax,[new_process_place] |
373 | shl eax,8 |
373 | shl eax,8 |
374 | mov eax,[0x80000+eax+0xB8] |
374 | mov eax,[0x80000+eax+0xB8] |
375 | call MEM_Free_Page |
375 | call MEM_Free_Page |
376 | .cleanfailed_mem: |
376 | .cleanfailed_mem: |
377 | ;there is no mem for directory entry, display message. |
377 | ;there is no mem for directory entry, display message. |
378 | mov esi,start_not_enough_memory |
378 | mov esi,start_not_enough_memory |
379 | call sys_msg_board_str |
379 | call sys_msg_board_str |
380 | .cleanfailed: ;clean process name |
380 | .cleanfailed: ;clean process name |
381 | push ecx ; save error code |
381 | push ecx ; save error code |
382 | ;can't read file, clean process name. |
382 | ;can't read file, clean process name. |
383 | ;this avoid problems with panel application. |
383 | ;this avoid problems with panel application. |
384 | mov edi,[new_process_place] |
384 | mov edi,[new_process_place] |
385 | shl edi,8 |
385 | shl edi,8 |
386 | add edi,0x80000 |
386 | add edi,0x80000 |
387 | mov ecx,11 |
387 | mov ecx,11 |
388 | mov eax,' ' |
388 | mov eax,' ' |
389 | cld |
389 | cld |
390 | rep stosb |
390 | rep stosb |
391 | pop eax |
391 | pop eax |
392 | .failed: |
392 | .failed: |
393 | ;no more slots |
393 | ;no more slots |
394 | add esp,8 |
394 | add esp,8 |
395 | mov [application_table_status],0 |
395 | mov [application_table_status],0 |
396 | mov [esp+1Ch], eax |
396 | mov [esp+1Ch], eax |
397 | popad |
397 | popad |
398 | call safe_sti |
398 | call safe_sti |
399 | ret |
399 | ret |
400 | 400 | ||
401 | .add_app_parameters: |
401 | .add_app_parameters: |
402 | ;input: |
402 | ;input: |
403 | ; [esp] - pointer to parameters |
403 | ; [esp] - pointer to parameters |
404 | ; [esp+4]-[esp+36] pushad registers. |
404 | ; [esp+4]-[esp+36] pushad registers. |
405 | ;result |
405 | ;result |
406 | ; eax - pid of new process |
406 | ; eax - pid of new process |
407 | ; or zero if failed |
407 | ; or zero if failed |
408 | cli |
408 | cli |
409 | mov ebx,[new_process_place] |
409 | mov ebx,[new_process_place] |
410 | cmp ebx,[0x3004] |
410 | cmp ebx,[0x3004] |
411 | jle .noinc |
411 | jle .noinc |
412 | inc dword [0x3004] ;update number of processes |
412 | inc dword [0x3004] ;update number of processes |
413 | .noinc: |
413 | .noinc: |
414 | 414 | ||
415 | ; mov ebx,[new_process_place] |
415 | ; mov ebx,[new_process_place] |
416 | ;set 0x8c field of extended information about process |
416 | ;set 0x8c field of extended information about process |
417 | ;(size of application memory) |
417 | ;(size of application memory) |
418 | shl ebx,8 |
418 | shl ebx,8 |
419 | mov eax,[app_mem] |
419 | mov eax,[app_mem] |
420 | mov [second_base_address+0x80000+0x8c+ebx],eax |
420 | mov [second_base_address+0x80000+0x8c+ebx],eax |
421 | ;set 0x10 field of information about process |
421 | ;set 0x10 field of information about process |
422 | ;(application base address) |
422 | ;(application base address) |
423 | ; mov ebx,[new_process_place] |
423 | ; mov ebx,[new_process_place] |
424 | ; shl ebx,5 |
424 | ; shl ebx,5 |
425 | shr ebx,3 |
425 | shr ebx,3 |
426 | mov dword [second_base_address+0x3000+ebx+0x10],std_application_base_address |
426 | mov dword [second_base_address+0x3000+ebx+0x10],std_application_base_address |
427 | 427 | ||
428 | ;add command line parameters |
428 | ;add command line parameters |
429 | .add_command_line: |
429 | .add_command_line: |
430 | mov edx,[app_i_param] |
430 | mov edx,[app_i_param] |
431 | test edx,edx |
431 | test edx,edx |
432 | jz .no_command_line ;application don't need parameters |
432 | jz .no_command_line ;application don't need parameters |
433 | mov eax,[esp+4] |
433 | mov eax,[esp+4] |
434 | test eax,eax |
434 | test eax,eax |
435 | jz .no_command_line ;no parameters specified |
435 | jz .no_command_line ;no parameters specified |
436 | ;calculate parameter length |
436 | ;calculate parameter length |
437 | mov esi,eax |
437 | mov esi,eax |
438 | xor ecx,ecx |
438 | xor ecx,ecx |
439 | .command_line_len: |
439 | .command_line_len: |
440 | cmp byte [esi],0 |
440 | cmp byte [esi],0 |
441 | jz .command_line_len_end |
441 | jz .command_line_len_end |
442 | inc esi |
442 | inc esi |
443 | inc ecx |
443 | inc ecx |
444 | cmp ecx,256 |
444 | cmp ecx,256 |
445 | jl .command_line_len |
445 | jl .command_line_len |
446 | 446 | ||
447 | .command_line_len_end: |
447 | .command_line_len_end: |
448 | ;ecx - parameter length |
448 | ;ecx - parameter length |
449 | ;edx - address of parameters in new process address space |
449 | ;edx - address of parameters in new process address space |
450 | mov ebx,eax ;ebx - address of parameters in our address space |
450 | mov ebx,eax ;ebx - address of parameters in our address space |
451 | mov eax,[new_process_place] |
451 | mov eax,[new_process_place] |
452 | call write_process_memory ;copy parameters to new process address space |
452 | call write_process_memory ;copy parameters to new process address space |
453 | 453 | ||
454 | .no_command_line: |
454 | .no_command_line: |
455 | ;****************************************************************** |
455 | ;****************************************************************** |
456 | mov edx,[app_i_icon] |
456 | mov edx,[app_i_icon] |
457 | test edx,edx |
457 | test edx,edx |
458 | jz .no_command_line_1 ;application don't need path of file |
458 | jz .no_command_line_1 ;application don't need path of file |
459 | mov ebx,[appl_path] |
459 | mov ebx,[appl_path] |
460 | mov ecx,[appl_path_size] |
460 | mov ecx,[appl_path_size] |
461 | mov eax,[new_process_place] |
461 | mov eax,[new_process_place] |
462 | call write_process_memory ;copy path of file to new process address space |
462 | call write_process_memory ;copy path of file to new process address space |
463 | .no_command_line_1: |
463 | .no_command_line_1: |
464 | ;****************************************************************** |
464 | ;****************************************************************** |
465 | mov ebx,[new_process_place] |
465 | mov ebx,[new_process_place] |
466 | mov eax,ebx |
466 | mov eax,ebx |
467 | shl ebx,5 |
467 | shl ebx,5 |
468 | add ebx,0x3000 ;ebx - pointer to information about process |
468 | add ebx,0x3000 ;ebx - pointer to information about process |
469 | mov [ebx+0xe],al ;set window number on screen = process slot |
469 | mov [ebx+0xe],al ;set window number on screen = process slot |
470 | 470 | ||
471 | mov [ebx],dword 1+2+4 ;set default event flags (see 40 function) |
471 | mov [ebx],dword 1+2+4 ;set default event flags (see 40 function) |
472 | 472 | ||
473 | inc dword [process_number] |
473 | inc dword [process_number] |
474 | mov eax,[process_number] |
474 | mov eax,[process_number] |
475 | mov [ebx+4],eax ;set PID |
475 | mov [ebx+4],eax ;set PID |
476 | 476 | ||
477 | mov ecx,ebx |
477 | mov ecx,ebx |
478 | add ecx,draw_data-0x3000 ;ecx - pointer to draw data |
478 | add ecx,draw_data-0x3000 ;ecx - pointer to draw data |
479 | ;set draw data to full screen |
479 | ;set draw data to full screen |
480 | mov [ecx+0],dword 0 |
480 | mov [ecx+0],dword 0 |
481 | mov [ecx+4],dword 0 |
481 | mov [ecx+4],dword 0 |
482 | mov eax,[0xfe00] |
482 | mov eax,[0xfe00] |
483 | mov [ecx+8],eax |
483 | mov [ecx+8],eax |
484 | mov eax,[0xfe04] |
484 | mov eax,[0xfe04] |
485 | mov [ecx+12],eax |
485 | mov [ecx+12],eax |
486 | ;set window state to 'normal' (non-minimized/maximized/rolled-up) state |
486 | ;set window state to 'normal' (non-minimized/maximized/rolled-up) state |
487 | mov [ecx+WDATA.fl_wstate],WSTATE_NORMAL |
487 | mov [ecx+WDATA.fl_wstate],WSTATE_NORMAL |
488 | ;set cr3 register in TSS of application |
488 | ;set cr3 register in TSS of application |
489 | mov ecx,[new_process_place] |
489 | mov ecx,[new_process_place] |
490 | shl ecx,8 |
490 | shl ecx,8 |
491 | mov eax,[0x800B8+ecx] |
491 | mov eax,[0x800B8+ecx] |
492 | add eax,8+16 ;add flags |
492 | add eax,8+16 ;add flags |
493 | mov [l.cr3],eax |
493 | mov [l.cr3],eax |
494 | 494 | ||
495 | mov eax,[app_start] |
495 | mov eax,[app_start] |
496 | mov [l.eip],eax ;set eip in TSS |
496 | mov [l.eip],eax ;set eip in TSS |
497 | mov eax,[app_esp] |
497 | mov eax,[app_esp] |
498 | mov [l.esp],eax ;set stack in TSS |
498 | mov [l.esp],eax ;set stack in TSS |
499 | 499 | ||
500 | ;gdt |
500 | ;gdt |
501 | ;mov ebx,[new_process_place] |
501 | ;mov ebx,[new_process_place] |
502 | ;shl ebx,3 |
502 | ;shl ebx,3 |
503 | mov ax,app_code ;ax - selector of code segment |
503 | mov ax,app_code ;ax - selector of code segment |
504 | ;add ax,bx |
504 | ;add ax,bx |
505 | mov [l.cs],ax |
505 | mov [l.cs],ax |
506 | mov ax,app_data |
506 | mov ax,app_data |
507 | ;add ax,bx ;ax - selector of data segment |
507 | ;add ax,bx ;ax - selector of data segment |
508 | mov [l.ss],ax |
508 | mov [l.ss],ax |
509 | mov [l.ds],ax |
509 | mov [l.ds],ax |
510 | mov [l.es],ax |
510 | mov [l.es],ax |
511 | mov [l.fs],ax |
511 | mov [l.fs],ax |
512 | mov ax,graph_data ;ax - selector of graphic segment |
512 | mov ax,graph_data ;ax - selector of graphic segment |
513 | mov [l.gs],ax |
513 | mov [l.gs],ax |
514 | mov [l.io],word 128 |
514 | mov [l.io],word 128 |
515 | mov [l.eflags],dword 0x11202 |
515 | mov [l.eflags],dword 0x11202 |
516 | mov [l.ss0],os_data |
516 | mov [l.ss0],os_data |
517 | mov ebx,[new_process_place] |
517 | mov ebx,[new_process_place] |
518 | shl ebx,12 |
518 | shl ebx,12 |
519 | add ebx,sysint_stack_data+4096 |
519 | add ebx,sysint_stack_data+4096 |
520 | mov [l.esp0],ebx |
520 | mov [l.esp0],ebx |
521 | 521 | ||
522 | ;copy tss to it place |
522 | ;copy tss to it place |
523 | mov eax,tss_sceleton |
523 | mov eax,tss_sceleton |
524 | mov ebx,[new_process_place] |
524 | mov ebx,[new_process_place] |
525 | imul ebx,tss_step |
525 | imul ebx,tss_step |
526 | add ebx,tss_data ;ebx - address of application TSS |
526 | add ebx,tss_data ;ebx - address of application TSS |
527 | mov ecx,120 |
527 | mov ecx,120 |
528 | call memmove |
528 | call memmove |
529 | 529 | ||
530 | ;Add IO access table - bit array of permitted ports |
530 | ;Add IO access table - bit array of permitted ports |
531 | or eax,-1 |
531 | or eax,-1 |
532 | mov edi,[new_process_place] |
532 | mov edi,[new_process_place] |
533 | imul edi,tss_step |
533 | imul edi,tss_step |
534 | add edi,tss_data+128 |
534 | add edi,tss_data+128 |
535 | mov ecx,2048 |
535 | mov ecx,2048 |
536 | cld |
536 | cld |
537 | rep stosd ;full access to 2048*8=16384 ports |
537 | rep stosd ;full access to 2048*8=16384 ports |
538 | 538 | ||
539 | mov ecx,ebx ;ecx - address of application TSS |
539 | mov ecx,ebx ;ecx - address of application TSS |
540 | mov edi,[new_process_place] |
540 | mov edi,[new_process_place] |
541 | shl edi,3 |
541 | shl edi,3 |
542 | ;set TSS descriptor |
542 | ;set TSS descriptor |
543 | mov [edi+gdts+tss0+0],word tss_step ;limit (size) |
543 | mov [edi+gdts+tss0+0],word tss_step ;limit (size) |
544 | mov [edi+gdts+tss0+2],cx ;part of offset |
544 | mov [edi+gdts+tss0+2],cx ;part of offset |
545 | mov eax,ecx |
545 | mov eax,ecx |
546 | shr eax,16 |
546 | shr eax,16 |
547 | mov [edi+gdts+tss0+4],al ;part of offset |
547 | mov [edi+gdts+tss0+4],al ;part of offset |
548 | mov [edi+gdts+tss0+7],ah ;part of offset |
548 | mov [edi+gdts+tss0+7],ah ;part of offset |
549 | mov [edi+gdts+tss0+5],word 01010000b*256+11101001b ;system flags |
549 | mov [edi+gdts+tss0+5],word 01010000b*256+11101001b ;system flags |
550 | 550 | ||
551 | 551 | ||
552 | ;flush keyboard and buttons queue |
552 | ;flush keyboard and buttons queue |
553 | mov [0xf400],byte 0 |
553 | mov [0xf400],byte 0 |
554 | mov [0xf500],byte 0 |
554 | mov [0xf500],byte 0 |
555 | 555 | ||
556 | mov edi,[new_process_place] |
556 | mov edi,[new_process_place] |
557 | shl edi,5 |
557 | shl edi,5 |
558 | add edi,window_data |
558 | add edi,window_data |
559 | mov ebx,[new_process_place] |
559 | mov ebx,[new_process_place] |
560 | movzx esi,word [0xC000+ebx*2] |
560 | movzx esi,word [0xC000+ebx*2] |
561 | lea esi,[0xC400+esi*2] |
561 | lea esi,[0xC400+esi*2] |
562 | call windowactivate ;gui initialization |
562 | call windowactivate ;gui initialization |
563 | 563 | ||
564 | mov ebx,[new_process_place] |
564 | mov ebx,[new_process_place] |
565 | shl ebx,5 |
565 | shl ebx,5 |
566 | mov [0x3000+ebx+0xa],byte 0 ;set process state - running |
- | |
567 | ; set if debuggee |
566 | ; set if debuggee |
568 | test byte [esp+28], 1 |
567 | test byte [esp+28], 1 |
569 | jz .no_debug |
568 | jz .no_debug |
570 | mov [0x3000+ebx+0xa],byte 1 ;set process state - suspended |
569 | mov [0x3000+ebx+0xa], byte 1 ; set process state - suspended |
571 | mov eax,[0x3000] |
570 | mov eax, [0x3000] |
572 | mov [0x80000+ebx*8+0xac],eax ;set debugger PID - current |
571 | mov [0x80000+ebx*8+0xac], eax ;set debugger PID - current |
- | 572 | jmp .debug |
|
573 | .no_debug: |
573 | .no_debug: |
- | 574 | mov [0x3000+ebx+0xa], byte 0 ; set process state - running |
|
- | 575 | .debug: |
|
574 | 576 | ||
575 | mov esi,new_process_running |
577 | mov esi,new_process_running |
576 | call sys_msg_board_str ;output information about succefull startup |
578 | call sys_msg_board_str ;output information about succefull startup |
577 | 579 | ||
578 | ; add esp,4 ;pop pointer to parameters |
580 | ; add esp,4 ;pop pointer to parameters |
579 | ; popad |
581 | ; popad |
580 | mov eax,[process_number] ;set result |
582 | mov eax,[process_number] ;set result |
581 | mov [application_table_status],0 ;unlock application_table_status mutex |
583 | mov [application_table_status],0 ;unlock application_table_status mutex |
582 | call safe_sti |
584 | call safe_sti |
583 | ret 4 |
585 | ret 4 |
584 | ;----------------------------------------------------------------------------- |
586 | ;----------------------------------------------------------------------------- |
585 | new_sys_threads: |
587 | new_sys_threads: |
586 | ;eax=1 - create thread |
588 | ;eax=1 - create thread |
587 | ; ebx=thread start |
589 | ; ebx=thread start |
588 | ; ecx=thread stack value |
590 | ; ecx=thread stack value |
589 | ;result: |
591 | ;result: |
590 | ; eax=pid |
592 | ; eax=pid |
591 | xor edx,edx ; flags=0 |
593 | xor edx,edx ; flags=0 |
592 | pushad |
594 | pushad |
593 | 595 | ||
594 | cmp eax,1 |
596 | cmp eax,1 |
595 | jnz .ret ;other subfunctions |
597 | jnz .ret ;other subfunctions |
596 | mov esi,new_process_loading |
598 | mov esi,new_process_loading |
597 | call sys_msg_board_str |
599 | call sys_msg_board_str |
598 | ;lock application_table_status mutex |
600 | ;lock application_table_status mutex |
599 | .table_status: |
601 | .table_status: |
600 | cli |
602 | cli |
601 | cmp [application_table_status],0 |
603 | cmp [application_table_status],0 |
602 | je .stf |
604 | je .stf |
603 | sti |
605 | sti |
604 | call change_task |
606 | call change_task |
605 | jmp .table_status |
607 | jmp .table_status |
606 | .stf: |
608 | .stf: |
607 | call set_application_table_status |
609 | call set_application_table_status |
608 | ;find free process slot |
610 | ;find free process slot |
609 | 611 | ||
610 | call find_new_process_place |
612 | call find_new_process_place |
611 | test eax,eax |
613 | test eax,eax |
612 | jz .failed |
614 | jz .failed |
613 | 615 | ||
614 | ;set parameters for thread |
616 | ;set parameters for thread |
615 | xor eax,eax |
617 | xor eax,eax |
616 | mov [app_i_param],eax |
618 | mov [app_i_param],eax |
617 | mov [app_i_icon],eax |
619 | mov [app_i_icon],eax |
618 | mov [app_start],ebx |
620 | mov [app_start],ebx |
619 | mov [app_esp],ecx |
621 | mov [app_esp],ecx |
620 | 622 | ||
621 | mov esi,[0x3000] |
623 | mov esi,[0x3000] |
622 | shl esi,8 |
624 | shl esi,8 |
623 | add esi,0x80000 |
625 | add esi,0x80000 |
624 | mov ebx,esi ;ebx=esi - pointer to extended information about current thread |
626 | mov ebx,esi ;ebx=esi - pointer to extended information about current thread |
625 | 627 | ||
626 | mov edi,[new_process_place] |
628 | mov edi,[new_process_place] |
627 | shl edi,8 |
629 | shl edi,8 |
628 | add edi,0x80000 |
630 | add edi,0x80000 |
629 | mov edx,edi ;edx=edi - pointer to extended infomation about new thread |
631 | mov edx,edi ;edx=edi - pointer to extended infomation about new thread |
630 | mov ecx,256/4 |
632 | mov ecx,256/4 |
631 | rep stosd ;clean extended information about new thread |
633 | rep stosd ;clean extended information about new thread |
632 | mov edi,edx |
634 | mov edi,edx |
633 | mov ecx,11 |
635 | mov ecx,11 |
634 | rep movsb ;copy process name |
636 | rep movsb ;copy process name |
635 | mov eax,[ebx+0x8c] |
637 | mov eax,[ebx+0x8c] |
636 | mov [app_mem],eax ;set memory size |
638 | mov [app_mem],eax ;set memory size |
637 | mov eax,[ebx+0xb8] |
639 | mov eax,[ebx+0xb8] |
638 | mov [edx+0xb8],eax ;copy page directory |
640 | mov [edx+0xb8],eax ;copy page directory |
639 | ; mov eax,[new_process_place] |
641 | ; mov eax,[new_process_place] |
640 | ; mov ebx,[0x3000] |
642 | ; mov ebx,[0x3000] |
641 | ; call addreference_app_cr3_table |
643 | ; call addreference_app_cr3_table |
642 | 644 | ||
643 | push 0 ;no parameters |
645 | push 0 ;no parameters |
644 | call new_start_application_fl.add_app_parameters ;start thread |
646 | call new_start_application_fl.add_app_parameters ;start thread |
645 | mov [esp+28],eax |
647 | mov [esp+28],eax |
646 | popad |
648 | popad |
647 | ret |
649 | ret |
648 | 650 | ||
649 | .failed: |
651 | .failed: |
650 | sti |
652 | sti |
651 | popad |
653 | popad |
652 | mov eax,-1 |
654 | mov eax,-1 |
653 | ret |
655 | ret |
654 | .ret: |
656 | .ret: |
655 | popad |
657 | popad |
656 | ret |
658 | ret |
657 | ;----------------------------------------------------------------------------- |
659 | ;----------------------------------------------------------------------------- |
658 | new_mem_resize: |
660 | new_mem_resize: |
659 | ;input: |
661 | ;input: |
660 | ; ebx - new size |
662 | ; ebx - new size |
661 | ;result: |
663 | ;result: |
662 | ; [esp+36]:=0 - normal |
664 | ; [esp+36]:=0 - normal |
663 | ; [esp+36]:=1 - error |
665 | ; [esp+36]:=1 - error |
664 | ;This function set new application memory size. |
666 | ;This function set new application memory size. |
665 | mov esi,ebx ;save new size |
667 | mov esi,ebx ;save new size |
666 | add ebx,4095 |
668 | add ebx,4095 |
667 | and ebx,not (4096-1) ;round up size |
669 | and ebx,not (4096-1) ;round up size |
668 | mov ecx,[0x3000] |
670 | mov ecx,[0x3000] |
669 | shl ecx,8 |
671 | shl ecx,8 |
670 | mov edx,[0x8008C+ecx] |
672 | mov edx,[0x8008C+ecx] |
671 | add edx,4095 |
673 | add edx,4095 |
672 | and edx,not (4096-1) ;old size |
674 | and edx,not (4096-1) ;old size |
673 | mov eax,[0x800B8+ecx] |
675 | mov eax,[0x800B8+ecx] |
674 | call MEM_Get_Linear_Address |
676 | call MEM_Get_Linear_Address |
675 | ;eax - linear address of page directory |
677 | ;eax - linear address of page directory |
676 | call MEM_Heap_Lock ;guarantee that two threads willn't |
678 | call MEM_Heap_Lock ;guarantee that two threads willn't |
677 | ;change memory size simultaneously |
679 | ;change memory size simultaneously |
678 | cmp ebx,edx |
680 | cmp ebx,edx |
679 | ; mov esi,ebx ;save new size |
681 | ; mov esi,ebx ;save new size |
680 | jg .expand |
682 | jg .expand |
681 | 683 | ||
682 | .free: |
684 | .free: |
683 | sub edx,ebx |
685 | sub edx,ebx |
684 | jz .unlock ;do nothing |
686 | jz .unlock ;do nothing |
685 | mov ecx,edx |
687 | mov ecx,edx |
686 | shr ecx,12 |
688 | shr ecx,12 |
687 | add ebx,std_application_base_address |
689 | add ebx,std_application_base_address |
688 | call mem_free_specified_region ;free unnecessary pages |
690 | call mem_free_specified_region ;free unnecessary pages |
689 | jmp .unlock |
691 | jmp .unlock |
690 | 692 | ||
691 | .expand: |
693 | .expand: |
692 | sub ebx,edx |
694 | sub ebx,edx |
693 | mov ecx,ebx |
695 | mov ecx,ebx |
694 | shr ecx,12 |
696 | shr ecx,12 |
695 | mov ebx,edx |
697 | mov ebx,edx |
696 | add ebx,std_application_base_address |
698 | add ebx,std_application_base_address |
697 | call mem_alloc_specified_region ;alloc necessary pages |
699 | call mem_alloc_specified_region ;alloc necessary pages |
698 | test eax,eax |
700 | test eax,eax |
699 | jz .failed ;not enough memory |
701 | jz .failed ;not enough memory |
700 | 702 | ||
701 | .unlock: |
703 | .unlock: |
702 | mov ebx,esi |
704 | mov ebx,esi |
703 | mov eax,[0x3000] |
705 | mov eax,[0x3000] |
704 | shl eax,8 |
706 | shl eax,8 |
705 | mov [eax+0x8008c],ebx ;write new memory size |
707 | mov [eax+0x8008c],ebx ;write new memory size |
706 | ;search threads and update |
708 | ;search threads and update |
707 | ;application memory size infomation |
709 | ;application memory size infomation |
708 | mov ecx,[eax+0x800b8] |
710 | mov ecx,[eax+0x800b8] |
709 | mov eax,2 |
711 | mov eax,2 |
710 | 712 | ||
711 | .search_threads: |
713 | .search_threads: |
712 | ;eax = current slot |
714 | ;eax = current slot |
713 | ;ebx = new memory size |
715 | ;ebx = new memory size |
714 | ;ecx = page directory |
716 | ;ecx = page directory |
715 | cmp eax,[0x3004] |
717 | cmp eax,[0x3004] |
716 | jg .search_threads_end |
718 | jg .search_threads_end |
717 | mov edx,eax |
719 | mov edx,eax |
718 | shl edx,5 |
720 | shl edx,5 |
719 | cmp word [0x3000+edx+0xa],9 ;if slot empty? |
721 | cmp word [0x3000+edx+0xa],9 ;if slot empty? |
720 | jz .search_threads_next |
722 | jz .search_threads_next |
721 | shl edx,3 |
723 | shl edx,3 |
722 | cmp [edx+0x800b8],ecx ;if it is our thread? |
724 | cmp [edx+0x800b8],ecx ;if it is our thread? |
723 | jnz .search_threads_next |
725 | jnz .search_threads_next |
724 | mov [edx+0x8008c],ebx ;update memory size |
726 | mov [edx+0x8008c],ebx ;update memory size |
725 | .search_threads_next: |
727 | .search_threads_next: |
726 | inc eax |
728 | inc eax |
727 | jmp .search_threads |
729 | jmp .search_threads |
728 | .search_threads_end: |
730 | .search_threads_end: |
729 | 731 | ||
730 | call MEM_Heap_UnLock |
732 | call MEM_Heap_UnLock |
731 | mov dword [esp+36],0 |
733 | mov dword [esp+36],0 |
732 | ret |
734 | ret |
733 | 735 | ||
734 | .failed: |
736 | .failed: |
735 | call MEM_Heap_UnLock |
737 | call MEM_Heap_UnLock |
736 | mov dword [esp+36],1 |
738 | mov dword [esp+36],1 |
737 | ret |
739 | ret |
738 | ;----------------------------------------------------------------------------- |
740 | ;----------------------------------------------------------------------------- |
739 | pid_to_slot: |
741 | pid_to_slot: |
740 | ;Input: |
742 | ;Input: |
741 | ; eax - pid of process |
743 | ; eax - pid of process |
742 | ;Output: |
744 | ;Output: |
743 | ; eax - slot of process or 0 if process don't exists |
745 | ; eax - slot of process or 0 if process don't exists |
744 | ;Search process by PID. |
746 | ;Search process by PID. |
745 | push ebx |
747 | push ebx |
746 | push ecx |
748 | push ecx |
747 | mov ebx,[0x3004] |
749 | mov ebx,[0x3004] |
748 | shl ebx,5 |
750 | shl ebx,5 |
749 | mov ecx,2*32 |
751 | mov ecx,2*32 |
750 | 752 | ||
751 | .loop: |
753 | .loop: |
752 | ;ecx=offset of current process info entry |
754 | ;ecx=offset of current process info entry |
753 | ;ebx=maximum permitted offset |
755 | ;ebx=maximum permitted offset |
754 | cmp byte [second_base_address+0x3000+ecx+0xa],9 |
756 | cmp byte [second_base_address+0x3000+ecx+0xa],9 |
755 | jz .endloop ;skip empty slots |
757 | jz .endloop ;skip empty slots |
756 | cmp [second_base_address+0x3000+ecx+0x4],eax ;check PID |
758 | cmp [second_base_address+0x3000+ecx+0x4],eax ;check PID |
757 | jz .pid_found |
759 | jz .pid_found |
758 | .endloop: |
760 | .endloop: |
759 | add ecx,32 |
761 | add ecx,32 |
760 | cmp ecx,ebx |
762 | cmp ecx,ebx |
761 | jle .loop |
763 | jle .loop |
762 | 764 | ||
763 | pop ecx |
765 | pop ecx |
764 | pop ebx |
766 | pop ebx |
765 | xor eax,eax |
767 | xor eax,eax |
766 | ret |
768 | ret |
767 | 769 | ||
768 | .pid_found: |
770 | .pid_found: |
769 | shr ecx,5 |
771 | shr ecx,5 |
770 | mov eax,ecx ;convert offset to index of slot |
772 | mov eax,ecx ;convert offset to index of slot |
771 | pop ecx |
773 | pop ecx |
772 | pop ebx |
774 | pop ebx |
773 | ret |
775 | ret |
774 | ;----------------------------------------------------------------------------- |
776 | ;----------------------------------------------------------------------------- |
775 | is_new_process: |
777 | is_new_process: |
776 | ;Input: |
778 | ;Input: |
777 | ; eax - process slot |
779 | ; eax - process slot |
778 | ;Output: |
780 | ;Output: |
779 | ; eax=1 - it is new process |
781 | ; eax=1 - it is new process |
780 | ; eax=0 - it is old process |
782 | ; eax=0 - it is old process |
781 | ; shl eax,5 |
783 | ; shl eax,5 |
782 | ; mov eax,[second_base_address+0x3000+eax+0x10] |
784 | ; mov eax,[second_base_address+0x3000+eax+0x10] |
783 | ; cmp eax,std_application_base_address ;check base address of application |
785 | ; cmp eax,std_application_base_address ;check base address of application |
784 | ; jz .new_process |
786 | ; jz .new_process |
785 | ; xor eax,eax |
787 | ; xor eax,eax |
786 | ; ret |
788 | ; ret |
787 | 789 | ||
788 | ;.new_process: |
790 | ;.new_process: |
789 | mov eax,1 |
791 | mov eax,1 |
790 | ret |
792 | ret |
791 | ;----------------------------------------------------------------------------- |
793 | ;----------------------------------------------------------------------------- |
792 | write_process_memory: |
794 | write_process_memory: |
793 | ;Input: |
795 | ;Input: |
794 | ; eax - process slot |
796 | ; eax - process slot |
795 | ; ebx - buffer address |
797 | ; ebx - buffer address |
796 | ; ecx - buffer size |
798 | ; ecx - buffer size |
797 | ; edx - start address in other process |
799 | ; edx - start address in other process |
798 | ;Output: |
800 | ;Output: |
799 | ; eax - number of bytes written |
801 | ; eax - number of bytes written |
800 | pushad |
802 | pushad |
801 | shl eax,8 |
803 | shl eax,8 |
802 | mov eax,[0x80000+eax+0xB8] |
804 | mov eax,[0x80000+eax+0xB8] |
803 | call MEM_Get_Linear_Address |
805 | call MEM_Get_Linear_Address |
804 | mov ebp,eax |
806 | mov ebp,eax |
805 | ;ebp=linear address of page directory of other process. |
807 | ;ebp=linear address of page directory of other process. |
806 | add edx,std_application_base_address ;convert to linear address |
808 | add edx,std_application_base_address ;convert to linear address |
807 | test ecx,ecx |
809 | test ecx,ecx |
808 | jle .ret |
810 | jle .ret |
809 | 811 | ||
810 | .write_loop: |
812 | .write_loop: |
811 | ;ebx = current buffer address |
813 | ;ebx = current buffer address |
812 | ;ecx>0 = current size |
814 | ;ecx>0 = current size |
813 | ;edx = current address in other process |
815 | ;edx = current address in other process |
814 | ;ebp = linear address of page directory |
816 | ;ebp = linear address of page directory |
815 | 817 | ||
816 | call MEM_Heap_Lock ;cli |
818 | call MEM_Heap_Lock ;cli |
817 | mov esi,edx |
819 | mov esi,edx |
818 | shr esi,22 |
820 | shr esi,22 |
819 | mov eax,[ebp+4*esi] ;find page directory entry |
821 | mov eax,[ebp+4*esi] ;find page directory entry |
820 | and eax,not (4096-1) ;clear flags |
822 | and eax,not (4096-1) ;clear flags |
821 | test eax,eax |
823 | test eax,eax |
822 | jz .page_not_found |
824 | jz .page_not_found |
823 | call MEM_Get_Linear_Address ;calculate linear address of page table |
825 | call MEM_Get_Linear_Address ;calculate linear address of page table |
824 | test eax,eax |
826 | test eax,eax |
825 | jz .page_not_found |
827 | jz .page_not_found |
826 | mov esi,edx |
828 | mov esi,edx |
827 | shr esi,12 |
829 | shr esi,12 |
828 | and esi,1023 |
830 | and esi,1023 |
829 | mov eax,[eax+4*esi] ;find page table entry |
831 | mov eax,[eax+4*esi] ;find page table entry |
830 | and eax,not (4096-1) |
832 | and eax,not (4096-1) |
831 | test eax,eax |
833 | test eax,eax |
832 | jz .page_not_found |
834 | jz .page_not_found |
833 | call MEM_Get_Linear_Address ;calculate linear address of page |
835 | call MEM_Get_Linear_Address ;calculate linear address of page |
834 | test eax,eax |
836 | test eax,eax |
835 | jz .page_not_found |
837 | jz .page_not_found |
836 | mov edi,eax |
838 | mov edi,eax |
837 | call MEM_Add_Reference_Linear;guarantee that page willn't disappear |
839 | call MEM_Add_Reference_Linear;guarantee that page willn't disappear |
838 | call MEM_Heap_UnLock ;sti |
840 | call MEM_Heap_UnLock ;sti |
839 | 841 | ||
840 | mov esi,edx |
842 | mov esi,edx |
841 | and esi,4095 |
843 | and esi,4095 |
842 | add edi,esi ;add offset in page |
844 | add edi,esi ;add offset in page |
843 | ;edi = linear address corresponding edx in other process |
845 | ;edi = linear address corresponding edx in other process |
844 | sub esi,4096 |
846 | sub esi,4096 |
845 | neg esi ;esi - number of remaining bytes in page |
847 | neg esi ;esi - number of remaining bytes in page |
846 | cmp esi,ecx |
848 | cmp esi,ecx |
847 | jl .min_ecx |
849 | jl .min_ecx |
848 | mov esi,ecx |
850 | mov esi,ecx |
849 | .min_ecx: ;esi=min(ecx,esi) - number of bytes to write |
851 | .min_ecx: ;esi=min(ecx,esi) - number of bytes to write |
850 | sub ecx,esi |
852 | sub ecx,esi |
851 | push ecx |
853 | push ecx |
852 | mov ecx,esi ;ecx - number of bytes to write |
854 | mov ecx,esi ;ecx - number of bytes to write |
853 | mov esi,ebx ;esi - source, edi - destination |
855 | mov esi,ebx ;esi - source, edi - destination |
854 | add edx,ecx ;move pointer in address space of other process |
856 | add edx,ecx ;move pointer in address space of other process |
855 | push edi |
857 | push edi |
856 | 858 | ||
857 | ;move ecx bytes |
859 | ;move ecx bytes |
858 | test ecx,3 |
860 | test ecx,3 |
859 | jnz .not_aligned |
861 | jnz .not_aligned |
860 | shr ecx,2 |
862 | shr ecx,2 |
861 | rep movsd |
863 | rep movsd |
862 | jmp .next_iter |
864 | jmp .next_iter |
863 | .not_aligned: |
865 | .not_aligned: |
864 | rep movsb |
866 | rep movsb |
865 | .next_iter: |
867 | .next_iter: |
866 | 868 | ||
867 | pop eax |
869 | pop eax |
868 | and eax,not (4096-1) ;eax - linear address of current page |
870 | and eax,not (4096-1) ;eax - linear address of current page |
869 | call MEM_Free_Page_Linear ;free reference |
871 | call MEM_Free_Page_Linear ;free reference |
870 | mov ebx,esi ;new pointer to buffer - movsb automaticaly advance it. |
872 | mov ebx,esi ;new pointer to buffer - movsb automaticaly advance it. |
871 | pop ecx ;restore number of remaining bytes |
873 | pop ecx ;restore number of remaining bytes |
872 | test ecx,ecx |
874 | test ecx,ecx |
873 | jnz .write_loop |
875 | jnz .write_loop |
874 | .ret: |
876 | .ret: |
875 | popad |
877 | popad |
876 | mov eax,ecx |
878 | mov eax,ecx |
877 | ret |
879 | ret |
878 | 880 | ||
879 | .page_not_found: |
881 | .page_not_found: |
880 | call MEM_Heap_UnLock ;error has appeared in critical region |
882 | call MEM_Heap_UnLock ;error has appeared in critical region |
881 | sub ecx,[esp+24] ;[esp+24]<-->ecx |
883 | sub ecx,[esp+24] ;[esp+24]<-->ecx |
882 | neg ecx ;ecx=number_of_written_bytes |
884 | neg ecx ;ecx=number_of_written_bytes |
883 | mov [esp+28],ecx ;[esp+28]<-->eax |
885 | mov [esp+28],ecx ;[esp+28]<-->eax |
884 | popad |
886 | popad |
885 | ret |
887 | ret |
886 | ;----------------------------------------------------------------------------- |
888 | ;----------------------------------------------------------------------------- |
887 | syscall_test: |
889 | syscall_test: |
888 | ;for testing memory manager from applications. |
890 | ;for testing memory manager from applications. |
889 | mov edx,ecx |
891 | mov edx,ecx |
890 | mov ecx,ebx |
892 | mov ecx,ebx |
891 | call trans_address |
893 | call trans_address |
892 | mov ebx,eax |
894 | mov ebx,eax |
893 | mov eax,[0x3000] |
895 | mov eax,[0x3000] |
894 | call read_process_memory |
896 | call read_process_memory |
895 | ret |
897 | ret |
896 | ;----------------------------------------------------------------------------- |
898 | ;----------------------------------------------------------------------------- |
897 | read_process_memory: |
899 | read_process_memory: |
898 | ;Input: |
900 | ;Input: |
899 | ; eax - process slot |
901 | ; eax - process slot |
900 | ; ebx - buffer address |
902 | ; ebx - buffer address |
901 | ; ecx - buffer size |
903 | ; ecx - buffer size |
902 | ; edx - start address in other process |
904 | ; edx - start address in other process |
903 | ;Output: |
905 | ;Output: |
904 | ; eax - number of bytes read. |
906 | ; eax - number of bytes read. |
905 | pushad |
907 | pushad |
906 | shl eax,8 |
908 | shl eax,8 |
907 | mov eax,[0x80000+eax+0xB8] |
909 | mov eax,[0x80000+eax+0xB8] |
908 | call MEM_Get_Linear_Address |
910 | call MEM_Get_Linear_Address |
909 | mov ebp,eax |
911 | mov ebp,eax |
910 | add edx,std_application_base_address |
912 | add edx,std_application_base_address |
911 | .read_loop: |
913 | .read_loop: |
912 | ;ebx = current buffer address |
914 | ;ebx = current buffer address |
913 | ;ecx>0 = current size |
915 | ;ecx>0 = current size |
914 | ;edx = current address in other process |
916 | ;edx = current address in other process |
915 | ;ebp = linear address of page directory |
917 | ;ebp = linear address of page directory |
916 | 918 | ||
917 | call MEM_Heap_Lock ;cli |
919 | call MEM_Heap_Lock ;cli |
918 | mov esi,edx |
920 | mov esi,edx |
919 | shr esi,22 |
921 | shr esi,22 |
920 | mov eax,[ebp+4*esi] ;find page directory entry |
922 | mov eax,[ebp+4*esi] ;find page directory entry |
921 | and eax,not (4096-1) |
923 | and eax,not (4096-1) |
922 | test eax,eax |
924 | test eax,eax |
923 | jz .page_not_found |
925 | jz .page_not_found |
924 | call MEM_Get_Linear_Address |
926 | call MEM_Get_Linear_Address |
925 | test eax,eax |
927 | test eax,eax |
926 | jz .page_not_found |
928 | jz .page_not_found |
927 | mov esi,edx |
929 | mov esi,edx |
928 | shr esi,12 |
930 | shr esi,12 |
929 | and esi,1023 |
931 | and esi,1023 |
930 | mov eax,[eax+4*esi] ;find page table entry |
932 | mov eax,[eax+4*esi] ;find page table entry |
931 | and eax,not (4096-1) |
933 | and eax,not (4096-1) |
932 | test eax,eax |
934 | test eax,eax |
933 | jz .page_not_found |
935 | jz .page_not_found |
934 | call MEM_Get_Linear_Address ;calculate linear address of page |
936 | call MEM_Get_Linear_Address ;calculate linear address of page |
935 | test eax,eax |
937 | test eax,eax |
936 | jz .page_not_found |
938 | jz .page_not_found |
937 | mov esi,eax |
939 | mov esi,eax |
938 | call MEM_Add_Reference_Linear;guarantee that page willn't disappear |
940 | call MEM_Add_Reference_Linear;guarantee that page willn't disappear |
939 | call MEM_Heap_UnLock ;sti |
941 | call MEM_Heap_UnLock ;sti |
940 | 942 | ||
941 | mov edi,edx |
943 | mov edi,edx |
942 | and edi,4095 |
944 | and edi,4095 |
943 | add esi,edi ;add offset in page |
945 | add esi,edi ;add offset in page |
944 | ;esi = linear address corresponding edx in other process |
946 | ;esi = linear address corresponding edx in other process |
945 | sub edi,4096 |
947 | sub edi,4096 |
946 | neg edi |
948 | neg edi |
947 | 949 | ||
948 | ;edi=min(edi,ecx) - number of bytes to copy |
950 | ;edi=min(edi,ecx) - number of bytes to copy |
949 | cmp edi,ecx |
951 | cmp edi,ecx |
950 | jl .min_ecx |
952 | jl .min_ecx |
951 | mov edi,ecx |
953 | mov edi,ecx |
952 | .min_ecx: |
954 | .min_ecx: |
953 | 955 | ||
954 | sub ecx,edi ;update size of remaining bytes |
956 | sub ecx,edi ;update size of remaining bytes |
955 | add edx,edi ;update current pointer in other address space. |
957 | add edx,edi ;update current pointer in other address space. |
956 | push ecx |
958 | push ecx |
957 | mov ecx,edi ;ecx - number of bytes to read |
959 | mov ecx,edi ;ecx - number of bytes to read |
958 | mov edi,ebx ;esi - source, edi - destination |
960 | mov edi,ebx ;esi - source, edi - destination |
959 | push esi |
961 | push esi |
960 | ;move ecx bytes |
962 | ;move ecx bytes |
961 | test ecx,3 |
963 | test ecx,3 |
962 | jnz .not_aligned |
964 | jnz .not_aligned |
963 | shr ecx,2 |
965 | shr ecx,2 |
964 | rep movsd |
966 | rep movsd |
965 | jmp .next_iter |
967 | jmp .next_iter |
966 | .not_aligned: |
968 | .not_aligned: |
967 | rep movsb |
969 | rep movsb |
968 | .next_iter: |
970 | .next_iter: |
969 | pop eax |
971 | pop eax |
970 | and eax,not (4096-1) ;eax - linear address of current page |
972 | and eax,not (4096-1) ;eax - linear address of current page |
971 | call MEM_Free_Page_Linear ;free reference |
973 | call MEM_Free_Page_Linear ;free reference |
972 | mov ebx,edi ;new pointer to buffer - movsb automaticaly advance it. |
974 | mov ebx,edi ;new pointer to buffer - movsb automaticaly advance it. |
973 | pop ecx ;restore number of remaining bytes |
975 | pop ecx ;restore number of remaining bytes |
974 | test ecx,ecx |
976 | test ecx,ecx |
975 | jnz .read_loop |
977 | jnz .read_loop |
976 | 978 | ||
977 | popad |
979 | popad |
978 | mov eax,ecx |
980 | mov eax,ecx |
979 | ret |
981 | ret |
980 | 982 | ||
981 | .page_not_found: |
983 | .page_not_found: |
982 | call MEM_Heap_UnLock ;error has appeared in critical region |
984 | call MEM_Heap_UnLock ;error has appeared in critical region |
983 | sub ecx,[esp+24] ;[esp+24]<-->ecx |
985 | sub ecx,[esp+24] ;[esp+24]<-->ecx |
984 | neg ecx ;ecx=number_of_read_bytes |
986 | neg ecx ;ecx=number_of_read_bytes |
985 | mov [esp+28],ecx ;[esp+28]<-->eax |
987 | mov [esp+28],ecx ;[esp+28]<-->eax |
986 | popad |
988 | popad |
987 | ret |
989 | ret |
988 | ;----------------------------------------------------------------------------- |
990 | ;----------------------------------------------------------------------------- |
989 | check_region: |
991 | check_region: |
990 | ;input: |
992 | ;input: |
991 | ; ebx - start of buffer |
993 | ; ebx - start of buffer |
992 | ; ecx - size of buffer |
994 | ; ecx - size of buffer |
993 | ;result: |
995 | ;result: |
994 | ; eax = 1 region lays in app memory |
996 | ; eax = 1 region lays in app memory |
995 | ; eax = 0 region don't lays in app memory |
997 | ; eax = 0 region don't lays in app memory |
996 | mov eax,[0x3000] |
998 | mov eax,[0x3000] |
997 | jmp check_process_region |
999 | jmp check_process_region |
998 | ;----------------------------------------------------------------------------- |
1000 | ;----------------------------------------------------------------------------- |
999 | check_process_region: |
1001 | check_process_region: |
1000 | ;input: |
1002 | ;input: |
1001 | ; eax - slot |
1003 | ; eax - slot |
1002 | ; ebx - start of buffer |
1004 | ; ebx - start of buffer |
1003 | ; ecx - size of buffer |
1005 | ; ecx - size of buffer |
1004 | ;result: |
1006 | ;result: |
1005 | ; eax = 1 region lays in app memory |
1007 | ; eax = 1 region lays in app memory |
1006 | ; eax = 0 region don't lays in app memory |
1008 | ; eax = 0 region don't lays in app memory |
1007 | test ecx,ecx |
1009 | test ecx,ecx |
1008 | jle .ok |
1010 | jle .ok |
1009 | shl eax,5 |
1011 | shl eax,5 |
1010 | cmp word [0x3000+eax+0xa],0 |
1012 | cmp word [0x3000+eax+0xa],0 |
1011 | jnz .failed |
1013 | jnz .failed |
1012 | shl eax,3 |
1014 | shl eax,3 |
1013 | mov eax,[0x80000+eax+0xb8] |
1015 | mov eax,[0x80000+eax+0xb8] |
1014 | test eax,eax |
1016 | test eax,eax |
1015 | jz .failed |
1017 | jz .failed |
1016 | call MEM_Get_Linear_Address |
1018 | call MEM_Get_Linear_Address |
1017 | push ebx |
1019 | push ebx |
1018 | push ecx |
1020 | push ecx |
1019 | push edx |
1021 | push edx |
1020 | mov edx,ebx |
1022 | mov edx,ebx |
1021 | and edx,not (4096-1) |
1023 | and edx,not (4096-1) |
1022 | sub ebx,edx |
1024 | sub ebx,edx |
1023 | add ecx,ebx |
1025 | add ecx,ebx |
1024 | mov ebx,edx |
1026 | mov ebx,edx |
1025 | add ecx,(4096-1) |
1027 | add ecx,(4096-1) |
1026 | and ecx,not (4096-1) |
1028 | and ecx,not (4096-1) |
1027 | .loop: |
1029 | .loop: |
1028 | ;eax - linear address of page directory |
1030 | ;eax - linear address of page directory |
1029 | ;ebx - current page |
1031 | ;ebx - current page |
1030 | ;ecx - current size |
1032 | ;ecx - current size |
1031 | mov edx,ebx |
1033 | mov edx,ebx |
1032 | shr edx,22 |
1034 | shr edx,22 |
1033 | mov edx,[eax+4*edx] |
1035 | mov edx,[eax+4*edx] |
1034 | and edx,not (4096-1) |
1036 | and edx,not (4096-1) |
1035 | test edx,edx |
1037 | test edx,edx |
1036 | jz .failed1 |
1038 | jz .failed1 |
1037 | push eax |
1039 | push eax |
1038 | mov eax,edx |
1040 | mov eax,edx |
1039 | call MEM_Get_Linear_Address |
1041 | call MEM_Get_Linear_Address |
1040 | mov edx,ebx |
1042 | mov edx,ebx |
1041 | shr edx,12 |
1043 | shr edx,12 |
1042 | and edx,(1024-1) |
1044 | and edx,(1024-1) |
1043 | mov eax,[eax+4*edx] |
1045 | mov eax,[eax+4*edx] |
1044 | and eax,not (4096-1) |
1046 | and eax,not (4096-1) |
1045 | test eax,eax |
1047 | test eax,eax |
1046 | pop eax |
1048 | pop eax |
1047 | jz .failed1 |
1049 | jz .failed1 |
1048 | add ebx,4096 |
1050 | add ebx,4096 |
1049 | sub ecx,4096 |
1051 | sub ecx,4096 |
1050 | jg .loop |
1052 | jg .loop |
1051 | pop edx |
1053 | pop edx |
1052 | pop ecx |
1054 | pop ecx |
1053 | pop ebx |
1055 | pop ebx |
1054 | .ok: |
1056 | .ok: |
1055 | mov eax,1 |
1057 | mov eax,1 |
1056 | ret |
1058 | ret |
1057 | 1059 | ||
1058 | .failed1: |
1060 | .failed1: |
1059 | pop edx |
1061 | pop edx |
1060 | pop ecx |
1062 | pop ecx |
1061 | pop ebx |
1063 | pop ebx |
1062 | .failed: |
1064 | .failed: |
1063 | xor eax,eax |
1065 | xor eax,eax |
1064 | ret |
1066 | ret |
1065 | ;----------------------------------------------------------------------------- |
1067 | ;----------------------------------------------------------------------------- |
1066 | new_sys_ipc: |
1068 | new_sys_ipc: |
1067 | ;input: |
1069 | ;input: |
1068 | ; eax=1 - set ipc buffer area |
1070 | ; eax=1 - set ipc buffer area |
1069 | ; ebx=address of buffer |
1071 | ; ebx=address of buffer |
1070 | ; ecx=size of buffer |
1072 | ; ecx=size of buffer |
1071 | ; eax=2 - send message |
1073 | ; eax=2 - send message |
1072 | ; ebx=PID |
1074 | ; ebx=PID |
1073 | ; ecx=address of message |
1075 | ; ecx=address of message |
1074 | ; edx=size of message |
1076 | ; edx=size of message |
1075 | cmp eax,1 |
1077 | cmp eax,1 |
1076 | jnz .no_ipc_def |
1078 | jnz .no_ipc_def |
1077 | ;set ipc buffer area |
1079 | ;set ipc buffer area |
1078 | mov edi,[0x3000] |
1080 | mov edi,[0x3000] |
1079 | shl edi,8 |
1081 | shl edi,8 |
1080 | add edi,0x80000 |
1082 | add edi,0x80000 |
1081 | cli |
1083 | cli |
1082 | mov [edi+0xA0],ebx ;set fields in extended information area |
1084 | mov [edi+0xA0],ebx ;set fields in extended information area |
1083 | mov [edi+0xA4],ecx |
1085 | mov [edi+0xA4],ecx |
1084 | sti |
1086 | sti |
1085 | mov [esp+36],dword 0 ;success |
1087 | mov [esp+36],dword 0 ;success |
1086 | ret |
1088 | ret |
1087 | 1089 | ||
1088 | .no_ipc_def: |
1090 | .no_ipc_def: |
1089 | cmp eax,2 |
1091 | cmp eax,2 |
1090 | jnz .no_ipc_send |
1092 | jnz .no_ipc_send |
1091 | ;send message |
1093 | ;send message |
1092 | cli |
1094 | cli |
1093 | ;obtain slot from PID |
1095 | ;obtain slot from PID |
1094 | mov eax,ebx |
1096 | mov eax,ebx |
1095 | call pid_to_slot |
1097 | call pid_to_slot |
1096 | test eax,eax |
1098 | test eax,eax |
1097 | jz .no_pid |
1099 | jz .no_pid |
1098 | mov ebp,eax |
1100 | mov ebp,eax |
1099 | ;ebp = slot of other process |
1101 | ;ebp = slot of other process |
1100 | shl eax,8 |
1102 | shl eax,8 |
1101 | mov edi,[eax+0x80000+0xa0] ;is ipc area defined? |
1103 | mov edi,[eax+0x80000+0xa0] ;is ipc area defined? |
1102 | test edi,edi |
1104 | test edi,edi |
1103 | jz .no_ipc_area |
1105 | jz .no_ipc_area |
1104 | mov esi,[eax+0x80000+0xa4] ;esi - size of buffer |
1106 | mov esi,[eax+0x80000+0xa4] ;esi - size of buffer |
1105 | push dword -1 ;temp variable for read_process_memory |
1107 | push dword -1 ;temp variable for read_process_memory |
1106 | mov ebx,esp |
1108 | mov ebx,esp |
1107 | push ecx |
1109 | push ecx |
1108 | push edx |
1110 | push edx |
1109 | mov ecx,4 ;read 4 bytes |
1111 | mov ecx,4 ;read 4 bytes |
1110 | mov eax,ebp |
1112 | mov eax,ebp |
1111 | mov edx,edi ;from beginning of buffer. |
1113 | mov edx,edi ;from beginning of buffer. |
1112 | call read_process_memory |
1114 | call read_process_memory |
1113 | mov eax,[esp+8] |
1115 | mov eax,[esp+8] |
1114 | test eax,eax |
1116 | test eax,eax |
1115 | jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now |
1117 | jnz .ipc_blocked ;if dword [buffer]<>0 - ipc blocked now |
1116 | add edx,4 ;move to next 4 bytes |
1118 | add edx,4 ;move to next 4 bytes |
1117 | mov eax,ebp |
1119 | mov eax,ebp |
1118 | call read_process_memory ;read size of occupied space in buffer |
1120 | call read_process_memory ;read size of occupied space in buffer |
1119 | sub esi,8 |
1121 | sub esi,8 |
1120 | sub esi,[esp] |
1122 | sub esi,[esp] |
1121 | sub esi,[esp+8] ;esi=(buffer size)-(occupied size)-(message size)-(header of message size) |
1123 | sub esi,[esp+8] ;esi=(buffer size)-(occupied size)-(message size)-(header of message size) |
1122 | js .buffer_overflow ;esi<0 - not enough memory in buffer |
1124 | js .buffer_overflow ;esi<0 - not enough memory in buffer |
1123 | mov esi,[esp+8] ;previous offset |
1125 | mov esi,[esp+8] ;previous offset |
1124 | add dword [esp+8],8 |
1126 | add dword [esp+8],8 |
1125 | mov edi,[esp] |
1127 | mov edi,[esp] |
1126 | add [esp+8],edi ;add (size of message)+(size of header of message) to [buffer+4] |
1128 | add [esp+8],edi ;add (size of message)+(size of header of message) to [buffer+4] |
1127 | mov eax,ebp |
1129 | mov eax,ebp |
1128 | call write_process_memory |
1130 | call write_process_memory |
1129 | add edx,esi |
1131 | add edx,esi |
1130 | sub edx,4 ;move to beginning of place for our message |
1132 | sub edx,4 ;move to beginning of place for our message |
1131 | mov eax,[second_base_address+0x3010] |
1133 | mov eax,[second_base_address+0x3010] |
1132 | mov eax,[eax+0x4] ;eax - our PID |
1134 | mov eax,[eax+0x4] ;eax - our PID |
1133 | mov [esp+8],eax |
1135 | mov [esp+8],eax |
1134 | mov eax,ebp |
1136 | mov eax,ebp |
1135 | call write_process_memory ;write PID |
1137 | call write_process_memory ;write PID |
1136 | mov ebx,esp ;address of size of message |
1138 | mov ebx,esp ;address of size of message |
1137 | mov eax,ebp |
1139 | mov eax,ebp |
1138 | add edx,4 |
1140 | add edx,4 |
1139 | call write_process_memory ;write size of message |
1141 | call write_process_memory ;write size of message |
1140 | add edx,4 |
1142 | add edx,4 |
1141 | pop ecx ;ecx - size of message |
1143 | pop ecx ;ecx - size of message |
1142 | pop eax |
1144 | pop eax |
1143 | call trans_address |
1145 | call trans_address |
1144 | mov ebx,eax ;ebx - linear address of message |
1146 | mov ebx,eax ;ebx - linear address of message |
1145 | add esp,4 ;pop temporary variable |
1147 | add esp,4 ;pop temporary variable |
1146 | mov eax,ebp |
1148 | mov eax,ebp |
1147 | call write_process_memory ;write message |
1149 | call write_process_memory ;write message |
1148 | sti |
1150 | sti |
1149 | ;awake other process |
1151 | ;awake other process |
1150 | shl ebp,8 |
1152 | shl ebp,8 |
1151 | mov eax,ebp |
1153 | mov eax,ebp |
1152 | or [eax+0x800A8],dword 0x40 |
1154 | or [eax+0x800A8],dword 0x40 |
1153 | 1155 | ||
1154 | cmp dword [check_idle_semaphore],20 |
1156 | cmp dword [check_idle_semaphore],20 |
1155 | jge .ipc_no_cis |
1157 | jge .ipc_no_cis |
1156 | mov dword [check_idle_semaphore],5 |
1158 | mov dword [check_idle_semaphore],5 |
1157 | .ipc_no_cis: |
1159 | .ipc_no_cis: |
1158 | mov dword [esp+36],0 |
1160 | mov dword [esp+36],0 |
1159 | ret |
1161 | ret |
1160 | .no_ipc_send: |
1162 | .no_ipc_send: |
1161 | mov dword [esp+36],-1 |
1163 | mov dword [esp+36],-1 |
1162 | ret |
1164 | ret |
1163 | .no_pid: |
1165 | .no_pid: |
1164 | sti |
1166 | sti |
1165 | mov dword [esp+36],4 |
1167 | mov dword [esp+36],4 |
1166 | ret |
1168 | ret |
1167 | .no_ipc_area: |
1169 | .no_ipc_area: |
1168 | sti |
1170 | sti |
1169 | mov dword [esp+36],1 |
1171 | mov dword [esp+36],1 |
1170 | ret |
1172 | ret |
1171 | .ipc_blocked: |
1173 | .ipc_blocked: |
1172 | sti |
1174 | sti |
1173 | add esp,12 |
1175 | add esp,12 |
1174 | mov dword [esp+36],2 |
1176 | mov dword [esp+36],2 |
1175 | ret |
1177 | ret |
1176 | .buffer_overflow: |
1178 | .buffer_overflow: |
1177 | sti |
1179 | sti |
1178 | add esp,12 |
1180 | add esp,12 |
1179 | mov dword [esp+36],3 |
1181 | mov dword [esp+36],3 |
1180 | ret |
1182 | ret |
1181 | ;----------------------------------------------------------------------------- |
1183 | ;----------------------------------------------------------------------------- |
1182 | trans_address: |
1184 | trans_address: |
1183 | ;Input |
1185 | ;Input |
1184 | ; eax - application address |
1186 | ; eax - application address |
1185 | ;Output |
1187 | ;Output |
1186 | ; eax - linear address for kernel |
1188 | ; eax - linear address for kernel |
1187 | add eax,std_application_base_address |
1189 | add eax,std_application_base_address |
1188 | ret |
1190 | ret |
1189 | ;----------------------------------------------------------------------------- |
1191 | ;----------------------------------------------------------------------------- |
1190 | new_start_application_hd: |
1192 | new_start_application_hd: |
1191 | ;eax - file name (kernel address) |
1193 | ;eax - file name (kernel address) |
1192 | ;ebx - file name length |
1194 | ;ebx - file name length |
1193 | ;ecx - work area (kernel address) |
1195 | ;ecx - work area (kernel address) |
1194 | ;edx - flags |
1196 | ;edx - flags |
1195 | ;ebp - parameters |
1197 | ;ebp - parameters |
1196 | mov [appl_path],edi |
1198 | mov [appl_path],edi |
1197 | pushad |
1199 | pushad |
1198 | 1200 | ||
1199 | mov esi,new_process_loading |
1201 | mov esi,new_process_loading |
1200 | call sys_msg_board_str ;write message to message board |
1202 | call sys_msg_board_str ;write message to message board |
1201 | 1203 | ||
1202 | ;lock application_table_status mutex |
1204 | ;lock application_table_status mutex |
1203 | .table_status: |
1205 | .table_status: |
1204 | cli |
1206 | cli |
1205 | cmp [application_table_status],0 |
1207 | cmp [application_table_status],0 |
1206 | jz .stf |
1208 | jz .stf |
1207 | sti |
1209 | sti |
1208 | call change_task |
1210 | call change_task |
1209 | jmp .table_status |
1211 | jmp .table_status |
1210 | .stf: |
1212 | .stf: |
1211 | call set_application_table_status |
1213 | call set_application_table_status |
1212 | 1214 | ||
1213 | push ebp |
1215 | push ebp |
1214 | push ebx |
1216 | push ebx |
1215 | push eax |
1217 | push eax |
1216 | push ecx |
1218 | push ecx |
1217 | call find_new_process_place ;find new process slot |
1219 | call find_new_process_place ;find new process slot |
1218 | sti |
1220 | sti |
1219 | test eax,eax |
1221 | test eax,eax |
1220 | mov ecx, -0x20 ; too many processes |
1222 | mov ecx, -0x20 ; too many processes |
1221 | jz .failed |
1223 | jz .failed |
1222 | 1224 | ||
1223 | ;write application name |
1225 | ;write application name |
1224 | xor eax,eax |
1226 | xor eax,eax |
1225 | mov [appl_path_size],eax |
1227 | mov [appl_path_size],eax |
1226 | mov eax,[esp+4] |
1228 | mov eax,[esp+4] |
1227 | .find_last_byte: |
1229 | .find_last_byte: |
1228 | cmp byte [eax],0 |
1230 | cmp byte [eax],0 |
1229 | jz .find_last_byte_end |
1231 | jz .find_last_byte_end |
1230 | inc eax |
1232 | inc eax |
1231 | inc [appl_path_size] |
1233 | inc [appl_path_size] |
1232 | jmp .find_last_byte |
1234 | jmp .find_last_byte |
1233 | .find_last_byte_end: |
1235 | .find_last_byte_end: |
1234 | add [appl_path_size],24 |
1236 | add [appl_path_size],24 |
1235 | lea esi,[eax-11] ;last 11 bytes = application name |
1237 | lea esi,[eax-11] ;last 11 bytes = application name |
1236 | mov edi,[new_process_place] |
1238 | mov edi,[new_process_place] |
1237 | shl edi,8 |
1239 | shl edi,8 |
1238 | add edi,0x80000 |
1240 | add edi,0x80000 |
1239 | mov ecx,11 |
1241 | mov ecx,11 |
1240 | cld |
1242 | cld |
1241 | rep movsb ;copy name to extended information about process |
1243 | rep movsb ;copy name to extended information about process |
1242 | 1244 | ||
1243 | ;read header |
1245 | ;read header |
1244 | mov eax,[esp+4] ;file name |
1246 | mov eax,[esp+4] ;file name |
1245 | mov esi,[esp] ;work area |
1247 | mov esi,[esp] ;work area |
1246 | mov ecx,1 ;read from first block |
1248 | mov ecx,1 ;read from first block |
1247 | mov edx,1 ;read 1 block |
1249 | mov edx,1 ;read 1 block |
1248 | call read_hd_file |
1250 | call read_hd_file |
1249 | mov ecx, eax |
1251 | mov ecx, eax |
1250 | neg ecx |
1252 | neg ecx |
1251 | jnz .cleanfailed |
1253 | jnz .cleanfailed |
1252 | 1254 | ||
1253 | pop esi |
1255 | pop esi |
1254 | push esi |
1256 | push esi |
1255 | ;check menuet signature |
1257 | ;check menuet signature |
1256 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
1258 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
1257 | cmp [esi+1024+0],dword 'MENU' ;read_hd_file function write file to +1024 offset |
1259 | cmp [esi+1024+0],dword 'MENU' ;read_hd_file function write file to +1024 offset |
1258 | jnz .cleanfailed |
1260 | jnz .cleanfailed |
1259 | cmp [esi+1024+4],word 'ET' |
1261 | cmp [esi+1024+4],word 'ET' |
1260 | jnz .cleanfailed |
1262 | jnz .cleanfailed |
1261 | add esi,1024 |
1263 | add esi,1024 |
1262 | mov edi,0x90000 |
1264 | mov edi,0x90000 |
1263 | mov ecx,512/4 |
1265 | mov ecx,512/4 |
1264 | cld |
1266 | cld |
1265 | rep movsd ;copy first block to 0x90000 address for get_app_params function |
1267 | rep movsd ;copy first block to 0x90000 address for get_app_params function |
1266 | call get_app_params |
1268 | call get_app_params |
1267 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
1269 | mov ecx, -0x1F ; not Menuet/Kolibri executable |
1268 | test esi,esi |
1270 | test esi,esi |
1269 | jz .cleanfailed |
1271 | jz .cleanfailed |
1270 | 1272 | ||
1271 | mov eax,[new_process_place] |
1273 | mov eax,[new_process_place] |
- | 1274 | inc ecx ; -0x1E = no memory |
|
1272 | call create_app_cr3_table ;create page directory |
1275 | call create_app_cr3_table ;create page directory |
1273 | test eax,eax |
1276 | test eax,eax |
1274 | inc ecx ; -0x1E = no memory |
- | |
1275 | jz .cleanfailed_mem |
1277 | jz .cleanfailed_mem |
1276 | 1278 | ||
1277 | call MEM_Get_Linear_Address |
1279 | call MEM_Get_Linear_Address |
1278 | 1280 | ||
1279 | mov ebx,std_application_base_address |
1281 | mov ebx,std_application_base_address |
1280 | mov ecx,[app_mem] |
1282 | mov ecx,[app_mem] |
1281 | add ecx,4096-1 |
1283 | add ecx,4096-1 |
1282 | shr ecx,12 |
1284 | shr ecx,12 |
1283 | mov edx,eax ;edx - linear address of page directory |
1285 | mov edx,eax ;edx - linear address of page directory |
1284 | call mem_alloc_specified_region ;allocate memory for application |
1286 | call mem_alloc_specified_region ;allocate memory for application |
1285 | mov ecx, -0x1E ; no memory |
1287 | mov ecx, -0x1E ; no memory |
1286 | test eax,eax |
1288 | test eax,eax |
1287 | jz .cleanfailed_mem1 |
1289 | jz .cleanfailed_mem1 |
1288 | 1290 | ||
1289 | add edx,(std_application_base_address shr 20) |
1291 | add edx,(std_application_base_address shr 20) |
1290 | mov eax,[edx] |
1292 | mov eax,[edx] |
1291 | and eax,not (4096-1) |
1293 | and eax,not (4096-1) |
1292 | call MEM_Get_Linear_Address |
1294 | call MEM_Get_Linear_Address |
1293 | push edx ;save pointer to first page table |
1295 | push edx ;save pointer to first page table |
1294 | mov edx,eax |
1296 | mov edx,eax |
1295 | ;read file |
1297 | ;read file |
1296 | mov ecx,1 |
1298 | mov ecx,1 |
1297 | xor ebp,ebp |
1299 | xor ebp,ebp |
1298 | .loop1: |
1300 | .loop1: |
1299 | ;[esp] - pointer to current page directory entry |
1301 | ;[esp] - pointer to current page directory entry |
1300 | ;edx - pointer to current page table |
1302 | ;edx - pointer to current page table |
1301 | ;ebp - offset in page |
1303 | ;ebp - offset in page |
1302 | ;ecx - current cluster |
1304 | ;ecx - current cluster |
1303 | push edx |
1305 | push edx |
1304 | mov eax,[esp+12] ;file name |
1306 | mov eax,[esp+12] ;file name |
1305 | mov ebx,[esp+16] ;file name length |
1307 | mov ebx,[esp+16] ;file name length |
1306 | mov esi,[esp+8] ;work area |
1308 | mov esi,[esp+8] ;work area |
1307 | mov edx,1 ;number of blocks to read |
1309 | mov edx,1 ;number of blocks to read |
1308 | push ecx |
1310 | push ecx |
1309 | push ebp |
1311 | push ebp |
1310 | cli |
1312 | cli |
1311 | call read_hd_file |
1313 | call read_hd_file |
1312 | sti |
1314 | sti |
1313 | pop ebp |
1315 | pop ebp |
1314 | test eax,eax |
1316 | test eax,eax |
1315 | jnz .endloop1 ;check io errors |
1317 | jnz .endloop1 ;check io errors |
1316 | 1318 | ||
1317 | mov esi,[esp+8+4] ;work area |
1319 | mov esi,[esp+8+4] ;work area |
1318 | add esi,1024 |
1320 | add esi,1024 |
1319 | mov eax,[esp+4] ;current page table |
1321 | mov eax,[esp+4] ;current page table |
1320 | mov eax,[eax] |
1322 | mov eax,[eax] |
1321 | and eax,not (4096-1) |
1323 | and eax,not (4096-1) |
1322 | call MEM_Get_Linear_Address;calculate linear page address |
1324 | call MEM_Get_Linear_Address;calculate linear page address |
1323 | lea edi,[eax+ebp] ;add page offset |
1325 | lea edi,[eax+ebp] ;add page offset |
1324 | mov ecx,512/4 |
1326 | mov ecx,512/4 |
1325 | cld |
1327 | cld |
1326 | rep movsd ;copy data |
1328 | rep movsd ;copy data |
1327 | 1329 | ||
1328 | pop ecx |
1330 | pop ecx |
1329 | inc ecx ;next block |
1331 | inc ecx ;next block |
1330 | mov eax,[app_i_end] ;todo: precalculate ([app_i_end]+4095)/4096 |
1332 | mov eax,[app_i_end] ;todo: precalculate ([app_i_end]+4095)/4096 |
1331 | add eax,512-1 |
1333 | add eax,512-1 |
1332 | shr eax,9 ;calculate application image size |
1334 | shr eax,9 ;calculate application image size |
1333 | cmp ecx,eax |
1335 | cmp ecx,eax |
1334 | jg .endloop11 |
1336 | jg .endloop11 |
1335 | pop edx |
1337 | pop edx |
1336 | add ebp,512 ;new offset |
1338 | add ebp,512 ;new offset |
1337 | test ebp,4096 |
1339 | test ebp,4096 |
1338 | jz .loop1 |
1340 | jz .loop1 |
1339 | xor ebp,ebp |
1341 | xor ebp,ebp |
1340 | add edx,4 ;go to next page |
1342 | add edx,4 ;go to next page |
1341 | test edx,(4096-1) |
1343 | test edx,(4096-1) |
1342 | jnz .loop1 |
1344 | jnz .loop1 |
1343 | add dword [esp],4 ;go to next directory entry |
1345 | add dword [esp],4 ;go to next directory entry |
1344 | mov eax,[esp] |
1346 | mov eax,[esp] |
1345 | mov eax,[eax] |
1347 | mov eax,[eax] |
1346 | and eax,not (4096-1) |
1348 | and eax,not (4096-1) |
1347 | call MEM_Get_Linear_Address |
1349 | call MEM_Get_Linear_Address |
1348 | mov edx,eax |
1350 | mov edx,eax |
1349 | jmp .loop1 |
1351 | jmp .loop1 |
1350 | .endloop1: |
1352 | .endloop1: |
1351 | add esp,4 ;pop ecx |
1353 | add esp,4 ;pop ecx |
1352 | .endloop11: |
1354 | .endloop11: |
1353 | add esp,4+4 ;pop edx, pop edx |
1355 | add esp,4+4 ;pop edx, pop edx |
1354 | 1356 | ||
1355 | ;add_app_parameters |
1357 | ;add_app_parameters |
1356 | add esp,12 ;now pointer to parameters is on the top of the stack |
1358 | add esp,12 ;now pointer to parameters is on the top of the stack |
1357 | call new_start_application_fl.add_app_parameters ;start process |
1359 | call new_start_application_fl.add_app_parameters ;start process |
1358 | mov [esp+28],eax |
1360 | mov [esp+28],eax |
1359 | popad |
1361 | popad |
1360 | ret |
1362 | ret |
1361 | 1363 | ||
1362 | .cleanfailed_mem1: |
1364 | .cleanfailed_mem1: |
1363 | ;there is mem for directory entry, but there is no mem for pages |
1365 | ;there is mem for directory entry, but there is no mem for pages |
1364 | ;so free directory entry |
1366 | ;so free directory entry |
1365 | mov eax,[new_process_place] |
1367 | mov eax,[new_process_place] |
1366 | shl eax,8 |
1368 | shl eax,8 |
1367 | mov eax,[0x80000+eax+0xB8] |
1369 | mov eax,[0x80000+eax+0xB8] |
1368 | call MEM_Free_Page |
1370 | call MEM_Free_Page |
1369 | .cleanfailed_mem: |
1371 | .cleanfailed_mem: |
1370 | ;there is no mem for directory entry, display message. |
1372 | ;there is no mem for directory entry, display message. |
1371 | mov esi,start_not_enough_memory |
1373 | mov esi,start_not_enough_memory |
1372 | call sys_msg_board_str |
1374 | call sys_msg_board_str |
1373 | .cleanfailed: ;clean process name |
1375 | .cleanfailed: ;clean process name |
1374 | push ecx |
1376 | push ecx |
1375 | ;can't read file, clean process name. |
1377 | ;can't read file, clean process name. |
1376 | ;this avoid problems with panel application. |
1378 | ;this avoid problems with panel application. |
1377 | mov edi,[new_process_place] |
1379 | mov edi,[new_process_place] |
1378 | shl edi,8 |
1380 | shl edi,8 |
1379 | add edi,0x80000 |
1381 | add edi,0x80000 |
1380 | mov ecx,11 |
1382 | mov ecx,11 |
1381 | mov eax,' ' |
1383 | mov eax,' ' |
1382 | cld |
1384 | cld |
1383 | rep stosb |
1385 | rep stosb |
1384 | pop eax |
1386 | pop eax |
1385 | .failed: |
1387 | .failed: |
1386 | ;no more slots |
1388 | ;no more slots |
1387 | add esp,16 |
1389 | add esp,16 |
1388 | mov [esp+1Ch], eax |
1390 | mov [esp+1Ch], eax |
1389 | popad |
1391 | popad |
1390 | mov [application_table_status],0 |
1392 | mov [application_table_status],0 |
1391 | sti |
1393 | sti |
1392 | ret |
1394 | ret |
1393 | end if |
1395 | end if |
- | 1396 | ||
1394 | 1397 | ; \begin{diamond} |
|
- | 1398 | include 'debug.inc' |
|
- | 1399 | ||
- | 1400 | fs_execute: |
|
- | 1401 | ; ebx - cmdline |
|
- | 1402 | ; edx - flags |
|
- | 1403 | ; ebp - full filename |
|
- | 1404 | ; [esp+4] = procedure DoRead, [esp+8] = filesize & [esp+12]... - arguments for it |
|
- | 1405 | pushad |
|
- | 1406 | ; check filename length - with terminating NULL must be no more than 1024 symbols |
|
- | 1407 | mov edi, ebp |
|
- | 1408 | mov ecx, 1024 |
|
- | 1409 | xor eax, eax |
|
- | 1410 | repnz scasb |
|
- | 1411 | jz @f |
|
- | 1412 | popad |
|
- | 1413 | mov eax, -ERROR_FILE_NOT_FOUND |
|
- | 1414 | ret |
|
- | 1415 | @@: |
|
- | 1416 | ||
- | 1417 | mov esi, new_process_loading |
|
- | 1418 | call sys_msg_board_str ; write message to message board |
|
- | 1419 | ||
- | 1420 | ; lock application_table_status mutex |
|
- | 1421 | .table_status: |
|
- | 1422 | cli |
|
- | 1423 | cmp [application_table_status], 0 |
|
- | 1424 | jz .stf |
|
- | 1425 | sti |
|
- | 1426 | call change_task |
|
- | 1427 | jmp .table_status |
|
- | 1428 | .stf: |
|
- | 1429 | call set_application_table_status |
|
- | 1430 | push ebx ; save command line pointer for add_app_parameters |
|
- | 1431 | ||
- | 1432 | call find_new_process_place ; find new process slot |
|
- | 1433 | call safe_sti |
|
- | 1434 | test eax, eax |
|
- | 1435 | mov ecx, -0x20 ; too many processes |
|
- | 1436 | jz .failed |
|
- | 1437 | ||
- | 1438 | ; write application name |
|
- | 1439 | push edi |
|
- | 1440 | mov ecx, edi |
|
- | 1441 | sub ecx, ebp |
|
- | 1442 | mov [appl_path], ebp |
|
- | 1443 | mov [appl_path_size], ecx |
|
- | 1444 | dec edi |
|
- | 1445 | std |
|
- | 1446 | mov al, '/' |
|
- | 1447 | repnz scasb |
|
- | 1448 | cld |
|
- | 1449 | jnz @f |
|
- | 1450 | inc edi |
|
- | 1451 | @@: |
|
- | 1452 | inc edi |
|
- | 1453 | ; now edi points to name without path |
|
- | 1454 | mov esi, edi |
|
- | 1455 | mov ecx, 8 ; 8 chars for name |
|
- | 1456 | mov edi, [new_process_place] |
|
- | 1457 | shl edi, cl |
|
- | 1458 | add edi, 0x80000 |
|
- | 1459 | .copy_process_name_loop: |
|
- | 1460 | lodsb |
|
- | 1461 | cmp al, '.' |
|
- | 1462 | jz .copy_process_name_done |
|
- | 1463 | test al, al |
|
- | 1464 | jz .copy_process_name_done |
|
- | 1465 | stosb |
|
- | 1466 | loop .copy_process_name_loop |
|
- | 1467 | .copy_process_name_done: |
|
- | 1468 | mov al, ' ' |
|
- | 1469 | rep stosb |
|
- | 1470 | pop eax |
|
- | 1471 | mov cl, 3 ; 3 chars for extension |
|
- | 1472 | dec esi |
|
- | 1473 | @@: |
|
- | 1474 | dec eax |
|
- | 1475 | cmp eax, esi |
|
- | 1476 | jbe .copy_process_ext_done |
|
- | 1477 | cmp byte [eax], '.' |
|
- | 1478 | jnz @b |
|
- | 1479 | lea esi, [eax+1] |
|
- | 1480 | .copy_process_ext_loop: |
|
- | 1481 | lodsb |
|
- | 1482 | test al, al |
|
- | 1483 | jz .copy_process_ext_done |
|
- | 1484 | stosb |
|
- | 1485 | loop .copy_process_ext_loop |
|
- | 1486 | .copy_process_ext_done: |
|
- | 1487 | mov al, ' ' |
|
- | 1488 | rep stosb |
|
- | 1489 | ||
- | 1490 | ; read header |
|
- | 1491 | lea eax, [esp+8+36] |
|
- | 1492 | mov edi, 0x90000 |
|
- | 1493 | call dword [eax-4] |
|
- | 1494 | mov ecx, eax |
|
- | 1495 | neg ecx |
|
- | 1496 | jnz .cleanfailed |
|
- | 1497 | ; check menuet signature |
|
- | 1498 | mov ecx, -0x1F |
|
- | 1499 | cmp dword [0x90000], 'MENU' |
|
- | 1500 | jnz .cleanfailed |
|
- | 1501 | cmp word [0x90004], 'ET' |
|
- | 1502 | jnz .cleanfailed |
|
- | 1503 | call get_app_params |
|
- | 1504 | mov ecx, -0x1F |
|
- | 1505 | test esi, esi |
|
- | 1506 | jz .cleanfailed |
|
- | 1507 | ||
- | 1508 | mov eax, [new_process_place] |
|
- | 1509 | inc ecx ; -0x1E = no memory |
|
- | 1510 | call create_app_cr3_table |
|
- | 1511 | test eax, eax |
|
- | 1512 | jz .cleanfailed_mem |
|
- | 1513 | ||
- | 1514 | call MEM_Get_Linear_Address |
|
- | 1515 | ||
- | 1516 | mov ebx, std_application_base_address |
|
- | 1517 | mov ecx, [app_mem] |
|
- | 1518 | add ecx, 4095 |
|
- | 1519 | shr ecx, 12 |
|
- | 1520 | mov edx, eax ; edx - linear address of page directory |
|
- | 1521 | call mem_alloc_specified_region |
|
- | 1522 | mov ecx, -0x1E ; no memory |
|
- | 1523 | test eax, eax |
|
- | 1524 | jz .cleanfailed_mem1 |
|
- | 1525 | ||
- | 1526 | add edx, std_application_base_address shr 20 |
|
- | 1527 | mov eax, [edx] |
|
- | 1528 | and eax, not 4095 |
|
- | 1529 | call MEM_Get_Linear_Address |
|
- | 1530 | push edx ; save pointer to first page table |
|
- | 1531 | mov edx, eax |
|
- | 1532 | ; read file |
|
- | 1533 | ; first block is already read to 0x90000 |
|
- | 1534 | mov eax, [edx] |
|
- | 1535 | and eax, not 0xFFF |
|
- | 1536 | call MEM_Get_Linear_Address |
|
- | 1537 | mov esi, 0x90000 |
|
- | 1538 | mov edi, eax |
|
- | 1539 | mov ecx, 512/4 |
|
- | 1540 | rep movsd |
|
- | 1541 | sub edi, eax |
|
- | 1542 | .loop1: |
|
- | 1543 | ; [esp] = pointer to current page directory entry |
|
- | 1544 | ; edx = pointer to current page table |
|
- | 1545 | ; edi = offset in page |
|
- | 1546 | mov eax, [edx] |
|
- | 1547 | and eax, not 0xFFF |
|
- | 1548 | call MEM_Get_Linear_Address |
|
- | 1549 | push edi |
|
- | 1550 | add edi, eax |
|
- | 1551 | lea eax, [esp+8+36+8] |
|
- | 1552 | call dword [eax-4] |
|
- | 1553 | pop edi |
|
- | 1554 | test eax, eax |
|
- | 1555 | jnz .endloop1 |
|
- | 1556 | add edi, 512 ; new offset |
|
- | 1557 | cmp edi, 4096 |
|
- | 1558 | jb .loop1 |
|
- | 1559 | xor edi, edi |
|
- | 1560 | add edx, 4 ; go to next page |
|
- | 1561 | test edx, 4096-1 |
|
- | 1562 | jnz .loop1 |
|
- | 1563 | pop eax |
|
- | 1564 | add eax, 4 ; go to next directory entry |
|
- | 1565 | push eax |
|
- | 1566 | mov eax, [eax] |
|
- | 1567 | and eax, not 0xFFF |
|
- | 1568 | call MEM_Get_Linear_Address |
|
- | 1569 | mov edx, eax |
|
- | 1570 | jmp .loop1 |
|
- | 1571 | .endloop1: |
|
- | 1572 | pop edx |
|
- | 1573 | cmp eax, 6 |
|
- | 1574 | jnz .cleanfailed_mem2 |
|
- | 1575 | call new_start_application_fl.add_app_parameters |
|
- | 1576 | mov [esp+28], eax |
|
- | 1577 | popad |
|
- | 1578 | ret |
|
- | 1579 | ||
- | 1580 | .cleanfailed_mem2: |
|
- | 1581 | ; file read error; free all allocated mem |
|
- | 1582 | mov ecx, eax |
|
- | 1583 | neg ecx |
|
- | 1584 | mov eax, [new_process_place] |
|
- | 1585 | call dispose_app_cr3_table |
|
- | 1586 | jmp .cleanfailed |
|
- | 1587 | .cleanfailed_mem1: |
|
- | 1588 | ; there is mem for directory entry, but there is no mem for pages |
|
- | 1589 | ; so free directory entry |
|
- | 1590 | mov eax, [new_process_place] |
|
- | 1591 | shl eax, 8 |
|
- | 1592 | mov eax, [0x80000+eax+0xB8] |
|
- | 1593 | call MEM_Free_Page |
|
- | 1594 | .cleanfailed_mem: |
|
- | 1595 | ; there is no mem for directory entry, display message |
|
- | 1596 | mov esi, start_not_enough_memory |
|
- | 1597 | call sys_msg_board_str |
|
- | 1598 | .cleanfailed: |
|
- | 1599 | push ecx |
|
- | 1600 | ; clean process name, this avoid problems with @panel |
|
- | 1601 | mov edi, [new_process_place] |
|
- | 1602 | shl edi, 8 |
|
- | 1603 | add edi, 0x80000 |
|
- | 1604 | mov ecx, 11 |
|
- | 1605 | mov al, ' ' |
|
- | 1606 | rep stosb |
|
- | 1607 | pop eax |
|
- | 1608 | .failed: |
|
- | 1609 | pop ebx |
|
- | 1610 | mov [esp+28], eax |
|
- | 1611 | popad |
|
- | 1612 | mov [application_table_status], 0 |
|
- | 1613 | call safe_sti |
|
- | 1614 | ret |
|
1395 | include 'debug.inc'0>>-->-->-->-->256 |
1615 | ; \end{diamond}0>>-->-->-->-->256 |
1396 | >> |
1616 | >> |