Subversion Repositories Kolibri OS

Rev

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