Subversion Repositories Kolibri OS

Rev

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

Rev Author Line No. Line
425 victor 1
$Revision: 566 $
431 serge 2
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
3
;;                                                              ;;
4
;; Copyright (C) KolibriOS team 2004-2007. All rights reserved. ;;
5
;; Distributed under terms of the GNU General Public License    ;;
6
;;                                                              ;;
7
;;                                                              ;;
8
;;  MenuetOS process management, protected ring3                ;;
9
;;                                                              ;;
10
;;  Distributed under GPL. See file COPYING for details.        ;;
11
;;  Copyright 2003 Ville Turjanmaa                              ;;
12
;;                                                              ;;
13
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
1 ha 14
 
389 serge 15
align 4
1 ha 16
idtreg:
17
     dw   8*0x41-1
18
     dd   idts+8
19
 
20
build_interrupt_table:
21
 
6 poddubny 22
        mov    edi, idts+8
23
        mov    esi, sys_int
8 poddubny 24
        mov    ecx, 0x40
6 poddubny 25
     @@:
434 diamond 26
        lodsd
465 serge 27
        mov    [edi],   ax           ; lower part of offset
28
        mov    [edi+2], word os_code ; segment selector
434 diamond 29
        mov     ax, word 10001110b shl 8        ; type: interrupt gate
30
        mov     [edi+4], eax
465 serge 31
        add    edi, 8
434 diamond 32
        loop    @b
164 serge 33
 
8 poddubny 34
        ;mov    edi,8*0x40+idts+8
434 diamond 35
        mov     dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
36
        mov     dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
37
                                                ; type: trap gate
1 ha 38
        ret
39
 
40
iglobal
41
  sys_int:
164 serge 42
    dd e0,debug_exc,e2,e3
43
    dd e4,e5,e6,e7
44
    dd e8,e9,e10,e11
45
    dd e12,e13,page_fault_handler,e15
46
 
168 serge 47
    dd except_16, e17,e18, except_19
48
    times 12 dd unknown_interrupt
1 ha 49
 
566 serge 50
    dd   irq0, irq_serv.irq_1, p_irq2
51
if USE_COM_IRQ
52
    dd   irq_serv.irq_3, irq_serv.irq_4
53
else
54
    dd   p_irq3, p_irq4
55
end if
56
    dd   irq_serv.irq_5,  p_irq6,         irq_serv.irq_7
57
    dd   irq_serv.irq_8,  irq_serv.irq_9, irq_serv.irq_10
58
    dd   irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15
1 ha 59
 
60
    times 16 dd unknown_interrupt
61
 
62
    dd   i40
63
endg
64
 
40 halyavin 65
macro save_ring3_context
66
{
58 mario79 67
    pushad
40 halyavin 68
}
69
macro restore_ring3_context
70
{
58 mario79 71
    popad
40 halyavin 72
}
73
 
8 poddubny 74
; simply return control to interrupted process
75
unknown_interrupt:
76
     iret
1 ha 77
 
22 poddubny 78
macro exc_wo_code [num]
8 poddubny 79
{
80
  forward
81
  e#num :
40 halyavin 82
      save_ring3_context
20 mario79 83
      mov bl, num
84
      jmp exc_c
8 poddubny 85
}
1 ha 86
 
22 poddubny 87
macro exc_w_code [num]
88
{
89
  forward
90
  e#num :
91
      add esp, 4
40 halyavin 92
      save_ring3_context
22 poddubny 93
      mov bl, num
94
      jmp exc_c
95
}
96
 
168 serge 97
exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 18
22 poddubny 98
exc_w_code 8, 10, 11, 12, 13, 14, 17
99
 
8 poddubny 100
exc_c:
465 serge 101
        mov   ax, app_data  ;исключение
102
        mov   ds, ax        ;загрузим правильные значени
103
        mov   es, ax        ;в регистры
1 ha 104
 
40 halyavin 105
; test if debugging
106
        cli
465 serge 107
        mov   eax, [current_slot]
108
        mov   eax, [eax+APPDATA.debugger_slot]
40 halyavin 109
        test  eax, eax
110
        jnz   .debug
111
        sti
112
; not debuggee => say error and terminate
465 serge 113
        add   esp, 0x20  ;28h
164 serge 114
        movzx eax, bl
8 poddubny 115
        mov   [error_interrupt], eax
1 ha 116
        call  show_error_parameters
164 serge 117
 
379 serge 118
        mov   edx, [TASK_BASE]
115 poddubny 119
        mov   [edx + TASKDATA.state], byte 4
164 serge 120
 
1 ha 121
        jmp   change_task
122
 
40 halyavin 123
.debug:
124
; we are debugged process, notify debugger and suspend ourself
125
; eax=debugger PID
113 diamond 126
        cld
40 halyavin 127
        movzx ecx, bl
128
        push  ecx
379 serge 129
        mov   ecx, [TASK_BASE]
115 poddubny 130
        push  dword [ecx+TASKDATA.pid]    ; PID of current process
40 halyavin 131
        push  12
132
        pop   ecx
58 mario79 133
        push  1        ; 1=exception
40 halyavin 134
        call  debugger_notify
135
        pop   ecx
136
        pop   ecx
137
        pop   ecx
379 serge 138
        mov   edx, [TASK_BASE]
115 poddubny 139
        mov   byte [edx+TASKDATA.state], 1        ; suspended
40 halyavin 140
        call  change_task
141
        restore_ring3_context
142
        iretd
1 ha 143
 
144
writehex:
145
      pusha
164 serge 146
 
8 poddubny 147
      mov  edi, [write_error_to]
148
      mov  esi, 8
149
    @@:
150
      mov  ecx, eax
151
      and  ecx, 0xf
1 ha 152
 
8 poddubny 153
      mov  cl,[ecx+hexletters]
1 ha 154
      mov  [edi],cl
8 poddubny 155
      dec  edi
1 ha 156
 
8 poddubny 157
      shr  eax,4
1 ha 158
      dec  esi
8 poddubny 159
      jnz  @b
1 ha 160
 
161
      popa
162
      ret
163
 
164
iglobal
165
  hexletters  db '0123456789ABCDEF'
166
 
167
  error_interrupt         dd  -1
168
 
169
  process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
170
  process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
171
  process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
172
  system_error   db 'K : Kernel error',13,10,0
173
endg
174
 
175
uglobal
176
  write_error_to  dd  0x0
177
endg
178
 
179
show_error_parameters:
164 serge 180
 
1 ha 181
        mov    [write_error_to],process_pid+43
379 serge 182
        mov    eax,[CURRENT_TASK]
1 ha 183
        shl    eax, 5
379 serge 184
        mov    eax,[CURRENT_TASK+TASKDATA.pid+eax]
1 ha 185
        call   writehex
164 serge 186
 
1 ha 187
        mov    [write_error_to],process_error+43
188
        mov    eax,[error_interrupt]
189
        call   writehex
16 poddubny 190
 
191
        cmp    dword [esp+4+4], os_code ; CS
192
        jnz    @f
506 mikedld 193
        ;mov    esi,system_error
194
        ;call   sys_msg_board_str
195
        DEBUGF 1,"%s",system_error
10 poddubny 196
      @@:
16 poddubny 197
        mov    eax, [esp+4] ; EIP
10 poddubny 198
 
1 ha 199
        mov    [write_error_to],process_eip+43
200
        call   writehex
201
 
506 mikedld 202
        ;mov    esi,process_error
203
        ;call   sys_msg_board_str
204
        DEBUGF 1,"%s",process_error
1 ha 205
 
506 mikedld 206
        ;mov    esi,process_pid
207
        ;call   sys_msg_board_str
208
        DEBUGF 1,"%s",process_pid
1 ha 209
 
506 mikedld 210
        ;mov    esi,process_eip
211
        ;call   sys_msg_board_str
212
        DEBUGF 1,"%s",process_eip
1 ha 213
 
214
        ret
215
 
216
 
217
 
6 poddubny 218
; irq1  ->  hid/keyboard.inc
1 ha 219
 
220
 
10 poddubny 221
macro irqh [num]
8 poddubny 222
{
223
  forward
224
  p_irq#num :
40 halyavin 225
     save_ring3_context
8 poddubny 226
     mov   edi, num
227
     jmp   irq_c
228
}
1 ha 229
 
