Subversion Repositories Kolibri OS

Rev

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

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