Subversion Repositories Kolibri OS

Rev

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