Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2007. 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: 684 $
  15.  
  16.  
  17. align 4
  18. idtreg:
  19.      dw   8*0x41-1
  20.      dd   idts+8
  21.  
  22. build_interrupt_table:
  23.  
  24.         mov    edi, idts+8
  25.         mov    esi, sys_int
  26.         mov    ecx, 0x40
  27.      @@:
  28.         lodsd
  29.         mov    [edi],   ax           ; lower part of offset
  30.         mov    [edi+2], word os_code ; segment selector
  31.         mov     ax, word 10001110b shl 8        ; type: interrupt gate
  32.         mov     [edi+4], eax
  33.         add    edi, 8
  34.         loop    @b
  35.  
  36.         ;mov    edi,8*0x40+idts+8
  37.         mov     dword [edi], (i40 and 0xFFFF) or (os_code shl 16)
  38.         mov     dword [edi+4], (11101111b shl 8) or (i40 and 0xFFFF0000)
  39.                                                 ; type: trap gate
  40.         ret
  41.  
  42. iglobal
  43.  
  44.   msg_sel_ker   db "kernel", 0
  45.   msg_sel_app   db "application", 0
  46.  
  47.   sys_int:
  48.     dd e0,debug_exc,e2,e3
  49.     dd e4,e5,e6,e7
  50.     dd e8,e9,e10,e11
  51.     dd e12,e13,page_fault_handler,e15
  52.  
  53.     dd except_16, e17,e18, except_19
  54.     times 12 dd unknown_interrupt
  55.  
  56.     dd   irq0, irq_serv.irq_1, p_irq2
  57. if USE_COM_IRQ
  58.     dd   irq_serv.irq_3, irq_serv.irq_4
  59. else
  60.     dd   p_irq3, p_irq4
  61. end if
  62.     dd   irq_serv.irq_5,  p_irq6,         irq_serv.irq_7
  63.     dd   irq_serv.irq_8,  irq_serv.irq_9, irq_serv.irq_10
  64.     dd   irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15
  65.  
  66.     times 16 dd unknown_interrupt
  67.  
  68.     dd   i40
  69. endg
  70.  
  71. macro save_ring3_context
  72. {
  73.     pushad
  74. }
  75. macro restore_ring3_context
  76. {
  77.     popad
  78. }
  79.  
  80. ; simply return control to interrupted process
  81. unknown_interrupt:
  82.      iret
  83.  
  84. macro exc_wo_code [num]
  85. {
  86.   forward
  87.   e#num :
  88.       save_ring3_context
  89.       mov bl, num
  90.       jmp exc_c
  91. }
  92.  
  93. macro exc_w_code [num]
  94. {
  95.   forward
  96.   e#num :
  97.       add esp, 4
  98.       save_ring3_context
  99.       mov bl, num
  100.       jmp exc_c
  101. }
  102.  
  103. exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 18
  104. exc_w_code 8, 10, 11, 12, 13, 14, 17
  105.  
  106. exc_c:
  107.         mov   ax, app_data  ;èñêëþ÷åíèå
  108.         mov   ds, ax        ;çàãðóçèì ïðàâèëüíûå çíà÷åíè
  109.         mov   es, ax        ;â ðåãèñòðû
  110.  
  111. ; test if debugging
  112.         cli
  113.         mov   eax, [current_slot]
  114.         mov   eax, [eax+APPDATA.debugger_slot]
  115.         test  eax, eax
  116.         jnz   .debug
  117.         sti
  118. ; not debuggee => say error and terminate
  119.         movzx eax, bl
  120.         mov   [error_interrupt], eax
  121.         call  show_error_parameters
  122.         add   esp, 0x20
  123.         mov   edx, [TASK_BASE]
  124.         mov   [edx + TASKDATA.state], byte 4
  125.  
  126.         jmp   change_task
  127.  
  128. .debug:
  129. ; we are debugged process, notify debugger and suspend ourself
  130. ; eax=debugger PID
  131.         cld
  132.         movzx ecx, bl
  133.         push  ecx
  134.         mov   ecx, [TASK_BASE]
  135.         push  dword [ecx+TASKDATA.pid]    ; PID of current process
  136.         push  12
  137.         pop   ecx
  138.         push  1        ; 1=exception
  139.         call  debugger_notify
  140.         pop   ecx
  141.         pop   ecx
  142.         pop   ecx
  143.         mov   edx, [TASK_BASE]
  144.         mov   byte [edx+TASKDATA.state], 1        ; suspended
  145.         call  change_task
  146.         restore_ring3_context
  147.         iretd
  148.  
  149. iglobal
  150.         hexletters      db '0123456789ABCDEF'
  151.         error_interrupt dd  -1
  152. endg
  153.  
  154. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  155. show_error_parameters:
  156.     mov eax,[CURRENT_TASK]
  157.     shl eax, 5
  158.     DEBUGF  1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax]
  159.     DEBUGF  1, "K : Exception : %x Error : xxxxxxxx\n", [error_interrupt]
  160.     DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20]
  161.     DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20]
  162.     DEBUGF  1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20]
  163.  
  164.     mov eax, [esp + 8 + 0x20]
  165.     mov edi, msg_sel_app
  166.     mov ebx, [esp + 16 + 0x20]
  167.     cmp eax, app_code
  168.     je  @f
  169.     mov edi, msg_sel_ker
  170.     mov ebx, [esp - 16 + 0x20]
  171. @@:
  172.     DEBUGF  1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi
  173.     ret
  174. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  175.  
  176.  
  177. ; irq1  ->  hid/keyboard.inc
  178. macro irqh [num]
  179. {
  180.   forward
  181.   p_irq#num :
  182.      save_ring3_context
  183.      mov   edi, num
  184.      jmp   irq_c
  185. }
  186.  
  187. irqh 2,5,7,8,9,10,11
  188.  
  189. irq_c:
  190.      mov   ax, app_data  ;os_data
  191.      mov   ds, ax
  192.      mov   es, ax
  193.      call  irqhandler
  194.      restore_ring3_context
  195.      iret
  196.  
  197. p_irq6:
  198.      save_ring3_context
  199.      mov   ax, app_data  ;os_data
  200.      mov   ds, ax
  201.      mov   es, ax
  202.      call  fdc_irq
  203.      call  ready_for_next_irq
  204.      restore_ring3_context
  205.      iret
  206.  
  207. p_irq3:
  208.      save_ring3_context
  209.      mov   ax, app_data  ;os_data
  210.      mov   ds, ax
  211.      mov   es, ax
  212.      cmp   [com2_mouse_detected],0
  213.      je    old_irq3_handler
  214.      mov   esi, com2_mouse
  215.      mov   dx, 2F8h     ;[COMPortBaseAddr]
  216.      call  check_mouse_data_com
  217.      jmp   p_irq3_1
  218.  old_irq3_handler:
  219.      mov   edi,3
  220.      call  irqhandler
  221.   p_irq3_1:
  222.      restore_ring3_context
  223.      iret
  224.  
  225. p_irq4:
  226.      save_ring3_context
  227.      mov   ax, app_data  ;os_data
  228.      mov   ds, ax
  229.      mov   es, ax
  230.      cmp   [com1_mouse_detected],0
  231.      je    old_irq4_handler
  232.      mov   esi, com1_mouse
  233.      mov   dx, 3F8h     ;[COMPortBaseAddr]
  234.      call  check_mouse_data_com
  235.      jmp   p_irq4_1
  236.  old_irq4_handler:
  237.      mov   edi,4
  238.      call  irqhandler
  239.   p_irq4_1:
  240.      restore_ring3_context
  241.      iret
  242.  
  243. p_irq14:
  244.         save_ring3_context
  245.         mov     ax, app_data  ;os_data
  246.         mov     ds, ax
  247.         mov     es, ax
  248.         call    [irq14_func]
  249.         call    ready_for_next_irq_1
  250.         restore_ring3_context
  251.         iret
  252. p_irq15:
  253.         save_ring3_context
  254.         mov     ax, app_data  ;os_data
  255.         mov     ds, ax
  256.         mov     es, ax
  257.         call    [irq15_func]
  258.         call    ready_for_next_irq_1
  259.         restore_ring3_context
  260.         iret
  261.  
  262. ready_for_next_irq:
  263.      mov    [check_idle_semaphore],5
  264.      mov   al, 0x20
  265.      out   0x20, al
  266.      ret
  267.  
  268. ready_for_next_irq_1:
  269.      mov    [check_idle_semaphore],5
  270.      mov   al, 0x20
  271.      out    0xa0,al
  272.      out   0x20, al
  273.      ret
  274.  
  275. irqD:
  276.      save_ring3_context
  277.      mov   ax, app_data  ;os_data
  278.      mov   ds, ax
  279.      mov   es, ax
  280.  
  281.      mov   dx,0xf0
  282.      mov   al,0
  283.      out   dx,al
  284.  
  285.      mov   dx,0xa0
  286.      mov   al,0x20
  287.      out   dx,al
  288.      mov   dx,0x20
  289.      out   dx,al
  290.  
  291.      restore_ring3_context
  292.  
  293.      iret
  294.  
  295.  
  296. irqhandler:
  297.  
  298.      push   edi
  299.  
  300.      mov    esi,edi          ; 1
  301.      shl    esi,6            ; 1
  302.      add    esi,irq00read    ; 1
  303.      shl    edi,12           ; 1
  304.      add    edi,IRQ_SAVE
  305.      mov    ecx,16
  306.  
  307.      mov    [check_idle_semaphore],5
  308.  
  309.    irqnewread:
  310.      dec    ecx
  311.      js     irqover
  312.  
  313.      mov    dx,[esi]         ; 2+
  314.  
  315.      cmp    dx,0             ; 1
  316.      jz     irqover
  317.      cmp    [esi+3],byte 1   ; 2     ; byte read
  318.      jne    noirqbyte        ; 4-11
  319.  
  320.      in     al,dx
  321.  
  322.      mov    edx,[edi]
  323.      cmp    edx,4000
  324.      je     irqfull
  325.      mov    ebx,edi
  326.      add    ebx,0x10
  327.      add    ebx,edx
  328.      mov    [ebx],al
  329.      inc    edx
  330.      mov    [edi],edx
  331.  
  332.      add    esi,4
  333.      jmp    irqnewread
  334.  
  335.    noirqbyte:
  336.  
  337.  
  338.      cmp    [esi+3],byte 2     ; word read
  339.      jne    noirqword
  340.  
  341.      in     ax,dx
  342.  
  343.      mov    edx,[edi]
  344.      cmp    edx,4000
  345.      je     irqfull
  346.      mov    ebx,edi
  347.      add    ebx,0x10
  348.      add    ebx,edx
  349.      mov    [ebx],ax
  350.      add    edx,2
  351.      mov    [edi],edx
  352.      add    esi,4
  353.      jmp    irqnewread
  354.  
  355.    noirqword:
  356.    irqfull:
  357.    irqover:
  358.  
  359.      mov    al,0x20            ; ready for next irq
  360.      out    0x20,al
  361.  
  362.      pop    ebx
  363.      cmp    ebx,7
  364.      jbe    noa0
  365.      out    0xa0,al
  366.    noa0:
  367.  
  368.      ret
  369.  
  370.  
  371.  
  372. set_application_table_status:
  373.         push eax
  374.  
  375.         mov  eax,[CURRENT_TASK]
  376.         shl  eax, 5
  377.         add  eax,CURRENT_TASK+TASKDATA.pid
  378.         mov  eax,[eax]
  379.  
  380.         mov  [application_table_status],eax
  381.  
  382.         pop  eax
  383.  
  384.         ret
  385.  
  386.  
  387. clear_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.         cmp  eax,[application_table_status]
  396.         jne  apptsl1
  397.         mov  [application_table_status],0
  398.       apptsl1:
  399.  
  400.         pop  eax
  401.  
  402.         ret
  403.  
  404. sys_resize_app_memory:
  405.         ; eax = 1 - resize
  406.         ;     ebx = new amount of memory
  407.  
  408.         cmp    eax,1
  409.         jne    .no_application_mem_resize
  410.  
  411.         stdcall new_mem_resize, ebx
  412.         mov [esp+36], eax
  413.         ret
  414.  
  415. .no_application_mem_resize:
  416.         ret
  417.  
  418. sys_threads:
  419.  
  420. ; eax=1 create thread
  421. ;
  422. ;   ebx=thread start
  423. ;   ecx=thread stack value
  424. ;
  425. ; on return : eax = pid
  426. jmp new_sys_threads
  427.  
  428. iglobal
  429.   process_terminating   db 'K : Process - terminating',13,10,0
  430.   process_terminated    db 'K : Process - done',13,10,0
  431.   msg_obj_destroy       db 'K : destroy app object',13,10,0
  432. endg
  433.  
  434. ; param
  435. ;  esi= slot
  436.  
  437. terminate: ; terminate application
  438.  
  439.            .slot equ esp   ;locals
  440.  
  441.            push   esi      ;save .slot
  442.  
  443.            shl esi, 8
  444.            cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
  445.            jne @F
  446.            add esp, 4
  447.            ret
  448. @@:
  449.            ;mov    esi,process_terminating
  450.            ;call   sys_msg_board_str
  451.            DEBUGF 1,"%s",process_terminating
  452. @@:
  453.            cli
  454.            cmp   [application_table_status],0
  455.            je    term9
  456.            sti
  457.            call  change_task
  458.            jmp   @b
  459. term9:
  460.            call  set_application_table_status
  461.  
  462.            mov esi, [.slot]
  463.            shl esi,8
  464.            add esi, SLOT_BASE+APP_OBJ_OFFSET
  465. @@:
  466.            mov eax, [esi+APPOBJ.fd]
  467.            test eax, eax
  468.            jz @F
  469.  
  470.            cmp eax, esi
  471.            je @F
  472.  
  473.            push esi
  474.            call [eax+APPOBJ.destroy]
  475.            ;mov  esi, msg_obj_destroy
  476.            ;call sys_msg_board_str
  477.            DEBUGF 1,"%s",msg_obj_destroy
  478.            pop esi
  479.            jmp @B
  480. @@:
  481.            mov eax, [.slot]
  482.            shl eax, 8
  483.            mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
  484.            stdcall destroy_app_space, eax
  485.  
  486.            mov esi, [.slot]
  487.            cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  488.            jne @F
  489.  
  490.            mov [fpu_owner],1
  491.            mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
  492.            clts
  493.            bt [cpu_caps], CAPS_SSE
  494.            jnc .no_SSE
  495.            fxrstor [eax]
  496.            jmp @F
  497. .no_SSE:
  498.            fnclex
  499.            frstor [eax]
  500. @@:
  501.  
  502.     mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
  503.     mov   [BTN_COUNT],byte 0           ; empty button buffer
  504.  
  505.  
  506. ; remove defined hotkeys
  507.         mov     eax, hotkey_list
  508. .loop:
  509.         cmp     [eax+8], esi
  510.         jnz     .cont
  511.         mov     ecx, [eax]
  512.         jecxz   @f
  513.         push    dword [eax+12]
  514.         pop     dword [ecx+12]
  515. @@:
  516.         mov     ecx, [eax+12]
  517.         push    dword [eax]
  518.         pop     dword [ecx]
  519.         xor     ecx, ecx
  520.         mov     [eax], ecx
  521.         mov     [eax+4], ecx
  522.         mov     [eax+8], ecx
  523.         mov     [eax+12], ecx
  524. .cont:
  525.         add     eax, 16
  526.         cmp     eax, hotkey_list+256*16
  527.         jb      .loop
  528. ; remove hotkeys in buffer
  529.         mov     eax, hotkey_buffer
  530. .loop2:
  531.         cmp     [eax], esi
  532.         jnz     .cont2
  533.         and     dword [eax+4], 0
  534.         and     dword [eax], 0
  535. .cont2:
  536.         add     eax, 8
  537.         cmp     eax, hotkey_buffer+120*8
  538.         jb      .loop2
  539.  
  540.     mov   ecx,esi                 ; remove buttons
  541.   bnewba2:
  542.     mov   edi,[BTN_ADDR]
  543.     mov   eax,edi
  544.     cld
  545.     movzx ebx,word [edi]
  546.     inc   bx
  547.   bnewba:
  548.     dec   bx
  549.     jz    bnmba
  550.     add   eax,0x10
  551.     cmp   cx,[eax]
  552.     jnz   bnewba
  553.     pusha
  554.     mov   ecx,ebx
  555.     inc   ecx
  556.     shl   ecx,4
  557.     mov   ebx,eax
  558.     add   eax,0x10
  559.     call  memmove
  560.     dec   dword [edi]
  561.     popa
  562.     jmp   bnewba2
  563.   bnmba:
  564.  
  565.     pusha     ; save window coordinates for window restoring
  566.     cld
  567.     shl   esi,5
  568.     add   esi,window_data
  569.     mov   eax,[esi+WDATA.box.left]
  570.     mov   [dlx],eax
  571.     add   eax,[esi+WDATA.box.width]
  572.     mov   [dlxe],eax
  573.     mov   eax,[esi+WDATA.box.top]
  574.     mov   [dly],eax
  575.     add   eax,[esi+WDATA.box.height]
  576.     mov   [dlye],eax
  577.  
  578.     xor   eax, eax
  579.     mov   [esi+WDATA.box.left],eax
  580.     mov   [esi+WDATA.box.width],eax
  581.     mov   [esi+WDATA.box.top],eax
  582.     mov   [esi+WDATA.box.height],eax
  583.     mov   [esi+WDATA.cl_workarea],eax
  584.     mov   [esi+WDATA.cl_titlebar],eax
  585.     mov   [esi+WDATA.cl_frames],eax
  586.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  587.     lea   edi, [esi-window_data+draw_data]
  588.     mov   ecx,32/4
  589.     rep   stosd
  590.     popa
  591.  
  592. ; debuggee test
  593.     pushad
  594.     mov  edi, esi
  595.     shl  edi, 5
  596.     mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
  597.     test eax, eax
  598.     jz   .nodebug
  599.     push 8
  600.     pop  ecx
  601.     push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
  602.     push 2
  603.     call debugger_notify
  604.     pop  ecx
  605.     pop  ecx
  606. .nodebug:
  607.     popad
  608.  
  609.            mov ebx, [.slot]
  610.            shl ebx, 8
  611.            push ebx
  612.            mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
  613.  
  614.            stdcall kernel_free, ebx
  615.  
  616.            pop ebx
  617.            mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
  618.            stdcall kernel_free, ebx
  619.  
  620.            mov edi, [.slot]
  621.            shl edi,8
  622.            add edi,SLOT_BASE
  623.  
  624.            mov eax, [edi+APPDATA.io_map]
  625.            cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
  626.            je @F
  627.            call free_page
  628. @@:
  629.            mov eax, [edi+APPDATA.io_map+4]
  630.            cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
  631.            je @F
  632.            call free_page
  633. @@:
  634.            mov eax, 0x20202020
  635.            stosd
  636.            stosd
  637.            stosd
  638.            mov ecx,244/4
  639.            xor eax, eax
  640.            rep stosd
  641.  
  642.   ; activate window
  643.         movzx  eax, word [WIN_STACK + esi*2]
  644.         cmp    eax, [TASK_COUNT]
  645.         jne    .dont_activate
  646.         pushad
  647.  .check_next_window:
  648.         dec    eax
  649.         cmp    eax, 1
  650.         jbe    .nothing_to_activate
  651.         lea    esi, [WIN_POS+eax*2]
  652.         movzx  edi, word [esi]               ; edi = process
  653.         shl    edi, 5
  654.         cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
  655.         je     .check_next_window
  656.         add    edi, window_data
  657. ; \begin{diamond}[19.09.2006]
  658. ; skip minimized windows
  659.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  660.         jnz    .check_next_window
  661. ; \end{diamond}
  662.         call   waredraw
  663.  .nothing_to_activate:
  664.         popad
  665.  .dont_activate:
  666.  
  667.         push    esi     ; remove hd1 & cd & flp reservation
  668.         shl     esi, 5
  669.         mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
  670.         cmp     [hd1_status], esi
  671.         jnz     @f
  672.         call    free_hd_channel
  673.         mov     [hd1_status], 0
  674. @@:
  675.         cmp     [cd_status], esi
  676.         jnz     @f
  677.         call    free_cd_channel
  678.         mov     [cd_status], 0
  679. @@:
  680.         cmp     [flp_status], esi
  681.         jnz     @f
  682.         mov     [flp_status], 0
  683. @@:
  684.         pop     esi
  685.         cmp     [bgrlockpid], esi
  686.         jnz     @f
  687.         and     [bgrlockpid], 0
  688.         mov     [bgrlock], 0
  689. @@:
  690.  
  691.     pusha ; remove all irq reservations
  692.     mov   eax,esi
  693.     shl   eax, 5
  694.     mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
  695.     mov   edi,irq_owner
  696.     mov   ecx,16
  697.   newirqfree:
  698.     scasd
  699.     jne   nofreeirq
  700.     mov   [edi-4],dword 0
  701.   nofreeirq:
  702.     loop   newirqfree
  703.     popa
  704.  
  705.     pusha                     ; remove all port reservations
  706.     mov   edx,esi
  707.     shl   edx, 5
  708.     add   edx,CURRENT_TASK
  709.     mov   edx,[edx+TASKDATA.pid]
  710.  
  711.   rmpr0:
  712.  
  713.     mov   esi,[RESERVED_PORTS]
  714.  
  715.     cmp   esi,0
  716.     je    rmpr9
  717.  
  718.   rmpr3:
  719.  
  720.     mov   edi,esi
  721.     shl   edi,4
  722.     add   edi,RESERVED_PORTS
  723.  
  724.     cmp   edx,[edi]
  725.     je    rmpr4
  726.  
  727.     dec   esi
  728.     jnz   rmpr3
  729.  
  730.     jmp   rmpr9
  731.  
  732.   rmpr4:
  733.  
  734.     mov   ecx,256
  735.     sub   ecx,esi
  736.     shl   ecx,4
  737.  
  738.     mov   esi,edi
  739.     add   esi,16
  740.     cld
  741.     rep   movsb
  742.  
  743.     dec   dword [RESERVED_PORTS]
  744.  
  745.     jmp   rmpr0
  746.  
  747.   rmpr9:
  748.  
  749.     popa
  750.     mov  edi,esi         ; do not run this process slot
  751.     shl  edi, 5
  752.     mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
  753. ; debugger test - terminate all debuggees
  754.     mov  eax, 2
  755.     mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
  756. .xd0:
  757.     cmp  eax, [TASK_COUNT]
  758.     ja   .xd1
  759.     cmp  dword [ecx], esi
  760.     jnz  @f
  761.     and  dword [ecx], 0
  762.     pushad
  763.     xchg eax, ecx
  764.     mov  ebx, 2
  765.     call sys_system
  766.     popad
  767. @@:
  768.     inc  eax
  769.     add  ecx, 0x100
  770.     jmp  .xd0
  771. .xd1:
  772. ;    call  systest
  773.     sti  ; .. and life goes on
  774.  
  775.     mov   eax, [dlx]
  776.     mov   ebx, [dly]
  777.     mov   ecx, [dlxe]
  778.     mov   edx, [dlye]
  779.     call  calculatescreen
  780.     xor   eax, eax
  781.     xor   esi, esi
  782.     call  redrawscreen
  783.  
  784.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  785.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  786.  
  787.     mov   [application_table_status],0
  788.     ;mov   esi,process_terminated
  789.     ;call  sys_msg_board_str
  790.     DEBUGF 1,"%s",process_terminated
  791.     add esp, 4
  792.     ret
  793. restore .slot
  794.  
  795. iglobal
  796.   boot_sched_1    db   'Building gdt tss pointer',0
  797.   boot_sched_2    db   'Building IDT table',0
  798. endg
  799.  
  800.  
  801. build_scheduler:
  802.  
  803.         mov    esi,boot_sched_1
  804.         call   boot_log
  805.   ;      call   build_process_gdt_tss_pointer
  806.  
  807.   ;      mov    esi,boot_sched_2
  808.   ;      call   boot_log
  809.  
  810.         ret
  811.