160 diamond 230
irqh 2,5,7,8,9,10,11
1 ha 231
 
465 serge 232
irq_c:
233
     mov   ax, app_data  ;os_data
8 poddubny 234
     mov   ds, ax
235
     mov   es, ax
1 ha 236
     call  irqhandler
40 halyavin 237
     restore_ring3_context
8 poddubny 238
     iret
11 poddubny 239
 
240
p_irq6:
40 halyavin 241
     save_ring3_context
465 serge 242
     mov   ax, app_data  ;os_data
11 poddubny 243
     mov   ds, ax
244
     mov   es, ax
245
     call  fdc_irq
33 mario79 246
     call  ready_for_next_irq
40 halyavin 247
     restore_ring3_context
33 mario79 248
     iret
15 poddubny 249
 
33 mario79 250
p_irq3:
40 halyavin 251
     save_ring3_context
465 serge 252
     mov   ax, app_data  ;os_data
33 mario79 253
     mov   ds, ax
254
     mov   es, ax
58 mario79 255
     cmp   [com2_mouse_detected],0
256
     je    old_irq3_handler
473 diamond 257
     mov   esi, com2_mouse
258
     mov   dx, 2F8h     ;[COMPortBaseAddr]
259
     call  check_mouse_data_com
58 mario79 260
     jmp   p_irq3_1
261
 old_irq3_handler:
262
     mov   edi,3
263
     call  irqhandler
164 serge 264
  p_irq3_1:
40 halyavin 265
     restore_ring3_context
33 mario79 266
     iret
15 poddubny 267
 
33 mario79 268
p_irq4:
40 halyavin 269
     save_ring3_context
465 serge 270
     mov   ax, app_data  ;os_data
33 mario79 271
     mov   ds, ax
272
     mov   es, ax
58 mario79 273
     cmp   [com1_mouse_detected],0
274
     je    old_irq4_handler
473 diamond 275
     mov   esi, com1_mouse
276
     mov   dx, 3F8h     ;[COMPortBaseAddr]
277
     call  check_mouse_data_com
58 mario79 278
     jmp   p_irq4_1
279
 old_irq4_handler:
280
     mov   edi,4
281
     call  irqhandler
164 serge 282
  p_irq4_1:
40 halyavin 283
     restore_ring3_context
11 poddubny 284
     iret
285
 
160 diamond 286
p_irq14:
287
        save_ring3_context
465 serge 288
        mov     ax, app_data  ;os_data
160 diamond 289
        mov     ds, ax
290
        mov     es, ax
291
        call    [irq14_func]
292
        call    ready_for_next_irq_1
293
        restore_ring3_context
294
        iret
295
p_irq15:
296
        save_ring3_context
465 serge 297
        mov     ax, app_data  ;os_data
160 diamond 298
        mov     ds, ax
299
        mov     es, ax
300
        call    [irq15_func]
301
        call    ready_for_next_irq_1
302
        restore_ring3_context
303
        iret
304
 
33 mario79 305
ready_for_next_irq:
306
     mov    [check_idle_semaphore],5
307
     mov   al, 0x20
308
     out   0x20, al
309
     ret
310
 
311
ready_for_next_irq_1:
312
     mov    [check_idle_semaphore],5
313
     mov   al, 0x20
314
     out    0xa0,al
315
     out   0x20, al
316
     ret
317
 
6 poddubny 318
irqD:
40 halyavin 319
     save_ring3_context
465 serge 320
     mov   ax, app_data  ;os_data
8 poddubny 321
     mov   ds, ax
322
     mov   es, ax
164 serge 323
 
6 poddubny 324
     mov   dx,0xf0
325
     mov   al,0
326
     out   dx,al
1 ha 327
 
6 poddubny 328
     mov   dx,0xa0
329
     mov   al,0x20
330
     out   dx,al
331
     mov   dx,0x20
40 halyavin 332
     out   dx,al
333
 
334
     restore_ring3_context
164 serge 335
 
8 poddubny 336
     iret
1 ha 337
 
338
 
339
irqhandler:
340
 
341
     push   edi
