Subversion Repositories Kolibri OS

Rev

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

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