2003-10-21 20:34:56 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
/* */
|
2013-05-09 11:56:54 +00:00
|
|
|
/* segment.h */
|
2003-10-21 20:34:56 +00:00
|
|
|
/* */
|
|
|
|
/* Segments for the ca65 macroassembler */
|
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* */
|
2012-01-04 22:15:47 +00:00
|
|
|
/* (C) 1998-2012, Ullrich von Bassewitz */
|
2011-08-05 13:45:33 +00:00
|
|
|
/* Roemerstrasse 52 */
|
|
|
|
/* D-70794 Filderstadt */
|
|
|
|
/* EMail: uz@cc65.org */
|
2003-10-21 20:34:56 +00:00
|
|
|
/* */
|
|
|
|
/* */
|
|
|
|
/* This software is provided 'as-is', without any expressed or implied */
|
|
|
|
/* warranty. In no event will the authors be held liable for any damages */
|
|
|
|
/* arising from the use of this software. */
|
|
|
|
/* */
|
|
|
|
/* Permission is granted to anyone to use this software for any purpose, */
|
|
|
|
/* including commercial applications, and to alter it and redistribute it */
|
|
|
|
/* freely, subject to the following restrictions: */
|
|
|
|
/* */
|
|
|
|
/* 1. The origin of this software must not be misrepresented; you must not */
|
|
|
|
/* claim that you wrote the original software. If you use this software */
|
|
|
|
/* in a product, an acknowledgment in the product documentation would be */
|
|
|
|
/* appreciated but is not required. */
|
|
|
|
/* 2. Altered source versions must be plainly marked as such, and must not */
|
|
|
|
/* be misrepresented as being the original software. */
|
|
|
|
/* 3. This notice may not be removed or altered from any source */
|
|
|
|
/* distribution. */
|
|
|
|
/* */
|
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef SEGMENT_H
|
|
|
|
#define SEGMENT_H
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* common */
|
2011-08-05 13:45:33 +00:00
|
|
|
#include "coll.h"
|
2003-10-21 20:34:56 +00:00
|
|
|
#include "fragdefs.h"
|
2003-11-07 19:28:37 +00:00
|
|
|
#include "inline.h"
|
2003-10-21 20:34:56 +00:00
|
|
|
|
|
|
|
/* ca65 */
|
|
|
|
#include "fragment.h"
|
2012-01-04 22:02:02 +00:00
|
|
|
#include "segdef.h"
|
2003-10-21 20:34:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Data */
|
2003-10-21 20:34:56 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
2003-11-07 19:28:37 +00:00
|
|
|
/* Segment definition */
|
|
|
|
typedef struct Segment Segment;
|
|
|
|
struct Segment {
|
2013-05-09 11:56:54 +00:00
|
|
|
Fragment* Root; /* Root of fragment list */
|
|
|
|
Fragment* Last; /* Pointer to last fragment */
|
2003-11-07 19:28:37 +00:00
|
|
|
unsigned long FragCount; /* Number of fragments */
|
2013-05-09 11:56:54 +00:00
|
|
|
unsigned Num; /* Segment number */
|
2012-01-04 22:15:47 +00:00
|
|
|
unsigned Flags; /* Segment flags */
|
2013-05-09 11:56:54 +00:00
|
|
|
unsigned long Align; /* Segment alignment */
|
2007-08-23 19:48:43 +00:00
|
|
|
int RelocMode; /* Relocatable mode if OrgPerSeg */
|
|
|
|
unsigned long PC; /* PC if in relocatable mode */
|
|
|
|
unsigned long AbsPC; /* PC if in local absolute mode */
|
|
|
|
/* (OrgPerSeg is true) */
|
2003-11-07 19:28:37 +00:00
|
|
|
SegDef* Def; /* Segment definition (name and type) */
|
|
|
|
};
|
|
|
|
|
2003-10-21 20:34:56 +00:00
|
|
|
/* Definitions for predefined segments */
|
|
|
|
extern SegDef NullSegDef;
|
|
|
|
extern SegDef ZeropageSegDef;
|
|
|
|
extern SegDef DataSegDef;
|
|
|
|
extern SegDef BssSegDef;
|
|
|
|
extern SegDef RODataSegDef;
|
|
|
|
extern SegDef CodeSegDef;
|
|
|
|
|
2011-08-05 13:45:33 +00:00
|
|
|
/* Collection containing all segments */
|
|
|
|
extern Collection SegmentList;
|
2003-12-06 14:16:27 +00:00
|
|
|
|
2003-11-07 19:28:37 +00:00
|
|
|
/* Currently active segment */
|
|
|
|
extern Segment* ActiveSeg;
|
|
|
|
|
2003-10-21 20:34:56 +00:00
|
|
|
|
|
|
|
|
|
|
|
/*****************************************************************************/
|
2013-05-09 11:56:54 +00:00
|
|
|
/* Code */
|
2003-10-21 20:34:56 +00:00
|
|
|
/*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Fragment* GenFragment (unsigned char Type, unsigned short Len);
|
|
|
|
/* Generate a new fragment, add it to the current segment and return it. */
|
|
|
|
|
|
|
|
void UseSeg (const SegDef* D);
|
|
|
|
/* Use the given segment */
|
|
|
|
|
2003-11-07 19:28:37 +00:00
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE const SegDef* GetCurrentSegDef (void)
|
2003-10-21 20:34:56 +00:00
|
|
|
/* Get a pointer to the segment defininition of the current segment */
|
2003-11-07 19:28:37 +00:00
|
|
|
{
|
|
|
|
return ActiveSeg->Def;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define GetCurrentSegDef() (ActiveSeg->Def)
|
|
|
|
#endif
|
2003-10-21 20:34:56 +00:00
|
|
|
|
2003-11-07 19:28:37 +00:00
|
|
|
#if defined(HAVE_INLINE)
|
|
|
|
INLINE unsigned GetCurrentSegNum (void)
|
2003-10-21 20:34:56 +00:00
|
|
|
/* Get the number of the current segment */
|
2003-11-07 19:28:37 +00:00
|
|
|
{
|
|
|
|
return ActiveSeg->Num;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define GetCurrentSegNum() (ActiveSeg->Num)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined(HAVE_INLINE)
|
2003-11-23 21:39:12 +00:00
|
|
|
INLINE unsigned char GetCurrentSegAddrSize (void)
|
2003-11-07 19:28:37 +00:00
|
|
|
/* Get the address size of the current segment */
|
|
|
|
{
|
|
|
|
return ActiveSeg->Def->AddrSize;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
# define GetCurrentSegAddrSize() (ActiveSeg->Def->AddrSize)
|
|
|
|
#endif
|
2003-10-21 20:34:56 +00:00
|
|
|
|
2011-12-27 22:54:52 +00:00
|
|
|
void SegAlign (unsigned long Alignment, int FillVal);
|
|
|
|
/* Align the PC segment to Alignment. If FillVal is -1, emit fill fragments
|
|
|
|
* (the actual fill value will be determined by the linker), otherwise use
|
|
|
|
* the given value.
|
2003-10-21 20:34:56 +00:00
|
|
|
*/
|
|
|
|
|
2003-11-23 21:39:12 +00:00
|
|
|
unsigned char GetSegAddrSize (unsigned SegNum);
|
2003-11-07 19:28:37 +00:00
|
|
|
/* Return the address size of the segment with the given number */
|
2003-10-21 20:34:56 +00:00
|
|
|
|
|
|
|
unsigned long GetPC (void);
|
|
|
|
/* Get the program counter of the current segment */
|
|
|
|
|
2007-08-23 19:48:43 +00:00
|
|
|
int GetRelocMode (void);
|
|
|
|
/* Return true if we're currently in relocatable mode */
|
|
|
|
|
|
|
|
void EnterAbsoluteMode (unsigned long AbsPC);
|
|
|
|
/* Enter absolute (non relocatable mode). Depending on the OrgPerSeg flag,
|
|
|
|
* this will either switch the mode globally or for the current segment.
|
|
|
|
*/
|
|
|
|
|
|
|
|
void EnterRelocMode (void);
|
|
|
|
/* Enter relocatable mode. Depending on the OrgPerSeg flag, this will either
|
|
|
|
* switch the mode globally or for the current segment.
|
|
|
|
*/
|
2003-10-21 20:34:56 +00:00
|
|
|
|
2011-08-19 20:55:48 +00:00
|
|
|
void SegDone (void);
|
|
|
|
/* Check the segments for range and other errors. Do cleanup. */
|
2003-10-21 20:34:56 +00:00
|
|
|
|
|
|
|
void SegDump (void);
|
|
|
|
/* Dump the contents of all segments */
|
|
|
|
|
2011-08-19 20:55:48 +00:00
|
|
|
void SegInit (void);
|
2003-11-28 22:12:14 +00:00
|
|
|
/* Initialize segments */
|
|
|
|
|
2011-08-05 13:45:33 +00:00
|
|
|
void SetSegmentSizes (void);
|
|
|
|
/* Set the default segment sizes according to the memory model */
|
|
|
|
|
2003-10-21 20:34:56 +00:00
|
|
|
void WriteSegments (void);
|
|
|
|
/* Write the segment data to the object file */
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/* End of segment.h */
|
|
|
|
|
|
|
|
#endif
|