Subversion Repositories Kolibri OS

Rev

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

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