5.1 KiB
Ghidra Setup for Amiga 68k Binaries
Requirements
| Component | Version / Notes |
|---|---|
| Ghidra | 10.x+ or 11.x+ recommended |
| Processor module | M68k — included in Ghidra standard install |
| HUNK loader & Amiga extensions | ghidra-amiga by BartmanAbyss |
Step 1: Install the Amiga Extension
Ghidra natively supports the M68000 architecture and includes a powerful decompiler for it, but it does not understand the Amiga OS executable format (HUNK) out of the box.
- Download the latest release of
ghidra-amigafrom: https://github.com/BartmanAbyss/ghidra-amiga - Open Ghidra.
- Go to
File → Install Extensions... - Click the green
+(Add extension) button. - Select the downloaded
.zipfile (do not extract it). - Restart Ghidra.
This essential extension provides:
- A complete Amiga HUNK format loader.
- Custom chipset register definitions mapped to
$DFF000. - OS library LVO (Library Vector Offset) definitions.
- Analyzer scripts specifically for resolving Amiga binaries.
Step 2: Importing and Analyzing
- Create a new project or open an existing one.
- Select
File → Import File...and choose your Amiga executable or library. - The format should automatically be detected as
Amiga Executable(thanks to the extension). - Double-click the imported file to open it in the CodeBrowser.
- When prompted to analyze, click Yes.
- Ensure the
Amigaanalyzers (provided by the extension) are enabled in the analysis options list before hitting Analyze.
Step 3: Decompilation and M68k Specifics
Unlike IDA Pro (which lacks Hex-Rays support for M68k), Ghidra's built-in decompiler fully supports the Motorola 68000 family.
- The
ghidra-amigaextension actively assists the decompiler by automatically annotating library calls (likeexec/AllocMemordos/Open) when it detects jumps to negative offsets onA6. - The decompiler will translate these
JSRinstructions directly into C pseudocode function calls with the correct parameters, making it vastly superior for analyzing C/C++ compiled Amiga software.
Step 4: Custom Hardware Registers ($DFF000)
The ghidra-amiga extension automatically creates memory blocks for Amiga custom chips and CIA registers.
- Go to
Window → Memory Map. You will seecustom($DFF000),ciaa($BFE001), andciab($BFD000) accurately mapped into the address space. - The extension automatically defines the Amiga Custom Chip data types.
- When analyzing code that bangs the hardware (e.g.,
move.w d0, $096(A4)), if Ghidra knowsA4is$DFF000, it will automatically format it ascustom->dmaconin the C pseudocode! - If it fails to detect the base register automatically, you can manually set the register value by highlighting the start of the function, right-clicking, and selecting
Set Register Values(orCtrl-R), then definingA4 = 0xDFF000.
Step 5: Dynamic Analysis
Ghidra is purely for static analysis. For dynamic debugging, the workflow is identical to IDA:
- Do your mapping and decompilation in Ghidra.
- Note the physical addresses and offsets.
- Run the binary in WinUAE and drop into the native debugger (
Shift+F12) to set breakpoints and step through the hardware state live.
Step 6: GCC Binary Specific Workflows
When dealing with GCC-compiled Amiga binaries (especially those with debug info), there are a few Ghidra-specific workflows to note:
1. Install ghidra-gcc2-stabs (RidgeX/ghidra-gcc2-stabs) if the binary has debug info. After loading:
- Run the script:
Analysis → Run Script → ImportGCC2Stabs.java - The script reads
HUNK_DEBUG, extractsN_FUN/N_SLINE/N_LSYMstabs, and creates function labels, source line annotations, and local variable names automatically. - Even partial stabs (e.g.,
N_SO+N_FUNonly) restore function boundaries and names.
2. PC-relative string handling. Ghidra's m68k analyzer natively handles LEA xxx(PC), An correctly and creates data cross-references. Check the References view for LEA targets — strings listed there can be viewed and renamed.
3. Function boundary heuristic. Ghidra's default analysis finds GCC functions reasonably well. For missed functions:
- Use
Search → For Instruction Patterns→MOVEM.L *, -(SP)(opcode48E7) to find all prologues. - Right-click →
Create Functionat each found address.
4. Recognizing tail calls. Ghidra may misidentify BRA _otherFunc as a local branch. If Ghidra marks code after a BRA as unreachable or creates a new function at the BRA target, verify manually: if the BRA target is a named function elsewhere in .text, it's a tail call — the BRA terminates the current function and the target function returns directly to the original caller.
References
- ghidra-amiga by BartmanAbyss — The definitive Amiga loader and extension suite for Ghidra.
- Ghidra Official Website
- vscode-amiga-debug — Excellent extension for source-level Amiga debugging if you are writing modern Amiga patches.