Subversion Repositories Kolibri OS

Rev

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