Subversion Repositories Kolibri OS

Rev

Rev 420 | Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

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