
Introduction of QEMU, TCG (Tiny Code Generator), and Dragon CPU architecture.
Prepare container for development, check out QEMU source code, and make QEMU build to verify development environment.
Set up the build files and the initial source files to build qemu-system-dragon.
Explain QEMU Object Model, including how to define and register QOM type, and define the type cast macros.
Add QOM types for Dragon machine, Dragon CPU, and Dragon Arch CPU.
Populate the device tree of Dragon machine and load firmware file.
Add general purpose registers and program counters in Dragon Arch CPU state, include register names.
Initialize and realize DragonArchCPU.
Explain DecodeTree grammar.
Add DecodeTree definition file and decode instruction ADD.W.
Decode more instructions.
Initialize SysemuCPUOps and TCGCPUOps.
Initialize TranslatorOps.
Explain the example code of Dragon.
Add translation code for ADD.W, ADD.D, LU12I.W, and LU32I.D.
Translate B (Branch Instruction).
Translate ADDI.W, ADDI.D, LD.W, LD.D, ST.W, ST.D, and BEQ.
Explain TCG helper function and add helper functions for BITREV.W and BITREV.D.
Fix some problems and verify the register contents of example code execution result.
Add exception helper function for the illegal instruction.
Add disassembler support to show Dragon assembly lines in QEMU debug output.
Summary and Thank You.
This course will walk you through the procedure to add a new CPU architecture to QEMU TCG (Tiny Code Generator), so that you will gain the rich understanding about TCG in practice. A faked CPU architecture named Dragon is used, which borrows some instructions from LoongArch CPU architecture. Correspondingly, a faked Dragon machine is added to drive Dragon CPU from QEMU system emulator.
This course will help you:
Prepare QEMU source code and build environment
Understand QEMU building environment and build files like Kconfig and meson build file
Understand QOM (QEMU Object Model), including how to add new QOM type and do type cast
Add the devices of Dragon machine and CPU, and connect Dragon CPU to machine
Add the new CPU target of Dragon, and initialize Dragon Arch CPU state
Understand DecodeTree and decode Dragon instructions with DecodeTree definition file
Initialize the structs like SystemCPUOps, TCGCPUOps, and TranslatorOps
Translate the instructions include arithmetic instructions, load/store instructions, and branch instructions
Translate the complicated bits reverse instruction with TCG helper function
Test, debug and verify the implementation with an example program and examine CPU state with QEMU option "-d cpu"
Implement exception helper function to unknown instructions
Add disassembler support to show Dragon instructions with QEMU option "-d in_asm"