qemu-devel
[Top][All Lists]
Advanced

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

[RFC v3 07/10] target/i386: Add support for native library calls


From: Yeqi Fu
Subject: [RFC v3 07/10] target/i386: Add support for native library calls
Date: Mon, 26 Jun 2023 05:27:04 +0800

Upon encountering specialized instructions reserved for native calls,
store the function id and argument types, then invoke helper.

Signed-off-by: Yeqi Fu <fufuyqqqqqq@gmail.com>
---
 target/i386/tcg/translate.c | 33 +++++++++++++++++++++++++++++++++
 1 file changed, 33 insertions(+)

diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
index 91c9c0c478..27d5d2231b 100644
--- a/target/i386/tcg/translate.c
+++ b/target/i386/tcg/translate.c
@@ -33,6 +33,7 @@
 #include "helper-tcg.h"
 
 #include "exec/log.h"
+#include "native/native-defs.h"
 
 #define PREFIX_REPZ   0x01
 #define PREFIX_REPNZ  0x02
@@ -6806,6 +6807,38 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
     case 0x1d0 ... 0x1fe:
         disas_insn_new(s, cpu, b);
         break;
+    case 0x1ff:
+        if (native_call_enabled()) {
+            uint16_t sig;
+            sig = x86_lduw_code(env, s);
+            TCGv_i32 func_id = tcg_constant_i32(sig);
+            sig = x86_lduw_code(env, s);
+            TCGv_i32 abi_map = tcg_constant_i32(sig);
+            TCGv arg1 = tcg_temp_new();
+            TCGv arg2 = tcg_temp_new();
+            TCGv arg3 = tcg_temp_new();
+#ifdef TARGET_X86_64
+            tcg_gen_mov_tl(arg1, cpu_regs[R_EDI]);
+            tcg_gen_mov_tl(arg2, cpu_regs[R_ESI]);
+            tcg_gen_mov_tl(arg3, cpu_regs[R_EDX]);
+#else
+            uintptr_t ra = GETPC();
+            uint32_t a1 = cpu_ldl_data_ra(env, env->regs[R_ESP] + 4, ra);
+            uint32_t a2 = cpu_ldl_data_ra(env, env->regs[R_ESP] + 8, ra);
+            uint32_t a3 = cpu_ldl_data_ra(env, env->regs[R_ESP] + 12, ra);
+            tcg_gen_movi_tl(arg1, a1);
+            tcg_gen_movi_tl(arg2, a2);
+            tcg_gen_movi_tl(arg3, a3);
+#endif
+            TCGv res = tcg_temp_new();
+            TCGv_i32 mmu_idx = tcg_constant_i32(MMU_USER_IDX);
+            gen_helper_native_call(res, cpu_env, arg1, arg2, arg3,
+                                    abi_map, func_id, mmu_idx);
+
+            tcg_gen_mov_tl(cpu_regs[R_EAX], res);
+            break;
+        }
+        break;
     default:
         goto unknown_op;
     }
-- 
2.34.1




reply via email to

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