Subversion Repositories Kolibri OS

Rev

Rev 223 | Rev 313 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;--------------------------------------------------------------------
  2. ; Çàãðóçêà ïðîöåññîðà
  3. ; OUT : AL - çàãðóçêà â ïðîöåíòàõ
  4. cpu_usage:
  5.         pusha
  6.         mov     byte [c_u_t], 0
  7.         mov     eax, 18         ; TSC / SEC
  8.         mov     ebx, 5
  9.         int     0x40
  10.         shr     eax, 20
  11.         push    eax
  12.  
  13.         mov     eax, 18         ; IDLE / SEC
  14.         mov     ebx, 4
  15.         int     0x40            ; eax - ïóñòûõ öèêëîâ â ñåêóíäó
  16.         shr     eax, 20         ; eax = IDLE / 1048576
  17.         pop     ebx
  18.         cmp     eax, ebx        ; BUG : time to time ICPS > TSCPS
  19.         jnl     c_u_o
  20.         push    ebx
  21.         xor     edx, edx
  22.         mov     ebx, 100
  23.         mul     ebx             ; eax =(IDLE / 1048576) * 100
  24.  
  25.         xor     edx, edx
  26.         pop     ebx             ; ebx = (TSC/1048576)+1
  27.         inc     ebx
  28.         div     ebx             ; eax = ((IDLE / 1048576) * 100) / ((TSC/1048576)+1)
  29.  
  30.         mov     bl, 100
  31.         sub     bl, al
  32.         cmp     bl, 101
  33.         jnl     c_u_o
  34.         mov     [c_u_t], bl
  35.  
  36. c_u_o:  popa
  37.         mov     al, [c_u_t]
  38.         ret
  39. uglobal
  40.         c_u_t:  db      0
  41. endg
  42. ;--------------------------------------------------------------------
  43. mem_usage:
  44. ; Èñïðîëüçîâàíèå ïàìÿòè
  45. ; OUT : al - ïðîöåòí èñïðîëüçóåìîé ïàìÿòè
  46. display nl, 'Memory usage : '
  47. if (OS_version >= 0x0530)
  48.         display 'yes'
  49.         pusha
  50.         mov     byte [m_u_t], 0
  51.  
  52.         mov     eax, 18         ; full mem
  53.         mov     ebx, 17
  54.         int     0x40
  55.         shr     eax, 10
  56.         push    eax
  57.  
  58.         mov     eax, 18         ; free mem
  59.         mov     ebx, 16
  60.         int     0x40            ; eax - free mem
  61.         shr     eax, 10         ; eax = fmem / 1024
  62.         xor     edx, edx
  63.         mov     ebx, 100
  64.         mul     ebx             ; eax =(free mem / 1024) * 100
  65.  
  66.         xor     edx, edx
  67.         pop     ebx             ; ebx = (full mem/1024)+1
  68.         inc     ebx
  69.         div     ebx             ; eax = ((free mem / 1024) * 100) / ((full mem/1024)+1)
  70.  
  71.         mov     bl, 100
  72.         sub     bl, al
  73.         cmp     bl, 101
  74.         jnb     m_u_o
  75.         mov     [m_u_t], bl
  76.  
  77. m_u_o:  popa
  78.         mov     al, [m_u_t]
  79.         ret
  80. uglobal
  81.         m_u_t:  db      0
  82. endg
  83. else
  84.         display 'no'
  85.         xor     eax, eax
  86.         ret
  87. end if
  88.  
  89. ;#######################################################################
  90. stop_test:
  91.         ; ïîðòÿòñÿ ðåãèñòðû
  92.         display nl, 'Kill process type : '
  93. if (OS_version < 0x0400)
  94.         ; êîä äëÿ Menuet
  95.         display 'Menuet'
  96.         mov     eax, 18
  97.         mov     ebx, 2
  98.         mov     ecx, [test_pid]
  99.         int     0x40
  100.         mov     byte[test_id], 0
  101.         ret
  102.         ; -------------------------------
  103. else if (OS_version >= 0x0400)
  104. if (OS_version < 0x0580)
  105.         display 'old Kolibri'
  106.         ; -- ñëåäóéøèé êîä óáèâàåò ïðîöåññ â Kolibri 4 è ñòàðøå
  107.         mov     ebx, Buf
  108.         xor     ecx, ecx
  109. find_th:mov     eax, 9
  110.         int     0x40
  111.         mov     edx, dword [Buf + 30]
  112.         cmp     edx, dword [test_pid]
  113.         je      kill_t
  114.         inc     ecx
  115.         cmp     ecx, eax                ; eax - êîëè÷åñòâî ïðîöåññîâ
  116.         jle     find_th
  117.         jmp     cl_tinf                 ; ÎØÈÁÊÀ !!!! ïîòîê íå íàéäåí !!!!
  118. kill_t: mov     ebx, 2                  ; óáèâàåì òåñòîâûé ïîòîê
  119.         mov     eax, 18
  120.         int     0x40
  121. cl_tinf:
  122.         mov     byte[test_id], 0
  123.         ret
  124.         uglobal
  125.         Buf:            times   1024 db ?       ; Áóôåð äëÿ íàõîæäåíèÿ PID`à çàïóùåííîãî òåñòà
  126.         endg
  127. else
  128.         ; -------------------------------
  129.         ; êîä äëÿ Kolibri 0.5.8.0 è ñòàðøå
  130.         display 'Kolibri 0.5.8.0'
  131.         mov     eax, 18
  132.         mov     ebx, 18
  133.         mov     ecx, [test_pid]
  134.         int     0x40
  135.         mov     byte [test_id], 0
  136.         ret
  137.         ; -------------------------------
  138. end if
  139. end if
  140. ;#######################################################################
  141.  
  142. ; Âûâîäèò ñòðîêè òåêñòà
  143. ; in : edx - óêàçàòåëü íà mls
  144. ;      ebx - êîîðäèíàòû : X << 16 + Y
  145. show_text:
  146.         mov     eax, 4
  147.         mov     ecx, 0x10000000
  148. @@:
  149.         movzx   esi, byte[edx]
  150.         inc     edx
  151.         int     0x40
  152.         add     ebx, 10
  153.         add     edx, esi
  154.         cmp     byte[edx], -1
  155.         jne     @b
  156.         ret
  157. ;--------------------------------------------------------------------- 
  158. multiplier:
  159. ;--- âû÷èñëåíèå êîýôôèöèåíòà óìíîæåíèÿ -
  160. ; ïîðòèò ðåãèñòðû
  161. ; out : CL = êîýôô.óìíîæåíèÿ * 10, èëè 0
  162.         xor     ecx, ecx
  163. if (OS_version >= 0x0510)
  164.         display nl, 'Multiplier (RDMSR) : yes'
  165.         cmp     dword [Vendor + 8], 'cAMD'      ; Check for Advanced Micro Devices CPU
  166.         jne     noAMD
  167.         cmp     byte [CPU_fam], 5
  168.         jne     noAMDK6
  169.         mov     eax, 68         ; AMD-K6 (p.30)
  170.         mov     ebx, 3
  171.         mov     edx, 0x0C0000087
  172.         int     0x40            ; eax - low dword
  173.         and     eax, 111b
  174.         mov     cl, [athloncoef3 + eax]
  175.         cmp     eax, 6
  176.         jne     @f
  177.         cmp     byte[CPU_mod], 8
  178.         jae     @f
  179.         mov     cl, 20
  180. @@:     ret    
  181.  
  182. noAMDK6:cmp     byte [CPU_fam], 6
  183.         jne     noAMDK7
  184.         cmp     byte [CPU_mod], 5
  185.         jna     @f
  186.         mov     eax, 0x80000007
  187.         cpuid
  188.         and     edx, 6          ;  voltage ID control & frequency ID control
  189.         cmp     edx, 6
  190.         je      AMDK7M
  191. @@:     mov     eax, 68         ; Athlon/AthlonXP
  192.         mov     ebx, 3
  193.         mov     edx, 0x0C0010015
  194.         int     0x40
  195.         mov     ebx, eax
  196.         shr     ebx, 24
  197.         and     ebx, 0x0F
  198.         shr     eax, 20
  199.         jnc     @f
  200.         add     bl, 16
  201. @@:     mov     cl, [athloncoef + ebx]
  202.         ret
  203.  
  204. AMDK7M: mov     eax, 68         ; AthonXP-M
  205.         mov     ebx, 3
  206.         mov     edx, 0xC0010042
  207.         int     0x40
  208.         and     eax, 0x1F
  209.         mov     cl, [athlonmcoef + eax]
  210.         ret
  211.  
  212. noAMDK7:cmp     byte [CPU_fam], 0xF
  213.         jne     noAMDK8
  214.         mov     eax, 0x80000007
  215.         cpuid
  216.         and     edx, 6          ;  voltage ID control & frequency ID control
  217.         cmp     edx, 6
  218.         je      AMDK8M
  219.         mov     eax, 68         ; Athon64
  220.         mov     ebx, 3
  221.         mov     edx, 0xC0010015
  222.         int     0x40
  223.         shr     eax, 24
  224.         and     al, 0x3F
  225.         shr     al, 1
  226.         add     al, 4
  227.         mov     dl, 10
  228.         mul     dl
  229.         mov     cl, al
  230.         ret
  231.  
  232. AMDK8M: mov     eax, 68         ; Athon64-M
  233.         mov     ebx, 3
  234.         mov     edx, 0xC0010042
  235.         int     0x40
  236.         and     al, 0x3F
  237.         shr     al, 1
  238.         add     al, 4
  239.         mov     dl, 10
  240.         mul     dl
  241.         mov     cl, al
  242.         ret
  243.        
  244. noAMD:  cmp     dword [Vendor + 8], 'ntel'      ; Check for International Electronics CPU
  245.         jne     noIntel
  246.         cmp     byte[CPU_fam], 0x0F
  247.         jne     noIntelP4
  248.         cmp     byte [CPU_type], 6
  249.         jne     @f
  250.         mov     eax, 68         ; Pentium M
  251.         mov     ebx, 3
  252.         mov     edx, 0x2A
  253.         int     0x40
  254.         shr     eax, 22
  255.         and     eax, 0x1F
  256.         mov     dl, 10
  257.         mul     dl
  258.         mov     cl, al
  259.         ret
  260. @@:     cmp     byte [CPU_mod], 2
  261.         jae     @f
  262.         mov     eax, 68         ; Pentium 4 / Xeon (model < 2)
  263.         mov     ebx, 3
  264.         mov     edx, 0x2A
  265.         int     0x40
  266.         shr     eax, 8
  267.         and     eax, 0x0F
  268.         mov     cl, [p4coef + eax]
  269.         ret
  270. @@:     mov     eax, 68         ; Pentium 4 / Xeon (model >= 2)
  271.         mov     ebx, 3
  272.         mov     edx, 0x2C
  273.         int     0x40
  274.        
  275.         ; shr   eax, 24
  276.         ; and   eax, 0x1F
  277.         shr     eax, 27
  278.         and     al, 0Fh
  279.         add     al, 8
  280.        
  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
  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.