Subversion Repositories Kolibri OS

Rev

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

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