Skip to content

Update libtcg to QEMU v8.2.1 #5

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 71 commits into
base: feature/rebase
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
543199a
Added `libtcg` headers and sources files
Sep 2, 2021
e63347b
scripts: Add libtcg enable/disable meson-buildoptions
Feb 9, 2024
4532176
Add libtcg options to configure script
Jun 13, 2022
a0e3ee6
Override `cpu_ld*_code` functions
Sep 2, 2021
1da5062
accel/tcg: remove plugins and QEMUs tcg prologue/epilogue
Sep 2, 2021
3a698e3
accel/tcg: don't early exit code reads
Jul 18, 2024
10a694d
libtcg: exposed an adapted version of QEMUs tcg api
Sep 2, 2021
92b4ad7
libtcg: pass code buffer via CPU state instead of globals
Dec 13, 2021
e2a9753
libtcg: Split args in 3, formatting names out of band
Dec 13, 2021
6b5dbd6
libtcg: better naming, moved initialization from translate
Dec 13, 2021
4b04877
libtcg: added comment/removed TODO
Feb 21, 2022
428c02b
libtcg: fix typos
Apr 4, 2022
bb49f65
libtcg: added TODO to `tinycode_temp_create_name`
Apr 4, 2022
2c47698
libtcg: removed old comment + better TODO
Apr 4, 2022
e5c50ae
libtcg: fixed handling of first 2 constant arguments
Apr 11, 2022
766e7ac
libtcg: added elf.h include required by m68k
May 16, 2022
359d0e3
libtcg: fix endianness define post rebase
Jun 13, 2022
0b178c2
tcg: Expose tcg_get_arg_str
Jun 13, 2022
c067a4a
libtcg: all `temp` variables are now stored separately
Jun 13, 2022
1a640a8
libtcg: fixed bug in dump function
Jun 13, 2022
5ca3d94
[TMP] linux-user: fix aarch64
Jun 13, 2022
30ef543
Emit libtcg-helpers-$ARCH.bc
Sep 1, 2022
4353e18
libtcg: add size_in_bytes field to LibTcgInstructionList
Jul 18, 2022
e1d3f72
libtcg: add cast to silence warnings
Jul 18, 2022
3d8e174
libtcg: add LibTcgInterface struct containing func. ptrs
Jul 18, 2022
b9228a3
libtcg: add more interface expected by revng
Aug 20, 2022
d0a1892
[TMP] linux-user: glibc 2.13 compatability patch
Aug 30, 2022
1739b7e
libtcg: expose libtcg_dump_instruction_to_buffer
Sep 19, 2022
6354827
libtcg: set TB flags
Sep 19, 2022
e1ec6d9
libtc: check result of `mem_alloc`
Sep 19, 2022
55f04e6
Add `max_pc`
Oct 31, 2022
f5aade4
libtcg: change prefix tinycode -> libtcg
Oct 31, 2022
109b24d
libtcg: expose helper info/instruction name through dlopen API
Jul 18, 2024
9ba67dd
[post-rebase-fix] libtcg: added missing temp type
Nov 22, 2022
6101e19
[for-revng] [TMP] linux-user: Workaround for old linux-headers in orc…
Jan 11, 2023
bc6ea7f
libtcg: add flags to libtcg_translate() for ARM_THUMB
Feb 14, 2023
6f62ea5
libtcg: expose env offset and target ArchCPU name
Feb 9, 2024
9dc0a57
Add cpp as build language, exclude subdirs when building libtcg
Feb 9, 2024
4af93f1
libtcg: rebase
Feb 9, 2024
01a37ef
libtcg: Allocate TB more carefully
Mar 4, 2024
6d574a2
[post-rebase-fix] libtcg: update enums and macros to match QEMU
Jul 18, 2024
7d9fdd1
[TMP] libtcg: dum_tinycode_inst* comment
Jul 18, 2024
a7c816b
libtcg: set Hexagon version via ELF flags
Jul 18, 2024
9173462
libtcg: translate start_address
Jul 18, 2024
238385a
libtcg: set TB used for code generation
Jul 18, 2024
c8848e8
libtcg: add Hexagon and Loongarch CPU fields
Jul 18, 2024
d2a0006
[for-revng] linux-user: abort on forking
Jul 18, 2024
e6e2796
[TMP] [for-revng] target/hexagon: replace cpu_loop_exit_restore
Jul 18, 2024
36e53dc
libtcg: refactor memory access functions
Jul 17, 2024
c8c55d2
tcg: disable vector and i128 support for backends
Jul 17, 2024
b9a46c8
libtcg: assert room in buffer
Apr 19, 2024
e8bd139
libtcg: remove startaddress arg. from translate
May 10, 2024
3eb519d
[TMP] hexagon: idef parser fix mem leak
May 10, 2024
94cfa3e
[TMP] target/s390x: don't translate past end of buffer
May 10, 2024
718d6a4
libtcg: minor formatting fix
Jun 15, 2024
6a4e23c
[post-rebase-fix] libtcg: handle negsetcond
Jun 15, 2024
70395f3
[for-revng]: comment out non-csaa-able stuff
Jun 15, 2024
9ecd926
libtcg: expose bp register
Jul 17, 2024
8225bf7
libtcg: update names
Jul 17, 2024
913f8cd
libtcg: introduce get_arch_info
Jul 17, 2024
f7bee35
libtcg: rename
Jul 17, 2024
e0cfa7b
libtcg: allow for specifying alloc/free funcs. separately
Jul 17, 2024
67a4662
libtcg: add optimization and helper-to-tcg translation flags
Jul 17, 2024
fefdfa3
libtcg: fix translation loop
Jul 17, 2024
59ea55b
libtcg: more string dumping functions
Jul 17, 2024
dfeaf46
libtcg: split instruction printing function
Jul 17, 2024
d29a8db
tcg: don't constant propagate through registers
Jul 17, 2024
0b35194
target/cris: siglongjmp on translation bug
Jul 17, 2024
e883c50
target/hexagon: siglongjmp on lifting failure
Jul 17, 2024
80669b0
target/hexagon: disable instruction and packet counting
Jul 17, 2024
c730fb2
libtcg: introduce libtcg-loader
Jul 17, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 20 additions & 35 deletions accel/tcg/translator.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