342
 
343
     mov    esi,edi          ; 1
344
     shl    esi,6            ; 1
345
     add    esi,irq00read    ; 1
346
     shl    edi,12           ; 1
381 serge 347
     add    edi,IRQ_SAVE
75 diamond 348
     mov    ecx,16
1 ha 349
 
350
     mov    [check_idle_semaphore],5
351
 
352
   irqnewread:
75 diamond 353
     dec    ecx
354
     js     irqover
1 ha 355
 
356
     mov    dx,[esi]         ; 2+
357
 
358
     cmp    dx,0             ; 1
359
     jz     irqover
360
     cmp    [esi+3],byte 1   ; 2     ; byte read
361
     jne    noirqbyte        ; 4-11
362
 
363
     in     al,dx
364
 
365
     mov    edx,[edi]
366
     cmp    edx,4000
367
     je     irqfull
368
     mov    ebx,edi
369
     add    ebx,0x10
370
     add    ebx,edx
371
     mov    [ebx],al
372
     inc    edx
373
     mov    [edi],edx
374
 
375
     add    esi,4
376
     jmp    irqnewread
377
 
378
   noirqbyte:
379
 
380
 
381
     cmp    [esi+3],byte 2     ; word read
382
     jne    noirqword
383
 
384
     in     ax,dx
385
 
386
     mov    edx,[edi]
387
     cmp    edx,4000
388
     je     irqfull
389
     mov    ebx,edi
390
     add    ebx,0x10
391
     add    ebx,edx
392
     mov    [ebx],ax
393
     add    edx,2
394
     mov    [edi],edx
395
     add    esi,4
396
     jmp    irqnewread
397
 
398
   noirqword:
399
   irqfull:
400
   irqover:
401
 
402
     mov    al,0x20            ; ready for next irq
403
     out    0x20,al
404
 
405
     pop    ebx
406
     cmp    ebx,7
407
     jbe    noa0
408
     out    0xa0,al
409
   noa0:
410
 
411
     ret
412
 
413
 
414
 
415
set_application_table_status:
416
        push eax
417
 
379 serge 418
        mov  eax,[CURRENT_TASK]
1 ha 419
        shl  eax, 5
379 serge 420
        add  eax,CURRENT_TASK+TASKDATA.pid
1 ha 421
        mov  eax,[eax]
422
 
423
        mov  [application_table_status],eax
424
 
425
        pop  eax
426
 
427
        ret
428
 
429
 
430
clear_application_table_status:
431
        push eax
432
 
379 serge 433
        mov  eax,[CURRENT_TASK]
1 ha 434
        shl  eax, 5
379 serge 435
        add  eax,CURRENT_TASK+TASKDATA.pid
1 ha 436
        mov  eax,[eax]
437
 
438
        cmp  eax,[application_table_status]
439
        jne  apptsl1
440
        mov  [application_table_status],0
441
      apptsl1:
442
 
443
        pop  eax
444
 
445
        ret
446
 
447
sys_resize_app_memory:
448
        ; eax = 1 - resize
449
        ;     ebx = new amount of memory
450
 
451
        cmp    eax,1
4 poddubny 452
        jne    .no_application_mem_resize
1 ha 453
 
164 serge 454
        stdcall new_mem_resize, ebx
455
        mov [esp+36], eax
456
        ret
1 ha 457
 
164 serge 458
.no_application_mem_resize:
1 ha 459
        ret
460
 
461
sys_threads:
462
 
463
; eax=1 create thread
464
;
465
;   ebx=thread start
466
;   ecx=thread stack value
467
;
468
; on return : eax = pid
469
jmp new_sys_threads
470
 
471
iglobal
472
  process_terminating   db 'K : Process - terminating',13,10,0
473
  process_terminated    db 'K : Process - done',13,10,0
329 serge 474
  msg_obj_destroy       db 'K : destroy app object',13,10,0
1 ha 475
endg
476
 
329 serge 477
; param
478
;  esi= slot
1 ha 479
 
480
terminate: ; terminate application
481
 
329 serge 482
           .slot equ esp   ;locals
483
 
484
           push   esi      ;save .slot
334 serge 485
 
486
           shl esi, 8
