Subversion Repositories Kolibri OS

Rev

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

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