mirror of
https://github.com/alfishe/amiga-bootcamp.git
synced 2026-06-13 00:26:28 +00:00
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.
118 lines
3.2 KiB
Markdown
118 lines
3.2 KiB
Markdown
[← Home](../../README.md) · [Reverse Engineering](../README.md)
|
|
|
|
# Serial Debugging — kprintf and Serial Output
|
|
|
|
## Overview
|
|
|
|
The Amiga's built-in serial port is the primary low-level debugging channel. `kprintf()` (kernel printf) and `RawPutChar()` write directly to the serial hardware, bypassing `dos.library` and working even from interrupt context or before OS initialization.
|
|
|
|
---
|
|
|
|
## `kprintf()` — Kernel Printf
|
|
|
|
`kprintf()` is a ROM debug function present in Kickstart 1.3 and later debug ROMs. It formats a string and outputs each character via `RawPutChar`.
|
|
|
|
```c
|
|
/* Prototype (exec internal, not in NDK — declare manually): */
|
|
void kprintf(const char *fmt, ...);
|
|
/* Arguments in: D1=fmt, stack args (unlike standard AmigaOS register ABI) */
|
|
```
|
|
|
|
### Calling `kprintf` from Assembly
|
|
|
|
```asm
|
|
MOVEA.L 4.W, A6 ; SysBase
|
|
LEA _fmt_str(PC), A0 ; format string
|
|
MOVE.L A0, -(SP) ; push as stack argument
|
|
MOVE.L A0, D1 ; some implementations use D1
|
|
JSR (-$F0,A6) ; RawDoFmt or debug rom entry
|
|
; OR for ROM debug builds:
|
|
JSR _kprintf
|
|
```
|
|
|
|
> [!NOTE]
|
|
> `kprintf` is **not available** in standard Kickstart 3.1 release ROMs. Use `debug.lib` stubs (`dprintf`) or `RawDoFmt + RawPutChar` instead.
|
|
|
|
---
|
|
|
|
## `RawDoFmt` + `RawPutChar` — Universal Approach
|
|
|
|
This works on **all** Kickstart versions (1.2+):
|
|
|
|
```c
|
|
/* Format into a buffer and output via RawPutChar */
|
|
static void serial_putchar(UBYTE c, APTR dummy) {
|
|
/* write directly to serial data register */
|
|
volatile UWORD *SERDATR = (UWORD *)0xDFF018;
|
|
volatile UWORD *SERDATW = (UWORD *)0xDFF030;
|
|
volatile UWORD *SERDATSTAT;
|
|
/* Wait for TBE (transmit buffer empty) */
|
|
while (!(*SERDATR & 0x2000));
|
|
*SERDATW = 0x0100 | c; /* 8 bits + start bit */
|
|
}
|
|
|
|
void dbg_printf(const char *fmt, ...) {
|
|
UBYTE buf[256];
|
|
va_list args;
|
|
va_start(args, fmt);
|
|
/* RawDoFmt(fmt, args, putChar, buf) */
|
|
RawDoFmt((STRPTR)fmt, &args,
|
|
(VOID (*)())serial_putchar, buf);
|
|
va_end(args);
|
|
}
|
|
```
|
|
|
|
Or simpler — write to the serial hardware directly:
|
|
|
|
```c
|
|
static void SerPutChar(UBYTE c) {
|
|
while (!(*((volatile UWORD *)0xDFF018) & 0x2000)); /* wait TBE */
|
|
*((volatile UWORD *)0xDFF030) = 0x0100 | c;
|
|
}
|
|
```
|
|
|
|
---
|
|
|
|
## `debug.lib` (SAS/C)
|
|
|
|
SAS/C ships `debug.lib` providing `dprintf`:
|
|
|
|
```c
|
|
#include <debug.h>
|
|
dprintf("mylib: Open called, name=%s\n", name);
|
|
```
|
|
|
|
Output goes to the serial port at the rate set by SERPER (default 9600 baud on startup, 115200 if set).
|
|
|
|
---
|
|
|
|
## Setting Baud Rate
|
|
|
|
```c
|
|
/* Set serial to 115200 baud (PAL, 3.546895 MHz clock): */
|
|
/* SERPER = (clock / (16 * baud)) - 1 */
|
|
/* = (3546895 / (16 * 115200)) - 1 = 0 */
|
|
volatile UWORD *SERPER = (UWORD *)0xDFF032;
|
|
*SERPER = 0x0000; /* 115200 on PAL */
|
|
```
|
|
|
|
---
|
|
|
|
## Host-Side Capture
|
|
|
|
```bash
|
|
# macOS (USB-serial adapter):
|
|
screen /dev/cu.usbserial-XXXX 115200
|
|
# or:
|
|
stty -f /dev/cu.usbserial-XXXX 115200 raw && cat /dev/cu.usbserial-XXXX
|
|
```
|
|
|
|
MiSTer FPGA: the UART bridge is exposed on the MiSTer IO board or via the DE10-Nano UART.
|
|
|
|
---
|
|
|
|
## References
|
|
|
|
- NDK39: `exec/execbase.h` — `RawDoFmt`, `RawPutChar` LVOs
|
|
- `01_hardware/ocs_a500/paula_serial.md` — SERPER, SERDATR, SERDATW register details
|
|
- Aminet: `debug/misc/dprintf.lha`
|