Solved

__Asm and CPUID

Posted on 1997-12-09
10
410 Views
Last Modified: 2013-12-03
HI! I am useing Visual C++ 5.0 to write a MMX CPU emulater. It's just a test and I don't know that it will every get any where, however, here is my question. I have a __asm block in one program that writes to the cpu register that tells the computer it is mmx. In another program I use the CPUID to find out if the computer is mmx or not. the test fails. Whats wrong? jesse.laeuchli@usa.net
0
Comment
Question by:laeuchli
  • 5
  • 4
10 Comments
 
LVL 22

Expert Comment

by:nietod
ID: 1409223
By the "test fails" do you mean that the test does not work to indicate if MMX is there or not?  Or do you mean a different type of failure (crash etc).

How are you doing the CPUID test?  I don't know how to do the test as it is not in my (regular i.e. non-mmx) pentium manual.  However in general you must make sure that the chip supports the test you are doing.  (The tests are numbered from zero and each chips supports tests up to a specific number.)  That is, that it was designed to handle the number you specify to the CPUID instruction.  If not, then you can assume the feature is not available.

If this doesn't help, (it would be suprised if it did) please post the code of the test.  
0
 
LVL 1

Expert Comment

by:tiago
ID: 1409224
The CPUID instruction sets the register(s) you just modified to
the appropriate value for this instruction. There is NO WAY of
getting a non-MMX processor to respond as a MMX processor via
CPUID instruction.

BTW, take a look at http://developer.intel.com
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409225
Is don't think Lasuchli is try to get

"a non-MMX processor to respond as a MMX processor via CPUID instruction."

He's just trying to determine if the processor is an MMX processor.  I assume that is one of the capabilities returned by the CPUID instruction  (I don't know since it is not documented in my regular pentium manual)  Presumably, an mmx processor will allow a higher value in EAX (pentium allows 0 or 1) or it will return with some additional bits sets in EDX on the EAX=1 sub-function.
0
 
LVL 1

Expert Comment

by:tiago
ID: 1409226
Quoting laeuchli: "I have a __asm block in one program that writes to the cpu register that tells the computer it is mmx. In another program I use the CPUID to find out if the computer is mmx or not. the test fails."

So why would he(laeuchli) set the CPU register(s) BEFORE he does a CPUID?
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409227
We should probably be talking to laeuchli instead of debating with each other about he meant, but to continue the debate. . .

I interpreted that to mean that one program (the second one) looks for an MMX chip.  If it is found, fine.  If not, it loads a different program that acks as an emmulator.

You;ve heard of creative writing?  Well, you might have just witnessed creative reading.  But then again, maybe not.  When laeuchli responds, we'll find out.
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 5

Author Comment

by:laeuchli
ID: 1409228
Here is the program that tests for mmx . It is run while program 2 is runing.
#include <stdio.h>
#include<iostream.h>
void main (void) { int ISON;

_asm {
mov      EAX, 1                  
_emit 0x0f            
_emit 0xa2  

test      EDX,00800000h      ; Is IA MMX technology bit (Bit 23 of EDX) in feature flags set?
jnz      MMX_Technology_Found
jmp MMX_Not
MMX_Technology_Found:
mov ISON,1
jmp Exit
MMX_Not:
mov ISON,0
Exit:
}
if(ISON==1)
{
cout<<"MMX FOUND";
cin;
}
else
{
cout<<"MMX NOT FOUND";
}

cin;
}
Here is program 2
#include<iostream.h>
#include<windows.h>
void main()
{
      cout<<"Emulater for MMX";
__asm
{

Emulate_MMX:
sub EDX,EDX ;Startup make sure EDX is  empty
mov EDX,00800000h ;Fib to the CPU that it's MMX when it's only a 75MHz
jmp Emulate_MMX
}

}
As to the debate tigo is right about what I am trying to do.

0
 
LVL 1

Accepted Solution

by:
tiago earned 120 total points
ID: 1409229
You are doing things the wrong way.

First: the two programs are running as different processes. Setting registers on one process will not cause any change on the other process.

Second: You will never get CPUID respondin' "MMX processor" if it's not.

0
 
LVL 22

Expert Comment

by:nietod
ID: 1409230
I'm not sure what tiago means in his second point.  But his first point is certainly correct.  Your second program is caught in an endless loop setting the EDX to 0 and then to 800000H.  While that process is running, EDX will be one of those values.  While another process is running it will be something else.  When processes are changed the registers are saved and restored.  Otherwise there would be chaos.

What is it that you are trying to do?

If you are trying to fool you own program into believing its on an MMX chip, that is possible.  If you are trying to fool another program, that will be (practically) impossible.  You cannot tell when another program will run the CPUID instruction.   You cannot modify the value the other program will get from the CPUID instruction.
0
 
LVL 1

Expert Comment

by:tiago
ID: 1409231
Maybe it is possible to catch the "Invalid Opcode" exception if the processor doesn't have the CPUID/MMX extensions and do the appropriate "emulation".
0
 
LVL 22

Expert Comment

by:nietod
ID: 1409232
No, the CPUID is available on pentium and later processors.  Pentium processors that are not MMX will not cause the invalid opcode exception and will not have MMX.

In addition, I suspect laeuchli is not really tring to emmulate MMX.  He's trying to fool a program into thinking it is there. That's likely to be a mistake.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

If you have ever found yourself doing a repetitive action with the mouse and keyboard, and if you have even a little programming experience, there is a good chance that you can use a text editor to whip together a sort of macro to automate the proce…
What my article will show is if you ever had to do processing to a listbox without being able to just select all the items in it. My software Visual Studio 2008 crystal report v11 My issue was I wanted to add crystal report to a form and show…
This is Part 3 in a 3-part series on Experts Exchange to discuss error handling in VBA code written for Excel. Part 1 of this series discussed basic error handling code using VBA. http://www.experts-exchange.com/videos/1478/Excel-Error-Handlin…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now