Subversion Repositories Kolibri OS

Rev

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