Subversion Repositories Kolibri OS

Rev

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