qemu-tcg-frontend
Skill60 starsChanged 13 days agoMITView on GitHub
Use for adding, reviewing, or debugging guest ISA decode and translation in a QEMU TCG frontend, including feature gates, exceptions, PC/TB behavior, and focused instruction tests.
We split this skill into the rules it gives an agent
7 rules. About 0 are common, 4 are distinctive, and 3 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈4
Distinctive · estimate
This author's own choices. Worth a look.
3
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Distinctive: line 27
Keep file-header comments minimal: SPDX/copyright plus at most a one-line component identity.
- Distinctive: line 73
When an instruction decodes to the wrong pattern or a pattern is unreachable:
- Distinctive: line 84
Before emitting IR, gate:
- Very specific: line 93
Use direct TCG ops for simple integer/logical/shift/select operations.
- Distinctive: line 107
Check target conventions for:
- Very specific: line 128
Add focused tests/tcg/<target>/ coverage when applicable.
- Very specific: line 131
Use -accel tcg,one-insn-per-tb=on when debugging instruction boundaries.
≈ “Common” is an estimate: at least 1 in 5 of the 308,232 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
QEMU TCG Frontend
Audit workflow
For a non-trivial task that writes to the workspace, use only the needed entries under
.oh-my-qemu/<task-slug>/: audit.md (baseline, plan, decisions, evidence, verification, and
gaps), commands.md (redacted commands, working directories, and results), logs/ (decisive
build, test, and runtime output), scripts/ (probes, parsers, and harnesses), and output/
(generated deliverables, third-party dependencies, and non-QEMU binaries). Keep QEMU's own build
tree at source-root builds/build-<target>/, never an unqualified build/. In a Git worktree,
add .agents/, .oh-my-qemu/, and builds/ to the file from
git rev-parse --git-path info/exclude before writing artifacts or configuring QEMU; preserve
existing entries and avoid duplicates. Never stage or commit these paths; stage source only when
the user explicitly requests that separate action. At handoff, reconcile git status --short
with the baseline and report the task directory, build directory, source changes, pre-existing
changes, and unresolved gaps.
Source comment hygiene
Keep file-header comments minimal: SPDX/copyright plus at most a one-line
component identity. Do not put implementation strategy, framework choice/defense,
"modeled contract" pointers, neighboring-device convention, or review/audit
rationale in source. Comment only key ISA/decode/backend code, in one to three
lines with at most one brief public QEMU or ISA reference; do not expand it into
a design or translation essay. Never write .oh-my-qemu/..., output/...,
audit.md, evidence paths, round/milestone/AC status, review notes, commands,
progress, or absolute host paths into source. When qemu-workflow is installed,
run its source-comments gate on changed source files.
QEMU upstream boundary
QEMU's official GitLab and mailing lists are upstream channels. A patch becomes an upstream
contribution when it is sent to the maintainers selected through MAINTAINERS. Do not prepare or
send agent-generated code, documentation, commit messages, or patches for upstream submission; see
the checked-out tree's docs/devel/code-provenance.rst. Research, debugging, analysis, local
experiments, verification, and workflow guidance remain allowed. Local branches, commits, patch
files, pushes, and pull requests are not by themselves upstream contributions; perform those Git
actions only when requested.
Workflow
- Record the ISA version, encoding, feature/privilege gates, exception behavior, PC/TB rules, and allowed source paths.
- Inspect the checked-out decoder and the nearest comparable target before choosing decodetree, direct TCG ops, or a helper.
- Work in small reviewable rounds; record changed paths, verification, review result, and gaps.
- Build the target and run focused valid, invalid, and disabled-feature instruction tests.
- Capture bounded TCG logs only when needed; distinguish translated, helper, and fallback paths.
Frontend contract
Record in audit.md: ISA version and privilege requirements; instruction encoding, aliases, and
operand sign/zero extension; XLEN/vector/FPU constraints; expected illegal-instruction cases; the
helper-versus-direct-op decision; and the tests that prove semantics and invalid encodings. Use
the ISA coverage template for per-instruction coverage.
Decoder rules
For decodetree targets, reuse existing fields, formats, and argument sets; confirm fixedmask/fixedbits uniqueness; handle overlap groups intentionally; use field functions for transformed immediates; and keep ordering consistent with nearby extensions. For hand decoders, preserve existing fallback and illegal-instruction behavior.
Decoder collision and priority debugging
When an instruction decodes to the wrong pattern or a pattern is unreachable:
- List the patterns that match the same instruction word and compare fixedbits/fixedmask.
- Rebuild and read the decodetree generator error or generated decoder path reported by Meson; conflicts fail generation or leave a later pattern unreachable.
- Order patterns from most specific to most general; comment intentional overlap groups and add a negative test for every shadowed encoding.
- Record the pattern order and tested encodings in
audit.md.
trans_* rules
Before emitting IR, gate:
- CPU/ISA feature;
- privilege/virtualization mode;
- XLEN/operand width;
- reserved bits and invalid immediates;
- vector/FPU state where relevant;
- alignment or memory-mode constraints if architectural.
Use direct TCG ops for simple integer/logical/shift/select operations. Use helpers for complex state, softfloat/crypto/vector libraries, or exception-heavy semantics.
Helper side-effect flags
Helper flags tell TCG which globals a helper reads or writes and whether the call has side
effects; a helper that raises an exception or mutates guest-visible state must keep those effects
visible. Failure example: a raising helper declared with the no-side-effects flag looks removable
to TCG, so the call can be dropped or reordered when its result is unused. The build still
succeeds; only a guest test that depends on the exception or state write fails. Inspect the
checked-out flag definitions (in include/tcg/tcg.h) and add such a test.
PC and TB rules
Check target conventions for:
pc_nextadvancement;- PC update before exceptions;
- branch/direct-block chaining;
ctx->base.is_jmpstate;- page-boundary behavior;
- single-step and interrupt trigger behavior.
Wrong PC state corrupts exceptions, gdbstub state, and replay/debug evidence.
Custom ISA modeling
For a new toy, vendor, or reverse-engineered ISA target, use custom-isa.md: target enablement, decode and translation registration, TCG op mapping, CPU state and control-register helpers, per-instruction functional tests, qtest coverage, and build targets. Keep the frontend testable per instruction group.
Verification expectations
- Build the target translator.
- Add focused
tests/tcg/<target>/coverage when applicable; otherwise add a functional per-instruction test. - Cover edge values, invalid encodings, feature-disabled behavior, and privilege errors.
- Use
-accel tcg,one-insn-per-tb=onwhen debugging instruction boundaries. - Store TCG logs under
.oh-my-qemu/<task-slug>/logs/.
Upstream references
docs/devel/code-provenance.rstdocs/devel/decodetree.rstdocs/devel/tcg.rstdocs/devel/tcg-ops.rstdocs/devel/submitting-a-patch.rsttarget/riscv/(decodetree andinsn_trans/implementation examples)
Paths can differ between QEMU versions; locate them in the checked-out tree.
In this repository19 other files it gives its agents.
- AGENTS.mdAGENTS.md
- qemu-agent-feedbackSkill
- qemu-board-modelingSkill
- qemu-boot-runSkill
- qemu-buildSkill
- qemu-debugSkill
- qemu-imageSkill
- qemu-kernel-buildSkill
- qemu-linux-bootSkill
- qemu-modelerSkill
- qemu-model-reviewSkill
- qemu-model-verificationSkill
- qemu-peripheral-modelingSkill
- qemu-qtestSkill
- qemu-register-extractionSkill
- qemu-rst-documentationSkill
- qemu-tcg-backendSkill
- qemu-uboot-buildSkill
- qemu-workflowSkill
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

