From 8c300b0e0a2f7740f696c385e0ad7315d73c97f3 Mon Sep 17 00:00:00 2001 From: Tinic Uro Date: Sat, 26 Sep 2026 02:30:19 +0000 Subject: [PATCH] netdev: card.resource stubs list every scratch register the call may destroy The five card.resource stubs in netdev_pcmcia.c passed their argument registers (a1, and a0/d1 where used) as inputs only. The library ABI lets every LVO destroy d0/d1/a0/a1, but GCC was told those registers still held their values after the jsr. This was REAL in anxnet.device at main 71086503. pc_misc_control loads d1 = 10 for CardMiscControl (jsr -48 at 0x68aa), and GCC reused d1 as the value argument of netdev_diag_note(ANXDIAG_PC_IOMODE) at 0x68b0, so the diagnostic IOMODE value was whatever card.resource left in d1. The other four stubs were latent: today's code rewrites or never reads the register. Each argument register is now a "+r" operand; unused scratch registers remain clobbers. After the change, 0x68b0 is `pea 0xa` (the constant), and the OwnCard / ReleaseCard / CardResetCard / CopyTuple sites compile to the same instructions, only shifted by 2 bytes. The #70 scanner no longer flags netdev_pcmcia.c. anxnet.device 7d62fbe4 -> 9e8e9011 (default preset). Part of #70 (shipped sites, PR A of 3). Co-Authored-By: Claude Opus 5.5 (1M context) --- CHANGELOG.md | 1 + src/netdev/netdev_pcmcia.c | 24 +++++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index cf48a0f29..6c5869c3b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ version at the top when it merges. ## Unreleased +- `anxnet.device` on a PC Card slot records the correct I/O mode in its diagnostic record. - The installer can set the clock from an Internet time server at boot; the answer defaults to no. - `SO_REUSEPORT` on a UDP socket now shares the port instead of being ignored, and `SO_REUSEADDR` opts into the same sharing for callers that know only that diff --git a/src/netdev/netdev_pcmcia.c b/src/netdev/netdev_pcmcia.c index ef1f2a968..29bd3d4db 100644 --- a/src/netdev/netdev_pcmcia.c +++ b/src/netdev/netdev_pcmcia.c @@ -26,7 +26,9 @@ struct Library *CardResource; /* * card.resource stubs: no proto header works on both toolchains. LVOs: * OwnCard -0x06(a1), ReleaseCard -0x0c(a1,d0), CardMiscControl -0x30(a1,d1), - * CopyTuple -0x48(a1,a0,d1,d0). + * CopyTuple -0x48(a1,a0,d1,d0). Every one may destroy d0/d1/a0/a1, so each + * of those is an output ("+r" when it also carries an argument) or a clobber; + * an argument register listed only as an input was reused stale (#70). */ static struct CardHandle *pc_own_card(struct CardHandle *h) @@ -36,8 +38,8 @@ static struct CardHandle *pc_own_card(struct CardHandle *h) register struct CardHandle *res __asm("d0"); __asm __volatile ("jsr a6@(-0x6)" - : "=r" (res) - : "r" (_a6), "r" (_a1) + : "=r" (res), "+r" (_a1) + : "r" (_a6) : "d1", "a0", "cc", "memory"); return res; @@ -50,8 +52,8 @@ static VOID pc_release_card(struct CardHandle *h, ULONG flags) register ULONG _d0 __asm("d0") = flags; __asm __volatile ("jsr a6@(-0xc)" - : "+r" (_d0) - : "r" (_a6), "r" (_a1) + : "+r" (_d0), "+r" (_a1) + : "r" (_a6) : "d1", "a0", "cc", "memory"); } @@ -62,8 +64,8 @@ static BOOL pc_reset_card(struct CardHandle *h) register LONG res __asm("d0"); __asm __volatile ("jsr a6@(-0x42)" - : "=r" (res) - : "r" (_a6), "r" (_a1) + : "=r" (res), "+r" (_a1) + : "r" (_a6) : "d1", "a0", "cc", "memory"); return (BOOL)(res != 0); @@ -77,8 +79,8 @@ static UBYTE pc_misc_control(struct CardHandle *h, UBYTE bits) register LONG res __asm("d0"); __asm __volatile ("jsr a6@(-0x30)" - : "=r" (res) - : "r" (_a6), "r" (_a1), "r" (_d1) + : "=r" (res), "+r" (_a1), "+r" (_d1) + : "r" (_a6) : "a0", "cc", "memory"); return (UBYTE)res; @@ -95,8 +97,8 @@ static BOOL pc_copy_tuple(struct CardHandle *h, UBYTE *buf, ULONG code, register LONG res __asm("d0"); __asm __volatile ("jsr a6@(-0x48)" - : "=r" (res) - : "r" (_a6), "r" (_a1), "r" (_a0), "r" (_d1), "0" (_d0) + : "=r" (res), "+r" (_a1), "+r" (_a0), "+r" (_d1) + : "r" (_a6), "0" (_d0) : "cc", "memory"); return (BOOL)(res != 0);