Skip to content
Snippets Groups Projects
Commit bab456f1 authored by Anton's avatar Anton
Browse files

Initialize tb more carefully

parent 44e5a763
No related branches found
No related tags found
No related merge requests found
......@@ -17,6 +17,8 @@
#include "qemu.h"
#include "qemu/osdep.h"
#include "cpu.h"
#include "cpu-param.h"
#include "tcg/insn-start-words.h"
#include "disas/disas.h"
#include "exec/exec-all.h"
#include "exec/translator.h"
......@@ -178,9 +180,6 @@ LibTcgInstructionList libtcg_translate(LibTcgContext *context,
};
context->cpu->opaque = &region;
/* Needed to initialize fields in `tcg_ctx` */
tcg_func_start(tcg_ctx);
vaddr pc;
uint64_t cs_base;
uint32_t flags;
......@@ -210,21 +209,30 @@ LibTcgInstructionList libtcg_translate(LibTcgContext *context,
}
cflags |= CF_NO_GOTO_TB;
/*
* Initialize backend fields to avoid
* triggering asserts in tcg_func_start
* */
tcg_ctx->addr_type = TARGET_LONG_BITS == 32 ? TCG_TYPE_I32 : TCG_TYPE_I64;
tcg_ctx->insn_start_words = TARGET_INSN_START_WORDS;
/* Needed to initialize fields in `tcg_ctx` */
tcg_func_start(tcg_ctx);
/*
* Set `max_insns` to the number of bytes in the buffer
* so we don't have to worry about it being too small.
*/
int max_insns = size;
TranslationBlock tb = {
.pc = pc,
.cs_base = cs_base,
.max_pc = virtual_address + size,
.flags = flags,
.cflags = cflags,
};
TranslationBlock *tb = tcg_tb_alloc(tcg_ctx);
tb->pc = pc;
tb->cs_base = cs_base;
tb->max_pc = virtual_address + size;
tb->flags = flags;
tb->cflags = cflags;
void *host_pc = NULL;
gen_intermediate_code(context->cpu, &tb, &max_insns, pc, host_pc);
gen_intermediate_code(context->cpu, tb, &max_insns, pc, host_pc);
LibTcgInstructionList instruction_list = {
.list = context->desc.mem_alloc(sizeof(LibTcgInstruction) * tcg_ctx->nb_ops),
......@@ -237,7 +245,7 @@ LibTcgInstructionList libtcg_translate(LibTcgContext *context,
.labels = context->desc.mem_alloc(sizeof(LibTcgLabel) * (tcg_ctx->nb_labels)),
.label_count = 0,
.size_in_bytes = tb.size,
.size_in_bytes = tb->size,
};
assert(instruction_list.list != NULL &&
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment