From a4b43370e7600b627f0189ccb12315151f85a6b5 Mon Sep 17 00:00:00 2001 From: cuz Date: Sun, 2 Sep 2007 19:49:12 +0000 Subject: [PATCH] More segment support stuff. git-svn-id: svn://svn.cc65.org/cc65/trunk@3806 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- src/da65/attrtab.c | 26 +++++++++++++++++++++++++- src/da65/attrtab.h | 7 +++++++ src/da65/data.c | 20 ++++++++++++++------ src/da65/labels.c | 6 +++--- src/da65/main.c | 6 +++--- src/da65/output.c | 24 +++++++++++++++++++++--- src/da65/output.h | 14 ++++++++++---- src/da65/segment.c | 15 +++++++++------ 8 files changed, 92 insertions(+), 26 deletions(-) diff --git a/src/da65/attrtab.c b/src/da65/attrtab.c index 277ee8b0e..61ed6b440 100644 --- a/src/da65/attrtab.c +++ b/src/da65/attrtab.c @@ -75,7 +75,19 @@ int SegmentDefined (unsigned Start, unsigned End) } } return 0; -} +} + + + +int HaveSegmentChange (unsigned Addr) +/* Return true if the segment change attribute is set for the given address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Return the attribute */ + return (AttrTab[Addr] & atSegmentChange) != 0; +} @@ -133,6 +145,18 @@ void MarkAddr (unsigned Addr, attr_t Attr) +attr_t GetAttr (unsigned Addr) +/* Return the attribute for the given address */ +{ + /* Check the given address */ + AddrCheck (Addr); + + /* Return the attribute */ + return AttrTab[Addr]; +} + + + attr_t GetStyleAttr (unsigned Addr) /* Return the style attribute for the given address */ { diff --git a/src/da65/attrtab.h b/src/da65/attrtab.h index 23413abed..40a414c2e 100644 --- a/src/da65/attrtab.h +++ b/src/da65/attrtab.h @@ -73,6 +73,7 @@ typedef enum attr_t { /* Segment */ atSegment = 0x0100, /* Code is in a segment */ + atSegmentChange = 0x0200, /* Either segment start or segment end */ } attr_t; @@ -89,6 +90,9 @@ void AddrCheck (unsigned Addr); int SegmentDefined (unsigned Start, unsigned End); /* Return true if the atSegment bit is set somewhere in the given range */ +int HaveSegmentChange (unsigned Addr); +/* Return true if the segment change attribute is set for the given address */ + unsigned GetGranularity (attr_t Style); /* Get the granularity for the given style */ @@ -98,6 +102,9 @@ void MarkRange (unsigned Start, unsigned End, attr_t Attr); void MarkAddr (unsigned Addr, attr_t Attr); /* Mark an address with an attribute */ +attr_t GetAttr (unsigned Addr); +/* Return the attribute for the given address */ + attr_t GetStyleAttr (unsigned Addr); /* Return the style attribute for the given address */ diff --git a/src/da65/data.c b/src/da65/data.c index 1569f7aee..bafd14e23 100644 --- a/src/da65/data.c +++ b/src/da65/data.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 2000-2004 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 2000-2007 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -57,14 +57,22 @@ static unsigned GetSpan (attr_t Style) unsigned RemainingBytes = GetRemainingBytes (); /* Count how many bytes are available. This number is limited by the - * number of remaining bytes, a label, or the end of the given Style - * attribute. + * number of remaining bytes, a label, a segment change, or the end of + * the given Style attribute. */ unsigned Count = 1; while (Count < RemainingBytes) { - if (MustDefLabel(PC+Count) || GetStyleAttr (PC+Count) != Style) { + attr_t Attr; + if (MustDefLabel(PC+Count)) { break; - } + } + Attr = GetAttr (PC+Count); + if ((Attr & atStyleMask) != Style) { + break; + } + if ((Attr & atSegmentChange)) { + break; + } ++Count; } diff --git a/src/da65/labels.c b/src/da65/labels.c index 20f93a98d..59c571b49 100644 --- a/src/da65/labels.c +++ b/src/da65/labels.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 2006-2007 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -378,7 +378,7 @@ static void DefOutOfRangeLabel (unsigned long Addr) case atIntLabel: case atExtLabel: - DefineConst (SymTab[Addr], GetComment (Addr), Addr); + DefConst (SymTab[Addr], GetComment (Addr), Addr); break; case atUnnamedLabel: diff --git a/src/da65/main.c b/src/da65/main.c index a43c564d3..83b1784e8 100644 --- a/src/da65/main.c +++ b/src/da65/main.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 1998-2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 1998-2007 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -385,7 +385,7 @@ static void OneOpcode (unsigned RemainingBytes) } else { unsigned I; for (I = 1; I < D->Size; ++I) { - if (HaveLabel (PC+I)) { + if (HaveLabel (PC+I) || HaveSegmentChange (PC+I)) { Style = atIllegal; MarkAddr (PC, Style); break; diff --git a/src/da65/output.c b/src/da65/output.c index 5b68eae88..3b4ffe47f 100644 --- a/src/da65/output.c +++ b/src/da65/output.c @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 2000-2006 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 2000-2007 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -40,6 +40,7 @@ #include /* common */ +#include "addrsize.h" #include "cpu.h" #include "version.h" @@ -199,7 +200,7 @@ void DefForward (const char* Name, const char* Comment, unsigned Offs) -void DefineConst (const char* Name, const char* Comment, unsigned Addr) +void DefConst (const char* Name, const char* Comment, unsigned Addr) /* Define an address constant */ { if (Pass == PassCount) { @@ -216,6 +217,23 @@ void DefineConst (const char* Name, const char* Comment, unsigned Addr) +void StartSegment (const char* Name, unsigned AddrSize) +/* Start a segment */ +{ + if (Pass == PassCount) { + Output (".segment"); + Indent (ACol); + if (AddrSize == ADDR_SIZE_DEFAULT) { + Output ("\"%s\"", Name); + } else { + Output ("\"%s\": %s", Name, AddrSizeToStr (AddrSize)); + } + LineFeed (); + } +} + + + void DataByteLine (unsigned ByteCount) /* Output a line with bytes */ { diff --git a/src/da65/output.h b/src/da65/output.h index 8aba0ff87..37c0915c8 100644 --- a/src/da65/output.h +++ b/src/da65/output.h @@ -6,8 +6,8 @@ /* */ /* */ /* */ -/* (C) 2000-2003 Ullrich von Bassewitz */ -/* Römerstrasse 52 */ +/* (C) 2000-2007 Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ /* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ @@ -67,13 +67,19 @@ void LineFeed (void); void DefLabel (const char* Name); /* Define a label with the given name */ -void DefForward (const char* Name, const char* Comment, unsigned Offs); +void DefForward (const char* Name, const char* Comment, unsigned Offs); /* Define a label as "* + x", where x is the offset relative to the * current PC. */ -void DefineConst (const char* Name, const char* Comment, unsigned Addr); +void DefConst (const char* Name, const char* Comment, unsigned Addr); /* Define an address constant */ + +void StartSegment (const char* Name, unsigned AddrSize); +/* Start a segment */ + +void EndSegment (void); +/* End a segment */ void OneDataByte (void); /* Output a .byte line with the current code byte */ diff --git a/src/da65/segment.c b/src/da65/segment.c index e648a3618..1098efdc4 100644 --- a/src/da65/segment.c +++ b/src/da65/segment.c @@ -52,8 +52,7 @@ /* Hash definitions */ -#define HASH_SIZE 64 /* Must be power of two */ -#define HASH_MASK (HASH_SIZE-1) +#define HASH_SIZE 53 /* Segment definition */ typedef struct Segment Segment; @@ -96,10 +95,14 @@ void AddAbsSegment (unsigned Start, unsigned End, const char* Name) memcpy (S->Name, Name, Len + 1); /* Insert the segment into the hash tables */ - S->NextStart = StartTab[Start & HASH_MASK]; - StartTab[Start & HASH_MASK] = S; - S->NextEnd = EndTab[End & HASH_MASK]; - EndTab[End & HASH_MASK] = S; + S->NextStart = StartTab[Start % HASH_SIZE]; + StartTab[Start % HASH_SIZE] = S; + S->NextEnd = EndTab[End % HASH_SIZE]; + EndTab[End % HASH_SIZE] = S; + + /* Mark start and end of the segment */ + MarkAddr (Start, atSegmentChange); + MarkAddr (End, atSegmentChange); /* Mark the addresses within the segment */ MarkRange (Start, End, atSegment);