Author Topic: program to identify cpu and fpu type  (Read 17590 times)

Offline vikram

  • Jr. Member
  • *
  • Posts: 2
program to identify cpu and fpu type
« on: October 06, 2013, 04:52:19 PM »
Hello everybody i really need 2 programs very urgent
1.alp to find cpu and fpu type
2.alp to define two tasks and execute them on different cpu cores
need for submissions

Offline encryptor256

  • Full Member
  • **
  • Posts: 250
  • Country: lv
  • Win64 .
    • On Youtube: encryptor256
Re: program to identify cpu and fpu type
« Reply #1 on: October 07, 2013, 07:14:31 AM »
Hi!

1. To, find cpu and fpu type, you can, using opcode cpuid, description about it you can find here:

http://en.wikipedia.org/wiki/CPUID

2. To execute two tasks, each on different cpu:

Im using Windows XP, and Win32 API provide functions to execute programs on selected cpu core.

I did like this: Create program that assings all running programs single cpu core,
then i setup second cpu core for some special program, like games.

Im using currently this code, to set all running processes a single cpu, it's only in C.

Sometimes os performs better, if all processes running on a single core.

Code: [Select]
#include <windows.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <TlHelp32.h>

BOOL SetPrivilege(HANDLE hToken,LPCTSTR lpszPrivilege,BOOL bEnablePrivilege)
{
    TOKEN_PRIVILEGES tp;
    LUID luid;

    if ( !LookupPrivilegeValue(
            NULL,            // lookup privilege on local system
            lpszPrivilege,   // privilege to lookup
            &luid ) )        // receives LUID of privilege
    {
MessageBox(0,"ERROR: SetPrivilege (LookupPrivilegeValue)",0,0);
ExitProcess(0);
return FALSE;
    }

    tp.PrivilegeCount = 1;
    tp.Privileges[0].Luid = luid;
    if (bEnablePrivilege)
        tp.Privileges[0].Attributes = SE_PRIVILEGE_ENABLED;
    else
        tp.Privileges[0].Attributes = 0;

    // Enable the privilege or disable all privileges.

    if ( !AdjustTokenPrivileges(
           hToken,
           FALSE,
           &tp,
           sizeof(TOKEN_PRIVILEGES),
           (PTOKEN_PRIVILEGES) NULL,
           (PDWORD) NULL) )
    {
MessageBox(0,"ERROR: SetPrivilege (AdjustTokenPrivileges)",0,0);
ExitProcess(0);
return FALSE;
    }

    if (GetLastError() == ERROR_NOT_ALL_ASSIGNED)
    {
MessageBox(0,"ERROR: SetPrivilege",0,0);
ExitProcess(0);
        return FALSE;
    }

    return TRUE;
}

void mooThread(void)
{
HANDLE hSnapShot;

hSnapShot = CreateToolhelp32Snapshot(TH32CS_SNAPTHREAD,0);

THREADENTRY32 entry;

entry.dwSize = sizeof(THREADENTRY32);
Thread32First(hSnapShot,&entry);

do
{
HANDLE hProc = OpenProcess(PROCESS_SET_INFORMATION,0,entry.th32OwnerProcessID);
SetProcessAffinityMask(hProc,2);
SetProcessPriorityBoost(hProc,TRUE);
CloseHandle(hProc);

HANDLE hThread = OpenThread(THREAD_SET_INFORMATION,0,entry.th32ThreadID);
SetThreadAffinityMask(hThread,2);
SetThreadIdealProcessor(hThread,2);
CloseHandle(hThread);

}while(Thread32Next(hSnapShot,&entry));

CloseHandle(hSnapShot);
};

