Subversion Repositories Kolibri OS

Rev

Rev 168 | Rev 183 | 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,e18, except_19
  176.     times 12 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
  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.  
  302. .no_SSE:
  303.         fnsave [eax]
  304.         mov ebx, [CURRENT_TASK]
  305.         mov [fpu_owner], ebx
  306.         shl ebx, 8
  307.         cmp dword [ebx+PROC_BASE+APPDATA.fpu_init], 0
  308.         je .ready
  309.  
  310.         mov eax, [ebx+PROC_BASE+APPDATA.fpu_state]
  311.         frstor [eax]
  312.         restore_ring3_context
  313.         iret
  314.  
  315. .init:
  316.         fninit                      ;­ ¬ ­¥ ­ã¦­ë ­¥¬ áª¨à®¢ ­­ë¥ ¨áª«î祭¨ï
  317. .ready:
  318.         mov dword [ebx+PROC_BASE+APPDATA.fpu_init], 1
  319. .exit:
  320.         restore_ring3_context
  321.         iret
  322.  
  323. iglobal
  324.   fpu_owner dd 1
  325.  endg
  326.  
  327.  
  328. writehex:
  329.       pusha
  330.  
  331.       mov  edi, [write_error_to]
  332.       mov  esi, 8
  333.     @@:
  334.       mov  ecx, eax
  335.       and  ecx, 0xf
  336.  
  337.       mov  cl,[ecx+hexletters]
  338.       mov  [edi],cl
  339.       dec  edi
  340.  
  341.       shr  eax,4
  342.       dec  esi
  343.       jnz  @b
  344.  
  345.       popa
  346.       ret
  347.  
  348. iglobal
  349.   hexletters  db '0123456789ABCDEF'
  350.  
  351.   error_interrupt         dd  -1
  352.  
  353.   process_error  db 'K : Process - forced terminate INT: 00000000',13,10,0
  354.   process_pid    db 'K : Process - forced terminate PID: 00000000',13,10,0
  355.   process_eip    db 'K : Process - forced terminate EIP: 00000000',13,10,0
  356.   system_error   db 'K : Kernel error',13,10,0
  357. endg
  358.  
  359. uglobal
  360.   write_error_to  dd  0x0
  361. endg
  362.  
  363. show_error_parameters:
  364.  
  365.         mov    [write_error_to],process_pid+43
  366.         mov    eax,[0x3000]
  367.         shl    eax, 5
  368.         mov    eax,[0x3000+TASKDATA.pid+eax]
  369.         call   writehex
  370.  
  371.         mov    [write_error_to],process_error+43
  372.         mov    eax,[error_interrupt]
  373.         call   writehex
  374.  
  375.         cmp    dword [esp+4+4], os_code ; CS
  376.         jnz    @f
  377.         mov    esi,system_error
  378.         call   sys_msg_board_str
  379.       @@:
  380.         mov    eax, [esp+4] ; EIP
  381.  
  382.         mov    [write_error_to],process_eip+43
  383.         call   writehex
  384.  
  385.         mov    esi,process_error
  386.         call   sys_msg_board_str
  387.  
  388.         mov    esi,process_pid
  389.         call   sys_msg_board_str
  390.  
  391.         mov    esi,process_eip
  392.         call   sys_msg_board_str
  393.  
  394.         ret
  395.  
  396.  
  397.  
  398. ; irq1  ->  hid/keyboard.inc
  399.  
  400.  
  401. macro irqh [num]
  402. {
  403.   forward
  404.   p_irq#num :
  405.      save_ring3_context
  406.      mov   edi, num
  407.      jmp   irq_c
  408. }
  409.  
  410. irqh 2,5,7,8,9,10,11
  411.  
  412.  irq_c:
  413.      mov   ax, os_data
  414.      mov   ds, ax
  415.      mov   es, ax
  416.      call  irqhandler
  417.      restore_ring3_context
  418.      iret
  419.  
  420. p_irq6:
  421.      save_ring3_context
  422.      mov   ax, os_data
  423.      mov   ds, ax
  424.      mov   es, ax
  425.      call  fdc_irq
  426.      call  ready_for_next_irq
  427.      restore_ring3_context
  428.      iret
  429.  
  430. p_irq3:
  431.      save_ring3_context
  432.      mov   ax, os_data
  433.      mov   ds, ax
  434.      mov   es, ax
  435.      cmp   [com2_mouse_detected],0
  436.      je    old_irq3_handler
  437.      call  check_mouse_data_com2
  438.      jmp   p_irq3_1
  439.  old_irq3_handler:
  440.      mov   edi,3
  441.      call  irqhandler
  442.   p_irq3_1:
  443.      restore_ring3_context
  444.      iret
  445.  
  446. p_irq4:
  447.      save_ring3_context
  448.      mov   ax, os_data
  449.      mov   ds, ax
  450.      mov   es, ax
  451.      cmp   [com1_mouse_detected],0
  452.      je    old_irq4_handler
  453.      call  check_mouse_data_com1
  454.      jmp   p_irq4_1
  455.  old_irq4_handler:
  456.      mov   edi,4
  457.      call  irqhandler
  458.   p_irq4_1:
  459.      restore_ring3_context
  460.      iret
  461.  
  462. p_irq12:
  463.      save_ring3_context
  464.      mov   ax, os_data
  465.      mov   ds, ax
  466.      mov   es, ax
  467.      call  check_mouse_data_ps2
  468.      restore_ring3_context
  469.      iret
  470.  
  471. p_irq14:
  472.         save_ring3_context
  473.         mov     ax, os_data
  474.         mov     ds, ax
  475.         mov     es, ax
  476.         call    [irq14_func]
  477.         call    ready_for_next_irq_1
  478.         restore_ring3_context
  479.         iret
  480. p_irq15:
  481.         save_ring3_context
  482.         mov     ax, os_data
  483.         mov     ds, ax
  484.         mov     es, ax
  485.         call    [irq15_func]
  486.         call    ready_for_next_irq_1
  487.         restore_ring3_context
  488.         iret
  489.  
  490. ready_for_next_irq:
  491.      mov    [check_idle_semaphore],5
  492.      mov   al, 0x20
  493.      out   0x20, al
  494.      ret
  495.  
  496. ready_for_next_irq_1:
  497.      mov    [check_idle_semaphore],5
  498.      mov   al, 0x20
  499.      out    0xa0,al
  500.      out   0x20, al
  501.      ret
  502.  
  503. irqD:
  504.      save_ring3_context
  505.      mov   ax, os_data
  506.      mov   ds, ax
  507.      mov   es, ax
  508.  
  509.      mov   dx,0xf0
  510.      mov   al,0
  511.      out   dx,al
  512.  
  513.      mov   dx,0xa0
  514.      mov   al,0x20
  515.      out   dx,al
  516.      mov   dx,0x20
  517.      out   dx,al
  518.  
  519.      restore_ring3_context
  520.  
  521.      iret
  522.  
  523.  
  524. irqhandler:
  525.  
  526.      push   edi
  527.  
  528.      mov    esi,edi          ; 1
  529.      shl    esi,6            ; 1
  530.      add    esi,irq00read    ; 1
  531.      shl    edi,12           ; 1
  532.      add    edi,0x2E0000
  533.      mov    ecx,16
  534.  
  535.      mov    [check_idle_semaphore],5
  536.  
  537.    irqnewread:
  538.      dec    ecx
  539.      js     irqover
  540.  
  541.      mov    dx,[esi]         ; 2+
  542.  
  543.      cmp    dx,0             ; 1
  544.      jz     irqover
  545.      cmp    [esi+3],byte 1   ; 2     ; byte read
  546.      jne    noirqbyte        ; 4-11
  547.  
  548.      in     al,dx
  549.  
  550.      mov    edx,[edi]
  551.      cmp    edx,4000
  552.      je     irqfull
  553.      mov    ebx,edi
  554.      add    ebx,0x10
  555.      add    ebx,edx
  556.      mov    [ebx],al
  557.      inc    edx
  558.      mov    [edi],edx
  559.  
  560.      add    esi,4
  561.      jmp    irqnewread
  562.  
  563.    noirqbyte:
  564.  
  565.  
  566.      cmp    [esi+3],byte 2     ; word read
  567.      jne    noirqword
  568.  
  569.      in     ax,dx
  570.  
  571.      mov    edx,[edi]
  572.      cmp    edx,4000
  573.      je     irqfull
  574.      mov    ebx,edi
  575.      add    ebx,0x10
  576.      add    ebx,edx
  577.      mov    [ebx],ax
  578.      add    edx,2
  579.      mov    [edi],edx
  580.      add    esi,4
  581.      jmp    irqnewread
  582.  
  583.    noirqword:
  584.    irqfull:
  585.    irqover:
  586.  
  587.      mov    al,0x20            ; ready for next irq
  588.      out    0x20,al
  589.  
  590.      pop    ebx
  591.      cmp    ebx,7
  592.      jbe    noa0
  593.      out    0xa0,al
  594.    noa0:
  595.  
  596.      ret
  597.  
  598.  
  599.  
  600. set_application_table_status:
  601.         push eax
  602.  
  603.         mov  eax,[0x3000]
  604.         shl  eax, 5
  605.         add  eax,0x3000+TASKDATA.pid
  606.         mov  eax,[eax]
  607.  
  608.         mov  [application_table_status],eax
  609.  
  610.         pop  eax
  611.  
  612.         ret
  613.  
  614.  
  615. clear_application_table_status:
  616.         push eax
  617.  
  618.         mov  eax,[0x3000]
  619.         shl  eax, 5
  620.         add  eax,0x3000+TASKDATA.pid
  621.         mov  eax,[eax]
  622.  
  623.         cmp  eax,[application_table_status]
  624.         jne  apptsl1
  625.         mov  [application_table_status],0
  626.       apptsl1:
  627.  
  628.         pop  eax
  629.  
  630.         ret
  631.  
  632.  
  633.  
  634. sys_resize_app_memory:
  635.         ; eax = 1 - resize
  636.         ;     ebx = new amount of memory
  637.  
  638.         cmp    eax,1
  639.         jne    .no_application_mem_resize
  640.  
  641.         stdcall new_mem_resize, ebx
  642.         mov [esp+36], eax
  643.         ret
  644.  
  645. .no_application_mem_resize:
  646.         ret
  647.  
  648.  
  649.  
  650. get_app_params:
  651.  
  652.     push eax
  653.  
  654.     cmp  [0x90000+6],word '00'
  655.     jne  no_00_header
  656.  
  657.     mov  eax,[0x90000+12]
  658.     mov  [app_start],eax
  659.     mov  eax,[0x90000+16]
  660.     mov  [app_i_end],eax
  661.     mov  eax,[0x90000+20]
  662.     mov  [app_mem],eax
  663. ; \begin{diamond}[20.08.2006]
  664. ; sanity check (functions 19,58 load app_i_end bytes and that must
  665. ; fit in allocated memory to prevent kernel faults)
  666.     cmp  eax,[app_i_end]
  667.     jb   no_01_header
  668. ; \end{diamond}[20.08.2006]
  669.     shr  eax,1
  670.     sub  eax,0x10
  671.     mov  [app_esp],eax
  672.     mov  eax,[0x90000+24]
  673.     mov  [app_i_param],eax
  674.     mov  [app_i_icon],dword 0
  675.  
  676.     pop  eax
  677.     clc
  678.     ret
  679.  
  680.   no_00_header:
  681.  
  682.  
  683.     cmp  [0x90000+6],word '01'
  684.     jne  no_01_header
  685.  
  686.     mov  eax,[0x90000+12]
  687.     mov  [app_start],eax
  688.     mov  eax,[0x90000+16]
  689.     mov  [app_i_end],eax
  690.     mov  eax,[0x90000+20]
  691.     mov  [app_mem],eax
  692. ; \begin{diamond}[20.08.2006]
  693.     cmp  eax,[app_i_end]
  694.     jb   no_01_header
  695. ; \end{diamond}[20.08.2006]
  696.     mov  eax,[0x90000+24]
  697.     mov  [app_esp],eax
  698.     mov  eax,[0x90000+28]
  699.     mov  [app_i_param],eax
  700.     mov  eax,[0x90000+32]
  701.     mov  [app_i_icon],eax
  702.  
  703.     pop  eax
  704.     clc
  705.     ret
  706.  
  707.    no_01_header:
  708.  
  709.     pop  eax
  710.     stc
  711.     ret
  712.  
  713.  
  714. uglobal
  715.   new_process_place  dd  0x0
  716.   app_start    dd  0x0
  717.   app_i_end    dd  0x0
  718.   app_mem      dd  0x0
  719.   app_esp      dd  0x0
  720.   app_i_param  dd  0x0
  721.   app_i_icon   dd  0x0
  722. ;  app_mem_pos  dd  0x0
  723.   appl_path        dd 0x0
  724.   appl_path_size   dd 0x0
  725. endg
  726.  
  727.  
  728. sys_threads:
  729.  
  730. ; eax=1 create thread
  731. ;
  732. ;   ebx=thread start
  733. ;   ecx=thread stack value
  734. ;
  735. ; on return : eax = pid
  736. jmp new_sys_threads
  737.  
  738. iglobal
  739.   process_terminating   db 'K : Process - terminating',13,10,0
  740.   process_terminated    db 'K : Process - done',13,10,0
  741. endg
  742.  
  743.  
  744. terminate: ; terminate application
  745.     push   esi
  746.     mov    esi,process_terminating
  747.     call   sys_msg_board_str
  748.     pop    esi
  749.  
  750. @@:
  751.     cli
  752.     cmp   [application_table_status],0
  753.     je    term9
  754.     sti
  755.     call  change_task
  756.     jmp   @b
  757.   term9:
  758.  
  759.     call  set_application_table_status
  760.  
  761.     mov    eax,esi
  762.  
  763.     pushad
  764.     shl   eax,8
  765.     mov   eax,[PROC_BASE+eax+0xB8]
  766.     stdcall destroy_app_space, eax
  767.     popad
  768.  
  769.     cmp   [fpu_owner],esi   ; if user fpu last -> fpu user = 1
  770.     jne   fpu_ok_1
  771.     mov   [fpu_owner],1
  772.   fpu_ok_1:
  773.  
  774.     mov   [0xf400],byte 0           ; empty keyboard buffer
  775.     mov   [0xf500],byte 0           ; empty button buffer
  776.  
  777.  
  778. ; remove defined hotkeys
  779.         mov     eax, hotkey_list
  780. .loop:
  781.         cmp     [eax+8], esi
  782.         jnz     .cont
  783.         mov     ecx, [eax]
  784.         jecxz   @f
  785.         push    dword [eax+12]
  786.         pop     dword [ecx+12]
  787. @@:
  788.         mov     ecx, [eax+12]
  789.         push    dword [eax]
  790.         pop     dword [ecx]
  791.         xor     ecx, ecx
  792.         mov     [eax], ecx
  793.         mov     [eax+4], ecx
  794.         mov     [eax+8], ecx
  795.         mov     [eax+12], ecx
  796. .cont:
  797.         add     eax, 16
  798.         cmp     eax, hotkey_list+256*16
  799.         jb      .loop
  800. ; remove hotkeys in buffer
  801.         mov     eax, hotkey_buffer
  802. .loop2:
  803.         cmp     [eax], esi
  804.         jnz     .cont2
  805.         and     dword [eax+4], 0
  806.         and     dword [eax], 0
  807. .cont2:
  808.         add     eax, 8
  809.         cmp     eax, hotkey_buffer+120*8
  810.         jb      .loop2
  811.  
  812.     mov   ecx,esi                 ; remove buttons
  813.   bnewba2:
  814.     mov   edi,[0xfe88]
  815.     mov   eax,edi
  816.     cld
  817.     movzx ebx,word [edi]
  818.     inc   bx
  819.   bnewba:
  820.     dec   bx
  821.     jz    bnmba
  822.     add   eax,0x10
  823.     cmp   cx,[eax]
  824.     jnz   bnewba
  825.     pusha
  826.     mov   ecx,ebx
  827.     inc   ecx
  828.     shl   ecx,4
  829.     mov   ebx,eax
  830.     add   eax,0x10
  831.     call  memmove
  832.     dec   dword [edi]
  833.     popa
  834.     jmp   bnewba2
  835.   bnmba:
  836.  
  837.     pusha     ; save window coordinates for window restoring
  838.     cld
  839.     shl   esi,5
  840.     add   esi,window_data
  841.     mov   eax,[esi+WDATA.box.left]
  842.     mov   [dlx],eax
  843.     add   eax,[esi+WDATA.box.width]
  844.     mov   [dlxe],eax
  845.     mov   eax,[esi+WDATA.box.top]
  846.     mov   [dly],eax
  847.     add   eax,[esi+WDATA.box.height]
  848.     mov   [dlye],eax
  849.  
  850.     xor   eax, eax
  851.     mov   [esi+WDATA.box.left],eax
  852.     mov   [esi+WDATA.box.width],eax
  853.     mov   [esi+WDATA.box.top],eax
  854.     mov   [esi+WDATA.box.height],eax
  855.     mov   [esi+WDATA.cl_workarea],eax
  856.     mov   [esi+WDATA.cl_titlebar],eax
  857.     mov   [esi+WDATA.cl_frames],eax
  858.     mov   dword [esi+WDATA.reserved],eax ; clear all flags: wstate, redraw, wdrawn
  859.     lea   edi, [esi-window_data+draw_data]
  860.     mov   ecx,32/4
  861.     rep   stosd
  862.     popa
  863.  
  864. ; debuggee test
  865.     pushad
  866.     mov  edi, esi
  867.     shl  edi, 5
  868.     mov  eax, [0x80000+edi*8+APPDATA.debugger_slot]
  869.     test eax, eax
  870.     jz   .nodebug
  871.     push 8
  872.     pop  ecx
  873.     push dword [0x3000+edi+TASKDATA.pid]   ; PID
  874.     push 2
  875.     call debugger_notify
  876.     pop  ecx
  877.     pop  ecx
  878. .nodebug:
  879.     popad
  880.  
  881.     pusha         ; at 0x80000+
  882.     mov   edi,esi
  883.     shl   edi,8
  884.     add   edi,0x80000
  885.     mov   ecx,256/4
  886.     xor   eax, eax
  887.     rep   stosd
  888.     popa
  889.  
  890.     pusha          ; name to spaces
  891.     mov   edi,esi
  892.     shl   edi,8
  893.     add   edi,0x80000+APPDATA.app_name
  894.     mov   ecx,11
  895.     mov   eax,' '
  896.     rep   stosb
  897.     popa
  898.  
  899.  
  900.   ; activate window
  901.         movzx  eax, word [0xC000 + esi*2]
  902.         cmp    eax, [0x3004]
  903.         jne    .dont_activate
  904.         pushad
  905.  .check_next_window:
  906.         dec    eax
  907.         cmp    eax, 1
  908.         jbe    .nothing_to_activate
  909.         lea    esi, [0xc400+eax*2]
  910.         movzx  edi, word [esi]               ; edi = process
  911.         shl    edi, 5
  912.         cmp    [0x3000 + edi + TASKDATA.state], byte 9  ; skip dead slots
  913.         je     .check_next_window
  914.         add    edi, window_data
  915. ; \begin{diamond}[19.09.2006]
  916. ; skip minimized windows
  917.         test   [edi + WDATA.fl_wstate], WSTATE_MINIMIZED
  918.         jnz    .check_next_window
  919. ; \end{diamond}
  920.         call   waredraw
  921.  .nothing_to_activate:
  922.         popad
  923.  .dont_activate:
  924.  
  925.         push    esi     ; remove hd1 & cd & flp reservation
  926.         shl     esi, 5
  927.         mov     esi, [esi+0x3000+TASKDATA.pid]
  928.         cmp     [hd1_status], esi
  929.         jnz     @f
  930.         mov     [hd1_status], 0
  931. @@:
  932.         cmp     [cd_status], esi
  933.         jnz     @f
  934.         mov     [cd_status], 0
  935. @@:
  936.         cmp     [flp_status], esi
  937.         jnz     @f
  938.         mov     [flp_status], 0
  939. @@:
  940.         pop     esi
  941.  
  942.     pusha ; remove all irq reservations
  943.     mov   eax,esi
  944.     shl   eax, 5
  945.     mov   eax,[eax+0x3000+TASKDATA.pid]
  946.     mov   edi,irq_owner
  947.     mov   ecx,16
  948.   newirqfree:
  949.     scasd
  950.     jne   nofreeirq
  951.     mov   [edi-4],dword 0
  952.   nofreeirq:
  953.     loop   newirqfree
  954.     popa
  955.  
  956.  
  957.     pusha                     ; remove all port reservations
  958.     mov   edx,esi
  959.     shl   edx, 5
  960.     add   edx,0x3000
  961.     mov   edx,[edx+TASKDATA.pid]
  962.  
  963.   rmpr0:
  964.  
  965.     mov   esi,[0x2d0000]
  966.  
  967.     cmp   esi,0
  968.     je    rmpr9
  969.  
  970.   rmpr3:
  971.  
  972.     mov   edi,esi
  973.     shl   edi,4
  974.     add   edi,0x2d0000
  975.  
  976.     cmp   edx,[edi]
  977.     je    rmpr4
  978.  
  979.     dec   esi
  980.     jnz   rmpr3
  981.  
  982.     jmp   rmpr9
  983.  
  984.   rmpr4:
  985.  
  986.     mov   ecx,256
  987.     sub   ecx,esi
  988.     shl   ecx,4
  989.  
  990.     mov   esi,edi
  991.     add   esi,16
  992.     cld
  993.     rep   movsb
  994.  
  995.     dec   dword [0x2d0000]
  996.  
  997.     jmp   rmpr0
  998.  
  999.   rmpr9:
  1000.  
  1001.     popa
  1002.     mov  edi,esi         ; do not run this process slot
  1003.     shl  edi, 5
  1004.     mov  [edi+0x3000 + TASKDATA.state],byte 9
  1005. ; debugger test - terminate all debuggees
  1006.     mov  eax, 2
  1007.     mov  ecx, 0x80000+2*0x100+APPDATA.debugger_slot
  1008. .xd0:
  1009.     cmp  eax, [0x3004]
  1010.     ja   .xd1
  1011.     cmp  dword [ecx], esi
  1012.     jnz  @f
  1013.     and  dword [ecx], 0
  1014.     pushad
  1015.     xchg eax, ebx
  1016.     mov  eax, 2
  1017.     call sys_system
  1018.     popad
  1019. @@:
  1020.     inc  eax
  1021.     add  ecx, 0x100
  1022.     jmp  .xd0
  1023. .xd1:
  1024. ;    call  systest
  1025.     sti  ; .. and life goes on
  1026.  
  1027.     mov   eax, [dlx]
  1028.     mov   ebx, [dly]
  1029.     mov   ecx, [dlxe]
  1030.     mov   edx, [dlye]
  1031.     call  calculatescreen
  1032.     xor   eax, eax
  1033.     xor   esi, esi
  1034.     call  redrawscreen
  1035.  
  1036.     mov   [0xfff4],byte 0  ; no mouse background
  1037.     mov   [0xfff5],byte 0  ; draw mouse
  1038.  
  1039.     mov   [application_table_status],0
  1040.     mov   esi,process_terminated
  1041.     call  sys_msg_board_str
  1042.  
  1043.     ret
  1044.  
  1045. iglobal
  1046.   boot_sched_1    db   'Building gdt tss pointer',0
  1047.   boot_sched_2    db   'Building IDT table',0
  1048. endg
  1049.  
  1050.  
  1051. build_scheduler:
  1052.  
  1053.         mov    esi,boot_sched_1
  1054.         call   boot_log
  1055.         call   build_process_gdt_tss_pointer
  1056.  
  1057.         mov    esi,boot_sched_2
  1058.         call   boot_log
  1059.         call   build_interrupt_table
  1060.  
  1061.         ret
  1062.  
  1063.