Re: [snipersim] SimMagic2() queries

94 views
Skip to first unread message
Message has been deleted

Trevor E. Carlson

unread,
Jul 31, 2021, 2:35:45 AM7/31/21
to snip...@googlegroups.com, shaikh...@gmail.com
Shaikhul Hadi,

     You shouldn’t need to modify the magic function, just call it.

     What are you trying to do exactly? The return value will come back as _res, which is the return of the macro, as defined by GCC. _res will we assigned by Sniper when running. You can check the SimInSimulator() function as an example of how that works.

     One of the easiest ways to get started is to use a SimUser magic instruction, as you were mentioning in your email. You can handle the callback from a Python script that is running in Sniper. You can check the examples for SimUser in the sniper/scripts directory, to see what you can do from there. There is no need to write assembly if you use SimUser, just call the function in C, and you’ll get the callback in Sniper.

Trevor

On Jul 31, 2021, at 2:09 PM, Shaikhul Hadi <shaikh...@gmail.com> wrote:


I'm trying to understand how to implement my own magic function in sniper. I have gone through many posts in this group and the manual but could not find anything that properly explained this. Let's see some code from sim_api.h file.

#define SimMagic2(cmd, arg0, arg1) ({ \
unsigned long _cmd = (cmd), _arg0 = (arg0), _arg1 = (arg1), _res; \
__asm__ __volatile__ ( \
"mov %1, %%" MAGIC_REG_A "\n" \
"\tmov %2, %%" MAGIC_REG_B "\n" \
"\tmov %3, %%" MAGIC_REG_C "\n" \
"\txchg %%bx, %%bx\n" \
: "=a" (_res) /* output */ \
: "g"(_cmd), \
"g"(_arg0), \
"g"(_arg1) /* input */ \
: "%" MAGIC_REG_B, "%" MAGIC_REG_C ); /* clobbered */ \
_res; \
})

...
...
...
#define SimUser(cmd, arg) SimMagic2(SIM_CMD_USER, cmd, arg)


Now I have multiple questions, if anyone bothers to explain it to me, I would be grateful. Thanks in advance.

  1. Who assigned or provide _res value? There is no return type is defined for SimMagic2() or SimUser(). In that case, who is using the value or _res?
  2. Is there any proper guideline on how I should write the assembly portion of the instruction (__asm__)? I searched on the internet and most of the tutorials I got on assembly in C++, their structure does not clear everything the way SimMagic2() is defined. (Perdon my lack of knowledge on writing assembly in C++, I never tried this before.)
  3. %1 will use value _cmd , %2 will use value _arg0 ; is my assumption write? What task does the line with the comment "/* clobbered */" perform?


I apologize if my question is silly. I just want to clear my concept about how to work with magic function in sniper and what is its limit. Any resources (except sniper manual and this group) suggestions will be greatly appreciated. 


Thank you


--
--
--
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/77654e1d-48d2-4e4a-992f-19d1321bcd45n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages