Results 1 to 1 of 1

Thread: [C++ with inline ASM] CPU condition flags - saving/restoring?

Threaded View

  1. #1

    Thread Starter
    type Woss is new Grumpy; wossname's Avatar
    Join Date
    Aug 2002
    Location
    #!/bin/bash
    Posts
    5,682

    [C++ with inline ASM] CPU condition flags - saving/restoring?

    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...

    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
    
    /////////
    }
    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.
    Last edited by wossname; Mar 27th, 2008 at 08:00 AM.
    I don't live here any more.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width