Subversion Repositories Kolibri OS

Rev

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

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