380 serge 487
           cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
334 serge 488
           jne @F
489
           add esp, 4
490
           ret
491
@@:
506 mikedld 492
           ;mov    esi,process_terminating
493
           ;call   sys_msg_board_str
494
           DEBUGF 1,"%s",process_terminating
40 halyavin 495
@@:
329 serge 496
           cli
497
           cmp   [application_table_status],0
498
           je    term9
499
           sti
500
           call  change_task
501
           jmp   @b
502
term9:
503
           call  set_application_table_status
1 ha 504
 
329 serge 505
           mov esi, [.slot]
506
           shl esi,8
380 serge 507
           add esi, SLOT_BASE+APP_OBJ_OFFSET
329 serge 508
@@:
509
           mov eax, [esi+APPOBJ.fd]
334 serge 510
           test eax, eax
511
           jz @F
512
 
329 serge 513
           cmp eax, esi
514
           je @F
164 serge 515
 
329 serge 516
           push esi
517
           call [eax+APPOBJ.destroy]
506 mikedld 518
           ;mov  esi, msg_obj_destroy
519
           ;call sys_msg_board_str
520
           DEBUGF 1,"%s",msg_obj_destroy
329 serge 521
           pop esi
522
           jmp @B
523
@@:
524
           mov eax, [.slot]
525
           shl eax, 8
380 serge 526
           mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
329 serge 527
           stdcall destroy_app_space, eax
1 ha 528
 
357 serge 529
           mov esi, [.slot]
329 serge 530
           cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
357 serge 531
           jne @F
164 serge 532
 
329 serge 533
           mov [fpu_owner],1
380 serge 534
           mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
379 serge 535
           clts
329 serge 536
           bt [cpu_caps], CAPS_SSE
537
           jnc .no_SSE
538
           fxrstor [eax]
357 serge 539
           jmp @F
203 serge 540
.no_SSE:
329 serge 541
           fnclex
542
           frstor [eax]
357 serge 543
@@:
203 serge 544
 
381 serge 545
    mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
546
    mov   [BTN_COUNT],byte 0           ; empty button buffer
1 ha 547
 
548
 
92 diamond 549
; remove defined hotkeys
550
        mov     eax, hotkey_list
551
.loop:
552
        cmp     [eax+8], esi
553
        jnz     .cont
554
        mov     ecx, [eax]
555
        jecxz   @f
556
        push    dword [eax+12]
557
        pop     dword [ecx+12]
558
@@:
559
        mov     ecx, [eax+12]
560
        push    dword [eax]
561
        pop     dword [ecx]
562
        xor     ecx, ecx
563
        mov     [eax], ecx
564
        mov     [eax+4], ecx
565
        mov     [eax+8], ecx
566
        mov     [eax+12], ecx
567
.cont:
568
        add     eax, 16
569
        cmp     eax, hotkey_list+256*16
570
        jb      .loop
571
; remove hotkeys in buffer
572
        mov     eax, hotkey_buffer
573
.loop2:
574
        cmp     [eax], esi
575
        jnz     .cont2
576
        and     dword [eax+4], 0
577
        and     dword [eax], 0
578
.cont2:
579
        add     eax, 8
580
        cmp     eax, hotkey_buffer+120*8
581
        jb      .loop2
582
 
1 ha 583
    mov   ecx,esi                 ; remove buttons
584
  bnewba2:
381 serge 585
    mov   edi,[BTN_ADDR]
1 ha 586
    mov   eax,edi
587
    cld
588
    movzx ebx,word [edi]
589
    inc   bx
590
  bnewba:
591
    dec   bx
592
    jz    bnmba
593
    add   eax,0x10
594
    cmp   cx,[eax]
595
    jnz   bnewba
596
    pusha
597
    mov   ecx,ebx
598
    inc   ecx
599
    shl   ecx,4
600
    mov   ebx,eax
601
    add   eax,0x10
602
    call  memmove
603
    dec   dword [edi]
604
    popa
605
    jmp   bnewba2
606
  bnmba:
607
 
608
    pusha     ; save window coordinates for window restoring
609
    cld
610
    shl   esi,5
611
    add   esi,window_data
