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