]> git.sur5r.net Git - cc65/blob - src/ld65/segments.h
Since we have now builtin search paths, we need to be able to forget them,
[cc65] / src / ld65 / segments.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                segments.h                                 */
4 /*                                                                           */
5 /*                   Segment handling for the ld65 linker                    */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2003 Ullrich von Bassewitz                                       */
10 /*               Römerstraße 52                                              */
11 /*               D-70794 Filderstadt                                         */
12 /* EMail:        uz@cc65.org                                                 */
13 /*                                                                           */
14 /*                                                                           */
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.                                    */
18 /*                                                                           */
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:                            */
22 /*                                                                           */
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              */
30 /*    distribution.                                                          */
31 /*                                                                           */
32 /*****************************************************************************/
33
34
35
36 #ifndef SEGMENTS_H
37 #define SEGMENTS_H
38
39
40
41 #include <stdio.h>
42
43 /* common */
44 #include "exprdefs.h"
45
46
47
48 /*****************************************************************************/
49 /*                                   Data                                    */
50 /*****************************************************************************/
51
52
53
54 /* Segment structure */
55 typedef struct Segment Segment;
56 struct Segment {
57     unsigned            Name;           /* Name index of the segment */
58     Segment*            Next;           /* Hash list */
59     Segment*            List;           /* List of all segments */
60     struct Section*     SecRoot;        /* Section list */
61     struct Section*     SecLast;        /* Pointer to last section */
62     unsigned long       PC;             /* PC were this segment is located */
63     unsigned long       Size;           /* Size of data so far */
64     struct ObjData*     AlignObj;       /* Module that requested the alignment */
65     unsigned char       Align;          /* Alignment needed */
66     unsigned char       FillVal;        /* Value to use for fill bytes */
67     unsigned char       AddrSize;       /* Address size of segment */
68     unsigned char       ReadOnly;       /* True for readonly segments (config) */
69     unsigned char       Relocatable;    /* True if the segment is relocatable */
70     unsigned char       Dumped;         /* Did we dump this segment? */
71 };
72
73
74
75 /* Section structure (a section is a part of a segment) */
76 typedef struct Section Section;
77 struct Section {
78     Section*            Next;           /* List of sections in a segment */
79     Segment*            Seg;            /* Segment that contains the section */
80     struct Fragment*    FragRoot;       /* Fragment list */
81     struct Fragment*    FragLast;       /* Pointer to last fragment */
82     unsigned long       Offs;           /* Offset into the segment */
83     unsigned long       Size;           /* Size of the section */
84     unsigned char       Align;          /* Alignment */
85     unsigned char       Fill;           /* Fill bytes for alignment */
86     unsigned char       AddrSize;       /* Address size of segment */
87 };
88
89
90
91 /* Prototype for a function that is used to write expressions to the target
92  * file (used in SegWrite). It returns one of the following values:
93  */
94 #define SEG_EXPR_OK             0U      /* Ok */
95 #define SEG_EXPR_RANGE_ERROR    1U      /* Range error */
96 #define SEG_EXPR_TOO_COMPLEX    2U      /* Expression too complex */
97 #define SEG_EXPR_INVALID        3U      /* Expression is invalid (e.g. unmapped segment) */
98
99 typedef unsigned (*SegWriteFunc) (ExprNode* E,        /* The expression to write */
100                                   int Signed,         /* Signed expression? */
101                                   unsigned Size,      /* Size (=range) */
102                                   unsigned long Offs, /* File offset */
103                                   void* Data);        /* Callers data */
104
105
106
107 /*****************************************************************************/
108 /*                                   Code                                    */
109 /*****************************************************************************/
110
111
112
113 Segment* GetSegment (unsigned Name, unsigned char AddrSize, const char* ObjName);
114 /* Search for a segment and return an existing one. If the segment does not
115  * exist, create a new one and return that. ObjName is only used for the error
116  * message and may be NULL if the segment is linker generated.
117  */
118
119 Section* NewSection (Segment* Seg, unsigned char Align, unsigned char AddrSize);
120 /* Create a new section for the given segment */
121
122 Section* ReadSection (FILE* F, struct ObjData* O);
123 /* Read a section from a file */
124
125 Segment* SegFind (unsigned Name);
126 /* Return the given segment or NULL if not found. */
127
128 int IsBSSType (Segment* S);
129 /* Check if the given segment is a BSS style segment, that is, it does not
130  * contain non-zero data.
131  */
132
133 void SegDump (void);
134 /* Dump the segments and it's contents */
135
136 unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size);
137 /* Write a supposedly constant expression to the target file. Do a range
138  * check and return one of the SEG_EXPR_xxx codes.
139  */
140
141 void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data);
142 /* Write the data from the given segment to a file. For expressions, F is
143  * called (see description of SegWriteFunc above).
144  */
145
146 void PrintSegmentMap (FILE* F);
147 /* Print a segment map to the given file */
148
149 void PrintDbgSegments (FILE* F);
150 /* Output the segments to the debug file */
151
152 void CheckSegments (void);
153 /* Walk through the segment list and check if there are segments that were
154  * not written to the output file. Output an error if this is the case.
155  */
156
157
158
159 /* End of segments.h */
160
161 #endif
162
163
164
165