Subversion Repositories Kolibri OS

Rev

Rev 66 | Rev 76 | 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,debug_exc,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. macro save_ring3_context
  168. {
  169.     push    ds es
  170.     pushad
  171. }
  172. macro restore_ring3_context
  173. {
  174.     popad
  175.     pop    es ds
  176. }
  177.  
  178. ; simply return control to interrupted process
  179. unknown_interrupt:
  180.      iret
  181.  
  182. macro exc_wo_code [num]
  183. {
  184.   forward
  185.   e#num :
  186.       save_ring3_context
  187.       mov bl, num
  188.       jmp exc_c
  189. }
  190.  
  191. macro exc_w_code [num]
  192. {
  193.   forward
  194.   e#num :
  195.       add esp, 4
  196.       save_ring3_context
  197.       mov bl, num
  198.       jmp exc_c
  199. }
  200.  
  201. exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15, 16 ; 18, 19
  202. exc_w_code 8, 10, 11, 12, 13, 14, 17
  203.  
  204. exc_c:
  205.         mov   ax, os_data
  206.         mov   ds, ax
  207.         mov   es, ax
  208.  
  209. ; test if debugging
  210.         cli
  211.         mov   eax, [0x3000]
  212.         shl   eax, 8
  213.         mov   eax, [0x80000+eax+0xAC]
  214.         test  eax, eax
  215.         jnz   .debug
  216.         sti
  217. ; not debuggee => say error and terminate
  218.         add   esp, 28h
  219.         movzx eax, bl        
  220.         mov   [error_interrupt], eax
  221.         call  show_error_parameters
  222.        
  223.         mov   edx, [0x3010]
  224.         mov   [edx + 0xA], byte 4
  225.        
  226.         jmp   change_task
  227.  
  228. .debug:
  229. ; we are debugged process, notify debugger and suspend ourself
  230. ; eax=debugger PID
  231.         movzx ecx, bl
  232.         push  ecx
  233.         mov   ecx, [0x3010]
  234.         push  dword [ecx+4]    ; PID of current process
  235.         push  12
  236.         pop   ecx
  237.         push  1        ; 1=exception
  238.         call  debugger_notify
  239.         pop   ecx
  240.         pop   ecx
  241.         pop   ecx
  242.         mov   edx, [0x3010]
  243.         mov   byte [edx+0xA], 1        ; suspended
  244.         call  change_task
  245.         restore_ring3_context
  246.         iretd
  247.  
  248. ;;;;;;;;;;;;;;;;;;;;;;;
  249. ;; FPU ERROR HANDLER ;;
  250. ;;;;;;;;;;;;;;;;;;;;;;;
  251.  
  252. align 4
  253. e7:
  254.         save_ring3_context
  255.         clts
  256.         mov   ax, os_data
  257.         mov   ds, ax
  258.         mov   es, ax
  259.        
  260.         mov   eax, [prev_user_of_fpu]
  261.         shl   eax, 8
  262.         add   eax, 0x80000 + 0x10
  263.         fsave [eax]
  264.        
  265.         mov   eax, [0x3000]
  266.         mov   [prev_user_of_fpu], eax
  267.         shl   eax, 8
  268.         add   eax, 0x80000
  269.         cmp   [eax + 0x7f], byte 0
  270.         je    @f
  271.         frstor [eax+0x10]
  272.      @@:
  273.         mov   [eax + 0x7f], byte 1
  274.         restore_ring3_context
  275.         iret
  276.        
  277. iglobal
  278.   prev_user_of_fpu dd 1
  279. endg
  280.  
  281.  
  282. writehex:
  283.       pusha
  284.      
  285.       mov  edi, [write_error_to]
  286.       mov  esi, 8
  287.     @@:
  288.       mov  ecx, eax
  289.       and  ecx, 0xf
  290.  
  291.       mov  cl,[ecx+hexletters]
  292.       mov  [edi],cl
  293.       dec  edi
  294.  
  295.       shr  eax,4
  296.       dec  esi
  297.       jnz  @b
  298.  
  299.       popa
  300.       ret
  301.  
  302. iglobal
  303.   hexletters  db '0123456789ABCDEF'
  304.  
  305.   error_interrupt         dd  -1
  306.  
  307.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  308.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  309.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  310.   system_error   db 'K : Kernel error',13,10,0
  311. endg
  312.  
  313. uglobal
  314.   write_error_to  dd  0x0
  315. endg
  316.  
  317. show_error_parameters:
  318.        
  319.         mov    [write_error_to],process_pid+43
  320.         mov    eax,[0x3000]
  321.         shl    eax, 5
  322.         mov    eax,[0x3000+4+eax]
  323.         call   writehex
  324.        
  325.         mov    [write_error_to],process_error+43
  326.         mov    eax,[error_interrupt]
  327.         call   writehex
  328.  
  329.         cmp    dword [esp+4+4], os_code ; CS
  330.         jnz    @f
  331.         mov    esi,system_error
  332.         call   sys_msg_board_str
  333.       @@:
  334.         mov    eax, [esp+4] ; EIP
  335.  
  336.         mov    [write_error_to],process_eip+43
  337.         call   writehex
  338.  
  339.         mov    esi,process_error
  340.         call   sys_msg_board_str
  341.  
  342.         mov    esi,process_pid
  343.         call   sys_msg_board_str
  344.  
  345.         mov    esi,process_eip
  346.         call   sys_msg_board_str
  347.  
  348.         ret
  349.  
  350.  
  351.  
  352. ; irq1  ->  hid/keyboard.inc
  353.  
  354.  
  355. macro irqh [num]
  356. {
  357.   forward
  358.   p_irq#num :
  359.      save_ring3_context
  360.      mov   edi, num
  361.      jmp   irq_c
  362. }
  363.  
  364. irqh 2,5,7,8,9,10,11,14,15
  365.  
  366.  irq_c:
  367.      mov   ax, os_data
  368.      mov   ds, ax
  369.      mov   es, ax
  370.      call  irqhandler
  371.      restore_ring3_context
  372.      iret
  373.  
  374. p_irq6:
  375.      save_ring3_context
  376.      mov   ax, os_data
  377.      mov   ds, ax
  378.      mov   es, ax
  379.      call  fdc_irq
  380.      call  ready_for_next_irq
  381.      restore_ring3_context
  382.      iret
  383.  
  384. p_irq3:
  385.      save_ring3_context
  386.      mov   ax, os_data
  387.      mov   ds, ax
  388.      mov   es, ax
  389.      cmp   [com2_mouse_detected],0
  390.      je    old_irq3_handler
  391.      call  check_mouse_data_com2
  392.      jmp   p_irq3_1
  393.  old_irq3_handler:
  394.      mov   edi,3
  395.      call  irqhandler
  396.   p_irq3_1:
  397.      restore_ring3_context
  398.      iret
  399.  
  400. p_irq4:
  401.      save_ring3_context
  402.      mov   ax, os_data
  403.      mov   ds, ax
  404.      mov   es, ax
  405.      cmp   [com1_mouse_detected],0
  406.      je    old_irq4_handler
  407.      call  check_mouse_data_com1
  408.      jmp   p_irq4_1
  409.  old_irq4_handler:
  410.      mov   edi,4
  411.      call  irqhandler
  412.   p_irq4_1:  
  413.      restore_ring3_context
  414.      iret
  415.  
  416. p_irq12:
  417.      save_ring3_context
  418.      mov   ax, os_data
  419.      mov   ds, ax
  420.      mov   es, ax
  421.      call  check_mouse_data_ps2
  422.      restore_ring3_context
  423.      iret
  424.  
  425. ready_for_next_irq:
  426.      mov    [check_idle_semaphore],5
  427.      mov   al, 0x20
  428.      out   0x20, al
  429.      ret
  430.  
  431. ready_for_next_irq_1:
  432.      mov    [check_idle_semaphore],5
  433.      mov   al, 0x20
  434.      out    0xa0,al
  435.      out   0x20, al
  436.      ret
  437.  
  438. irqD:
  439.      save_ring3_context
  440.      mov   ax, os_data
  441.      mov   ds, ax
  442.      mov   es, ax
  443.      
  444.      mov   dx,0xf0
  445.      mov   al,0
  446.      out   dx,al
  447.  
  448.      mov   dx,0xa0
  449.      mov   al,0x20
  450.      out   dx,al
  451.      mov   dx,0x20
  452.      out   dx,al
  453.  
  454.      restore_ring3_context
  455.      
  456.      iret
  457.  
  458.  
  459. irqhandler:
  460.  
  461.      push   edi
  462.  
  463.      mov    esi,edi          ; 1
  464.      shl    esi,6            ; 1
  465.      add    esi,irq00read    ; 1
  466.      shl    edi,12           ; 1
  467.      add    edi,0x2E0000
  468.      mov    ecx,16
  469.  
  470.      mov    [check_idle_semaphore],5
  471.  
  472.    irqnewread:
  473.      dec    ecx
  474.      js     irqover
  475.  
  476.      mov    dx,[esi]         ; 2+
  477.  
  478.      cmp    dx,0             ; 1
  479.      jz     irqover
  480.      cmp    [esi+3],byte 1   ; 2     ; byte read
  481.      jne    noirqbyte        ; 4-11
  482.  
  483.      in     al,dx
  484.  
  485.      mov    edx,[edi]
  486.      cmp    edx,4000
  487.      je     irqfull
  488.      mov    ebx,edi
  489.      add    ebx,0x10
  490.      add    ebx,edx
  491.      mov    [ebx],al
  492.      inc    edx
  493.      mov    [edi],edx
  494.  
  495.      add    esi,4
  496.      jmp    irqnewread
  497.  
  498.    noirqbyte:
  499.  
  500.  
  501.      cmp    [esi+3],byte 2     ; word read
  502.      jne    noirqword
  503.  
  504.      in     ax,dx
  505.  
  506.      mov    edx,[edi]
  507.      cmp    edx,4000
  508.      je     irqfull
  509.      mov    ebx,edi
  510.      add    ebx,0x10
  511.      add    ebx,edx
  512.      mov    [ebx],ax
  513.      add    edx,2
  514.      mov    [edi],edx
  515.      add    esi,4
  516.      jmp    irqnewread
  517.  
  518.    noirqword:
  519.    irqfull:
  520.    irqover:
  521.  
  522.      mov    al,0x20            ; ready for next irq
  523.      out    0x20,al
  524.  
  525.      pop    ebx
  526.      cmp    ebx,7
  527.      jbe    noa0
  528.      out    0xa0,al
  529.    noa0:
  530.  
  531.      ret
  532.  
  533.  
  534.  
  535. set_application_table_status:
  536.         push eax
  537.  
  538.         mov  eax,[0x3000]
  539.         shl  eax, 5
  540.         add  eax,0x3000+4
  541.         mov  eax,[eax]
  542.  
  543.         mov  [application_table_status],eax
  544.  
  545.         pop  eax
  546.  
  547.         ret
  548.  
  549.  
  550. clear_application_table_status:
  551.         push eax
  552.  
  553.         mov  eax,[0x3000]
  554.         shl  eax, 5
  555.         add  eax,0x3000+4
  556.         mov  eax,[eax]
  557.  
  558.         cmp  eax,[application_table_status]
  559.         jne  apptsl1
  560.         mov  [application_table_status],0
  561.       apptsl1:
  562.  
  563.         pop  eax
  564.  
  565.         ret
  566.  
  567.  
  568.  
  569. sys_resize_app_memory:
  570.         ; eax = 1 - resize
  571.         ;     ebx = new amount of memory
  572.  
  573.         cmp    eax,1
  574.         jne    .no_application_mem_resize
  575.        
  576.         jmp    new_mem_resize ;resize for new type of processes
  577.  
  578.  
  579.      .no_application_mem_resize:
  580.  
  581.         ret
  582.  
  583.  
  584.  
  585. get_app_params:
  586.  
  587.     push eax
  588.  
  589.     cmp  [0x90000+6],word '00'
  590.     jne  no_00_header
  591.  
  592.     mov  eax,[0x90000+12]
  593.     mov  [app_start],eax
  594.     mov  eax,[0x90000+16]
  595.     mov  [app_i_end],eax
  596.     mov  eax,[0x90000+20]
  597.     mov  [app_mem],eax
  598.     shr  eax,1
  599.     sub  eax,0x10
  600.     mov  [app_esp],eax
  601.     mov  eax,[0x90000+24]
  602.     mov  [app_i_param],eax
  603.     mov  [app_i_icon],dword 0
  604.  
  605.     pop  eax
  606.     mov  esi,1
  607.     ret
  608.  
  609.   no_00_header:
  610.  
  611.  
  612.     cmp  [0x90000+6],word '01'
  613.     jne  no_01_header
  614.  
  615.     mov  eax,[0x90000+12]
  616.     mov  [app_start],eax
  617.     mov  eax,[0x90000+16]
  618.     mov  [app_i_end],eax
  619.     mov  eax,[0x90000+20]
  620.     mov  [app_mem],eax
  621.     mov  eax,[0x90000+24]
  622.     mov  [app_esp],eax
  623.     mov  eax,[0x90000+28]
  624.     mov  [app_i_param],eax
  625.     mov  eax,[0x90000+32]
  626.     mov  [app_i_icon],eax
  627.  
  628.     pop  eax
  629.     mov  esi,1
  630.     ret
  631.  
  632.    no_01_header:
  633.  
  634.     pop  eax
  635.     mov  esi,0
  636.     ret
  637.  
  638.  
  639. start_application_fl:
  640.     jmp new_start_application_fl
  641.  
  642. ;************************************************************************
  643.  
  644. start_application_floppy:
  645.     jmp  new_start_application_floppy
  646.  
  647. ;********************************************************************
  648.  
  649. start_application_hd:
  650.     jmp   new_start_application_hd
  651.  
  652. uglobal
  653.   new_process_place  dd  0x0
  654.   app_start    dd  0x0
  655.   app_i_end    dd  0x0
  656.   app_mem      dd  0x0
  657.   app_esp      dd  0x0
  658.   app_i_param  dd  0x0
  659.   app_i_icon   dd  0x0
  660.   app_mem_pos  dd  0x0
  661.   appl_path        dd 0x0
  662.   appl_path_size   dd 0x0        
  663. endg
  664.  
  665. iglobal
  666.   hd_app_string      db  'HDAPP       '
  667.   process_loading    db 'K : Process - loading ',13,10,0
  668.   process_running    db 'K : Process - done',13,10,0
  669.   first_gdt_search   dd 0x2
  670. endg
  671.  
  672.  
  673. sys_threads:
  674.  
  675. ; eax=1 create thread
  676. ;
  677. ;   ebx=thread start
  678. ;   ecx=thread stack value
  679. ;
  680. ; on return : eax = pid
  681. jmp new_sys_threads
  682.  
  683. iglobal
  684.   process_terminating   db 'K : Process - terminating',13,10,0
  685.   process_terminated    db 'K : Process - done',13,10,0
  686. endg
  687.  
  688.  
  689. terminate: ; terminate application
  690.     push   esi
  691.     mov    esi,process_terminating
  692.     call   sys_msg_board_str
  693.     pop    esi
  694.  
  695. @@:
  696.     cli
  697.     cmp   [application_table_status],0
  698.     je    term9
  699.     sti
  700.     call  change_task
  701.     jmp   @b
  702.   term9:
  703.  
  704.     call  set_application_table_status
  705.    
  706.     mov    eax,esi
  707.     call   dispose_app_cr3_table
  708.  
  709.     cmp   [prev_user_of_fpu],esi   ; if user fpu last -> fpu user = 1
  710.     jne   fpu_ok_1
  711.     mov   [prev_user_of_fpu],1
  712.   fpu_ok_1:
  713.  
  714.     mov   [0xf400],byte 0           ; empty keyboard buffer
  715.     mov   [0xf500],byte 0           ; empty button buffer
  716.  
  717.  
  718.     mov   ecx,esi                 ; remove buttons
  719.   bnewba2:
  720.     mov   edi,[0xfe88]
  721.     mov   eax,edi
  722.     cld
  723.     movzx ebx,word [edi]
  724.     inc   bx
  725.   bnewba:
  726.     dec   bx
  727.     jz    bnmba
  728.     add   eax,0x10
  729.     cmp   cx,[eax]
  730.     jnz   bnewba
  731.     pusha
  732.     mov   ecx,ebx
  733.     inc   ecx
  734.     shl   ecx,4
  735.     mov   ebx,eax
  736.     add   eax,0x10
  737.     call  memmove
  738.     dec   dword [edi]
  739.     popa
  740.     jmp   bnewba2
  741.   bnmba:
  742.  
  743.     pusha     ; save window coordinates for window restoring
  744.     cld
  745.     shl   esi,5
  746.     add   esi,window_data
  747.     mov   ax,[esi+0]
  748.     mov   word [dlx],ax
  749.     mov   bx,[esi+8]
  750.     add   ax,bx
  751.     mov   word [dlxe],ax
  752.     mov   ax,[esi+4]
  753.     mov   word [dly],ax
  754.     mov   bx,[esi+12]
  755.     add   ax,bx
  756.     mov   word [dlye],ax
  757.     mov   [esi+0],word 0
  758.     mov   [esi+8],word 5
  759.     mov   ax,[0xFE04]
  760.     mov   [esi+4],ax
  761.     mov   [esi+12],word 5
  762.     xor   eax, eax
  763.     mov   [esi+16],eax;dword 0
  764.     mov   [esi+20],eax;dword 0
  765.     mov   [esi+24],eax;dword 0
  766.     mov   [esi+28],eax;dword 0
  767.     popa
  768.  
  769.     pusha
  770.     mov   edi,esi
  771.     shl   edi,5
  772.     add   edi,window_data
  773.     mov   ecx,32/4
  774.     xor   eax, eax
  775.   ;  cld
  776.     rep   stosd
  777.  
  778.     mov   eax,[0xFE04]      ; set window to start from maxy+1
  779.     add   eax,2
  780.  
  781.     mov   edi,esi
  782.     shl   edi,5
  783.     add   edi,window_data
  784.     mov   [edi+4],eax
  785.  
  786.     popa
  787.  
  788.     pusha
  789.     mov   edi,esi
  790.     shl   edi,5
  791.     add   edi,draw_data
  792.     mov   ecx,32/4
  793.     xor   eax, eax
  794.   ;  cld
  795.     rep   stosd
  796.     popa
  797.  
  798. ; debuggee test
  799.     pushad
  800.     mov  edi, esi
  801.     shl  edi, 5
  802.     mov  eax, [0x80000+edi*8+0xAC]
  803.     test eax, eax
  804.     jz   .nodebug
  805.     push 8
  806.     pop  ecx
  807.     push dword [0x3000+edi+0x4]   ; PID
  808.     push 2
  809.     call debugger_notify
  810.     pop  ecx
  811.     pop  ecx
  812. .nodebug:
  813.     popad
  814.  
  815.     pusha         ; at 0x80000+
  816.     mov   edi,esi
  817.     shl   edi,8
  818.     add   edi,0x80000
  819.     mov   ecx,256/4
  820.     xor   eax, eax
  821.   ;  cld
  822.     rep   stosd
  823.     popa
  824.  
  825.     pusha          ; name to spaces
  826.     mov   edi,esi
  827.     shl   edi,8
  828.     add   edi,0x80000
  829.     mov   ecx,11
  830.     mov   eax,' '
  831.   ;  cld
  832.     rep   stosb
  833.     popa
  834.  
  835.     pusha                ; C000 --> C400
  836.     mov   eax, 0xc000
  837.     mov   esi, 0
  838.   nlc40:
  839.     add   eax, 2
  840.     inc   esi
  841.     cmp   esi, [0x3004]
  842.     jae   nlc41
  843.     movzx ecx, word [eax]
  844.     mov   [0xC400 + ecx*2], si
  845.     jmp   nlc40
  846.   nlc41:
  847.     popa
  848.  
  849.     pusha ; remove hd1 reservation
  850.     mov   edx,esi
  851.     shl   edx, 5 ;imul  edx,0x20
  852.     add   edx,0x3000
  853.     mov   edx,[edx+4]
  854.     cmp   [hd1_status],edx
  855.     jne   no_hd1_s_remove
  856.     mov   [hd1_status],0
  857.   no_hd1_s_remove:
  858.     popa
  859.  
  860.     pusha ; remove all irq reservations
  861.     mov   edx,esi
  862.     shl   edx, 5 ;imul  edx,0x20
  863.     add   edx,0x3000
  864.     mov   edx,[edx+4]
  865.     mov   edi,irq_owner
  866.     mov   ecx,16
  867.   newirqfree:
  868.     cmp   [edi],edx
  869.     jne   nofreeirq
  870.     mov   [edi],dword 0
  871.   nofreeirq:
  872.     add    edi,4
  873.     loop   newirqfree
  874.     popa
  875.  
  876.  
  877.     pusha                     ; remove all port reservations
  878.     mov   [deleted_process],esi
  879.     mov   edx,esi
  880.     shl   edx, 5 ;imul  edx,0x20
  881.     add   edx,0x3000
  882.     mov   edx,[edx+4]
  883.  
  884.   rmpr0:
  885.  
  886.     mov   esi,[0x2d0000]
  887.  
  888.     cmp   esi,0
  889.     je    rmpr9
  890.  
  891.   rmpr3:
  892.  
  893.     mov   edi,esi
  894.     shl   edi,4
  895.     add   edi,0x2d0000
  896.  
  897.     cmp   edx,[edi]
  898.     je    rmpr4
  899.  
  900.     dec   esi
  901.     jnz   rmpr3
  902.  
  903.     jmp   rmpr9
  904.  
  905.   rmpr4:
  906.  
  907.     mov   ecx,256
  908.     sub   ecx,esi
  909.     shl   ecx,4
  910.  
  911.     mov   esi,edi
  912.     add   esi,16
  913.     cld
  914.     rep   movsb
  915.  
  916.     dec   dword [0x2d0000]
  917.  
  918.     jmp   rmpr0
  919.  
  920.   rmpr9:
  921.  
  922.     popa
  923.     mov  edi,esi         ; do not run this process slot
  924.     shl  edi, 5
  925.     mov  [edi+0x300A],byte 9
  926. ; debugger test - terminate all debuggees
  927.     mov  eax, 2
  928.     mov  ecx, 0x80000+2*0x100+0xAC
  929. .xd0:
  930.     cmp  eax, [0x3004]
  931.     ja   .xd1
  932.     cmp  dword [ecx], esi
  933.     jnz  @f
  934.     and  dword [ecx], 0
  935.     pushad
  936.     xchg eax, ebx
  937.     mov  eax, 2
  938.     call sys_system
  939.     popad
  940. @@:
  941.     inc  eax
  942.     add  ecx, 0x100
  943.     jmp  .xd0
  944. .xd1:
  945. ;    call  systest
  946.     sti  ; .. and life goes on
  947.  
  948. ;    movzx eax,word [dlx]
  949. ;    movzx ebx,word [dly]
  950. ;    movzx ecx,word [dlxe]
  951. ;    movzx edx,word [dlye]
  952.     call  calculatescreen
  953.     cli
  954.     mov  eax,[deleted_process]
  955.     cmp  eax,[active_process]
  956.     jne  no_activate_process
  957.     call read_active_process_stack
  958.   no_activate_process:
  959.     sti
  960.     xor   eax, eax
  961.     xor   esi, esi
  962.     call  redrawscreen
  963.  
  964.     mov   [0xfff4],byte 0  ; no mouse background
  965.     mov   [0xfff5],byte 0  ; draw mouse
  966.  
  967.     mov   [application_table_status],0
  968.     mov   esi,process_terminated
  969.     call  sys_msg_board_str
  970.     ret
  971.  
  972. save_active_process_stack:
  973.     cmp   [active_proc_stack_coun],0xa400+0x400-4
  974.     jne   @f
  975.     mov   [active_proc_stack_coun],0xa400-4
  976.   @@:
  977.     push  eax
  978.     push  ebx
  979.     mov   eax,[active_process]
  980.     shl   eax,5
  981.     add   eax,0x3000
  982.     mov   [eax-twdw+31],byte 1
  983.     add   [active_proc_stack_coun],4
  984.     mov   eax,[active_process]
  985.     mov   ebx,[active_proc_stack_coun]
  986.     mov   [ebx],eax
  987.     pop   ebx
  988.     pop   eax
  989.     ret
  990.  
  991. read_active_process_stack:
  992.     cmp   [active_proc_stack_coun],0xa400-4
  993.     jne   @f
  994.     mov   [active_proc_stack_coun],0xa400+0x400-4
  995.   @@:
  996.     push  eax
  997.     push  ebx
  998.     mov   ebx,[active_proc_stack_coun]
  999.     mov   eax,[ebx]
  1000.     mov   [0xff01],eax     ; activate
  1001.     sub   [active_proc_stack_coun],4
  1002.     mov   [active_process_flag],1
  1003.     pop   ebx
  1004.     pop   eax
  1005.     ret
  1006.  
  1007. iglobal
  1008.   boot_sched_1    db   'Building gdt tss pointer',0
  1009.   boot_sched_2    db   'Building IDT table',0
  1010. endg
  1011.  
  1012.  
  1013. build_scheduler:
  1014.  
  1015.         mov    esi,boot_sched_1
  1016.         call   boot_log
  1017.         call   build_process_gdt_tss_pointer
  1018.  
  1019.         mov    esi,boot_sched_2
  1020.         call   boot_log
  1021.         call   build_interrupt_table
  1022.  
  1023.         ret
  1024.  
  1025.