简体   繁体   English

QEMU CPU仿真原理

[英]principle of QEMU CPU emulation

In QEMU, an operating system can run above software emulated CPU. 在QEMU中,操作系统可以在软件模拟CPU之上运行。 How can be a CPU emulated by software? 如何通过软件模拟CPU? I want to know about detail. 我想知道细节。

If CPU is emulated by software does registers are emulated with host system memory? 如果CPU是由软件模拟的,寄存器是用主机系统内存模拟的吗?

Let say there is ARM assembly code 假设有ARM汇编代码

LDRB r0, [r1], #1

How can this be emulated in x86 environment? 如何在x86环境中进行仿真?

My guess is that emulating software keeps memory mapping space for r0 (4 bytes), r1 (4 bytes) and then updates the register value for corresponding memory location... Am I wrong? 我的猜测是仿真软件为r0 (4字节), r1 (4字节)保留内存映射空间,然后更新相应内存位置的寄存器值...我错了吗?

Please see this file for the C-level modelling of the state of an ARM CPU as done by QEMU. 请参阅此文件,了解由QEMU完成的ARM CPU状态的C级建模。

It's pretty straight-forward, and (of course) as you suspect the registers (and all other state) are modelled as C variables. 这是非常直接的,并且(当然)因为您怀疑寄存器(以及所有其他状态)被建模为C变量。

The core structure begins: 核心结构开始:

typedef struct CPUARMState {
    /* Regs for current mode.  */
    uint32_t regs[16];
   /* Frequently accessed CPSR bits are stored separately for efficiency.
      This contains all the other bits.  Use cpsr_{read,write} to access
      the whole CPSR.  */
   uint32_t uncached_cpsr;
   uint32_t spsr;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM