Do some misc cleanup of output.c

This commit is contained in:
ISSOtm
2020-02-03 22:52:46 +01:00
parent d0278d8663
commit bfdbd00092
2 changed files with 17 additions and 50 deletions

View File

@@ -13,9 +13,11 @@
#include "asm/rpn.h" #include "asm/rpn.h"
#include "linkdefs.h"
struct Section { struct Section {
char *pzName; char *pzName;
uint8_t nType; enum SectionType nType;
uint32_t nPC; uint32_t nPC;
uint32_t nOrg; uint32_t nOrg;
uint32_t nBank; uint32_t nBank;

View File

@@ -110,31 +110,6 @@ void out_PopSection(void)
free(pSect); free(pSect);
} }
static uint32_t getmaxsectionsize(uint32_t secttype, char *sectname)
{
switch (secttype) {
case SECTTYPE_ROM0:
return 0x8000; /* If ROMX sections not used */
case SECTTYPE_ROMX:
return 0x4000;
case SECTTYPE_VRAM:
return 0x2000;
case SECTTYPE_SRAM:
return 0x2000;
case SECTTYPE_WRAM0:
return 0x2000; /* If WRAMX sections not used */
case SECTTYPE_WRAMX:
return 0x1000;
case SECTTYPE_OAM:
return 0xA0;
case SECTTYPE_HRAM:
return 0x7F;
default:
break;
}
errx(1, "Section \"%s\" has an invalid section type.", sectname);
}
/* /*
* Count the number of symbols used in this object * Count the number of symbols used in this object
*/ */
@@ -144,13 +119,12 @@ static uint32_t countsymbols(void)
uint32_t count = 0; uint32_t count = 0;
pSym = pPatchSymbols; pSym = pPatchSymbols;
while (pSym) { while (pSym) {
count++; count++;
pSym = pSym->pNext; pSym = pSym->pNext;
} }
return (count); return count;
} }
/* /*
@@ -162,13 +136,12 @@ static uint32_t countsections(void)
uint32_t count = 0; uint32_t count = 0;
pSect = pSectionList; pSect = pSectionList;
while (pSect) { while (pSect) {
count++; count++;
pSect = pSect->pNext; pSect = pSect->pNext;
} }
return (count); return count;
} }
/* /*
@@ -185,7 +158,7 @@ static uint32_t countpatches(struct Section *pSect)
pPatch = pPatch->pNext; pPatch = pPatch->pNext;
} }
return (r); return r;
} }
/* /*
@@ -226,8 +199,7 @@ static uint32_t getsectid(struct Section *pSect)
sec = sec->pNext; sec = sec->pNext;
} }
fatalerror("%s: Unknown section", __func__); fatalerror("Unknown section '%s'", pSect->pzName);
return (uint32_t)(-1);
} }
/* /*
@@ -513,21 +485,20 @@ static void checksection(void)
static void checkcodesection(void) static void checkcodesection(void)
{ {
checksection(); checksection();
if (!sect_HasData(pCurrentSection->nType)) {
if (!sect_HasData(pCurrentSection->nType))
fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)", fatalerror("Section '%s' cannot contain code or data (not ROM0 or ROMX)",
pCurrentSection->pzName); pCurrentSection->pzName);
} else if (nUnionDepth > 0) { else if (nUnionDepth > 0)
fatalerror("UNIONs cannot contain code or data"); fatalerror("UNIONs cannot contain code or data");
} }
}
/* /*
* Check if the section has grown too much. * Check if the section has grown too much.
*/ */
static void checksectionoverflow(uint32_t delta_size) static void checksectionoverflow(uint32_t delta_size)
{ {
uint32_t maxSize = getmaxsectionsize(pCurrentSection->nType, uint32_t maxSize = maxsize[pCurrentSection->nType];
pCurrentSection->pzName);
uint32_t newSize = pCurrentSection->nPC + delta_size; uint32_t newSize = pCurrentSection->nPC + delta_size;
if (newSize > maxSize) { if (newSize > maxSize) {
@@ -623,8 +594,8 @@ struct Section *out_FindSectionByName(const char *pzName)
/* /*
* Find a section by name and type. If it doesn't exist, create it * Find a section by name and type. If it doesn't exist, create it
*/ */
struct Section *out_FindSection(char *pzName, uint32_t secttype, int32_t org, struct Section *out_FindSection(char *pzName, enum SectionType secttype,
int32_t bank, int32_t alignment) int32_t org, int32_t bank, int32_t alignment)
{ {
struct Section *pSect = out_FindSectionByName(pzName); struct Section *pSect = out_FindSectionByName(pzName);
@@ -638,7 +609,7 @@ struct Section *out_FindSection(char *pzName, uint32_t secttype, int32_t org,
fatalerror("Section already exists but with a different type"); fatalerror("Section already exists but with a different type");
} }
pSect = malloc(sizeof(struct Section)); pSect = malloc(sizeof(*pSect));
if (pSect == NULL) if (pSect == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section");
@@ -646,14 +617,8 @@ struct Section *out_FindSection(char *pzName, uint32_t secttype, int32_t org,
if (pSect->pzName == NULL) if (pSect->pzName == NULL)
fatalerror("Not enough memory for sectionname"); fatalerror("Not enough memory for sectionname");
// Force the bank to be 0 if that's the only possibility if (nbbanks(secttype) == 1)
switch (secttype) { bank = bankranges[secttype][0];
case SECTTYPE_ROM0:
case SECTTYPE_WRAM0:
case SECTTYPE_OAM:
case SECTTYPE_HRAM:
bank = 0;
}
pSect->nType = secttype; pSect->nType = secttype;
pSect->nPC = 0; pSect->nPC = 0;
@@ -667,7 +632,7 @@ struct Section *out_FindSection(char *pzName, uint32_t secttype, int32_t org,
if (sect_HasData(secttype)) { if (sect_HasData(secttype)) {
uint32_t sectsize; uint32_t sectsize;
sectsize = getmaxsectionsize(secttype, pzName); sectsize = maxsize[secttype];
pSect->tData = malloc(sectsize); pSect->tData = malloc(sectsize);
if (pSect->tData == NULL) if (pSect->tData == NULL)
fatalerror("Not enough memory for section"); fatalerror("Not enough memory for section");