From 69d7f845025dfcc3017e58453273be46a0107993 Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Fri, 21 May 2021 09:06:48 +0200 Subject: [PATCH] Reset LOAD offset when changing SECTIONs This would cause spurious section overflow messages, since the load offset is added to the section's when computing its size. --- src/asm/section.c | 18 +++++++++--------- test/asm/load-pushs-load.asm | 27 +++++++++++++++++++++++++++ test/asm/load-pushs-load.err | 0 test/asm/load-pushs-load.out | 0 test/asm/load-pushs-load.out.bin | 1 + test/asm/load-pushs.asm | 15 +++++++++++++++ test/asm/load-pushs.err | 0 test/asm/load-pushs.out | 0 test/asm/load-pushs.out.bin | Bin 0 -> 3 bytes 9 files changed, 52 insertions(+), 9 deletions(-) create mode 100644 test/asm/load-pushs-load.asm create mode 100644 test/asm/load-pushs-load.err create mode 100644 test/asm/load-pushs-load.out create mode 100644 test/asm/load-pushs-load.out.bin create mode 100644 test/asm/load-pushs.asm create mode 100644 test/asm/load-pushs.err create mode 100644 test/asm/load-pushs.out create mode 100644 test/asm/load-pushs.out.bin diff --git a/src/asm/section.c b/src/asm/section.c index c1656816..15ac74ff 100644 --- a/src/asm/section.c +++ b/src/asm/section.c @@ -418,6 +418,7 @@ void sect_NewSection(char const *name, uint32_t type, uint32_t org, changeSection(); curOffset = mod == SECTION_UNION ? 0 : sect->size; + loadOffset = 0; // This is still used when checking for section size overflow! currentSection = sect; } @@ -989,16 +990,15 @@ void sect_PopSection(void) if (currentLoadSection) fatalerror("Cannot change the section within a `LOAD` block!\n"); - struct SectionStackEntry *sect; + struct SectionStackEntry *entry = sectionStack; - sect = sectionStack; changeSection(); - currentSection = sect->section; - currentLoadSection = sect->loadSection; - sym_SetCurrentSymbolScope(sect->scope); - curOffset = sect->offset; - loadOffset = sect->loadOffset; + currentSection = entry->section; + currentLoadSection = entry->loadSection; + sym_SetCurrentSymbolScope(entry->scope); + curOffset = entry->offset; + loadOffset = entry->loadOffset; - sectionStack = sect->next; - free(sect); + sectionStack = entry->next; + free(entry); } diff --git a/test/asm/load-pushs-load.asm b/test/asm/load-pushs-load.asm new file mode 100644 index 00000000..d5b4fb47 --- /dev/null +++ b/test/asm/load-pushs-load.asm @@ -0,0 +1,27 @@ + +SECTION "Output", ROM0[0] + dw Rom0Label1 + dw Rom0Label2 + dw SramLabel1 + dw SramLabel2 + dw RomxLabel1 + dw RomxLabel2 + dw HramLabel + + +SECTION "A", ROM0[$1324] +Rom0Label1: +LOAD "LA", SRAM[$BEAD] + SramLabel1: + PUSHS + ; not inside a section or load section here yet + SECTION "B", ROMX[$4698] + RomxLabel1: + LOAD "LB", HRAM[$FF86] + HramLabel: + ENDL + RomxLabel2: + POPS + SramLabel2: +ENDL +Rom0Label2: diff --git a/test/asm/load-pushs-load.err b/test/asm/load-pushs-load.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/load-pushs-load.out b/test/asm/load-pushs-load.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/load-pushs-load.out.bin b/test/asm/load-pushs-load.out.bin new file mode 100644 index 00000000..6b5c9a6b --- /dev/null +++ b/test/asm/load-pushs-load.out.bin @@ -0,0 +1 @@ +$$­¾­¾˜F˜F†ÿ \ No newline at end of file diff --git a/test/asm/load-pushs.asm b/test/asm/load-pushs.asm new file mode 100644 index 00000000..9896cd2e --- /dev/null +++ b/test/asm/load-pushs.asm @@ -0,0 +1,15 @@ + +SECTION "Output", ROM0[0] + db SIZEOF("ROM CODE") + db SIZEOF("RAM CODE") + db SIZEOF("HRAM") + + +SECTION "ROM CODE",ROM0 + ds $80 +LOAD "RAM CODE",SRAM +PUSHS +SECTION "HRAM",HRAM + ds 1 +POPS +ENDL diff --git a/test/asm/load-pushs.err b/test/asm/load-pushs.err new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/load-pushs.out b/test/asm/load-pushs.out new file mode 100644 index 00000000..e69de29b diff --git a/test/asm/load-pushs.out.bin b/test/asm/load-pushs.out.bin new file mode 100644 index 0000000000000000000000000000000000000000..458f0df227e8a9b638c6544ffc4361c06995b012 GIT binary patch literal 3 KcmZo*U<3dGgaCp7 literal 0 HcmV?d00001