Subversion Repositories Kolibri OS

Rev

Rev 3145 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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