Subversion Repositories Kolibri OS

Rev

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