114 mikedld 612
    mov   eax,[esi+WDATA.box.left]
102 poddubny 613
    mov   [dlx],eax
114 mikedld 614
    add   eax,[esi+WDATA.box.width]
102 poddubny 615
    mov   [dlxe],eax
114 mikedld 616
    mov   eax,[esi+WDATA.box.top]
102 poddubny 617
    mov   [dly],eax
114 mikedld 618
    add   eax,[esi+WDATA.box.height]
102 poddubny 619
    mov   [dlye],eax
1 ha 620
 
142 diamond 621
    xor   eax, eax
622
    mov   [esi+WDATA.box.left],eax
623
    mov   [esi+WDATA.box.width],eax
114 mikedld 624
    mov   [esi+WDATA.box.top],eax
142 diamond 625
    mov   [esi+WDATA.box.height],eax
115 poddubny 626
    mov   [esi+WDATA.cl_workarea],eax
627
    mov   [esi+WDATA.cl_titlebar],eax
628
    mov   [esi+WDATA.cl_frames],eax
629
    mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
102 poddubny 630
    lea   edi, [esi-window_data+draw_data]
1 ha 631
    mov   ecx,32/4
632
    rep   stosd
633
    popa
634
 
40 halyavin 635
; debuggee test
636
    pushad
637
    mov  edi, esi
638
    shl  edi, 5
380 serge 639
    mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
40 halyavin 640
    test eax, eax
641
    jz   .nodebug
642
    push 8
643
    pop  ecx
379 serge 644
    push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
40 halyavin 645
    push 2
646
    call debugger_notify
647
    pop  ecx
648
    pop  ecx
649
.nodebug:
650
    popad
651
 
357 serge 652
           mov ebx, [.slot]
653
           shl ebx, 8
521 diamond 654
           push ebx
380 serge 655
           mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
1 ha 656
 
357 serge 657
           stdcall kernel_free, ebx
1 ha 658
 
521 diamond 659
           pop ebx
660
           mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
661
           stdcall kernel_free, ebx
662
 
357 serge 663
           mov edi, [.slot]
664
           shl edi,8
380 serge 665
           add edi,SLOT_BASE
465 serge 666
 
667
           mov eax, [edi+APPDATA.io_map]
668
           cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
669
           je @F
670
           call free_page
671
@@:
672
           mov eax, [edi+APPDATA.io_map+4]
673
           cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
674
           je @F
675
           call free_page
676
@@:
357 serge 677
           mov eax, 0x20202020
678
           stosd
679
           stosd
680
           stosd
681
           mov ecx,244/4
682
           xor eax, eax
683
           rep stosd
1 ha 684
 
102 poddubny 685
  ; activate window
380 serge 686
        movzx  eax, word [WIN_STACK + esi*2]
379 serge 687
        cmp    eax, [TASK_COUNT]
102 poddubny 688
        jne    .dont_activate
689
        pushad
690
 .check_next_window:
691
        dec    eax
692
        cmp    eax, 1
693
        jbe    .nothing_to_activate
380 serge 694
        lea    esi, [WIN_POS+eax*2]
102 poddubny 695
        movzx  edi, word [esi]               ; edi = process
696
        shl    edi, 5
379 serge 697
        cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
102 poddubny 698
        je     .check_next_window
699
        add    edi, window_data
154 diamond 700
; \begin{diamond}[19.09.2006]
701
; skip minimized windows
164 serge 702
        test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
703
        jnz    .check_next_window
154 diamond 704
; \end{diamond}
102 poddubny 705
        call   waredraw
706
 .nothing_to_activate:
707
        popad
708
 .dont_activate:
709
 
92 diamond 710
        push    esi     ; remove hd1 & cd & flp reservation
711
        shl     esi, 5
379 serge 712
        mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
92 diamond 713
        cmp     [hd1_status], esi
714
        jnz     @f
321 diamond 715
        call    free_hd_channel
92 diamond 716
        mov     [hd1_status], 0
717
@@:
718
        cmp     [cd_status], esi
719
        jnz     @f
321 diamond 720
        call    free_cd_channel
92 diamond 721
        mov     [cd_status], 0
722
@@:
723
        cmp     [flp_status], esi
