From 24f41ef8973a464896db7123019bed96761856ad Mon Sep 17 00:00:00 2001 From: ISSOtm Date: Mon, 3 Feb 2020 14:58:25 +0100 Subject: [PATCH] Expose link def arrays to RGBASM --- Makefile | 6 ++++-- include/link/section.h | 23 --------------------- include/linkdefs.h | 39 +++++++++++++++++++++++++++++------ src/asm/output.c | 10 ++++----- src/link/section.c | 44 ---------------------------------------- src/linkdefs.c | 46 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 88 insertions(+), 80 deletions(-) create mode 100644 src/linkdefs.c diff --git a/Makefile b/Makefile index fc6e159b..e945a598 100644 --- a/Makefile +++ b/Makefile @@ -67,7 +67,8 @@ rgbasm_obj := \ src/asm/warning.o \ src/extern/err.o \ src/extern/getopt.o \ - src/extern/utf8decoder.o + src/extern/utf8decoder.o \ + src/linkdefs.o src/asm/globlex.o src/asm/lexer.o src/asm/constexpr.o: src/asm/asmy.h @@ -82,7 +83,8 @@ rgblink_obj := \ src/link/symbol.o \ src/extern/err.o \ src/extern/getopt.o \ - src/hashmap.o + src/hashmap.o \ + src/linkdefs.o rgbfix_obj := \ src/fix/main.o \ diff --git a/include/link/section.h b/include/link/section.h index 64b91278..635a7c0d 100644 --- a/include/link/section.h +++ b/include/link/section.h @@ -53,29 +53,6 @@ struct Section { struct Symbol const **symbols; }; -extern uint16_t startaddr[]; -extern uint16_t maxsize[]; -extern uint32_t bankranges[][2]; -extern char const * const typeNames[SECTTYPE_INVALID]; - -/** - * Computes a memory region's end address (last byte), eg. 0x7FFF - * @return The address of the last byte in that memory region - */ -static inline uint16_t endaddr(enum SectionType type) -{ - return startaddr[type] + maxsize[type] - 1; -} - -/** - * Computes a memory region's number of banks - * @return The number of banks, 1 for regions without banking - */ -static inline uint32_t nbbanks(enum SectionType type) -{ - return bankranges[type][1] - bankranges[type][0] + 1; -} - /* * Execute a callback for each section currently registered. * This is to avoid exposing the data structure in which sections are stored. diff --git a/include/linkdefs.h b/include/linkdefs.h index 3e630501..227722c3 100644 --- a/include/linkdefs.h +++ b/include/linkdefs.h @@ -9,6 +9,9 @@ #ifndef RGBDS_LINKDEFS_H #define RGBDS_LINKDEFS_H +#include +#include + #define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu" #define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)6 @@ -92,6 +95,17 @@ enum SectionType { SECTTYPE_INVALID }; +/** + * Tells whether a section has data in its object file definition, + * depending on type. + * @param type The section's type + * @return `true` if the section's definition includes data + */ +static inline bool sect_HasData(enum SectionType type) +{ + return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX; +} + enum ExportLevel { SYMTYPE_LOCAL, SYMTYPE_IMPORT, @@ -107,15 +121,28 @@ enum PatchType { PATCHTYPE_INVALID }; +extern uint16_t startaddr[]; +extern uint16_t maxsize[]; +extern uint32_t bankranges[][2]; + /** - * Tells whether a section has data in its object file definition, - * depending on type. - * @param type The section's type - * @return `true` if the section's definition includes data + * Computes a memory region's end address (last byte), eg. 0x7FFF + * @return The address of the last byte in that memory region */ -static inline bool sect_HasData(enum SectionType type) +static inline uint16_t endaddr(enum SectionType type) { - return type == SECTTYPE_ROM0 || type == SECTTYPE_ROMX; + return startaddr[type] + maxsize[type] - 1; } +/** + * Computes a memory region's number of banks + * @return The number of banks, 1 for regions without banking + */ +static inline uint32_t nbbanks(enum SectionType type) +{ + return bankranges[type][1] - bankranges[type][0] + 1; +} + +extern char const * const typeNames[SECTTYPE_INVALID]; + #endif /* RGBDS_LINKDEFS_H */ diff --git a/src/asm/output.c b/src/asm/output.c index 60077cf1..80833db1 100644 --- a/src/asm/output.c +++ b/src/asm/output.c @@ -509,11 +509,11 @@ static void checkcodesection(void) */ static void checksectionoverflow(uint32_t delta_size) { - uint32_t maxsize = getmaxsectionsize(pCurrentSection->nType, - pCurrentSection->pzName); - uint32_t new_size = pCurrentSection->nPC + delta_size; + uint32_t maxSize = getmaxsectionsize(pCurrentSection->nType, + pCurrentSection->pzName); + uint32_t newSize = pCurrentSection->nPC + delta_size; - if (new_size > maxsize) { + if (newSize > maxSize) { /* * This check is here to trap broken code that generates * sections that are too big and to prevent the assembler from @@ -522,7 +522,7 @@ static void checksectionoverflow(uint32_t delta_size) * The real check must be done at the linking stage. */ fatalerror("Section '%s' is too big (max size = 0x%X bytes, reached 0x%X).", - pCurrentSection->pzName, maxsize, new_size); + pCurrentSection->pzName, maxSize, newSize); } } diff --git a/src/link/section.c b/src/link/section.c index 28ebc4b7..02ee418f 100644 --- a/src/link/section.c +++ b/src/link/section.c @@ -15,50 +15,6 @@ #include "hashmap.h" -uint16_t startaddr[] = { - [SECTTYPE_ROM0] = 0x0000, - [SECTTYPE_ROMX] = 0x4000, - [SECTTYPE_VRAM] = 0x8000, - [SECTTYPE_SRAM] = 0xA000, - [SECTTYPE_WRAM0] = 0xC000, - [SECTTYPE_WRAMX] = 0xD000, - [SECTTYPE_OAM] = 0xFE00, - [SECTTYPE_HRAM] = 0xFF80 -}; - -uint16_t maxsize[] = { - [SECTTYPE_ROM0] = 0x4000, - [SECTTYPE_ROMX] = 0x4000, - [SECTTYPE_VRAM] = 0x2000, - [SECTTYPE_SRAM] = 0x2000, - [SECTTYPE_WRAM0] = 0x1000, - [SECTTYPE_WRAMX] = 0x1000, - [SECTTYPE_OAM] = 0x00A0, - [SECTTYPE_HRAM] = 0x007F -}; - -uint32_t bankranges[][2] = { - [SECTTYPE_ROM0] = {BANK_MIN_ROM0, BANK_MAX_ROM0}, - [SECTTYPE_ROMX] = {BANK_MIN_ROMX, BANK_MAX_ROMX}, - [SECTTYPE_VRAM] = {BANK_MIN_VRAM, BANK_MAX_VRAM}, - [SECTTYPE_SRAM] = {BANK_MIN_SRAM, BANK_MAX_SRAM}, - [SECTTYPE_WRAM0] = {BANK_MIN_WRAM0, BANK_MAX_WRAM0}, - [SECTTYPE_WRAMX] = {BANK_MIN_WRAMX, BANK_MAX_WRAMX}, - [SECTTYPE_OAM] = {BANK_MIN_OAM, BANK_MAX_OAM}, - [SECTTYPE_HRAM] = {BANK_MIN_HRAM, BANK_MAX_HRAM} -}; - -char const * const typeNames[] = { - [SECTTYPE_ROM0] = "ROM0", - [SECTTYPE_ROMX] = "ROMX", - [SECTTYPE_VRAM] = "VRAM", - [SECTTYPE_SRAM] = "SRAM", - [SECTTYPE_WRAM0] = "WRAM0", - [SECTTYPE_WRAMX] = "WRAMX", - [SECTTYPE_OAM] = "OAM", - [SECTTYPE_HRAM] = "HRAM" -}; - HashMap sections; struct ForEachArg { diff --git a/src/linkdefs.c b/src/linkdefs.c new file mode 100644 index 00000000..4a3d9b30 --- /dev/null +++ b/src/linkdefs.c @@ -0,0 +1,46 @@ + +#include "linkdefs.h" + +uint16_t startaddr[] = { + [SECTTYPE_ROM0] = 0x0000, + [SECTTYPE_ROMX] = 0x4000, + [SECTTYPE_VRAM] = 0x8000, + [SECTTYPE_SRAM] = 0xA000, + [SECTTYPE_WRAM0] = 0xC000, + [SECTTYPE_WRAMX] = 0xD000, + [SECTTYPE_OAM] = 0xFE00, + [SECTTYPE_HRAM] = 0xFF80 +}; + +uint16_t maxsize[] = { + [SECTTYPE_ROM0] = 0x4000, + [SECTTYPE_ROMX] = 0x4000, + [SECTTYPE_VRAM] = 0x2000, + [SECTTYPE_SRAM] = 0x2000, + [SECTTYPE_WRAM0] = 0x1000, + [SECTTYPE_WRAMX] = 0x1000, + [SECTTYPE_OAM] = 0x00A0, + [SECTTYPE_HRAM] = 0x007F +}; + +uint32_t bankranges[][2] = { + [SECTTYPE_ROM0] = {BANK_MIN_ROM0, BANK_MAX_ROM0}, + [SECTTYPE_ROMX] = {BANK_MIN_ROMX, BANK_MAX_ROMX}, + [SECTTYPE_VRAM] = {BANK_MIN_VRAM, BANK_MAX_VRAM}, + [SECTTYPE_SRAM] = {BANK_MIN_SRAM, BANK_MAX_SRAM}, + [SECTTYPE_WRAM0] = {BANK_MIN_WRAM0, BANK_MAX_WRAM0}, + [SECTTYPE_WRAMX] = {BANK_MIN_WRAMX, BANK_MAX_WRAMX}, + [SECTTYPE_OAM] = {BANK_MIN_OAM, BANK_MAX_OAM}, + [SECTTYPE_HRAM] = {BANK_MIN_HRAM, BANK_MAX_HRAM} +}; + +char const * const typeNames[] = { + [SECTTYPE_ROM0] = "ROM0", + [SECTTYPE_ROMX] = "ROMX", + [SECTTYPE_VRAM] = "VRAM", + [SECTTYPE_SRAM] = "SRAM", + [SECTTYPE_WRAM0] = "WRAM0", + [SECTTYPE_WRAMX] = "WRAMX", + [SECTTYPE_OAM] = "OAM", + [SECTTYPE_HRAM] = "HRAM" +};