Subversion Repositories Kolibri OS

Rev

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