Skip to content

Instantly share code, notes, and snippets.

@jevinskie
Created June 3, 2025 20:57
Show Gist options
  • Save jevinskie/2ecbf824c45f15f3ab12dcbf5a8d4a61 to your computer and use it in GitHub Desktop.
Save jevinskie/2ecbf824c45f15f3ab12dcbf5a8d4a61 to your computer and use it in GitHub Desktop.
QEMU decodetree example
/* This file is autogenerated by scripts/decodetree.py. */
typedef struct {
int reg0;
int reg1;
int imm16;
} arg_ri;
typedef arg_ri arg_addi;
static bool trans_addi(DisasContext *ctx, arg_addi *a);
static void decode_extract_ri(DisasContext *ctx, arg_ri *a, uint32_t insn) {
a->reg1 = extract32(insn, 16, 5);
a->reg0 = extract32(insn, 21, 5);
a->imm16 = extract32(insn, 0, 16);
}
static bool decode(DisasContext *ctx, uint32_t insn) {
union {
arg_ri f_ri;
} u;
decode_extract_ri(ctx, &u.f_ri, insn);
switch ((insn >> 26) & 0x3f) {
case 0xd:
/* 001101.. ........ ........ ........ */
/* target/lm32/insns.decode:28 */
if (trans_addi(ctx, &u.f_ri))
return true;
break;
}
return false;
}
# Fields:
%reg0 21:5
%reg1 16:5
# Immediates:
%imm16 0:16
# Argument sets:
&ri reg0 reg1 imm16
# Formats:
@ri . ..... ..... ..... ................ &ri %reg0 %reg1 %imm16
# Instructions:
addi 0 01101 ..... ..... ................ @ri
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment