From 83491bc9e3b3d2f1877f5ed2cbf57ebfeb5c9de6 Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Thu, 17 Sep 2026 03:55:30 +0200 Subject: [PATCH] test: let the shim compile sources that touch the SFRs and libc Two things kept every register-driven module out of the host harness. The SFR keywords were unknown, so rtl837x_sfr.h did not compile at all, and once it did, each translation unit would have defined its own copy of the registers. They map to extern declarations now; a mock emits the storage once by re-including the header with the keywords redefined. The other was memset. rtl837x_common.h hides the firmware's own prototypes under RTLP_HOST_TEST so host builds use the C library, but nothing declared the library versions, and the modules do call them. The shim pulls in string.h ahead of everything, where nothing can clash with it. --- test/sdcc_shim.h | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/test/sdcc_shim.h b/test/sdcc_shim.h index c080ff44..a1dfa848 100644 --- a/test/sdcc_shim.h +++ b/test/sdcc_shim.h @@ -12,6 +12,7 @@ #define SDCC_SHIM_H #include +#include /* Memory-space qualifiers → nothing (host has one flat address space). */ #define __xdata @@ -22,12 +23,27 @@ /* bool, not unsigned char: SDCC's bit types normalize any assigned value * to 0/1, which _Bool reproduces exactly. */ #define __bit bool -#define __sbit bool -/* NOTE: the firmware ships its own 8051 memcpy/memset/strlen/strcpy/sleep with - * incompatible signatures (rtl837x_common.h). Host TUs must therefore build with - * -fno-builtin (so gcc doesn't auto-declare the builtins) and must NOT include - * /. Test code uses the t_* helpers in support.h instead. */ +/* Special-function registers are declared in rtl837x_sfr.h as + * `__sfr __at(0xNN) NAME;`. With __at erased those become plain declarations, + * so they must carry extern or every translation unit including the header + * defines its own copy. __sbit is the bit-in-an-SFR form and only appears + * there; the local bit variable keyword is __bit above. test/hw_mock.c + * undefines these four and re-includes the header once to emit the storage. */ +#define __sfr extern volatile uint8_t +#define __sfr16 extern volatile uint16_t +#define __sfr32 extern volatile uint32_t +#define __sbit extern bool + +/* The firmware ships its own memcpy/memset/strlen/strcpy/sleep, and + * rtl837x_common.h hides those prototypes under RTLP_HOST_TEST so host builds + * take the C library versions. Something has to declare them, and firmware + * sources do call memset and memcpy; this header is force-included ahead of + * everything, so pulling in here puts the libc versions in scope + * before any firmware header and nothing clashes. sleep() is not in + * and is declared on its own rather than through . */ +#include +extern unsigned int sleep(unsigned int seconds); /* Function attributes → nothing (no banking / no 8051 calling conventions). */ #define __banked