well, i don't think the above code will even work. AFAIK pushfd pushes the EFLAGS register onto the stack; so
"pushfd xbox_flags"
doesn't make sense (shouldn't take any operands).
i think you meant something like:
IDK if theres a faster way to get a mem value to EFLAGS than the 2 instructions i used in the above code.
Anyways, i'm not entirely sure what you're trying to do in the above code.
code_addr is what? some xbox function that you're going to natively run (since both processors are x86)?
or is this your dynarec dispatcher? which means code_addr is your recompiled code block?
emulating x86 on x86 is a bit odd for me since its not what i'm used to, and i guess there's many ways you can do it.
i guess the 2 main approaches would be to 'emulate' the flag register, and the other is to try and use the one on the host cpu (which i guess you're trying to do).
on emus like pcsx2 or dolphin, we emulate the flag registers.
as in, we have a memory location which stores the emulated flag register, and we manually set/clear the corresponding bits ourselves.
since this is slow, the smart thing to do is to only set flags when they will be read (this involves a multi-pass dynarec and can get very complex in some cases).
"pushfd xbox_flags"
doesn't make sense (shouldn't take any operands).
i think you meant something like:
Code:
u32 xbox_flags;
__asm
{
// Save host flags and regs
pushad
pushfd
// Set emulated flags
push xbox_flags
popfd
// Execute code
call code_addr
// Save emulated flags
pushfd
pop xbox_flags
// Restore host flags and regs
popfd
popad
}
Anyways, i'm not entirely sure what you're trying to do in the above code.
code_addr is what? some xbox function that you're going to natively run (since both processors are x86)?
or is this your dynarec dispatcher? which means code_addr is your recompiled code block?
emulating x86 on x86 is a bit odd for me since its not what i'm used to, and i guess there's many ways you can do it.
i guess the 2 main approaches would be to 'emulate' the flag register, and the other is to try and use the one on the host cpu (which i guess you're trying to do).
on emus like pcsx2 or dolphin, we emulate the flag registers.
as in, we have a memory location which stores the emulated flag register, and we manually set/clear the corresponding bits ourselves.
since this is slow, the smart thing to do is to only set flags when they will be read (this involves a multi-pass dynarec and can get very complex in some cases).