lightning
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Lightning] How to get call address / instruction pointer without a hack


From: Bruno Loff
Subject: [Lightning] How to get call address / instruction pointer without a hack?
Date: Sun, 9 Mar 2014 15:05:11 +0000

Hello again :-)

As a way of being able to pause the execution of lightning-compiled code, and resume where it was, I programmed the following hack:

Just before the main code, I add the following function:

// void test(void )
jit_prolog();
  jit_ldxi(JIT_R0, JIT_FP, 0x30);
  jit_ret();
  jit_epilog();

The value 0x30 was chosen because when disassembling the generated code I noticed that lightning adds 0x30 bytes to the frame pointer immediately after it jumps to the function. This is probably a result of jit_prolog(), but I'm not sure.

Now, when I need to know the IP of some place, all I have to do is:
1:  jit_prepare();
2:  PUT_ADDRESS_OF_TEST_INTO_R0
3:  jit_finishr(JIT_R0); 
4:  ref = jit_beqi(JIT_R0, 0);
5:  STORE_R0_SOMEWHERE_TO_BE_USED_LATER
6:  jit_ret();
7:  jit_patch(ref);


and as soon as it returns, R0 has the address of (4), which is different than 0. Now I can store this address <somewhere>, leave the execution with jit_ret, and when I want to resume it all I need to do is set R0 to 0 and jump to the address I stored <somewhere>. When that happens the branch on (4) will jump into (7), and the code proceeds merrily onwards.

This is a neat trick, the thing that annoys me is that I have to use this hack to get the address of 4. As far as I know, the value 0x30 for the prolog() could well change from one lightning version / platform to the next.

Is there any way to avoid that?

Bruno




reply via email to

[Prev in Thread] Current Thread [Next in Thread]