1 /*****************************************************************************/
5 /* Segment handling for the ld65 linker */
9 /* (C) 1998-2001 Ullrich von Bassewitz */
11 /* D-70597 Stuttgart */
12 /* EMail: uz@cc65.org */
15 /* This software is provided 'as-is', without any expressed or implied */
16 /* warranty. In no event will the authors be held liable for any damages */
17 /* arising from the use of this software. */
19 /* Permission is granted to anyone to use this software for any purpose, */
20 /* including commercial applications, and to alter it and redistribute it */
21 /* freely, subject to the following restrictions: */
23 /* 1. The origin of this software must not be misrepresented; you must not */
24 /* claim that you wrote the original software. If you use this software */
25 /* in a product, an acknowledgment in the product documentation would be */
26 /* appreciated but is not required. */
27 /* 2. Altered source versions must be plainly marked as such, and must not */
28 /* be misrepresented as being the original software. */
29 /* 3. This notice may not be removed or altered from any source */
32 /*****************************************************************************/
48 /*****************************************************************************/
50 /*****************************************************************************/
54 /* Segment structure */
55 typedef struct Segment Segment;
57 Segment* Next; /* Hash list */
58 Segment* List; /* List of all segments */
59 struct Section* SecRoot; /* Section list */
60 struct Section* SecLast; /* Pointer to last section */
61 unsigned long PC; /* PC were this segment is located */
62 unsigned long Size; /* Size of data so far */
63 struct ObjData* AlignObj; /* Module that requested the alignment */
64 unsigned char Align; /* Alignment needed */
65 unsigned char FillVal; /* Value to use for fill bytes */
66 unsigned char Type; /* Type of segment */
67 char Dumped; /* Did we dump this segment? */
68 char Name [1]; /* Name, dynamically allocated */
73 /* Section structure (a section is a part of a segment) */
74 typedef struct Section Section;
76 Section* Next; /* List of sections in a segment */
77 Segment* Seg; /* Segment that contains the section */
78 struct Fragment* FragRoot; /* Fragment list */
79 struct Fragment* FragLast; /* Pointer to last fragment */
80 unsigned long Offs; /* Offset into the segment */
81 unsigned long Size; /* Size of the section */
82 unsigned char Align; /* Alignment */
83 unsigned char Fill; /* Fill bytes for alignment */
84 unsigned char Type; /* Type of segment */
89 /* Prototype for a function that is used to write expressions to the target
90 * file (used in SegWrite). It returns one of the following values:
92 #define SEG_EXPR_OK 0U /* Ok */
93 #define SEG_EXPR_RANGE_ERROR 1U /* Range error */
94 #define SEG_EXPR_TOO_COMPLEX 2U /* Expression too complex */
95 #define SEG_EXPR_INVALID 3U /* Expression is invalid (e.g. unmapped segment) */
97 typedef unsigned (*SegWriteFunc) (ExprNode* E, /* The expression to write */
98 int Signed, /* Signed expression? */
99 unsigned Size, /* Size (=range) */
100 unsigned long Offs, /* File offset */
101 void* Data); /* Callers data */
105 /*****************************************************************************/
107 /*****************************************************************************/
111 Segment* GetSegment (const char* Name, unsigned char Type, const char* ObjName);
112 /* Search for a segment and return an existing one. If the segment does not
113 * exist, create a new one and return that. ObjName is only used for the error
114 * message and may be NULL if the segment is linker generated.
117 Section* NewSection (Segment* Seg, unsigned char Align, unsigned char Type);
118 /* Create a new section for the given segment */
120 Section* ReadSection (FILE* F, struct ObjData* O);
121 /* Read a section from a file */
123 Segment* SegFind (const char* Name);
124 /* Return the given segment or NULL if not found. */
126 int IsBSSType (Segment* S);
127 /* Check if the given segment is a BSS style segment, that is, it does not
128 * contain non-zero data.
132 /* Dump the segments and it's contents */
134 unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size);
135 /* Write a supposedly constant expression to the target file. Do a range
136 * check and return one of the SEG_EXPR_xxx codes.
139 void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data);
140 /* Write the data from the given segment to a file. For expressions, F is
141 * called (see description of SegWriteFunc above).
144 void PrintSegmentMap (FILE* F);
145 /* Print a segment map to the given file */
147 void CheckSegments (void);
148 /* Walk through the segment list and check if there are segments that were
149 * not written to the output file. Output an error if this is the case.
154 /* End of segments.h */