Subversion Repositories Kolibri OS

Rev

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

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