1/*****************************************************************************/
2/* */
3/* segment.h */
4/* */
5/* Segments for the ca65 macroassembler */
6/* */
7/* */
8/* */
9/* (C) 1998-2012, Ullrich von Bassewitz */
10/* Roemerstrasse 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 SEGMENT_H
37#define SEGMENT_H
38
39
40
41/* common */
42#include "coll.h"
43#include "fragdefs.h"
44#include "inline.h"
45
46/* ca65 */
47#include "fragment.h"
48#include "segdef.h"
49
50
51
52/*****************************************************************************/
53/* Data */
54/*****************************************************************************/
55
56
57
58/* Segment definition */
59typedef struct Segment Segment;
60struct 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) */
72};
73
74/* Definitions for predefined segments */
75extern SegDef NullSegDef;
76extern SegDef ZeropageSegDef;
77extern SegDef DataSegDef;
78extern SegDef BssSegDef;
79extern SegDef RODataSegDef;
80extern SegDef CodeSegDef;
81
82/* Collection containing all segments */
83extern Collection SegmentList;
84
85/* Currently active segment */
86extern Segment* ActiveSeg;
87
88
89
90/*****************************************************************************/
91/* Code */
92/*****************************************************************************/
93
94
95
96Fragment* GenFragment (unsigned char Type, unsigned short Len);
97/* Generate a new fragment, add it to the current segment and return it. */
98
99void UseSeg (const SegDef* D);
100/* Use the given segment */
101
102#if defined(HAVE_INLINE)
103INLINE const SegDef* GetCurrentSegDef (void)
104/* Get a pointer to the segment defininition of the current segment */
105{
106 return ActiveSeg->Def;
107}
108#else
109# define GetCurrentSegDef() (ActiveSeg->Def)
110#endif
111
112#if defined(HAVE_INLINE)
113INLINE unsigned GetCurrentSegNum (void)
114/* Get the number of the current segment */
115{
116 return ActiveSeg->Num;
117}
118#else
119# define GetCurrentSegNum() (ActiveSeg->Num)
120#endif
121
122#if defined(HAVE_INLINE)
123INLINE unsigned char GetCurrentSegAddrSize (void)
124/* Get the address size of the current segment */
125{
126 return ActiveSeg->Def->AddrSize;
127}
128#else
129# define GetCurrentSegAddrSize() (ActiveSeg->Def->AddrSize)
130#endif
131
132void 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
135** the given value.
136*/
137
138unsigned char GetSegAddrSize (unsigned SegNum);
139/* Return the address size of the segment with the given number */
140
141unsigned long GetPC (void);
142/* Get the program counter of the current segment */
143
144int GetRelocMode (void);
145/* Return true if we're currently in relocatable mode */
146
147void 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.
150*/
151
152void EnterRelocMode (void);
153/* Enter relocatable mode. Depending on the OrgPerSeg flag, this will either
154** switch the mode globally or for the current segment.
155*/
156
157void SegDone (void);
158/* Check the segments for range and other errors. Do cleanup. */
159
160void SegDump (void);
161/* Dump the contents of all segments */
162
163void SegInit (void);
164/* Initialize segments */
165
166void SetSegmentSizes (void);
167/* Set the default segment sizes according to the memory model */
168
169void WriteSegments (void);
170/* Write the segment data to the object file */
171
172
173
174/* End of segment.h */
175
176#endif
177