Subversion Repositories Kolibri OS

Rev

Rev 854 | Rev 860 | 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: 859 $
  15.  
  16. align 4
  17. _init_idt:
  18.            push edi
  19.            push esi
  20.            mov edi, idts
  21.            mov dword [idtreg+2], edi
  22.  
  23.            mov esi, sys_int
  24.            mov ecx, 0x40
  25. @@:
  26.            lodsd
  27.            mov [edi],   ax                ; lower part of offset
  28.            mov [edi+2], word os_code      ; segment selector
  29.            mov ax, word 10001110b shl 8   ; type: interrupt gate
  30.            mov [edi+4], eax
  31.            add edi, 8
  32.            loop @b
  33.  
  34.            mov eax, i40
  35.            mov ecx, i40
  36.            and eax, 0x0000FFFF
  37.            and ecx, 0xFFFF0000
  38.            or eax, os_code shl 16
  39.            or ecx, (11101111b shl 8)
  40.            mov [edi], eax
  41.            mov [edi+4], ecx
  42.  
  43.            lidt [idtreg]
  44.            pop esi
  45.            pop edi
  46.            ret
  47.  
  48.  
  49.  
  50. iglobal
  51.  
  52.   msg_sel_ker   db "kernel", 0
  53.   msg_sel_app   db "application", 0
  54.  
  55. align 4
  56.  
  57.   sys_int:
  58.     dd e0,debug_exc,e2,e3
  59.     dd e4,e5,e6,e7
  60.     dd e8,e9,e10,e11
  61.     dd e12,e13,page_fault_handler,e15
  62.  
  63.     dd except_16, e17,e18, except_19
  64.     times 12 dd unknown_interrupt
  65.  
  66.     dd   irq0, irq_serv.irq_1, irq_serv.irq_2
  67. if USE_COM_IRQ
  68.     dd   irq_serv.irq_3, irq_serv.irq_4
  69. else
  70.     dd   p_irq3, p_irq4
  71. end if
  72.     dd   irq_serv.irq_5,  p_irq6,         irq_serv.irq_7
  73.     dd   irq_serv.irq_8,  irq_serv.irq_9, irq_serv.irq_10
  74.     dd   irq_serv.irq_11, irq_serv.irq_12,irqD ,p_irq14,p_irq15
  75.  
  76.     times 16 dd unknown_interrupt
  77.  
  78.     dd   i40
  79.  
  80. idtreg:
  81.      dw   8*0x41-1
  82.      dd   idts
  83.  
  84. endg
  85.  
  86. macro save_ring3_context
  87. {
  88.     pushad
  89. }
  90. macro restore_ring3_context
  91. {
  92.     popad
  93. }
  94.  
  95. ; simply return control to interrupted process
  96. unknown_interrupt:
  97.      iret
  98.  
  99. macro exc_wo_code [num]
  100. {
  101.   forward
  102.   e#num :
  103.       save_ring3_context
  104.       mov bl, num
  105.       jmp exc_c
  106. }
  107.  
  108. macro exc_w_code [num]
  109. {
  110.   forward
  111.   e#num :
  112.       add esp, 4
  113.       save_ring3_context
  114.       mov bl, num
  115.       jmp exc_c
  116. }
  117.  
  118. exc_wo_code 0, 2, 3, 4, 5, 6, 9, 15, 18
  119. exc_w_code 8, 10, 11, 12, 13, 14, 17
  120.  
  121. exc_c:
  122.         mov   ax, app_data  ;èñêëþ÷åíèå
  123.         mov   ds, ax        ;çàãðóçèì ïðàâèëüíûå çíà÷åíè
  124.         mov   es, ax        ;â ðåãèñòðû
  125.  
  126. ; redirect to V86 manager? (EFLAGS & 0x20000) != 0?
  127.         test    byte [esp+20h+8+2], 2
  128.         jnz     v86_exc_c
  129.  
  130. ; test if debugging
  131.         cli
  132.         mov   eax, [current_slot]
  133.         mov   eax, [eax+APPDATA.debugger_slot]
  134.         test  eax, eax
  135.         jnz   .debug
  136.         sti
  137. ; not debuggee => say error and terminate
  138.         movzx eax, bl
  139.         mov   [error_interrupt], eax
  140.         call  show_error_parameters
  141.         add   esp, 0x20
  142.         mov   edx, [TASK_BASE]
  143.         mov   [edx + TASKDATA.state], byte 4
  144.  
  145.         jmp   change_task
  146.  
  147. .debug:
  148. ; we are debugged process, notify debugger and suspend ourself
  149. ; eax=debugger PID
  150.         cld
  151.         movzx ecx, bl
  152.         push  ecx
  153.         mov   ecx, [TASK_BASE]
  154.         push  dword [ecx+TASKDATA.pid]    ; PID of current process
  155.         push  12
  156.         pop   ecx
  157.         push  1        ; 1=exception
  158.         call  debugger_notify
  159.         pop   ecx
  160.         pop   ecx
  161.         pop   ecx
  162.         mov   edx, [TASK_BASE]
  163.         mov   byte [edx+TASKDATA.state], 1        ; suspended
  164.         call  change_task
  165.         restore_ring3_context
  166.         iretd
  167.  
  168. iglobal
  169.         hexletters      db '0123456789ABCDEF'
  170.         error_interrupt dd  -1
  171. endg
  172.  
  173. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  174. show_error_parameters:
  175.     mov eax,[CURRENT_TASK]
  176.     shl eax, 5
  177.     DEBUGF  1, "K : Process - forced terminate PID: %x\n", [CURRENT_TASK + TASKDATA.pid + eax]
  178.     DEBUGF  1, "K : Exception : %x Error : xxxxxxxx\n", [error_interrupt]
  179.     DEBUGF  1, "K : EAX : %x EBX : %x ECX : %x\n", [esp + 0x20], [esp - 12 + 0x20], [esp - 4 + 0x20]
  180.     DEBUGF  1, "K : EDX : %x ESI : %x EDI : %x\n", [esp - 8 + 0x20], [esp - 24 + 0x20], [esp - 28 + 0x20]
  181.     DEBUGF  1, "K : EBP : %x EIP : %x ", [esp - 20 + 0x20], [esp + 4 + 0x20]
  182.  
  183.     mov eax, [esp + 8 + 0x20]
  184.     mov edi, msg_sel_app
  185.     mov ebx, [esp + 16 + 0x20]
  186.     cmp eax, app_code
  187.     je  @f
  188.     mov edi, msg_sel_ker
  189.     mov ebx, [esp - 16 + 0x20]
  190. @@:
  191.     DEBUGF  1, "ESP : %x\nK : Flags : %x CS : %x (%s)\n", ebx, [esp + 12 + 0x20], eax, edi
  192.     ret
  193. ;-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  194.  
  195.  
  196. ; irq1  ->  hid/keyboard.inc
  197. macro irqh [num]
  198. {
  199.   forward
  200.   p_irq#num :
  201.      mov   edi, num
  202.      jmp   irqhandler
  203. }
  204.  
  205. irqh 2,3,4,5,7,8,9,10,11
  206.  
  207.  
  208. p_irq6:
  209.      save_ring3_context
  210.      mov   ax, app_data  ;os_data
  211.      mov   ds, ax
  212.      mov   es, ax
  213.      call  fdc_irq
  214.      call  ready_for_next_irq
  215.      restore_ring3_context
  216.      iret
  217.  
  218.  
  219. p_irq14:
  220.         save_ring3_context
  221.         mov     ax, app_data  ;os_data
  222.         mov     ds, ax
  223.         mov     es, ax
  224.         mov     byte [BOOT_VAR + 0x48E], 0xFF
  225.         call    [irq14_func]
  226.         call    ready_for_next_irq_1
  227.         restore_ring3_context
  228.         iret
  229. p_irq15:
  230.         save_ring3_context
  231.         mov     ax, app_data  ;os_data
  232.         mov     ds, ax
  233.         mov     es, ax
  234.         mov     byte [BOOT_VAR + 0x48E], 0xFF
  235.         call    [irq15_func]
  236.         call    ready_for_next_irq_1
  237.         restore_ring3_context
  238.         iret
  239.  
  240. ready_for_next_irq:
  241.      mov    [check_idle_semaphore],5
  242.      mov   al, 0x20
  243.      out   0x20, al
  244.      ret
  245.  
  246. ready_for_next_irq_1:
  247.      mov    [check_idle_semaphore],5
  248.      mov   al, 0x20
  249.      out    0xa0,al
  250.      out   0x20, al
  251.      ret
  252.  
  253. irqD:
  254.      save_ring3_context
  255.      mov   ax, app_data  ;os_data
  256.      mov   ds, ax
  257.      mov   es, ax
  258.  
  259.      mov   dx,0xf0
  260.      mov   al,0
  261.      out   dx,al
  262.  
  263.      mov   dx,0xa0
  264.      mov   al,0x20
  265.      out   dx,al
  266.      mov   dx,0x20
  267.      out   dx,al
  268.  
  269.      restore_ring3_context
  270.  
  271.      iret
  272.  
  273.  
  274. irqhandler:
  275.  
  276.      mov    esi,edi          ; 1
  277.      shl    esi,6            ; 1
  278.      add    esi,irq00read    ; 1
  279.      shl    edi,12           ; 1
  280.      add    edi,IRQ_SAVE
  281.      mov    ecx,16
  282.  
  283.    irqnewread:
  284.      dec    ecx
  285.      js     irqover
  286.  
  287.      movzx  edx, word [esi]        ; 2+
  288.  
  289.      test   edx, edx               ; 1
  290.      jz     irqover
  291.  
  292.  
  293.      mov    ebx, [edi]             ; address of begin of buffer in edi      ; + 0x0 dword - data size
  294.      mov    eax, 4000                                                       ; + 0x4 dword - data begin offset
  295.      cmp    ebx, eax
  296.      je     irqfull
  297.      add    ebx, [edi + 0x4]       ; add data size to data begin offset
  298.      cmp    ebx, eax               ; if end of buffer, begin cycle again
  299.      jb     @f
  300.  
  301.      xor    ebx, ebx
  302.  
  303.   @@:
  304.      add    ebx, edi
  305.      movzx  eax, byte[esi + 3]     ; get type of data being received 1 - byte, 2 - word
  306.      dec    eax
  307.      jz     irqbyte
  308.      dec    eax
  309.      jnz    noirqword
  310.  
  311.      in     ax,dx
  312.      cmp    ebx, 3999              ; check for address odd in the end of buffer
  313.      jne    .odd
  314.      mov    [ebx + 0x10], ax
  315.      jmp    .add_size
  316.   .odd:
  317.      mov    [ebx + 0x10], al       ; I could make mistake here :)
  318.      mov    [edi + 0x10], ah
  319.   .add_size:
  320.      add    dword [edi], 2
  321.      jmp    nextport
  322.  
  323.  
  324.   irqbyte:
  325.      in     al,dx
  326.      mov    [ebx + 0x10],al
  327.      inc    dword [edi]
  328.   nextport:
  329.      add    esi,4
  330.      jmp    irqnewread
  331.  
  332.  
  333.    noirqword:
  334.    irqfull:
  335.    irqover:
  336.  
  337.      ret
  338.  
  339.  
  340.  
  341. set_application_table_status:
  342.         push eax
  343.  
  344.         mov  eax,[CURRENT_TASK]
  345.         shl  eax, 5
  346.         add  eax,CURRENT_TASK+TASKDATA.pid
  347.         mov  eax,[eax]
  348.  
  349.         mov  [application_table_status],eax
  350.  
  351.         pop  eax
  352.  
  353.         ret
  354.  
  355.  
  356. clear_application_table_status:
  357.         push eax
  358.  
  359.         mov  eax,[CURRENT_TASK]
  360.         shl  eax, 5
  361.         add  eax,CURRENT_TASK+TASKDATA.pid
  362.         mov  eax,[eax]
  363.  
  364.         cmp  eax,[application_table_status]
  365.         jne  apptsl1
  366.         mov  [application_table_status],0
  367.       apptsl1:
  368.  
  369.         pop  eax
  370.  
  371.         ret
  372.  
  373. sys_resize_app_memory:
  374.         ; eax = 1 - resize
  375.         ;     ebx = new amount of memory
  376.  
  377.         cmp    eax,1
  378.         jne    .no_application_mem_resize
  379.  
  380.         stdcall new_mem_resize, ebx
  381.         mov [esp+36], eax
  382.         ret
  383.  
  384. .no_application_mem_resize:
  385.         ret
  386.  
  387. sys_threads:
  388.  
  389. ; eax=1 create thread
  390. ;
  391. ;   ebx=thread start
  392. ;   ecx=thread stack value
  393. ;
  394. ; on return : eax = pid
  395. jmp new_sys_threads
  396.  
  397. iglobal
  398.   process_terminating   db 'K : Process - terminating',13,10,0
  399.   process_terminated    db 'K : Process - done',13,10,0
  400.   msg_obj_destroy       db 'K : destroy app object',13,10,0
  401. endg
  402.  
  403. ; param
  404. ;  esi= slot
  405.  
  406. terminate: ; terminate application
  407.  
  408.            .slot equ esp   ;locals
  409.  
  410.            push   esi      ;save .slot
  411.  
  412.            shl esi, 8
  413.            cmp [SLOT_BASE+esi+APPDATA.dir_table], 0
  414.            jne @F
  415.            pop    esi
  416.            shl    esi, 5
  417.            mov    [CURRENT_TASK+esi+TASKDATA.state], 9
  418.            ret
  419. @@:
  420.            ;mov    esi,process_terminating
  421.            ;call   sys_msg_board_str
  422.            DEBUGF 1,"%s",process_terminating
  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.            mov eax, [.slot]
  469.            shl eax, 8
  470.            mov eax,[SLOT_BASE+eax+APPDATA.dir_table]
  471.        ;    stdcall destroy_app_space, eax
  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   [dlx],eax
  558.     add   eax,[esi+WDATA.box.width]
  559.     mov   [dlxe],eax
  560.     mov   eax,[esi+WDATA.box.top]
  561.     mov   [dly],eax
  562.     add   eax,[esi+WDATA.box.height]
  563.     mov   [dlye],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 edi, [.slot]
  597.            shl edi, 8
  598.            add edi,SLOT_BASE
  599.  
  600.            mov eax,[edi+APPDATA.pl0_stack]
  601.            sub eax, OS_BASE
  602.            call free_page
  603.  
  604.            mov eax,[edi+APPDATA.cur_dir]
  605.            sub eax, OS_BASE
  606.            call free_page
  607.  
  608.            mov eax, [edi+APPDATA.io_map]
  609.            cmp eax, (tss._io_map_0-OS_BASE+PG_MAP)
  610.            je @F
  611.            call free_page
  612. @@:
  613.            mov eax, [edi+APPDATA.io_map+4]
  614.            cmp eax, (tss._io_map_1-OS_BASE+PG_MAP)
  615.            je @F
  616.            call free_page
  617. @@:
  618.            mov eax, 0x20202020
  619.            stosd
  620.            stosd
  621.            stosd
  622.            mov ecx,244/4
  623.            xor eax, eax
  624.            rep stosd
  625.  
  626.   ; activate window
  627.         movzx  eax, word [WIN_STACK + esi*2]
  628.         cmp    eax, [TASK_COUNT]
  629.         jne    .dont_activate
  630.         pushad
  631.  .check_next_window:
  632.         dec    eax
  633.         cmp    eax, 1
  634.         jbe    .nothing_to_activate
  635.         lea    esi, [WIN_POS+eax*2]
  636.         movzx  edi, word [esi]               ; edi = process
  637.         shl    edi, 5
  638.         cmp    [CURRENT_TASK + edi + TASKDATA.state], byte 9  ; skip dead slots
  639.         je     .check_next_window
  640.         add    edi, window_data
  641. ; \begin{diamond}[19.09.2006]
  642. ; skip minimized windows
  643.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  644.         jnz    .check_next_window
  645. ; \end{diamond}
  646.         call   waredraw
  647.  .nothing_to_activate:
  648.         popad
  649.  .dont_activate:
  650.  
  651.         push    esi     ; remove hd1 & cd & flp reservation
  652.         shl     esi, 5
  653.         mov     esi, [esi+CURRENT_TASK+TASKDATA.pid]
  654.         cmp     [hd1_status], esi
  655.         jnz     @f
  656.         call    free_hd_channel
  657.         mov     [hd1_status], 0
  658. @@:
  659.         cmp     [cd_status], esi
  660.         jnz     @f
  661.         call    free_cd_channel
  662.         mov     [cd_status], 0
  663. @@:
  664.         cmp     [flp_status], esi
  665.         jnz     @f
  666.         mov     [flp_status], 0
  667. @@:
  668.         pop     esi
  669.         cmp     [bgrlockpid], esi
  670.         jnz     @f
  671.         and     [bgrlockpid], 0
  672.         mov     [bgrlock], 0
  673. @@:
  674.  
  675.     pusha ; remove all irq reservations
  676.     mov   eax,esi
  677.     shl   eax, 5
  678.     mov   eax,[eax+CURRENT_TASK+TASKDATA.pid]
  679.     mov   edi,irq_owner
  680.     xor   ebx, ebx
  681.     xor   edx, edx
  682.   newirqfree:
  683.     cmp   [edi + 4 * ebx], eax
  684.     jne   nofreeirq
  685.     mov   [edi + 4 * ebx], edx                          ; remove irq reservation
  686.     mov   [irq_tab + 4 * ebx], edx                      ; remove irq handler
  687.     mov   [irq_rights + 4 * ebx], edx                   ; set access rights to full access
  688.   nofreeirq:
  689.     inc   ebx
  690.     cmp   ebx, 16
  691.     jb    newirqfree
  692.     popa
  693.  
  694.     pusha                     ; remove all port reservations
  695.     mov   edx,esi
  696.     shl   edx, 5
  697.     add   edx,CURRENT_TASK
  698.     mov   edx,[edx+TASKDATA.pid]
  699.  
  700.   rmpr0:
  701.  
  702.     mov   esi,[RESERVED_PORTS]
  703.  
  704.     cmp   esi,0
  705.     je    rmpr9
  706.  
  707.   rmpr3:
  708.  
  709.     mov   edi,esi
  710.     shl   edi,4
  711.     add   edi,RESERVED_PORTS
  712.  
  713.     cmp   edx,[edi]
  714.     je    rmpr4
  715.  
  716.     dec   esi
  717.     jnz   rmpr3
  718.  
  719.     jmp   rmpr9
  720.  
  721.   rmpr4:
  722.  
  723.     mov   ecx,256
  724.     sub   ecx,esi
  725.     shl   ecx,4
  726.  
  727.     mov   esi,edi
  728.     add   esi,16
  729.     cld
  730.     rep   movsb
  731.  
  732.     dec   dword [RESERVED_PORTS]
  733.  
  734.     jmp   rmpr0
  735.  
  736.   rmpr9:
  737.  
  738.     popa
  739.     mov  edi,esi         ; do not run this process slot
  740.     shl  edi, 5
  741.     mov  [edi+CURRENT_TASK + TASKDATA.state],byte 9
  742. ; debugger test - terminate all debuggees
  743.     mov  eax, 2
  744.     mov  ecx, SLOT_BASE+2*0x100+APPDATA.debugger_slot
  745. .xd0:
  746.     cmp  eax, [TASK_COUNT]
  747.     ja   .xd1
  748.     cmp  dword [ecx], esi
  749.     jnz  @f
  750.     and  dword [ecx], 0
  751.     pushad
  752.     xchg eax, ecx
  753.     mov  ebx, 2
  754.     call sys_system
  755.     popad
  756. @@:
  757.     inc  eax
  758.     add  ecx, 0x100
  759.     jmp  .xd0
  760. .xd1:
  761. ;    call  systest
  762.     sti  ; .. and life goes on
  763.  
  764.     mov   eax, [dlx]
  765.     mov   ebx, [dly]
  766.     mov   ecx, [dlxe]
  767.     mov   edx, [dlye]
  768.     call  calculatescreen
  769.     xor   eax, eax
  770.     xor   esi, esi
  771.     call  redrawscreen
  772.  
  773.     mov   [MOUSE_BACKGROUND],byte 0  ; no mouse background
  774.     mov   [DONT_DRAW_MOUSE],byte 0  ; draw mouse
  775.  
  776.     mov   [application_table_status],0
  777.     ;mov   esi,process_terminated
  778.     ;call  sys_msg_board_str
  779.     DEBUGF 1,"%s",process_terminated
  780.     add esp, 4
  781.     ret
  782. restore .slot
  783.  
  784. iglobal
  785.   boot_sched_1    db   'Building gdt tss pointer',0
  786.   boot_sched_2    db   'Building IDT table',0
  787. endg
  788.  
  789.  
  790. build_scheduler:
  791.  
  792.         mov    esi,boot_sched_1
  793.         call   boot_log
  794.   ;      call   build_process_gdt_tss_pointer
  795.  
  796.   ;      mov    esi,boot_sched_2
  797.   ;      call   boot_log
  798.  
  799.         ret
  800.