Skip to content

Add new TMS320C2x (legacy) and TMS320C5x (legacy) series support#6582

Draft
notxvilka wants to merge 6 commits into
devfrom
asan-tms320-c2xc5x
Draft

Add new TMS320C2x (legacy) and TMS320C5x (legacy) series support#6582
notxvilka wants to merge 6 commits into
devfrom
asan-tms320-c2xc5x

Conversation

@notxvilka

@notxvilka notxvilka commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Your checklist for this pull request

  • I've read the guidelines for contributing to this repository.
  • I made sure to follow the project's coding style.
  • I've documented every RZ_API function and struct this PR changes.
  • I've added tests that prove my changes are effective (required for changes to RZ_API).
  • I've updated the Rizin book with the relevant information (if needed).
  • I've used AI tools to generate fully or partially these code changes and I'm sure the changes are not copyrighted by somebody else.

Detailed description

Legacy TMS320C2x (pre-C28x) and TMS320C5x (pre-C54x) were quite common in many places, and they share some of the infrastructure with already implemented TMS320C54x/C55x in Rizin.

Add both disassembly and RzIL uplifting.

Because no public toolchain available, I vibe-coded and verified against some other projects and pairs of source-binary the small toolchain for C2x and C5x in Rust - assembler, disassembler, C compiler, linker, and emulator: https://codeberg.org/xvilka/tms320-rs

Requires this PR for testbins: rizinorg/rizin-testbins#302

Test plan

CI is green

@Rot127 Rot127 left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Came until c2x_il.c

Comment on lines +110 to +116
switch (m->amode) {
case C55_AM_POSTINC: kind = 1; break;
case C55_AM_POSTDEC: kind = 2; break;
case C55_AM_POSTADD: kind = 3; break;
case C55_AM_POSTSUB: kind = 4; break;
default: return NULL; // *no-modify or reverse-carry (AR left as-is)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of that it could just use m->amode directly, couldn't it?

Comment thread librz/arch/isa/tms320/c2x/c2x_il.c Outdated
Comment thread librz/arch/isa/tms320/c2x/c2x_il.c Outdated
Comment thread librz/arch/isa/tms320/c2x/c2x_il.c Outdated
Comment thread librz/arch/isa/tms320/c2x/c2x_il.c Outdated
Comment thread librz/arch/isa/tms320/c2x/c2x.c
Comment thread librz/arch/isa/tms320/c2x/c2x.c Outdated
Comment thread librz/arch/isa/tms320/c2x/c2x.c Outdated
@notxvilka notxvilka force-pushed the asan-tms320-c2xc5x branch from 40bd096 to 4cca7b6 Compare July 11, 2026 08:09
@github-actions github-actions Bot added the AI/LLM Partially or fully AI generated. Critical thinking is advised! label Jul 11, 2026
@notxvilka notxvilka requested a review from Rot127 July 11, 2026 08:11
XVilka added 6 commits July 11, 2026 12:46
The legacy TMS320 fixed-point families ship as 16-bit big-endian COFF
objects whose magic and machine identifiers were not recognised by the
COFF loader. Teach the COFF format backend and the bin plugin to detect
and load them so the new tms320 c2x/c5x analysis can operate on real
object files.
Add support for the legacy TMS320C2x (C25-class) fixed-point DSP family
to the shared C55 decode-IR engine: the C2x opcode table, operand
extractors, mnemonic and op-type tables, and the register profile, wired
into the tms320 asm and analysis plugins under cpu "c2x". The decoder
fills the shared C55 instruction representation so the common formatter
and analysis filler apply unchanged. Includes disassembly and opcode
classification tests, plus a COFF-loading test exercising the new bin
autodetect.
Add the real TMS320C5x (C50/C51/C53) object encoding. The C5x is
source-compatible with the C2x but encodes instructions differently, so
it cannot reuse the C2x decode table: a dedicated C5x decode front-end
fills the shared C55 instruction representation, carrying the C2x ids for
shared-semantics instructions (so the common consumers apply unchanged)
and new C5x-only ids for the C5x additions (ACCB ops, parallel-logic,
memory-mapped register access, conditional execute/call/return, block
moves, ...). Wired into the tms320 asm and analysis plugins under cpu
"c5x", with the C5x mnemonic and op-type tables and register profile.
Includes disassembly and opcode classification tests.
Lift the TMS320C2x instruction set to RzIL: the 32-bit accumulator and
product paths, the auxiliary-register file with all indirect addressing
modes, the status bits (carry, overflow, OVM saturation, SXM sign
extension, product-mode shifts, TC), and the load/store, multiply,
accumulate, shift, logical and control-flow instructions. Wired into the
analysis plugin's il_config under cpu "c2x". The asm tests now assert the
lifted RzIL for every instruction, with execution tests covering the IL
VM end to end.
Lift the TMS320C5x instruction set to RzIL. Shared-semantics
instructions reuse the C2x lifter (the C5x-only forms that are a renamed
C2x op, such as the delayed branches, map onto their non-delayed
equivalents); the C5x-only core instructions (the ACCB accumulator-buffer
loads and logical ops, the swap, the zero-accumulator forms, the control
bits and the store-long-immediate) are lifted directly. Instructions with
effects the per-instruction RzIL cannot model cleanly (conditional
control transfers, block moves, parallel-logic, memory-mapped register
access, the MAC fetch forms) are decoded and analysed but left without
IL. Wired into the analysis plugin's il_config under cpu "c5x", with the
C5x register bindings (ACCB and the C5x-specific registers). The asm
tests assert the lifted RzIL, with execution tests covering the IL VM.
BSAR (Barrel Shift ACC Right) was grouped with the left-shift ops and
reported RZ_ANALYSIS_OP_TYPE_SHL. It shifts the accumulator right (1..16
bits, sign-extended under SXM), so it belongs with the SHR group next to
RORB/SFRB. The decode (shift code + 1) was already correct and continues
to match the reference disassembler bit-for-bit.
@notxvilka notxvilka force-pushed the asan-tms320-c2xc5x branch from 4cca7b6 to 8c44ed0 Compare July 11, 2026 08:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

AI/LLM Partially or fully AI generated. Critical thinking is advised! rz-test RzAnalysis RzBin RZIL TMS320

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants