Unify all section declarations

This commit is contained in:
ISSOtm
2020-02-04 01:52:18 +01:00
parent 34597ce6a0
commit a4fe274c25
5 changed files with 60 additions and 74 deletions

View File

@@ -37,20 +37,6 @@ char *tzNewMacro;
uint32_t ulNewMacroSize;
int32_t nPCOffset;
static void bankrangecheck(char *name, uint32_t secttype, int32_t org,
int32_t bank)
{
if (secttype != SECTTYPE_ROMX && secttype != SECTTYPE_VRAM
&& secttype != SECTTYPE_SRAM && secttype != SECTTYPE_WRAMX)
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
else if (bank < bankranges[secttype][0] || bank > bankranges[secttype][1])
yyerror("%s bank value $%x out of range ($%x to $%x)",
typeNames[secttype], bank, bankranges[secttype][0],
bankranges[secttype][1]);
out_NewAbsSection(name, secttype, org, bank);
}
size_t symvaluetostring(char *dest, size_t maxLength, char *symName,
const char *mode)
{
@@ -509,6 +495,7 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
char tzString[MAXSTRLEN + 1];
struct Expression sVal;
int32_t nConstValue;
struct SectionSpec sectSpec;
}
%type <sVal> relocconst
@@ -521,6 +508,9 @@ static void strsubUTF8(char *dest, const char *src, uint32_t pos, uint32_t len)
%type <tzString> string
%type <nConstValue> sectorg
%type <sectSpec> sectattrs
%token <nConstValue> T_NUMBER
%token <tzString> T_STRING
@@ -1384,38 +1374,9 @@ string : T_STRING
}
;
section : T_POP_SECTION string comma sectiontype
section : T_POP_SECTION string comma sectiontype sectorg sectattrs
{
out_NewSection($2, $4);
}
| T_POP_SECTION string comma sectiontype '[' uconst ']'
{
if (($6 >= 0) && ($6 < 0x10000))
out_NewAbsSection($2, $4, $6, -1);
else
yyerror("Address $%x not 16-bit", $6);
}
| T_POP_SECTION string comma sectiontype comma T_OP_ALIGN '[' uconst ']'
{
out_NewAlignedSection($2, $4, $8, -1);
}
| T_POP_SECTION string comma sectiontype comma T_OP_BANK '[' uconst ']'
{
bankrangecheck($2, $4, -1, $8);
}
| T_POP_SECTION string comma sectiontype '[' uconst ']' comma T_OP_BANK '[' uconst ']'
{
if (($6 < 0) || ($6 > 0x10000))
yyerror("Address $%x not 16-bit", $6);
bankrangecheck($2, $4, $6, $11);
}
| T_POP_SECTION string comma sectiontype comma T_OP_ALIGN '[' uconst ']' comma T_OP_BANK '[' uconst ']'
{
out_NewAlignedSection($2, $4, $8, $13);
}
| T_POP_SECTION string comma sectiontype comma T_OP_BANK '[' uconst ']' comma T_OP_ALIGN '[' uconst ']'
{
out_NewAlignedSection($2, $4, $13, $8);
out_NewSection($2, $4, $5, &$6);
}
;
@@ -1449,6 +1410,36 @@ sectiontype : T_SECT_WRAM0 { $$ = SECTTYPE_WRAM0; }
}
;
sectorg : { $$ = -1; }
| '[' uconst ']'
{
if ($2 < 0 || $2 >= 0x10000)
yyerror("Address $%x is not 16-bit", $2);
else
$$ = $2;
}
;
sectattrs :
{
$$.alignment = 0;
$$.bank = -1;
}
| sectattrs comma T_OP_ALIGN '[' uconst ']'
{
if ($5 < 0 || $5 > 16)
yyerror("Alignment must be between 0 and 16 bits, not %u",
$5);
else
$$.alignment = $5;
}
| sectattrs comma T_OP_BANK '[' uconst ']'
{
/* We cannot check the validity of this now */
$$.bank = $5;
}
;
cpu_command : z80_adc
| z80_add

View File

@@ -17,7 +17,7 @@
#include "asm/lexer.h"
#include "asm/main.h"
#include "asm/rpn.h"
#include "asm/symbol.h"
#include "asm/section.h"
#include "asm/symbol.h"
#include "asm/warning.h"

View File

@@ -19,6 +19,7 @@
#include "asm/lexer.h"
#include "asm/main.h"
#include "asm/rpn.h"
#include "asm/section.h"
#include "asm/warning.h"
#include "extern/err.h"

View File

@@ -156,31 +156,23 @@ static void setCurrentSection(struct Section *pSect)
/*
* Set the current section by name and type
*/
void out_NewSection(char const *pzName, uint32_t secttype)
void out_NewSection(char const *pzName, uint32_t secttype, int32_t org,
struct SectionSpec const *attributes)
{
setCurrentSection(findSection(pzName, secttype, -1, -1, 1));
}
if (attributes->bank != -1) {
if (secttype != SECTTYPE_ROMX && secttype != SECTTYPE_VRAM
&& secttype != SECTTYPE_SRAM && secttype != SECTTYPE_WRAMX)
yyerror("BANK only allowed for ROMX, WRAMX, SRAM, or VRAM sections");
else if (attributes->bank < bankranges[secttype][0]
|| attributes->bank > bankranges[secttype][1])
yyerror("%s bank value $%x out of range ($%x to $%x)",
typeNames[secttype], attributes->bank,
bankranges[secttype][0],
bankranges[secttype][1]);
}
/*
* Set the current section by name and type
*/
void out_NewAbsSection(char const *pzName, uint32_t secttype, int32_t org,
int32_t bank)
{
setCurrentSection(findSection(pzName, secttype, org, bank, 1));
}
/*
* Set the current section by name and type, using a given byte alignment
*/
void out_NewAlignedSection(char const *pzName, uint32_t secttype,
int32_t alignment, int32_t bank)
{
if (alignment < 0 || alignment > 16)
yyerror("Alignment must be between 0-16 bits.");
setCurrentSection(findSection(pzName, secttype, -1, bank,
1 << alignment));
setCurrentSection(findSection(pzName, secttype, org, attributes->bank,
1 << attributes->alignment));
}
/*