Subversion Repositories Kolibri OS

Rev

Rev 3145 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 serge 1
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
2
;;                                                              ;;
2540 hidnplayr 3
;; Copyright (C) KolibriOS team 2004-2011. All rights reserved. ;;
431 serge 4
;; Distributed under terms of the GNU General Public License    ;;
5
;;                                                              ;;
6
;;                                                              ;;
7
;;  MenuetOS process management, protected ring3                ;;
8
;;                                                              ;;
9
;;  Distributed under GPL. See file COPYING for details.        ;;
10
;;  Copyright 2003 Ville Turjanmaa                              ;;
11
;;                                                              ;;
12
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 13
 
2540 hidnplayr 14
$Revision $
593 mikedld 15
 
16
 
1056 Galkov 17
align 4 ;3A08
1 ha 18
build_interrupt_table:
2382 hidnplayr 19
        mov     edi, idts
20
        mov     esi, sys_int
21
        mov     ecx, 0x40
22
        mov     eax, (10001110b shl 24) + os_code
23
  @@:
24
        movsw   ;low word of code-entry
25
        stosd   ;interrupt gate type : os_code selector
26
        movsw   ;high word of code-entry
27
        loop    @b
28
        movsd   ;copy low  dword of trap gate for int 0x40
29
        movsd   ;copy high dword of trap gate for int 0x40
30
        lidt    [esi]
31
        ret
1 ha 32
 
1056 Galkov 33
iglobal
34
  align 4
35
  sys_int:
36
    ;exception handlers addresses (for interrupt gate construction)
2382 hidnplayr 37
        dd      e0,e1,e2,e3,e4,e5,e6,except_7 ; SEE: core/fpu.inc
38
        dd      e8,e9,e10,e11,e12,e13,page_fault_exc,e15
39
        dd      e16, e17,e18, e19
40
        times   12 dd unknown_interrupt ;int_20..int_31
164 serge 41
 
1056 Galkov 42
    ;interrupt handlers addresses (for interrupt gate construction)
2382 hidnplayr 43
        ; 0x20 .. 0x2F - IRQ handlers
44
        dd      irq0, irq_serv.irq_1, irq_serv.irq_2
45
        dd      irq_serv.irq_3, irq_serv.irq_4
46
        dd      irq_serv.irq_5,  irq_serv.irq_6,  irq_serv.irq_7
47
        dd      irq_serv.irq_8,  irq_serv.irq_9,  irq_serv.irq_10
48
        dd      irq_serv.irq_11, irq_serv.irq_12, irqD, irq_serv.irq_14, irq_serv.irq_15
49
        dd irq_serv.irq_16
50
        dd irq_serv.irq_17
51
        dd irq_serv.irq_18
52
        dd irq_serv.irq_19
53
        dd irq_serv.irq_20
54
        dd irq_serv.irq_21
55
        dd irq_serv.irq_22
56
        dd irq_serv.irq_23
1 ha 57
 
2382 hidnplayr 58
    times 32 - IRQ_RESERVED dd unknown_interrupt
1056 Galkov 59
    ;int_0x40 gate trap (for directly copied)
2382 hidnplayr 60
        dw      i40 and 0xFFFF, os_code, 11101111b shl 8, i40 shr 16
656 mikedld 61
 
1076 Galkov 62
  idtreg: ; data for LIDT instruction (!!! must be immediately below sys_int data)
2382 hidnplayr 63
        dw      2*($-sys_int-4)-1
64
        dd      idts ;0x8000B100
65
        dw      0    ;просто выравнивание
656 mikedld 66
 
1056 Galkov 67
  msg_fault_sel dd  msg_exc_8,msg_exc_u,msg_exc_a,msg_exc_b
2382 hidnplayr 68
                dd  msg_exc_c,msg_exc_d,msg_exc_e
164 serge 69
 
2382 hidnplayr 70
  msg_exc_8     db "Double fault", 0
71
  msg_exc_u     db "Undefined Exception", 0
72
  msg_exc_a     db "Invalid TSS", 0
73
  msg_exc_b     db "Segment not present", 0
74
  msg_exc_c     db "Stack fault", 0
75
  msg_exc_d     db "General protection fault", 0
76
  msg_exc_e     db "Page fault", 0
1 ha 77
 
