principle of QEMU CPU emulation
Asked Answered
C

1

10

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?

Chartism answered 2/1, 2013 at 16:26 Comment(1)
I dont think the above is a fair comment.Spatial
D
13

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;
Doenitz answered 2/1, 2013 at 16:32 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.