static void set_can_do_io(DisasContextBase *db, bool val)
{
#ifndef CONFIG_LIBTCG
if (db->saved_can_do_io != val) {
db->saved_can_do_io = val;

Expand All @@ -26,6 +27,7 @@ static void set_can_do_io(DisasContextBase *db, bool val)
offsetof(ArchCPU, parent_obj.neg.can_do_io) -
offsetof(ArchCPU, env));
}
#endif
}

bool translator_io_start(DisasContextBase *db)
Expand Down Expand Up @@ -129,7 +131,9 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
{
uint32_t cflags = tb_cflags(tb);
TCGOp *icount_start_insn;
#ifndef CONFIG_LIBTCG
bool plugin_enabled;
#endif

/* Initialize DisasContext */
db->tb = tb;
Expand All @@ -148,20 +152,25 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,

/* Start translating. */
icount_start_insn = gen_tb_start(db, cflags);
#ifndef CONFIG_LIBTCG
ops->tb_start(db, cpu);
#ifndef CONFIG_LIBTCG
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */

plugin_enabled = plugin_gen_tb_start(cpu, db, cflags & CF_MEMI_ONLY);
db->plugin_enabled = plugin_enabled;
#endif

while (true) {
*max_insns = ++db->num_insns;
ops->insn_start(db, cpu);
tcg_debug_assert(db->is_jmp == DISAS_NEXT); /* no early exit */

#ifndef CONFIG_LIBTCG
if (plugin_enabled) {
plugin_gen_insn_start(cpu, db);
}
#endif

/*
* Disassemble one instruction. The translate_insn hook should
Expand All @@ -184,9 +193,11 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
* needs to see a matching plugin_gen_insn_{start,end}() pair in order
* to accurately track instrumented helpers that might access memory.
*/
#ifndef CONFIG_LIBTCG
if (plugin_enabled) {
plugin_gen_insn_end();
}
#endif

/* Stop translation if translate_insn so indicated. */
if (db->is_jmp != DISAS_NEXT) {
Expand All @@ -195,7 +206,8 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,

/* Stop translation if the output buffer is full,
or we have executed all of the allowed instructions. */
if (tcg_op_buf_full() || db->num_insns >= db->max_insns) {
if (tcg_op_buf_full() || db->num_insns >= db->max_insns ||
db->pc_next >= tb->max_pc) {
db->is_jmp = DISAS_TOO_MANY;
break;
}
Expand All @@ -205,9 +217,11 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
ops->tb_stop(db, cpu);
gen_tb_end(tb, cflags, icount_start_insn, db->num_insns);

#ifndef CONFIG_LIBTCG
if (plugin_enabled) {
plugin_gen_tb_end(cpu, db->num_insns);
}
#endif

/* The disas_log hook may use these values rather than recompute. */
tb->size = db->pc_next - db->pc_first;
Expand All @@ -225,6 +239,7 @@ void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
}
}

#ifndef CONFIG_LIBTSCG
static void *translator_access(CPUArchState *env, DisasContextBase *db,
vaddr pc, size_t len)
{
Expand Down Expand Up @@ -289,6 +304,7 @@ static void *translator_access(CPUArchState *env, DisasContextBase *db,
tcg_debug_assert(pc >= base);
return host + (pc - base);
}
#endif

static void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
{
Expand All @@ -314,59 +330,28 @@ static void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
{
uint8_t ret;
void *p = translator_access(env, db, pc, sizeof(ret));

if (p) {
plugin_insn_append(pc, p, sizeof(ret));
return ldub_p(p);
}
ret = cpu_ldub_code(env, pc);
plugin_insn_append(pc, &ret, sizeof(ret));
return ret;
}

uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
{
uint16_t ret, plug;
void *p = translator_access(env, db, pc, sizeof(ret));

if (p) {
plugin_insn_append(pc, p, sizeof(ret));
return lduw_p(p);
}
uint16_t ret;
ret = cpu_lduw_code(env, pc);
plug = tswap16(ret);
plugin_insn_append(pc, &plug, sizeof(ret));
return ret;
}

uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
{
uint32_t ret, plug;
void *p = translator_access(env, db, pc, sizeof(ret));

if (p) {
plugin_insn_append(pc, p, sizeof(ret));
return ldl_p(p);
}
uint32_t ret;
ret = cpu_ldl_code(env, pc);
plug = tswap32(ret);
plugin_insn_append(pc, &plug, sizeof(ret));
return ret;
}

uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
{
uint64_t ret, plug;
void *p = translator_access(env, db, pc, sizeof(ret));

if (p) {
plugin_insn_append(pc, p, sizeof(ret));
return ldq_p(p);
}
uint64_t ret;
ret = cpu_ldq_code(env, pc);
plug = tswap64(ret);
plugin_insn_append(pc, &plug, sizeof(ret));
return ret;
}

Expand Down
2 changes: 2 additions & 0 deletions accel/tcg/user-exec.c
Original file line number Diff line number Diff line change
Expand Up @@ -1121,6 +1121,7 @@ static void do_st16_mmu(CPUState *cpu, vaddr addr, Int128 val,
clear_helper_retaddr();
}

#ifndef CONFIG_LIBTCG
uint32_t cpu_ldub_code(CPUArchState *env, abi_ptr ptr)
{
uint32_t ret;
Expand Down Expand Up @@ -1160,6 +1161,7 @@ uint64_t cpu_ldq_code(CPUArchState *env, abi_ptr ptr)
clear_helper_retaddr();
return ret;
}
#endif

uint8_t cpu_ldb_code_mmu(CPUArchState *env, abi_ptr addr,
MemOpIdx oi, uintptr_t ra)
Expand Down
6 changes: 6 additions & 0 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -733,6 +733,10 @@ for opt do
;;
--enable-bsd-user) bsd_user="yes"
;;
--disable-libtcg) libtcg="no"
;;
--enable-libtcg) libtcg="yes"; linux_user="yes";
;;
--enable-pie) pie="yes"
;;
--disable-pie) pie="no"
Expand Down Expand Up @@ -1828,6 +1832,8 @@ if test "$skip_meson" = no; then
test -n "${LIB_FUZZING_ENGINE+xxx}" && meson_option_add "-Dfuzzing_engine=$LIB_FUZZING_ENGINE"
test "$plugins" = yes && meson_option_add "-Dplugins=true"
test "$tcg" != enabled && meson_option_add "-Dtcg=$tcg"
test "$libtcg" = yes && meson_option_add -Dlibtcg=true
test "$libtcg" = yes && meson_option_add -Db_staticpic=true
run_meson() {
NINJA=$ninja $meson setup "$@" "$PWD" "$source_path"
}
Expand Down
2 changes: 2 additions & 0 deletions include/exec/translation-block.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ struct TranslationBlock {
*/
uint64_t cs_base;

vaddr max_pc; /* maximum PC for this block */

uint32_t flags; /* flags defining in which context the code was generated */
uint32_t cflags; /* compile flags */

Expand Down
Loading
Loading