Subversion Repositories Kolibri OS

Rev

Rev 183 | Rev 214 | 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 ,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. ;;;;;;;;;;;;;;;;;;;;;;;
  196. ;; FPU ERROR HANDLER ;;
  197. ;;;;;;;;;;;;;;;;;;;;;;;
  198.  
  199. align 4
  200. e7:
  201.         save_ring3_context
  202.         clts
  203.         mov ax, os_data
  204.         mov ds, ax
  205.         mov es, ax
  206.  
  207.         mov ebx, [fpu_owner]
  208.         cmp ebx, [CURRENT_TASK]
  209.         je .exit
  210.  
  211.         shl ebx, 8
  212.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  213.         bt [cpu_caps], CAPS_FXSR
  214.         jnc .no_SSE
  215.  
  216.         fxsave [eax]
  217.         mov ebx, [CURRENT_TASK]
  218.         mov [fpu_owner], ebx
  219.         shl ebx, 8
  220.         cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
  221.         je .init
  222.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  223.         fxrstor [eax]
  224.         restore_ring3_context
  225.         iret
  226.  
  227. .no_SSE:
  228.         fnsave [eax]
  229.         mov ebx, [CURRENT_TASK]
  230.         mov [fpu_owner], ebx
  231.         shl ebx, 8
  232.         cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
  233.         je .ready
  234.  
  235.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  236.         frstor [eax]
  237.         restore_ring3_context
  238.         iret
  239. .init:
  240.         fninit                      ;­ ¬ ­¥ ­ã¦­ë ­¥¬ áª¨à®¢ ­­ë¥ ¨áª«î祭¨ï
  241. .ready:
  242.         mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
  243. .exit:
  244.         restore_ring3_context
  245.         iret
  246.  
  247. iglobal
  248.   fpu_owner dd 1
  249.  endg
  250.  
  251.  
  252. writehex:
  253.       pusha
  254.  
  255.       mov  edi, [write_error_to]
  256.       mov  esi, 8
  257.     @@:
  258.       mov  ecx, eax
  259.       and  ecx, 0xf
  260.  
  261.       mov  cl,[ecx+hexletters]
  262.       mov  [edi],cl
  263.       dec  edi
  264.  
  265.       shr  eax,4
  266.       dec  esi
  267.       jnz  @b
  268.  
  269.       popa
  270.       ret
  271.  
  272. iglobal
  273.   hexletters  db '0123456789ABCDEF'
  274.  
  275.   error_interrupt         dd  -1
  276.  
  277.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  278.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  279.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  280.   system_error   db 'K : Kernel error',13,10,0
  281. endg
  282.  
  283. uglobal
  284.   write_error_to  dd  0x0
  285. endg
  286.  
  287. show_error_parameters:
  288.  
  289.         mov    [write_error_to],process_pid+43
  290.         mov    eax,[0x3000]
  291.         shl    eax, 5
  292.         mov    eax,[0x3000+TASKDATA.pid+eax]
  293.         call   writehex
  294.  
  295.         mov    [write_error_to],process_error+43
  296.         mov    eax,[error_interrupt]
  297.         call   writehex
  298.  
  299.         cmp    dword [esp+4+4], os_code ; CS
  300.         jnz    @f
  301.         mov    esi,system_error
  302.         call   sys_msg_board_str
  303.       @@:
  304.         mov    eax, [esp+4] ; EIP
  305.  
  306.         mov    [write_error_to],process_eip+43
  307.         call   writehex
  308.  
  309.         mov    esi,process_error
  310.         call   sys_msg_board_str
  311.  
  312.         mov    esi,process_pid
  313.         call   sys_msg_board_str
  314.  
  315.         mov    esi,process_eip
  316.         call   sys_msg_board_str
  317.  
  318.         ret
  319.  
  320.  
  321.  
  322. ; irq1  ->  hid/keyboard.inc
  323.  
  324.  
  325. macro irqh [num]
  326. {
  327.   forward
  328.   p_irq#num :
  329.      save_ring3_context
  330.      mov   edi, num
  331.      jmp   irq_c
  332. }
  333.  
  334. irqh 2,5,7,8,9,10,11
  335.  
  336.  irq_c:
  337.      mov   ax, os_data
  338.      mov   ds, ax
  339.      mov   es, ax
  340.      call  irqhandler
  341.      restore_ring3_context
  342.      iret
  343.  
  344. p_irq6:
  345.      save_ring3_context
  346.      mov   ax, os_data
  347.      mov   ds, ax
  348.      mov   es, ax
  349.      call  fdc_irq
  350.      call  ready_for_next_irq
  351.      restore_ring3_context
  352.      iret
  353.  
  354. p_irq3:
  355.      save_ring3_context
  356.      mov   ax, os_data
  357.      mov   ds, ax
  358.      mov   es, ax
  359.      cmp   [com2_mouse_detected],0
  360.      je    old_irq3_handler
  361.      call  check_mouse_data_com2
  362.      jmp   p_irq3_1
  363.  old_irq3_handler:
  364.      mov   edi,3
  365.      call  irqhandler
  366.   p_irq3_1:
  367.      restore_ring3_context
  368.      iret
  369.  
  370. p_irq4:
  371.      save_ring3_context
  372.      mov   ax, os_data
  373.      mov   ds, ax
  374.      mov   es, ax
  375.      cmp   [com1_mouse_detected],0
  376.      je    old_irq4_handler
  377.      call  check_mouse_data_com1
  378.      jmp   p_irq4_1
  379.  old_irq4_handler:
  380.      mov   edi,4
  381.      call  irqhandler
  382.   p_irq4_1:
  383.      restore_ring3_context
  384.      iret
  385.  
  386. p_irq12:
  387.      save_ring3_context
  388.      mov   ax, os_data
  389.      mov   ds, ax
  390.      mov   es, ax
  391.      call  check_mouse_data_ps2
  392.      restore_ring3_context
  393.      iret
  394.  
  395. p_irq14:
  396.         save_ring3_context
  397.         mov     ax, os_data
  398.         mov     ds, ax
  399.         mov     es, ax
  400.         call    [irq14_func]
  401.         call    ready_for_next_irq_1
  402.         restore_ring3_context
  403.         iret
  404. p_irq15:
  405.         save_ring3_context
  406.         mov     ax, os_data
  407.         mov     ds, ax
  408.         mov     es, ax
  409.         call    [irq15_func]
  410.         call    ready_for_next_irq_1
  411.         restore_ring3_context
  412.         iret
  413.  
  414. ready_for_next_irq:
  415.      mov    [check_idle_semaphore],5
  416.      mov   al, 0x20
  417.      out   0x20, al
  418.      ret
  419.  
  420. ready_for_next_irq_1:
  421.      mov    [check_idle_semaphore],5
  422.      mov   al, 0x20
  423.      out    0xa0,al
  424.      out   0x20, al
  425.      ret
  426.  
  427. irqD:
  428.      save_ring3_context
  429.      mov   ax, os_data
  430.      mov   ds, ax
  431.      mov   es, ax
  432.  
  433.      mov   dx,0xf0
  434.      mov   al,0
  435.      out   dx,al
  436.  
  437.      mov   dx,0xa0
  438.      mov   al,0x20
  439.      out   dx,al
  440.      mov   dx,0x20
  441.      out   dx,al
  442.  
  443.      restore_ring3_context
  444.  
  445.      iret
  446.  
  447.  
  448. irqhandler:
  449.  
  450.      push   edi
  451.  
  452.      mov    esi,edi          ; 1
  453.      shl    esi,6            ; 1
  454.      add    esi,irq00read    ; 1
  455.      shl    edi,12           ; 1
  456.      add    edi,0x2E0000
  457.      mov    ecx,16
  458.  
  459.      mov    [check_idle_semaphore],5
  460.  
  461.    irqnewread:
  462.      dec    ecx
  463.      js     irqover
  464.  
  465.      mov    dx,[esi]         ; 2+
  466.  
  467.      cmp    dx,0             ; 1
  468.      jz     irqover
  469.      cmp    [esi+3],byte 1   ; 2     ; byte read
  470.      jne    noirqbyte        ; 4-11
  471.  
  472.      in     al,dx
  473.  
  474.      mov    edx,[edi]
  475.      cmp    edx,4000
  476.      je     irqfull
  477.      mov    ebx,edi
  478.      add    ebx,0x10
  479.      add    ebx,edx
  480.      mov    [ebx],al
  481.      inc    edx
  482.      mov    [edi],edx
  483.  
  484.      add    esi,4
  485.      jmp    irqnewread
  486.  
  487.    noirqbyte:
  488.  
  489.  
  490.      cmp    [esi+3],byte 2     ; word read
  491.      jne    noirqword
  492.  
  493.      in     ax,dx
  494.  
  495.      mov    edx,[edi]
  496.      cmp    edx,4000
  497.      je     irqfull
  498.      mov    ebx,edi
  499.      add    ebx,0x10
  500.      add    ebx,edx
  501.      mov    [ebx],ax
  502.      add    edx,2
  503.      mov    [edi],edx
  504.      add    esi,4
  505.      jmp    irqnewread
  506.  
  507.    noirqword:
  508.    irqfull:
  509.    irqover:
  510.  
  511.      mov    al,0x20            ; ready for next irq
  512.      out    0x20,al
  513.  
  514.      pop    ebx
  515.      cmp    ebx,7
  516.      jbe    noa0
  517.      out    0xa0,al
  518.    noa0:
  519.  
  520.      ret
  521.  
  522.  
  523.  
  524. set_application_table_status:
  525.         push eax
  526.  
  527.         mov  eax,[0x3000]
  528.         shl  eax, 5
  529.         add  eax,0x3000+TASKDATA.pid
  530.         mov  eax,[eax]
  531.  
  532.         mov  [application_table_status],eax
  533.  
  534.         pop  eax
  535.  
  536.         ret
  537.  
  538.  
  539. clear_application_table_status:
  540.         push eax
  541.  
  542.         mov  eax,[0x3000]
  543.         shl  eax, 5
  544.         add  eax,0x3000+TASKDATA.pid
  545.         mov  eax,[eax]
  546.  
  547.         cmp  eax,[application_table_status]
  548.         jne  apptsl1
  549.         mov  [application_table_status],0
  550.       apptsl1:
  551.  
  552.         pop  eax
  553.  
  554.         ret
  555.  
  556.  
  557.  
  558. sys_resize_app_memory:
  559.         ; eax = 1 - resize
  560.         ;     ebx = new amount of memory
  561.  
  562.         cmp    eax,1
  563.         jne    .no_application_mem_resize
  564.  
  565.         stdcall new_mem_resize, ebx
  566.         mov [esp+36], eax
  567.         ret
  568.  
  569. .no_application_mem_resize:
  570.         ret
  571.  
  572.  
  573.  
  574. get_app_params:
  575.  
  576.     push eax
  577.  
  578.     cmp  [0x90000+6],word '00'
  579.     jne  no_00_header
  580.  
  581.     mov  eax,[0x90000+12]
  582.     mov  [app_start],eax
  583.     mov  eax,[0x90000+16]
  584.     mov  [app_i_end],eax
  585.     mov  eax,[0x90000+20]
  586.     mov  [app_mem],eax
  587. ; \begin{diamond}[20.08.2006]
  588. ; sanity check (functions 19,58 load app_i_end bytes and that must
  589. ; fit in allocated memory to prevent kernel faults)
  590.     cmp  eax,[app_i_end]
  591.     jb   no_01_header
  592. ; \end{diamond}[20.08.2006]
  593.     shr  eax,1
  594.     sub  eax,0x10
  595.     mov  [app_esp],eax
  596.     mov  eax,[0x90000+24]
  597.     mov  [app_i_param],eax
  598.     mov  [app_i_icon],dword 0
  599.  
  600.     pop  eax
  601.     clc
  602.     ret
  603.  
  604.   no_00_header:
  605.  
  606.  
  607.     cmp  [0x90000+6],word '01'
  608.     jne  no_01_header
  609.  
  610.     mov  eax,[0x90000+12]
  611.     mov  [app_start],eax
  612.     mov  eax,[0x90000+16]
  613.     mov  [app_i_end],eax
  614.     mov  eax,[0x90000+20]
  615.     mov  [app_mem],eax
  616. ; \begin{diamond}[20.08.2006]
  617.     cmp  eax,[app_i_end]
  618.     jb   no_01_header
  619. ; \end{diamond}[20.08.2006]
  620.     mov  eax,[0x90000+24]
  621.     mov  [app_esp],eax
  622.     mov  eax,[0x90000+28]
  623.     mov  [app_i_param],eax
  624.     mov  eax,[0x90000+32]
  625.     mov  [app_i_icon],eax
  626.  
  627.     pop  eax
  628.     clc
  629.     ret
  630.  
  631.    no_01_header:
  632.  
  633.     pop  eax
  634.     stc
  635.     ret
  636.  
  637.  
  638. uglobal
  639.   new_process_place  dd  0x0
  640.   app_start    dd  0x0
  641.   app_i_end    dd  0x0
  642.   app_mem      dd  0x0
  643.   app_esp      dd  0x0
  644.   app_i_param  dd  0x0
  645.   app_i_icon   dd  0x0
  646. ;  app_mem_pos  dd  0x0
  647.   appl_path        dd 0x0
  648.   appl_path_size   dd 0x0
  649. endg
  650.  
  651.  
  652. sys_threads:
  653.  
  654. ; eax=1 create thread
  655. ;
  656. ;   ebx=thread start
  657. ;   ecx=thread stack value
  658. ;
  659. ; on return : eax = pid
  660. jmp new_sys_threads
  661.  
  662. iglobal
  663.   process_terminating   db 'K : Process - terminating',13,10,0
  664.   process_terminated    db 'K : Process - done',13,10,0
  665. endg
  666.  
  667.  
  668. terminate: ; terminate application
  669.     push   esi
  670.     mov    esi,process_terminating
  671.     call   sys_msg_board_str
  672.     pop    esi
  673.  
  674. @@:
  675.     cli
  676.     cmp   [application_table_status],0
  677.     je    term9
  678.     sti
  679.     call  change_task
  680.     jmp   @b
  681.   term9:
  682.  
  683.     call  set_application_table_status
  684.  
  685.     mov    eax,esi
  686.  
  687.     pushad
  688.     shl   eax,8
  689.     mov   eax,[PROC_BASE+eax+0xB8]
  690.     stdcall destroy_app_space, eax
  691.     popad
  692.  
  693.     cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  694.     jne   fpu_ok_1
  695.  
  696.     mov [fpu_owner],1
  697.     mov eax, [256+PROC_BASE+0x10]
  698.     bt [cpu_caps], CAPS_FXSR
  699.     jnc .no_SSE
  700.     fxrstor [eax]
  701.     jmp fpu_ok_1
  702. .no_SSE:
  703.     fnclex
  704.     frstor [eax]
  705. fpu_ok_1:
  706.  
  707.     mov   [0xf400],byte 0           ; empty keyboard buffer
  708.     mov   [0xf500],byte 0           ; empty button buffer
  709.  
  710.  
  711. ; remove defined hotkeys
  712.         mov     eax, hotkey_list
  713. .loop:
  714.         cmp     [eax+8], esi
  715.         jnz     .cont
  716.         mov     ecx, [eax]
  717.         jecxz   @f
  718.         push    dword [eax+12]
  719.         pop     dword [ecx+12]
  720. @@:
  721.         mov     ecx, [eax+12]
  722.         push    dword [eax]
  723.         pop     dword [ecx]
  724.         xor     ecx, ecx
  725.         mov     [eax], ecx
  726.         mov     [eax+4], ecx
  727.         mov     [eax+8], ecx
  728.         mov     [eax+12], ecx
  729. .cont:
  730.         add     eax, 16
  731.         cmp     eax, hotkey_list+256*16
  732.         jb      .loop
  733. ; remove hotkeys in buffer
  734.         mov     eax, hotkey_buffer
  735. .loop2:
  736.         cmp     [eax], esi
  737.         jnz     .cont2
  738.         and     dword [eax+4], 0
  739.         and     dword [eax], 0
  740. .cont2:
  741.         add     eax, 8
  742.         cmp     eax, hotkey_buffer+120*8
  743.         jb      .loop2
  744.  
  745.     mov   ecx,esi                 ; remove buttons
  746.   bnewba2:
  747.     mov   edi,[0xfe88]
  748.     mov   eax,edi
  749.     cld
  750.     movzx ebx,word [edi]
  751.     inc   bx
  752.   bnewba:
  753.     dec   bx
  754.     jz    bnmba
  755.     add   eax,0x10
  756.     cmp   cx,[eax]
  757.     jnz   bnewba
  758.     pusha
  759.     mov   ecx,ebx
  760.     inc   ecx
  761.     shl   ecx,4
  762.     mov   ebx,eax
  763.     add   eax,0x10
  764.     call  memmove
  765.     dec   dword [edi]
  766.     popa
  767.     jmp   bnewba2
  768.   bnmba:
  769.  
  770.     pusha     ; save window coordinates for window restoring
  771.     cld
  772.     shl   esi,5
  773.     add   esi,window_data
  774.     mov   eax,[esi+WDATA.box.left]
  775.     mov   [dlx],eax
  776.     add   eax,[esi+WDATA.box.width]
  777.     mov   [dlxe],eax
  778.     mov   eax,[esi+WDATA.box.top]
  779.     mov   [dly],eax
  780.     add   eax,[esi+WDATA.box.height]
  781.     mov   [dlye],eax
  782.  
  783.     xor   eax, eax
  784.     mov   [esi+WDATA.box.left],eax
  785.     mov   [esi+WDATA.box.width],eax
  786.     mov   [esi+WDATA.box.top],eax
  787.     mov   [esi+WDATA.box.height],eax
  788.     mov   [esi+WDATA.cl_workarea],eax
  789.     mov   [esi+WDATA.cl_titlebar],eax
  790.     mov   [esi+WDATA.cl_frames],eax
  791.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  792.     lea   edi, [esi-window_data+draw_data]
  793.     mov   ecx,32/4
  794.     rep   stosd
  795.     popa
  796.  
  797. ; debuggee test
  798.     pushad
  799.     mov  edi, esi
  800.     shl  edi, 5
  801.     mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
  802.     test eax, eax
  803.     jz   .nodebug
  804.     push 8
  805.     pop  ecx
  806.     push dword [0x3000+edi+TASKDATA.pid]   ; PID
  807.     push 2
  808.     call debugger_notify
  809.     pop  ecx
  810.     pop  ecx
  811. .nodebug:
  812.     popad
  813.  
  814.     pusha         ; at 0x80000+
  815.     mov   edi,esi
  816.     shl   edi,8
  817.     add   edi,0x80000
  818.     mov   ecx,256/4
  819.     xor   eax, eax
  820.     rep   stosd
  821.     popa
  822.  
  823.     pusha          ; name to spaces
  824.     mov   edi,esi
  825.     shl   edi,8
  826.     add   edi,0x80000+APPDATA.app_name
  827.     mov   ecx,11
  828.     mov   eax,' '
  829.     rep   stosb
  830.     popa
  831.  
  832.  
  833.   ; activate window
  834.         movzx  eax, word [0xC000 + esi*2]
  835.         cmp    eax, [0x3004]
  836.         jne    .dont_activate
  837.         pushad
  838.  .check_next_window:
  839.         dec    eax
  840.         cmp    eax, 1
  841.         jbe    .nothing_to_activate
  842.         lea    esi, [0xc400+eax*2]
  843.         movzx  edi, word [esi]               ; edi = process
  844.         shl    edi, 5
  845.         cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
  846.         je     .check_next_window
  847.         add    edi, window_data
  848. ; \begin{diamond}[19.09.2006]
  849. ; skip minimized windows
  850.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  851.         jnz    .check_next_window
  852. ; \end{diamond}
  853.         call   waredraw
  854.  .nothing_to_activate:
  855.         popad
  856.  .dont_activate:
  857.  
  858.         push    esi     ; remove hd1 & cd & flp reservation
  859.         shl     esi, 5
  860.         mov     esi, [esi+0x3000+TASKDATA.pid]
  861.         cmp     [hd1_status], esi
  862.         jnz     @f
  863.         mov     [hd1_status], 0
  864. @@:
  865.         cmp     [cd_status], esi
  866.         jnz     @f
  867.         mov     [cd_status], 0
  868. @@:
  869.         cmp     [flp_status], esi
  870.         jnz     @f
  871.         mov     [flp_status], 0
  872. @@:
  873.         pop     esi
  874.  
  875.     pusha ; remove all irq reservations
  876.     mov   eax,esi
  877.     shl   eax, 5
  878.     mov   eax,[eax+0x3000+TASKDATA.pid]
  879.     mov   edi,irq_owner
  880.     mov   ecx,16
  881.   newirqfree:
  882.     scasd
  883.     jne   nofreeirq
  884.     mov   [edi-4],dword 0
  885.   nofreeirq:
  886.     loop   newirqfree
  887.     popa
  888.  
  889.  
  890.     pusha                     ; remove all port reservations
  891.     mov   edx,esi
  892.     shl   edx, 5
  893.     add   edx,0x3000
  894.     mov   edx,[edx+TASKDATA.pid]
  895.  
  896.   rmpr0:
  897.  
  898.     mov   esi,[0x2d0000]
  899.  
  900.     cmp   esi,0
  901.     je    rmpr9
  902.  
  903.   rmpr3:
  904.  
  905.     mov   edi,esi
  906.     shl   edi,4
  907.     add   edi,0x2d0000
  908.  
  909.     cmp   edx,[edi]
  910.     je    rmpr4
  911.  
  912.     dec   esi
  913.     jnz   rmpr3
  914.  
  915.     jmp   rmpr9
  916.  
  917.   rmpr4:
  918.  
  919.     mov   ecx,256
  920.     sub   ecx,esi
  921.     shl   ecx,4
  922.  
  923.     mov   esi,edi
  924.     add   esi,16
  925.     cld
  926.     rep   movsb
  927.  
  928.     dec   dword [0x2d0000]
  929.  
  930.     jmp   rmpr0
  931.  
  932.   rmpr9:
  933.  
  934.     popa
  935.     mov  edi,esi         ; do not run this process slot
  936.     shl  edi, 5
  937.     mov  [edi+0x3000 + TASKDATA.state],byte 9
  938. ; debugger test - terminate all debuggees
  939.     mov  eax, 2
  940.     mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
  941. .xd0:
  942.     cmp  eax, [0x3004]
  943.     ja   .xd1
  944.     cmp  dword [ecx], esi
  945.     jnz  @f
  946.     and  dword [ecx], 0
  947.     pushad
  948.     xchg eax, ebx
  949.     mov  eax, 2
  950.     call sys_system
  951.     popad
  952. @@:
  953.     inc  eax
  954.     add  ecx, 0x100
  955.     jmp  .xd0
  956. .xd1:
  957. ;    call  systest
  958.     sti  ; .. and life goes on
  959.  
  960.     mov   eax, [dlx]
  961.     mov   ebx, [dly]
  962.     mov   ecx, [dlxe]
  963.     mov   edx, [dlye]
  964.     call  calculatescreen
  965.     xor   eax, eax
  966.     xor   esi, esi
  967.     call  redrawscreen
  968.  
  969.     mov   [0xfff4],byte 0  ; no mouse background
  970.     mov   [0xfff5],byte 0  ; draw mouse
  971.  
  972.     mov   [application_table_status],0
  973.     mov   esi,process_terminated
  974.     call  sys_msg_board_str
  975.  
  976.     ret
  977.  
  978. iglobal
  979.   boot_sched_1    db   'Building gdt tss pointer',0
  980.   boot_sched_2    db   'Building IDT table',0
  981. endg
  982.  
  983.  
  984. build_scheduler:
  985.  
  986.         mov    esi,boot_sched_1
  987.         call   boot_log
  988.         call   build_process_gdt_tss_pointer
  989.  
  990.         mov    esi,boot_sched_2
  991.         call   boot_log
  992.         call   build_interrupt_table
  993.  
  994.         ret
  995.  
  996.