Subversion Repositories Kolibri OS

Rev

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