How to update ZF from magic function

13 views
Skip to first unread message

Shaikhul Hadi

unread,
Aug 23, 2021, 2:14:31 AM8/23/21
to Sniper simulator
Hi,
I have a magic function that is defined in core.cc . I wan't to update Zero Flag based on some calculation and don't want to use "return true"/ "return false" as I will return some value based on some computation. I have gone through this group to find some clue on how to do so but found nothing.

Do anyone have any idea how I could manually update zero flag from core.cc ??

Best

Trevor E. Carlson

unread,
Aug 23, 2021, 8:43:37 AM8/23/21
to snip...@googlegroups.com, shaikh...@gmail.com
Shaikhul,

     Why not return true / false from the magic instruction, and then update the value of the zero flag based on the value in the code on the Pin side directly? If you want to use the value that returns, then you can do the comparison on the value directly.

     One issue is that setting the ZF manually will not be honored by the compiler typically, because when you call the asm() function (and you specify that the condition codes have been updated), the compiler will make sure to update them before they are used. Care will need to be taken to get this right, so it could be easier to handle the if condition from the magic instruction call in some new C code directly instead of trying to modify the ZF.

     Unfortunately without more detail with respect to what you’d like to do, it will be difficult for me to help further.

Good luck,
Trevor

On Aug 23, 2021, at 2:14 PM, Shaikhul Hadi <shaikh...@gmail.com> wrote:

Hi,
I have a magic function that is defined in core.cc . I wan't to update Zero Flag based on some calculation and don't want to use "return true"/ "return false" as I will return some value based on some computation. I have gone through this group to find some clue on how to do so but found nothing.

Do anyone have any idea how I could manually update zero flag from core.cc ??

Best

--
--
--
You received this message because you are subscribed to the Google
Groups "Sniper simulator" group.
To post to this group, send email to snip...@googlegroups.com
To unsubscribe from this group, send email to
snipersim+...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/snipersim?hl=en

---
You received this message because you are subscribed to the Google Groups "Sniper simulator" group.
To unsubscribe from this group and stop receiving emails from it, send an email to snipersim+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/snipersim/e077c6f0-a14e-4676-bbd6-50725118ad1cn%40googlegroups.com.

Shaikhul Hadi

unread,
Aug 23, 2021, 12:37:11 PM8/23/21
to Sniper simulator
Trevor,

I'm trying to implement magic function that will perform similar functionality of "lock CMPXCHG" . If you look for it's functionality, you realize that it updates value of RAX or EAX if comparison fails or updates value of destination address if comparison succeeds. And set ZF based on either comparison succeeds or not. I could do that by returning true/false, but in that case I have to find a way to update RAX value from core.cc which I could not do (don't know if possible in sniper. If so, don't know how). So, I'm thinking maybe I update ZF from here and return updated value of RAX as return value of magic function is written back in register RAX.

Hope I could make it clear. Thank you for your reply.

Best

Trevor E. Carlson

unread,
Aug 23, 2021, 7:59:21 PM8/23/21
to snip...@googlegroups.com, shaikh...@gmail.com
Shaikhul,

One solution could be to call into the simulator multiple times. The first call could actually perform the CMPXCHG check, and implementation, etc. Subsequent calls (with different command numbers) could then read the appropriate state from the simulator based on the most recent CMPXCHG done on that core. You can then collect all of the data that you need, and the software can make the appropriate decisions / update local state, etc.

Trevor

Reply all
Reply to author
Forward
0 new messages