Subversion Repositories Kolibri OS

Rev

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

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;;                                                              ;;
  3. ;; Copyright (C) KolibriOS team 2004-2008. All rights reserved. ;;
  4. ;; Distributed under terms of the GNU General Public License    ;;
  5. ;;                                                              ;;
  6. ;;                                                              ;;
  7. ;;  MenuetOS process management, protected ring3                ;;
  8. ;;                                                              ;;
  9. ;;  Distributed under GPL. See file COPYING for details.        ;;
  10. ;;  Copyright 2003 Ville Turjanmaa                              ;;
  11. ;;                                                              ;;
  12. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  13.  
  14. $Revision: 839 $
  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, irq_serv.irq_2
  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, 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. ; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
  112.         test    byte [esp+20h+8+2], 2
  113.         jnz     v86_exc_c
  114.  
  115. ; test if debugging
  116.         cli
  117.         mov   eax, [current_slot]
  118.         mov   eax, [eax+APPDATA.debugger_slot]
  119.         test  eax, eax
  120.         jnz   .debug
  121.         sti
  122. ; not debuggee => say error and terminate
  123.         movzx eax, bl
  124.         mov   [error_interrupt], eax
  125.         call  show_error_parameters
  126.         add   esp, 0x20
  127.         mov   edx, [TASK_BASE]
  128.         mov   [edx + TASKDATA.state], byte 4
  129.  
  130.         jmp   change_task
  131.  
  132. .debug:
  133. ; we are debugged process, notify debugger and suspend ourself
  134. ; eax=debugger PID
  135.         cld
  136.         movzx ecx, bl
  137.         push  ecx
  138.         mov   ecx, [TASK_BASE]
  139.         push  dword [ecx+TASKDATA.pid]    ; PID of current process
  140.         push  12
  141.         pop   ecx
  142.         push  1        ; 1=exception
  143.         call  debugger_notify
  144.         pop   ecx
  145.         pop   ecx
  146.         pop   ecx
  147.         mov   edx, [TASK_BASE]
  148.         mov   byte [edx+TASKDATA.state], 1        ; suspended
  149.         call  change_task
  150.         restore_ring3_context
  151.         iretd
  152.  
  153. iglobal
  154.         hexletters      db '0123456789ABCDEF'
  155.         error_interrupt dd  -1
  156. endg
  157.  
  158. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  159. show_error_parameters:
  160.     mov eax,[CURRENT_TASK]
  161.     shl eax, 5
  162.     DEBUGF  1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax]
  163.     DEBUGF  1, "K : Exception : %x Error : xxxxxxxx\n", [error_interrupt]
  164.     DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20]
  165.     DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20]
  166.     DEBUGF  1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20]
  167.  
  168.     mov eax, [esp + 8 + 0x20]
  169.     mov edi, msg_sel_app
  170.     mov ebx, [esp + 16 + 0x20]
  171.     cmp eax, app_code
  172.     je  @f
  173.     mov edi, msg_sel_ker
  174.     mov ebx, [esp - 16 + 0x20]
  175. @@:
  176.     DEBUGF  1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi
  177.     ret
  178. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  179.  
  180.  
  181. ; irq1  ->  hid/keyboard.inc
  182. macro irqh [num]
  183. {
  184.   forward
  185.   p_irq#num :
  186.      mov   edi, num
  187.      jmp   irqhandler
  188. }
  189.  
  190. irqh 2,3,4,5,7,8,9,10,11
  191.  
  192.  
  193. p_irq6:
  194.      save_ring3_context
  195.      mov   ax, app_data  ;os_data
  196.      mov   ds, ax
  197.      mov   es, ax
  198.      call  fdc_irq
  199.      call  ready_for_next_irq
  200.      restore_ring3_context
  201.      iret
  202.  
  203.  
  204. p_irq14:
  205.         save_ring3_context
  206.         mov     ax, app_data  ;os_data
  207.         mov     ds, ax
  208.         mov     es, ax
  209.         mov     byte [BOOT_VAR + 0x48E], 0xFF
  210.         call    [irq14_func]
  211.         call    ready_for_next_irq_1
  212.         restore_ring3_context
  213.         iret
  214. p_irq15:
  215.         save_ring3_context
  216.         mov     ax, app_data  ;os_data
  217.         mov     ds, ax
  218.         mov     es, ax
  219.         mov     byte [BOOT_VAR + 0x48E], 0xFF
  220.         call    [irq15_func]
  221.         call    ready_for_next_irq_1
  222.         restore_ring3_context
  223.         iret
  224.  
  225. ready_for_next_irq:
  226.      mov    [check_idle_semaphore],5
  227.      mov   al, 0x20
  228.      out   0x20, al
  229.      ret
  230.  
  231. ready_for_next_irq_1:
  232.      mov    [check_idle_semaphore],5
  233.      mov   al, 0x20
  234.      out    0xa0,al
  235.      out   0x20, al
  236.      ret
  237.  
  238. irqD:
  239.      save_ring3_context
  240.      mov   ax, app_data  ;os_data
  241.      mov   ds, ax
  242.      mov   es, ax
  243.  
  244.      mov   dx,0xf0
  245.      mov   al,0
  246.      out   dx,al
  247.  
  248.      mov   dx,0xa0
  249.      mov   al,0x20
  250.      out   dx,al
  251.      mov   dx,0x20
  252.      out   dx,al
  253.  
  254.      restore_ring3_context
  255.  
  256.      iret
  257.  
  258.  
  259. irqhandler:
  260.  
  261.      mov    esi,edi          ; 1
  262.      shl    esi,6            ; 1
  263.      add    esi,irq00read    ; 1
  264.      shl    edi,12           ; 1
  265.      add    edi,IRQ_SAVE
  266.      mov    ecx,16
  267.  
  268.    irqnewread:
  269.      dec    ecx
  270.      js     irqover
  271.  
  272.      movzx  edx, word [esi]        ; 2+
  273.  
  274.      test   edx, edx               ; 1
  275.      jz     irqover
  276.  
  277.  
  278.      mov    ebx, [edi]             ; address of begin of buffer in edi      ; + 0x0 dword - data size
  279.      mov    eax, 4000                                                       ; + 0x4 dword - data begin offset
  280.      cmp    ebx, eax
  281.      je     irqfull
  282.      add    ebx, [edi + 0x4]       ; add data size to data begin offset
  283.      cmp    ebx, eax               ; if end of buffer, begin cycle again
  284.      jb     @f
  285.  
  286.      xor    ebx, ebx
  287.  
  288.   @@:
  289.      add    ebx, edi
  290.      movzx  eax, byte[esi + 3]     ; get type of data being received 1 - byte, 2 - word
  291.      dec    eax
  292.      jz     irqbyte
  293.      dec    eax
  294.      jnz    noirqword
  295.  
  296.      in     ax,dx
  297.      cmp    ebx, 3999              ; check for address odd in the end of buffer
  298.      jne    .odd
  299.      mov    [ebx + 0x10], ax
  300.      jmp    .add_size
  301.   .odd:
  302.      mov    [ebx + 0x10], al       ; I could make mistake here :)
  303.      mov    [edi + 0x10], ah
  304.   .add_size:
  305.      add    dword [edi], 2
  306.      jmp    nextport
  307.  
  308.  
  309.   irqbyte:
  310.      in     al,dx
  311.      mov    [ebx + 0x10],al
  312.      inc    dword [edi]
  313.   nextport:
  314.      add    esi,4
  315.      jmp    irqnewread
  316.  
  317.  
  318.    noirqword:
  319.    irqfull:
  320.    irqover:
  321.  
  322.      ret
  323.  
  324.  
  325.  
  326. set_application_table_status:
  327.         push eax
  328.  
  329.         mov  eax,[CURRENT_TASK]
  330.         shl  eax, 5
  331.         add  eax,CURRENT_TASK+TASKDATA.pid
  332.         mov  eax,[eax]
  333.  
  334.         mov  [application_table_status],eax
  335.  
  336.         pop  eax
  337.  
  338.         ret
  339.  
  340.  
  341. clear_application_table_status:
  342.         push eax
  343.  
  344.         mov  eax,[CURRENT_TASK]
  345.         shl  eax, 5
  346.         add  eax,CURRENT_TASK+TASKDATA.pid
  347.         mov  eax,[eax]
  348.  
  349.         cmp  eax,[application_table_status]
  350.         jne  apptsl1
  351.         mov  [application_table_status],0
  352.       apptsl1:
  353.  
  354.         pop  eax
  355.  
  356.         ret
  357.  
  358. sys_resize_app_memory:
  359.         ; eax = 1 - resize
  360.         ;     ebx = new amount of memory
  361.  
  362.         cmp    eax,1
  363.         jne    .no_application_mem_resize
  364.  
  365.         stdcall new_mem_resize, ebx
  366.         mov [esp+36], eax
  367.         ret
  368.  
  369. .no_application_mem_resize:
  370.         ret
  371.  
  372. sys_threads:
  373.  
  374. ; eax=1 create thread
  375. ;
  376. ;   ebx=thread start
  377. ;   ecx=thread stack value
  378. ;
  379. ; on return : eax = pid
  380. jmp new_sys_threads
  381.  
  382. iglobal
  383.   process_terminating   db 'K : Process - terminating',13,10,0
  384.   process_terminated    db 'K : Process - done',13,10,0
  385.   msg_obj_destroy       db 'K : destroy app object',13,10,0
  386. endg
  387.  
  388. ; param
  389. ;  esi= slot
  390.  
  391. terminate: ; terminate application
  392.  
  393.            .slot equ esp   ;locals
  394.  
  395.            push   esi      ;save .slot
  396.  
  397.            shl esi, 8
  398.            cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
  399.            jne @F
  400.            pop    esi
  401.            shl    esi, 5
  402.            mov    [CURRENT_TASK+esi+TASKDATA.state], 9
  403.            ret
  404. @@:
  405.            ;mov    esi,process_terminating
  406.            ;call   sys_msg_board_str
  407.            DEBUGF 1,"%s",process_terminating
  408. @@:
  409.            cli
  410.            cmp   [application_table_status],0
  411.            je    term9
  412.            sti
  413.            call  change_task
  414.            jmp   @b
  415. term9:
  416.            call  set_application_table_status
  417.  
  418. ; if the process is in V86 mode...
  419.         mov     eax, [.slot]
  420.         shl     eax, 8
  421.         mov     esi, [eax+SLOT_BASE+APPDATA.pl0_stack]
  422.         add     esi, RING0_STACK_SIZE
  423.         cmp     [eax+SLOT_BASE+APPDATA.saved_esp0], esi
  424.         jz      .nov86
  425. ; ...it has page directory for V86 mode
  426.         mov     esi, [eax+SLOT_BASE+APPDATA.saved_esp0]
  427.         mov     ecx, [esi+4]
  428.         mov     [eax+SLOT_BASE+APPDATA.dir_table], ecx
  429. ; ...and I/O permission map for V86 mode
  430.         mov     ecx, [esi+12]
  431.         mov     [eax+SLOT_BASE+APPDATA.io_map], ecx
  432.         mov     ecx, [esi+8]
  433.         mov     [eax+SLOT_BASE+APPDATA.io_map+4], ecx
  434. .nov86:
  435.  
  436.            mov esi, [.slot]
  437.            shl esi,8
  438.            add esi, SLOT_BASE+APP_OBJ_OFFSET
  439. @@:
  440.            mov eax, [esi+APPOBJ.fd]
  441.            test eax, eax
  442.            jz @F
  443.  
  444.            cmp eax, esi
  445.            je @F
  446.  
  447.            push esi
  448.            call [eax+APPOBJ.destroy]
  449.            DEBUGF 1,"%s",msg_obj_destroy
  450.            pop esi
  451.            jmp @B
  452. @@:
  453.            mov eax, [.slot]
  454.            shl eax, 8
  455.            mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
  456.            stdcall destroy_app_space, eax
  457.  
  458.            mov esi, [.slot]
  459.            cmp [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  460.            jne @F
  461.  
  462.            mov [fpu_owner],1
  463.            mov eax, [256+SLOT_BASE+APPDATA.fpu_state]
  464.            clts
  465.            bt [cpu_caps], CAPS_SSE
  466.            jnc .no_SSE
  467.            fxrstor [eax]
  468.            jmp @F
  469. .no_SSE:
  470.            fnclex
  471.            frstor [eax]
  472. @@:
  473.  
  474.     mov   [KEY_COUNT],byte 0           ; empty keyboard buffer
  475.     mov   [BTN_COUNT],byte 0           ; empty button buffer
  476.  
  477.  
  478. ; remove defined hotkeys
  479.         mov     eax, hotkey_list
  480. .loop:
  481.         cmp     [eax+8], esi
  482.         jnz     .cont
  483.         mov     ecx, [eax]
  484.         jecxz   @f
  485.         push    dword [eax+12]
  486.         pop     dword [ecx+12]
  487. @@:
  488.         mov     ecx, [eax+12]
  489.         push    dword [eax]
  490.         pop     dword [ecx]
  491.         xor     ecx, ecx
  492.         mov     [eax], ecx
  493.         mov     [eax+4], ecx
  494.         mov     [eax+8], ecx
  495.         mov     [eax+12], ecx
  496. .cont:
  497.         add     eax, 16
  498.         cmp     eax, hotkey_list+256*16
  499.         jb      .loop
  500. ; remove hotkeys in buffer
  501.         mov     eax, hotkey_buffer
  502. .loop2:
  503.         cmp     [eax], esi
  504.         jnz     .cont2
  505.         and     dword [eax+4], 0
  506.         and     dword [eax], 0
  507. .cont2:
  508.         add     eax, 8
  509.         cmp     eax, hotkey_buffer+120*8
  510.         jb      .loop2
  511.  
  512.     mov   ecx,esi                 ; remove buttons
  513.   bnewba2:
  514.     mov   edi,[BTN_ADDR]
  515.     mov   eax,edi
  516.     cld
  517.     movzx ebx,word [edi]
  518.     inc   bx
  519.   bnewba:
  520.     dec   bx
  521.     jz    bnmba
  522.     add   eax,0x10
  523.     cmp   cx,[eax]
  524.     jnz   bnewba
  525.     pusha
  526.     mov   ecx,ebx
  527.     inc   ecx
  528.     shl   ecx,4
  529.     mov   ebx,eax
  530.     add   eax,0x10
  531.     call  memmove
  532.     dec   dword [edi]
  533.     popa
  534.     jmp   bnewba2
  535.   bnmba:
  536.  
  537.     pusha     ; save window coordinates for window restoring
  538.     cld
  539.     shl   esi,5
  540.     add   esi,window_data
  541.     mov   eax,[esi+WDATA.box.left]
  542.     mov   [dlx],eax
  543.     add   eax,[esi+WDATA.box.width]
  544.     mov   [dlxe],eax
  545.     mov   eax,[esi+WDATA.box.top]
  546.     mov   [dly],eax
  547.     add   eax,[esi+WDATA.box.height]
  548.     mov   [dlye],eax
  549.  
  550.     xor   eax, eax
  551.     mov   [esi+WDATA.box.left],eax
  552.     mov   [esi+WDATA.box.width],eax
  553.     mov   [esi+WDATA.box.top],eax
  554.     mov   [esi+WDATA.box.height],eax
  555.     mov   [esi+WDATA.cl_workarea],eax
  556.     mov   [esi+WDATA.cl_titlebar],eax
  557.     mov   [esi+WDATA.cl_frames],eax
  558.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  559.     lea   edi, [esi-window_data+draw_data]
  560.     mov   ecx,32/4
  561.     rep   stosd
  562.     popa
  563.  
  564. ; debuggee test
  565.     pushad
  566.     mov  edi, esi
  567.     shl  edi, 5
  568.     mov  eax, [SLOT_BASE+edi*8+APPDATA.debugger_slot]
  569.     test eax, eax
  570.     jz   .nodebug
  571.     push 8
  572.     pop  ecx
  573.     push dword [CURRENT_TASK+edi+TASKDATA.pid]   ; PID
  574.     push 2
  575.     call debugger_notify
  576.     pop  ecx
  577.     pop  ecx
  578. .nodebug:
  579.     popad
  580.  
  581.            mov edi, [.slot]
  582.            shl edi, 8
  583.            add edi,SLOT_BASE
  584.  
  585.            mov eax,[edi+APPDATA.pl0_stack]
  586.            sub eax, OS_BASE
  587.            call free_page
  588.  
  589.            mov eax,[edi+APPDATA.cur_dir]
  590.            sub eax, OS_BASE
  591.            call free_page
  592.  
  593.            mov eax, [edi+APPDATA.io_map]
  594.            cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
  595.            je @F
  596.            call free_page
  597. @@:
  598.            mov eax, [edi+APPDATA.io_map+4]
  599.            cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
  600.            je @F
  601.            call free_page
  602. @@:
  603.            mov eax, 0x20202020
  604.            stosd
  605.            stosd
  606.            stosd
  607.            mov ecx,244/4
  608.            xor eax, eax
  609.            rep stosd
  610.  
  611.   ; activate window
  612.         movzx  eax, word [WIN_STACK + esi*2]
  613.         cmp    eax, [TASK_COUNT]
  614.         jne    .dont_activate
  615.         pushad
  616.  .check_next_window:
  617.         dec    eax
  618.         cmp    eax, 1
  619.         jbe    .nothing_to_activate
  620.         lea    esi, [WIN_POS+eax*2]
  621.         movzx  edi, word [esi]               ; edi = process
  622.         shl    edi, 5
  623.         cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
  624.         je     .check_next_window
  625.         add    edi, window_data
  626. ; \begin{diamond}[19.09.2006]
  627. ; skip minimized windows
  628.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  629.         jnz    .check_next_window
  630. ; \end{diamond}
  631.         call   waredraw
  632.  .nothing_to_activate:
  633.         popad
  634.  .dont_activate:
  635.  
  636.         push    esi     ; remove hd1 & cd & flp reservation
  637.         shl     esi, 5
  638.         mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
  639.         cmp     [hd1_status], esi
  640.         jnz     @f
  641.         call    free_hd_channel
  642.         mov     [hd1_status], 0
  643. @@:
  644.         cmp     [cd_status], esi
  645.         jnz     @f
  646.         call    free_cd_channel
  647.         mov     [cd_status], 0
  648. @@:
  649.         cmp     [flp_status], esi
  650.         jnz     @f
  651.         mov     [flp_status], 0
  652. @@:
  653.         pop     esi
  654.         cmp     [bgrlockpid], esi
  655.         jnz     @f
  656.         and     [bgrlockpid], 0
  657.         mov     [bgrlock], 0
  658. @@:
  659.  
  660.     pusha ; remove all irq reservations
  661.     mov   eax,esi
  662.     shl   eax, 5
  663.     mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
  664.     mov   edi,irq_owner
  665.     xor   ebx, ebx
  666.     xor   edx, edx
  667.   newirqfree:
  668.     cmp   [edi + 4 * ebx], eax
  669.     jne   nofreeirq
  670.     mov   [edi + 4 * ebx], edx                          ; remove irq reservation
  671.     mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
  672.     mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
  673.   nofreeirq:
  674.     inc   ebx
  675.     cmp   ebx, 16
  676.     jb    newirqfree
  677.     popa
  678.  
  679.     pusha                     ; remove all port reservations
  680.     mov   edx,esi
  681.     shl   edx, 5
  682.     add   edx,CURRENT_TASK
  683.     mov   edx,[edx+TASKDATA.pid]
  684.  
  685.   rmpr0:
  686.  
  687.     mov   esi,[RESERVED_PORTS]
  688.  
  689.     cmp   esi,0
  690.     je    rmpr9
  691.  
  692.   rmpr3:
  693.  
  694.     mov   edi,esi
  695.     shl   edi,4
  696.     add   edi,RESERVED_PORTS
  697.  
  698.     cmp   edx,[edi]
  699.     je    rmpr4
  700.  
  701.     dec   esi
  702.     jnz   rmpr3
  703.  
  704.     jmp   rmpr9
  705.  
  706.   rmpr4:
  707.  
  708.     mov   ecx,256
  709.     sub   ecx,esi
  710.     shl   ecx,4
  711.  
  712.     mov   esi,edi
  713.     add   esi,16
  714.     cld
  715.     rep   movsb
  716.  
  717.     dec   dword [RESERVED_PORTS]
  718.  
  719.     jmp   rmpr0
  720.  
  721.   rmpr9:
  722.  
  723.     popa
  724.     mov  edi,esi         ; do not run this process slot
  725.     shl  edi, 5
  726.     mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
  727. ; debugger test - terminate all debuggees
  728.     mov  eax, 2
  729.     mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
  730. .xd0:
  731.     cmp  eax, [TASK_COUNT]
  732.     ja   .xd1
  733.     cmp  dword [ecx], esi
  734.     jnz  @f
  735.     and  dword [ecx], 0
  736.     pushad
  737.     xchg eax, ecx
  738.     mov  ebx, 2
  739.     call sys_system
  740.     popad
  741. @@:
  742.     inc  eax
  743.     add  ecx, 0x100
  744.     jmp  .xd0
  745. .xd1:
  746. ;    call  systest
  747.     sti  ; .. and life goes on
  748.  
  749.     mov   eax, [dlx]
  750.     mov   ebx, [dly]
  751.     mov   ecx, [dlxe]
  752.     mov   edx, [dlye]
  753.     call  calculatescreen
  754.     xor   eax, eax
  755.     xor   esi, esi
  756.     call  redrawscreen
  757.  
  758.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  759.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  760.  
  761.     mov   [application_table_status],0
  762.     ;mov   esi,process_terminated
  763.     ;call  sys_msg_board_str
  764.     DEBUGF 1,"%s",process_terminated
  765.     add esp, 4
  766.     ret
  767. restore .slot
  768.  
  769. iglobal
  770.   boot_sched_1    db   'Building gdt tss pointer',0
  771.   boot_sched_2    db   'Building IDT table',0
  772. endg
  773.  
  774.  
  775. build_scheduler:
  776.  
  777.         mov    esi,boot_sched_1
  778.         call   boot_log
  779.   ;      call   build_process_gdt_tss_pointer
  780.  
  781.   ;      mov    esi,boot_sched_2
  782.   ;      call   boot_log
  783.  
  784.         ret
  785.