tcg-dyngen.c
来自「xen虚拟机源代码安装包」· C语言 代码 · 共 535 行 · 第 1/2 页
C
535 行
}static inline void ia64_patch_imm60 (uint64_t insn_addr, uint64_t val){ ia64_patch(insn_addr, 0x011ffffe000UL, ( ((val & 0x0800000000000000UL) >> 23) /* bit 59 -> 36 */ | ((val & 0x00000000000fffffUL) << 13) /* bit 0 -> 13 */)); ia64_patch(insn_addr - 1, 0x1fffffffffcUL, val >> 18);}static inline void ia64_imm64 (void *insn, uint64_t val){ /* Ignore the slot number of the relocation; GCC and Intel toolchains differed for some time on whether IMM64 relocs are against slot 1 (Intel) or slot 2 (GCC). */ uint64_t insn_addr = (uint64_t) insn & ~3UL; ia64_patch(insn_addr + 2, 0x01fffefe000UL, ( ((val & 0x8000000000000000UL) >> 27) /* bit 63 -> 36 */ | ((val & 0x0000000000200000UL) << 0) /* bit 21 -> 21 */ | ((val & 0x00000000001f0000UL) << 6) /* bit 16 -> 22 */ | ((val & 0x000000000000ff80UL) << 20) /* bit 7 -> 27 */ | ((val & 0x000000000000007fUL) << 13) /* bit 0 -> 13 */) ); ia64_patch(insn_addr + 1, 0x1ffffffffffUL, val >> 22);}static inline void ia64_imm60b (void *insn, uint64_t val){ /* Ignore the slot number of the relocation; GCC and Intel toolchains differed for some time on whether IMM64 relocs are against slot 1 (Intel) or slot 2 (GCC). */ uint64_t insn_addr = (uint64_t) insn & ~3UL; if (val + ((uint64_t) 1 << 59) >= (1UL << 60)) fprintf(stderr, "%s: value %ld out of IMM60 range\n", __FUNCTION__, (int64_t) val); ia64_patch_imm60(insn_addr + 2, val);}static inline void ia64_imm22 (void *insn, uint64_t val){ if (val + (1 << 21) >= (1 << 22)) fprintf(stderr, "%s: value %li out of IMM22 range\n", __FUNCTION__, (int64_t)val); ia64_patch((uint64_t) insn, 0x01fffcfe000UL, ( ((val & 0x200000UL) << 15) /* bit 21 -> 36 */ | ((val & 0x1f0000UL) << 6) /* bit 16 -> 22 */ | ((val & 0x00ff80UL) << 20) /* bit 7 -> 27 */ | ((val & 0x00007fUL) << 13) /* bit 0 -> 13 */));}/* Like ia64_imm22(), but also clear bits 20-21. For addl, this has the effect of turning "addl rX=imm22,rY" into "addl rX=imm22,r0". */static inline void ia64_imm22_r0 (void *insn, uint64_t val){ if (val + (1 << 21) >= (1 << 22)) fprintf(stderr, "%s: value %li out of IMM22 range\n", __FUNCTION__, (int64_t)val); ia64_patch((uint64_t) insn, 0x01fffcfe000UL | (0x3UL << 20), ( ((val & 0x200000UL) << 15) /* bit 21 -> 36 */ | ((val & 0x1f0000UL) << 6) /* bit 16 -> 22 */ | ((val & 0x00ff80UL) << 20) /* bit 7 -> 27 */ | ((val & 0x00007fUL) << 13) /* bit 0 -> 13 */));}static inline void ia64_imm21b (void *insn, uint64_t val){ if (val + (1 << 20) >= (1 << 21)) fprintf(stderr, "%s: value %li out of IMM21b range\n", __FUNCTION__, (int64_t)val); ia64_patch((uint64_t) insn, 0x11ffffe000UL, ( ((val & 0x100000UL) << 16) /* bit 20 -> 36 */ | ((val & 0x0fffffUL) << 13) /* bit 0 -> 13 */));}static inline void ia64_nop_b (void *insn){ ia64_patch((uint64_t) insn, (1UL << 41) - 1, 2UL << 37);}static inline void ia64_ldxmov(void *insn, uint64_t val){ if (val + (1 << 21) < (1 << 22)) ia64_patch((uint64_t) insn, 0x1fff80fe000UL, 8UL << 37);}static inline int ia64_patch_ltoff(void *insn, uint64_t val, int relaxable){ if (relaxable && (val + (1 << 21) < (1 << 22))) { ia64_imm22_r0(insn, val); return 0; } return 1;}struct ia64_fixup { struct ia64_fixup *next; void *addr; /* address that needs to be patched */ long value;};#define IA64_PLT(insn, plt_index) \do { \ struct ia64_fixup *fixup = alloca(sizeof(*fixup)); \ fixup->next = plt_fixes; \ plt_fixes = fixup; \ fixup->addr = (insn); \ fixup->value = (plt_index); \ plt_offset[(plt_index)] = 1; \} while (0)#define IA64_LTOFF(insn, val, relaxable) \do { \ if (ia64_patch_ltoff(insn, val, relaxable)) { \ struct ia64_fixup *fixup = alloca(sizeof(*fixup)); \ fixup->next = ltoff_fixes; \ ltoff_fixes = fixup; \ fixup->addr = (insn); \ fixup->value = (val); \ } \} while (0)static inline void ia64_apply_fixes (uint8_t **gen_code_pp, struct ia64_fixup *ltoff_fixes, uint64_t gp, struct ia64_fixup *plt_fixes, int num_plts, unsigned long *plt_target, unsigned int *plt_offset){ static const uint8_t plt_bundle[] = { 0x04, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* nop 0; movl r1=GP */ 0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x60, 0x05, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, 0x00, /* nop 0; brl IP */ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc0 }; uint8_t *gen_code_ptr = *gen_code_pp, *plt_start, *got_start; uint64_t *vp; struct ia64_fixup *fixup; unsigned int offset = 0; struct fdesc { long ip; long gp; } *fdesc; int i; if (plt_fixes) { plt_start = gen_code_ptr; for (i = 0; i < num_plts; ++i) { if (plt_offset[i]) { plt_offset[i] = offset; offset += sizeof(plt_bundle); fdesc = (struct fdesc *) plt_target[i]; memcpy(gen_code_ptr, plt_bundle, sizeof(plt_bundle)); ia64_imm64 (gen_code_ptr + 0x02, fdesc->gp); ia64_imm60b(gen_code_ptr + 0x12, (fdesc->ip - (long) (gen_code_ptr + 0x10)) >> 4); gen_code_ptr += sizeof(plt_bundle); } } for (fixup = plt_fixes; fixup; fixup = fixup->next) ia64_imm21b(fixup->addr, ((long) plt_start + plt_offset[fixup->value] - ((long) fixup->addr & ~0xf)) >> 4); } got_start = gen_code_ptr; /* First, create the GOT: */ for (fixup = ltoff_fixes; fixup; fixup = fixup->next) { /* first check if we already have this value in the GOT: */ for (vp = (uint64_t *) got_start; vp < (uint64_t *) gen_code_ptr; ++vp) if (*vp == fixup->value) break; if (vp == (uint64_t *) gen_code_ptr) { /* Nope, we need to put the value in the GOT: */ *vp = fixup->value; gen_code_ptr += 8; } ia64_imm22(fixup->addr, (long) vp - gp); } /* Keep code ptr aligned. */ if ((long) gen_code_ptr & 15) gen_code_ptr += 8; *gen_code_pp = gen_code_ptr;}#endif#endif#ifdef CONFIG_DYNGEN_OP#if defined __hppa__struct hppa_branch_stub { uint32_t *location; long target; struct hppa_branch_stub *next;};#define HPPA_RECORD_BRANCH(LIST, LOC, TARGET) \do { \ struct hppa_branch_stub *stub = alloca(sizeof(struct hppa_branch_stub)); \ stub->location = LOC; \ stub->target = TARGET; \ stub->next = LIST; \ LIST = stub; \} while (0)static inline void hppa_process_stubs(struct hppa_branch_stub *stub, uint8_t **gen_code_pp){ uint32_t *s = (uint32_t *)*gen_code_pp; uint32_t *p = s + 1; if (!stub) return; for (; stub != NULL; stub = stub->next) { unsigned long l = (unsigned long)p; /* stub: * ldil L'target, %r1 * be,n R'target(%sr4,%r1) */ *p++ = 0x20200000 | reassemble_21(lrsel(stub->target, 0)); *p++ = 0xe0202002 | (reassemble_17(rrsel(stub->target, 0) >> 2)); hppa_patch17f(stub->location, l, 0); } /* b,l,n stub,%r0 */ *s = 0xe8000002 | reassemble_17((p - s) - 2); *gen_code_pp = (uint8_t *)p;}#endif /* __hppa__ */const TCGArg *dyngen_op(TCGContext *s, int opc, const TCGArg *opparam_ptr){ uint8_t *gen_code_ptr;#ifdef __hppa__ struct hppa_branch_stub *hppa_stubs = NULL;#endif gen_code_ptr = s->code_ptr; switch(opc) {/* op.h is dynamically generated by dyngen.c from op.c */#include "op.h" default: tcg_abort(); }#ifdef __hppa__ hppa_process_stubs(hppa_stubs, &gen_code_ptr);#endif s->code_ptr = gen_code_ptr; return opparam_ptr;}#endif
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?