1 /*****************************************************************************/
5 /* Segments for the ca65 macroassembler */
9 /* (C) 1998-2012, Ullrich von Bassewitz */
10 /* Roemerstrasse 52 */
11 /* D-70794 Filderstadt */
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 /*****************************************************************************/
52 /*****************************************************************************/
54 /*****************************************************************************/
58 /* Segment definition */
59 typedef struct Segment Segment;
61 Fragment* Root; /* Root of fragment list */
62 Fragment* Last; /* Pointer to last fragment */
63 unsigned long FragCount; /* Number of fragments */
64 unsigned Num; /* Segment number */
65 unsigned Flags; /* Segment flags */
66 unsigned long Align; /* Segment alignment */
67 int RelocMode; /* Relocatable mode if OrgPerSeg */
68 unsigned long PC; /* PC if in relocatable mode */
69 unsigned long AbsPC; /* PC if in local absolute mode */
70 /* (OrgPerSeg is true) */
71 SegDef* Def; /* Segment definition (name and type) */
74 /* Definitions for predefined segments */
75 extern SegDef NullSegDef;
76 extern SegDef ZeropageSegDef;
77 extern SegDef DataSegDef;
78 extern SegDef BssSegDef;
79 extern SegDef RODataSegDef;
80 extern SegDef CodeSegDef;
82 /* Collection containing all segments */
83 extern Collection SegmentList;
85 /* Currently active segment */
86 extern Segment* ActiveSeg;
90 /*****************************************************************************/
92 /*****************************************************************************/
96 Fragment* GenFragment (unsigned char Type, unsigned short Len);
97 /* Generate a new fragment, add it to the current segment and return it. */
99 void UseSeg (const SegDef* D);
100 /* Use the given segment */
102 #if defined(HAVE_INLINE)
103 INLINE const SegDef* GetCurrentSegDef (void)
104 /* Get a pointer to the segment defininition of the current segment */
106 return ActiveSeg->Def;
109 # define GetCurrentSegDef() (ActiveSeg->Def)
112 #if defined(HAVE_INLINE)
113 INLINE unsigned GetCurrentSegNum (void)
114 /* Get the number of the current segment */
116 return ActiveSeg->Num;
119 # define GetCurrentSegNum() (ActiveSeg->Num)
122 #if defined(HAVE_INLINE)
123 INLINE unsigned char GetCurrentSegAddrSize (void)
124 /* Get the address size of the current segment */
126 return ActiveSeg->Def->AddrSize;
129 # define GetCurrentSegAddrSize() (ActiveSeg->Def->AddrSize)
132 void SegAlign (unsigned long Alignment, int FillVal);
133 /* Align the PC segment to Alignment. If FillVal is -1, emit fill fragments
134 * (the actual fill value will be determined by the linker), otherwise use
138 unsigned char GetSegAddrSize (unsigned SegNum);
139 /* Return the address size of the segment with the given number */
141 unsigned long GetPC (void);
142 /* Get the program counter of the current segment */
144 int GetRelocMode (void);
145 /* Return true if we're currently in relocatable mode */
147 void EnterAbsoluteMode (unsigned long AbsPC);
148 /* Enter absolute (non relocatable mode). Depending on the OrgPerSeg flag,
149 * this will either switch the mode globally or for the current segment.
152 void EnterRelocMode (void);
153 /* Enter relocatable mode. Depending on the OrgPerSeg flag, this will either
154 * switch the mode globally or for the current segment.
158 /* Check the segments for range and other errors. Do cleanup. */
161 /* Dump the contents of all segments */
164 /* Initialize segments */
166 void SetSegmentSizes (void);
167 /* Set the default segment sizes according to the memory model */
169 void WriteSegments (void);
170 /* Write the segment data to the object file */
174 /* End of segment.h */