2017年11月22日星期三

Intuition about qemu and how it works

So qemu will have  threads, each thread has its own cpu state and page table, so it has its own .text .data .init sections, these sections will be mapped in memory of the thread. So, we have a thread for emulating peripheral devices and IO, a thread for translating target code to host code, a thread for the cpu state and memory state of the target cpu processor.

What we want to do is to change the virtual device object and make everytime it is running its callback function, it will change the memory map of the IO part of the target system memory. Basically, we want to focus on figuring out the memory map and add function when perpherals are called.

Actually, how it works is to allocate Memory(system RAM memory ROM memory and IO memory) for target first, and put the binary into ROM memory and RAM memory, and put peripherals controller or Bus in IO memory. (Initialization of peripherals memory and state is another object, it can change system IO memory when called). Then allocate space for virtual CPU(as an object.) Then it can fetch code from RAM memory and translate and execute and change virtual CPU state. Qemu core has its own functions and stack to deal with multi thread or things like that.

The way it allocate memory is allocate ram block from qemu_vmalloc and every ram block has its name.

没有评论:

发表评论