724
        jnz     @f
725
        mov     [flp_status], 0
726
@@:
727
        pop     esi
546 diamond 728
        cmp     [bgrlockpid], esi
729
        jnz     @f
730
        and     [bgrlockpid], 0
731
        mov     [bgrlock], 0
732
@@:
1 ha 733
 
734
    pusha ; remove all irq reservations
92 diamond 735
    mov   eax,esi
115 poddubny 736
    shl   eax, 5
379 serge 737
    mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
1 ha 738
    mov   edi,irq_owner
739
    mov   ecx,16
740
  newirqfree:
92 diamond 741
    scasd
1 ha 742
    jne   nofreeirq
92 diamond 743
    mov   [edi-4],dword 0
1 ha 744
  nofreeirq:
745
    loop   newirqfree
746
    popa
747
 
748
    pusha                     ; remove all port reservations
749
    mov   edx,esi
115 poddubny 750
    shl   edx, 5
379 serge 751
    add   edx,CURRENT_TASK
115 poddubny 752
    mov   edx,[edx+TASKDATA.pid]
1 ha 753
 
754
  rmpr0:
755
 
381 serge 756
    mov   esi,[RESERVED_PORTS]
1 ha 757
 
758
    cmp   esi,0
759
    je    rmpr9
760
 
761
  rmpr3:
762
 
763
    mov   edi,esi
764
    shl   edi,4
381 serge 765
    add   edi,RESERVED_PORTS
1 ha 766
 
767
    cmp   edx,[edi]
768
    je    rmpr4
769
 
770
    dec   esi
771
    jnz   rmpr3
772
 
773
    jmp   rmpr9
774
 
775
  rmpr4:
776
 
777
    mov   ecx,256
778
    sub   ecx,esi
779
    shl   ecx,4
780
 
781
    mov   esi,edi
782
    add   esi,16
783
    cld
784
    rep   movsb
785
 
381 serge 786
    dec   dword [RESERVED_PORTS]
1 ha 787
 
788
    jmp   rmpr0
789
 
790
  rmpr9:
791
 
792
    popa
793
    mov  edi,esi         ; do not run this process slot
6 poddubny 794
    shl  edi, 5
379 serge 795
    mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
40 halyavin 796
; debugger test - terminate all debuggees
797
    mov  eax, 2
380 serge 798
    mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
40 halyavin 799
.xd0:
379 serge 800
    cmp  eax, [TASK_COUNT]
40 halyavin 801
    ja   .xd1
802
    cmp  dword [ecx], esi
803
    jnz  @f
804
    and  dword [ecx], 0
805
    pushad
806
    xchg eax, ebx
807
    mov  eax, 2
808
    call sys_system
809
    popad
810
@@:
811
    inc  eax
812
    add  ecx, 0x100
813
    jmp  .xd0
814
.xd1:
1 ha 815
;    call  systest
816
    sti  ; .. and life goes on
817
 
112 poddubny 818
    mov   eax, [dlx]
819
    mov   ebx, [dly]
820
    mov   ecx, [dlxe]
821
    mov   edx, [dlye]
1 ha 822
    call  calculatescreen
823
    xor   eax, eax
824
    xor   esi, esi
825
    call  redrawscreen
826
 
381 serge 827
    mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
828
    mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
1 ha 829
 
830
    mov   [application_table_status],0
506 mikedld 831
    ;mov   esi,process_terminated
832
    ;call  sys_msg_board_str
833
    DEBUGF 1,"%s",process_terminated
357 serge 834
    add esp, 4
1 ha 835
    ret
345 serge 836
restore .slot
1 ha 837
 
838
iglobal
839
  boot_sched_1    db   'Building gdt tss pointer',0
8 poddubny 840
  boot_sched_2    db   'Building IDT table',0
1 ha 841
endg
842
 
843
 
844
build_scheduler:
845
 
465 serge 846
        mov    esi,boot_sched_1
847
        call   boot_log
848
  ;      call   build_process_gdt_tss_pointer
1 ha 849
 
465 serge 850
  ;      mov    esi,boot_sched_2
851
  ;      call   boot_log
1 ha 852
 
853
        ret
854