startup: clear MAP_FLASH_PAGE_TO_XDATA before the C runtime initialises xdata

Hardware reset starts the firmware with SFR 0x97 = 1, which maps xdata
0x4000-0xbfff to the flash image: reads return flash bytes, writes are
lost. main() cleared it only after __mcs51_genXINIT and the XSEG clear
had run, so XISEG (initialised globals) and the part of XSEG above
0x4000 kept stale RAM contents, e.g. session_timeout = 4484 and LLDP
blocked on logical ports 0, 3 and 5. Clear it in
__sdcc_external_startup(), which SDCC calls before both.

Rename SFR_97 to MAP_FLASH_PAGE_TO_XDATA.
This commit is contained in:
Andre Brait committed 2026-10-26 17:08:27 +01:00
1 parent 80a30b705e
commit 98763e3bff
4 files changed
+17 -3

No files matched your search

+6
View File
@@ -47,6 +47,12 @@
- The web UI and the configuration upload now refuse a line the replay cannot take,
instead of writing it to flash.
- Startup
- Initialised and zero-initialised globals above xdata 0x4000 now get their values at boot.
Hardware reset leaves SFR 0x97 at 1, which maps xdata 0x4000-0xbfff to the flash image,
and it was cleared only in `main()`, after the C startup code had copied and cleared them.
This showed as a random web session timeout and LLDP blocked on some ports without config.
## Breaking changes
- Config