2382 hidnplayr 78
  msg_sel_ker   db "kernel", 0
79
  msg_sel_app   db "application", 0
1 ha 80
 
81
endg
82
 
1056 Galkov 83
macro save_ring3_context {
2382 hidnplayr 84
        pushad
40 halyavin 85
}
1056 Galkov 86
macro restore_ring3_context {
2382 hidnplayr 87
        popad
40 halyavin 88
}
1056 Galkov 89
macro exc_wo_code [num] {
8 poddubny 90
  e#num :
2382 hidnplayr 91
        save_ring3_context
92
        mov     bl, num
93
        jmp     exc_c
94
} exc_wo_code   0,1,2,3,4,5,6,15,16,19
1 ha 95
 
1056 Galkov 96
macro exc_w_code [num] {
22 poddubny 97
  e#num :
2382 hidnplayr 98
        add     esp, 4
99
        save_ring3_context
100
        mov     bl, num
101
        jmp     exc_c
102
} exc_w_code    8,9,10,11,12,13,17,18
22 poddubny 103
 
104
 
1056 Galkov 105
uglobal
2382 hidnplayr 106
  pf_err_code   dd ?
1056 Galkov 107
endg
1 ha 108
 
2382 hidnplayr 109
page_fault_exc:                 ; дуракоусточивость: селекторы испорчены...
110
        pop     [ss:pf_err_code]; действительно до следующего #PF
111
        save_ring3_context
112
        mov     bl, 14
1086 Galkov 113
 
