X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;f=src%2Fld65%2Fmain.c;h=489ac5cb9fd458d625f1c55116f35c75775f9ecb;hb=dbbce2e939af8fd78f659e5c66eea8b002369ba2;hp=0d1f171ef0fcdb536e941b7d832c9f712a1d7d7d;hpb=c3105a4e5d483131e48ca3cd5e9107c5a2c18e51;p=cc65 diff --git a/src/ld65/main.c b/src/ld65/main.c index 0d1f171ef..489ac5cb9 100644 --- a/src/ld65/main.c +++ b/src/ld65/main.c @@ -6,10 +6,10 @@ /* */ /* */ /* */ -/* (C) 1998-2000 Ullrich von Bassewitz */ -/* Wacholderweg 14 */ -/* D-70597 Stuttgart */ -/* EMail: uz@musoftware.de */ +/* (C) 1998-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 */ @@ -42,12 +42,14 @@ #include "cmdline.h" #include "libdefs.h" #include "objdefs.h" +#include "print.h" #include "target.h" #include "version.h" #include "xmalloc.h" /* ld65 */ #include "binfmt.h" +#include "condes.h" #include "config.h" #include "error.h" #include "exports.h" @@ -87,21 +89,25 @@ static void Usage (void) fprintf (stderr, "Usage: %s [options] module ...\n" "Short options:\n" + " -C name\t\tUse linker config file\n" + " -Ln name\t\tCreate a VICE label file\n" + " -Lp\t\t\tMark write protected segments as such (VICE)\n" + " -S addr\t\tSet the default start address\n" + " -V\t\t\tPrint the linker version\n" " -h\t\t\tHelp (this text)\n" " -m name\t\tCreate a map file\n" " -o name\t\tName the default output file\n" " -t sys\t\tSet the target system\n" " -v\t\t\tVerbose mode\n" " -vm\t\t\tVerbose map file\n" - " -C name\t\tUse linker config file\n" - " -Ln name\t\tCreate a VICE label file\n" - " -Lp\t\t\tMark write protected segments as such (VICE)\n" - " -S addr\t\tSet the default start address\n" - " -V\t\t\tPrint the linker version\n" "\n" "Long options:\n" + " --config name\t\tUse linker config file\n" + " --dump-config name\tDump a builtin configuration\n" " --help\t\tHelp (this text)\n" " --mapfile name\tCreate a map file\n" + " --module-id id\tSpecify a module id\n" + " --start-addr addr\tSet the default start address\n" " --target sys\t\tSet the target system\n" " --version\t\tPrint the linker version\n", ProgName); @@ -127,8 +133,7 @@ static unsigned long CvtNumber (const char* Arg, const char* Number) /* Check if we do really have a number */ if (Converted != 1) { - fprintf (stderr, "Invalid number given in argument: %s\n", Arg); - exit (EXIT_FAILURE); + Error ("Invalid number given in argument: %s\n", Arg); } /* Return the result */ @@ -213,7 +218,7 @@ static void LinkFile (const char* Name) -static void OptConfig (const char* Opt, const char* Arg) +static void OptConfig (const char* Opt attribute ((unused)), const char* Arg) /* Define the config file */ { if (CfgAvail ()) { @@ -224,7 +229,31 @@ static void OptConfig (const char* Opt, const char* Arg) -static void OptHelp (const char* Opt, const char* Arg) +static void OptDbgFile (const char* Opt attribute ((unused)), const char* Arg) +/* Give the name of the debug file */ +{ + DbgFileName = Arg; +} + + + +static void OptDumpConfig (const char* Opt attribute ((unused)), const char* Arg) +/* Dump a builtin linker configuration */ +{ + /* Map the given target name to its id */ + target_t T = FindTarget (Arg); + if (T == TGT_UNKNOWN) { + Error ("Target system `%s' is unknown", Arg); + } + + /* Dump the builtin configuration */ + DumpBuiltinConfig (stdout, T); +} + + + +static void OptHelp (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Print usage information and exit */ { Usage (); @@ -233,7 +262,7 @@ static void OptHelp (const char* Opt, const char* Arg) -static void OptMapFile (const char* Opt, const char* Arg) +static void OptMapFile (const char* Opt attribute ((unused)), const char* Arg) /* Give the name of the map file */ { MapFileName = Arg; @@ -241,7 +270,28 @@ static void OptMapFile (const char* Opt, const char* Arg) -static void OptTarget (const char* Opt, const char* Arg) +static void OptModuleId (const char* Opt, const char* Arg) +/* Specify a module id */ +{ + unsigned long Id = CvtNumber (Opt, Arg); + if (Id > 0xFFFFUL) { + Error ("Range error in module id"); + } + ModuleId = (unsigned) Id; +} + + + +static void OptStartAddr (const char* Opt, const char* Arg) +/* Set the default start address */ +{ + StartAddr = CvtNumber (Opt, Arg); + HaveStartAddr = 1; +} + + + +static void OptTarget (const char* Opt attribute ((unused)), const char* Arg) /* Set the target system */ { const TargetDesc* D; @@ -262,11 +312,12 @@ static void OptTarget (const char* Opt, const char* Arg) -static void OptVersion (const char* Opt, const char* Arg) +static void OptVersion (const char* Opt attribute ((unused)), + const char* Arg attribute ((unused))) /* Print the assembler version */ { fprintf (stderr, - "ld65 V%u.%u.%u - (C) Copyright 1998-2000 Ullrich von Bassewitz\n", + "ld65 V%u.%u.%u - (C) Copyright 1998-2002 Ullrich von Bassewitz\n", VER_MAJOR, VER_MINOR, VER_PATCH); } @@ -277,17 +328,21 @@ int main (int argc, char* argv []) { /* Program long options */ static const LongOpt OptTab[] = { - { "--config", 1, OptConfig }, - { "--help", 0, OptHelp }, - { "--mapfile", 1, OptMapFile }, - { "--target", 1, OptTarget }, - { "--version", 0, OptVersion }, + { "--config", 1, OptConfig }, + { "--dbgfile", 1, OptDbgFile }, + { "--dump-config", 1, OptDumpConfig }, + { "--help", 0, OptHelp }, + { "--mapfile", 1, OptMapFile }, + { "--module-id", 1, OptModuleId }, + { "--start-addr", 1, OptStartAddr }, + { "--target", 1, OptTarget }, + { "--version", 0, OptVersion }, }; - int I; + unsigned I; /* Initialize the cmdline module */ - InitCmdLine (argc, argv, "ld65"); + InitCmdLine (&argc, &argv, "ld65"); /* Evaluate the CC65_LIB environment variable */ LibPath = getenv ("CC65_LIB"); @@ -303,10 +358,10 @@ int main (int argc, char* argv []) /* Check the parameters */ I = 1; - while (I < argc) { + while (I < ArgCount) { /* Get the argument */ - const char* Arg = argv [I]; + const char* Arg = ArgVec[I]; /* Check for an option */ if (Arg [0] == '-') { @@ -318,6 +373,11 @@ int main (int argc, char* argv []) LongOption (&I, OptTab, sizeof(OptTab)/sizeof(OptTab[0])); break; + case 'h': + case '?': + OptHelp (Arg, 0); + break; + case 'm': OptMapFile (Arg, GetArg (&I, 2)); break; @@ -335,8 +395,8 @@ int main (int argc, char* argv []) case 'v': switch (Arg [2]) { - case 'm': VerboseMap = 1; break; - case '\0': ++Verbose; break; + case 'm': VerboseMap = 1; break; + case '\0': ++Verbosity; break; default: UnknownOption (Arg); } break; @@ -348,13 +408,13 @@ int main (int argc, char* argv []) case 'L': switch (Arg [2]) { case 'n': LabelFileName = GetArg (&I, 3); break; - case 'p': WProtSegs = 1; break; + case 'p': WProtSegs = 1; break; default: UnknownOption (Arg); break; } break; case 'S': - StartAddr = CvtNumber (Arg, GetArg (&I, 2)); + OptStartAddr (Arg, GetArg (&I, 2)); break; case 'V': @@ -390,6 +450,9 @@ int main (int argc, char* argv []) /* Read the config file */ CfgRead (); + /* Create the condes tables if requested */ + ConDesCreate (); + /* Assign start addresses for the segments, define linker symbols */ CfgAssignSegments (); @@ -406,10 +469,14 @@ int main (int argc, char* argv []) if (LabelFileName) { CreateLabelFile (); } + if (DbgFileName) { + CreateDbgFile (); + } /* Dump the data for debugging */ - if (Verbose > 1) { + if (Verbosity > 1) { SegDump (); + ConDesDump (); } /* Return an apropriate exit code */