l = &s->labels[label_index];
if (l->has_value) {
+ /* FIXME: This is wrong. We can not resolve the relocation
+ immediately because the caller has not yet written the
+ initial value. */
patch_reloc(code_ptr, type, l->u.value + addend);
} else {
/* add a new relocation entry */
static inline int tcg_gen_code_common(TCGContext *s, uint8_t *gen_code_buf,
- int do_search_pc,
- const uint8_t *searched_pc)
+ long search_pc)
{
int opc, op_index, macro_op_index;
const TCGOpDef *def;
}
#endif
tcg_reg_alloc_bb_end(s);
- if (do_search_pc) {
+ if (search_pc >= 0) {
s->code_ptr += def->copy_size;
args += def->nb_args;
} else {
}
args += def->nb_args;
next: ;
- if (do_search_pc) {
- if (searched_pc < s->code_ptr) {
- if (macro_op_index >= 0)
- return macro_op_index;
- else
- return op_index;
- }
+ if (search_pc >= 0 && search_pc < s->code_ptr - gen_code_buf) {
+ if (macro_op_index >= 0)
+ return macro_op_index;
+ else
+ return op_index;
}
op_index++;
#ifndef NDEBUG
}
#endif
- tcg_gen_code_common(s, gen_code_buf, 0, NULL);
+ tcg_gen_code_common(s, gen_code_buf, -1);
/* flush instruction cache */
flush_icache_range((unsigned long)gen_code_buf,
return s->code_ptr - gen_code_buf;
}
-/* return the index of the micro operation such as the pc after is <
- search_pc. Note: gen_code_buf is accessed during the operation, but
- its content should not be modified. Return -1 if not found. */
-int dyngen_code_search_pc(TCGContext *s, uint8_t *gen_code_buf,
- const uint8_t *searched_pc)
+static uint8_t *dummy_code_buf;
+
+/* Return the index of the micro operation such as the pc after is <
+ offset bytes from the start of the TB.
+ We have to use a dummy code buffer here to avoid clobbering the
+ oringinal code. Because we terminate code generation part way through
+ we can end up with unresolved relocations. Return -1 if not found. */
+int dyngen_code_search_pc(TCGContext *s, long offset)
{
- return tcg_gen_code_common(s, gen_code_buf, 1, searched_pc);
+ if (!dummy_code_buf)
+ dummy_code_buf = qemu_malloc(code_gen_max_block_size());
+ return tcg_gen_code_common(s, dummy_code_buf, offset);
}
void tcg_func_start(TCGContext *s);
int dyngen_code(TCGContext *s, uint8_t *gen_code_buf);
-int dyngen_code_search_pc(TCGContext *s, uint8_t *gen_code_buf,
- const uint8_t *searched_pc);
+int dyngen_code_search_pc(TCGContext *s, long offset);
void tcg_set_frame(TCGContext *s, int reg,
tcg_target_long start, tcg_target_long size);