mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-20 18:22:07 +00:00
Implement linkerscript parser
Signed-off-by: AntonioND <antonio_nd@outlook.com>
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "extern/err.h"
|
||||
#include "link/mylink.h"
|
||||
@@ -214,6 +215,54 @@ FindLargestSection(enum eSectionType type, bool bankFixed)
|
||||
return r;
|
||||
}
|
||||
|
||||
int
|
||||
IsSectionSameTypeBankAndFloating(const char *name, enum eSectionType type, int bank)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0) {
|
||||
if (strcmp(pSection->pzName, name) == 0) {
|
||||
/* Section must be floating in source */
|
||||
if (pSection->nOrg != -1 || pSection->nAlign != 1)
|
||||
return 0;
|
||||
/* It must have the same type in source and linkerscript */
|
||||
if (pSection->Type != type)
|
||||
return 0;
|
||||
/* Bank number must be unassigned in source or equal */
|
||||
if (pSection->nBank != -1 && pSection->nBank != bank)
|
||||
return 0;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
|
||||
errx(1, "Section \"%s\" not found (or already used).\n", name);
|
||||
}
|
||||
|
||||
unsigned int
|
||||
AssignSectionAddressByName(const char *name, unsigned int address)
|
||||
{
|
||||
struct sSection *pSection;
|
||||
|
||||
pSection = pSections;
|
||||
while (pSection) {
|
||||
if (pSection->oAssigned == 0) {
|
||||
if (strcmp(pSection->pzName, name) == 0) {
|
||||
if (pSection->nOrg != -1 || pSection->nAlign != 1)
|
||||
errx(1, "Section \"%s\" from linkerscript isn't floating.\n", name);
|
||||
pSection->nOrg = address;
|
||||
pSection->nAlign = -1;
|
||||
return pSection->nByteSize;
|
||||
}
|
||||
}
|
||||
pSection = pSection->pNext;
|
||||
}
|
||||
|
||||
errx(1, "Section \"%s\" not found (or already used).\n", name);
|
||||
}
|
||||
|
||||
bool
|
||||
VerifyAndSetBank(struct sSection *pSection)
|
||||
|
||||
Reference in New Issue
Block a user