Subversion Repositories Kolibri OS

Rev

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