Subversion Repositories Kolibri OS

Rev

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