[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH v3 02/35] translate: Listify tcg_exec_init()
From: |
Peter Crosthwaite |
Subject: |
[Qemu-devel] [PATCH v3 02/35] translate: Listify tcg_exec_init() |
Date: |
Sat, 18 Jul 2015 02:40:12 -0700 |
Create a global list of tcg_exec_init() functions that is populated at
startup. Multiple translation engines can register an init function
and all will be called on the master call to tcg_exec_init().
Introduce a new module, translate-common. This is a common-obj for
translation functionality such as this.
Signed-off-by: Peter Crosthwaite <address@hidden>
Reviewed-by: Richard Henderson <address@hidden>
---
Changed since RFCv2
Move to obj-y (needed by linux-user)
---
Makefile.target | 1 +
include/qemu-common.h | 1 +
translate-all.c | 7 ++++++-
translate-common.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
4 files changed, 58 insertions(+), 1 deletion(-)
create mode 100644 translate-common.c
diff --git a/Makefile.target b/Makefile.target
index 6435c96..7dc6d0c 100644
--- a/Makefile.target
+++ b/Makefile.target
@@ -85,6 +85,7 @@ all: $(PROGS) stap
#########################################################
# cpu emulator library
obj-y = exec.o translate-all.o cpu-exec.o
+obj-y += translate-common.o
obj-y += cpu-exec-common.o
obj-y += tcg/tcg.o tcg/tcg-op.o tcg/optimize.o
obj-$(CONFIG_TCG_INTERPRETER) += tci.o
diff --git a/include/qemu-common.h b/include/qemu-common.h
index 237d654..4ac8e6f 100644
--- a/include/qemu-common.h
+++ b/include/qemu-common.h
@@ -267,6 +267,7 @@ typedef struct PCIHostDeviceAddress {
unsigned int function;
} PCIHostDeviceAddress;
+void tcg_exec_init_add(void (*fn)(unsigned long));
void tcg_exec_init(unsigned long tb_size);
bool tcg_enabled(void);
diff --git a/translate-all.c b/translate-all.c
index 60a3d8b..27f5d9c 100644
--- a/translate-all.c
+++ b/translate-all.c
@@ -680,7 +680,7 @@ static inline void code_gen_alloc(size_t tb_size)
/* Must be called before using the QEMU cpus. 'tb_size' is the size
(in bytes) allocated to the translation buffer. Zero means default
size. */
-void tcg_exec_init(unsigned long tb_size)
+static void do_tcg_exec_init(unsigned long tb_size)
{
cpu_gen_init();
code_gen_alloc(tb_size);
@@ -694,6 +694,11 @@ void tcg_exec_init(unsigned long tb_size)
#endif
}
+static __attribute__((constructor)) void register_tcg_exec_init(void)
+{
+ tcg_exec_init_add(do_tcg_exec_init);
+}
+
bool tcg_enabled(void)
{
return tcg_ctx.code_gen_buffer != NULL;
diff --git a/translate-common.c b/translate-common.c
new file mode 100644
index 0000000..563ae5a
--- /dev/null
+++ b/translate-common.c
@@ -0,0 +1,50 @@
+/*
+ * Host code generation common components
+ *
+ * Copyright (c) 2015 Peter Crosthwaite <address@hidden>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>.
+ */
+
+#include "qemu-common.h"
+
+typedef struct TCGExecInitFn {
+ void (*do_tcg_exec_init)(unsigned long tb_size);
+ QLIST_ENTRY(TCGExecInitFn) list;
+} TCGExecInitFn;
+
+static QLIST_HEAD(, TCGExecInitFn) tcg_exec_init_list;
+
+void tcg_exec_init_add(void (*fn)(unsigned long))
+{
+ static bool inited;
+ TCGExecInitFn *lelem = g_malloc0(sizeof *lelem);
+
+ if (!inited) {
+ inited = true;
+ QLIST_INIT(&tcg_exec_init_list);
+ }
+
+ lelem->do_tcg_exec_init = fn;
+ QLIST_INSERT_HEAD(&tcg_exec_init_list, lelem, list);
+}
+
+void tcg_exec_init(unsigned long tb_size)
+{
+ TCGExecInitFn *t;
+
+ QLIST_FOREACH(t, &tcg_exec_init_list, list) {
+ t->do_tcg_exec_init(tb_size);
+ }
+}
--
1.9.1
- [Qemu-devel] [PATCH v3 00/35] Multi Architecture System Emulation, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 01/35] cpu-exec: Migrate some generic fns to cpu-exec-common, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 02/35] translate: Listify tcg_exec_init(),
Peter Crosthwaite <=
- [Qemu-devel] [PATCH v3 03/35] translate-all: Move tcg_handle_interrupt() to -common, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 04/35] tcg: split tcg_op_defs to -common, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 05/35] tcg: Move tcg_tb_ptr to -common, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 06/35] translate: move real_host_page setting to -common, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 07/35] cpus: Listify cpu_list() function, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 08/35] translate-common: Listify tcg_enabled(), Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 09/35] core: Convert tcg_enabled() users to tcg_(any|all)_enabled(), Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 10/35] exec-all: Move cpu_can_do_io() to qom/cpu.h, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 11/35] cputlb: move CPU_LOOP() for tlb_reset() to exec.c, Peter Crosthwaite, 2015/07/18
- [Qemu-devel] [PATCH v3 12/35] cputlb: Change tlb_set_dirty() arg to cpu, Peter Crosthwaite, 2015/07/18