Subversion Repositories Kolibri OS

Rev

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