Jump to content
Setting up an AI agent? ReverseEngineering.wiki skill (works from the command line, no configuration): https://reverseengineering.wiki/skill/rewiki/SKILL.md · setup for every client, including MCP: https://reverseengineering.wiki/llms.txt · REWiki:Connect

Format:Atari TOS executable

From ReverseEngineering.wiki
Format
Magic 60 1A (0x601A) at offset 0
Extensions .prg .tos .ttp .app .acc
Endianness big endian (68000)
On this wiki Facts · Code · Notes · Topics

Atari ST/TT/Falcon program files (.PRG, .TOS, .TTP, .APP, .ACC): a 28-byte big-endian header starting 0x601A (text, data, bss and symbol sizes, a symbol-table type longword, ph_prgflags, a no-relocation word), then text+data, the symbol table and a relocation table of one longword plus byte deltas.

Layout

The file is: 28-byte header, text, data (together tlen + dlen bytes, loaded as one block), the symbol table (slen bytes, may be empty), then the relocation table. All values are big endian. EmuTOS reads the 2-byte magic first and refuses anything but 0x601A (EPLFMT); Hatari rejects files shorter than 30 bytes. See Fact:Atari TOS executable/struct/TOS program header.

The loader puts text at the first byte after the 256-byte basepage (PD). The basepage fields p_tbase/p_tlen/p_dbase/p_dlen/p_bbase/p_blen sit at offsets 8..31 of the basepage; p_dta is at 32, p_parent at 36, p_env at 44, the command line at 0x80 (Hatari GemDOS_LoadAndReloc).

Program flags (ph_prgflags)

Bit 0 FASTLOAD (clear only the BSS instead of the whole free memory), bit 1 TTRAMLOAD (may be loaded into TT-RAM), bit 2 TTRAMMEM (may allocate TT-RAM), bit 3 MINIMUM (MagiC), bit 12 SHAREDTEXT; bits 4-5 are the memory protection mode (0 private, 1 global, 2 super, 3 readable by all). See Fact:Atari TOS executable/enum/ph prgflags bits. A program built without FASTLOAD has its whole heap zeroed at load time, which is why old binaries start slower on big-memory machines.

Relocation

If the last header word (the absolute flag) is zero the file is relocatable. At file offset 0x1C + tlen + dlen + slen there is a longword: the offset from the start of text of the first longword to fix; 0 means nothing to relocate. Then come bytes: 0 ends the table, 1 advances the pointer by 254 without fixing anything, any other value advances by that many bytes and adds the text base to the longword found there (the target must be word aligned and below the BSS). See Fact:Atari TOS executable/behavior/Relocation table. EmuTOS notes that real Atari TOS does not fail the load if reading the first offset fails: it simply does not relocate.

Symbol tables

The longword at header offset 18 (documented as reserved/zero in the original format) tells the symbol-table type: 0 = DRI/GST table, MiNT (0x4D694E54) = GST table in a GCC/MiNT binary, GNU_ (0x474E555F) = a.out symbol table, ELF\0 (0x454C4600) = ELF sections follow. See Fact:Atari TOS executable/identification/Symbol table type. The DRI table has 14-byte entries (8-byte name, 16-bit type, 32-bit value); GST extends names to 22 characters by using a second slot. See Fact:Atari TOS executable/struct/DRI symbol entry. Pure C binaries keep the real long names in a debug area after the table (Hatari read_pc_debug_names; Unverified: its layout was not read).

MiNT/GCC executables

For MiNT and GNU_ binaries Hatari checks that the text starts with the bytes 28 3A 00 1A 4E FB 48 FA or 20 3A 00 1A 4E FB 08 FA (a move.l 28(pc),dn / jmp 0(pc,dn.l) stub), after which an a.out-style extended header and tparel fields follow; Unverified: 0x601A is also the encoding of bra.s +26, which jumps over the rest of the header, so a PRG can be entered at its first byte. Unverified: that this is the whole layout of the extended header; read symbols-common.c lines 1439-1520 before relying on it.

System calls

Program code calls GEMDOS through trap #1, BIOS trap #13, XBIOS trap #14: see Platform:Atari ST#System calls.

Code & repositories

  • https://github.com/emutos/emutos @ 02c2db75fc875265c1449efea014450466cf20b7 · license: GPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize a license file)
    EmuTOS, free TOS replacement (GPL-2): bdos/kpgmld.c is the PRG loader and relocator, bdos/bdosmain.c the GEMDOS function table, bios/bios.c and bios/xbios.c the BIOS/XBIOS tables, bios/vectors.S the trap 13/14 entry.
    Tested on: source read, not run: source reading only · checked 2026-10-19
  • https://github.com/hatari/hatari @ 1262318909db005b6cbc4b9caaec75865ec19708 · license: GPL-2.0-or-later (declared by the contributor; GitHub's detector did not recognize a license file)
    Hatari Atari ST/TT/Falcon emulator (GPL-2): src/gemdos.c GemDOS_LoadAndReloc loads PRG files, src/debug/symbols-common.c parses DRI/GST, a.out and ELF symbol tables and prints the program flags.
    Tested on: source read, not run: source reading only · checked 2026-10-19

Pitfalls

  • Unverified: treat res1 as a type word, not as padding; tools that zero it would lose the symbol-table type of GCC/MiNT binaries.
  • Overlays, resource files and accessories share the 0x601A header; the extension only says how the desktop starts them.
  • Unverified: what distinguishes .PRG, .TOS, .TTP and .APP is the desktop's choice (GEM or text mode, parameters), not the header.