Subversion Repositories Kolibri OS

Rev

Rev 2100 | Rev 2112 | 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: 2104 $
  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,  irq_serv.irq_6,  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, irq_serv.irq_14, irq_serv.irq_15
  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. ; bl - error vector
  194. show_error_parameters:
  195.         cmp     bl, 0x06
  196.         jnz     .no_ud
  197.         push    ebx
  198.         mov     ebx, ud_user_message
  199.         mov     ebp, notifyapp
  200.         call    fs_execute_from_sysdir_param
  201.         pop     ebx
  202. .no_ud:
  203.         mov     edx,[TASK_BASE] ;not scratched below
  204.         DEBUGF  1, "K : Process - forced terminate PID: %x\n", [edx+TASKDATA.pid]
  205.         cmp     bl, 0x08
  206.         jb      .l0
  207.         cmp     bl, 0x0e
  208.         jbe     .l1
  209.   .l0:  mov     bl, 0x09
  210.   .l1:  mov     eax,[msg_fault_sel+ebx*4 - 0x08*4]
  211.         DEBUGF  1, "K : %s\n", eax
  212.         mov     eax, [reg_cs3+4]
  213.         mov     edi, msg_sel_app
  214.         mov     ebx, [reg_esp3+4]
  215.         cmp     eax, app_code
  216.         je      @f
  217.         mov     edi, msg_sel_ker
  218.         mov     ebx, [reg_esp0+4]
  219.     @@: DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [reg_eax+4], [reg_ebx+4], [reg_ecx+4]
  220.         DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [reg_edx+4], [reg_esi+4], [reg_edi+4]
  221.         DEBUGF  1, "K : EBP : %x EIP : %x ESP : %x\n", [reg_ebp+4], [reg_eip+4], ebx
  222.         DEBUGF  1, "K : Flags : %x CS : %x (%s)\n", [reg_eflags+4], eax, edi
  223.         ret
  224. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  225.  
  226.   restore  reg_ss
  227.   restore  reg_esp3
  228.   restore  reg_eflags
  229.   restore  reg_cs
  230.   restore  reg_eip
  231.   restore  reg_eax
  232.   restore  reg_ecx
  233.   restore  reg_edx
  234.   restore  reg_ebx
  235.   restore  reg_esp0
  236.   restore  reg_ebp
  237.   restore  reg_esi
  238.   restore  reg_edi
  239.  
  240.  
  241. align 4
  242. irqD:
  243.         push  eax
  244.         xor   eax,eax
  245.         out   0xf0,al
  246.         mov   al,0x20
  247.         out   0xa0,al
  248.         out   0x20,al
  249.         pop   eax
  250.         iret
  251.  
  252.  
  253. align 4
  254. set_application_table_status:
  255.         push eax
  256.  
  257.         mov  eax,[CURRENT_TASK]
  258.         shl  eax, 5
  259.         add  eax,CURRENT_TASK+TASKDATA.pid
  260.         mov  eax,[eax]
  261.  
  262.         mov  [application_table_status],eax
  263.  
  264.         pop  eax
  265.  
  266.         ret
  267.  
  268. align 4
  269. clear_application_table_status:
  270.         push eax
  271.  
  272.         mov  eax,[CURRENT_TASK]
  273.         shl  eax, 5
  274.         add  eax,CURRENT_TASK+TASKDATA.pid
  275.         mov  eax,[eax]
  276.  
  277.         cmp  eax,[application_table_status]
  278.         jne  apptsl1
  279.         xor  eax,eax
  280.         mov  [application_table_status],eax
  281.       apptsl1:
  282.  
  283.         pop  eax
  284.  
  285.         ret
  286.  
  287. ;  * eax = 64 - íîìåð ôóíêöèè
  288. ;  * ebx = 1 - åäèíñòâåííàÿ ïîäôóíêöèÿ
  289. ;  * ecx = íîâûé ðàçìåð ïàìÿòè
  290. ;Âîçâðàùàåìîå çíà÷åíèå:
  291. ;  * eax = 0 - óñïåøíî
  292. ;  * eax = 1 - íåäîñòàòî÷íî ïàìÿòè
  293.  
  294. align 4
  295. sys_resize_app_memory:
  296.         ; ebx = 1 - resize
  297.         ; ecx = new amount of memory
  298.  
  299. ;        cmp    eax,1
  300.         dec     ebx
  301.         jnz    .no_application_mem_resize
  302.         stdcall new_mem_resize, ecx
  303.         mov [esp+32], eax
  304. .no_application_mem_resize:
  305.         ret
  306.  
  307. iglobal
  308. ;  process_terminating  db 'K : Process - terminating',13,10,0
  309. ;  process_terminated   db 'K : Process - done',13,10,0
  310.   msg_obj_destroy       db 'K : destroy app object',13,10,0
  311. endg
  312.  
  313. ; param
  314. ;  esi= slot
  315.  
  316. align 4
  317. terminate: ; terminate application
  318.  
  319.            .slot equ esp   ;locals
  320.  
  321.            push   esi      ;save .slot
  322.  
  323.            shl esi, 8
  324.            cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
  325.            jne @F
  326.            pop    esi
  327.            shl    esi, 5
  328.            mov    [CURRENT_TASK+esi+TASKDATA.state], 9
  329.            ret
  330. @@:
  331.            ;mov    esi,process_terminating
  332.            ;call   sys_msg_board_str
  333. @@:
  334.            cli
  335.            cmp   [application_table_status],0
  336.            je    term9
  337.            sti
  338.            call  change_task
  339.            jmp   @b
  340. term9:
  341.            call  set_application_table_status
  342.  
  343. ; if the process is in V86 mode...
  344.         mov     eax, [.slot]
  345.         shl     eax, 8
  346.         mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
  347.         add     esi, RING0_STACK_SIZE
  348.         cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
  349.         jz      .nov86
  350. ; ...it has page directory for V86 mode
  351.         mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
  352.         mov     ecx, [esi+4]
  353.         mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
  354. ; ...and I/O permission map for V86 mode
  355.         mov     ecx, [esi+12]
  356.         mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
  357.         mov     ecx, [esi+8]
  358.         mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
  359. .nov86:
  360.  
  361.            mov esi, [.slot]
  362.            shl esi,8
  363.            add esi, SLOT_BASE+APP_OBJ_OFFSET
  364. @@:
  365.            mov eax, [esi+APPOBJ.fd]
  366.            test eax, eax
  367.            jz @F
  368.  
  369.            cmp eax, esi
  370.            je @F
  371.  
  372.            push esi
  373.            call [eax+APPOBJ.destroy]
  374.            DEBUGF 1,"%s",msg_obj_destroy
  375.            pop esi
  376.            jmp @B
  377. @@:
  378.  
  379.            mov eax, [.slot]
  380.            shl eax, 8
  381.            stdcall destroy_app_space, [SLOT_BASE+eax+APPDATA.dir_table], [SLOT_BASE+eax+APPDATA.dlls_list_ptr]
  382.  
  383.            mov esi, [.slot]
  384.            cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  385.            jne @F
  386.  
  387.            mov [fpu_owner],1
  388.            mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
  389.            clts
  390.            bt [cpu_caps], CAPS_SSE
  391.            jnc .no_SSE
  392.            fxrstor [eax]
  393.            jmp @F
  394. .no_SSE:
  395.            fnclex
  396.            frstor [eax]
  397. @@:
  398.  
  399.     mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
  400.     mov   [BTN_COUNT],byte 0           ; empty button buffer
  401.  
  402.  
  403. ; remove defined hotkeys
  404.         mov     eax, hotkey_list
  405. .loop:
  406.         cmp     [eax+8], esi
  407.         jnz     .cont
  408.         mov     ecx, [eax]
  409.         jecxz   @f
  410.         push    dword [eax+12]
  411.         pop     dword [ecx+12]
  412. @@:
  413.         mov     ecx, [eax+12]
  414.         push    dword [eax]
  415.         pop     dword [ecx]
  416.         xor     ecx, ecx
  417.         mov     [eax], ecx
  418.         mov     [eax+4], ecx
  419.         mov     [eax+8], ecx
  420.         mov     [eax+12], ecx
  421. .cont:
  422.         add     eax, 16
  423.         cmp     eax, hotkey_list+256*16
  424.         jb      .loop
  425. ; remove hotkeys in buffer
  426.         mov     eax, hotkey_buffer
  427. .loop2:
  428.         cmp     [eax], esi
  429.         jnz     .cont2
  430.         and     dword [eax+4], 0
  431.         and     dword [eax], 0
  432. .cont2:
  433.         add     eax, 8
  434.         cmp     eax, hotkey_buffer+120*8
  435.         jb      .loop2
  436.  
  437.     mov   ecx,esi                 ; remove buttons
  438.   bnewba2:
  439.     mov   edi,[BTN_ADDR]
  440.     mov   eax,edi
  441.     cld
  442.     movzx ebx,word [edi]
  443.     inc   bx
  444.   bnewba:
  445.     dec   bx
  446.     jz    bnmba
  447.     add   eax,0x10
  448.     cmp   cx,[eax]
  449.     jnz   bnewba
  450.     pusha
  451.     mov   ecx,ebx
  452.     inc   ecx
  453.     shl   ecx,4
  454.     mov   ebx,eax
  455.     add   eax,0x10
  456.     call  memmove
  457.     dec   dword [edi]
  458.     popa
  459.     jmp   bnewba2
  460.   bnmba:
  461.  
  462.     pusha     ; save window coordinates for window restoring
  463.     cld
  464.     shl   esi,5
  465.     add   esi,window_data
  466.     mov   eax,[esi+WDATA.box.left]
  467.     mov   [draw_limits.left],eax
  468.     add   eax,[esi+WDATA.box.width]
  469.     mov   [draw_limits.right],eax
  470.     mov   eax,[esi+WDATA.box.top]
  471.     mov   [draw_limits.top],eax
  472.     add   eax,[esi+WDATA.box.height]
  473.     mov   [draw_limits.bottom],eax
  474.  
  475.     xor   eax, eax
  476.     mov   [esi+WDATA.box.left],eax
  477.     mov   [esi+WDATA.box.width],eax
  478.     mov   [esi+WDATA.box.top],eax
  479.     mov   [esi+WDATA.box.height],eax
  480.     mov   [esi+WDATA.cl_workarea],eax
  481.     mov   [esi+WDATA.cl_titlebar],eax
  482.     mov   [esi+WDATA.cl_frames],eax
  483.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  484.     lea   edi, [esi-window_data+draw_data]
  485.     mov   ecx,32/4
  486.     rep   stosd
  487.     popa
  488.  
  489. ; debuggee test
  490.     pushad
  491.     mov  edi, esi
  492.     shl  edi, 5
  493.     mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
  494.     test eax, eax
  495.     jz   .nodebug
  496.     push 8
  497.     pop  ecx
  498.     push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
  499.     push 2
  500.     call debugger_notify
  501.     pop  ecx
  502.     pop  ecx
  503. .nodebug:
  504.     popad
  505.  
  506.            mov ebx, [.slot]
  507.            shl ebx, 8
  508.            push ebx
  509.            mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
  510.  
  511.            stdcall kernel_free, ebx
  512.  
  513.            pop ebx
  514.            mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
  515.            stdcall kernel_free, ebx
  516.  
  517.            mov edi, [.slot]
  518.            shl edi,8
  519.            add edi,SLOT_BASE
  520.  
  521.            mov eax, [edi+APPDATA.io_map]
  522.            cmp eax, [SLOT_BASE+256+APPDATA.io_map]
  523.            je @F
  524.            call free_page
  525. @@:
  526.            mov eax, [edi+APPDATA.io_map+4]
  527.            cmp eax, [SLOT_BASE+256+APPDATA.io_map+4]
  528.            je @F
  529.            call free_page
  530. @@:
  531.            mov eax, 0x20202020
  532.            stosd
  533.            stosd
  534.            stosd
  535.            mov ecx,244/4
  536.            xor eax, eax
  537.            rep stosd
  538.  
  539.   ; activate window
  540.         movzx  eax, word [WIN_STACK + esi*2]
  541.         cmp    eax, [TASK_COUNT]
  542.         jne    .dont_activate
  543.         pushad
  544.  .check_next_window:
  545.         dec    eax
  546.         cmp    eax, 1
  547.         jbe    .nothing_to_activate
  548.         lea    esi, [WIN_POS+eax*2]
  549.         movzx  edi, word [esi]               ; edi = process
  550.         shl    edi, 5
  551.         cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
  552.         je     .check_next_window
  553.         add    edi, window_data
  554. ; \begin{diamond}[19.09.2006]
  555. ; skip minimized windows
  556.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  557.         jnz    .check_next_window
  558. ; \end{diamond}
  559.         call   waredraw
  560.  .nothing_to_activate:
  561.         popad
  562.  .dont_activate:
  563.  
  564.         push    esi     ; remove hd1 & cd & flp reservation
  565.         shl     esi, 5
  566.         mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
  567.         cmp     [hd1_status], esi
  568.         jnz     @f
  569.         call    free_hd_channel
  570.         and     [hd1_status], 0
  571. @@:
  572.         cmp     [cd_status], esi
  573.         jnz     @f
  574.         call    free_cd_channel
  575.         and     [cd_status], 0
  576. @@:
  577.         cmp     [flp_status], esi
  578.         jnz     @f
  579.         and     [flp_status], 0
  580. @@:
  581.         pop     esi
  582.         cmp     [bgrlockpid], esi
  583.         jnz     @f
  584.         and     [bgrlockpid], 0
  585.         and     [bgrlock], 0
  586. @@:
  587.  
  588.     pusha                     ; remove all port reservations
  589.     mov   edx,esi
  590.     shl   edx, 5
  591.     add   edx,CURRENT_TASK
  592.     mov   edx,[edx+TASKDATA.pid]
  593.  
  594.   rmpr0:
  595.  
  596.     mov   esi,[RESERVED_PORTS]
  597.  
  598.     test  esi,esi
  599.     jz    rmpr9
  600.  
  601.   rmpr3:
  602.  
  603.     mov   edi,esi
  604.     shl   edi,4
  605.     add   edi,RESERVED_PORTS
  606.  
  607.     cmp   edx,[edi]
  608.     je    rmpr4
  609.  
  610.     dec   esi
  611.     jnz   rmpr3
  612.  
  613.     jmp   rmpr9
  614.  
  615.   rmpr4:
  616.  
  617.     mov   ecx,256
  618.     sub   ecx,esi
  619.     shl   ecx,4
  620.  
  621.     mov   esi,edi
  622.     add   esi,16
  623.     cld
  624.     rep   movsb
  625.  
  626.     dec   dword [RESERVED_PORTS]
  627.  
  628.     jmp   rmpr0
  629.  
  630.   rmpr9:
  631.  
  632.     popa
  633.     mov  edi,esi         ; do not run this process slot
  634.     shl  edi, 5
  635.     mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
  636. ; debugger test - terminate all debuggees
  637.     mov  eax, 2
  638.     mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
  639. .xd0:
  640.     cmp  eax, [TASK_COUNT]
  641.     ja   .xd1
  642.     cmp  dword [ecx], esi
  643.     jnz  @f
  644.     and  dword [ecx], 0
  645.     pushad
  646.     xchg eax, ecx
  647.     mov  ebx, 2
  648.     call sys_system
  649.     popad
  650. @@:
  651.     inc  eax
  652.     add  ecx, 0x100
  653.     jmp  .xd0
  654. .xd1:
  655. ;    call  systest
  656.     sti  ; .. and life goes on
  657.  
  658.     mov   eax, [draw_limits.left]
  659.     mov   ebx, [draw_limits.top]
  660.     mov   ecx, [draw_limits.right]
  661.     mov   edx, [draw_limits.bottom]
  662.     call  calculatescreen
  663.     xor   eax, eax
  664.     xor   esi, esi
  665.     call  redrawscreen
  666.  
  667.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  668.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  669.  
  670.     and   [application_table_status],0
  671.     ;mov   esi,process_terminated
  672.     ;call  sys_msg_board_str
  673.     add esp, 4
  674.     ret
  675. restore .slot
  676.  
  677. iglobal
  678. if lang eq ru
  679.   boot_sched_1    db   '‘®§¤ ­¨¥ GDT TSS 㪠§ â¥«ï',0
  680.   boot_sched_2    db   '‘®§¤ ­¨¥ IDT â ¡«¨æë',0
  681. else
  682.   boot_sched_1    db   'Building gdt tss pointer',0
  683.   boot_sched_2    db   'Building IDT table',0
  684. end if
  685. endg
  686.  
  687.  
  688. build_scheduler:
  689.  
  690.         mov    esi,boot_sched_1
  691.         call   boot_log
  692.   ;      call   build_process_gdt_tss_pointer
  693.  
  694.   ;      mov    esi,boot_sched_2
  695.   ;      call   boot_log
  696.  
  697.         ret
  698.