Subversion Repositories Kolibri OS

Rev

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