From 59c60504e7a873ecd9bea41e879cd72bc96156ba Mon Sep 17 00:00:00 2001 From: d00f <8052722+DrDoof@users.noreply.github.com> Date: Sat, 15 Aug 2026 17:41:34 +0200 Subject: [PATCH] crtbank: put the bank switching helpers in HOME __sdcc_banked_call and __sdcc_banked_ret were assembled into GSFINAL, which sits in the startup path: GSINIT ends exactly where GSFINAL begins, so the processor falls into it rather than being sent there. It works today only because this object comes after every C object on the link line, so the LJMP to __sdcc_program_startup is laid down first and the helpers land behind it. Reordering that line, or moving main() into another module, would put the helper body at the fallthrough address instead, and the board would not come up out of a build that reports nothing wrong. SDCC's own crtbank.asm declares the area order and then puts both symbols in HOME, so the file takes that name and that preamble as well. GSFINAL now holds the three byte jump and nothing else. Of 401 symbols 17 change address, every one in the startup region, and between the reset vector and 0x0094 not a byte differs, so no interrupt vector is disturbed. Run on a SWTGW218AS: it came back after about 42 seconds reporting the new build, with its stored configuration byte identical and every link at the speed it had before. --- Makefile | 2 +- crtbank.asm | 29 +++++++++++++++++++++++++++++ crtstart.asm | 17 ----------------- 3 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 crtbank.asm delete mode 100644 crtstart.asm diff --git a/Makefile b/Makefile index 9ab0da8..4044551 100644 --- a/Makefile +++ b/Makefile @@ -118,7 +118,7 @@ $(BUILDDIR)/%.rel: %.asm ${ASM} ${AFLAGS} -o $@ $< # mv -f $(addprefix $(basename $^), .lst .rel .sym) . -$(BUILDDIR)/rtlplayground.ihx: $(OBJS) $(BUILDDIR)/crtstart.rel $(BUILDDIR)/crc16.rel +$(BUILDDIR)/rtlplayground.ihx: $(OBJS) $(BUILDDIR)/crtbank.rel $(BUILDDIR)/crc16.rel $(CC) $(CC_FLAGS) -Wl-bHOME=0x00000 -Wl-bBANK1=0x14000 -Wl-bBANK2=0x24000 -Wl-r -o $@ $^ $(BUILDDIR)/rtlplayground.img: $(BUILDDIR)/rtlplayground.ihx diff --git a/crtbank.asm b/crtbank.asm new file mode 100644 index 0000000..7a00868 --- /dev/null +++ b/crtbank.asm @@ -0,0 +1,29 @@ + .area HOME (CODE) + .area GSINIT0 (CODE) + .area GSINIT1 (CODE) + .area GSINIT2 (CODE) + .area GSINIT3 (CODE) + .area GSINIT4 (CODE) + .area GSINIT5 (CODE) + .area GSINIT (CODE) + .area GSFINAL (CODE) + .area CSEG (CODE) + + + .area HOME (CODE) + +__sdcc_banked_call:: + push _PSBANK + xch a,r0 + push a + mov a,r1 + push a + mov a,r2 + anl a,#0x1f + mov _PSBANK, a + xch a, r0 + ret + +__sdcc_banked_ret:: + pop _PSBANK + ret diff --git a/crtstart.asm b/crtstart.asm deleted file mode 100644 index 23146a7..0000000 --- a/crtstart.asm +++ /dev/null @@ -1,17 +0,0 @@ - .area GSFINAL (CODE) - -__sdcc_banked_call:: - push _PSBANK - xch a,r0 - push a - mov a,r1 - push a - mov a,r2 - anl a,#0x1f - mov _PSBANK, a - xch a, r0 - ret - -__sdcc_banked_ret:: - pop _PSBANK - ret