QEMU CPU仿真原理 [英] principle of QEMU CPU emulation
问题描述
在QEMU中,操作系统可以在软件仿真的CPU之上运行. 如何用软件模拟CPU? 我想了解细节.
In QEMU, an operating system can run above software emulated CPU. How can be a CPU emulated by software? I want to know about detail.
如果CPU由软件仿真,寄存器是否与主机系统内存仿真?
假设有ARM汇编代码
LDRB r0, [r1], #1
如何在x86环境中进行仿真?
我的猜测是,仿真软件会保留r0
(4个字节),r1
(4个字节)的内存映射空间,然后为相应的内存位置更新寄存器值...我错了吗?
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?
推荐答案
Please see this file for the C-level modelling of the state of an ARM CPU as done by QEMU.
这很简单,而且(当然)是因为您怀疑寄存器(以及所有其他状态)都被建模为C变量.
It's pretty straight-forward, and (of course) as you suspect the registers (and all other state) are modelled as C variables.
核心结构开始:
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;
这篇关于QEMU CPU仿真原理的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!