Skip to main content

Crate nyxstone_tricore_gcc

Crate nyxstone_tricore_gcc 

Source
Expand description

NyxstoneTricoreGCC, Rust bindings.

Safe Rust wrapper around the C ABI defined in c_api/nyxstone_c.h. The underlying library is an in-process TriCore assembler/disassembler built on the EEESlab tricore-binutils-gdb fork.

The API shape mirrors that of the sibling project Nyxstone, a separate codebase built on LLVM-MC, covering the architectures LLVM supports. This crate is an independent implementation using GNU binutils to cover TriCore (which LLVM-MC has no backend for). Both projects expose four methods named assemble, assemble_to_instructions, disassemble, and disassemble_to_instructions, all taking an absolute address (and, for the assembly entry points, a slice of LabelDefinitions for external symbols).

§Threading

All GAS globals are process-wide; a process-wide lock serializes every C call. NyxstoneTricoreGCC is both Send and Sync, but two threads sharing one or two handles will serialize on the global lock, they won’t actually run concurrently.

§Section restriction (Nyxstone-style)

Any directive that would switch the active section to something other than .text (e.g. .data, .bss, .section .foo) makes assemble return an error. .text and .section .text / .section .text.<name> are accepted as no-ops.

§Example

use nyxstone_tricore_gcc::NyxstoneTricoreGCC;

let nx = NyxstoneTricoreGCC::new()?;
let bytes = nx.assemble("start:\n nop\n j here\nhere:\n ret\n", 0, &[])?;
// `j here` relaxes to its 2-byte short form and targets `here` (disp 0x01).
assert_eq!(bytes, [0x00, 0x00, 0x3c, 0x01, 0x00, 0x90]);

let insns = nx.disassemble_to_instructions(&bytes, 0x80000000, 0)?;
for ins in &insns {
    println!("0x{:08x}  {}", ins.address, ins.assembly);
}

Structs§

Instruction
One disassembled (or freshly assembled) instruction.
LabelDefinition
External label definition (input to assemble / assemble_to_instructions).
NyxstoneTricoreGCC
In-process TriCore assembler/disassembler. Same API shape as the sibling Nyxstone project (which is LLVM-MC-based and an independent codebase).
RelocationInfo
One relocation entry, the same shape gas/gcc emits with -r.
RelocationSymbol
Symbol target of a relocation, with the resolved address copied from the matching LabelDefinition (0 if the caller did not supply one).

Enums§

Error
Errors produced by NyxstoneTricoreGCC methods. Each variant carries a free-form message from the underlying library where available.

Type Aliases§

Address
Convenience alias matching the public C++/Rust API contract.