Subversion Repositories Kolibri OS

Rev

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

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