2382 hidnplayr 114
exc_c:                          ; исключения (все, кроме 7-го - #NM)
1056 Galkov 115
; Фрэйм стека при исключении/прерывании из 3-го кольца + pushad (т.е., именно здесь)
2382 hidnplayr 116
  reg_ss        equ esp+0x30
117
  reg_esp3      equ esp+0x2C
118
  reg_eflags    equ esp+0x28
119
  reg_cs3       equ esp+0x24
120
  reg_eip       equ esp+0x20
1056 Galkov 121
 ; это фрэйм от pushad
2382 hidnplayr 122
  reg_eax       equ esp+0x1C
123
  reg_ecx       equ esp+0x18
124
  reg_edx       equ esp+0x14
125
  reg_ebx       equ esp+0x10
126
  reg_esp0      equ esp+0x0C
127
  reg_ebp       equ esp+0x08
128
  reg_esi       equ esp+0x04
129
  reg_edi       equ esp+0x00
1056 Galkov 130
 
2382 hidnplayr 131
        mov     ax, app_data        ;исключение
132
        mov     ds, ax                  ;загрузим правильные значения
133
        mov     es, ax                  ;в регистры
134
        cld                     ; и приводим DF к стандарту
135
        movzx   ebx, bl
709 diamond 136
; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
2382 hidnplayr 137
        test    byte[reg_eflags+2], 2
138
        jnz     v86_exc_c
139
        cmp     bl, 14          ; #PF
140
        jne     @f
141
        call    page_fault_handler ; SEE: core/memory.inc
142
  @@:
143
        mov     esi, [current_slot]
144
        btr     [esi+APPDATA.except_mask], ebx
145
        jnc     @f
146
        mov     eax, [esi+APPDATA.exc_handler]
147
        test    eax, eax
148
        jnz     IRetToUserHook
149
  @@:
150
        cli
151
        mov     eax, [esi+APPDATA.debugger_slot]
152
        test    eax, eax
153
        jnz     .debug
154
        sti
40 halyavin 155
; not debuggee => say error and terminate
2382 hidnplayr 156
        call    show_error_parameters ;; only ONE using, inline ???
3145 hidnplayr 157
 
158
; kill open sockets
159
        pusha
160
        mov     edx, [edx + TASKDATA.pid]
161
        call    SOCKET_process_end
162
        popa
163
 
2382 hidnplayr 164
        mov     [edx + TASKDATA.state], byte 4 ; terminate
165
        jmp     change_task     ; stack - here it does not matter at all, SEE: core/shed.inc
40 halyavin 166
.debug:
167
; we are debugged process, notify debugger and suspend ourself
168
; eax=debugger PID
2382 hidnplayr 169
        mov     ecx, 1          ; debug_message code=other_exception
170
        cmp     bl, 1           ; #DB
171
        jne     .notify         ; notify debugger and suspend ourself
172
        mov     ebx, dr6        ; debug_message data=DR6_image
173
        xor     edx, edx
174
        mov     dr6, edx
175
        mov     edx, dr7
176
        mov     cl, not 8
177
  .l1:
178
        shl     dl, 2
179
        jc      @f
180
        and     bl, cl
181
  @@:
182
        sar     cl, 1
183
        jc      .l1
184
        mov     cl, 3           ; debug_message code=debug_exception
1076 Galkov 185
.notify:
2382 hidnplayr 186
        push    ebx             ; debug_message data
187
        mov     ebx, [TASK_BASE]
188
        push    [ebx+TASKDATA.pid] ; PID
189
        push    ecx             ; debug_message code ((here: ecx==1/3))
190
        mov     cl, 12          ; debug_message size
191
        call    debugger_notify ;; only ONE using, inline ??? SEE: core/debug.inc
192
        add     esp, 12
193
        mov     edx, [TASK_BASE]
194
        mov     byte [edx+TASKDATA.state], 1 ; suspended
195
        call    change_task     ; SEE: core/shed.inc
196
        restore_ring3_context
197
        iretd
1 ha 198
 
1056 Galkov 199
IRetToUserHook:
2382 hidnplayr 200
        xchg    eax, [reg_eip]
201
        sub     dword[reg_esp3], 8
202
        mov     edi, [reg_esp3]
203
        stosd
204
        mov     [edi], ebx
205
        restore_ring3_context
206
; simply return control to interrupted process
1056 Galkov 207
unknown_interrupt:
2382 hidnplayr 208
        iretd
1 ha 209
 
658 Ghost 210
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
2382 hidnplayr 211
; bl - error vector
1 ha 212
show_error_parameters:
2382 hidnplayr 213
        cmp     bl, 0x06
214
        jnz     .no_ud
215
        push    ebx
216
        mov     ebx, ud_user_message
217
        mov     ebp, notifyapp
218
        call    fs_execute_from_sysdir_param
219
        pop     ebx
220
.no_ud:
221
        mov     edx, [TASK_BASE];not scratched below
222
        DEBUGF  1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
223
        cmp     bl, 0x08
224
        jb      .l0
225
        cmp     bl, 0x0e
226
        jbe     .l1
227
  .l0:
228
        mov     bl, 0x09
229
  .l1:
230
        mov     eax, [msg_fault_sel+ebx*4 - 0x08*4]
231
        DEBUGF  1, "K : %s\n", eax
232
        mov     eax, [reg_cs3+4]
233
        mov     edi, msg_sel_app
234
        mov     ebx, [reg_esp3+4]
235
        cmp     eax, app_code
236
        je      @f
237
        mov     edi, msg_sel_ker
238
        mov     ebx, [reg_esp0+4]
239
    @@:
240
        DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4]
241
        DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4]
242
        DEBUGF  1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx
243
        DEBUGF  1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi
244
        ret
658 Ghost 245
;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
164 serge 246
 
1056 Galkov 247
  restore  reg_ss
248
  restore  reg_esp3
249
  restore  reg_eflags
250
  restore  reg_cs
251
  restore  reg_eip
252
  restore  reg_eax
253
  restore  reg_ecx
254
  restore  reg_edx
255
  restore  reg_ebx
256
  restore  reg_esp0
257
  restore  reg_ebp
258
  restore  reg_esi
259
  restore  reg_edi
16 poddubny 260
 
1 ha 261
 
2382 hidnplayr 262
align 4
1 ha 263
set_application_table_status:
2382 hidnplayr 264
        push    eax
1 ha 265
 
2382 hidnplayr 266
        mov     eax, [CURRENT_TASK]
267
        shl     eax, 5
268
        add     eax, CURRENT_TASK+TASKDATA.pid
269
        mov     eax, [eax]
1 ha 270
 
2382 hidnplayr 271
        mov     [application_table_status], eax
1 ha 272
 
2382 hidnplayr 273
        pop     eax
1 ha 274
 
2382 hidnplayr 275
        ret
1 ha 276
 
2382 hidnplayr 277
align 4
1 ha 278
clear_application_table_status:
2382 hidnplayr 279
        push    eax
1 ha 280
 
2382 hidnplayr 281
        mov     eax, [CURRENT_TASK]
