Subversion Repositories Kolibri OS

Rev

Rev 379 | Rev 381 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

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