]> git.sur5r.net Git - cc65/blobdiff - src/ld65/segments.h
Finish support for .BANK.
[cc65] / src / ld65 / segments.h
index f69e9c2db6170a584712e7f4bdf1ab37ac670657..9810c0f574174a9166b37bffd6265cd22038cfcb 100644 (file)
@@ -6,10 +6,10 @@
 /*                                                                           */
 /*                                                                           */
 /*                                                                           */
-/* (C) 1998-2000 Ullrich von Bassewitz                                       */
-/*               Wacholderweg 14                                             */
-/*               D-70597 Stuttgart                                           */
-/* EMail:        uz@musoftware.de                                            */
+/* (C) 1998-2012, Ullrich von Bassewitz                                      */
+/*                Roemerstrasse 52                                           */
+/*                D-70794 Filderstadt                                        */
+/* EMail:         uz@cc65.org                                                */
 /*                                                                           */
 /*                                                                           */
 /* This software is provided 'as-is', without any expressed or implied       */
@@ -40,9 +40,9 @@
 
 #include <stdio.h>
 
-#include "../common/exprdefs.h"
-
-#include "objdata.h"
+/* common */
+#include "coll.h"
+#include "exprdefs.h"
 
 
 
 
 
 
-/* Forward for the section structure (a section is a part of a segment) */
-typedef struct Section_ Section;
+/* Forwards */
+struct MemoryArea;
 
 /* Segment structure */
-typedef struct Segment_ Segment;
-struct Segment_ {
-    Segment*           Next;           /* Hash list */
-    Segment*           List;           /* List of all segments */
-    Section*           SecRoot;        /* Section list */
-    Section*           SecLast;        /* Pointer to last section */
-    unsigned long      PC;             /* PC were this segment is located */
-    unsigned long      Size;           /* Size of data so far */
-    ObjData*           AlignObj;       /* Module that requested the alignment */
-    unsigned char      Align;          /* Alignment needed */
-    unsigned char      FillVal;        /* Value to use for fill bytes */
-    unsigned char      Type;           /* Type of segment */
-    char               Dumped;         /* Did we dump this segment? */
-    char                       Name [1];       /* Name, dynamically allocated */
+typedef struct Segment Segment;
+struct Segment {
+    unsigned            Name;           /* Name index of the segment */
+    unsigned            Id;             /* Segment id for debug info */
+    Segment*           Next;           /* Hash list */
+    unsigned            Flags;          /* Segment flags */
+    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 */
+    unsigned long       OutputOffs;     /* Offset in output file */
+    unsigned long       Alignment;      /* Alignment needed */
+    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              Dumped;         /* Did we dump this segment? */
 };
 
 
 
 /* Section structure (a section is a part of a segment) */
-struct Section_ {
-    Section*           Next;           /* List of sections in a segment */
-    Segment*           Seg;            /* Segment that contains the section */
-    struct Fragment_*  FragRoot;       /* Fragment list */
-    struct Fragment_*  FragLast;       /* Pointer to last fragment */
+typedef struct Section Section;
+struct Section {
+    Section*           Next;           /* List of sections in a segment */
+    Segment*           Seg;            /* Segment that contains the section */
+    struct ObjData*     Obj;            /* Object file this section comes from */
+    struct Fragment*   FragRoot;       /* Fragment list */
+    struct Fragment*   FragLast;       /* Pointer to last fragment */
     unsigned long      Offs;           /* Offset into the segment */
     unsigned long      Size;           /* Size of the section */
-    unsigned char      Align;          /* Alignment */
-    unsigned char      Fill;           /* Fill bytes for alignment */
-    unsigned char      Type;           /* Type of segment */
+    unsigned long       Fill;           /* Fill bytes for alignment */
+    unsigned long       Alignment;      /* Alignment */
+    unsigned char      AddrSize;       /* Address size of segment */
 };
 
 
@@ -92,15 +97,16 @@ struct Section_ {
 /* Prototype for a function that is used to write expressions to the target
  * file (used in SegWrite). It returns one of the following values:
  */
-#define SEG_EXPR_OK            0       /* Ok */
-#define SEG_EXPR_RANGE_ERROR   1       /* Range error */
-#define SEG_EXPR_TOO_COMPLEX   2       /* Expression too complex */
+#define SEG_EXPR_OK            0U      /* Ok */
+#define SEG_EXPR_RANGE_ERROR   1U      /* Range error */
+#define SEG_EXPR_TOO_COMPLEX   2U      /* Expression too complex */
+#define SEG_EXPR_INVALID        3U      /* Expression is invalid (e.g. unmapped segment) */
 
 typedef unsigned (*SegWriteFunc) (ExprNode* E,               /* The expression to write */
-                                 int Signed,         /* Signed expression? */
-                                 unsigned Size,      /* Size (=range) */
-                                 unsigned long Offs, /* File offset */
-                                 void* Data);        /* Callers data */
+                                 int Signed,         /* Signed expression? */
+                                 unsigned Size,      /* Size (=range) */
+                                 unsigned long Offs, /* File offset */
+                                 void* Data);        /* Callers data */
 
 
 
@@ -110,10 +116,19 @@ typedef unsigned (*SegWriteFunc) (ExprNode* E,          /* The expression to write
 
 
 
-Section* ReadSection (FILE* F, ObjData* O);
+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.
+ */
+
+Section* NewSection (Segment* Seg, unsigned long Alignment, unsigned char AddrSize);
+/* Create a new section for the given segment */
+
+Section* ReadSection (FILE* F, struct ObjData* O);
 /* Read a section from a file */
 
-Segment* SegFind (const char* Name);
+Segment* SegFind (unsigned Name);
 /* Return the given segment or NULL if not found. */
 
 int IsBSSType (Segment* S);
@@ -129,14 +144,20 @@ unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size);
  * check and return one of the SEG_EXPR_xxx codes.
  */
 
-void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data);
+void SegWrite (const char* TgtName, FILE* Tgt, Segment* S, SegWriteFunc F, void* Data);
 /* Write the data from the given segment to a file. For expressions, F is
  * called (see description of SegWriteFunc above).
  */
 
+unsigned SegmentCount (void);
+/* Return the total number of segments */
+
 void PrintSegmentMap (FILE* F);
 /* Print a segment map to the given file */
 
+void PrintDbgSegments (FILE* F);
+/* Output the segments to the debug file */
+
 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.
@@ -150,3 +171,4 @@ void CheckSegments (void);
 
 
 
+