Introduction
A hunk is one contiguous piece of the program in memory. The file has a block that gives it its contents (code, data or just a size), optional blocks
that belong to it (relocations, symbols, debug information), and HUNK_END. Hunks are numbered in file order, from the first hunk of the header. A block
is a long id followed by what that block needs; the ids below are the same in every source that was read, and in the assembler’s source.
Block ids
| Id | Decimal | Name | Where |
|---|---|---|---|
$3E7 | 999 | HUNK_UNIT | starts an object file’s unit (libraries) |
$3E8 | 1000 | HUNK_NAME | names the next hunk in an object file |
$3E9 | 1001 | HUNK_CODE | code |
$3EA | 1002 | HUNK_DATA | data |
$3EB | 1003 | HUNK_BSS | zeroed memory |
$3EC | 1004 | HUNK_RELOC32 | relocations |
$3ED | 1005 | HUNK_RELOC16 | relocations (object files) |
$3EE | 1006 | HUNK_RELOC8 | relocations (object files) |
$3EF | 1007 | HUNK_EXT | external symbols (symbols) |
$3F0 | 1008 | HUNK_SYMBOL | symbol names |
$3F1 | 1009 | HUNK_DEBUG | debug information |
$3F2 | 1010 | HUNK_END | ends a hunk |
$3F3 | 1011 | HUNK_HEADER | starts an executable (header) |
$3F5 | 1013 | HUNK_OVERLAY | overlay table |
$3F6 | 1014 | HUNK_BREAK | ends the overlay part |
$3F7 | 1015 | HUNK_DREL32 | relocations (short form in an executable) |
$3F8 | 1016 | HUNK_DREL16 | relocations (object files) |
$3F9 | 1017 | HUNK_DREL8 | relocations (object files) |
$3FA | 1018 | HUNK_LIB | starts a link library |
$3FB | 1019 | HUNK_INDEX | a link library’s index |
$3FC | 1020 | HUNK_RELOC32SHORT | relocations in words |
$3FD | 1021 | HUNK_RELRELOC32 | PC-relative 32-bit relocations in words |
$3FE | 1022 | HUNK_ABSRELOC16 | 16-bit absolute relocations |
$4E9 | 1257 | HUNK_PPC_CODE | PowerPC code (extended hunk format) |
$4EC | 1260 | HUNK_RELRELOC26 | 26-bit PowerPC branch relocations (extended hunk format) |
Only the low 29 bits are the id; the top bits ask for chip or fast memory (below). The number $3F4 is unused in every source. Wikipedia and the amitools reader
give the numbers in this table; the amiga-dev wiki prints $3FD as HUNK_ABSRELOC16, which disagrees with them and with the vasm assembler, whose header file has
HUNK_RELRELOC32 at 1021 and HUNK_ABSRELOC16 at 1022. The viewer follows Wikipedia, amitools and vasm. An id above $3FE that is not in the table is
read as a count of longs and skipped, the way the amiga-dev wiki says dos.library treats such ids.
HUNK_CODE
A count of longs, then that many longs of machine code. The loader copies them to the hunk’s memory. The viewer disassembles every HUNK_CODE hunk with the
68000-family decoder; the processor is an option because the file does not say. A HUNK_PPC_CODE hunk has the same layout and is shown as
bytes.
HUNK_DATA
The same layout as code: a count of longs and the data. The viewer lists the runs of four or more printable characters in data hunks.
HUNK_BSS
One long: the number of longs to allocate and clear. No bytes follow and no relocation block applies to it.
HUNK_END
No body. It closes the hunk, after the hunk’s relocation, symbol and debug blocks. A stray HUNK_END with no hunk open exists in a real file: the Workbench 1.1 calculator has one after
a BSS hunk; the viewer notes it and goes on.
HUNK_OVERLAY and HUNK_BREAK
An overlay program loads only its root hunks at first. After the root hunks comes HUNK_OVERLAY: a count, then that count plus one longs of table (as the amitools reader
reads it), and HUNK_BREAK, which has no body. In the real overlay executables on the Workbench disks and the loose Amiga files the table is followed either by a second
header with the overlay segments’ hunks (AExplorer), or by data that only the program’s own overlay manager reads (WHDLoad: about 89 KB after a 26-entry table). The viewer reads
the first and shows the second as “Overlay data”, bytes it does not interpret. The table’s entries are shown as a count, not decoded.
Memory type in the id
In an object file the memory type of a hunk is in the top two bits of the hunk’s id (HUNK_CODE, HUNK_DATA or HUNK_BSS); in an executable it is in the
header’s size table.
Not described
Known, not yet covered
- Reference: the overlay table’s entries and the overlay manager’s protocol, the PowerPC extended blocks other than
HUNK_PPC_CODEandHUNK_RELRELOC26(the sources name only those two), and the loader’s behaviour for blocks it refuses. - Viewer: overlay segments are not followed;
HUNK_PPC_CODEis shown as bytes.
Links
Reference
- Amiga Hunk – Wikipedia: the block ids
- Hunk file format – amiga-dev wiki: CODE, DATA, BSS and the loader’s rules
- amitools hunk reader – the id constants and the block reader