From: Richard Henderson <richard.henderson@linaro.org>
To: Yeqi Fu <fufuyqqqqqq@gmail.com>, alex.bennee@linaro.org
Cc: qemu-devel@nongnu.org, Laurent Vivier <laurent@vivier.eu>,
Paolo Bonzini <pbonzini@redhat.com>,
Eduardo Habkost <eduardo@habkost.net>
Subject: Re: [RFC v4 07/11] target/i386: Add support for native library calls
Date: Wed, 9 Aug 2023 09:44:42 -0700 [thread overview]
Message-ID: <7cf090b3-c124-cfe2-85b7-aeccc09139db@linaro.org> (raw)
In-Reply-To: <20230808141739.3110740-8-fufuyqqqqqq@gmail.com>
On 8/8/23 07:17, Yeqi Fu wrote:
> This commit introduces support for native library calls on the
> i386 target. When special instructions reserved for native calls
> are encountered, the code now performs address translation and
> generates the corresponding native call.
>
> Signed-off-by: Yeqi Fu <fufuyqqqqqq@gmail.com>
> ---
> configs/targets/i386-linux-user.mak | 1 +
> configs/targets/x86_64-linux-user.mak | 1 +
> target/i386/tcg/translate.c | 27 +++++++++++++++++++++++++++
> 3 files changed, 29 insertions(+)
>
> diff --git a/configs/targets/i386-linux-user.mak b/configs/targets/i386-linux-user.mak
> index 5b2546a430..2d8bca8f93 100644
> --- a/configs/targets/i386-linux-user.mak
> +++ b/configs/targets/i386-linux-user.mak
> @@ -2,3 +2,4 @@ TARGET_ARCH=i386
> TARGET_SYSTBL_ABI=i386
> TARGET_SYSTBL=syscall_32.tbl
> TARGET_XML_FILES= gdb-xml/i386-32bit.xml
> +CONFIG_NATIVE_CALL=y
> diff --git a/configs/targets/x86_64-linux-user.mak b/configs/targets/x86_64-linux-user.mak
> index 9ceefbb615..a53b017454 100644
> --- a/configs/targets/x86_64-linux-user.mak
> +++ b/configs/targets/x86_64-linux-user.mak
> @@ -3,3 +3,4 @@ TARGET_BASE_ARCH=i386
> TARGET_SYSTBL_ABI=common,64
> TARGET_SYSTBL=syscall_64.tbl
> TARGET_XML_FILES= gdb-xml/i386-64bit.xml
> +CONFIG_NATIVE_CALL=y
> diff --git a/target/i386/tcg/translate.c b/target/i386/tcg/translate.c
> index 90c7b32f36..28bf4477fb 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.h"
>
> #define HELPER_H "helper.h"
> #include "exec/helper-info.c.inc"
> @@ -6810,6 +6811,32 @@ static bool disas_insn(DisasContext *s, CPUState *cpu)
> case 0x1d0 ... 0x1fe:
> disas_insn_new(s, cpu, b);
> break;
> + case 0x1ff:
> + if (native_bypass_enabled()) {
> + TCGv ret = tcg_temp_new();
> + TCGv arg1 = tcg_temp_new();
> + TCGv arg2 = tcg_temp_new();
> + TCGv arg3 = tcg_temp_new();
> + const char *fun_name = lookup_symbol((s->base.pc_next) & 0xfff);
I'm not keen on this lookup_symbol interface.
I would much rather there be some data encoded in the native.so.
> + 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);
This is wrong. You are performing the stack load at translation time, but it must be done
at execution time. You need
tcg_gen_addi_tl(arg1, cpu_regs[R_ESP], 4); /* arg1 = esp + 4 */
gen_op_ld_v(s, MO_UL, arg1, arg1); /* arg1 = *arg1 */
etc.
r~
next prev parent reply other threads:[~2023-08-09 16:45 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-08-08 14:17 [RFC v4 00/11] Native Library Calls Yeqi Fu
2023-08-08 14:17 ` [RFC v4 01/11] build: Implement logic for sharing cross-building config files Yeqi Fu
2023-08-09 12:24 ` Manos Pitsidianakis
2023-08-09 14:42 ` Alex Bennée
2023-08-09 15:23 ` Alex Bennée
2023-08-10 8:41 ` Alex Bennée
2023-08-08 14:17 ` [RFC v4 02/11] build: Implement libnative library and the build machinery for libnative Yeqi Fu
2023-08-09 15:18 ` Alex Bennée
2023-08-09 16:10 ` Richard Henderson
2023-08-08 14:17 ` [RFC v4 03/11] linux-user: Implement envlist_appendenv and add tests for envlist Yeqi Fu
2023-08-09 15:27 ` Alex Bennée
2023-08-09 15:44 ` Richard Henderson
2023-08-09 16:06 ` Richard Henderson
2023-08-08 14:17 ` [RFC v4 04/11] linux-user: Implement native-bypass option support Yeqi Fu
2023-08-09 15:42 ` Richard Henderson
2023-08-09 15:47 ` Alex Bennée
2023-08-08 14:17 ` [RFC v4 05/11] linux-user/elfload: Add support for parsing symbols of native libraries Yeqi Fu
2023-08-09 16:14 ` Richard Henderson
2023-08-09 17:04 ` Alex Bennée
2023-08-08 14:17 ` [RFC v4 06/11] tcg: Add tcg opcodes and helpers for native library calls Yeqi Fu
2023-08-09 16:41 ` Alex Bennée
2023-08-08 14:17 ` [RFC v4 07/11] target/i386: Add support " Yeqi Fu
2023-08-09 16:44 ` Richard Henderson [this message]
2023-08-08 14:17 ` [RFC v4 08/11] target/mips: " Yeqi Fu
2023-08-08 14:17 ` [RFC v4 09/11] target/arm: " Yeqi Fu
2023-08-08 14:17 ` [RFC v4 10/11] tests/tcg/multiarch: Add nativecall.c test Yeqi Fu
2023-08-09 8:42 ` Alex Bennée
2023-08-09 17:01 ` Alex Bennée
2023-08-09 17:12 ` Alex Bennée
2023-08-08 14:17 ` [RFC v4 11/11] docs/user: Add doc for native library calls Yeqi Fu
2023-08-09 12:51 ` Manos Pitsidianakis
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=7cf090b3-c124-cfe2-85b7-aeccc09139db@linaro.org \
--to=richard.henderson@linaro.org \
--cc=alex.bennee@linaro.org \
--cc=eduardo@habkost.net \
--cc=fufuyqqqqqq@gmail.com \
--cc=laurent@vivier.eu \
--cc=pbonzini@redhat.com \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).