Subversion Repositories Kolibri OS

Rev

Rev 160 | Rev 168 | 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. ; --------------- APM ---------------------
  39. apm_code_32:
  40.         dw     0x10        ; limit 64kb
  41.         db     0, 0, 0
  42.         dw     11011111b *256 +10011010b
  43.         db     0x00
  44. apm_code_16:
  45.         dw     0x10
  46.         db     0, 0, 0
  47.         dw     10011111b *256 +10011010b
  48.         db     0x00
  49. apm_data_16:
  50.         dw     0x10
  51.         db     0, 0, 0
  52.         dw     10011111b *256 +10010010b
  53.         db     0x00
  54. ; -----------------------------------------
  55.  
  56. app_code_l:
  57.       dw 0xFFFF;((0x80000000-std_application_base_address) shr 12) and 0xffff
  58.       dw 0
  59.       db 0x40
  60.       db cpl3
  61.       dw G32+D32+0x6000+0x7;
  62.  
  63. app_data_l:
  64.       dw 0xFFFF;(0x80000000-std_application_base_address) shr 12 and 0xffff
  65.       dw 0
  66.       db 0x40
  67.       db drw3
  68.       dw G32+D32+0x6000+0x7;
  69.  
  70. graph_data_l:
  71.  
  72.         dw     0x3ff
  73.         dw     0x0000
  74.         db     0x00
  75.         dw     11010000b *256 +11110010b
  76.         db     0x00
  77.  
  78. tss0_l:
  79.       times (max_processes+10) dd 0,0
  80.  
  81. gdte:
  82.  
  83.  
  84. idtreg:
  85.      dw   8*0x41-1
  86.      dd   idts+8
  87. ;label idts at 0xB100-8
  88.  
  89.  
  90.  
  91. uglobal
  92.  tss_sceleton:
  93.   l.back   dw 0,0
  94.   l.esp0   dd 0
  95.   l.ss0    dw 0,0
  96.   l.esp1   dd 0
  97.   l.ss1    dw 0,0
  98.   l.esp2   dd 0
  99.   l.ss2    dw 0,0
  100.   l.cr3    dd 0
  101.   l.eip    dd 0
  102.   l.eflags dd 0
  103.   l.eax    dd 0
  104.   l.ecx    dd 0
  105.   l.edx    dd 0
  106.   l.ebx    dd 0
  107.   l.esp    dd 0
  108.   l.ebp    dd 0
  109.   l.esi    dd 0
  110.   l.edi    dd 0
  111.   l.es     dw 0,0
  112.   l.cs     dw 0,0
  113.   l.ss     dw 0,0
  114.   l.ds     dw 0,0
  115.   l.fs     dw 0,0
  116.   l.gs     dw 0,0
  117.   l.ldt    dw 0,0
  118.   l.trap   dw 0
  119.   l.io     dw 0
  120. endg
  121.  
  122.  
  123. build_process_gdt_tss_pointer:
  124.  
  125.         mov    ecx,tss_data
  126.         mov    edi,0
  127.       setgdtl2:
  128.         mov    [edi+gdts+ tss0 +0], word tss_step
  129.         mov    [edi+gdts+ tss0 +2], cx
  130.         mov    eax,ecx
  131.         shr    eax,16
  132.         mov    [edi+gdts+ tss0 +4], al
  133.         mov    [edi+gdts+ tss0 +7], ah
  134.         mov    [edi+gdts+ tss0 +5], word 01010000b *256 +11101001b
  135.         add    ecx,tss_step
  136.         add    edi,8
  137.         cmp    edi,8*(max_processes+5)
  138.         jbe    setgdtl2
  139.  
  140.         ret
  141.  
  142.  
  143. build_interrupt_table:
  144.  
  145.         mov    edi, idts+8
  146.         mov    esi, sys_int
  147.         mov    ecx, 0x40
  148.      @@:
  149.         mov    eax, [esi]
  150.         mov    [edi],   ax           ; lower part of offset
  151.         mov    [edi+2], word os_code ; segment selector
  152.         shr    eax, 16
  153.         mov    [edi+4], word 10001110b shl 8 ; interrupt descriptor
  154.         mov    [edi+6], ax
  155.         add    esi, 4
  156.         add    edi, 8
  157.         dec    ecx
  158.         jnz    @b
  159.  
  160.         ;mov    edi,8*0x40+idts+8
  161.         mov    [edi + 0], word (i40 and ((1 shl 16)-1))
  162.         mov    [edi + 2], word os_code
  163.         mov    [edi + 4], word 11101110b*256
  164.         mov    [edi + 6], word (i40 shr 16)
  165.  
  166.         ret
  167.  
  168. iglobal
  169.   sys_int:
  170.     dd e0,debug_exc,e2,e3
  171.     dd e4,e5,e6,e7
  172.     dd e8,e9,e10,e11
  173.     dd e12,e13,page_fault_handler,e15
  174.  
  175.     dd except_16, e17
  176.     times 14 dd unknown_interrupt
  177.  
  178.     dd   irq0  , irq_serv.irq_1, p_irq2 ,irq_serv.irq_3
  179.     dd   p_irq4 ,irq_serv.irq_5,p_irq6,irq_serv.irq_7
  180.     dd   irq_serv.irq_8, irq_serv.irq_9, irq_serv.irq_10
  181.     dd   irq_serv.irq_11,p_irq12,irqD ,p_irq14,p_irq15
  182.  
  183.     times 16 dd unknown_interrupt
  184.  
  185.     dd   i40
  186. endg
  187.  
  188. macro save_ring3_context
  189. {
  190.     push    ds es
  191.     pushad
  192. }
  193. macro restore_ring3_context
  194. {
  195.     popad
  196.     pop    es ds
  197. }
  198.  
  199. ; simply return control to interrupted process
  200. unknown_interrupt:
  201.      iret
  202.  
  203. macro exc_wo_code [num]
  204. {
  205.   forward
  206.   e#num :
  207.       save_ring3_context
  208.       mov bl, num
  209.       jmp exc_c
  210. }
  211.  
  212. macro exc_w_code [num]
  213. {
  214.   forward
  215.   e#num :
  216.       add esp, 4
  217.       save_ring3_context
  218.       mov bl, num
  219.       jmp exc_c
  220. }
  221.  
  222. exc_wo_code 0, 1, 2, 3, 4, 5, 6, 9, 15 ; 18, 19
  223. exc_w_code 8, 10, 11, 12, 13, 14, 17
  224.  
  225. exc_c:
  226.         mov   ax, os_data
  227.         mov   ds, ax
  228.         mov   es, ax
  229.  
  230. ; test if debugging
  231.         cli
  232.         mov   eax, [0x3000]
  233.         shl   eax, 8
  234.         mov   eax, [0x80000+eax+APPDATA.debugger_slot]
  235.         test  eax, eax
  236.         jnz   .debug
  237.         sti
  238. ; not debuggee => say error and terminate
  239.         add   esp, 28h
  240.         movzx eax, bl
  241.         mov   [error_interrupt], eax
  242.         call  show_error_parameters
  243.  
  244.         mov   edx, [0x3010]
  245.         mov   [edx + TASKDATA.state], byte 4
  246.  
  247.         jmp   change_task
  248.  
  249. .debug:
  250. ; we are debugged process, notify debugger and suspend ourself
  251. ; eax=debugger PID
  252.         cld
  253.         movzx ecx, bl
  254.         push  ecx
  255.         mov   ecx, [0x3010]
  256.         push  dword [ecx+TASKDATA.pid]    ; PID of current process
  257.         push  12
  258.         pop   ecx
  259.         push  1        ; 1=exception
  260.         call  debugger_notify
  261.         pop   ecx
  262.         pop   ecx
  263.         pop   ecx
  264.         mov   edx, [0x3010]
  265.         mov   byte [edx+TASKDATA.state], 1        ; suspended
  266.         call  change_task
  267.         restore_ring3_context
  268.         iretd
  269.  
  270. ;;;;;;;;;;;;;;;;;;;;;;;
  271. ;; FPU ERROR HANDLER ;;
  272. ;;;;;;;;;;;;;;;;;;;;;;;
  273.  
  274. align 4
  275. e7:
  276.         save_ring3_context
  277.         clts
  278.         mov ax, os_data
  279.         mov ds, ax
  280.         mov es, ax
  281.  
  282.         mov ebx, [fpu_owner]
  283.         cmp ebx, [CURRENT_TASK]
  284.         je .exit
  285.  
  286.         shl ebx, 8
  287.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  288.         bt [cpu_caps], CAPS_FXSR
  289.         jnc .no_SSE
  290.  
  291.         fxsave [eax]
  292.         mov ebx, [CURRENT_TASK]
  293.         mov [fpu_owner], ebx
  294.         shl ebx, 8
  295.         cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
  296.         je .init
  297.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  298.         fxrstor [eax]
  299.         restore_ring3_context
  300.         iret
  301. .init:
  302.         fninit                      ;­ ¬ ­¥ ­ã¦­ë ­¥¬ áª¨à®¢ ­­ë¥ ¨áª«î祭¨ï
  303.         mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
  304. .exit:
  305.         restore_ring3_context
  306.         iret
  307. .no_SSE:
  308.         fnsave [eax]
  309.         mov ebx, [CURRENT_TASK]
  310.         mov [fpu_owner], ebx
  311.         shl ebx, 8
  312.         cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
  313.         je .init
  314.  
  315.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  316.         frstor [eax]
  317.         restore_ring3_context
  318.         iret
  319.  
  320. iglobal
  321.   fpu_owner dd 1
  322.  endg
  323.  
  324.  
  325. writehex:
  326.       pusha
  327.  
  328.       mov  edi, [write_error_to]
  329.       mov  esi, 8
  330.     @@:
  331.       mov  ecx, eax
  332.       and  ecx, 0xf
  333.  
  334.       mov  cl,[ecx+hexletters]
  335.       mov  [edi],cl
  336.       dec  edi
  337.  
  338.       shr  eax,4
  339.       dec  esi
  340.       jnz  @b
  341.  
  342.       popa
  343.       ret
  344.  
  345. iglobal
  346.   hexletters  db '0123456789ABCDEF'
  347.  
  348.   error_interrupt         dd  -1
  349.  
  350.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  351.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  352.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  353.   system_error   db 'K : Kernel error',13,10,0
  354. endg
  355.  
  356. uglobal
  357.   write_error_to  dd  0x0
  358. endg
  359.  
  360. show_error_parameters:
  361.  
  362.         mov    [write_error_to],process_pid+43
  363.         mov    eax,[0x3000]
  364.         shl    eax, 5
  365.         mov    eax,[0x3000+TASKDATA.pid+eax]
  366.         call   writehex
  367.  
  368.         mov    [write_error_to],process_error+43
  369.         mov    eax,[error_interrupt]
  370.         call   writehex
  371.  
  372.         cmp    dword [esp+4+4], os_code ; CS
  373.         jnz    @f
  374.         mov    esi,system_error
  375.         call   sys_msg_board_str
  376.       @@:
  377.         mov    eax, [esp+4] ; EIP
  378.  
  379.         mov    [write_error_to],process_eip+43
  380.         call   writehex
  381.  
  382.         mov    esi,process_error
  383.         call   sys_msg_board_str
  384.  
  385.         mov    esi,process_pid
  386.         call   sys_msg_board_str
  387.  
  388.         mov    esi,process_eip
  389.         call   sys_msg_board_str
  390.  
  391.         ret
  392.  
  393.  
  394.  
  395. ; irq1  ->  hid/keyboard.inc
  396.  
  397.  
  398. macro irqh [num]
  399. {
  400.   forward
  401.   p_irq#num :
  402.      save_ring3_context
  403.      mov   edi, num
  404.      jmp   irq_c
  405. }
  406.  
  407. irqh 2,5,7,8,9,10,11
  408.  
  409.  irq_c:
  410.      mov   ax, os_data
  411.      mov   ds, ax
  412.      mov   es, ax
  413.      call  irqhandler
  414.      restore_ring3_context
  415.      iret
  416.  
  417. p_irq6:
  418.      save_ring3_context
  419.      mov   ax, os_data
  420.      mov   ds, ax
  421.      mov   es, ax
  422.      call  fdc_irq
  423.      call  ready_for_next_irq
  424.      restore_ring3_context
  425.      iret
  426.  
  427. p_irq3:
  428.      save_ring3_context
  429.      mov   ax, os_data
  430.      mov   ds, ax
  431.      mov   es, ax
  432.      cmp   [com2_mouse_detected],0
  433.      je    old_irq3_handler
  434.      call  check_mouse_data_com2
  435.      jmp   p_irq3_1
  436.  old_irq3_handler:
  437.      mov   edi,3
  438.      call  irqhandler
  439.   p_irq3_1:
  440.      restore_ring3_context
  441.      iret
  442.  
  443. p_irq4:
  444.      save_ring3_context
  445.      mov   ax, os_data
  446.      mov   ds, ax
  447.      mov   es, ax
  448.      cmp   [com1_mouse_detected],0
  449.      je    old_irq4_handler
  450.      call  check_mouse_data_com1
  451.      jmp   p_irq4_1
  452.  old_irq4_handler:
  453.      mov   edi,4
  454.      call  irqhandler
  455.   p_irq4_1:
  456.      restore_ring3_context
  457.      iret
  458.  
  459. p_irq12:
  460.      save_ring3_context
  461.      mov   ax, os_data
  462.      mov   ds, ax
  463.      mov   es, ax
  464.      call  check_mouse_data_ps2
  465.      restore_ring3_context
  466.      iret
  467.  
  468. p_irq14:
  469.         save_ring3_context
  470.         mov     ax, os_data
  471.         mov     ds, ax
  472.         mov     es, ax
  473.         call    [irq14_func]
  474.         call    ready_for_next_irq_1
  475.         restore_ring3_context
  476.         iret
  477. p_irq15:
  478.         save_ring3_context
  479.         mov     ax, os_data
  480.         mov     ds, ax
  481.         mov     es, ax
  482.         call    [irq15_func]
  483.         call    ready_for_next_irq_1
  484.         restore_ring3_context
  485.         iret
  486.  
  487. ready_for_next_irq:
  488.      mov    [check_idle_semaphore],5
  489.      mov   al, 0x20
  490.      out   0x20, al
  491.      ret
  492.  
  493. ready_for_next_irq_1:
  494.      mov    [check_idle_semaphore],5
  495.      mov   al, 0x20
  496.      out    0xa0,al
  497.      out   0x20, al
  498.      ret
  499.  
  500. irqD:
  501.      save_ring3_context
  502.      mov   ax, os_data
  503.      mov   ds, ax
  504.      mov   es, ax
  505.  
  506.      mov   dx,0xf0
  507.      mov   al,0
  508.      out   dx,al
  509.  
  510.      mov   dx,0xa0
  511.      mov   al,0x20
  512.      out   dx,al
  513.      mov   dx,0x20
  514.      out   dx,al
  515.  
  516.      restore_ring3_context
  517.  
  518.      iret
  519.  
  520.  
  521. irqhandler:
  522.  
  523.      push   edi
  524.  
  525.      mov    esi,edi          ; 1
  526.      shl    esi,6            ; 1
  527.      add    esi,irq00read    ; 1
  528.      shl    edi,12           ; 1
  529.      add    edi,0x2E0000
  530.      mov    ecx,16
  531.  
  532.      mov    [check_idle_semaphore],5
  533.  
  534.    irqnewread:
  535.      dec    ecx
  536.      js     irqover
  537.  
  538.      mov    dx,[esi]         ; 2+
  539.  
  540.      cmp    dx,0             ; 1
  541.      jz     irqover
  542.      cmp    [esi+3],byte 1   ; 2     ; byte read
  543.      jne    noirqbyte        ; 4-11
  544.  
  545.      in     al,dx
  546.  
  547.      mov    edx,[edi]
  548.      cmp    edx,4000
  549.      je     irqfull
  550.      mov    ebx,edi
  551.      add    ebx,0x10
  552.      add    ebx,edx
  553.      mov    [ebx],al
  554.      inc    edx
  555.      mov    [edi],edx
  556.  
  557.      add    esi,4
  558.      jmp    irqnewread
  559.  
  560.    noirqbyte:
  561.  
  562.  
  563.      cmp    [esi+3],byte 2     ; word read
  564.      jne    noirqword
  565.  
  566.      in     ax,dx
  567.  
  568.      mov    edx,[edi]
  569.      cmp    edx,4000
  570.      je     irqfull
  571.      mov    ebx,edi
  572.      add    ebx,0x10
  573.      add    ebx,edx
  574.      mov    [ebx],ax
  575.      add    edx,2
  576.      mov    [edi],edx
  577.      add    esi,4
  578.      jmp    irqnewread
  579.  
  580.    noirqword:
  581.    irqfull:
  582.    irqover:
  583.  
  584.      mov    al,0x20            ; ready for next irq
  585.      out    0x20,al
  586.  
  587.      pop    ebx
  588.      cmp    ebx,7
  589.      jbe    noa0
  590.      out    0xa0,al
  591.    noa0:
  592.  
  593.      ret
  594.  
  595.  
  596.  
  597. set_application_table_status:
  598.         push eax
  599.  
  600.         mov  eax,[0x3000]
  601.         shl  eax, 5
  602.         add  eax,0x3000+TASKDATA.pid
  603.         mov  eax,[eax]
  604.  
  605.         mov  [application_table_status],eax
  606.  
  607.         pop  eax
  608.  
  609.         ret
  610.  
  611.  
  612. clear_application_table_status:
  613.         push eax
  614.  
  615.         mov  eax,[0x3000]
  616.         shl  eax, 5
  617.         add  eax,0x3000+TASKDATA.pid
  618.         mov  eax,[eax]
  619.  
  620.         cmp  eax,[application_table_status]
  621.         jne  apptsl1
  622.         mov  [application_table_status],0
  623.       apptsl1:
  624.  
  625.         pop  eax
  626.  
  627.         ret
  628.  
  629.  
  630.  
  631. sys_resize_app_memory:
  632.         ; eax = 1 - resize
  633.         ;     ebx = new amount of memory
  634.  
  635.         cmp    eax,1
  636.         jne    .no_application_mem_resize
  637.  
  638.         stdcall new_mem_resize, ebx
  639.         mov [esp+36], eax
  640.         ret
  641.  
  642. .no_application_mem_resize:
  643.         ret
  644.  
  645.  
  646.  
  647. get_app_params:
  648.  
  649.     push eax
  650.  
  651.     cmp  [0x90000+6],word '00'
  652.     jne  no_00_header
  653.  
  654.     mov  eax,[0x90000+12]
  655.     mov  [app_start],eax
  656.     mov  eax,[0x90000+16]
  657.     mov  [app_i_end],eax
  658.     mov  eax,[0x90000+20]
  659.     mov  [app_mem],eax
  660. ; \begin{diamond}[20.08.2006]
  661. ; sanity check (functions 19,58 load app_i_end bytes and that must
  662. ; fit in allocated memory to prevent kernel faults)
  663.     cmp  eax,[app_i_end]
  664.     jb   no_01_header
  665. ; \end{diamond}[20.08.2006]
  666.     shr  eax,1
  667.     sub  eax,0x10
  668.     mov  [app_esp],eax
  669.     mov  eax,[0x90000+24]
  670.     mov  [app_i_param],eax
  671.     mov  [app_i_icon],dword 0
  672.  
  673.     pop  eax
  674.     clc
  675.     ret
  676.  
  677.   no_00_header:
  678.  
  679.  
  680.     cmp  [0x90000+6],word '01'
  681.     jne  no_01_header
  682.  
  683.     mov  eax,[0x90000+12]
  684.     mov  [app_start],eax
  685.     mov  eax,[0x90000+16]
  686.     mov  [app_i_end],eax
  687.     mov  eax,[0x90000+20]
  688.     mov  [app_mem],eax
  689. ; \begin{diamond}[20.08.2006]
  690.     cmp  eax,[app_i_end]
  691.     jb   no_01_header
  692. ; \end{diamond}[20.08.2006]
  693.     mov  eax,[0x90000+24]
  694.     mov  [app_esp],eax
  695.     mov  eax,[0x90000+28]
  696.     mov  [app_i_param],eax
  697.     mov  eax,[0x90000+32]
  698.     mov  [app_i_icon],eax
  699.  
  700.     pop  eax
  701.     clc
  702.     ret
  703.  
  704.    no_01_header:
  705.  
  706.     pop  eax
  707.     stc
  708.     ret
  709.  
  710.  
  711. uglobal
  712.   new_process_place  dd  0x0
  713.   app_start    dd  0x0
  714.   app_i_end    dd  0x0
  715.   app_mem      dd  0x0
  716.   app_esp      dd  0x0
  717.   app_i_param  dd  0x0
  718.   app_i_icon   dd  0x0
  719. ;  app_mem_pos  dd  0x0
  720.   appl_path        dd 0x0
  721.   appl_path_size   dd 0x0
  722. endg
  723.  
  724.  
  725. sys_threads:
  726.  
  727. ; eax=1 create thread
  728. ;
  729. ;   ebx=thread start
  730. ;   ecx=thread stack value
  731. ;
  732. ; on return : eax = pid
  733. jmp new_sys_threads
  734.  
  735. iglobal
  736.   process_terminating   db 'K : Process - terminating',13,10,0
  737.   process_terminated    db 'K : Process - done',13,10,0
  738. endg
  739.  
  740.  
  741. terminate: ; terminate application
  742.     push   esi
  743.     mov    esi,process_terminating
  744.     call   sys_msg_board_str
  745.     pop    esi
  746.  
  747. @@:
  748.     cli
  749.     cmp   [application_table_status],0
  750.     je    term9
  751.     sti
  752.     call  change_task
  753.     jmp   @b
  754.   term9:
  755.  
  756.     call  set_application_table_status
  757.  
  758.     mov    eax,esi
  759.  
  760.     pushad
  761.     shl   eax,8
  762.     mov   eax,[PROC_BASE+eax+0xB8]
  763.     stdcall destroy_app_space, eax
  764.     popad
  765.  
  766.     cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  767.     jne   fpu_ok_1
  768.     mov   [fpu_owner],1
  769.   fpu_ok_1:
  770.  
  771.     mov   [0xf400],byte 0           ; empty keyboard buffer
  772.     mov   [0xf500],byte 0           ; empty button buffer
  773.  
  774.  
  775. ; remove defined hotkeys
  776.         mov     eax, hotkey_list
  777. .loop:
  778.         cmp     [eax+8], esi
  779.         jnz     .cont
  780.         mov     ecx, [eax]
  781.         jecxz   @f
  782.         push    dword [eax+12]
  783.         pop     dword [ecx+12]
  784. @@:
  785.         mov     ecx, [eax+12]
  786.         push    dword [eax]
  787.         pop     dword [ecx]
  788.         xor     ecx, ecx
  789.         mov     [eax], ecx
  790.         mov     [eax+4], ecx
  791.         mov     [eax+8], ecx
  792.         mov     [eax+12], ecx
  793. .cont:
  794.         add     eax, 16
  795.         cmp     eax, hotkey_list+256*16
  796.         jb      .loop
  797. ; remove hotkeys in buffer
  798.         mov     eax, hotkey_buffer
  799. .loop2:
  800.         cmp     [eax], esi
  801.         jnz     .cont2
  802.         and     dword [eax+4], 0
  803.         and     dword [eax], 0
  804. .cont2:
  805.         add     eax, 8
  806.         cmp     eax, hotkey_buffer+120*8
  807.         jb      .loop2
  808.  
  809.     mov   ecx,esi                 ; remove buttons
  810.   bnewba2:
  811.     mov   edi,[0xfe88]
  812.     mov   eax,edi
  813.     cld
  814.     movzx ebx,word [edi]
  815.     inc   bx
  816.   bnewba:
  817.     dec   bx
  818.     jz    bnmba
  819.     add   eax,0x10
  820.     cmp   cx,[eax]
  821.     jnz   bnewba
  822.     pusha
  823.     mov   ecx,ebx
  824.     inc   ecx
  825.     shl   ecx,4
  826.     mov   ebx,eax
  827.     add   eax,0x10
  828.     call  memmove
  829.     dec   dword [edi]
  830.     popa
  831.     jmp   bnewba2
  832.   bnmba:
  833.  
  834.     pusha     ; save window coordinates for window restoring
  835.     cld
  836.     shl   esi,5
  837.     add   esi,window_data
  838.     mov   eax,[esi+WDATA.box.left]
  839.     mov   [dlx],eax
  840.     add   eax,[esi+WDATA.box.width]
  841.     mov   [dlxe],eax
  842.     mov   eax,[esi+WDATA.box.top]
  843.     mov   [dly],eax
  844.     add   eax,[esi+WDATA.box.height]
  845.     mov   [dlye],eax
  846.  
  847.     xor   eax, eax
  848.     mov   [esi+WDATA.box.left],eax
  849.     mov   [esi+WDATA.box.width],eax
  850.     mov   [esi+WDATA.box.top],eax
  851.     mov   [esi+WDATA.box.height],eax
  852.     mov   [esi+WDATA.cl_workarea],eax
  853.     mov   [esi+WDATA.cl_titlebar],eax
  854.     mov   [esi+WDATA.cl_frames],eax
  855.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  856.     lea   edi, [esi-window_data+draw_data]
  857.     mov   ecx,32/4
  858.     rep   stosd
  859.     popa
  860.  
  861. ; debuggee test
  862.     pushad
  863.     mov  edi, esi
  864.     shl  edi, 5
  865.     mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
  866.     test eax, eax
  867.     jz   .nodebug
  868.     push 8
  869.     pop  ecx
  870.     push dword [0x3000+edi+TASKDATA.pid]   ; PID
  871.     push 2
  872.     call debugger_notify
  873.     pop  ecx
  874.     pop  ecx
  875. .nodebug:
  876.     popad
  877.  
  878.     pusha         ; at 0x80000+
  879.     mov   edi,esi
  880.     shl   edi,8
  881.     add   edi,0x80000
  882.     mov   ecx,256/4
  883.     xor   eax, eax
  884.     rep   stosd
  885.     popa
  886.  
  887.     pusha          ; name to spaces
  888.     mov   edi,esi
  889.     shl   edi,8
  890.     add   edi,0x80000+APPDATA.app_name
  891.     mov   ecx,11
  892.     mov   eax,' '
  893.     rep   stosb
  894.     popa
  895.  
  896.  
  897.   ; activate window
  898.         movzx  eax, word [0xC000 + esi*2]
  899.         cmp    eax, [0x3004]
  900.         jne    .dont_activate
  901.         pushad
  902.  .check_next_window:
  903.         dec    eax
  904.         cmp    eax, 1
  905.         jbe    .nothing_to_activate
  906.         lea    esi, [0xc400+eax*2]
  907.         movzx  edi, word [esi]               ; edi = process
  908.         shl    edi, 5
  909.         cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
  910.         je     .check_next_window
  911.         add    edi, window_data
  912. ; \begin{diamond}[19.09.2006]
  913. ; skip minimized windows
  914.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  915.         jnz    .check_next_window
  916. ; \end{diamond}
  917.         call   waredraw
  918.  .nothing_to_activate:
  919.         popad
  920.  .dont_activate:
  921.  
  922.         push    esi     ; remove hd1 & cd & flp reservation
  923.         shl     esi, 5
  924.         mov     esi, [esi+0x3000+TASKDATA.pid]
  925.         cmp     [hd1_status], esi
  926.         jnz     @f
  927.         mov     [hd1_status], 0
  928. @@:
  929.         cmp     [cd_status], esi
  930.         jnz     @f
  931.         mov     [cd_status], 0
  932. @@:
  933.         cmp     [flp_status], esi
  934.         jnz     @f
  935.         mov     [flp_status], 0
  936. @@:
  937.         pop     esi
  938.  
  939.     pusha ; remove all irq reservations
  940.     mov   eax,esi
  941.     shl   eax, 5
  942.     mov   eax,[eax+0x3000+TASKDATA.pid]
  943.     mov   edi,irq_owner
  944.     mov   ecx,16
  945.   newirqfree:
  946.     scasd
  947.     jne   nofreeirq
  948.     mov   [edi-4],dword 0
  949.   nofreeirq:
  950.     loop   newirqfree
  951.     popa
  952.  
  953.  
  954.     pusha                     ; remove all port reservations
  955.     mov   edx,esi
  956.     shl   edx, 5
  957.     add   edx,0x3000
  958.     mov   edx,[edx+TASKDATA.pid]
  959.  
  960.   rmpr0:
  961.  
  962.     mov   esi,[0x2d0000]
  963.  
  964.     cmp   esi,0
  965.     je    rmpr9
  966.  
  967.   rmpr3:
  968.  
  969.     mov   edi,esi
  970.     shl   edi,4
  971.     add   edi,0x2d0000
  972.  
  973.     cmp   edx,[edi]
  974.     je    rmpr4
  975.  
  976.     dec   esi
  977.     jnz   rmpr3
  978.  
  979.     jmp   rmpr9
  980.  
  981.   rmpr4:
  982.  
  983.     mov   ecx,256
  984.     sub   ecx,esi
  985.     shl   ecx,4
  986.  
  987.     mov   esi,edi
  988.     add   esi,16
  989.     cld
  990.     rep   movsb
  991.  
  992.     dec   dword [0x2d0000]
  993.  
  994.     jmp   rmpr0
  995.  
  996.   rmpr9:
  997.  
  998.     popa
  999.     mov  edi,esi         ; do not run this process slot
  1000.     shl  edi, 5
  1001.     mov  [edi+0x3000 + TASKDATA.state],byte 9
  1002. ; debugger test - terminate all debuggees
  1003.     mov  eax, 2
  1004.     mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
  1005. .xd0:
  1006.     cmp  eax, [0x3004]
  1007.     ja   .xd1
  1008.     cmp  dword [ecx], esi
  1009.     jnz  @f
  1010.     and  dword [ecx], 0
  1011.     pushad
  1012.     xchg eax, ebx
  1013.     mov  eax, 2
  1014.     call sys_system
  1015.     popad
  1016. @@:
  1017.     inc  eax
  1018.     add  ecx, 0x100
  1019.     jmp  .xd0
  1020. .xd1:
  1021. ;    call  systest
  1022.     sti  ; .. and life goes on
  1023.  
  1024.     mov   eax, [dlx]
  1025.     mov   ebx, [dly]
  1026.     mov   ecx, [dlxe]
  1027.     mov   edx, [dlye]
  1028.     call  calculatescreen
  1029.     xor   eax, eax
  1030.     xor   esi, esi
  1031.     call  redrawscreen
  1032.  
  1033.     mov   [0xfff4],byte 0  ; no mouse background
  1034.     mov   [0xfff5],byte 0  ; draw mouse
  1035.  
  1036.     mov   [application_table_status],0
  1037.     mov   esi,process_terminated
  1038.     call  sys_msg_board_str
  1039.  
  1040.     ret
  1041.  
  1042. iglobal
  1043.   boot_sched_1    db   'Building gdt tss pointer',0
  1044.   boot_sched_2    db   'Building IDT table',0
  1045. endg
  1046.  
  1047.  
  1048. build_scheduler:
  1049.  
  1050.         mov    esi,boot_sched_1
  1051.         call   boot_log
  1052.         call   build_process_gdt_tss_pointer
  1053.  
  1054.         mov    esi,boot_sched_2
  1055.         call   boot_log
  1056.         call   build_interrupt_table
  1057.  
  1058.         ret
  1059.  
  1060.