Subversion Repositories Kolibri OS

Rev

Rev 787 | Rev 858 | 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: 788 $
  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 ebx, [.slot]
  582.            shl ebx, 8
  583.            push ebx
  584.            mov ebx,[SLOT_BASE+ebx+APPDATA.pl0_stack]
  585.  
  586.            stdcall kernel_free, ebx
  587.  
  588.            pop ebx
  589.            mov ebx,[SLOT_BASE+ebx+APPDATA.cur_dir]
  590.            stdcall kernel_free, ebx
  591.  
  592.            mov edi, [.slot]
  593.            shl edi,8
  594.            add edi,SLOT_BASE
  595.  
  596.            mov eax, [edi+APPDATA.io_map]
  597.            cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
  598.            je @F
  599.            call free_page
  600. @@:
  601.            mov eax, [edi+APPDATA.io_map+4]
  602.            cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
  603.            je @F
  604.            call free_page
  605. @@:
  606.            mov eax, 0x20202020
  607.            stosd
  608.            stosd
  609.            stosd
  610.            mov ecx,244/4
  611.            xor eax, eax
  612.            rep stosd
  613.  
  614.   ; activate window
  615.         movzx  eax, word [WIN_STACK + esi*2]
  616.         cmp    eax, [TASK_COUNT]
  617.         jne    .dont_activate
  618.         pushad
  619.  .check_next_window:
  620.         dec    eax
  621.         cmp    eax, 1
  622.         jbe    .nothing_to_activate
  623.         lea    esi, [WIN_POS+eax*2]
  624.         movzx  edi, word [esi]               ; edi = process
  625.         shl    edi, 5
  626.         cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
  627.         je     .check_next_window
  628.         add    edi, window_data
  629. ; \begin{diamond}[19.09.2006]
  630. ; skip minimized windows
  631.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  632.         jnz    .check_next_window
  633. ; \end{diamond}
  634.         call   waredraw
  635.  .nothing_to_activate:
  636.         popad
  637.  .dont_activate:
  638.  
  639.         push    esi     ; remove hd1 & cd & flp reservation
  640.         shl     esi, 5
  641.         mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
  642.         cmp     [hd1_status], esi
  643.         jnz     @f
  644.         call    free_hd_channel
  645.         mov     [hd1_status], 0
  646. @@:
  647.         cmp     [cd_status], esi
  648.         jnz     @f
  649.         call    free_cd_channel
  650.         mov     [cd_status], 0
  651. @@:
  652.         cmp     [flp_status], esi
  653.         jnz     @f
  654.         mov     [flp_status], 0
  655. @@:
  656.         pop     esi
  657.         cmp     [bgrlockpid], esi
  658.         jnz     @f
  659.         and     [bgrlockpid], 0
  660.         mov     [bgrlock], 0
  661. @@:
  662.  
  663.     pusha ; remove all irq reservations
  664.     mov   eax,esi
  665.     shl   eax, 5
  666.     mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
  667.     mov   edi,irq_owner
  668.     xor   ebx, ebx
  669.     xor   edx, edx
  670.   newirqfree:
  671.     cmp   [edi + 4 * ebx], eax
  672.     jne   nofreeirq
  673.     mov   [edi + 4 * ebx], edx                          ; remove irq reservation
  674.     mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
  675.     mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
  676.   nofreeirq:
  677.     inc   ebx
  678.     cmp   ebx, 16
  679.     jb    newirqfree
  680.     popa
  681.  
  682.     pusha                     ; remove all port reservations
  683.     mov   edx,esi
  684.     shl   edx, 5
  685.     add   edx,CURRENT_TASK
  686.     mov   edx,[edx+TASKDATA.pid]
  687.  
  688.   rmpr0:
  689.  
  690.     mov   esi,[RESERVED_PORTS]
  691.  
  692.     cmp   esi,0
  693.     je    rmpr9
  694.  
  695.   rmpr3:
  696.  
  697.     mov   edi,esi
  698.     shl   edi,4
  699.     add   edi,RESERVED_PORTS
  700.  
  701.     cmp   edx,[edi]
  702.     je    rmpr4
  703.  
  704.     dec   esi
  705.     jnz   rmpr3
  706.  
  707.     jmp   rmpr9
  708.  
  709.   rmpr4:
  710.  
  711.     mov   ecx,256
  712.     sub   ecx,esi
  713.     shl   ecx,4
  714.  
  715.     mov   esi,edi
  716.     add   esi,16
  717.     cld
  718.     rep   movsb
  719.  
  720.     dec   dword [RESERVED_PORTS]
  721.  
  722.     jmp   rmpr0
  723.  
  724.   rmpr9:
  725.  
  726.     popa
  727.     mov  edi,esi         ; do not run this process slot
  728.     shl  edi, 5
  729.     mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
  730. ; debugger test - terminate all debuggees
  731.     mov  eax, 2
  732.     mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
  733. .xd0:
  734.     cmp  eax, [TASK_COUNT]
  735.     ja   .xd1
  736.     cmp  dword [ecx], esi
  737.     jnz  @f
  738.     and  dword [ecx], 0
  739.     pushad
  740.     xchg eax, ecx
  741.     mov  ebx, 2
  742.     call sys_system
  743.     popad
  744. @@:
  745.     inc  eax
  746.     add  ecx, 0x100
  747.     jmp  .xd0
  748. .xd1:
  749. ;    call  systest
  750.     sti  ; .. and life goes on
  751.  
  752.     mov   eax, [dlx]
  753.     mov   ebx, [dly]
  754.     mov   ecx, [dlxe]
  755.     mov   edx, [dlye]
  756.     call  calculatescreen
  757.     xor   eax, eax
  758.     xor   esi, esi
  759.     call  redrawscreen
  760.  
  761.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  762.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  763.  
  764.     mov   [application_table_status],0
  765.     ;mov   esi,process_terminated
  766.     ;call  sys_msg_board_str
  767.     DEBUGF 1,"%s",process_terminated
  768.     add esp, 4
  769.     ret
  770. restore .slot
  771.  
  772. iglobal
  773.   boot_sched_1    db   'Building gdt tss pointer',0
  774.   boot_sched_2    db   'Building IDT table',0
  775. endg
  776.  
  777.  
  778. build_scheduler:
  779.  
  780.         mov    esi,boot_sched_1
  781.         call   boot_log
  782.   ;      call   build_process_gdt_tss_pointer
  783.  
  784.   ;      mov    esi,boot_sched_2
  785.   ;      call   boot_log
  786.  
  787.         ret
  788.