Solved

__Asm and CPUID

Posted on 1997-12-09
10
415 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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article shows how to make a Windows 7 gadget that extends its U/I with a flyout panel -- a window that pops out next to the gadget.  The example gadget shows several additional techniques:  How to automatically resize a gadget or flyout panel t…
This article describes how to programmatically preset the "Pages per Sheet" option that's available with most printer drivers.   This setting lets you do "n-Up" printing, where two, four, or more pages are printed on each sheet of paper. If your …
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…
Learn how to create flexible layouts using relative units in CSS.  New relative units added in CSS3 include vw(viewports width), vh(viewports height), vmin(minimum of viewports height and width), and vmax (maximum of viewports height and width).

911 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

20 Experts available now in Live!

Get 1:1 Help Now