docs(amiga): complete AmigaOS 3.1/3.2 developer reference — 172 files across 17 sections
Comprehensive technical documentation covering:
- Hardware: OCS/ECS/AGA custom chip registers, Copper & Blitter deep dives
- Boot sequence: cold boot through startup-sequence
- Binary format: HUNK executable spec, relocation, debug info
- Linking & ABI: .fd files, LVO tables, register calling conventions
- Exec kernel: tasks, interrupts, memory, signals, semaphores
- AmigaDOS: file I/O, FFS/OFS layout, CLI/Shell scripting
- Graphics: planar bitmaps, Copper programming, HAM/EHB modes
- Intuition: screens, windows, IDCMP, BOOPSI
- Devices: trackdisk, SCSI, serial, timer, audio, keyboard
- Libraries: utility, expansion, IFFParse, locale, ARexx
- Networking: bsdsocket API, SANA-II, TCP/IP stack comparison
- Toolchain: GCC, vasm/vlink, SAS/C, NDK, debugging
- Reverse engineering: IDA/Ghidra setup, compiler fingerprints, case studies
- CPU & MMU: 68040/060 emulation libs, PMMU, cache management
- Driver development: SANA-II, Picasso96/RTG, AHI audio
All files include breadcrumb navigation. No local paths or proprietary content.
2026-04-23 12:16:52 -04:00
[← Home ](../README.md )
# Linking & Library Integration
## Overview
This section documents how AmigaOS shared libraries work at the binary level — how compilers produce library call stubs, how the linker wires them up, and how to reconstruct this mechanism during reverse engineering.
## Contents
| File | Topic |
|---|---|
03/04: deep enrichment of loader/exec format and linking/libraries
Sections 03 and 04 augmented to bootcamp quality with targeted
enrichment based on content analysis (not just file size).
03_loader_and_exec_format:
- overlay_system.md: full rewrite — tree architecture diagram,
HUNK_OVERLAY binary format, overlay manager runtime internals,
worked binary example, linker support, modern alternatives
- hunk_relocation.md: full rewrite — visual before/after diagram,
patching algorithm with code, RELOC32SHORT and DREL32 formats,
PC-relative impact comparison table, self-referencing relocs,
error scenarios, Python reloc scanner tool
04_linking_and_libraries:
- library_structure.md: full rewrite — ASCII memory layout diagram,
JMP table encoding (why 6 bytes), MakeLibrary internals with both
function array formats, complete library creation example with
.fd file, checksum verification, lifecycle state diagram
- shared_libraries_runtime.md: full rewrite — OpenLibrary 4-step
resolution path, ramlib disk loader internals, disk search path,
version negotiation table (v33-v47), CloseLibrary/Expunge deep
dive, memory-low sweep, common pitfalls table
- register_conventions.md: full rewrite — FPU register map,
inter-library A6 save/restore pattern, small-data model with
__saveds keyword, varargs/TagItem pattern deep dive,
stack-based wrapper explanation, disassembly identification
Updated indexes:
- 03_loader_and_exec_format/README.md
- 04_linking_and_libraries/README.md
- Root README.md (sections 03 and 04)
2026-04-23 18:30:45 -04:00
| [library_structure.md ](library_structure.md ) | Library memory layout, JMP table encoding, MakeLibrary construction, complete library creation example |
| [shared_libraries_runtime.md ](shared_libraries_runtime.md ) | OpenLibrary resolution path, ramlib disk loader, version negotiation, expunge mechanics |
| [register_conventions.md ](register_conventions.md ) | Register ABI: integer, FPU, varargs/TagItem, small-data model, __saveds, inter-library calls |
| [fd_files.md ](fd_files.md ) | Function Definition files — the library ABI source of truth, LVO calculation |
| [lvo_table.md ](lvo_table.md ) | JMP table layout, complete exec.library LVO table, IDA reconstruction script |
| [compiler_stubs.md ](compiler_stubs.md ) | How SAS/C, GCC, VBCC call libraries — compiler signature identification |
| [inline_stubs.md ](inline_stubs.md ) | Compiler inline stubs: pragma (SAS/C), inline asm (GCC), __reg (VBCC), stub generation tools |
| [link_libraries.md ](link_libraries.md ) | Static linking: amiga.lib, sc.lib, libnix, auto.lib, WBStartup glue, stack cookie |
| [startup_code.md ](startup_code.md ) | c.o / gcrt0.S: entry contract, CLI vs WB detection, argument parsing, WBStartup message |
| [setfunction.md ](setfunction.md ) | Runtime function patching: canonical pattern, chaining, removal, RE detection heuristics |
docs(amiga): complete AmigaOS 3.1/3.2 developer reference — 172 files across 17 sections
Comprehensive technical documentation covering:
- Hardware: OCS/ECS/AGA custom chip registers, Copper & Blitter deep dives
- Boot sequence: cold boot through startup-sequence
- Binary format: HUNK executable spec, relocation, debug info
- Linking & ABI: .fd files, LVO tables, register calling conventions
- Exec kernel: tasks, interrupts, memory, signals, semaphores
- AmigaDOS: file I/O, FFS/OFS layout, CLI/Shell scripting
- Graphics: planar bitmaps, Copper programming, HAM/EHB modes
- Intuition: screens, windows, IDCMP, BOOPSI
- Devices: trackdisk, SCSI, serial, timer, audio, keyboard
- Libraries: utility, expansion, IFFParse, locale, ARexx
- Networking: bsdsocket API, SANA-II, TCP/IP stack comparison
- Toolchain: GCC, vasm/vlink, SAS/C, NDK, debugging
- Reverse engineering: IDA/Ghidra setup, compiler fingerprints, case studies
- CPU & MMU: 68040/060 emulation libs, PMMU, cache management
- Driver development: SANA-II, Picasso96/RTG, AHI audio
All files include breadcrumb navigation. No local paths or proprietary content.
2026-04-23 12:16:52 -04:00
## The Library ABI Model
Every AmigaOS shared library exposes its functions through a **negative-offset JMP table** relative to the library base pointer:
```
Library base: LIB+0 → Library node (struct Library)
03/04: deep enrichment of loader/exec format and linking/libraries
Sections 03 and 04 augmented to bootcamp quality with targeted
enrichment based on content analysis (not just file size).
03_loader_and_exec_format:
- overlay_system.md: full rewrite — tree architecture diagram,
HUNK_OVERLAY binary format, overlay manager runtime internals,
worked binary example, linker support, modern alternatives
- hunk_relocation.md: full rewrite — visual before/after diagram,
patching algorithm with code, RELOC32SHORT and DREL32 formats,
PC-relative impact comparison table, self-referencing relocs,
error scenarios, Python reloc scanner tool
04_linking_and_libraries:
- library_structure.md: full rewrite — ASCII memory layout diagram,
JMP table encoding (why 6 bytes), MakeLibrary internals with both
function array formats, complete library creation example with
.fd file, checksum verification, lifecycle state diagram
- shared_libraries_runtime.md: full rewrite — OpenLibrary 4-step
resolution path, ramlib disk loader internals, disk search path,
version negotiation table (v33-v47), CloseLibrary/Expunge deep
dive, memory-low sweep, common pitfalls table
- register_conventions.md: full rewrite — FPU register map,
inter-library A6 save/restore pattern, small-data model with
__saveds keyword, varargs/TagItem pattern deep dive,
stack-based wrapper explanation, disassembly identification
Updated indexes:
- 03_loader_and_exec_format/README.md
- 04_linking_and_libraries/README.md
- Root README.md (sections 03 and 04)
2026-04-23 18:30:45 -04:00
LIB-6 → JMP _Open (mandatory)
LIB-12 → JMP _Close (mandatory)
LIB-18 → JMP _Expunge (mandatory)
LIB-24 → JMP _Reserved (mandatory)
LIB-30 → JMP _func1 (first user function)
LIB-36 → JMP _func2
docs(amiga): complete AmigaOS 3.1/3.2 developer reference — 172 files across 17 sections
Comprehensive technical documentation covering:
- Hardware: OCS/ECS/AGA custom chip registers, Copper & Blitter deep dives
- Boot sequence: cold boot through startup-sequence
- Binary format: HUNK executable spec, relocation, debug info
- Linking & ABI: .fd files, LVO tables, register calling conventions
- Exec kernel: tasks, interrupts, memory, signals, semaphores
- AmigaDOS: file I/O, FFS/OFS layout, CLI/Shell scripting
- Graphics: planar bitmaps, Copper programming, HAM/EHB modes
- Intuition: screens, windows, IDCMP, BOOPSI
- Devices: trackdisk, SCSI, serial, timer, audio, keyboard
- Libraries: utility, expansion, IFFParse, locale, ARexx
- Networking: bsdsocket API, SANA-II, TCP/IP stack comparison
- Toolchain: GCC, vasm/vlink, SAS/C, NDK, debugging
- Reverse engineering: IDA/Ghidra setup, compiler fingerprints, case studies
- CPU & MMU: 68040/060 emulation libs, PMMU, cache management
- Driver development: SANA-II, Picasso96/RTG, AHI audio
All files include breadcrumb navigation. No local paths or proprietary content.
2026-04-23 12:16:52 -04:00
...
```
A C call like `OpenLibrary("graphics.library", 0)` compiles to:
```asm
MOVE.L 4.W, A6 ; A6 = SysBase (exec)
JSR -552(A6) ; LVO for OpenLibrary = -552
```
The negative offset (`-552` ) is the **Library Vector Offset (LVO)** — a fixed ABI value defined in the library's `.fd` file and `proto/` include.
## References
- NDK39: `fd/` directory, `proto/` includes, `inline/` inline stubs
- ADCD 2.1: Library writing guide, ROM Kernel Manual
- http://amigadev.elowar.com/read/ADCD_2.1/Libraries_Manual_guide/node0000.html