Subversion Repositories Kolibri OS

Rev

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

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