Subversion Repositories Kolibri OS

Rev

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