Subversion Repositories Kolibri OS

Rev

Rev 2455 | Rev 2498 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

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