282
        shl     eax, 5
283
        add     eax, CURRENT_TASK+TASKDATA.pid
284
        mov     eax, [eax]
1 ha 285
 
2382 hidnplayr 286
        cmp     eax, [application_table_status]
287
        jne     apptsl1
288
        xor     eax, eax
289
        mov     [application_table_status], eax
1 ha 290
      apptsl1:
291
 
2382 hidnplayr 292
        pop     eax
1 ha 293
 
2382 hidnplayr 294
        ret
1 ha 295
 
1306 Lrz 296
;  * eax = 64 - номер функции
297
;  * ebx = 1 - единственная подфункция
298
;  * ecx = новый размер памяти
299
;Возвращаемое значение:
300
;  * eax = 0 - успешно
301
;  * eax = 1 - недостаточно памяти
302
 
2382 hidnplayr 303
align 4
1 ha 304
sys_resize_app_memory:
2382 hidnplayr 305
        ; ebx = 1 - resize
306
        ; ecx = new amount of memory
1 ha 307
 
1306 Lrz 308
;        cmp    eax,1
2382 hidnplayr 309
        dec     ebx
310
        jnz     .no_application_mem_resize
311
        stdcall new_mem_resize, ecx
312
        mov     [esp+32], eax
164 serge 313
.no_application_mem_resize:
2382 hidnplayr 314
        ret
1 ha 315
 
316
iglobal
1056 Galkov 317
;  process_terminating  db 'K : Process - terminating',13,10,0
318
;  process_terminated   db 'K : Process - done',13,10,0
2382 hidnplayr 319
  msg_obj_destroy       db 'K : destroy app object',13,10,0
1 ha 320
endg
321
 
329 serge 322
; param
323
;  esi= slot
1 ha 324
 
2382 hidnplayr 325
align 4
1 ha 326
terminate: ; terminate application
327
 
2382 hidnplayr 328
           .slot equ esp   ;locals
329 serge 329
 
2382 hidnplayr 330
        push    esi        ;save .slot
334 serge 331
 
2382 hidnplayr 332
        shl     esi, 8
333
        cmp     [SLOT_BASE+esi+APPDATA.dir_table], 0
334
        jne     @F
335
        pop     esi
336
        shl     esi, 5
337
        mov     [CURRENT_TASK+esi+TASKDATA.state], 9
338
        ret
334 serge 339
@@:
2382 hidnplayr 340
           ;mov    esi,process_terminating
341
           ;call   sys_msg_board_str
40 halyavin 342
@@:
2382 hidnplayr 343
        cli
344
        cmp     [application_table_status], 0
345
        je      term9
346
        sti
347
        call    change_task
348
        jmp     @b
329 serge 349
term9:
2382 hidnplayr 350
        call    set_application_table_status
1 ha 351
 
709 diamond 352
; if the process is in V86 mode...
2382 hidnplayr 353
        mov     eax, [.slot]
354
        shl     eax, 8
355
        mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
356
        add     esi, RING0_STACK_SIZE
357
        cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
358
        jz      .nov86
709 diamond 359
; ...it has page directory for V86 mode
2382 hidnplayr 360
        mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
361
        mov     ecx, [esi+4]
362
        mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
709 diamond 363
; ...and I/O permission map for V86 mode
2382 hidnplayr 364
        mov     ecx, [esi+12]
365
        mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
366
        mov     ecx, [esi+8]
367
        mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
709 diamond 368
.nov86:
369
 
2382 hidnplayr 370
        mov     esi, [.slot]
371
        shl     esi, 8
372
        add     esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 373
@@:
2382 hidnplayr 374
        mov     eax, [esi+APPOBJ.fd]
375
        test    eax, eax
376
        jz      @F
334 serge 377
 
2382 hidnplayr 378
        cmp     eax, esi
379
        je      @F
164 serge 380
 
2382 hidnplayr 381
        push    esi
382
        call    [eax+APPOBJ.destroy]
383
           DEBUGF 1,"%s",msg_obj_destroy
384
        pop     esi
385
        jmp     @B
329 serge 386
@@:
1311 diamond 387
 
2382 hidnplayr 388
        mov     eax, [.slot]
389
        shl     eax, 8
390
        stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
1 ha 391
 
2382 hidnplayr 392
        mov     esi, [.slot]
