Subversion Repositories Kolibri OS

Rev

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