I require to simulate a hypothetical CPU ("X") which is quite similar in most respects to a regular 586 pentium.
X has a small instruction set but where those opcodes match up with pentium's set then I want those opcodes to behave in exactly the same way.
So basically I need to store the equivalent of the EFLAGS register in my X class. I want to be able to use the real pentium processor to actually perform the opcodes functionality for me, so I'd have to push X's EFLAGS on the stack and then use POPFD to stuff them into the pentium's EFLAGS register. Then perform the opcode.
Is this a potentially risky thing to do? Meddling with EFLAGS sounds a bit dangerous to me, BUT it would be really very handy for my purposes.
Would I need to "backup" the pentium's eflags (PUSHFD) and then restore it when i'm finished or is this even more dodgy?
Basically here's my idea in pseudocode...
The idea being that I can simply put the blue and red bits into C macros, thus ensuring all the instructions will be handled safely.Code:void X_INC() { //////// PUDHFD ;backup the pentium's EFLAGS PUSHD myEFLAGS ; push X's version of eflags on the stack POPFD ;now pentium has X's flags INC ... ;the opcode that we are having the pentium perform on X's behalf. PUSHFD ;put X's new flags on the stack POPD myEFLAGS ;update X's sflags in class memory POPFD ;restore the pentium's EFLAGS as if nothing has happened ///////// }


Reply With Quote