Subversion Repositories Kolibri OS

Rev

Rev 23 | Rev 40 | Go to most recent revision | Blame | Compare with Previous | 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 32
  11.  
  12. ; GDT TABLE
  13.  
  14. gdts:
  15.  
  16.         dw     gdte-$-1
  17.         dd     gdts
  18.         dw     0
  19.  
  20. int_code_l:
  21. os_code_l:
  22.  
  23.         dw     0xffff
  24.         dw     0x0000
  25.         db     0x00
  26.         dw     11011111b *256 +10011010b
  27.         db     0x00
  28.  
  29. int_data_l:
  30. os_data_l:
  31.  
  32.         dw     0xffff
  33.         dw     0x0000
  34.         db     0x00
  35.         dw     11011111b *256 +10010010b
  36.         db     0x00
  37.  
  38. app_code_l:
  39.       dw ((0x80000000-std_application_base_address) shr 12) and 0xffff
  40.       dw 0
  41.       db 0
  42.       dw 11010000b*256+11111010b+256*((0x80000000-std_application_base_address) shr 28)
  43.       db std_application_base_address shr 24
  44.  
  45. app_data_l:
  46.       dw (0x80000000-std_application_base_address) shr 12 and 0xffff
  47.       dw 0
  48.       db 0
  49.       dw 11010000b*256+11110010b+256*((0x80000000-std_application_base_address) shr 28)
  50.       db std_application_base_address shr 24
  51.  
  52. graph_data_l:
  53.  
  54.         dw     0x3ff
  55.         dw     0x0000
  56.         db     0x00
  57.         dw     11010000b *256 +11110010b
  58.         db     0x00
  59.  
  60. tss0_l:
  61.       times (max_processes+10) dd 0,0
  62.  
  63. gdte:
  64.  
  65.  
  66.  
  67. idtreg:
  68.      dw   8*0x41-1
  69.      dd   idts+8
  70. label idts at 0xB100-8
  71.  
  72.  
  73.  
  74. uglobal
  75.  tss_sceleton:
  76.   l.back   dw 0,0
  77.   l.esp0   dd 0
  78.   l.ss0    dw 0,0
  79.   l.esp1   dd 0
  80.   l.ss1    dw 0,0
  81.   l.esp2   dd 0
  82.   l.ss2    dw 0,0
  83.   l.cr3    dd 0
  84.   l.eip    dd 0
  85.   l.eflags dd 0
  86.   l.eax    dd 0
  87.   l.ecx    dd 0
  88.   l.edx    dd 0
  89.   l.ebx    dd 0
  90.   l.esp    dd 0
  91.   l.ebp    dd 0
  92.   l.esi    dd 0
  93.   l.edi    dd 0
  94.   l.es     dw 0,0
  95.   l.cs     dw 0,0
  96.   l.ss     dw 0,0
  97.   l.ds     dw 0,0
  98.   l.fs     dw 0,0
  99.   l.gs     dw 0,0
  100.   l.ldt    dw 0,0
  101.   l.trap   dw 0
  102.   l.io     dw 0
  103. endg
  104.  
  105.  
  106. build_process_gdt_tss_pointer:
  107.  
  108.         mov    ecx,tss_data
  109.         mov    edi,0
  110.       setgdtl2:
  111.         mov    [edi+gdts+ tss0 +0], word tss_step
  112.         mov    [edi+gdts+ tss0 +2], cx
  113.         mov    eax,ecx
  114.         shr    eax,16
  115.         mov    [edi+gdts+ tss0 +4], al
  116.         mov    [edi+gdts+ tss0 +7], ah
  117.         mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  118.         add    ecx,tss_step
  119.         add    edi,8
  120.         cmp    edi,8*(max_processes+5)
  121.         jbe    setgdtl2
  122.  
  123.         ret
  124.  
  125.  
  126. build_interrupt_table:
  127.  
  128.         mov    edi, idts+8
  129.         mov    esi, sys_int
  130.         mov    ecx, 0x40
  131.      @@:
  132.         mov    eax, [esi]
  133.         mov    [edi],   ax           ; lower part of offset
  134.         mov    [edi+2], word os_code ; segment selector
  135.         shr    eax, 16
  136.         mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
  137.         mov    [edi+6], ax
  138.         add    esi, 4
  139.         add    edi, 8
  140.         dec    ecx
  141.         jnz    @b
  142.        
  143.         ;mov    edi,8*0x40+idts+8
  144.         mov    [edi + 0], word (i40 and ((1 shl 16)-1))
  145.         mov    [edi + 2], word os_code
  146.         mov    [edi + 4], word 11101110b*256
  147.         mov    [edi + 6], word (i40 shr 16)
  148.  
  149.         ret
  150.  
  151.  
  152.  
  153. iglobal
  154.   sys_int:
  155.     dd   e0,e1,e2,e3,e4,e5,e6,e7,e8,e9,e10,e11,e12,e13,e14,e15
  156.     dd   e16,e17
  157.     times 14 dd unknown_interrupt
  158.  
  159.     dd   irq0  ,irq1  ,p_irq2 ,p_irq3 ,p_irq4 ,p_irq5,p_irq6 ,p_irq7
  160.     dd   p_irq8,p_irq9,p_irq10,p_irq11,p_irq12,irqD  ,p_irq14,p_irq15
  161.  
  162.     times 16 dd unknown_interrupt
  163.  
  164.     dd   i40
  165. endg
  166.  
  167. ; simply return control to interrupted process
  168. unknown_interrupt:
  169.      iret
  170.  
  171. macro exc_wo_code [num]
  172. {
  173.   forward
  174.   e#num :
  175.       mov bl, num
  176.       jmp exc_c
  177. }
  178.  
  179. macro exc_w_code [num]
  180. {
  181.   forward
  182.   e#num :
  183.       add esp, 4
  184.       mov bl, num
  185.       jmp exc_c
  186. }
  187.  
  188. exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 16 ; 18, 19
  189. exc_w_code 8, 10, 11, 12, 13, 14, 17
  190.  
  191. exc_c:
  192.         mov   ax, os_data
  193.         mov   ds, ax
  194.         mov   es, ax
  195.  
  196.         movzx eax, bl        
  197.         mov   [error_interrupt], eax
  198.         call  show_error_parameters
  199.        
  200.         mov   edx, [0x3010]
  201.         mov   [edx + 0xA], byte 4
  202.        
  203.         jmp   change_task
  204.  
  205.  
  206. ;;;;;;;;;;;;;;;;;;;;;;;
  207. ;; FPU ERROR HANDLER ;;
  208. ;;;;;;;;;;;;;;;;;;;;;;;
  209.  
  210. align 4
  211. e7:
  212.         clts
  213.          
  214.         push  eax
  215.         push  ds es
  216.        
  217.         mov   ax, os_data
  218.         mov   ds, ax
  219.         mov   es, ax
  220.        
  221.         mov   eax, [prev_user_of_fpu]
  222.         shl   eax, 8
  223.         add   eax, 0x80000 + 0x10
  224.         fsave [eax]
  225.        
  226.         mov   eax, [0x3000]
  227.         mov   [prev_user_of_fpu], eax
  228.         shl   eax, 8
  229.         add   eax, 0x80000
  230.         cmp   [eax + 0x7f], byte 0
  231.         je    @f
  232.         frstor [eax+0x10]
  233.      @@:
  234.         mov   [eax + 0x7f], byte 1
  235.        
  236.         pop   es ds
  237.         pop   eax
  238.        
  239.         iret
  240.        
  241. iglobal
  242.   prev_user_of_fpu dd 1
  243. endg
  244.  
  245.  
  246. writehex:
  247.       pusha
  248.      
  249.       mov  edi, [write_error_to]
  250.       mov  esi, 8
  251.     @@:
  252.       mov  ecx, eax
  253.       and  ecx, 0xf
  254.  
  255.       mov  cl,[ecx+hexletters]
  256.       mov  [edi],cl
  257.       dec  edi
  258.  
  259.       shr  eax,4
  260.       dec  esi
  261.       jnz  @b
  262.  
  263.       popa
  264.       ret
  265.  
  266. iglobal
  267.   hexletters  db '0123456789ABCDEF'
  268.  
  269.   error_interrupt         dd  -1
  270.  
  271.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  272.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  273.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  274.   system_error   db 'K : Kernel error',13,10,0
  275. endg
  276.  
  277. uglobal
  278.   write_error_to  dd  0x0
  279. endg
  280.  
  281. show_error_parameters:
  282.        
  283.         mov    [write_error_to],process_pid+43
  284.         mov    eax,[0x3000]
  285.         shl    eax, 5
  286.         mov    eax,[0x3000+4+eax]
  287.         call   writehex
  288.        
  289.         mov    [write_error_to],process_error+43
  290.         mov    eax,[error_interrupt]
  291.         call   writehex
  292.  
  293.         cmp    dword [esp+4+4], os_code ; CS
  294.         jnz    @f
  295.         mov    esi,system_error
  296.         call   sys_msg_board_str
  297.       @@:
  298.         mov    eax, [esp+4] ; EIP
  299.  
  300.         mov    [write_error_to],process_eip+43
  301.         call   writehex
  302.  
  303.         mov    esi,process_error
  304.         call   sys_msg_board_str
  305.  
  306.         mov    esi,process_pid
  307.         call   sys_msg_board_str
  308.  
  309.         mov    esi,process_eip
  310.         call   sys_msg_board_str
  311.  
  312.         ret
  313.  
  314.  
  315.  
  316. ; irq1  ->  hid/keyboard.inc
  317.  
  318.  
  319. macro irqh [num]
  320. {
  321.   forward
  322.   p_irq#num :
  323.      pushad
  324.      mov   edi, num
  325.      jmp   irq_c
  326. }
  327.  
  328. irqh 2,5,7,8,9,10,11,14,15
  329.  
  330.  irq_c:
  331.      push  ds es
  332.      mov   ax, os_data
  333.      mov   ds, ax
  334.      mov   es, ax
  335.      call  irqhandler
  336.      pop   es ds
  337.      popad
  338.      iret
  339.  
  340. p_irq6:
  341.      pushad
  342.      push  ds es
  343.      mov   ax, os_data
  344.      mov   ds, ax
  345.      mov   es, ax
  346.      call  fdc_irq
  347.      call  ready_for_next_irq
  348.      pop   es ds
  349.      popad
  350.      iret
  351.  
  352. p_irq3:
  353.      pushad
  354.      push  ds es
  355.      mov   ax, os_data
  356.      mov   ds, ax
  357.      mov   es, ax
  358.      call  check_mouse_data_com2
  359.      pop   es ds
  360.      popad
  361.      iret
  362.  
  363. p_irq4:
  364.      pushad
  365.      push  ds es
  366.      mov   ax, os_data
  367.      mov   ds, ax
  368.      mov   es, ax
  369.      call  check_mouse_data_com1
  370.      pop   es ds
  371.      popad
  372.      iret
  373.  
  374. p_irq12:
  375.      pushad
  376.      push  ds es
  377.      mov   ax, os_data
  378.      mov   ds, ax
  379.      mov   es, ax
  380.      call  check_mouse_data_ps2
  381.      pop   es ds
  382.      popad
  383.      iret
  384.  
  385. ready_for_next_irq:
  386.      mov    [check_idle_semaphore],5
  387.      mov   al, 0x20
  388.      out   0x20, al
  389.      ret
  390.  
  391. ready_for_next_irq_1:
  392.      mov    [check_idle_semaphore],5
  393.      mov   al, 0x20
  394.      out    0xa0,al
  395.      out   0x20, al
  396.      ret
  397.  
  398. irqD:
  399.      pushad
  400.      push  ds es
  401.      mov   ax, os_data
  402.      mov   ds, ax
  403.      mov   es, ax
  404.      
  405.      mov   dx,0xf0
  406.      mov   al,0
  407.      out   dx,al
  408.  
  409.      mov   dx,0xa0
  410.      mov   al,0x20
  411.      out   dx,al
  412.      mov   dx,0x20
  413.      out   dx,al    
  414.      
  415.      pop   es ds
  416.      popad
  417.      iret
  418.  
  419.  
  420. irqhandler:
  421.  
  422.      push   edi
  423.  
  424.      mov    esi,edi          ; 1
  425.      shl    esi,6            ; 1
  426.      add    esi,irq00read    ; 1
  427.      shl    edi,12           ; 1
  428.      add    edi,0x2E0000
  429.  
  430.      mov    [check_idle_semaphore],5
  431.  
  432.    irqnewread:
  433.  
  434.      mov    dx,[esi]         ; 2+
  435.  
  436.      cmp    dx,0             ; 1
  437.      jz     irqover
  438.      cmp    [esi+3],byte 1   ; 2     ; byte read
  439.      jne    noirqbyte        ; 4-11
  440.  
  441.      in     al,dx
  442.  
  443.      mov    edx,[edi]
  444.      cmp    edx,4000
  445.      je     irqfull
  446.      mov    ebx,edi
  447.      add    ebx,0x10
  448.      add    ebx,edx
  449.      mov    [ebx],al
  450.      inc    edx
  451.      mov    [edi],edx
  452.  
  453.      add    esi,4
  454.      jmp    irqnewread
  455.  
  456.    noirqbyte:
  457.  
  458.  
  459.      cmp    [esi+3],byte 2     ; word read
  460.      jne    noirqword
  461.  
  462.      in     ax,dx
  463.  
  464.      mov    edx,[edi]
  465.      cmp    edx,4000
  466.      je     irqfull
  467.      mov    ebx,edi
  468.      add    ebx,0x10
  469.      add    ebx,edx
  470.      mov    [ebx],ax
  471.      add    edx,2
  472.      mov    [edi],edx
  473.      add    esi,4
  474.      jmp    irqnewread
  475.  
  476.    noirqword:
  477.    irqfull:
  478.    irqover:
  479.  
  480.      mov    al,0x20            ; ready for next irq
  481.      out    0x20,al
  482.  
  483.      pop    ebx
  484.      cmp    ebx,7
  485.      jbe    noa0
  486.      out    0xa0,al
  487.    noa0:
  488.  
  489.      ret
  490.  
  491.  
  492.  
  493. set_application_table_status:
  494.         push eax
  495.  
  496.         mov  eax,[0x3000]
  497.         shl  eax, 5
  498.         add  eax,0x3000+4
  499.         mov  eax,[eax]
  500.  
  501.         mov  [application_table_status],eax
  502.  
  503.         pop  eax
  504.  
  505.         ret
  506.  
  507.  
  508. clear_application_table_status:
  509.         push eax
  510.  
  511.         mov  eax,[0x3000]
  512.         shl  eax, 5
  513.         add  eax,0x3000+4
  514.         mov  eax,[eax]
  515.  
  516.         cmp  eax,[application_table_status]
  517.         jne  apptsl1
  518.         mov  [application_table_status],0
  519.       apptsl1:
  520.  
  521.         pop  eax
  522.  
  523.         ret
  524.  
  525.  
  526.  
  527. sys_resize_app_memory:
  528.         ; eax = 1 - resize
  529.         ;     ebx = new amount of memory
  530.  
  531.         cmp    eax,1
  532.         jne    .no_application_mem_resize
  533.        
  534.         jmp    new_mem_resize ;resize for new type of processes
  535.  
  536.  
  537.      .no_application_mem_resize:
  538.  
  539.         ret
  540.  
  541.  
  542.  
  543. get_app_params:
  544.  
  545.     push eax
  546.  
  547.     cmp  [0x90000+6],word '00'
  548.     jne  no_00_header
  549.  
  550.     mov  eax,[0x90000+12]
  551.     mov  [app_start],eax
  552.     mov  eax,[0x90000+16]
  553.     mov  [app_i_end],eax
  554.     mov  eax,[0x90000+20]
  555.     mov  [app_mem],eax
  556.     shr  eax,1
  557.     sub  eax,0x10
  558.     mov  [app_esp],eax
  559.     mov  eax,[0x90000+24]
  560.     mov  [app_i_param],eax
  561.     mov  [app_i_icon],dword 0
  562.  
  563.     pop  eax
  564.     mov  esi,1
  565.     ret
  566.  
  567.   no_00_header:
  568.  
  569.  
  570.     cmp  [0x90000+6],word '01'
  571.     jne  no_01_header
  572.  
  573.     mov  eax,[0x90000+12]
  574.     mov  [app_start],eax
  575.     mov  eax,[0x90000+16]
  576.     mov  [app_i_end],eax
  577.     mov  eax,[0x90000+20]
  578.     mov  [app_mem],eax
  579.     mov  eax,[0x90000+24]
  580.     mov  [app_esp],eax
  581.     mov  eax,[0x90000+28]
  582.     mov  [app_i_param],eax
  583.     mov  eax,[0x90000+32]
  584.     mov  [app_i_icon],eax
  585.  
  586.     pop  eax
  587.     mov  esi,1
  588.     ret
  589.  
  590.    no_01_header:
  591.  
  592.     pop  eax
  593.     mov  esi,0
  594.     ret
  595.  
  596.  
  597. start_application_fl:
  598.     jmp new_start_application_fl
  599.  
  600. ;************************************************************************
  601.  
  602. start_application_floppy:
  603.     jmp  new_start_application_floppy
  604.  
  605. ;********************************************************************
  606.  
  607. start_application_hd:
  608.     jmp   new_start_application_hd
  609.  
  610. uglobal
  611.   new_process_place  dd  0x0
  612.   app_start    dd  0x0
  613.   app_i_end    dd  0x0
  614.   app_mem      dd  0x0
  615.   app_esp      dd  0x0
  616.   app_i_param  dd  0x0
  617.   app_i_icon   dd  0x0
  618.   app_mem_pos  dd  0x0
  619.   appl_path        dd 0x0
  620.   appl_path_size   dd 0x0        
  621. endg
  622.  
  623. iglobal
  624.   hd_app_string      db  'HDAPP       '
  625.   process_loading    db 'K : Process - loading ',13,10,0
  626.   process_running    db 'K : Process - done',13,10,0
  627.   first_gdt_search   dd 0x2
  628. endg
  629.  
  630.  
  631. sys_threads:
  632.  
  633. ; eax=1 create thread
  634. ;
  635. ;   ebx=thread start
  636. ;   ecx=thread stack value
  637. ;
  638. ; on return : eax = pid
  639. jmp new_sys_threads
  640.  
  641. iglobal
  642.   process_terminating   db 'K : Process - terminating',13,10,0
  643.   process_terminated    db 'K : Process - done',13,10,0
  644. endg
  645.  
  646.  
  647. terminate: ; terminate application
  648.     push   esi
  649.     mov    esi,process_terminating
  650.     call   sys_msg_board_str
  651.     pop    esi
  652.  
  653.     cli
  654.     cmp   [application_table_status],0
  655.     je    term9
  656.     sti
  657.     call  change_task
  658.     jmp   terminate
  659.   term9:
  660.  
  661.     call  set_application_table_status
  662.    
  663.     mov    eax,esi
  664.     call   dispose_app_cr3_table
  665.  
  666.     cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
  667.     jne   fpu_ok_1
  668.     mov   [prev_user_of_fpu],1
  669.   fpu_ok_1:
  670.  
  671.     mov   [0xf400],byte 0           ; empty keyboard buffer
  672.     mov   [0xf500],byte 0           ; empty button buffer
  673.  
  674.  
  675.     mov   ecx,esi                 ; remove buttons
  676.   bnewba2:
  677.     mov   edi,[0xfe88]
  678.     mov   eax,edi
  679.     cld
  680.     movzx ebx,word [edi]
  681.     inc   bx
  682.   bnewba:
  683.     dec   bx
  684.     jz    bnmba
  685.     add   eax,0x10
  686.     cmp   cx,[eax]
  687.     jnz   bnewba
  688.     pusha
  689.     mov   ecx,ebx
  690.     inc   ecx
  691.     shl   ecx,4
  692.     mov   ebx,eax
  693.     add   eax,0x10
  694.     call  memmove
  695.     dec   dword [edi]
  696.     popa
  697.     jmp   bnewba2
  698.   bnmba:
  699.  
  700.     pusha     ; save window coordinates for window restoring
  701.     cld
  702.     shl   esi,5
  703.     add   esi,window_data
  704.     mov   ax,[esi+0]
  705.     mov   word [dlx],ax
  706.     mov   bx,[esi+8]
  707.     add   ax,bx
  708.     mov   word [dlxe],ax
  709.     mov   ax,[esi+4]
  710.     mov   word [dly],ax
  711.     mov   bx,[esi+12]
  712.     add   ax,bx
  713.     mov   word [dlye],ax
  714.     mov   [esi+0],word 0
  715.     mov   [esi+8],word 5
  716.     mov   ax,[0xFE04]
  717.     mov   [esi+4],ax
  718.     mov   [esi+12],word 5
  719.     xor   eax, eax
  720.     mov   [esi+16],eax;dword 0
  721.     mov   [esi+20],eax;dword 0
  722.     mov   [esi+24],eax;dword 0
  723.     mov   [esi+28],eax;dword 0
  724.     popa
  725.  
  726.     pusha
  727.     mov   edi,esi
  728.     shl   edi,5
  729.     add   edi,window_data
  730.     mov   ecx,32/4
  731.     xor   eax, eax
  732.   ;  cld
  733.     rep   stosd
  734.  
  735.     mov   eax,[0xFE04]      ; set window to start from maxy+1
  736.     add   eax,2
  737.  
  738.     mov   edi,esi
  739.     shl   edi,5
  740.     add   edi,window_data
  741.     mov   [edi+4],eax
  742.  
  743.     popa
  744.  
  745.     pusha
  746.     mov   edi,esi
  747.     shl   edi,5
  748.     add   edi,draw_data
  749.     mov   ecx,32/4
  750.     xor   eax, eax
  751.   ;  cld
  752.     rep   stosd
  753.     popa
  754.  
  755.     pusha         ; at 0x80000+
  756.     mov   edi,esi
  757.     shl   edi,8
  758.     add   edi,0x80000
  759.     mov   ecx,256/4
  760.     xor   eax, eax
  761.   ;  cld
  762.     rep   stosd
  763.     popa
  764.  
  765.     pusha          ; name to spaces
  766.     mov   edi,esi
  767.     shl   edi,8
  768.     add   edi,0x80000
  769.     mov   ecx,11
  770.     mov   eax,' '
  771.   ;  cld
  772.     rep   stosb
  773.     popa
  774.  
  775.     pusha                ; C000 --> C400
  776.     mov   eax, 0xc000
  777.     mov   esi, 0
  778.   nlc40:
  779.     add   eax, 2
  780.     inc   esi
  781.     cmp   esi, [0x3004]
  782.     jae   nlc41
  783.     movzx ecx, word [eax]
  784.     mov   [0xC400 + ecx*2], si
  785.     jmp   nlc40
  786.   nlc41:
  787.     popa
  788.  
  789.     pusha ; remove hd1 reservation
  790.     mov   edx,esi
  791.     shl   edx, 5 ;imul  edx,0x20
  792.     add   edx,0x3000
  793.     mov   edx,[edx+4]
  794.     cmp   [hd1_status],edx
  795.     jne   no_hd1_s_remove
  796.     mov   [hd1_status],0
  797.   no_hd1_s_remove:
  798.     popa
  799.  
  800.     pusha ; remove all irq reservations
  801.     mov   edx,esi
  802.     shl   edx, 5 ;imul  edx,0x20
  803.     add   edx,0x3000
  804.     mov   edx,[edx+4]
  805.     mov   edi,irq_owner
  806.     mov   ecx,16
  807.   newirqfree:
  808.     cmp   [edi],edx
  809.     jne   nofreeirq
  810.     mov   [edi],dword 0
  811.   nofreeirq:
  812.     add    edi,4
  813.     loop   newirqfree
  814.     popa
  815.  
  816.  
  817.     pusha                     ; remove all port reservations
  818.     mov   [deleted_process],esi
  819.     mov   edx,esi
  820.     shl   edx, 5 ;imul  edx,0x20
  821.     add   edx,0x3000
  822.     mov   edx,[edx+4]
  823.  
  824.   rmpr0:
  825.  
  826.     mov   esi,[0x2d0000]
  827.  
  828.     cmp   esi,0
  829.     je    rmpr9
  830.  
  831.   rmpr3:
  832.  
  833.     mov   edi,esi
  834.     shl   edi,4
  835.     add   edi,0x2d0000
  836.  
  837.     cmp   edx,[edi]
  838.     je    rmpr4
  839.  
  840.     dec   esi
  841.     jnz   rmpr3
  842.  
  843.     jmp   rmpr9
  844.  
  845.   rmpr4:
  846.  
  847.     mov   ecx,256
  848.     sub   ecx,esi
  849.     shl   ecx,4
  850.  
  851.     mov   esi,edi
  852.     add   esi,16
  853.     cld
  854.     rep   movsb
  855.  
  856.     dec   dword [0x2d0000]
  857.  
  858.     jmp   rmpr0
  859.  
  860.   rmpr9:
  861.  
  862.     popa
  863.     mov  edi,esi         ; do not run this process slot
  864.     shl  edi, 5
  865.     mov  [edi+0x300A],byte 9
  866. ;    call  systest
  867.     sti  ; .. and life goes on
  868.  
  869. ;    movzx eax,word [dlx]
  870. ;    movzx ebx,word [dly]
  871. ;    movzx ecx,word [dlxe]
  872. ;    movzx edx,word [dlye]
  873.     call  calculatescreen
  874.     cli
  875.     mov  eax,[deleted_process]
  876.     cmp  eax,[active_process]
  877.     jne  no_activate_process
  878.     call read_active_process_stack
  879.   no_activate_process:
  880.     sti
  881.     xor   eax, eax
  882.     xor   esi, esi
  883.     call  redrawscreen
  884.  
  885.     mov   [0xfff4],byte 0  ; no mouse background
  886.     mov   [0xfff5],byte 0  ; draw mouse
  887.  
  888.     mov   [application_table_status],0
  889.     mov   esi,process_terminated
  890.     call  sys_msg_board_str
  891.     ret
  892.  
  893. save_active_process_stack:
  894.     cmp   [active_proc_stack_coun],0xa400+0x400-4
  895.     jne   @f
  896.     mov   [active_proc_stack_coun],0xa400-4
  897.   @@:
  898.     push  eax
  899.     push  ebx
  900.     mov   eax,[active_process]
  901.     shl   eax,5
  902.     add   eax,0x3000
  903.     mov   [eax-twdw+31],byte 1
  904.     add   [active_proc_stack_coun],4
  905.     mov   eax,[active_process]
  906.     mov   ebx,[active_proc_stack_coun]
  907.     mov   [ebx],eax
  908.     pop   ebx
  909.     pop   eax
  910.     ret
  911.  
  912. read_active_process_stack:
  913.     cmp   [active_proc_stack_coun],0xa400-4
  914.     jne   @f
  915.     mov   [active_proc_stack_coun],0xa400+0x400-4
  916.   @@:
  917.     push  eax
  918.     push  ebx
  919.     mov   ebx,[active_proc_stack_coun]
  920.     mov   eax,[ebx]
  921.     mov   [0xff01],eax     ; activate
  922.     sub   [active_proc_stack_coun],4
  923.     mov   [active_process_flag],1
  924.     pop   ebx
  925.     pop   eax
  926.     ret
  927.  
  928. iglobal
  929.   boot_sched_1    db   'Building gdt tss pointer',0
  930.   boot_sched_2    db   'Building IDT table',0
  931. endg
  932.  
  933.  
  934. build_scheduler:
  935.  
  936.         mov    esi,boot_sched_1
  937.         call   boot_log
  938.         call   build_process_gdt_tss_pointer
  939.  
  940.         mov    esi,boot_sched_2
  941.         call   boot_log
  942.         call   build_interrupt_table
  943.  
  944.         ret
  945.  
  946.