The tcg/tcg.h header is mostly definitions that are needed only by the translate-time code in the translate/$ARCH frontends and the plugin infrastructure, or by the TCG code itself in tcg/ and accel/tcg. However there are a few functions which need to be called directly by code in linux-user and bsd-user.
Split those functions out into a separate header, so that linux-user and bsd-user don't need to include this large header which is mostly useless to them and which includes some awkward things like a 'cpu_env' global that will be shadowed if that name is used in runtime functions. Signed-off-by: Peter Maydell <peter.mayd...@linaro.org> --- (1) I haven't tested that bsd-user compiles with this change (2) Suggestions for better naming welcome. I picked 'runtime.h' with a vague idea of splitting out the parts that are only of interest to the runtime framework from the parts that are translate-time or TCG-internal. We could perhaps move a few more functions and then be able to use only this header and not tcg/tcg.h in some or all of accel/tcg. Alternatively we could say it was purely for the benefit of the user-mode code and give it a suitable name. --- include/tcg/runtime.h | 51 +++++++++++++++++++++++++++++++++++++++++++ include/tcg/tcg.h | 6 +---- bsd-user/main.c | 2 +- linux-user/main.c | 2 +- linux-user/syscall.c | 2 +- 5 files changed, 55 insertions(+), 8 deletions(-) create mode 100644 include/tcg/runtime.h diff --git a/include/tcg/runtime.h b/include/tcg/runtime.h new file mode 100644 index 00000000000..0170a871a53 --- /dev/null +++ b/include/tcg/runtime.h @@ -0,0 +1,51 @@ +/* + * Tiny Code Generator for QEMU: definitions used by runtime + * + * Copyright (c) 2008 Fabrice Bellard + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in + * all copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN + * THE SOFTWARE. + */ + +#ifndef TCG_RUNTIME_H +#define TCG_RUNTIME_H + +typedef struct TCGContext TCGContext; + +extern __thread TCGContext *tcg_ctx; + +/** + * tcg_register_thread: Register this thread with the TCG runtime + * + * All TCG threads except the parent (i.e. the one that called the TCG + * accelerator's init_machine() method) must register with this + * function before initiating translation. + */ +void tcg_register_thread(void); + +/** + * tcg_prologue_init(): generate the code for the TCG prologue + * + * In softmmu this is done automatically as part of the TCG + * accelerator's init_machine() method, but for user-mode, the + * user-mode code must call this function after it has loaded + * the guest binary and the value of guest_base is known. + */ +void tcg_prologue_init(TCGContext *s); + +#endif diff --git a/include/tcg/tcg.h b/include/tcg/tcg.h index c9c6d770d05..d2e9795ade0 100644 --- a/include/tcg/tcg.h +++ b/include/tcg/tcg.h @@ -35,6 +35,7 @@ #include "tcg-target.h" #include "tcg/tcg-cond.h" #include "tcg/debug-assert.h" +#include "tcg/runtime.h" /* XXX: make safe guess about sizes */ #define MAX_OP_PER_INSTR 266 @@ -428,8 +429,6 @@ typedef struct TCGTemp { void *state_ptr; } TCGTemp; -typedef struct TCGContext TCGContext; - typedef struct TCGTempSet { unsigned long l[BITS_TO_LONGS(TCG_MAX_TEMPS)]; } TCGTempSet; @@ -574,7 +573,6 @@ static inline bool temp_readonly(TCGTemp *ts) return ts->kind >= TEMP_FIXED; } -extern __thread TCGContext *tcg_ctx; extern const void *tcg_code_gen_epilogue; extern uintptr_t tcg_splitwx_diff; extern TCGv_env cpu_env; @@ -784,8 +782,6 @@ static inline void *tcg_malloc(int size) } void tcg_init(size_t tb_size, int splitwx, unsigned max_cpus); -void tcg_register_thread(void); -void tcg_prologue_init(TCGContext *s); void tcg_func_start(TCGContext *s); int tcg_gen_code(TCGContext *s, TranslationBlock *tb, uint64_t pc_start); diff --git a/bsd-user/main.c b/bsd-user/main.c index f913cb55a72..062870c131c 100644 --- a/bsd-user/main.c +++ b/bsd-user/main.c @@ -36,7 +36,7 @@ #include "qemu/help_option.h" #include "qemu/module.h" #include "exec/exec-all.h" -#include "tcg/tcg.h" +#include "tcg/runtime.h" #include "qemu/timer.h" #include "qemu/envlist.h" #include "qemu/cutils.h" diff --git a/linux-user/main.c b/linux-user/main.c index 96be354897d..dc9b580b24b 100644 --- a/linux-user/main.c +++ b/linux-user/main.c @@ -41,7 +41,7 @@ #include "exec/exec-all.h" #include "exec/gdbstub.h" #include "gdbstub/user.h" -#include "tcg/tcg.h" +#include "tcg/runtime.h" #include "qemu/timer.h" #include "qemu/envlist.h" #include "qemu/guest-random.h" diff --git a/linux-user/syscall.c b/linux-user/syscall.c index 3521a2d70b0..8fd7f961459 100644 --- a/linux-user/syscall.c +++ b/linux-user/syscall.c @@ -23,6 +23,7 @@ #include "qemu/memfd.h" #include "qemu/queue.h" #include "qemu/plugin.h" +#include "tcg/runtime.h" #include "target_mman.h" #include <elf.h> #include <endian.h> @@ -141,7 +142,6 @@ #include "special-errno.h" #include "qapi/error.h" #include "fd-trans.h" -#include "tcg/tcg.h" #include "cpu_loop-common.h" #ifndef CLONE_IO -- 2.34.1