int WINAPI WinMain(HINSTANCE hInstance,HINSTANCE hPrevInstance,LPSTR lpCmdLine,int nCmdShow)
{

HANDLE tk;
OpenProcessToken(GetCurrentProcess(),TOKEN_ADJUST_PRIVILEGES,&tk);
if(!SetPrivilege(tk,SE_DEBUG_NAME,1))
{
MessageBox(0,"ERROR: SetPrivilege",0,0);
};


mooThread();
return 0;
};

Happy hunting! :)
« Last Edit: October 07, 2013, 07:20:28 AM by encryptor256 »
Encryptor256's Investigation \ Research Department.

Offline shwetamandare@yahoo.com

  • New Member
  • Posts: 1
Re: program to identify cpu and fpu type
« Reply #2 on: October 08, 2013, 12:23:59 PM »
can u tell the program in assembly language how to find cpu type and fpu type
i have done that program but only by passing 0 in eax register but i am getting confused how do it when i have pass 1,2,3 in eax register can please tell how to do this............

Code: [Select]
section .data
      msg1: db " The CPU type is  :"
      len1: equ $-msg1
      msg2: db " The FPU (Coprocessor) is  :"
      len2: equ $-msg2
      msg3: db " 8087/ 80287", 0ah
      len3: equ $-msg3
      msg4: db " 80387", 0ah
      len4: equ $-msg4
      msg5: db "   ", 0ah
      len5: equ $-msg5

%macro display 2
      mov eax, 4
      mov ebx, 1
      mov ecx, %1
      mov edx, %2
      int 80h
%endm

section .bss
      var1 resd 1
      var2 resd 1
      var3 resd 1
      var4 resd 1

section .data
      global _start

_start:
      CPUID
      mov [var1], ebx
      mov [var2], edx
      mov [var3], ecx

      display msg1, len1

      display var1, 4
      display var2, 4
      display var3, 4
      display msg5, len5
      display msg2, len2
       
;FPU
SMSW eax ;load the machine status word
      mov [var4], eax
      mov edx, [var4]
      bt edx, 4
      mov [var4], edx

      jc not
      display msg3, len3
      call ext

not:
      display msg4, len4
      display msg5, len5
ext:
      mov eax, 1
      mov ebx, 0
      int 80h



Offline Frank Kotler

  • NASM Developer
  • Hero Member
  • *****
  • Posts: 2667
  • Country: us
Re: program to identify cpu and fpu type
« Reply #3 on: October 08, 2013, 05:07:45 PM »
Hi Shwetamandare,

Thanks for the example. I haven't tried it yet - having trouble copying it out of here for some reason, but I'll get it! One problem I can see... you've got your code in "section .data". Easily fixed. When we do "cpuid" with eax = 0, besides the ebx/edx/ecx you've captured, eax contains the "highest supported cpuid level". Trying a higher number than this is a mistake - my old P4 reported 16 cores! Fat chance. Beyond that, I'm going to have to check out the link Encryptor256 provided for more information on "cpuid".

This is just a slightly more verbose version of what you've already got. It probably isn't much help, but it's what I've got.

There's a file, "/proc/cpuinfo" that we can check to see if we're getting the right answers. Might be useful? I don't know what the Windows guys have got. Probably similar information... someplace...

Code: [Select]
; nasm -f elf cpuname.asm
; ld -o cpuname cpuname.o

global _start

section .bss
    namestring resb 48

section .text
_start:

    mov eax, 80000000h
    cpuid
    cmp eax, 80000004h
    jb exit
   
    mov edi, namestring

    mov eax, 80000002h
    cpuid
    call savestring

    mov eax, 80000003h
    cpuid
    call savestring

    mov eax, 80000004h
    cpuid
    call savestring

    mov ecx, namestring
    mov edx, 48
    mov ebx, 1
    mov eax, 4
    int 80h

exit:
    mov eax, 1
    int 80h
;----------------

;----------------
savestring:
    stosd
    mov eax, ebx
    stosd
    mov eax, ecx
    stosd
    mov eax, edx
    stosd
    ret
;----------------

More later (probably)...

Best,
Frank