IoTQemu

[译]Qemu Dynamic Translator论文

2016-10-23  本文已影响84人  Elinx

Tittle

QEMU, a Fast and Portable Dynamic Translator

Abstract

Introduction

Protable dynamic translation

描述

A key idea is that in QEMU const parameters can be given to micro operations. For that purpose, dummy code relocations are generated with GCC for each constant parameter. This enable dyngen tool to locate the relocations and generate the appropriate C code to resolve them when building the dynamic code. Relocations are also supported to enable references to static data and to oher functions in the micro operations.

例子

movl_T0_r1        # T0 = r1
addl_T0_im -16    # T0 = T0 - 16
movl_r1_T0        # r1 = T0
void op_movl_T0_r1(void)
{
     T0 = env->regs[1];
}

extern int __op_param1;
void op_add1_T0_im(void)
{
    T0 = T0 + ((long)(&__op_param1));
}
for (;;) {
  switch(*opc_ptr++) {
  case INDEX_op_movl_T0_r1: {
    extern void op_mov1_T0_r1();
    memcpy(gen_code_ptr, (char *)&op_movl_T0_r1 + 0, 3);
    gen_code_ptr += 3;
    break;
  }
  case INDEX_op_add1_T0_im: {
    long param1;
    extern void op_addl_T0_im();
    memcpy(gen_code_ptr, (char *)&op_addl_T0_im+0, 6);
    param1 = *opparam_ptr++;
    *(uint32_t *)(gen_code_ptr + 2) = param1;
    gen_code_ptr += 6;
    break;
  }
  [...]
  }
  [...]
}
# movl_T0_r1
# ebx = env->reg[1]
mov 0x4(%ebp), %ebx
# add1_T0_im - 16
# ebx = ebx - 16
add $0xfffffff0, %ebx
# movl_r1_T0
# env->regs[1] = ebx
mov %ebx, 0x4(%ebp)

Dyngen的实现

实现细节

Translated Blocks and Translated Cache

Register allocation

Condition code optimizations

Direct block chainning

Memory management

自修改code和code invalidation

异常支持

硬件中断

User mode emulation

Porting work

Performance

总结和未来工作

References

[1] Optimizing direct threaded code by selective inlining.

上一篇下一篇

猜你喜欢

热点阅读