Subversion Repositories Kolibri OS

Rev

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

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