Introduction
A HUNK file is how AmigaOS stores a program. The loader reads it block by block, puts each hunk (a piece of
code, data or zeroed memory) at an address of its own, and adds that address to the places the file lists, so the program can be loaded
anywhere. The same block format serves three kinds of file, told apart by the first block: an
executable (a load file) starts with HUNK_HEADER, an object file from an assembler or compiler
starts with HUNK_UNIT, and a link library starts with HUNK_LIB. Every number is big-endian, as on the
68000. The code is for the Motorola 68000 family.
An Amiga program has no extension (Dir, diskfont.library, trackdisk.device), so the explorer
recognises a HUNK file by its first long, $000003F3, $000003E7 or $000003FA, in a file of at least 24 bytes. A file
inside an Amiga disk image (.adf) opens the same way.
Structure
HUNK_HEADERthe header: resident library names (none in a load file), the table size, the first and last hunk, then one size long per hunk with its memory typeexecutable onlyHUNK_CODE / DATA / BSSa hunk: a count of longs, then the bytes (BSS has none)one per hunkHUNK_RELOC32the relocations of that hunk: the places that hold an address of another hunkoptionalHUNK_SYMBOL, HUNK_DEBUGnames and line numbers for debuggersoptionalHUNK_ENDends the hunk; the next hunk follows4 bytes
HUNK_UNIT and a name instead, and may have HUNK_EXT blocks.The header page has the first block, and the hunks page the blocks that hold the program. Relocations says how an address is fixed up, and symbols and debug what a debugger gets. Objects and libraries is the linker side, and system addresses lists the fixed addresses the viewer names in the disassembly: address 4, the custom chips, the CIAs, and the library call offsets.
The three kinds of file
| First long | Block | File |
|---|---|---|
$000003F3 | HUNK_HEADER | An executable (load file): what LoadSeg reads. Programs, libraries (.library), devices (.device) and handlers are all load files. |
$000003E7 | HUNK_UNIT | An object file: one or more units with names, external symbols and relocations for a linker. |
$000003FA | HUNK_LIB | A link library: object-file units one after another, then an index. Loading a library as a program is an error. |
Not described
Known, not yet covered
- Reference: the layouts here come from third-party descriptions (Wikipedia, the amiga-dev wiki, the amitools source and the vasm assembler’s source); the fetch tool that read the web pages returned summaries, so the layouts rest on those summaries and on the real files below. Not covered: HUNK_RELOC32SHORT’s exact use by each linker, the PowerPC extended hunks other than
HUNK_PPC_CODEandHUNK_RELRELOC26, the line-debug formats other thanLINE(HCLN,HEAD,ODEF,OPTS,ZMAGIC), the overlay manager protocol, and howHUNK_ABSRELOC16is laid out (the two sources disagree). - Viewer: the explorer opens executables, object files and libraries: every block as a node, the hunk table with sizes and memory types, the relocations, symbols, external symbols,
LINEdebug tables, the library index, text in data hunks, and the code of everyHUNK_CODEhunk disassembled with the 68000-family decoder (68000 to 68060 as an option), with relocated longs marked, hardware addresses named, and library calls named for the library you choose. It was checked on 2,547 real HUNK files (the Workbench disks 1.0 to 3.1 and loose Amiga files, read in memory) and on files made by the vasm assembler, but the real files are all executables: no real object file or link library was found on this machine, so those two variants are checked on assembler output and built files only. It decodes every even address as an instruction (code and data are not told apart), does not follow jumps or the overlay manager, showsHUNK_PPC_CODEhunks as bytes, and has not been run in a browser by its author.
Links
Software
- FS-UAE – Amiga emulator (Windows, macOS, Linux)
- English Amiga Board – the Amiga community’s forum, with tools and documentation threads
Reference
- Amiga Hunk – Wikipedia: the table of block ids
- Hunk file format – the amiga-dev wiki: the header, the memory flags, the debug formats and what the loader accepts
- amitools hunk reader – a Python reader of every block, used here as a description
- vasm – the assembler whose
output_hunk.cwrites the object and executable forms