Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

principle of QEMU CPU emulation

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.

If CPU is emulated by software does registers are emulated with host system memory?

Let say there is ARM assembly code

LDRB r0, [r1], #1

How can this be emulated in x86 environment?

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?

like image 243
daehee Avatar asked Jan 02 '13 16:01

daehee


1 Answers

Please see this file for the C-level modelling of the state of an ARM CPU as done by QEMU.

It's pretty straight-forward, and (of course) as you suspect the registers (and all other state) are modelled as C variables.

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;
like image 115
unwind Avatar answered Oct 17 '22 22:10

unwind