393
        cmp     [fpu_owner], esi ; if user fpu last -> fpu user = 1
394
        jne     @F
164 serge 395
 
2382 hidnplayr 396
        mov     [fpu_owner], 1
397
        mov     eax, [256+SLOT_BASE+APPDATA.fpu_state]
398
        clts
399
        bt      [cpu_caps], CAPS_SSE
400
        jnc     .no_SSE
401
        fxrstor [eax]
402
        jmp     @F
203 serge 403
.no_SSE:
2382 hidnplayr 404
        fnclex
405
        frstor  [eax]
357 serge 406
@@:
203 serge 407
 
2382 hidnplayr 408
        mov     [KEY_COUNT], byte 0    ; empty keyboard buffer
409
        mov     [BTN_COUNT], byte 0    ; empty button buffer
1 ha 410
 
411
 
92 diamond 412
; remove defined hotkeys
2382 hidnplayr 413
        mov     eax, hotkey_list
92 diamond 414
.loop:
2382 hidnplayr 415
        cmp     [eax+8], esi
416
        jnz     .cont
417
        mov     ecx, [eax]
418
        jecxz   @f
419
        push    dword [eax+12]
420
        pop     dword [ecx+12]
92 diamond 421
@@:
2382 hidnplayr 422
        mov     ecx, [eax+12]
423
        push    dword [eax]
424
        pop     dword [ecx]
425
        xor     ecx, ecx
426
        mov     [eax], ecx
427
        mov     [eax+4], ecx
428
        mov     [eax+8], ecx
429
        mov     [eax+12], ecx
92 diamond 430
.cont:
3187 hidnplayr 431
        add     eax, 16
432
        cmp     eax, hotkey_list+256*16
433
        jb      .loop
434
; get process PID
435
        mov     eax, esi
436
        shl     eax, 5
437
        mov     eax, [eax+CURRENT_TASK+TASKDATA.pid]
438
; compare current lock input with process PID
439
        cmp     eax, [PID_lock_input]
440
        jne     @f
441
 
442
        xor     eax, eax
443
        mov     [PID_lock_input], eax
444
@@:
445
; remove hotkeys in buffer
446
        mov     eax, hotkey_buffer
447
.loop2:
2382 hidnplayr 448
        cmp     [eax], esi
449
        jnz     .cont2
450
        and     dword [eax+4], 0
451
        and     dword [eax], 0
92 diamond 452
.cont2:
2382 hidnplayr 453
        add     eax, 8
454
        cmp     eax, hotkey_buffer+120*8
455
        jb      .loop2
92 diamond 456
 
2382 hidnplayr 457
        mov     ecx, esi          ; remove buttons
1 ha 458
  bnewba2:
2382 hidnplayr 459
        mov     edi, [BTN_ADDR]
460
        mov     eax, edi
461
        cld
462
        movzx   ebx, word [edi]
463
        inc     bx
1 ha 464
  bnewba:
2382 hidnplayr 465
        dec     bx
466
        jz      bnmba
467
        add     eax, 0x10
468
        cmp     cx, [eax]
469
        jnz     bnewba
470
        pusha
471
        mov     ecx, ebx
472
        inc     ecx
473
        shl     ecx, 4
474
        mov     ebx, eax
475
        add     eax, 0x10
476
        call    memmove
477
        dec     dword [edi]
478
        popa
479
        jmp     bnewba2
1 ha 480
  bnmba:
481
 
2382 hidnplayr 482
        pusha   ; save window coordinates for window restoring
483
        cld
484
        shl     esi, 5
485
        add     esi, window_data
486
        mov     eax, [esi+WDATA.box.left]
487
        mov     [draw_limits.left], eax
488
        add     eax, [esi+WDATA.box.width]
489
        mov     [draw_limits.right], eax
490
        mov     eax, [esi+WDATA.box.top]
491
        mov     [draw_limits.top], eax
492
        add     eax, [esi+WDATA.box.height]
493
        mov     [draw_limits.bottom], eax
1 ha 494
 
2382 hidnplayr 495
        xor     eax, eax
496
        mov     [esi+WDATA.box.left], eax
497
        mov     [esi+WDATA.box.width], eax
498
        mov     [esi+WDATA.box.top], eax
499
        mov     [esi+WDATA.box.height], eax
500
        mov     [esi+WDATA.cl_workarea], eax
501
        mov     [esi+WDATA.cl_titlebar], eax
502
        mov     [esi+WDATA.cl_frames], eax
503
        mov     dword [esi+WDATA.reserved], eax; clear all flags: wstate, redraw, wdrawn
504
        lea     edi, [esi-window_data+draw_data]
505
        mov     ecx, 32/4
506
        rep stosd
507
        popa
1 ha 508
 
40 halyavin 509
; debuggee test
2382 hidnplayr 510
        pushad
511
        mov     edi, esi
512
        shl     edi, 5
513
        mov     eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
514
        test    eax, eax
515
        jz      .nodebug
516
        push    8
517
        pop     ecx
518
        push    dword [CURRENT_TASK+edi+TASKDATA.pid]; PID
519
        push    2
520
        call    debugger_notify
521
        pop     ecx
522
        pop     ecx
40 halyavin 523
.nodebug:
2382 hidnplayr 524
        popad
40 halyavin 525
 
2382 hidnplayr 526
        mov     ebx, [.slot]
527
        shl     ebx, 8
528
        push    ebx
529
        mov     ebx, [SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 530
 
2382 hidnplayr 531
        stdcall kernel_free, ebx
1 ha 532
 
2382 hidnplayr 533
        pop     ebx
534
        mov     ebx, [SLOT_BASE+ebx+APPDATA.cur_dir]
535
        stdcall kernel_free, ebx
521 diamond 536
 
2382 hidnplayr 537
        mov     edi, [.slot]
538
        shl     edi, 8
539
        add     edi, SLOT_BASE
465 serge 540
 
2382 hidnplayr 541
        mov     eax, [edi+APPDATA.io_map]
542
        cmp     eax, [SLOT_BASE+256+APPDATA.io_map]
543
        je      @F
544
        call    free_page
465 serge 545
@@:
2382 hidnplayr 546
        mov     eax, [edi+APPDATA.io_map+4]
547
        cmp     eax, [SLOT_BASE+256+APPDATA.io_map+4]
548
        je      @F
549
        call    free_page
465 serge 550
@@:
2382 hidnplayr 551
        mov     eax, 0x20202020
552
        stosd
553
        stosd
554
        stosd
555
        mov     ecx, 244/4
556
        xor     eax, eax
557
        rep stosd
1 ha 558
 
102 poddubny 559
  ; activate window
2382 hidnplayr 560
        movzx   eax, word [WIN_STACK + esi*2]
561
        cmp     eax, [TASK_COUNT]
562
        jne     .dont_activate
563
        pushad
102 poddubny 564
 .check_next_window:
2382 hidnplayr 565
        dec     eax
566
        cmp     eax, 1
567
        jbe     .nothing_to_activate
568
        lea     esi, [WIN_POS+eax*2]
569
        movzx   edi, word [esi]              ; edi = process
570
        shl     edi, 5
571
        cmp     [CURRENT_TASK + edi + TASKDATA.state], byte 9 ; skip dead slots
572
        je      .check_next_window
573
        add     edi, window_data
154 diamond 574
; \begin{diamond}[19.09.2006]
575
; skip minimized windows
2382 hidnplayr 576
        test    [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
577
        jnz     .check_next_window
154 diamond 578
; \end{diamond}
2382 hidnplayr 579
        call    waredraw
102 poddubny 580
 .nothing_to_activate:
2382 hidnplayr 581
        popad
102 poddubny 582
 .dont_activate:
583
 
2382 hidnplayr 584
        push    esi     ; remove hd1 & cd & flp reservation
585
        shl     esi, 5
586
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
587
        cmp     [hd1_status], esi
588
        jnz     @f
589
        call    free_hd_channel
590
        and     [hd1_status], 0
92 diamond 591
@@:
2382 hidnplayr 592
        cmp     [cd_status], esi
593
        jnz     @f
594
        call    free_cd_channel
595
        and     [cd_status], 0
92 diamond 596
@@:
2382 hidnplayr 597
        cmp     [flp_status], esi
598
        jnz     @f
599
        and     [flp_status], 0
92 diamond 600
@@:
2382 hidnplayr 601
        pop     esi
602
        cmp     [bgrlockpid], esi
603
        jnz     @f
604
        and     [bgrlockpid], 0
605
        and     [bgrlock], 0
546 diamond 606
@@:
1 ha 607
 
2382 hidnplayr 608
        pusha                 ; remove all port reservations
609
        mov     edx, esi
610
        shl     edx, 5
611
        add     edx, CURRENT_TASK
612
        mov     edx, [edx+TASKDATA.pid]
1 ha 613
 
614
  rmpr0:
615
 
2382 hidnplayr 616
        mov     esi, [RESERVED_PORTS]
1 ha 617
 
2382 hidnplayr 618
        test    esi, esi
619
        jz      rmpr9
1 ha 620
 
621
  rmpr3:
622
 
2382 hidnplayr 623
        mov     edi, esi
624
        shl     edi, 4
625
        add     edi, RESERVED_PORTS
1 ha 626
 
2382 hidnplayr 627
        cmp     edx, [edi]
628
        je      rmpr4
1 ha 629
 
2382 hidnplayr 630
        dec     esi
631
        jnz     rmpr3
1 ha 632
 
2382 hidnplayr 633
        jmp     rmpr9
1 ha 634
 
635
  rmpr4:
636
 
2382 hidnplayr 637
        mov     ecx, 256
638
        sub     ecx, esi
639
        shl     ecx, 4
1 ha 640
 
2382 hidnplayr 641
        mov     esi, edi
642
        add     esi, 16
643
        cld
644
        rep movsb
1 ha 645
 
2382 hidnplayr 646
        dec     dword [RESERVED_PORTS]
1 ha 647
 
2382 hidnplayr 648
        jmp     rmpr0
1 ha 649
 
650
  rmpr9:
651
 
2382 hidnplayr 652
        popa
653
        mov     edi, esi ; do not run this process slot
654
        shl     edi, 5
655
        mov     [edi+CURRENT_TASK + TASKDATA.state], byte 9
40 halyavin 656
; debugger test - terminate all debuggees
2382 hidnplayr 657
        mov     eax, 2
658
        mov     ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 659
.xd0:
2382 hidnplayr 660
        cmp     eax, [TASK_COUNT]
661
        ja      .xd1
662
        cmp     dword [ecx], esi
663
        jnz     @f
664
        and     dword [ecx], 0
665
        pushad
666
        xchg    eax, ecx
667
        mov     ebx, 2
668
        call    sys_system
669
        popad
40 halyavin 670
@@:
2382 hidnplayr 671
        inc     eax
672
        add     ecx, 0x100
673
        jmp     .xd0
40 halyavin 674
.xd1:
1 ha 675
;    call  systest
2382 hidnplayr 676
        sti     ; .. and life goes on
1 ha 677
 
2382 hidnplayr 678
        mov     eax, [draw_limits.left]
679
        mov     ebx, [draw_limits.top]
680
        mov     ecx, [draw_limits.right]
681
        mov     edx, [draw_limits.bottom]
682
        call    calculatescreen
683
        xor     eax, eax
684
        xor     esi, esi
685
        call    redrawscreen
1 ha 686
 
2382 hidnplayr 687
        mov     [MOUSE_BACKGROUND], byte 0; no mouse background
688
        mov     [DONT_DRAW_MOUSE], byte 0; draw mouse
1 ha 689
 
2382 hidnplayr 690
        and     [application_table_status], 0
506 mikedld 691
    ;mov   esi,process_terminated
692
    ;call  sys_msg_board_str
2382 hidnplayr 693
        add     esp, 4
3187 hidnplayr 694
        ret
695
restore .slot
696
 
697
;iglobal
698
;if lang eq ru
699
;  boot_sched_1    db   '‘®§¤ ­ЁҐ GDT TSS гЄ § вҐ«п',0
700
;  boot_sched_2    db   '‘®§¤ ­ЁҐ IDT в Ў«Ёжл',0
701
;else
702
;  boot_sched_1    db   'Building gdt tss pointer',0
703
;  boot_sched_2    db   'Building IDT table',0
704
;end if
705
;endg
706
 
707
 
708
;build_scheduler:
709
;        mov     esi, boot_sched_1
710
;        call    boot_log
711
;        call   build_process_gdt_tss_pointer
712
 
713
;        mov    esi,boot_sched_2
714
;        call   boot_log
715
;        ret