__Asm and CPUID

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
LVL 5
laeuchliAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

nietodCommented:
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
tiagoCommented:
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
nietodCommented:
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
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

tiagoCommented:
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
nietodCommented:
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
laeuchliAuthor Commented:
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
tiagoCommented:
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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
nietodCommented:
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
tiagoCommented:
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
nietodCommented:
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft Development

From novice to tech pro — start learning today.