Ensure that mid-section align 16 makes PC constant

This makes `align 16` a sort of `org`, which is *very* useful :)
This commit is contained in:
ISSOtm
2024-02-18 22:30:52 +01:00
committed by Sylvie
parent 36dad4380e
commit 1b08a12b26
3 changed files with 18 additions and 2 deletions

View File

@@ -353,10 +353,10 @@ static struct Section *getSection(char const *name, enum SectionType type, uint3
alignment = 0; // Ignore it if it's unattainable alignment = 0; // Ignore it if it's unattainable
org = 0; org = 0;
} else if (alignment == 16) { } else if (alignment == 16) {
// Treat an alignment of 16 as being fixed at address 0 // Treat an alignment of 16 as fixing the address.
alignment = 0; alignment = 0;
org = alignOffset; org = alignOffset;
// The address is known to be valid, since the alignment is // The address is known to be valid, since the alignment itself is.
} }
} }
@@ -508,6 +508,14 @@ void sect_AlignPC(uint8_t alignment, uint16_t offset)
- offset) % alignSize) { - offset) % alignSize) {
error("Section's alignment fails required alignment (offset from section start = $%04" error("Section's alignment fails required alignment (offset from section start = $%04"
PRIx32 ")\n", curOffset); PRIx32 ")\n", curOffset);
} else if (alignment >= 16) {
// Treat an alignment large enough as fixing the address.
// Note that this also ensures that a section's alignment never becomes 16 or greater.
if (alignment > 16) {
error("Alignment must be between 0 and 16, not %u\n", alignment);
}
sect->align = 0; // Reset the alignment, since we're fixing the address.
sect->org = offset - curOffset;
} else if (alignment > sect->align) { } else if (alignment > sect->align) {
sect->align = alignment; sect->align = alignment;
// We need `(sect->alignOfs + curOffset) % alignSize == offset` // We need `(sect->alignOfs + curOffset) % alignSize == offset`

View File

@@ -6,3 +6,9 @@ SECTION "Byte", ROM0
SECTION "ROM0", ROM0, ALIGN[16] SECTION "ROM0", ROM0, ALIGN[16]
db 1 db 1
println @ ; Ensure that PC is constant.
SECTION "Mid-section align makes PC constant", ROM0
align 16, 42
println @

2
test/asm/align-16.out Normal file
View File

@@ -0,0 +1,2 @@
$1
$2A