Udemy
Turn what you know into an opportunity and reach millions around the world.
Learn More
Your cart is empty.
Keep shopping
QEMU TCG Tutorial
Rating: 5.0 out of 5(1 rating)
29 students

QEMU TCG Tutorial

Learn QEMU TCG (Tiny Code Generator) by adding a new CPU architecture
Created byQi Liang
Last updated 12/2025
English
English [Auto],

What you'll learn

  • Learn how to add a machine type and CPU device for a new CPU architecture
  • Learn QOM (QEMU Object Model) and how to define the QOM types for new device and CPU target
  • Learn DecodeTree and how to decode the target instructions
  • Understand how TCG works and the data structures like SystemCPUOps, TCGCPUOps, and TranslatorOps
  • Learn how to use QEMU ops to translate the target instructions
  • Understand QEMU helper function and how it's used in translation
  • Learn how to disassemble the target instruction and show it with QEMU debug option

Course content

4 sections • 22 lectures • 6h 0m total length
  • Introduction9:49

    Introduction of QEMU, TCG (Tiny Code Generator), and Dragon CPU architecture.

Requirements

  • Basics of QEMU usage, Linux usage, and C language are required
  • Nice to have some experience in git, VS Code, podman, and gdb

Description

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:

  1. Prepare QEMU source code and build environment

  2. Understand QEMU building environment and build files like Kconfig and meson build file

  3. Understand QOM (QEMU Object Model), including how to add new QOM type and do type cast

  4. Add the devices of Dragon machine and CPU, and connect Dragon CPU to machine

  5. Add the new CPU target of Dragon, and initialize Dragon Arch CPU state

  6. Understand DecodeTree and decode Dragon instructions with DecodeTree definition file

  7. Initialize the structs like SystemCPUOps, TCGCPUOps, and TranslatorOps

  8. Translate the instructions include arithmetic instructions, load/store instructions, and branch instructions

  9. Translate the complicated bits reverse instruction with TCG helper function

  10. Test, debug and verify the implementation with an example program and examine CPU state with QEMU option "-d cpu"

  11. Implement exception helper function to unknown instructions

  12. Add disassembler support to show Dragon instructions with QEMU option "-d in_asm"

Who this course is for:

  • QEMU developers and anyone with interests in QEMU TCG (Tiny Code Generator)