From 2efaa0dfc793929990f044af11ae1e8c0bcd16be Mon Sep 17 00:00:00 2001
From: wobakj <jakob.wagner@uni-weimar.de>
Date: Thu, 8 Feb 2018 09:29:04 +0100
Subject: [PATCH] return ptr to next block after clal, rjump and rcall

---
 framework/source/chip_jit_instructions.c |  2 +-
 framework/source/chip_jit_logic.c        | 17 ++++-------------
 2 files changed, 5 insertions(+), 14 deletions(-)

diff --git a/framework/source/chip_jit_instructions.c b/framework/source/chip_jit_instructions.c
index cbff4b9..6c5129a 100644
--- a/framework/source/chip_jit_instructions.c
+++ b/framework/source/chip_jit_instructions.c
@@ -639,7 +639,7 @@ static inline void emit_ret_block_ptr(uint8_t** top, cpssp_t* cpssp, uint16_t pc
   void * next_ptr = jit_get_block_ptr(cpssp->jit, pc_position);
   if (next_ptr != NULL) {
     emit_mov_ir(top, QWORD, RAX, (uint64_t)next_ptr);
-    printf("direct call to %#x \n", pc_position* 2);
+    DEBUG("direct call to %#x \n", pc_position* 2);
   }
   else {
     emit_mov_ir(top, QWORD, RAX, (uint64_t)NULL);
diff --git a/framework/source/chip_jit_logic.c b/framework/source/chip_jit_logic.c
index 9593936..3ecba6a 100644
--- a/framework/source/chip_jit_logic.c
+++ b/framework/source/chip_jit_logic.c
@@ -692,13 +692,6 @@ static inline bool emit_instruction(uint8_t **top, uint16_t instruction, cpssp_t
             emit_mov_ir(top, WORD, RSI, addr);
             emit_call(top, &jmp);
             emit_ret_block_ptr(top, cpssp, addr);
-            // void * next_ptr = jit_get_block_ptr(cpssp->jit, addr);
-            // if (next_ptr != NULL) {
-            //   printf("direct call to %#x \n", addr* 2);
-            //   assert(0);
-            //   emit_call_c(top, cpssp, &chip_handle_signals);
-            //   emit_call(top, next_ptr);
-            // }
             return true;
             // postion in instructions,these are 2 bytes wide
             // uint16_t pos = flash_pop_w(cpssp);
@@ -720,8 +713,7 @@ static inline bool emit_instruction(uint8_t **top, uint16_t instruction, cpssp_t
             emit_mov_ir(top, QWORD, RDI, (uint64_t)cpssp);
             emit_mov_ir(top, WORD, RSI, addr);
             emit_call(top, &call);
-            emit_mov_ir(top, QWORD, RAX, (uint64_t)NULL);
-
+            emit_ret_block_ptr(top, cpssp, addr);
             return true;
             // postion in instructions, these are 2 bytes wide
             // jump to target address
@@ -1220,8 +1212,7 @@ static inline bool emit_instruction(uint8_t **top, uint16_t instruction, cpssp_t
       emit_set_pc(top, cpssp, RBX, *instr_ptr);
       // do actual jump
       emit_call_c_c(top, cpssp, offset, &rjmp);
-      emit_mov_ir(top, QWORD, RAX, (uint64_t)NULL);
-      //rjmp(cpssp, offset);
+      emit_ret_block_ptr(top, cpssp, (uint16_t)(*instr_ptr + offset));
       return true;
       break;
     }
@@ -1232,9 +1223,9 @@ static inline bool emit_instruction(uint8_t **top, uint16_t instruction, cpssp_t
       emit_set_pc(top, cpssp, RBX, *instr_ptr);
       // do actual call
       emit_call_c_c(top, cpssp, offset, &rcall);
-      //rcall(cpssp, offset);
-      emit_mov_ir(top, QWORD, RAX, (uint64_t)NULL);
+      emit_ret_block_ptr(top, cpssp, (uint16_t)(*instr_ptr + offset));
       return true;
+      //rcall(cpssp, offset);
       break;
     }
     case 14: {
-- 
GitLab