xref: /qemu/accel/tcg/translator.c (revision 0ca41ccf1c555f97873b8e02a47390fd6af4b18f)
1bb2e0039SLluís Vilanova /*
2bb2e0039SLluís Vilanova  * Generic intermediate code generation.
3bb2e0039SLluís Vilanova  *
4bb2e0039SLluís Vilanova  * Copyright (C) 2016-2017 Lluís Vilanova <vilanova@ac.upc.edu>
5bb2e0039SLluís Vilanova  *
6bb2e0039SLluís Vilanova  * This work is licensed under the terms of the GNU GPL, version 2 or later.
7bb2e0039SLluís Vilanova  * See the COPYING file in the top-level directory.
8bb2e0039SLluís Vilanova  */
9bb2e0039SLluís Vilanova 
10bb2e0039SLluís Vilanova #include "qemu/osdep.h"
11653c46daSRichard Henderson #include "qemu/log.h"
12bb2e0039SLluís Vilanova #include "qemu/error-report.h"
13bb2e0039SLluís Vilanova #include "exec/exec-all.h"
14bb2e0039SLluís Vilanova #include "exec/translator.h"
156ba6f818SEmilio G. Cota #include "exec/plugin-gen.h"
16653c46daSRichard Henderson #include "tcg/tcg-op-common.h"
17deba7870SRichard Henderson #include "internal.h"
1856234233SRichard Henderson 
19*0ca41ccfSRichard Henderson static void set_can_do_io(DisasContextBase *db, bool val)
2056234233SRichard Henderson {
21*0ca41ccfSRichard Henderson     if (db->saved_can_do_io != val) {
22*0ca41ccfSRichard Henderson         db->saved_can_do_io = val;
23*0ca41ccfSRichard Henderson         tcg_gen_st_i32(tcg_constant_i32(val), cpu_env,
2456234233SRichard Henderson                        offsetof(ArchCPU, parent_obj.can_do_io) -
2556234233SRichard Henderson                        offsetof(ArchCPU, env));
2656234233SRichard Henderson     }
27*0ca41ccfSRichard Henderson }
2856234233SRichard Henderson 
29dfd1b812SRichard Henderson bool translator_io_start(DisasContextBase *db)
30dfd1b812SRichard Henderson {
31dfd1b812SRichard Henderson     uint32_t cflags = tb_cflags(db->tb);
32dfd1b812SRichard Henderson 
33dfd1b812SRichard Henderson     if (!(cflags & CF_USE_ICOUNT)) {
34dfd1b812SRichard Henderson         return false;
35dfd1b812SRichard Henderson     }
36dfd1b812SRichard Henderson 
37*0ca41ccfSRichard Henderson     set_can_do_io(db, true);
38dfd1b812SRichard Henderson 
39dfd1b812SRichard Henderson     /*
40dfd1b812SRichard Henderson      * Ensure that this instruction will be the last in the TB.
41dfd1b812SRichard Henderson      * The target may override this to something more forceful.
42dfd1b812SRichard Henderson      */
43dfd1b812SRichard Henderson     if (db->is_jmp == DISAS_NEXT) {
44dfd1b812SRichard Henderson         db->is_jmp = DISAS_TOO_MANY;
45dfd1b812SRichard Henderson     }
46dfd1b812SRichard Henderson     return true;
47dfd1b812SRichard Henderson }
48dfd1b812SRichard Henderson 
49*0ca41ccfSRichard Henderson static TCGOp *gen_tb_start(DisasContextBase *db, uint32_t cflags)
5056234233SRichard Henderson {
51f47a90daSRichard Henderson     TCGv_i32 count = NULL;
5256234233SRichard Henderson     TCGOp *icount_start_insn = NULL;
5356234233SRichard Henderson 
54f47a90daSRichard Henderson     if ((cflags & CF_USE_ICOUNT) || !(cflags & CF_NOIRQ)) {
55f47a90daSRichard Henderson         count = tcg_temp_new_i32();
5656234233SRichard Henderson         tcg_gen_ld_i32(count, cpu_env,
5756234233SRichard Henderson                        offsetof(ArchCPU, neg.icount_decr.u32) -
5856234233SRichard Henderson                        offsetof(ArchCPU, env));
59f47a90daSRichard Henderson     }
6056234233SRichard Henderson 
6156234233SRichard Henderson     if (cflags & CF_USE_ICOUNT) {
6256234233SRichard Henderson         /*
6356234233SRichard Henderson          * We emit a sub with a dummy immediate argument. Keep the insn index
6456234233SRichard Henderson          * of the sub so that we later (when we know the actual insn count)
6556234233SRichard Henderson          * can update the argument with the actual insn count.
6656234233SRichard Henderson          */
6756234233SRichard Henderson         tcg_gen_sub_i32(count, count, tcg_constant_i32(0));
6856234233SRichard Henderson         icount_start_insn = tcg_last_op();
6956234233SRichard Henderson     }
7056234233SRichard Henderson 
7156234233SRichard Henderson     /*
7256234233SRichard Henderson      * Emit the check against icount_decr.u32 to see if we should exit
7356234233SRichard Henderson      * unless we suppress the check with CF_NOIRQ. If we are using
7456234233SRichard Henderson      * icount and have suppressed interruption the higher level code
7556234233SRichard Henderson      * should have ensured we don't run more instructions than the
7656234233SRichard Henderson      * budget.
7756234233SRichard Henderson      */
7856234233SRichard Henderson     if (cflags & CF_NOIRQ) {
7956234233SRichard Henderson         tcg_ctx->exitreq_label = NULL;
8056234233SRichard Henderson     } else {
8156234233SRichard Henderson         tcg_ctx->exitreq_label = gen_new_label();
8256234233SRichard Henderson         tcg_gen_brcondi_i32(TCG_COND_LT, count, 0, tcg_ctx->exitreq_label);
8356234233SRichard Henderson     }
8456234233SRichard Henderson 
8556234233SRichard Henderson     if (cflags & CF_USE_ICOUNT) {
8656234233SRichard Henderson         tcg_gen_st16_i32(count, cpu_env,
8756234233SRichard Henderson                          offsetof(ArchCPU, neg.icount_decr.u16.low) -
8856234233SRichard Henderson                          offsetof(ArchCPU, env));
8956234233SRichard Henderson         /*
9056234233SRichard Henderson          * cpu->can_do_io is cleared automatically here at the beginning of
9156234233SRichard Henderson          * each translation block.  The cost is minimal and only paid for
9256234233SRichard Henderson          * -icount, plus it would be very easy to forget doing it in the
93*0ca41ccfSRichard Henderson          * translator.
9456234233SRichard Henderson          */
95*0ca41ccfSRichard Henderson         set_can_do_io(db, false);
9656234233SRichard Henderson     }
9756234233SRichard Henderson 
9856234233SRichard Henderson     return icount_start_insn;
9956234233SRichard Henderson }
10056234233SRichard Henderson 
10156234233SRichard Henderson static void gen_tb_end(const TranslationBlock *tb, uint32_t cflags,
10256234233SRichard Henderson                        TCGOp *icount_start_insn, int num_insns)
10356234233SRichard Henderson {
10456234233SRichard Henderson     if (cflags & CF_USE_ICOUNT) {
10556234233SRichard Henderson         /*
10656234233SRichard Henderson          * Update the num_insn immediate parameter now that we know
10756234233SRichard Henderson          * the actual insn count.
10856234233SRichard Henderson          */
10956234233SRichard Henderson         tcg_set_insn_param(icount_start_insn, 2,
11056234233SRichard Henderson                            tcgv_i32_arg(tcg_constant_i32(num_insns)));
11156234233SRichard Henderson     }
11256234233SRichard Henderson 
11356234233SRichard Henderson     if (tcg_ctx->exitreq_label) {
11456234233SRichard Henderson         gen_set_label(tcg_ctx->exitreq_label);
11556234233SRichard Henderson         tcg_gen_exit_tb(tb, TB_EXIT_REQUESTED);
11656234233SRichard Henderson     }
11756234233SRichard Henderson }
11856234233SRichard Henderson 
119b1c09220SAnton Johansson bool translator_use_goto_tb(DisasContextBase *db, vaddr dest)
120d3a2a1d8SRichard Henderson {
12184f15616SRichard Henderson     /* Suppress goto_tb if requested. */
12284f15616SRichard Henderson     if (tb_cflags(db->tb) & CF_NO_GOTO_TB) {
12384f15616SRichard Henderson         return false;
12484f15616SRichard Henderson     }
12584f15616SRichard Henderson 
126d3a2a1d8SRichard Henderson     /* Check for the dest on the same page as the start of the TB.  */
127d3a2a1d8SRichard Henderson     return ((db->pc_first ^ dest) & TARGET_PAGE_MASK) == 0;
128d3a2a1d8SRichard Henderson }
129d3a2a1d8SRichard Henderson 
130597f9b2dSRichard Henderson void translator_loop(CPUState *cpu, TranslationBlock *tb, int *max_insns,
131b1c09220SAnton Johansson                      vaddr pc, void *host_pc, const TranslatorOps *ops,
132b1c09220SAnton Johansson                      DisasContextBase *db)
133bb2e0039SLluís Vilanova {
134d40c5c79SRichard Henderson     uint32_t cflags = tb_cflags(tb);
13556234233SRichard Henderson     TCGOp *icount_start_insn;
1366ba6f818SEmilio G. Cota     bool plugin_enabled;
137f9f1f56eSPavel Dovgalyuk 
138bb2e0039SLluís Vilanova     /* Initialize DisasContext */
139bb2e0039SLluís Vilanova     db->tb = tb;
140306c8721SRichard Henderson     db->pc_first = pc;
141306c8721SRichard Henderson     db->pc_next = pc;
142bb2e0039SLluís Vilanova     db->is_jmp = DISAS_NEXT;
143bb2e0039SLluís Vilanova     db->num_insns = 0;
144597f9b2dSRichard Henderson     db->max_insns = *max_insns;
145c2ffd754SRichard Henderson     db->singlestep_enabled = cflags & CF_SINGLE_STEP;
146*0ca41ccfSRichard Henderson     db->saved_can_do_io = -1;
14750627f1bSRichard Henderson     db->host_addr[0] = host_pc;
14850627f1bSRichard Henderson     db->host_addr[1] = NULL;
14950627f1bSRichard Henderson 
150b542683dSEmilio G. Cota     ops->init_disas_context(db, cpu);
151bb2e0039SLluís Vilanova     tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
152bb2e0039SLluís Vilanova 
153bb2e0039SLluís Vilanova     /* Start translating.  */
154*0ca41ccfSRichard Henderson     icount_start_insn = gen_tb_start(db, cflags);
155bb2e0039SLluís Vilanova     ops->tb_start(db, cpu);
156bb2e0039SLluís Vilanova     tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
157bb2e0039SLluís Vilanova 
1585d97e946SRichard Henderson     if (cflags & CF_MEMI_ONLY) {
1595d97e946SRichard Henderson         /* We should only see CF_MEMI_ONLY for io_recompile. */
1605d97e946SRichard Henderson         assert(cflags & CF_LAST_IO);
1615d97e946SRichard Henderson         plugin_enabled = plugin_gen_tb_start(cpu, db, true);
1625d97e946SRichard Henderson     } else {
1635d97e946SRichard Henderson         plugin_enabled = plugin_gen_tb_start(cpu, db, false);
1645d97e946SRichard Henderson     }
1656ba6f818SEmilio G. Cota 
166bb2e0039SLluís Vilanova     while (true) {
1679b1890adSRichard Henderson         *max_insns = ++db->num_insns;
168bb2e0039SLluís Vilanova         ops->insn_start(db, cpu);
169bb2e0039SLluís Vilanova         tcg_debug_assert(db->is_jmp == DISAS_NEXT);  /* no early exit */
170bb2e0039SLluís Vilanova 
1716ba6f818SEmilio G. Cota         if (plugin_enabled) {
1726ba6f818SEmilio G. Cota             plugin_gen_insn_start(cpu, db);
1736ba6f818SEmilio G. Cota         }
1746ba6f818SEmilio G. Cota 
175bb2e0039SLluís Vilanova         /* Disassemble one instruction.  The translate_insn hook should
176bb2e0039SLluís Vilanova            update db->pc_next and db->is_jmp to indicate what should be
177bb2e0039SLluís Vilanova            done next -- either exiting this loop or locate the start of
178bb2e0039SLluís Vilanova            the next instruction.  */
179d40c5c79SRichard Henderson         if (db->num_insns == db->max_insns && (cflags & CF_LAST_IO)) {
180bb2e0039SLluís Vilanova             /* Accept I/O on the last instruction.  */
181*0ca41ccfSRichard Henderson             set_can_do_io(db, true);
182bb2e0039SLluís Vilanova         }
1835d97e946SRichard Henderson         ops->translate_insn(db, cpu);
184bb2e0039SLluís Vilanova 
1856ba6f818SEmilio G. Cota         /*
1866ba6f818SEmilio G. Cota          * We can't instrument after instructions that change control
1876ba6f818SEmilio G. Cota          * flow although this only really affects post-load operations.
1880f92d94aSEmilio Cota          *
1890f92d94aSEmilio Cota          * Calling plugin_gen_insn_end() before we possibly stop translation
1900f92d94aSEmilio Cota          * is important. Even if this ends up as dead code, plugin generation
1910f92d94aSEmilio Cota          * needs to see a matching plugin_gen_insn_{start,end}() pair in order
1920f92d94aSEmilio Cota          * to accurately track instrumented helpers that might access memory.
1936ba6f818SEmilio G. Cota          */
1946ba6f818SEmilio G. Cota         if (plugin_enabled) {
1956ba6f818SEmilio G. Cota             plugin_gen_insn_end();
1966ba6f818SEmilio G. Cota         }
1976ba6f818SEmilio G. Cota 
1980f92d94aSEmilio Cota         /* Stop translation if translate_insn so indicated.  */
1990f92d94aSEmilio Cota         if (db->is_jmp != DISAS_NEXT) {
2000f92d94aSEmilio Cota             break;
2010f92d94aSEmilio Cota         }
2020f92d94aSEmilio Cota 
203bb2e0039SLluís Vilanova         /* Stop translation if the output buffer is full,
204bb2e0039SLluís Vilanova            or we have executed all of the allowed instructions.  */
205b542683dSEmilio G. Cota         if (tcg_op_buf_full() || db->num_insns >= db->max_insns) {
206bb2e0039SLluís Vilanova             db->is_jmp = DISAS_TOO_MANY;
207bb2e0039SLluís Vilanova             break;
208bb2e0039SLluís Vilanova         }
209bb2e0039SLluís Vilanova     }
210bb2e0039SLluís Vilanova 
211bb2e0039SLluís Vilanova     /* Emit code to exit the TB, as indicated by db->is_jmp.  */
212bb2e0039SLluís Vilanova     ops->tb_stop(db, cpu);
21356234233SRichard Henderson     gen_tb_end(tb, cflags, icount_start_insn, db->num_insns);
214bb2e0039SLluís Vilanova 
2156ba6f818SEmilio G. Cota     if (plugin_enabled) {
2166ba6f818SEmilio G. Cota         plugin_gen_tb_end(cpu);
2176ba6f818SEmilio G. Cota     }
2186ba6f818SEmilio G. Cota 
219bb2e0039SLluís Vilanova     /* The disas_log hook may use these values rather than recompute.  */
220d9971435SRichard Henderson     tb->size = db->pc_next - db->pc_first;
221d9971435SRichard Henderson     tb->icount = db->num_insns;
222bb2e0039SLluís Vilanova 
223bb2e0039SLluís Vilanova     if (qemu_loglevel_mask(CPU_LOG_TB_IN_ASM)
224bb2e0039SLluís Vilanova         && qemu_log_in_addr_range(db->pc_first)) {
225c60f599bSRichard Henderson         FILE *logfile = qemu_log_trylock();
22678b54858SRichard Henderson         if (logfile) {
22778b54858SRichard Henderson             fprintf(logfile, "----------------\n");
2288eb806a7SRichard Henderson             ops->disas_log(db, cpu, logfile);
22978b54858SRichard Henderson             fprintf(logfile, "\n");
230fc59d2d8SRobert Foley             qemu_log_unlock(logfile);
231bb2e0039SLluís Vilanova         }
23278b54858SRichard Henderson     }
233bb2e0039SLluís Vilanova }
234f025692cSIlya Leoshkevich 
23550627f1bSRichard Henderson static void *translator_access(CPUArchState *env, DisasContextBase *db,
236b1c09220SAnton Johansson                                vaddr pc, size_t len)
237f025692cSIlya Leoshkevich {
23850627f1bSRichard Henderson     void *host;
239b1c09220SAnton Johansson     vaddr base, end;
24050627f1bSRichard Henderson     TranslationBlock *tb;
24150627f1bSRichard Henderson 
24250627f1bSRichard Henderson     tb = db->tb;
24350627f1bSRichard Henderson 
24450627f1bSRichard Henderson     /* Use slow path if first page is MMIO. */
24528905cfbSRichard Henderson     if (unlikely(tb_page_addr0(tb) == -1)) {
24650627f1bSRichard Henderson         return NULL;
24750627f1bSRichard Henderson     }
24850627f1bSRichard Henderson 
24950627f1bSRichard Henderson     end = pc + len - 1;
25050627f1bSRichard Henderson     if (likely(is_same_page(db, end))) {
25150627f1bSRichard Henderson         host = db->host_addr[0];
25250627f1bSRichard Henderson         base = db->pc_first;
25350627f1bSRichard Henderson     } else {
25450627f1bSRichard Henderson         host = db->host_addr[1];
25550627f1bSRichard Henderson         base = TARGET_PAGE_ALIGN(db->pc_first);
25650627f1bSRichard Henderson         if (host == NULL) {
257deba7870SRichard Henderson             tb_page_addr_t page0, old_page1, new_page1;
258deba7870SRichard Henderson 
259deba7870SRichard Henderson             new_page1 = get_page_addr_code_hostp(env, base, &db->host_addr[1]);
2602627e452SRichard Henderson 
2612627e452SRichard Henderson             /*
2622627e452SRichard Henderson              * If the second page is MMIO, treat as if the first page
2632627e452SRichard Henderson              * was MMIO as well, so that we do not cache the TB.
2642627e452SRichard Henderson              */
265deba7870SRichard Henderson             if (unlikely(new_page1 == -1)) {
266deba7870SRichard Henderson                 tb_unlock_pages(tb);
2672627e452SRichard Henderson                 tb_set_page_addr0(tb, -1);
2682627e452SRichard Henderson                 return NULL;
2692627e452SRichard Henderson             }
2702627e452SRichard Henderson 
271deba7870SRichard Henderson             /*
272deba7870SRichard Henderson              * If this is not the first time around, and page1 matches,
273deba7870SRichard Henderson              * then we already have the page locked.  Alternately, we're
274deba7870SRichard Henderson              * not doing anything to prevent the PTE from changing, so
275deba7870SRichard Henderson              * we might wind up with a different page, requiring us to
276deba7870SRichard Henderson              * re-do the locking.
277deba7870SRichard Henderson              */
278deba7870SRichard Henderson             old_page1 = tb_page_addr1(tb);
279deba7870SRichard Henderson             if (likely(new_page1 != old_page1)) {
280deba7870SRichard Henderson                 page0 = tb_page_addr0(tb);
281deba7870SRichard Henderson                 if (unlikely(old_page1 != -1)) {
282deba7870SRichard Henderson                     tb_unlock_page1(page0, old_page1);
283deba7870SRichard Henderson                 }
284deba7870SRichard Henderson                 tb_set_page_addr1(tb, new_page1);
285deba7870SRichard Henderson                 tb_lock_page1(page0, new_page1);
286deba7870SRichard Henderson             }
28750627f1bSRichard Henderson             host = db->host_addr[1];
288f025692cSIlya Leoshkevich         }
289f025692cSIlya Leoshkevich 
29050627f1bSRichard Henderson         /* Use slow path when crossing pages. */
29150627f1bSRichard Henderson         if (is_same_page(db, pc)) {
29250627f1bSRichard Henderson             return NULL;
29350627f1bSRichard Henderson         }
294f025692cSIlya Leoshkevich     }
295f025692cSIlya Leoshkevich 
29650627f1bSRichard Henderson     tcg_debug_assert(pc >= base);
29750627f1bSRichard Henderson     return host + (pc - base);
29850627f1bSRichard Henderson }
299f025692cSIlya Leoshkevich 
300bc54ef8cSRichard Henderson static void plugin_insn_append(abi_ptr pc, const void *from, size_t size)
301bc54ef8cSRichard Henderson {
302bc54ef8cSRichard Henderson #ifdef CONFIG_PLUGIN
303bc54ef8cSRichard Henderson     struct qemu_plugin_insn *insn = tcg_ctx->plugin_insn;
304bc54ef8cSRichard Henderson     abi_ptr off;
305bc54ef8cSRichard Henderson 
306bc54ef8cSRichard Henderson     if (insn == NULL) {
307bc54ef8cSRichard Henderson         return;
308bc54ef8cSRichard Henderson     }
309bc54ef8cSRichard Henderson     off = pc - insn->vaddr;
310bc54ef8cSRichard Henderson     if (off < insn->data->len) {
311bc54ef8cSRichard Henderson         g_byte_array_set_size(insn->data, off);
312bc54ef8cSRichard Henderson     } else if (off > insn->data->len) {
313bc54ef8cSRichard Henderson         /* we have an unexpected gap */
314bc54ef8cSRichard Henderson         g_assert_not_reached();
315bc54ef8cSRichard Henderson     }
316bc54ef8cSRichard Henderson 
317bc54ef8cSRichard Henderson     insn->data = g_byte_array_append(insn->data, from, size);
318bc54ef8cSRichard Henderson #endif
319bc54ef8cSRichard Henderson }
320bc54ef8cSRichard Henderson 
32150627f1bSRichard Henderson uint8_t translator_ldub(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
32250627f1bSRichard Henderson {
32350627f1bSRichard Henderson     uint8_t ret;
32450627f1bSRichard Henderson     void *p = translator_access(env, db, pc, sizeof(ret));
32550627f1bSRichard Henderson 
32650627f1bSRichard Henderson     if (p) {
32750627f1bSRichard Henderson         plugin_insn_append(pc, p, sizeof(ret));
32850627f1bSRichard Henderson         return ldub_p(p);
32950627f1bSRichard Henderson     }
33050627f1bSRichard Henderson     ret = cpu_ldub_code(env, pc);
33150627f1bSRichard Henderson     plugin_insn_append(pc, &ret, sizeof(ret));
33250627f1bSRichard Henderson     return ret;
33350627f1bSRichard Henderson }
33450627f1bSRichard Henderson 
33550627f1bSRichard Henderson uint16_t translator_lduw(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
33650627f1bSRichard Henderson {
33750627f1bSRichard Henderson     uint16_t ret, plug;
33850627f1bSRichard Henderson     void *p = translator_access(env, db, pc, sizeof(ret));
33950627f1bSRichard Henderson 
34050627f1bSRichard Henderson     if (p) {
34150627f1bSRichard Henderson         plugin_insn_append(pc, p, sizeof(ret));
34250627f1bSRichard Henderson         return lduw_p(p);
34350627f1bSRichard Henderson     }
34450627f1bSRichard Henderson     ret = cpu_lduw_code(env, pc);
34550627f1bSRichard Henderson     plug = tswap16(ret);
34650627f1bSRichard Henderson     plugin_insn_append(pc, &plug, sizeof(ret));
34750627f1bSRichard Henderson     return ret;
34850627f1bSRichard Henderson }
34950627f1bSRichard Henderson 
35050627f1bSRichard Henderson uint32_t translator_ldl(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
35150627f1bSRichard Henderson {
35250627f1bSRichard Henderson     uint32_t ret, plug;
35350627f1bSRichard Henderson     void *p = translator_access(env, db, pc, sizeof(ret));
35450627f1bSRichard Henderson 
35550627f1bSRichard Henderson     if (p) {
35650627f1bSRichard Henderson         plugin_insn_append(pc, p, sizeof(ret));
35750627f1bSRichard Henderson         return ldl_p(p);
35850627f1bSRichard Henderson     }
35950627f1bSRichard Henderson     ret = cpu_ldl_code(env, pc);
36050627f1bSRichard Henderson     plug = tswap32(ret);
36150627f1bSRichard Henderson     plugin_insn_append(pc, &plug, sizeof(ret));
36250627f1bSRichard Henderson     return ret;
36350627f1bSRichard Henderson }
36450627f1bSRichard Henderson 
36550627f1bSRichard Henderson uint64_t translator_ldq(CPUArchState *env, DisasContextBase *db, abi_ptr pc)
36650627f1bSRichard Henderson {
36750627f1bSRichard Henderson     uint64_t ret, plug;
36850627f1bSRichard Henderson     void *p = translator_access(env, db, pc, sizeof(ret));
36950627f1bSRichard Henderson 
37050627f1bSRichard Henderson     if (p) {
37150627f1bSRichard Henderson         plugin_insn_append(pc, p, sizeof(ret));
37250627f1bSRichard Henderson         return ldq_p(p);
37350627f1bSRichard Henderson     }
37450627f1bSRichard Henderson     ret = cpu_ldq_code(env, pc);
37550627f1bSRichard Henderson     plug = tswap64(ret);
37650627f1bSRichard Henderson     plugin_insn_append(pc, &plug, sizeof(ret));
37750627f1bSRichard Henderson     return ret;
37850627f1bSRichard Henderson }
379309e014dSRichard Henderson 
380309e014dSRichard Henderson void translator_fake_ldb(uint8_t insn8, abi_ptr pc)
381309e014dSRichard Henderson {
382309e014dSRichard Henderson     plugin_insn_append(pc, &insn8, sizeof(insn8));
383309e014dSRichard Henderson }
384