Subversion Repositories Kolibri OS

Rev

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

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