Subversion Repositories Kolibri OS

Rev

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