Subversion Repositories Kolibri OS

Rev

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