]> git.sur5r.net Git - cc65/blobdiff - src/ld65/segments.c
New module strstack
[cc65] / src / ld65 / segments.c
index c685ac48eecd6b91bb7b968e7161c33faecd2ca5..1fb7fcbd792d16e58fc3e8dfcf57ff23338edb81 100644 (file)
@@ -7,7 +7,7 @@
 /*                                                                           */
 /*                                                                           */
 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
-/*               Römerstrasse 52                                             */
+/*               Römerstraße 52                                              */
 /*               D-70794 Filderstadt                                         */
 /* EMail:        uz@cc65.org                                                 */
 /*                                                                           */
@@ -70,7 +70,7 @@
 static Segment*                HashTab [HASHTAB_SIZE];
 
 static unsigned                SegCount = 0;   /* Segment count */
-static Segment*                SegRoot = 0;    /* List of all segments */
+static Segment*                SegRoot = 0;    /* List of all segments */
 
 
 
@@ -80,7 +80,7 @@ static Segment*               SegRoot = 0;    /* List of all segments */
 
 
 
-static Segment* NewSegment (unsigned Name, unsigned char Type)
+static Segment* NewSegment (unsigned Name, unsigned char AddrSize)
 /* Create a new segment and initialize it */
 {
     unsigned Hash;
@@ -89,17 +89,19 @@ static Segment* NewSegment (unsigned Name, unsigned char Type)
     Segment* S = xmalloc (sizeof (Segment));
 
     /* Initialize the fields */
-    S->Name     = Name;
-    S->Next    = 0;
-    S->SecRoot = 0;
-    S->SecLast = 0;
-    S->PC      = 0;
-    S->Size            = 0;
-    S->AlignObj        = 0;
-    S->Align    = 0;
-    S->FillVal = 0;
-    S->Type     = Type;
-    S->Dumped   = 0;
+    S->Name        = Name;
+    S->Next       = 0;
+    S->SecRoot    = 0;
+    S->SecLast    = 0;
+    S->PC         = 0;
+    S->Size               = 0;
+    S->AlignObj           = 0;
+    S->Align       = 0;
+    S->FillVal    = 0;
+    S->AddrSize    = AddrSize;
+    S->ReadOnly    = 0;
+    S->Relocatable = 0;
+    S->Dumped      = 0;
 
     /* Insert the segment into the segment list */
     S->List = SegRoot;
@@ -117,7 +119,7 @@ static Segment* NewSegment (unsigned Name, unsigned char Type)
 
 
 
-Segment* GetSegment (unsigned Name, unsigned char Type, const char* ObjName)
+Segment* GetSegment (unsigned Name, unsigned char AddrSize, const char* ObjName)
 /* Search for a segment and return an existing one. If the segment does not
  * exist, create a new one and return that. ObjName is only used for the error
  * message and may be NULL if the segment is linker generated.
@@ -131,10 +133,10 @@ Segment* GetSegment (unsigned Name, unsigned char Type, const char* ObjName)
      */
     if (S == 0) {
        /* Create a new segment */
-       S = NewSegment (Name, Type);
+       S = NewSegment (Name, AddrSize);
     } else {
-               /* Check if the existing segment has the requested type */
-               if (S->Type != Type) {
+               /* Check if the existing segment has the requested address size */
+               if (S->AddrSize != AddrSize) {
            /* Allow an empty object name */
            if (ObjName == 0) {
                ObjName = "[linker generated]";
@@ -150,7 +152,7 @@ Segment* GetSegment (unsigned Name, unsigned char Type, const char* ObjName)
 
 
 
-Section* NewSection (Segment* Seg, unsigned char Align, unsigned char Type)
+Section* NewSection (Segment* Seg, unsigned char Align, unsigned char AddrSize)
 /* Create a new section for the given segment */
 {
     unsigned long V;
@@ -166,7 +168,7 @@ Section* NewSection (Segment* Seg, unsigned char Align, unsigned char Type)
     S->FragLast = 0;
     S->Size    = 0;
     S->Align    = Align;
-    S->Type     = Type;
+    S->AddrSize = AddrSize;
 
     /* Calculate the alignment bytes needed for the section */
     V = (0x01UL << S->Align) - 1;
@@ -330,7 +332,7 @@ int IsBSSType (Segment* S)
                unsigned long Count = F->Size;
                while (Count--) {
                    if (*Data++ != 0) {
-                       return 0;
+                       return 0;
                    }
                }
            } else if (F->Type == FRAG_EXPR || F->Type == FRAG_SEXPR) {
@@ -383,13 +385,13 @@ void SegDump (void)
                    case FRAG_EXPR:
                        printf ("    Expression (%u bytes):\n", F->Size);
                        printf ("    ");
-                       DumpExpr (F->Expr);
+                       DumpExpr (F->Expr, 0);
                        break;
 
                    case FRAG_SEXPR:
                        printf ("    Signed expression (%u bytes):\n", F->Size);
                        printf ("      ");
-                       DumpExpr (F->Expr);
+                       DumpExpr (F->Expr, 0);
                        break;
 
                    case FRAG_FILL:
@@ -491,18 +493,18 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data)
                    /* Call the users function and evaluate the result */
                    switch (F (Frag->Expr, Sign, Frag->Size, Offs, Data)) {
 
-                       case SEG_EXPR_OK:
-                           break;
+                       case SEG_EXPR_OK:
+                           break;
 
-                       case SEG_EXPR_RANGE_ERROR:
-                           Error ("Range error in module `%s', line %lu",
-                                  GetSourceFileName (Frag->Obj, Frag->Pos.Name),
-                                  Frag->Pos.Line);
-                           break;
+                       case SEG_EXPR_RANGE_ERROR:
+                           Error ("Range error in module `%s', line %lu",
+                                  GetSourceFileName (Frag->Obj, Frag->Pos.Name),
+                                  Frag->Pos.Line);
+                           break;
 
-                       case SEG_EXPR_TOO_COMPLEX:
-                           Error ("Expression too complex in module `%s', line %lu",
-                                  GetSourceFileName (Frag->Obj, Frag->Pos.Name),
+                       case SEG_EXPR_TOO_COMPLEX:
+                           Error ("Expression too complex in module `%s', line %lu",
+                                  GetSourceFileName (Frag->Obj, Frag->Pos.Name),
                                   Frag->Pos.Line);
                            break;
 
@@ -601,15 +603,15 @@ void PrintSegmentMap (FILE* F)
        /* Get a pointer to the segment */
        S = SegPool [I];
 
-       /* Print empty segments only if explicitly requested */
-       if (VerboseMap || S->Size > 0) {
-           /* Print the segment data */
-           long End = S->PC + S->Size;
-           if (S->Size > 0) {
-               /* Point to last element addressed */
-               --End;
-           }
-           fprintf (F, "%-20s  %06lX  %06lX  %06lX\n",
+       /* Print empty segments only if explicitly requested */
+       if (VerboseMap || S->Size > 0) {
+           /* Print the segment data */
+           long End = S->PC + S->Size;
+           if (S->Size > 0) {
+               /* Point to last element addressed */
+               --End;
+           }
+           fprintf (F, "%-20s  %06lX  %06lX  %06lX\n",
                             GetString (S->Name), S->PC, End, S->Size);
        }
     }
@@ -620,6 +622,32 @@ void PrintSegmentMap (FILE* F)
 
 
 
+void PrintDbgSegments (FILE* F)
+/* Output the segments to the debug file */
+{
+    Segment* S;
+
+    /* Walk over all segments */
+    S = SegRoot;
+    while (S) {
+
+       /* Ignore empty segments */
+        if (S->Size > 0) {
+
+           /* Print the segment data */
+                   fprintf (F, "segment\t\"%s\",start=0x%06lX,size=0x%04lX,addrsize=%s,type=%s\n",
+                            GetString (S->Name), S->PC, S->Size,
+                     AddrSizeToStr (S->AddrSize),
+                     S->ReadOnly? "ro" : "rw");
+       }
+
+       /* Follow the linked list */
+       S = S->List;
+    }
+}
+
+
+
 void CheckSegments (void)
 /* Walk through the segment list and check if there are segments that were
  * not written to the output file. Output an error if this is the case.
@@ -627,7 +655,7 @@ void CheckSegments (void)
 {
     Segment* S = SegRoot;
     while (S) {
-       if (S->Size > 0 && S->Dumped == 0) {
+       if (S->Size > 0 && S->Dumped == 0) {
                    Error ("Missing memory area assignment for segment `%s'",
                    GetString (S->Name));
        }