#include <stdio.h>
#include <string.h>
#include <errno.h>
-
-#include "../common/xmalloc.h"
-
+
+/* common */
+#include "xmalloc.h"
+
+/* ld65 */
#include "global.h"
#include "error.h"
#include "fileio.h"
/* Free a binary format descriptor */
{
xfree (D);
-}
+}
-void BinWriteTarget (BinDesc* D, struct File_* F)
+void BinWriteTarget (BinDesc* D, struct File* F)
/* Write a binary output file */
{
Memory* M;
/* File list entry */
-typedef struct File_ File;
-struct File_ {
+typedef struct File File;
+struct File {
File* Next; /* Pointer to next entry in list */
unsigned Flags;
unsigned Format; /* Output format */
- struct Memory_* MemList; /* List of memory areas in this file */
- struct Memory_* MemLast; /* Last memory area in this file */
- char Name [1]; /* Name of file */
+ struct Memory* MemList; /* List of memory areas in this file */
+ struct Memory* MemLast; /* Last memory area in this file */
+ char Name [1]; /* Name of file */
};
/* Segment list node. Needed because there are two lists (RUN & LOAD) */
-typedef struct MemListNode_ MemListNode;
-struct MemListNode_ {
- MemListNode* Next; /* Next entry */
- struct SegDesc_* Seg; /* Segment */
+typedef struct MemListNode MemListNode;
+struct MemListNode {
+ MemListNode* Next; /* Next entry */
+ struct SegDesc* Seg; /* Segment */
};
/* Memory list entry */
-typedef struct Memory_ Memory;
-struct Memory_ {
- Memory* Next; /* Pointer to next entry in list */
+typedef struct Memory Memory;
+struct Memory {
+ Memory* Next; /* Pointer to next entry in list */
Memory* FNext; /* Next in file list */
unsigned Attr; /* Which values are valid? */
- unsigned Flags; /* Set of bitmapped flags */
+ unsigned Flags; /* Set of bitmapped flags */
unsigned long Start; /* Start address */
unsigned long Size; /* Length of memory section */
unsigned long FillLevel; /* Actual fill level of segment */
unsigned char FillVal; /* Value used to fill rest of seg */
MemListNode* SegList; /* List of segments for this section */
MemListNode* SegLast; /* Last segment in this section */
- File* F; /* File that contains the entry */
- char Name [1]; /* Name of the memory section */
+ File* F; /* File that contains the entry */
+ char Name [1]; /* Name of the memory section */
};
/* Segment descriptor entry */
-typedef struct SegDesc_ SegDesc;
-struct SegDesc_ {
- SegDesc* Next; /* Pointer to next entry in list */
- Segment* Seg; /* Pointer to segment structure */
- unsigned Attr; /* Attributes for segment */
- unsigned Flags; /* Set of bitmapped flags */
- Memory* Load; /* Load memory section */
- Memory* Run; /* Run memory section */
+typedef struct SegDesc SegDesc;
+struct SegDesc {
+ SegDesc* Next; /* Pointer to next entry in list */
+ Segment* Seg; /* Pointer to segment structure */
+ unsigned Attr; /* Attributes for segment */
+ unsigned Flags; /* Set of bitmapped flags */
+ Memory* Load; /* Load memory section */
+ Memory* Run; /* Run memory section */
unsigned long Addr; /* Start address or offset into segment */
- unsigned char Align; /* Alignment if given */
- char Name [1]; /* Copy of name */
+ unsigned char Align; /* Alignment if given */
+ char Name [1]; /* Copy of name */
};
/* Segment list */
#define MF_RO 0x0004 /* Read only memory area */
/* Segment flags */
-#define SF_RO 0x0001 /* Read only segment */
-#define SF_BSS 0x0002 /* Segment is BSS style segment */
-#define SF_ZP 0x0004 /* Zeropage segment (o65 only) */
-#define SF_WPROT 0x0008 /* Write protected segment */
+#define SF_RO 0x0001 /* Read only segment */
+#define SF_BSS 0x0002 /* Segment is BSS style segment */
+#define SF_ZP 0x0004 /* Zeropage segment (o65 only) */
+#define SF_WPROT 0x0008 /* Write protected segment */
#define SF_DEFINE 0x0010 /* Define start and size */
-#define SF_ALIGN 0x0020 /* Align the segment */
-#define SF_OFFSET 0x0040 /* Segment has offset in memory */
-#define SF_START 0x0080 /* Segment has fixed start address */
+#define SF_ALIGN 0x0020 /* Align the segment */
+#define SF_OFFSET 0x0040 /* Segment has offset in memory */
+#define SF_START 0x0080 /* Segment has fixed start address */
#define SF_LOAD_AND_RUN 0x1000 /* LOAD and RUN given */
#define SF_RUN_DEF 0x2000 /* RUN symbols already defined */
-#define SF_LOAD_DEF 0x4000 /* LOAD symbols already defined */
+#define SF_LOAD_DEF 0x4000 /* LOAD symbols already defined */
+
/* common */
#include "exprdefs.h"
#include "filepos.h"
-
+
/* ld65 */
#include "objdata.h"
/* Debug symbol structure */
-typedef struct DbgSym_ DbgSym;
-struct DbgSym_ {
+typedef struct DbgSym DbgSym;
+struct DbgSym {
DbgSym* Next; /* Pool linear list link */
unsigned Flags; /* Generic flags */
ObjData* Obj; /* Object file that exports the name */
-
+
+
/* */
/* exports.c */
/* */
-/* Exports handing for the ld65 linker */
+/* Exports handling for the ld65 linker */
/* */
/* */
/* */
/* common */
#include "exprdefs.h"
#include "filepos.h"
-
+
/* ld65 */
#include "objdata.h"
#include "config.h"
/* Import symbol structure */
-typedef struct Import_ Import;
-struct Import_ {
- Import* Next; /* Single linked list */
- ObjData* Obj; /* Object file that imports the name */
- FilePos Pos; /* File position of reference */
+typedef struct Import Import;
+struct Import {
+ Import* Next; /* Single linked list */
+ ObjData* Obj; /* Object file that imports the name */
+ FilePos Pos; /* File position of reference */
union {
- struct Export_* Exp; /* Matching export for this import */
- const char* Name; /* Name if not in table */
+ struct Export* Exp; /* Matching export for this import */
+ const char* Name; /* Name if not in table */
} V;
- unsigned char Type; /* Type of import */
+ unsigned char Type; /* Type of import */
};
/* Export symbol structure */
-typedef struct Export_ Export;
-struct Export_ {
+typedef struct Export Export;
+struct Export {
Export* Next; /* Hash table link */
- unsigned Flags; /* Generic flags */
- ObjData* Obj; /* Object file that exports the name */
- unsigned ImpCount; /* How many imports for this symbol? */
- Import* ImpList; /* List of imports for this symbol */
- FilePos Pos; /* File position of definition */
+ unsigned Flags; /* Generic flags */
+ ObjData* Obj; /* Object file that exports the name */
+ unsigned ImpCount; /* How many imports for this symbol? */
+ Import* ImpList; /* List of imports for this symbol */
+ FilePos Pos; /* File position of definition */
ExprNode* Expr; /* Expression (0 if not def'd) */
unsigned char Type; /* Type of export */
char* Name; /* Name - dynamically allocated */
/* Print an error about a circular reference using to define the given export */
-
+
/* End of exports.h */
#endif
-#include "../common/exprdefs.h"
-
+/* common */
+#include "exprdefs.h"
+
+/* ld65 */
#include "objdata.h"
#include "exports.h"
#include "config.h"
--- /dev/null
+/*****************************************************************************/
+/* */
+/* fragment.c */
+/* */
+/* Code/data fragment routines */
+/* */
+/* */
+/* */
+/* (C) 1998-2000 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
+/* */
+/* */
+/* 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. */
+/* */
+/*****************************************************************************/
+
+
+
+/* common */
+#include "xmalloc.h"
+
+/* ld65 */
+#include "segments.h"
+#include "fragment.h"
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
+/* Create a new fragment and insert it into the section S */
+{
+ /* Allocate memory */
+ Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */
+
+ /* Initialize the data */
+ F->Next = 0;
+ F->Obj = 0;
+ F->Size = Size;
+ F->Expr = 0;
+ F->Type = Type;
+
+ /* Insert the code fragment into the segment */
+ if (S->FragRoot == 0) {
+ /* First fragment */
+ S->FragRoot = F;
+ } else {
+ S->FragLast->Next = F;
+ }
+ S->FragLast = F;
+ S->Size += Size;
+
+ /* Return the new fragment */
+ return F;
+}
+
+
+
--- /dev/null
+/*****************************************************************************/
+/* */
+/* fragment.h */
+/* */
+/* Code/data fragment routines */
+/* */
+/* */
+/* */
+/* (C) 1998-2000 Ullrich von Bassewitz */
+/* Wacholderweg 14 */
+/* D-70597 Stuttgart */
+/* EMail: uz@musoftware.de */
+/* */
+/* */
+/* 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 FRAGMENT_H
+#define FRAGMENT_H
+
+
+
+/* common */
+#include "filepos.h"
+
+
+
+/*****************************************************************************/
+/* Data */
+/*****************************************************************************/
+
+
+
+/* Fragment structure */
+typedef struct Fragment Fragment;
+struct Fragment {
+ Fragment* Next; /* Next fragment in list */
+ struct ObjData* Obj; /* Source of fragment */
+ unsigned long Size; /* Size of data/expression */
+ struct ExprNode* Expr; /* Expression if FRAG_EXPR */
+ FilePos Pos; /* File position in source */
+ unsigned char Type; /* Type of fragment */
+ unsigned char LitBuf [1]; /* Dynamically alloc'ed literal buffer */
+};
+
+
+
+/*****************************************************************************/
+/* Code */
+/*****************************************************************************/
+
+
+
+Fragment* NewFragment (unsigned char Type, unsigned long Size, struct Section* S);
+/* Create a new fragment and insert it into the section S */
+
+
+
+/* End of fragment.h */
+
+#endif
+
+
+
+
expr.o \
extsyms.o \
fileio.o \
+ fragment.o \
global.o \
library.o \
main.o \
expr.obj \
extsyms.obj \
fileio.obj \
+ fragment.obj \
global.obj \
library.obj \
main.obj \
/* Internal structure holding object file data */
-typedef struct ObjData_ ObjData;
-struct ObjData_ {
+typedef struct ObjData ObjData;
+struct ObjData {
ObjData* Next; /* Linked list of all objects */
char* Name; /* Module name */
char* LibName; /* Name of library */
- ObjHeader Header; /* Header of file */
+ ObjHeader Header; /* Header of file */
unsigned long Start; /* Start offset of data in library */
unsigned Flags;
- unsigned FileCount; /* Input file count */
- char** Files; /* List of input files */
- unsigned SectionCount; /* Count of sections in this object */
- struct Section_** Sections; /* List of all sections */
- unsigned ExportCount; /* Count of exports */
- struct Export_** Exports; /* List of all exports */
- unsigned ImportCount; /* Count of imports */
- struct Import_** Imports; /* List of all imports */
- unsigned DbgSymCount; /* Count of debug symbols */
- struct DbgSym_** DbgSyms; /* List of debug symbols */
+ unsigned FileCount; /* Input file count */
+ char** Files; /* List of input files */
+ unsigned SectionCount; /* Count of sections in this object */
+ struct Section** Sections; /* List of all sections */
+ unsigned ExportCount; /* Count of exports */
+ struct Export** Exports; /* List of all exports */
+ unsigned ImportCount; /* Count of imports */
+ struct Import** Imports; /* List of all imports */
+ unsigned DbgSymCount; /* Count of debug symbols */
+ struct DbgSym** DbgSyms; /* List of debug symbols */
};
-
+
#include "error.h"
#include "expr.h"
#include "fileio.h"
+#include "fragment.h"
#include "global.h"
#include "segments.h"
-/* Fragment structure */
-typedef struct Fragment_ Fragment;
-struct Fragment_ {
- Fragment* Next; /* Next fragment in list */
- ObjData* Obj; /* Source of fragment */
- unsigned long Size; /* Size of data/expression */
- ExprNode* Expr; /* Expression if FRAG_EXPR */
- FilePos Pos; /* File position in source */
- unsigned char Type; /* Type of fragment */
- unsigned char LitBuf [1]; /* Dynamically alloc'ed literal buffer */
-};
-
-
-
/* Hash table */
#define HASHTAB_SIZE 253
static Segment* HashTab [HASHTAB_SIZE];
-static Fragment* NewFragment (unsigned char Type, unsigned long Size, Section* S)
-/* Create a new fragment and insert it into the segment S */
-{
- /* Allocate memory */
- Fragment* F = xmalloc (sizeof (Fragment) - 1 + Size); /* Portable? */
-
- /* Initialize the data */
- F->Next = 0;
- F->Obj = 0;
- F->Size = Size;
- F->Expr = 0;
- F->Type = Type;
-
- /* Insert the code fragment into the segment */
- if (S->FragRoot == 0) {
- /* First fragment */
- S->FragRoot = F;
- } else {
- S->FragLast->Next = F;
- }
- S->FragLast = F;
- S->Size += Size;
-
- /* Return the new fragment */
- return F;
-}
-
-
-
static Segment* NewSegment (const char* Name, unsigned char Type)
/* Create a new segment and initialize it */
{
while (Count--) {
if (I > 75) {
printf ("\n ");
- I = 3;
+ I = 3;
}
printf (" %02X", *Data++);
I += 3;
case FRAG_FILL:
printf (" Empty space (%lu bytes)\n", F->Size);
- break;
+ break;
default:
Internal ("Invalid fragment type: %02X", F->Type);
#include <stdio.h>
-#include "../common/exprdefs.h"
-
-#include "objdata.h"
+/* common */
+#include "exprdefs.h"
-/* Forward for the section structure (a section is a part of a segment) */
-typedef struct Section_ Section;
-
/* Segment structure */
-typedef struct Segment_ Segment;
-struct Segment_ {
- Segment* Next; /* Hash list */
- Segment* List; /* List of all segments */
- Section* SecRoot; /* Section list */
- Section* SecLast; /* Pointer to last section */
- unsigned long PC; /* PC were this segment is located */
- unsigned long Size; /* Size of data so far */
- ObjData* AlignObj; /* Module that requested the alignment */
- unsigned char Align; /* Alignment needed */
- unsigned char FillVal; /* Value to use for fill bytes */
- unsigned char Type; /* Type of segment */
- char Dumped; /* Did we dump this segment? */
+typedef struct Segment Segment;
+struct Segment {
+ Segment* Next; /* Hash list */
+ Segment* List; /* List of all segments */
+ struct Section* SecRoot; /* Section list */
+ struct Section* SecLast; /* Pointer to last section */
+ unsigned long PC; /* PC were this segment is located */
+ unsigned long Size; /* Size of data so far */
+ struct ObjData* AlignObj; /* Module that requested the alignment */
+ unsigned char Align; /* Alignment needed */
+ unsigned char FillVal; /* Value to use for fill bytes */
+ unsigned char Type; /* Type of segment */
+ char Dumped; /* Did we dump this segment? */
char Name [1]; /* Name, dynamically allocated */
};
/* Section structure (a section is a part of a segment) */
-struct Section_ {
- Section* Next; /* List of sections in a segment */
- Segment* Seg; /* Segment that contains the section */
- struct Fragment_* FragRoot; /* Fragment list */
- struct Fragment_* FragLast; /* Pointer to last fragment */
+typedef struct Section Section;
+struct Section {
+ Section* Next; /* List of sections in a segment */
+ Segment* Seg; /* Segment that contains the section */
+ struct Fragment* FragRoot; /* Fragment list */
+ struct Fragment* FragLast; /* Pointer to last fragment */
unsigned long Offs; /* Offset into the segment */
unsigned long Size; /* Size of the section */
unsigned char Align; /* Alignment */
#define SEG_EXPR_TOO_COMPLEX 2 /* Expression too complex */
typedef unsigned (*SegWriteFunc) (ExprNode* E, /* The expression to write */
- int Signed, /* Signed expression? */
- unsigned Size, /* Size (=range) */
- unsigned long Offs, /* File offset */
- void* Data); /* Callers data */
+ int Signed, /* Signed expression? */
+ unsigned Size, /* Size (=range) */
+ unsigned long Offs, /* File offset */
+ void* Data); /* Callers data */
-Section* ReadSection (FILE* F, ObjData* O);
+Section* ReadSection (FILE* F, struct ObjData* O);
/* Read a section from a file */
Segment* SegFind (const char* Name);
+