diff --git a/src/ld65/config.c b/src/ld65/config.c index a77f4c7ec..cf519e046 100644 --- a/src/ld65/config.c +++ b/src/ld65/config.c @@ -612,8 +612,7 @@ static void ParseSegments (void) { "RW", CFGTOK_RW }, { "BSS", CFGTOK_BSS }, { "ZP", CFGTOK_ZP }, - { "WP", CFGTOK_WPROT }, - { "WPROT", CFGTOK_WPROT }, + { "WPROT", CFGTOK_RO }, /* ### OBSOLETE */ }; unsigned Count; @@ -706,7 +705,6 @@ static void ParseSegments (void) case CFGTOK_RW: /* Default */ break; case CFGTOK_BSS: S->Flags |= SF_BSS; break; case CFGTOK_ZP: S->Flags |= (SF_BSS | SF_ZP); break; - case CFGTOK_WPROT: S->Flags |= (SF_RO | SF_WPROT); break; default: Internal ("Unexpected token: %d", CfgTok); } break; @@ -1473,11 +1471,13 @@ void CfgAssignSegments (void) Addr = NewAddr; } - /* If this is the run area, set the start address of this segment - * and remember if the segment is in a relocatable file or not. + /* If this is the run area, set the start address of this segment, + * set the readonly flag in the segment and and remember if the + * segment is in a relocatable file or not. */ if (S->Run == M) { S->Seg->PC = Addr; + S->Seg->ReadOnly = (S->Flags & SF_RO) != 0; S->Seg->Relocatable = M->Relocatable; } diff --git a/src/ld65/config.h b/src/ld65/config.h index 58036d5f3..38282689f 100644 --- a/src/ld65/config.h +++ b/src/ld65/config.h @@ -38,6 +38,7 @@ +/* ld65 */ #include "segments.h" @@ -111,12 +112,11 @@ extern unsigned SegDescCount; /* Number of entries in list */ #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_OPTIONAL 0x0100 /* Segment is optional (must not exist) */ +#define SF_DEFINE 0x0008 /* Define start and size */ +#define SF_ALIGN 0x0010 /* Align the segment */ +#define SF_OFFSET 0x0020 /* Segment has offset in memory */ +#define SF_START 0x0040 /* Segment has fixed start address */ +#define SF_OPTIONAL 0x0080 /* Segment is optional (must not exist) */ #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 */ diff --git a/src/ld65/dbgfile.c b/src/ld65/dbgfile.c new file mode 100644 index 000000000..9f2c20e3e --- /dev/null +++ b/src/ld65/dbgfile.c @@ -0,0 +1,88 @@ +/*****************************************************************************/ +/* */ +/* dbgfile.c */ +/* */ +/* Debug file creation for the ld65 linker */ +/* */ +/* */ +/* */ +/* (C) 2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* 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. */ +/* */ +/*****************************************************************************/ + + + +#include +#include +#include + +/* ld65 */ +#include "dbgfile.h" +#include "dbginfo.h" +#include "dbgsyms.h" +#include "error.h" +#include "global.h" +#include "segments.h" + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void CreateDbgFile (void) +/* Create a debug info file */ +{ + unsigned I; + + /* Open the debug info file */ + FILE* F = fopen (DbgFileName, "w"); + if (F == 0) { + Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno)); + } + + /* Output the segment info */ + PrintDbgSegments (F); + + /* Print line infos from all modules we have linked into the output file */ + for (I = 0; I < CollCount (&ObjDataList); ++I) { + + /* Get the object file */ + ObjData* O = CollAtUnchecked (&ObjDataList, I); + + /* Output debug info */ + PrintDbgInfo (O, F); + PrintDbgSyms (O, F); + } + + /* Close the file */ + if (fclose (F) != 0) { + Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno)); + } +} + + + diff --git a/src/ld65/dbgfile.h b/src/ld65/dbgfile.h new file mode 100644 index 000000000..ad660daaa --- /dev/null +++ b/src/ld65/dbgfile.h @@ -0,0 +1,57 @@ +/*****************************************************************************/ +/* */ +/* dbgfile.h */ +/* */ +/* Debug file creation for the ld65 linker */ +/* */ +/* */ +/* */ +/* (C) 2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* 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 DBGFILE_H +#define DBGFILE_H + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +void CreateDbgFile (void); +/* Create a debug info file */ + + + +/* End of dbgfile.h */ + +#endif + + + diff --git a/src/ld65/main.c b/src/ld65/main.c index 146b0db78..c5f4aec17 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -53,6 +53,7 @@ #include "binfmt.h" #include "condes.h" #include "config.h" +#include "dbgfile.h" #include "error.h" #include "exports.h" #include "fileio.h" diff --git a/src/ld65/make/gcc.mak b/src/ld65/make/gcc.mak index e9fdf92e2..241444fa2 100644 --- a/src/ld65/make/gcc.mak +++ b/src/ld65/make/gcc.mak @@ -23,6 +23,7 @@ OBJS = asserts.o \ binfmt.o \ condes.o \ config.o \ + dbgfile.o \ dbginfo.o \ dbgsyms.o \ error.o \ diff --git a/src/ld65/make/watcom.mak b/src/ld65/make/watcom.mak index 37b016522..4e452785e 100644 --- a/src/ld65/make/watcom.mak +++ b/src/ld65/make/watcom.mak @@ -48,6 +48,7 @@ OBJS = asserts.obj \ binfmt.obj \ condes.obj \ config.obj \ + dbgfile.obj \ dbginfo.obj \ dbgsyms.obj \ error.obj \ diff --git a/src/ld65/mapfile.c b/src/ld65/mapfile.c index 5fcba2b99..22c11d492 100644 --- a/src/ld65/mapfile.c +++ b/src/ld65/mapfile.c @@ -39,7 +39,6 @@ /* ld65 */ #include "config.h" -#include "dbginfo.h" #include "dbgsyms.h" #include "exports.h" #include "global.h" @@ -155,33 +154,3 @@ void CreateLabelFile (void) -void CreateDbgFile (void) -/* Create a debug info file */ -{ - unsigned I; - - /* Open the debug info file */ - FILE* F = fopen (DbgFileName, "w"); - if (F == 0) { - Error ("Cannot create debug file `%s': %s", DbgFileName, strerror (errno)); - } - - /* Print line infos from all modules we have linked into the output file */ - for (I = 0; I < CollCount (&ObjDataList); ++I) { - - /* Get the object file */ - ObjData* O = CollAtUnchecked (&ObjDataList, I); - - /* Output debug info */ - PrintDbgInfo (O, F); - PrintDbgSyms (O, F); - } - - /* Close the file */ - if (fclose (F) != 0) { - Error ("Error closing debug file `%s': %s", DbgFileName, strerror (errno)); - } -} - - - diff --git a/src/ld65/mapfile.h b/src/ld65/mapfile.h index 91a50f28d..b4cc31f18 100644 --- a/src/ld65/mapfile.h +++ b/src/ld65/mapfile.h @@ -6,9 +6,9 @@ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* (C) 1998-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ /* */ @@ -38,10 +38,6 @@ -#include - - - /*****************************************************************************/ /* Code */ /*****************************************************************************/ @@ -54,9 +50,6 @@ void CreateMapFile (void); void CreateLabelFile (void); /* Create a label file */ -void CreateDbgFile (void); -/* Create a debug info file */ - /* End of mapfile.h */ diff --git a/src/ld65/scanner.h b/src/ld65/scanner.h index c8c2c6a37..2af9fa161 100644 --- a/src/ld65/scanner.h +++ b/src/ld65/scanner.h @@ -91,7 +91,6 @@ typedef enum { CFGTOK_RW, CFGTOK_BSS, CFGTOK_ZP, - CFGTOK_WPROT, CFGTOK_O65, CFGTOK_BIN, diff --git a/src/ld65/segments.c b/src/ld65/segments.c index d834641d8..4a518702d 100644 --- a/src/ld65/segments.c +++ b/src/ld65/segments.c @@ -99,6 +99,7 @@ static Segment* NewSegment (unsigned Name, unsigned char Type) S->Align = 0; S->FillVal = 0; S->Type = Type; + S->ReadOnly = 0; S->Relocatable = 0; S->Dumped = 0; @@ -331,7 +332,7 @@ int IsBSSType (Segment* S) unsigned long Count = F->Size; while (Count--) { if (*Data++ != 0) { - return 0; + return 0; } } } else if (F->Type == FRAG_EXPR || F->Type == FRAG_SEXPR) { @@ -602,15 +603,15 @@ void PrintSegmentMap (FILE* F) /* Get a pointer to the segment */ S = SegPool [I]; - /* Print empty segments only if explicitly requested */ - if (VerboseMap || S->Size > 0) { - /* Print the segment data */ - long End = S->PC + S->Size; - if (S->Size > 0) { - /* Point to last element addressed */ - --End; - } - fprintf (F, "%-20s %06lX %06lX %06lX\n", + /* Print empty segments only if explicitly requested */ + if (VerboseMap || S->Size > 0) { + /* Print the segment data */ + long End = S->PC + S->Size; + if (S->Size > 0) { + /* Point to last element addressed */ + --End; + } + fprintf (F, "%-20s %06lX %06lX %06lX\n", GetString (S->Name), S->PC, End, S->Size); } } @@ -621,6 +622,32 @@ void PrintSegmentMap (FILE* F) +void PrintDbgSegments (FILE* F) +/* Output the segments to the debug file */ +{ + Segment* S; + + /* Walk over all segments */ + S = SegRoot; + while (S) { + + /* Ignore empty segments */ + if (S->Size > 0) { + + /* Print the segment data */ + fprintf (F, "segment\t\"%s\", 0x%06lX, 0x%04lX, %s, %s\n", + GetString (S->Name), S->PC, S->Size, + SegTypeToStr (S->Type), + S->ReadOnly? "ro" : "rw"); + } + + /* Follow the linked list */ + S = S->List; + } +} + + + void CheckSegments (void) /* Walk through the segment list and check if there are segments that were * not written to the output file. Output an error if this is the case. @@ -628,7 +655,7 @@ void CheckSegments (void) { Segment* S = SegRoot; while (S) { - if (S->Size > 0 && S->Dumped == 0) { + if (S->Size > 0 && S->Dumped == 0) { Error ("Missing memory area assignment for segment `%s'", GetString (S->Name)); } diff --git a/src/ld65/segments.h b/src/ld65/segments.h index 660ed78d1..0df7e8fc3 100644 --- a/src/ld65/segments.h +++ b/src/ld65/segments.h @@ -6,9 +6,9 @@ /* */ /* */ /* */ -/* (C) 1998-2001 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ +/* (C) 1998-2003 Ullrich von Bassewitz */ +/* Römerstrasse 52 */ +/* D-70794 Filderstadt */ /* EMail: uz@cc65.org */ /* */ /* */ @@ -65,6 +65,7 @@ struct Segment { unsigned char Align; /* Alignment needed */ unsigned char FillVal; /* Value to use for fill bytes */ unsigned char Type; /* Type of segment */ + unsigned char ReadOnly; /* True for readonly segments (config) */ unsigned char Relocatable; /* True if the segment is relocatable */ unsigned char Dumped; /* Did we dump this segment? */ }; @@ -145,6 +146,9 @@ void SegWrite (FILE* Tgt, Segment* S, SegWriteFunc F, void* Data); void PrintSegmentMap (FILE* F); /* Print a segment map to the given file */ +void PrintDbgSegments (FILE* F); +/* Output the segments to the debug file */ + void CheckSegments (void); /* Walk through the segment list and check if there are segments that were * not written to the output file. Output an error if this is the case.