diff --git a/src/asm/section.c b/src/asm/section.c index 0ae711d5..f45b4654 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -159,6 +159,8 @@ static void setCurrentSection(struct Section *pSect) void out_NewSection(char const *pzName, uint32_t secttype, int32_t org, struct SectionSpec const *attributes) { + uint32_t align = 1 << attributes->alignment; + if (attributes->bank != -1) { if (secttype != SECTTYPE_ROMX && secttype != SECTTYPE_VRAM && secttype != SECTTYPE_SRAM && secttype != SECTTYPE_WRAMX) @@ -171,6 +173,26 @@ void out_NewSection(char const *pzName, uint32_t secttype, int32_t org, bankranges[secttype][1]); } + if (align != 1) { + /* It doesn't make sense to have both set */ + uint32_t mask = align - 1; + + if (org != -1) { + if (org & mask) + yyerror("Section \"%s\"'s fixed address doesn't match its alignment", + pzName); + else + align = 1; /* Ignore it if it's satisfied */ + } + } + + if (org != -1) { + if (org < startaddr[secttype] || org > endaddr(secttype)) + yyerror("Section \"%s\"'s fixed address %#x is outside of range [%#x; %#x]", + pzName, org, startaddr[secttype], + endaddr(secttype)); + } + setCurrentSection(findSection(pzName, secttype, org, attributes->bank, 1 << attributes->alignment)); } diff --git a/test/link/fixed-oob.asm b/test/asm/fixed-oob.asm similarity index 100% rename from test/link/fixed-oob.asm rename to test/asm/fixed-oob.asm diff --git a/test/asm/fixed-oob.err b/test/asm/fixed-oob.err new file mode 100644 index 00000000..eac02cf2 --- /dev/null +++ b/test/asm/fixed-oob.err @@ -0,0 +1,15 @@ +ERROR: fixed-oob.asm(1): + Section "ROM0"'s fixed address 0xbabe is outside of range [0; 0x7fff] +ERROR: fixed-oob.asm(3): + Section "ROMX"'s fixed address 0xbeef is outside of range [0x4000; 0x7fff] +ERROR: fixed-oob.asm(5): + Section "VRAM"'s fixed address 0xc0de is outside of range [0x8000; 0x9fff] +ERROR: fixed-oob.asm(7): + Section "SRAM"'s fixed address 0xcafe is outside of range [0xa000; 0xbfff] +ERROR: fixed-oob.asm(11): + Section "WRAMX"'s fixed address 0xdad is outside of range [0xd000; 0xdfff] +ERROR: fixed-oob.asm(13): + Section "OAM"'s fixed address 0xcab is outside of range [0xfe00; 0xfe9f] +ERROR: fixed-oob.asm(15): + Section "HRAM"'s fixed address 0xbad is outside of range [0xff80; 0xfffe] +error: Assembly aborted (7 errors)! diff --git a/test/asm/fixed-oob.out b/test/asm/fixed-oob.out new file mode 100644 index 00000000..e69de29b diff --git a/test/link/fixed-oob.out b/test/link/fixed-oob.out deleted file mode 100644 index 3270d159..00000000 --- a/test/link/fixed-oob.out +++ /dev/null @@ -1,14 +0,0 @@ -warning: Section "VRAM"'s fixed address 0xc0de is outside of range [0x8000; 0x9fff] -warning: Section "VRAM"'s end address 0xc0de is greater than last address 0xa000 -warning: Section "OAM"'s fixed address 0xcab is outside of range [0xfe00; 0xfe9f] -warning: Section "WRAM0"'s fixed address 0xdead is outside of range [0xc000; 0xcfff] -warning: Section "WRAM0"'s end address 0xdead is greater than last address 0xd000 -warning: Section "HRAM"'s fixed address 0xbad is outside of range [0xff80; 0xfffe] -warning: Section "SRAM"'s fixed address 0xcafe is outside of range [0xa000; 0xbfff] -warning: Section "SRAM"'s end address 0xcafe is greater than last address 0xc000 -warning: Section "WRAMX"'s fixed address 0xdad is outside of range [0xd000; 0xdfff] -warning: Section "ROMX"'s fixed address 0xbeef is outside of range [0x4000; 0x7fff] -warning: Section "ROMX"'s end address 0xbeef is greater than last address 0x8000 -warning: Section "ROM0"'s fixed address 0xbabe is outside of range [0; 0x3fff] -warning: Section "ROM0"'s end address 0xbabe is greater than last address 0x4000 -error: Sanity checks failed