]> git.sur5r.net Git - cc65/blob - src/ld65/segments.h
This commit was generated by cvs2svn to compensate for changes in r2,
[cc65] / src / ld65 / segments.h
1 /*****************************************************************************/
2 /*                                                                           */
3 /*                                segments.h                                 */
4 /*                                                                           */
5 /*                   Segment handling for the ld65 linker                    */
6 /*                                                                           */
7 /*                                                                           */
8 /*                                                                           */
9 /* (C) 1998-2000 Ullrich von Bassewitz                                       */
10 /*               Wacholderweg 14                                             */
11 /*               D-70597 Stuttgart                                           */
12 /* EMail:        uz@musoftware.de                                            */
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 #include "../common/exprdefs.h"
44
45 #include "objdata.h"
46
47
48
49 /*****************************************************************************/
50 /*                                   Data                                    */
51 /*****************************************************************************/
52
53
54
55 /* Forward for the section structure (a section is a part of a segment) */
56 typedef struct Section_ Section;
57
58 /* Segment structure */
59 typedef struct Segment_ Segment;
60 struct Segment_ {
61     Segment*            Next;           /* Hash list */
62     Segment*            List;           /* List of all segments */
63     Section*            SecRoot;        /* Section list */
64     Section*            SecLast;        /* Pointer to last section */
65     unsigned long       PC;             /* PC were this segment is located */
66     unsigned long       Size;           /* Size of data so far */
67     ObjData*            AlignObj;       /* Module that requested the alignment */
68     unsigned char       Align;          /* Alignment needed */
69     unsigned char       FillVal;        /* Value to use for fill bytes */
70     unsigned char       Type;           /* Type of segment */
71     char                Dumped;         /* Did we dump this segment? */
72     char                Name [1];       /* Name, dynamically allocated */
73 };
74
75
76
77 /* Section structure (a section is a part of a segment) */
78 struct Section_ {
79     Section*            Next;           /* List of sections in a segment */
80     Segment*            Seg;            /* Segment that contains the section */
81     struct Fragment_*   FragRoot;       /* Fragment list */
82     struct Fragment_*   FragLast;       /* Pointer to last fragment */
83     unsigned long       Offs;           /* Offset into the segment */
84     unsigned long       Size;           /* Size of the section */
85     unsigned char       Align;          /* Alignment */
86     unsigned char       Fill;           /* Fill bytes for alignment */
87     unsigned char       Type;           /* Type of segment */
88 };
89
90
91
92 /* Prototype for a function that is used to write expressions to the target
93  * file (used in SegWrite). It returns one of the following values:
94  */
95 #define SEG_EXPR_OK             0       /* Ok */
96 #define SEG_EXPR_RANGE_ERROR    1       /* Range error */
97 #define SEG_EXPR_TOO_COMPLEX    2       /* Expression too complex */
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 Section* ReadSection (FILE* F, ObjData* O);
114 /* Read a section from a file */
115
116 Segment* SegFind (const char* Name);
117 /* Return the given segment or NULL if not found. */
118
119 int IsBSSType (Segment* S);
120 /* Check if the given segment is a BSS style segment, that is, it does not
121  * contain non-zero data.
122  */
123
124 void SegDump (void);
125 /* Dump the segments and it's contents */
126
127 unsigned SegWriteConstExpr (FILE* F, ExprNode* E, int Signed, unsigned Size);
128 /* Write a supposedly constant expression to the target file. Do a range
129  * check and return one of the SEG_EXPR_xxx codes.
130  */
131
132 void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data);
133 /* Write the data from the given segment to a file. For expressions, F is
134  * called (see description of SegWriteFunc above).
135  */
136
137 void PrintSegmentMap (FILE* F);
138 /* Print a segment map to the given file */
139
140 void CheckSegments (void);
141 /* Walk through the segment list and check if there are segments that were
142  * not written to the output file. Output an error if this is the case.
143  */
144
145
146
147 /* End of segments.h */
148
149 #endif
150
151
152