Subversion Repositories Kolibri OS

Rev

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