Subversion Repositories Kolibri OS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; Ghost Monitor - óòèëèòà (ñòðåññ) òåñòèðîâàíèÿ è ìîíèòîðèíãà ñèñòåìû
  3. ; Copyright (C) 2005, 2006, 2007 Mihailov Ilia (ghost.nsk@mail.ru)
  4. ; All Right Reserved
  5.  
  6. ;--------------------------------------------------------------------
  7. ; Çàãðóçêà ïðîöåññîðà
  8. ; OUT : AL - çàãðóçêà â ïðîöåíòàõ
  9. cpu_usage:
  10.         pusha
  11.         mov     byte [c_u_t], 0
  12.         mov     eax, 18         ; TSC / SEC
  13.         mov     ebx, 5
  14.         int     0x40
  15.         shr     eax, 20
  16.         push    eax
  17.  
  18.         mov     eax, 18         ; IDLE / SEC
  19.         mov     ebx, 4
  20.         int     0x40            ; eax - ïóñòûõ öèêëîâ â ñåêóíäó
  21.         shr     eax, 20         ; eax = IDLE / 1048576
  22.         pop     ebx
  23.         cmp     eax, ebx        ; BUG : time to time ICPS > TSCPS
  24.         jnl     c_u_o
  25.         push    ebx
  26.         xor     edx, edx
  27.         mov     ebx, 100
  28.         mul     ebx             ; eax =(IDLE / 1048576) * 100
  29.  
  30.         xor     edx, edx
  31.         pop     ebx             ; ebx = (TSC/1048576)+1
  32.         inc     ebx
  33.         div     ebx             ; eax = ((IDLE / 1048576) * 100) / ((TSC/1048576)+1)
  34.  
  35.         mov     bl, 100
  36.         sub     bl, al
  37.         cmp     bl, 101
  38.         jnl     c_u_o
  39.         mov     [c_u_t], bl
  40.  
  41. c_u_o:  popa
  42.         mov     al, [c_u_t]
  43.         ret
  44. uglobal
  45.         c_u_t:  db      0
  46. endg
  47. ;--------------------------------------------------------------------
  48. mem_usage:
  49. ; Èñïðîëüçîâàíèå ïàìÿòè
  50. ; OUT : al - ïðîöåòí èñïðîëüçóåìîé ïàìÿòè
  51. display nl, 'Memory usage : '
  52. if (OS_version >= 0x0530)
  53.         display 'yes'
  54.         pusha
  55.         mov     byte [m_u_t], 0
  56.  
  57.         mov     eax, 18         ; full mem
  58.         mov     ebx, 17
  59.         int     0x40
  60.         shr     eax, 10
  61.         push    eax
  62.  
  63.         mov     eax, 18         ; free mem
  64.         mov     ebx, 16
  65.         int     0x40            ; eax - free mem
  66.         shr     eax, 10         ; eax = fmem / 1024
  67.         xor     edx, edx
  68.         mov     ebx, 100
  69.         mul     ebx             ; eax =(free mem / 1024) * 100
  70.  
  71.         xor     edx, edx
  72.         pop     ebx             ; ebx = (full mem/1024)+1
  73.         inc     ebx
  74.         div     ebx             ; eax = ((free mem / 1024) * 100) / ((full mem/1024)+1)
  75.  
  76.         mov     bl, 100
  77.         sub     bl, al
  78.         cmp     bl, 101
  79.         jnb     m_u_o
  80.         mov     [m_u_t], bl
  81.  
  82. m_u_o:  popa
  83.         mov     al, [m_u_t]
  84.         ret
  85. uglobal
  86.         m_u_t:  db      0
  87. endg
  88. else
  89.         display 'no'
  90.         xor     eax, eax
  91.         ret
  92. end if
  93.  
  94. ;#######################################################################
  95. stop_test:
  96.         ; ïîðòÿòñÿ ðåãèñòðû
  97.         display nl, 'Kill process type : '
  98. if (OS_version < 0x0400)
  99.         ; êîä äëÿ Menuet
  100.         display 'Menuet'
  101.         mov     eax, 18
  102.         mov     ebx, 2
  103.         mov     ecx, [test_pid]
  104.         int     0x40
  105.         mov     byte[test_id], 0
  106.         ret
  107.         ; -------------------------------
  108. else if (OS_version >= 0x0400)
  109. if (OS_version < 0x0580)
  110.         display 'old Kolibri'
  111.         ; -- ñëåäóéøèé êîä óáèâàåò ïðîöåññ â Kolibri 4 è ñòàðøå
  112.         mov     ebx, Buf
  113.         xor     ecx, ecx
  114. find_th:mov     eax, 9
  115.         int     0x40
  116.         mov     edx, dword [Buf + 30]
  117.         cmp     edx, dword [test_pid]
  118.         je      kill_t
  119.         inc     ecx
  120.         cmp     ecx, eax                ; eax - êîëè÷åñòâî ïðîöåññîâ
  121.         jle     find_th
  122.         jmp     cl_tinf                 ; ÎØÈÁÊÀ !!!! ïîòîê íå íàéäåí !!!!
  123. kill_t: mov     ebx, 2                  ; óáèâàåì òåñòîâûé ïîòîê
  124.         mov     eax, 18
  125.         int     0x40
  126. cl_tinf:
  127.         mov     byte[test_id], 0
  128.         ret
  129.         uglobal
  130.         Buf:            times   1024 db ?       ; Áóôåð äëÿ íàõîæäåíèÿ PID`à çàïóùåííîãî òåñòà
  131.         endg
  132. else
  133.         ; -------------------------------
  134.         ; êîä äëÿ Kolibri 0.5.8.0 è ñòàðøå
  135.         display 'Kolibri 0.5.8.0'
  136.         mov     eax, 18
  137.         mov     ebx, 18
  138.         mov     ecx, [test_pid]
  139.         int     0x40
  140.         mov     byte [test_id], 0
  141.         ret
  142.         ; -------------------------------
  143. end if
  144. end if
  145. ;#######################################################################
  146.  
  147. ; Âûâîäèò ñòðîêè òåêñòà
  148. ; in : edx - óêàçàòåëü íà mls
  149. ;      ebx - êîîðäèíàòû : X << 16 + Y
  150. show_text:
  151.         mov     eax, 4
  152.         mov     ecx, 0x10000000
  153. @@:
  154.         movzx   esi, byte[edx]
  155.         inc     edx
  156.         int     0x40
  157.         add     ebx, 10
  158.         add     edx, esi
  159.         cmp     byte[edx], -1
  160.         jne     @b
  161.         ret
  162. ;--------------------------------------------------------------------- 
  163. multiplier:
  164. ;--- âû÷èñëåíèå êîýôôèöèåíòà óìíîæåíèÿ -
  165. ; ïîðòèò ðåãèñòðû
  166. ; out : CL = êîýôô.óìíîæåíèÿ * 10, èëè 0
  167.         xor     ecx, ecx
  168. if (OS_version >= 0x0510)
  169.         display nl, 'Multiplier (RDMSR) : yes'
  170.         cmp     dword [Vendor + 8], 'cAMD'      ; Check for Advanced Micro Devices CPU
  171.         jne     noAMD
  172.         cmp     byte [CPU_fam], 5
  173.         jne     noAMDK6
  174.         mov     eax, 68         ; AMD-K6 (p.30)
  175.         mov     ebx, 3
  176.         mov     edx, 0x0C0000087
  177.         int     0x40            ; eax - low dword
  178.         and     eax, 111b
  179.         mov     cl, [athloncoef3 + eax]
  180.         cmp     eax, 6
  181.         jne     @f
  182.         cmp     byte[CPU_mod], 8
  183.         jae     @f
  184.         mov     cl, 20
  185. @@:     ret    
  186.  
  187. noAMDK6:cmp     byte [CPU_fam], 6
  188.         jne     noAMDK7
  189.         cmp     byte [CPU_mod], 5
  190.         jna     @f
  191.         mov     eax, 0x80000007
  192.         cpuid
  193.         and     edx, 6          ;  voltage ID control & frequency ID control
  194.         cmp     edx, 6
  195.         je      AMDK7M
  196. @@:     mov     eax, 68         ; Athlon/AthlonXP
  197.         mov     ebx, 3
  198.         mov     edx, 0x0C0010015
  199.         int     0x40
  200.         mov     ebx, eax
  201.         shr     ebx, 24
  202.         and     ebx, 0x0F
  203.         shr     eax, 20
  204.         jnc     @f
  205.         add     bl, 16
  206. @@:     mov     cl, [athloncoef + ebx]
  207.         ret
  208.  
  209. AMDK7M: mov     eax, 68         ; AthonXP-M
  210.         mov     ebx, 3
  211.         mov     edx, 0xC0010042
  212.         int     0x40
  213.         and     eax, 0x1F
  214.         mov     cl, [athlonmcoef + eax]
  215.         ret
  216.  
  217. noAMDK7:
  218.       cmp       byte [CPU_fam], 0xF
  219.         jne     AMD_Fusion
  220.         mov     eax, 0x80000007
  221.         cpuid
  222.         and     edx, 6          ;  voltage ID control & frequency ID control
  223.         cmp     edx, 6
  224.         je      AMDK8M
  225.         mov     eax, 68         ; Athon64
  226.         mov     ebx, 3
  227.         mov     edx, 0xC0010015
  228.         int     0x40
  229.         shr     eax, 24
  230.         and     al, 0x3F
  231.         shr     al, 1
  232.         add     al, 4
  233.         mov     dl, 10
  234.         mul     dl
  235.         mov     cl, al
  236.         ret
  237.  
  238. AMDK8M: mov     eax, 68         ; Athon64-M
  239.         mov     ebx, 3
  240.         mov     edx, 0xC0010042
  241.         int     0x40
  242.         and     al, 0x3F
  243.         shr     al, 1
  244.         add     al, 4
  245.         mov     dl, 10
  246.         mul     dl
  247.         mov     cl, al
  248.         ret
  249.  
  250. AMD_Fusion:
  251.       cmp       byte [CPU_fam], 0x14
  252.         jne     unknownAMD
  253.         mov     eax, 68         ;
  254.         mov     ebx, 3
  255.         mov     edx, 0xC0010071
  256.         int     0x40
  257.       shr   ebx, 17
  258.         and     ebx, 0x3F
  259.         add     bl, 16  ; Fmax = 100MHz * (edx[54:49] + 10h)
  260.       shl   bl, 3
  261.       mov   edx, ebx
  262.       shl   edx, 2
  263.       add   ebx, edx    ;) that all was just to multiply ebx by 40
  264.       and   eax, 0x1ff
  265.       mov   dl, al
  266.       and   dl, 3       ; dl = 4*fractional part of the divisor
  267.       shr   eax, 4
  268.       inc   eax  
  269.       shl   eax, 2
  270.       or    al, dl      ; ax = 4 * divisor
  271.       xchg  eax, ebx
  272.         div     ebx
  273.         mov     cl, al
  274.         ret
  275.        
  276. noAMD:  cmp     dword [Vendor + 8], 'ntel'      ; Check for International Electronics CPU
  277.         jne     noIntel
  278.         cmp     byte[CPU_fam], 0x0F
  279.         jne     noIntelP4
  280.         cmp     byte [CPU_type], 6
  281.         jne     @f
  282.         mov     eax, 68         ; Pentium M
  283.         mov     ebx, 3
  284.         mov     edx, 0x2A
  285.         int     0x40
  286.         shr     eax, 22
  287.         and     eax, 0x1F
  288.         mov     dl, 10
  289.         mul     dl
  290.         mov     cl, al
  291.         ret
  292. @@:     cmp     byte [CPU_mod], 2
  293.         jae     @f
  294.         mov     eax, 68         ; Pentium 4 / Xeon (model < 2) Willamete
  295.         mov     ebx, 3
  296.         mov     edx, 0x2A
  297.         int     0x40
  298.         shr     eax, 8
  299.         and     eax, 0x0F
  300.         mov     cl, [p4coef + eax]
  301.         ret
  302. @@:     mov     eax, 68         ; Pentium 4 / Xeon (model >= 2) NorthWood
  303.         mov     ebx, 3
  304.         mov     edx, 0x2C
  305.         int     0x40
  306.         shr     eax, 24
  307.         and     eax, 0x1F
  308.         mov     dl, 10
  309.         mul     dl
  310.         mov     cl, al
  311.         ret    
  312. noIntelP4:
  313.         cmp     byte[CPU_fam], 6
  314.         jne     noIntelP6
  315.         mov     eax, 68         ; Pentium Pro / Pentium II / Pentium III
  316.         mov     ebx, 3
  317.         mov     edx, 0x2A
  318.         int     0x40
  319.         shr     eax, 22
  320.         test    al, 0x20
  321.         jz      @f
  322.         or      al, 0x10
  323. @@:     and     eax, 0x1f
  324.  
  325.         cmp     byte[CPU_mod], 0x06 ; ? 7
  326.         ja      @f
  327.         and     al, 0x0f
  328. @@:
  329.         mov     cl, [coppercoeff + eax]
  330.         cmp     byte[CPU_mod], 0x0B
  331.         jb      @f
  332.         mov     cl, [tualatcoeff + eax]
  333.        
  334.         cmp     byte[CPU_mod], 0x0B
  335.         je      @f
  336.         mov     dl, 10          ; model 0x0C - 0x0F - Dothan / Yonah  / Conroe / Merom
  337.         mul     dl
  338.         mov     cl, al
  339.        
  340. @@:     ret
  341.  
  342. noIntel:
  343. noIntelP6:
  344. unknownAMD:
  345.         ret
  346.  
  347. athloncoef      db      110, 115, 120, 125, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 120
  348.                 db      190, 120, 200, 130, 135, 140, 210, 150, 220, 160, 165, 170, 180, 230, 240
  349. athlonmcoef:    db      110, 115, 120, 125, 50, 55, 60, 65,  70, 75, 80, 85, 90, 95, 100, 105
  350.                 db      30, 190, 40, 200, 130, 135, 14, 210, 150, 220, 160, 165, 170, 230, 240
  351. athloncoef3     db      45, 50, 40, 55, 25, 30, 60, 35
  352. p4coef          db      160, 170, 180, 190, 200, 210, 220, 230, 80, 90, 100, 110, 120, 130, 140, 150    ; Pentium 4 (Willamete)
  353. coppercoeff     db       50, 30, 40, 20, 55, 35,  45, 25,  35, 70, 80, 60, 20, 75, 15, 65, 90, 110, 120, 20, 95, 115, 85, 25, 35, 70,  80, 100,  20, 75,  15, 105
  354. tualatcoeff     db      120, 35, 35, 40, 55, 35, 115, 35, 160, 70, 80, 60, 40, 75, 35, 65, 90, 110,  35, 35, 95,  35, 85, 35, 35, 35, 130, 100, 140, 35, 150, 105
  355. else
  356.         display nl, 'Multiplier : no'
  357.         ret
  358. end if
  359. ;---------------------------------------------------------------------
  360. digit_len:
  361.         ; Âû÷èñëåíèå äëèííû ÷èñëà äëÿ ôóíê. 47
  362.         ; ecx - ÷èñëî
  363.         ; ebx - äëèííà * 65536
  364.         pusha
  365.         xor     ebx, ebx
  366.         mov     eax, ecx
  367.         mov     esi, 10
  368. @@:     xor     edx, edx
  369.         inc     ebx
  370.         div     esi
  371.         test    eax, eax
  372.         jnz     @b
  373.         mov     [tdl], ebx
  374.         popa
  375.         mov     ebx, [tdl]
  376.         shl     ebx, 16
  377.         ret
  378. uglobal
  379.         tdl     dd      0
  380. endg
  381.  
  382.  
  383. ;--------------------------------------------------------------------
  384. ftoa:
  385. ; esi - ïðåîáðàçóåìîå ÷èñëî;
  386. ; Data_String - ñòðîêà-ðåçóëüòàò.
  387.  
  388.         pusha
  389.         mov     edi, Data_String
  390.         fninit
  391.         fld     dword [esi]
  392.         fmul    dword [MConst]
  393.         fbstp   [Data_BCD]
  394.         mov     ax, word[Data_BCD + 8]
  395.         cmp     ax, 0xFFFF
  396.         je      @@Overflow
  397.         mov     al, byte[Data_BCD + 9]
  398.         and     al, al
  399.         jz      @@NoSign
  400.         mov     AL,'-'
  401.         stosb
  402. @@NoSign:
  403.         mov     ebx, 8
  404.         mov     ecx, 9
  405.         mov     edx, 18 - 2     ; 2 çíàêà ïîñëå çàïÿòîé
  406. @@NextPair:
  407.         mov     al, byte[Data_BCD + ebx]
  408.         mov     AH,AL
  409.         shr     AL,4
  410.         add     AL,'0'
  411.         stosb
  412.         dec     edx
  413.         jnz     @@N0
  414.         mov     AL,'.'
  415.         stosb
  416. @@N0:   mov     AL,AH
  417.         and     AL,0Fh
  418.         add     AL,'0'
  419.         stosb
  420.         dec     edx
  421.         jnz     @@N1
  422.         mov     AL,'.'
  423.         stosb
  424. @@N1:   dec     ebx
  425.         loop    @@NextPair
  426.         xor     al, al
  427.         stosb
  428.         mov     edi, Data_String
  429.         mov     esi, Data_String
  430.         cmp     byte[esi], '-'
  431.         jne     @@N2
  432.         inc     esi
  433.         inc     edi
  434. @@N2:   mov     ecx, 18+1+1
  435. @@N3:   cmp     byte[esi], '0'
  436.         jne     @@N4
  437.         inc     esi
  438.         loop    @@N3
  439.         jmp     @@Error
  440. @@N4:   rep movsb
  441.         jmp     @@End
  442. @@Overflow:
  443. @@Error:mov     eax, 'ERR'
  444.         stosd
  445. @@End:  popa
  446.         ret
  447. MConst: dd 1.0E2        ; 2 çíàêà ïîñëå çàïÿòîé
  448.  
  449. uglobal
  450.         Data_BCD:       DT ?
  451.         Data_String:    times 20 db 0   ; ASCIIZ ñòîðêà ñ ïðåîáðàçîâàííûì ÷èñëîì
  452. endg
  453. ;--------------------------------------------------------------------
  454. ReservePorts:
  455.         ; In  : ecx - first port, edx - last port
  456.         ; Out : CF = 1 if error
  457.         pusha
  458.         mov     eax, 46
  459.         xor     ebx, ebx
  460.         int     0x40
  461.         clc
  462.         test    eax, eax
  463.         jz      @f
  464.         stc
  465. @@:     popa
  466.         ret
  467.        
  468. FreePorts:
  469.         ; In  : ecx - first port, edx - last port
  470.         pusha
  471.         mov     eax, 46         ; îñâîáîæäàåì 0x295 è 0x296 ïîðòû
  472.         xor     ebx, ebx
  473.         inc     ebx
  474.         int     0x40
  475.         popa
  476.         ret
  477.