mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 10:12:06 +00:00
Expose link def arrays to RGBASM
This commit is contained in:
6
Makefile
6
Makefile
@@ -67,7 +67,8 @@ rgbasm_obj := \
|
|||||||
src/asm/warning.o \
|
src/asm/warning.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/getopt.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
|
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/link/symbol.o \
|
||||||
src/extern/err.o \
|
src/extern/err.o \
|
||||||
src/extern/getopt.o \
|
src/extern/getopt.o \
|
||||||
src/hashmap.o
|
src/hashmap.o \
|
||||||
|
src/linkdefs.o
|
||||||
|
|
||||||
rgbfix_obj := \
|
rgbfix_obj := \
|
||||||
src/fix/main.o \
|
src/fix/main.o \
|
||||||
|
|||||||
@@ -53,29 +53,6 @@ struct Section {
|
|||||||
struct Symbol const **symbols;
|
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.
|
* Execute a callback for each section currently registered.
|
||||||
* This is to avoid exposing the data structure in which sections are stored.
|
* This is to avoid exposing the data structure in which sections are stored.
|
||||||
|
|||||||
@@ -9,6 +9,9 @@
|
|||||||
#ifndef RGBDS_LINKDEFS_H
|
#ifndef RGBDS_LINKDEFS_H
|
||||||
#define RGBDS_LINKDEFS_H
|
#define RGBDS_LINKDEFS_H
|
||||||
|
|
||||||
|
#include <stdbool.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
|
#define RGBDS_OBJECT_VERSION_STRING "RGB%1hhu"
|
||||||
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)6
|
#define RGBDS_OBJECT_VERSION_NUMBER (uint8_t)6
|
||||||
|
|
||||||
@@ -92,6 +95,17 @@ enum SectionType {
|
|||||||
SECTTYPE_INVALID
|
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 {
|
enum ExportLevel {
|
||||||
SYMTYPE_LOCAL,
|
SYMTYPE_LOCAL,
|
||||||
SYMTYPE_IMPORT,
|
SYMTYPE_IMPORT,
|
||||||
@@ -107,15 +121,28 @@ enum PatchType {
|
|||||||
PATCHTYPE_INVALID
|
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,
|
* Computes a memory region's end address (last byte), eg. 0x7FFF
|
||||||
* depending on type.
|
* @return The address of the last byte in that memory region
|
||||||
* @param type The section's type
|
|
||||||
* @return `true` if the section's definition includes data
|
|
||||||
*/
|
*/
|
||||||
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 */
|
#endif /* RGBDS_LINKDEFS_H */
|
||||||
|
|||||||
@@ -509,11 +509,11 @@ static void checkcodesection(void)
|
|||||||
*/
|
*/
|
||||||
static void checksectionoverflow(uint32_t delta_size)
|
static void checksectionoverflow(uint32_t delta_size)
|
||||||
{
|
{
|
||||||
uint32_t maxsize = getmaxsectionsize(pCurrentSection->nType,
|
uint32_t maxSize = getmaxsectionsize(pCurrentSection->nType,
|
||||||
pCurrentSection->pzName);
|
pCurrentSection->pzName);
|
||||||
uint32_t new_size = pCurrentSection->nPC + delta_size;
|
uint32_t newSize = pCurrentSection->nPC + delta_size;
|
||||||
|
|
||||||
if (new_size > maxsize) {
|
if (newSize > maxSize) {
|
||||||
/*
|
/*
|
||||||
* This check is here to trap broken code that generates
|
* This check is here to trap broken code that generates
|
||||||
* sections that are too big and to prevent the assembler from
|
* 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.
|
* The real check must be done at the linking stage.
|
||||||
*/
|
*/
|
||||||
fatalerror("Section '%s' is too big (max size = 0x%X bytes, reached 0x%X).",
|
fatalerror("Section '%s' is too big (max size = 0x%X bytes, reached 0x%X).",
|
||||||
pCurrentSection->pzName, maxsize, new_size);
|
pCurrentSection->pzName, maxSize, newSize);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,50 +15,6 @@
|
|||||||
|
|
||||||
#include "hashmap.h"
|
#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;
|
HashMap sections;
|
||||||
|
|
||||||
struct ForEachArg {
|
struct ForEachArg {
|
||||||
|
|||||||
46
src/linkdefs.c
Normal file
46
src/linkdefs.c
Normal file
@@ -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"
|
||||||
|
};
|
||||||
Reference in New Issue
Block a user