[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
- [RFC v3 00/10] Native Library Calls, Yeqi Fu, 2023/06/25
- [RFC v3 01/10] docs: Add specification for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 02/10] build: Add configure options for native calls, Yeqi Fu, 2023/06/25
- [RFC v3 03/10] build: Implement libnative library and configure options, Yeqi Fu, 2023/06/25
- [RFC v3 04/10] linux-user: Implement envlist_appendenv, Yeqi Fu, 2023/06/25
- [RFC v3 05/10] linux-user: Implement native-bypass option support, Yeqi Fu, 2023/06/25
- [RFC v3 06/10] accel/tcg: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 07/10] target/i386: Add support for native library calls,
Yeqi Fu <=
- [RFC v3 08/10] target/mips: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 09/10] target/arm: Add support for native library calls, Yeqi Fu, 2023/06/25
- [RFC v3 10/10] tests/tcg/multiarch: Add nativecalls.c test, Yeqi Fu, 2023/06/25