Started to add a new .BANK instruction that allows access to a memory area
attribute named "bank". Some error checks and a lot of testing is required. Don't use for now. git-svn-id: svn://svn.cc65.org/cc65/trunk@5375 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* (C) 1998-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -102,6 +102,7 @@ static Collection MemoryAreas = STATIC_COLLECTION_INITIALIZER;
|
||||
#define MA_DEFINE 0x0010
|
||||
#define MA_FILL 0x0020
|
||||
#define MA_FILLVAL 0x0040
|
||||
#define MA_BANK 0x0080
|
||||
|
||||
/* Segment list */
|
||||
static Collection SegDescList = STATIC_COLLECTION_INITIALIZER;
|
||||
@@ -405,13 +406,14 @@ static void ParseMemory (void)
|
||||
/* Parse a MEMORY section */
|
||||
{
|
||||
static const IdentTok Attributes [] = {
|
||||
{ "START", CFGTOK_START },
|
||||
{ "SIZE", CFGTOK_SIZE },
|
||||
{ "TYPE", CFGTOK_TYPE },
|
||||
{ "FILE", CFGTOK_FILE },
|
||||
{ "BANK", CFGTOK_BANK },
|
||||
{ "DEFINE", CFGTOK_DEFINE },
|
||||
{ "FILE", CFGTOK_FILE },
|
||||
{ "FILL", CFGTOK_FILL },
|
||||
{ "FILLVAL", CFGTOK_FILLVAL },
|
||||
{ "SIZE", CFGTOK_SIZE },
|
||||
{ "START", CFGTOK_START },
|
||||
{ "TYPE", CFGTOK_TYPE },
|
||||
};
|
||||
static const IdentTok Types [] = {
|
||||
{ "RO", CFGTOK_RO },
|
||||
@@ -442,31 +444,9 @@ static void ParseMemory (void)
|
||||
/* Check which attribute was given */
|
||||
switch (AttrTok) {
|
||||
|
||||
case CFGTOK_START:
|
||||
FlagAttr (&M->Attr, MA_START, "START");
|
||||
M->StartExpr = CfgExpr ();
|
||||
break;
|
||||
|
||||
case CFGTOK_SIZE:
|
||||
FlagAttr (&M->Attr, MA_SIZE, "SIZE");
|
||||
M->SizeExpr = CfgExpr ();
|
||||
break;
|
||||
|
||||
case CFGTOK_TYPE:
|
||||
FlagAttr (&M->Attr, MA_TYPE, "TYPE");
|
||||
CfgSpecialToken (Types, ENTRY_COUNT (Types), "Type");
|
||||
if (CfgTok == CFGTOK_RO) {
|
||||
M->Flags |= MF_RO;
|
||||
}
|
||||
CfgNextTok ();
|
||||
break;
|
||||
|
||||
case CFGTOK_FILE:
|
||||
FlagAttr (&M->Attr, MA_FILE, "FILE");
|
||||
CfgAssureStr ();
|
||||
/* Get the file entry and insert the memory area */
|
||||
FileInsert (GetFile (GetStrBufId (&CfgSVal)), M);
|
||||
CfgNextTok ();
|
||||
case CFGTOK_BANK:
|
||||
FlagAttr (&M->Attr, MA_BANK, "BANK");
|
||||
M->BankExpr = CfgExpr ();
|
||||
break;
|
||||
|
||||
case CFGTOK_DEFINE:
|
||||
@@ -479,6 +459,14 @@ static void ParseMemory (void)
|
||||
CfgNextTok ();
|
||||
break;
|
||||
|
||||
case CFGTOK_FILE:
|
||||
FlagAttr (&M->Attr, MA_FILE, "FILE");
|
||||
CfgAssureStr ();
|
||||
/* Get the file entry and insert the memory area */
|
||||
FileInsert (GetFile (GetStrBufId (&CfgSVal)), M);
|
||||
CfgNextTok ();
|
||||
break;
|
||||
|
||||
case CFGTOK_FILL:
|
||||
FlagAttr (&M->Attr, MA_FILL, "FILL");
|
||||
/* Map the token to a boolean */
|
||||
@@ -494,6 +482,25 @@ static void ParseMemory (void)
|
||||
M->FillVal = (unsigned char) CfgCheckedConstExpr (0, 0xFF);
|
||||
break;
|
||||
|
||||
case CFGTOK_SIZE:
|
||||
FlagAttr (&M->Attr, MA_SIZE, "SIZE");
|
||||
M->SizeExpr = CfgExpr ();
|
||||
break;
|
||||
|
||||
case CFGTOK_START:
|
||||
FlagAttr (&M->Attr, MA_START, "START");
|
||||
M->StartExpr = CfgExpr ();
|
||||
break;
|
||||
|
||||
case CFGTOK_TYPE:
|
||||
FlagAttr (&M->Attr, MA_TYPE, "TYPE");
|
||||
CfgSpecialToken (Types, ENTRY_COUNT (Types), "TYPE");
|
||||
if (CfgTok == CFGTOK_RO) {
|
||||
M->Flags |= MF_RO;
|
||||
}
|
||||
CfgNextTok ();
|
||||
break;
|
||||
|
||||
default:
|
||||
FAIL ("Unexpected attribute token");
|
||||
|
||||
@@ -1859,16 +1866,30 @@ unsigned CfgProcess (void)
|
||||
Addr = NewAddr;
|
||||
}
|
||||
|
||||
/* If the segment has .BANK expressions referring to it, it
|
||||
* must be placed into a memory area that has the bank
|
||||
* attribute.
|
||||
*/
|
||||
if (S->Seg->BankRef && M->BankExpr == 0) {
|
||||
CfgError (GetSourcePos (S->LI),
|
||||
"Segment `%s' is refered to by .BANK, but the "
|
||||
"memory area `%s' it is placed into has no BANK "
|
||||
"attribute",
|
||||
GetString (S->Name),
|
||||
GetString (M->Name));
|
||||
}
|
||||
|
||||
/* Set the start address of this segment, set the readonly flag
|
||||
* in the segment and and remember if the segment is in a
|
||||
* relocatable file or not.
|
||||
*/
|
||||
S->Seg->PC = Addr;
|
||||
S->Seg->ReadOnly = (S->Flags & SF_RO) != 0;
|
||||
S->Seg->Relocatable = M->Relocatable;
|
||||
|
||||
/* Remember that this segment is placed */
|
||||
S->Seg->Placed = 1;
|
||||
/* Remember the run memory for this segment, which is also a
|
||||
* flag that the segment has been placed.
|
||||
*/
|
||||
S->Seg->MemArea = M;
|
||||
|
||||
} else if (S->Load == M) {
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* (C) 1998-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -72,7 +72,7 @@ ExprNode* NewExprNode (ObjData* O, unsigned char Op)
|
||||
|
||||
static void FreeExprNode (ExprNode* E)
|
||||
/* Free a node */
|
||||
{
|
||||
{
|
||||
/* Free the memory */
|
||||
xfree (E);
|
||||
}
|
||||
@@ -99,6 +99,7 @@ int IsConstExpr (ExprNode* Root)
|
||||
int Const;
|
||||
Export* E;
|
||||
Section* S;
|
||||
MemoryArea* M;
|
||||
|
||||
if (EXPR_IS_LEAF (Root->Op)) {
|
||||
switch (Root->Op) {
|
||||
@@ -111,7 +112,7 @@ int IsConstExpr (ExprNode* Root)
|
||||
E = GetExprExport (Root);
|
||||
/* If this export has a mark set, we've already encountered it.
|
||||
* This means that the export is used to define it's own value,
|
||||
* which in turn means, that we have a circular reference.
|
||||
* which in turn means, that we have a circular reference.
|
||||
*/
|
||||
if (ExportHasMark (E)) {
|
||||
CircularRefError (E);
|
||||
@@ -119,8 +120,8 @@ int IsConstExpr (ExprNode* Root)
|
||||
} else {
|
||||
MarkExport (E);
|
||||
Const = IsConstExport (E);
|
||||
UnmarkExport (E);
|
||||
}
|
||||
UnmarkExport (E);
|
||||
}
|
||||
return Const;
|
||||
|
||||
case EXPR_SECTION:
|
||||
@@ -128,22 +129,35 @@ int IsConstExpr (ExprNode* Root)
|
||||
* not relocatable and already placed.
|
||||
*/
|
||||
S = GetExprSection (Root);
|
||||
return !S->Seg->Relocatable && S->Seg->Placed;
|
||||
M = S->Seg->MemArea;
|
||||
return M != 0 && (M->Flags & MF_PLACED) != 0 && !M->Relocatable;
|
||||
|
||||
case EXPR_SEGMENT:
|
||||
/* A segment is const if it is not relocatable and placed */
|
||||
return !Root->V.Seg->Relocatable && Root->V.Seg->Placed;
|
||||
M = Root->V.Seg->MemArea;
|
||||
return M != 0 && (M->Flags & MF_PLACED) != 0 && !M->Relocatable;
|
||||
|
||||
case EXPR_MEMAREA:
|
||||
/* A memory area is const if it is not relocatable and placed */
|
||||
return !Root->V.Mem->Relocatable &&
|
||||
(Root->V.Mem->Flags & MF_PLACED);
|
||||
|
||||
case EXPR_BANK:
|
||||
/* A bank expression is const if the section, the segment is
|
||||
* part of, is already placed, and the memory area has a
|
||||
* constant bank expression.
|
||||
*/
|
||||
S = GetExprSection (Root);
|
||||
M = S->Seg->MemArea;
|
||||
return M != 0 && (M->Flags & MF_PLACED) != 0 &&
|
||||
M->BankExpr != 0 && IsConstExpr (M->BankExpr);
|
||||
|
||||
default:
|
||||
/* Anything else is not const */
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
} else if (EXPR_IS_UNARY (Root->Op)) {
|
||||
|
||||
return IsConstExpr (Root->Left);
|
||||
@@ -201,7 +215,7 @@ Import* GetExprImport (ExprNode* Expr)
|
||||
* import pointer.
|
||||
*/
|
||||
if (Expr->Obj) {
|
||||
/* Return the Import */
|
||||
/* Return the Import */
|
||||
return GetObjImport (Expr->Obj, Expr->V.ImpNum);
|
||||
} else {
|
||||
return Expr->V.Imp;
|
||||
@@ -226,7 +240,7 @@ Section* GetExprSection (ExprNode* Expr)
|
||||
/* Get the segment for a section expression node */
|
||||
{
|
||||
/* Check that this is really a section node */
|
||||
PRECONDITION (Expr->Op == EXPR_SECTION);
|
||||
PRECONDITION (Expr->Op == EXPR_SECTION || Expr->Op == EXPR_BANK);
|
||||
|
||||
/* If we have an object file, get the section from it, otherwise
|
||||
* (internally generated expressions), get the section from the
|
||||
@@ -245,9 +259,11 @@ Section* GetExprSection (ExprNode* Expr)
|
||||
long GetExprVal (ExprNode* Expr)
|
||||
/* Get the value of a constant expression */
|
||||
{
|
||||
long Right, Left, Val;
|
||||
Section* S;
|
||||
Export* E;
|
||||
long Right;
|
||||
long Left;
|
||||
long Val;
|
||||
Section* S;
|
||||
Export* E;
|
||||
|
||||
switch (Expr->Op) {
|
||||
|
||||
@@ -281,6 +297,10 @@ long GetExprVal (ExprNode* Expr)
|
||||
case EXPR_MEMAREA:
|
||||
return Expr->V.Mem->Start;
|
||||
|
||||
case EXPR_BANK:
|
||||
S = GetExprSection (Expr);
|
||||
return GetExprVal (S->Seg->MemArea->BankExpr);
|
||||
|
||||
case EXPR_PLUS:
|
||||
return GetExprVal (Expr->Left) + GetExprVal (Expr->Right);
|
||||
|
||||
@@ -345,8 +365,8 @@ long GetExprVal (ExprNode* Expr)
|
||||
case EXPR_BOOLOR:
|
||||
return GetExprVal (Expr->Left) || GetExprVal (Expr->Right);
|
||||
|
||||
case EXPR_BOOLXOR:
|
||||
return (GetExprVal (Expr->Left) != 0) ^ (GetExprVal (Expr->Right) != 0);
|
||||
case EXPR_BOOLXOR:
|
||||
return (GetExprVal (Expr->Left) != 0) ^ (GetExprVal (Expr->Right) != 0);
|
||||
|
||||
case EXPR_MAX:
|
||||
Left = GetExprVal (Expr->Left);
|
||||
@@ -359,16 +379,16 @@ long GetExprVal (ExprNode* Expr)
|
||||
return (Left < Right)? Left : Right;
|
||||
|
||||
case EXPR_UNARY_MINUS:
|
||||
return -GetExprVal (Expr->Left);
|
||||
return -GetExprVal (Expr->Left);
|
||||
|
||||
case EXPR_NOT:
|
||||
return ~GetExprVal (Expr->Left);
|
||||
return ~GetExprVal (Expr->Left);
|
||||
|
||||
case EXPR_SWAP:
|
||||
Left = GetExprVal (Expr->Left);
|
||||
return ((Left >> 8) & 0x00FF) | ((Left << 8) & 0xFF00);
|
||||
Left = GetExprVal (Expr->Left);
|
||||
return ((Left >> 8) & 0x00FF) | ((Left << 8) & 0xFF00);
|
||||
|
||||
case EXPR_BOOLNOT:
|
||||
case EXPR_BOOLNOT:
|
||||
return !GetExprVal (Expr->Left);
|
||||
|
||||
case EXPR_BYTE0:
|
||||
@@ -569,11 +589,12 @@ ExprNode* ReadExpr (FILE* F, ObjData* O)
|
||||
/* Read an expression from the given file */
|
||||
{
|
||||
ExprNode* Expr;
|
||||
Section* S;
|
||||
|
||||
/* Read the node tag and handle NULL nodes */
|
||||
unsigned char Op = Read8 (F);
|
||||
if (Op == EXPR_NULL) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* Create a new node */
|
||||
@@ -581,20 +602,30 @@ ExprNode* ReadExpr (FILE* F, ObjData* O)
|
||||
|
||||
/* Check the tag and handle the different expression types */
|
||||
if (EXPR_IS_LEAF (Op)) {
|
||||
switch (Op) {
|
||||
switch (Op) {
|
||||
|
||||
case EXPR_LITERAL:
|
||||
Expr->V.IVal = Read32Signed (F);
|
||||
break;
|
||||
case EXPR_LITERAL:
|
||||
Expr->V.IVal = Read32Signed (F);
|
||||
break;
|
||||
|
||||
case EXPR_SYMBOL:
|
||||
/* Read the import number */
|
||||
case EXPR_SYMBOL:
|
||||
/* Read the import number */
|
||||
Expr->V.ImpNum = ReadVar (F);
|
||||
break;
|
||||
|
||||
case EXPR_SECTION:
|
||||
/* Read the segment number */
|
||||
Expr->V.SecNum = Read8 (F);
|
||||
/* Read the section number */
|
||||
Expr->V.SecNum = ReadVar (F);
|
||||
break;
|
||||
|
||||
case EXPR_BANK:
|
||||
/* Read the section number */
|
||||
Expr->V.SecNum = ReadVar (F);
|
||||
/* Mark the section so we know it must be placed into a memory
|
||||
* area with the "bank" attribute.
|
||||
*/
|
||||
S = GetExprSection (Expr);
|
||||
S->Seg->BankRef = 1;
|
||||
break;
|
||||
|
||||
default:
|
||||
@@ -624,12 +655,12 @@ int EqualExpr (ExprNode* E1, ExprNode* E2)
|
||||
return 0;
|
||||
}
|
||||
if (E1 == 0) {
|
||||
return 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
/* Both pointers not NULL, check OP */
|
||||
if (E1->Op != E2->Op) {
|
||||
return 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
/* OPs are identical, check data for leafs, or subtrees */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2010-2011, Ullrich von Bassewitz */
|
||||
/* (C) 2010-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -63,6 +63,7 @@ MemoryArea* NewMemoryArea (const FilePos* Pos, unsigned Name)
|
||||
M->Start = 0;
|
||||
M->SizeExpr = 0;
|
||||
M->Size = 0;
|
||||
M->BankExpr = 0;
|
||||
M->FillLevel = 0;
|
||||
M->FillVal = 0;
|
||||
M->Relocatable = 0;
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 2010-2011, Ullrich von Bassewitz */
|
||||
/* (C) 2010-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -68,6 +68,7 @@ struct MemoryArea {
|
||||
unsigned long Start; /* Start address */
|
||||
struct ExprNode* SizeExpr; /* Expression for size */
|
||||
unsigned long Size; /* Length of memory section */
|
||||
struct ExprNode* BankExpr; /* Expression for bank */
|
||||
unsigned long FillLevel; /* Actual fill level of segment */
|
||||
unsigned char FillVal; /* Value used to fill rest of seg */
|
||||
unsigned char Relocatable; /* Memory area is relocatable */
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2010, Ullrich von Bassewitz */
|
||||
/* (C) 1998-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -84,6 +84,7 @@ typedef enum {
|
||||
CFGTOK_TYPE,
|
||||
CFGTOK_FILE,
|
||||
CFGTOK_DEFINE,
|
||||
CFGTOK_BANK,
|
||||
CFGTOK_FILL,
|
||||
CFGTOK_FILLVAL,
|
||||
CFGTOK_EXPORT,
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* (C) 1998-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -94,6 +94,7 @@ static Segment* NewSegment (unsigned Name, unsigned char AddrSize)
|
||||
S->Name = Name;
|
||||
S->Next = 0;
|
||||
S->Sections = EmptyCollection;
|
||||
S->MemArea = 0;
|
||||
S->PC = 0;
|
||||
S->Size = 0;
|
||||
S->OutputName = 0;
|
||||
@@ -102,10 +103,9 @@ static Segment* NewSegment (unsigned Name, unsigned char AddrSize)
|
||||
S->FillVal = 0;
|
||||
S->AddrSize = AddrSize;
|
||||
S->ReadOnly = 0;
|
||||
S->Relocatable = 0;
|
||||
S->Placed = 0;
|
||||
S->Dumped = 0;
|
||||
|
||||
S->BankRef = 0;
|
||||
|
||||
/* Insert the segment into the segment list and assign the segment id */
|
||||
S->Id = CollCount (&SegmentList);
|
||||
CollAppend (&SegmentList, S);
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
/* (C) 1998-2011, Ullrich von Bassewitz */
|
||||
/* (C) 1998-2012, Ullrich von Bassewitz */
|
||||
/* Roemerstrasse 52 */
|
||||
/* D-70794 Filderstadt */
|
||||
/* EMail: uz@cc65.org */
|
||||
@@ -52,6 +52,9 @@
|
||||
|
||||
|
||||
|
||||
/* Forwards */
|
||||
struct MemoryArea;
|
||||
|
||||
/* Segment structure */
|
||||
typedef struct Segment Segment;
|
||||
struct Segment {
|
||||
@@ -59,6 +62,7 @@ struct Segment {
|
||||
unsigned Id; /* Segment id for debug info */
|
||||
Segment* Next; /* Hash list */
|
||||
Collection Sections; /* Sections in this segment */
|
||||
struct MemoryArea* MemArea; /* Run memory area once placed */
|
||||
unsigned long PC; /* PC were this segment is located */
|
||||
unsigned long Size; /* Size of data so far */
|
||||
const char* OutputName; /* Name of output file or NULL */
|
||||
@@ -67,9 +71,8 @@ struct Segment {
|
||||
unsigned char FillVal; /* Value to use for fill bytes */
|
||||
unsigned char AddrSize; /* Address size of segment */
|
||||
unsigned char ReadOnly; /* True for readonly segments (config) */
|
||||
unsigned char Relocatable; /* True if the segment is relocatable */
|
||||
unsigned char Placed; /* Did we place this segment already? */
|
||||
unsigned char Dumped; /* Did we dump this segment? */
|
||||
unsigned char BankRef; /* We need the bank of this segment */
|
||||
};
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user