Subversion Repositories Kolibri OS

Rev

Rev 241 | Go to most recent revision | Blame | Compare with Previous | 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:cmp     byte [CPU_fam], 0xF
  218.         jne     noAMDK8
  219.         mov     eax, 0x80000007
  220.         cpuid
  221.         and     edx, 6          ;  voltage ID control & frequency ID control
  222.         cmp     edx, 6
  223.         je      AMDK8M
  224.         mov     eax, 68         ; Athon64
  225.         mov     ebx, 3
  226.         mov     edx, 0xC0010015
  227.         int     0x40
  228.         shr     eax, 24
  229.         and     al, 0x3F
  230.         shr     al, 1
  231.         add     al, 4
  232.         mov     dl, 10
  233.         mul     dl
  234.         mov     cl, al
  235.         ret
  236.  
  237. AMDK8M: mov     eax, 68         ; Athon64-M
  238.         mov     ebx, 3
  239.         mov     edx, 0xC0010042
  240.         int     0x40
  241.         and     al, 0x3F
  242.         shr     al, 1
  243.         add     al, 4
  244.         mov     dl, 10
  245.         mul     dl
  246.         mov     cl, al
  247.         ret
  248.        
  249. noAMD:  cmp     dword [Vendor + 8], 'ntel'      ; Check for International Electronics CPU
  250.         jne     noIntel
  251.         cmp     byte[CPU_fam], 0x0F
  252.         jne     noIntelP4
  253.         cmp     byte [CPU_type], 6
  254.         jne     @f
  255.         mov     eax, 68         ; Pentium M
  256.         mov     ebx, 3
  257.         mov     edx, 0x2A
  258.         int     0x40
  259.         shr     eax, 22
  260.         and     eax, 0x1F
  261.         mov     dl, 10
  262.         mul     dl
  263.         mov     cl, al
  264.         ret
  265. @@:     cmp     byte [CPU_mod], 2
  266.         jae     @f
  267.         mov     eax, 68         ; Pentium 4 / Xeon (model < 2) Willamete
  268.         mov     ebx, 3
  269.         mov     edx, 0x2A
  270.         int     0x40
  271.         shr     eax, 8
  272.         and     eax, 0x0F
  273.         mov     cl, [p4coef + eax]
  274.         ret
  275. @@:     mov     eax, 68         ; Pentium 4 / Xeon (model >= 2) NorthWood
  276.         mov     ebx, 3
  277.         mov     edx, 0x2C
  278.         int     0x40
  279.         shr     eax, 24
  280.         and     eax, 0x1F
  281.         mov     dl, 10
  282.         mul     dl
  283.         mov     cl, al
  284.         ret    
  285. noIntelP4:
  286.         cmp     byte[CPU_fam], 6
  287.         jne     noIntelP6
  288.         mov     eax, 68         ; Pentium Pro / Pentium II / Pentium III
  289.         mov     ebx, 3
  290.         mov     edx, 0x2A
  291.         int     0x40
  292.         shr     eax, 22
  293.         test    al, 0x20
  294.         jz      @f
  295.         or      al, 0x10
  296. @@:     and     eax, 0x1f
  297.  
  298.         cmp     byte[CPU_mod], 0x06 ; ? 7
  299.         ja      @f
  300.         and     al, 0x0f
  301. @@:
  302.         mov     cl, [coppercoeff + eax]
  303.         cmp     byte[CPU_mod], 0x0B
  304.         jb      @f
  305.         mov     cl, [tualatcoeff + eax]
  306.        
  307.         cmp     byte[CPU_mod], 0x0B
  308.         je      @f
  309.         mov     dl, 10          ; model 0x0C - 0x0F - Dothan / Yonah  / Conroe / Merom
  310.         mul     dl
  311.         mov     cl, al
  312.        
  313. @@:     ret
  314.  
  315. noIntel:
  316. noIntelP6:
  317. noAMDK8:
  318.         ret
  319.  
  320. athloncoef      db      110, 115, 120, 125, 50, 55, 60, 65, 70, 75, 80, 85, 90, 95, 100, 105, 120
  321.                 db      190, 120, 200, 130, 135, 140, 210, 150, 220, 160, 165, 170, 180, 230, 240
  322. athlonmcoef:    db      110, 115, 120, 125, 50, 55, 60, 65,  70, 75, 80, 85, 90, 95, 100, 105
  323.                 db      30, 190, 40, 200, 130, 135, 14, 210, 150, 220, 160, 165, 170, 230, 240
  324. athloncoef3     db      45, 50, 40, 55, 25, 30, 60, 35
  325. p4coef          db      160, 170, 180, 190, 200, 210, 220, 230, 80, 90, 100, 110, 120, 130, 140, 150    ; Pentium 4 (Willamete)
  326. 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
  327. 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
  328. else
  329.         display nl, 'Multiplier : no'
  330.         ret
  331. end if
  332. ;---------------------------------------------------------------------
  333. digit_len:
  334.         ; Âû÷èñëåíèå äëèííû ÷èñëà äëÿ ôóíê. 47
  335.         ; ecx - ÷èñëî
  336.         ; ebx - äëèííà * 65536
  337.         pusha
  338.         xor     ebx, ebx
  339.         mov     eax, ecx
  340.         mov     esi, 10
  341. @@:     xor     edx, edx
  342.         inc     ebx
  343.         div     esi
  344.         test    eax, eax
  345.         jnz     @b
  346.         mov     [tdl], ebx
  347.         popa
  348.         mov     ebx, [tdl]
  349.         shl     ebx, 16
  350.         ret
  351. uglobal
  352.         tdl     dd      0
  353. endg
  354.  
  355.  
  356. ;--------------------------------------------------------------------
  357. ftoa:
  358. ; esi - ïðåîáðàçóåìîå ÷èñëî;
  359. ; Data_String - ñòðîêà-ðåçóëüòàò.
  360.  
  361.         pusha
  362.         mov     edi, Data_String
  363.         fninit
  364.         fld     dword [esi]
  365.         fmul    dword [MConst]
  366.         fbstp   [Data_BCD]
  367.         mov     ax, word[Data_BCD + 8]
  368.         cmp     ax, 0xFFFF
  369.         je      @@Overflow
  370.         mov     al, byte[Data_BCD + 9]
  371.         and     al, al
  372.         jz      @@NoSign
  373.         mov     AL,'-'
  374.         stosb
  375. @@NoSign:
  376.         mov     ebx, 8
  377.         mov     ecx, 9
  378.         mov     edx, 18 - 2     ; 2 çíàêà ïîñëå çàïÿòîé
  379. @@NextPair:
  380.         mov     al, byte[Data_BCD + ebx]
  381.         mov     AH,AL
  382.         shr     AL,4
  383.         add     AL,'0'
  384.         stosb
  385.         dec     edx
  386.         jnz     @@N0
  387.         mov     AL,'.'
  388.         stosb
  389. @@N0:   mov     AL,AH
  390.         and     AL,0Fh
  391.         add     AL,'0'
  392.         stosb
  393.         dec     edx
  394.         jnz     @@N1
  395.         mov     AL,'.'
  396.         stosb
  397. @@N1:   dec     ebx
  398.         loop    @@NextPair
  399.         xor     al, al
  400.         stosb
  401.         mov     edi, Data_String
  402.         mov     esi, Data_String
  403.         cmp     byte[esi], '-'
  404.         jne     @@N2
  405.         inc     esi
  406.         inc     edi
  407. @@N2:   mov     ecx, 18+1+1
  408. @@N3:   cmp     byte[esi], '0'
  409.         jne     @@N4
  410.         inc     esi
  411.         loop    @@N3
  412.         jmp     @@Error
  413. @@N4:   rep movsb
  414.         jmp     @@End
  415. @@Overflow:
  416. @@Error:mov     eax, 'ERR'
  417.         stosd
  418. @@End:  popa
  419.         ret
  420. MConst: dd 1.0E2        ; 2 çíàêà ïîñëå çàïÿòîé
  421.  
  422. uglobal
  423.         Data_BCD:       DT ?
  424.         Data_String:    times 20 db 0   ; ASCIIZ ñòîðêà ñ ïðåîáðàçîâàííûì ÷èñëîì
  425. endg
  426. ;--------------------------------------------------------------------
  427. ReservePorts:
  428.         ; In  : ecx - first port, edx - last port
  429.         ; Out : CF = 1 if error
  430.         pusha
  431.         mov     eax, 46
  432.         xor     ebx, ebx
  433.         int     0x40
  434.         clc
  435.         test    eax, eax
  436.         jz      @f
  437.         stc
  438. @@:     popa
  439.         ret
  440.        
  441. FreePorts:
  442.         ; In  : ecx - first port, edx - last port
  443.         pusha
  444.         mov     eax, 46         ; îñâîáîæäàåì 0x295 è 0x296 ïîðòû
  445.         xor     ebx, ebx
  446.         inc     ebx
  447.         int     0x40
  448.         popa
  449.         ret
  450.