Subversion Repositories Kolibri OS

Rev

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