Subversion Repositories Kolibri OS

Rev

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