Skip to the content.

TCGContext : 如何工作的,如何维护的,作用是什么

tb_gen_code : 让我们来分析一下这个狗东西

  1. 了解一下 TCGContext::tb_cflags
    • 这个只是在 tcg/tcg-op.c 中间使用, 但是现在 xqm 中,这个东西直接被移除掉了, 暂时不用考虑
    • 但是函数 tb_cflags 还是在使用的
  2. cflags 相关的 macro 的引用位置吧
FLAGS desc
CF_LAST_IO 在 cpu_io_recompile 插入,而 cpu_io_recompile 需要在 io_readx 和 io_writex 两个函数的地方使用
CF_NOCACHE cpu_exec_nocache 中插入,检测位置都是在 translate-all.h 中间的
CF_COUNT_MASK 似乎存储是这个 TB 中间到底有多少指令
CF_USE_ICOUNT  
CF_PARALLEL mttcg 相关的,还没有开始支持
CF_CLUSTER_MASK / CF_CLUSTER_SHIFT  
CF_INVALID - [ ] 应该追查一下到底什么时候,以及 invalid 一个 tb 所需要进行的操作是什么
  1. CPUState::cflags_next_tb 作用?

在 cpu_handle_exception 的下面,是这个数值唯一读取的时候:

      /* When requested, use an exact setting for cflags for the next
         execution.  This is used for icount, precise smc, and stop-
         after-access watchpoints.  Since this request should never
         have CF_INVALID set, -1 is a convenient invalid value that
         does not require tcg headers for cpu_common_reset.  */

此外,cflags_next_tb 将会 tb_find 的参数 而 tb_find 可能会查询以及生成 tb 只有 cpu_io_recompile 和 TARGET_HAS_PRECISE_SMC 特别的初始化这个东西

  1. 如何理解 curr_cflags ?
    • 其实就是封装 parallel_cpus 和 icount 在目前的配置,因为 mttcg 和 icount 都不支持,只是返回 0 了
    • 其实是相当于标准 cflags 了
  2. CF_CLUSTER_MASK 的作用
    • 在 tb_gen_code 和 tb_lookup__cpu_state 中都有一个要求将 cflags 的 mask 初始化为当前 cpu 的 cluster 的操作
    • 加深一下 cluster index 的理解之后再说
  3. tb_gen_code 中间有两个 label : buffer_overflow tb_overflow 分别表示发生了什么事情
    • buffer_overflow : 表示 tb 块太多了,该刷新了
    • tb_overflow : 一个 tb 中间的指令太多了

TCGContext::code_gen_

typedef struct TCGContext {

  /* Code generation.  Note that we specifically do not use tcg_insn_unit
     here, because there's too much arithmetic throughout that relies
     on addition and subtraction working on bytes.  Rely on the GCC
     extension that allows arithmetic on void*.  */
  void *code_gen_prologue;
  void *code_gen_epilogue;
  void *code_gen_buffer;
  size_t code_gen_buffer_size;
  void *code_gen_ptr;
  void *data_gen_ptr;

  /* Threshold to flush the translated code buffer.  */
  void *code_gen_highwater;

  /* goto_tb support */
  tcg_insn_unit *code_buf;

code_gen_buffer

赋值的地方:

code_gen_ptr

code_gen_ptr : 下一个 tb 应该存放的位置

从下面可以得到验证:

  atomic_set(
      &tcg_ctx->code_gen_ptr,
      (void *)ROUND_UP((uintptr_t)gen_code_buf + gen_code_size + search_size,
                       CODE_GEN_ALIGN));

本站所有文章转发 CSDN 将按侵权追究法律责任,其它情况随意。