65816-llvm-mos/demos/gnoBigBssProbe.c

31 lines
1.2 KiB
C

// D1 regression for the crt0Gno BSS-clear heartbeat bug: a large zero-init
// BSS array pushes __bss_end past the old ~0xB100 corruption threshold.
// crt0Gno no longer clears BSS (the loader fills the embedded zeros), so
// the program must run to the end AND read the array back as all-zero.
#include <stdint.h>
// 4 KB. The GNO runtime's code already pushes the BSS base to ~0xD000 (well
// above the old ~0xB100 heartbeat threshold), so this array only has to keep
// __bss_end large while the whole BSS still fits under the bank-0 top: the
// runtime's own BSS grows, and at 0x1700 the link overflowed by 236 bytes.
#define BIG_BSS_BYTES 0x1000u
static volatile uint8_t bigBss[BIG_BSS_BYTES];
int main(void) {
*(volatile uint16_t *)0x025010UL = 0xBEEF;
uint16_t zeroed = 1;
unsigned i;
for (i = 0; i < BIG_BSS_BYTES; i++) {
if (bigBss[i] != 0) {
zeroed = 0;
break;
}
}
*(volatile uint16_t *)0x025012UL = zeroed ? 0x0001 : 0xDEAD;
bigBss[0] = 1; // retain
bigBss[BIG_BSS_BYTES - 1u] = 2;
*(volatile uint16_t *)0x025000UL = 0xC0DE;
for (volatile unsigned long j = 0; j < 600000UL; j++) {
}
return 0;
}