amiga-bootcamp/13_toolchain/pragmas.md
Ilia Sharin 21751c0025 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:17:35 -04:00

83 lines
1.8 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

[← Home](../README.md) · [Toolchain](README.md)
# Compiler Pragmas and Inline Stubs
## Overview
AmigaOS library calls use **register-based** calling conventions (arguments in D0D7/A0A6). C compilers need pragmas or inline stubs to generate the correct register assignments instead of stack-based calls.
---
## Three Mechanisms
| Method | Compiler | How it works |
|---|---|---|
| **Pragmas** | SAS/C | `#pragma libcall` directive |
| **Inline headers** | GCC | Inline asm functions in `<inline/lib.h>` |
| **Proto headers** | All | `<proto/lib.h>` — auto-selects pragma or inline |
---
## Pragma Example (SAS/C)
```c
#pragma libcall DOSBase Open 1e 2102
/* Translates to: LVO = -0x1E = -30
Args: D1 = arg1 (name), D2 = arg2 (mode)
Result: D0 */
```
---
## Inline Example (GCC)
```c
/* inline/exec.h */
static __inline APTR
AllocMem(ULONG byteSize, ULONG requirements)
{
register APTR _res __asm("d0");
register ULONG _byteSize __asm("d0") = byteSize;
register ULONG _requirements __asm("d1") = requirements;
register struct ExecBase *_SysBase __asm("a6") = SysBase;
__asm volatile (
"jsr -198(%%a6)"
: "=r"(_res)
: "r"(_byteSize), "r"(_requirements), "r"(_SysBase)
: "d1","a0","a1","cc","memory"
);
return _res;
}
```
---
## Generating Pragmas/Inlines from FD Files
```bash
# fd2pragma (Aminet: dev/misc/fd2pragma.lha):
fd2pragma exec_lib.fd exec_lib.sfd TO pragmas/exec_pragmas.h SPECIAL 6
fd2pragma exec_lib.fd exec_lib.sfd TO inline/exec.h SPECIAL 70
```
---
## Proto Headers
```c
/* proto/exec.h — portable wrapper: */
#ifdef __SASC
#include <pragmas/exec_pragmas.h>
#elif defined(__GNUC__)
#include <inline/exec.h>
#endif
extern struct ExecBase *SysBase;
```
---
## References
- NDK39: `pragmas/`, `inline/`, `proto/` directories
- `13_toolchain/fd_files.md` — FD file format